Skip to content

Commit

Permalink
Update Copyable UI (#1656)
Browse files Browse the repository at this point in the history
* Make copyable UI similar to copy button in CodeBlock

* Fix truncation in links without icons

* Update snap

* Create CopyButton component
  • Loading branch information
laurakwhit authored and Alex-Tideman committed Oct 4, 2023
1 parent bf59034 commit d90815b
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/event/event-details-row-expanded.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { page } from '$app/stores';
import CodeBlock from '$lib/holocene/code-block.svelte';
import Copyable from '$lib/holocene/copyable.svelte';
import Copyable from '$lib/holocene/copyable/index.svelte';
import Link from '$lib/holocene/link.svelte';
import { translate } from '$lib/i18n/translate';
import { format } from '$lib/utilities/format-camel-case';
Expand Down
7 changes: 3 additions & 4 deletions src/lib/components/event/event-details-row.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { page } from '$app/stores';
import CodeBlock from '$lib/holocene/code-block.svelte';
import Copyable from '$lib/holocene/copyable.svelte';
import Copyable from '$lib/holocene/copyable/index.svelte';
import Link from '$lib/holocene/link.svelte';
import { translate } from '$lib/i18n/translate';
import { format } from '$lib/utilities/format-camel-case';
Expand Down Expand Up @@ -52,7 +52,7 @@
copyIconTitle={translate('copy-icon-title')}
copySuccessIconTitle={translate('copy-success-icon-title')}
content={value}
container-class="xl:flex-row h-12 pr-1"
container-class="xl:flex-row"
>
<Link
class="truncate"
Expand All @@ -76,7 +76,7 @@
copyIconTitle={translate('copy-icon-title')}
copySuccessIconTitle={translate('copy-success-icon-title')}
content={value}
container-class="xl:flex-row h-12 pr-1"
container-class="xl:flex-row"
>
<Link
class="truncate"
Expand All @@ -100,7 +100,6 @@
copyIconTitle={translate('copy-icon-title')}
copySuccessIconTitle={translate('copy-success-icon-title')}
content={value}
container-class="h-12 pr-1"
>
<Link
class="truncate"
Expand Down
5 changes: 2 additions & 3 deletions src/lib/components/workflow-actions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
import SplitButton from '$lib/holocene/split-button.svelte';
import Tooltip from '$lib/holocene/tooltip.svelte';
import { translate } from '$lib/i18n/translate';
import { Action } from '$lib/models/workflow-actions';
import { ResetReapplyType } from '$lib/models/workflow-actions';
import { Action, ResetReapplyType } from '$lib/models/workflow-actions';
import {
cancelWorkflow,
resetWorkflow,
signalWorkflow,
terminateWorkflow,
} from '$lib/services/workflow-service';
import { cancelWorkflow } from '$lib/services/workflow-service';
import { authUser } from '$lib/stores/auth-user';
import { coreUserStore } from '$lib/stores/core-user';
import { resetEvents } from '$lib/stores/events';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import Copyable from '$lib/holocene/copyable.svelte';
import Copyable from '$lib/holocene/copyable/index.svelte';
import Link from '$lib/holocene/link.svelte';
import TableHeaderRow from '$lib/holocene/table/table-header-row.svelte';
import TableRow from '$lib/holocene/table/table-row.svelte';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/workflow/parent-workflow-table.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import Copyable from '$lib/holocene/copyable.svelte';
import Copyable from '$lib/holocene/copyable/index.svelte';
import Link from '$lib/holocene/link.svelte';
import TableHeaderRow from '$lib/holocene/table/table-header-row.svelte';
import TableRow from '$lib/holocene/table/table-row.svelte';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/workflow/scheduler-table.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import Copyable from '$lib/holocene/copyable.svelte';
import Copyable from '$lib/holocene/copyable/index.svelte';
import Link from '$lib/holocene/link.svelte';
import TableHeaderRow from '$lib/holocene/table/table-header-row.svelte';
import TableRow from '$lib/holocene/table/table-row.svelte';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/workflow/workflow-detail.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import Copyable from '$lib/holocene/copyable.svelte';
import Copyable from '$lib/holocene/copyable/index.svelte';
import Link from '$lib/holocene/link.svelte';
import { translate } from '$lib/i18n/translate';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`Table_body_cell$ > History Size renders 1`] = `"<td class=\\"workflows-
exports[`Table_body_cell$ > Parent Namespace renders 1`] = `"<td class=\\"workflows-summary-table-body-cell svelte-qupenl\\" data-testid=\\"workflows-summary-table-body-cell\\">parent-namespace-id</td>"`;
exports[`Table_body_cell$ > Run ID renders 1`] = `"<td class=\\"workflows-summary-table-body-cell filterable svelte-qupenl\\" data-testid=\\"workflows-summary-table-body-cell\\"><a href=\\"/namespaces/default/workflows/abc-123/def-456/history\\" class=\\"link svelte-1v8baj6\\"> def-456</a> </td>"`;
exports[`Table_body_cell$ > Run ID renders 1`] = `"<td class=\\"workflows-summary-table-body-cell filterable svelte-qupenl\\" data-testid=\\"workflows-summary-table-body-cell\\"><a href=\\"/namespaces/default/workflows/abc-123/def-456/history\\" class=\\"link inline svelte-1f9ld6i\\"> def-456</a> </td>"`;
exports[`Table_body_cell$ > Start renders 1`] = `"<td class=\\"workflows-summary-table-body-cell svelte-qupenl\\" data-testid=\\"workflows-summary-table-body-cell\\">2023-04-27 UTC 00:00:00.00</td>"`;
Expand All @@ -22,6 +22,6 @@ exports[`Table_body_cell$ > Status renders 1`] = `"<td class=\\"workflows-summar
exports[`Table_body_cell$ > Task Queue renders 1`] = `"<td class=\\"workflows-summary-table-body-cell svelte-qupenl\\" data-testid=\\"workflows-summary-table-body-cell\\">task-queue</td>"`;
exports[`Table_body_cell$ > Type renders 1`] = `"<td class=\\"workflows-summary-table-body-cell filterable svelte-qupenl\\" data-testid=\\"workflows-summary-table-body-cell\\"><a href=\\"/namespaces/default/workflows/abc-123/def-456/history\\" class=\\"link svelte-1v8baj6\\"> mock-workflow</a> </td>"`;
exports[`Table_body_cell$ > Type renders 1`] = `"<td class=\\"workflows-summary-table-body-cell filterable svelte-qupenl\\" data-testid=\\"workflows-summary-table-body-cell\\"><a href=\\"/namespaces/default/workflows/abc-123/def-456/history\\" class=\\"link inline svelte-1f9ld6i\\"> mock-workflow</a> </td>"`;
exports[`Table_body_cell$ > Workflow ID renders 1`] = `"<td class=\\"workflows-summary-table-body-cell filterable svelte-qupenl\\" data-testid=\\"workflows-summary-table-body-cell\\"><a href=\\"/namespaces/default/workflows/abc-123/def-456/history\\" class=\\"link svelte-1v8baj6\\"> abc-123</a> </td>"`;
exports[`Table_body_cell$ > Workflow ID renders 1`] = `"<td class=\\"workflows-summary-table-body-cell filterable svelte-qupenl\\" data-testid=\\"workflows-summary-table-body-cell\\"><a href=\\"/namespaces/default/workflows/abc-123/def-456/history\\" class=\\"link inline svelte-1f9ld6i\\"> abc-123</a> </td>"`;
24 changes: 12 additions & 12 deletions src/lib/holocene/code-block.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { EditorView, keymap } from '@codemirror/view';
import { createEventDispatcher, onMount } from 'svelte';
import CopyButton from '$lib/holocene/copyable/button.svelte';
import { copyToClipboard } from '$lib/utilities/copy-to-clipboard';
import {
parseWithBigInt,
Expand All @@ -25,8 +26,6 @@
TEMPORAL_THEME,
} from '$lib/vendor/codemirror/theme';
import Icon from './icon/icon.svelte';
type BaseProps = HTMLAttributes<HTMLDivElement> & {
content: string;
language?: 'json' | 'text';
Expand Down Expand Up @@ -58,6 +57,10 @@
const { copy, copied } = copyToClipboard();
const handleCopy = (e: Event) => {
copy(e, stringifyWithBigInt(content, undefined, 2));
};
let editor: HTMLElement;
let view: EditorView;
Expand Down Expand Up @@ -145,15 +148,12 @@
{...$$restProps}
/>
{#if copyable}
<button
on:click={(e) => copy(e, stringifyWithBigInt(content, undefined, 2))}
class="absolute top-2.5 right-2.5 rounded-md bg-gray-900 opacity-90 hover:bg-white"
>
<Icon
title={$copied ? copySuccessIconTitle : copyIconTitle}
name={$copied ? 'checkmark' : 'copy'}
class="text-white hover:text-gray-900"
/>
</button>
<CopyButton
{copyIconTitle}
{copySuccessIconTitle}
class="absolute top-1 right-1 text-white hover:text-gray-900 focus-visible:text-gray-900"
on:click={handleCopy}
copied={$copied}
/>
{/if}
</div>
46 changes: 0 additions & 46 deletions src/lib/holocene/copyable.svelte

This file was deleted.

32 changes: 32 additions & 0 deletions src/lib/holocene/copyable/button.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script lang="ts">
import type { HTMLButtonAttributes } from 'svelte/elements';
import Icon from '$lib/holocene/icon/icon.svelte';
interface $$Props extends HTMLButtonAttributes {
copyIconTitle: string;
copySuccessIconTitle: string;
copied: boolean;
'data-testid'?: string;
}
export let copyIconTitle: string;
export let copySuccessIconTitle: string;
export let copied: boolean;
let className = '';
export { className as class };
</script>

<button class="copy-button {className}" on:click {...$$restProps}>
<Icon
title={copied ? copySuccessIconTitle : copyIconTitle}
name={copied ? 'checkmark' : 'copy'}
/>
</button>

<style lang="postcss">
.copy-button {
@apply m-1 rounded-md border-2 border-[transparent] hover:border-indigo-600 hover:bg-gradient-to-br hover:from-blue-100 hover:to-purple-100 hover:shadow-focus hover:shadow-blue-600/50 focus-visible:border-indigo-600 focus-visible:bg-gradient-to-br focus-visible:from-blue-100 focus-visible:to-purple-100 focus-visible:shadow-focus focus-visible:shadow-blue-600/50 focus-visible:outline-none;
}
</style>
52 changes: 52 additions & 0 deletions src/lib/holocene/copyable/index.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<script lang="ts">
import { copyToClipboard } from '$lib/utilities/copy-to-clipboard';
import CopyButton from './button.svelte';
export let content: string;
export let visible = false;
export let clickAllToCopy = false;
export let copyIconTitle: string;
export let copySuccessIconTitle: string;
const { copy, copied } = copyToClipboard();
function handleOnClick(e: Event) {
copy(e, content);
}
</script>

{#if clickAllToCopy}
<button
class="group flex items-center gap-1 {$$props['container-class']}"
on:click={handleOnClick}
>
<slot>
<span class={$$props.class} class:select-all={!$$slots.default}
>{content}</span
>
</slot>
<CopyButton
{copyIconTitle}
{copySuccessIconTitle}
class={visible ? 'visible' : 'invisible group-hover:visible'}
on:click={handleOnClick}
copied={$copied}
/>
</button>
{:else}
<div class="group flex items-center gap-1 {$$props['container-class']}">
<slot>
<span class={$$props.class} class:select-all={!$$slots.default}
>{content}</span
>
</slot>
<CopyButton
{copyIconTitle}
{copySuccessIconTitle}
class={visible ? 'visible' : 'invisible group-hover:visible'}
on:click={handleOnClick}
copied={$copied}
/>
</div>
{/if}
4 changes: 2 additions & 2 deletions src/lib/holocene/link.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{href}
target={newTab ? '_blank' : null}
rel={newTab ? 'noreferrer' : null}
class="link {className}"
class="link {icon ? 'inline-flex' : 'inline'} {className}"
class:active
on:click
{...$$restProps}
Expand All @@ -39,7 +39,7 @@

<style lang="postcss">
.link {
@apply inline-flex max-w-fit cursor-pointer items-center gap-2 rounded underline underline-offset-2 hover:text-indigo-600 focus-visible:bg-blue-100 focus-visible:shadow-focus focus-visible:shadow-blue-600/50 focus-visible:outline-none;
@apply max-w-fit cursor-pointer items-center gap-2 rounded underline underline-offset-2 hover:text-indigo-600 focus-visible:bg-blue-100 focus-visible:shadow-focus focus-visible:shadow-blue-600/50 focus-visible:outline-none;
&.active {
@apply text-blue-900;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/holocene/tooltip.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import Copyable from '$lib/holocene/copyable.svelte';
import Copyable from '$lib/holocene/copyable/index.svelte';
import Icon from '$lib/holocene/icon/icon.svelte';
import type { IconName } from '$lib/holocene/icon/paths';
import type { Only } from '$lib/types/global';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/layouts/workflow-header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import Alert from '$lib/holocene/alert.svelte';
import Badge from '$lib/holocene/badge.svelte';
import CompatibilityBadge from '$lib/holocene/compatibility-badge.svelte';
import Copyable from '$lib/holocene/copyable.svelte';
import Copyable from '$lib/holocene/copyable/index.svelte';
import Icon from '$lib/holocene/icon/icon.svelte';
import Link from '$lib/holocene/link.svelte';
import TabList from '$lib/holocene/tab/tab-list.svelte';
Expand Down

0 comments on commit d90815b

Please sign in to comment.