mirror of
https://github.com/pheralb/svgl.git
synced 2024-12-04 21:32:37 +08:00
🎨 Refactor copy component to use tabs for different frameworks
This commit is contained in:
parent
8e2ff763ae
commit
12a2fd8f19
@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
import { ClipboardIcon, CopyIcon, Loader, X } from 'lucide-svelte';
|
import { ClipboardIcon, CopyIcon, Loader, X } from 'lucide-svelte';
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
|
|
||||||
import * as Popover from '@/ui/popover';
|
import * as Popover from '@/ui/popover';
|
||||||
|
import * as Tabs from '@/ui/tabs';
|
||||||
|
|
||||||
// Utils:
|
// Utils:
|
||||||
import { getSvgContent } from '@/utils/getSvgContent';
|
import { getSvgContent } from '@/utils/getSvgContent';
|
||||||
@ -25,6 +27,8 @@
|
|||||||
export let isInFigma = false;
|
export let isInFigma = false;
|
||||||
export let isWordmarkSvg = false;
|
export let isWordmarkSvg = false;
|
||||||
export let svgInfo: iSVG;
|
export let svgInfo: iSVG;
|
||||||
|
|
||||||
|
// Variables:
|
||||||
let optionsOpen = false;
|
let optionsOpen = false;
|
||||||
let isLoading = false;
|
let isLoading = false;
|
||||||
|
|
||||||
@ -174,70 +178,93 @@
|
|||||||
<CopyIcon size={iconSize} strokeWidth={iconStroke} />
|
<CopyIcon size={iconSize} strokeWidth={iconStroke} />
|
||||||
{/if}
|
{/if}
|
||||||
</Popover.Trigger>
|
</Popover.Trigger>
|
||||||
<Popover.Content class="flex flex-col space-y-2" sideOffset={3}>
|
<Popover.Content class="flex flex-col space-y-2 p-3" sideOffset={2}>
|
||||||
<button
|
<Tabs.Root value="source" class="w-full">
|
||||||
class={cn(buttonStyles, 'w-full rounded-md')}
|
<Tabs.List>
|
||||||
title={isWordmarkSvg ? 'Copy wordmark SVG to clipboard' : 'Copy SVG to clipboard'}
|
<Tabs.Trigger value="source">Source</Tabs.Trigger>
|
||||||
on:click={() => copyToClipboard()}
|
<Tabs.Trigger value="react">React</Tabs.Trigger>
|
||||||
>
|
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
|
||||||
<ClipboardIcon size={16} strokeWidth={2} />
|
<Tabs.Trigger value="svelte">Svelte</Tabs.Trigger>
|
||||||
<span>Copy SVG</span>
|
</Tabs.List>
|
||||||
</button>
|
<Tabs.Content value="source">
|
||||||
<button
|
<section class="flex flex-col space-y-2">
|
||||||
class={cn(buttonStyles, 'w-full rounded-md')}
|
<button
|
||||||
title="Copy as React component"
|
class={cn(buttonStyles, 'w-full rounded-md')}
|
||||||
disabled={isLoading}
|
title={isWordmarkSvg ? 'Copy wordmark SVG to clipboard' : 'Copy SVG to clipboard'}
|
||||||
on:click={() => convertSvgReactComponent(true)}
|
on:click={() => copyToClipboard()}
|
||||||
>
|
>
|
||||||
<ReactIcon iconSize={18} color="#2563eb" />
|
<ClipboardIcon size={16} strokeWidth={2} />
|
||||||
<span>Copy TSX</span>
|
<span>Copy SVG</span>
|
||||||
</button>
|
</button>
|
||||||
<button
|
</section>
|
||||||
class={cn(buttonStyles, 'w-full rounded-md')}
|
</Tabs.Content>
|
||||||
title="Copy as React component"
|
<Tabs.Content value="react">
|
||||||
disabled={isLoading}
|
<section class="flex flex-col space-y-2">
|
||||||
on:click={() => convertSvgReactComponent(false)}
|
<button
|
||||||
>
|
class={cn(buttonStyles, 'w-full rounded-md')}
|
||||||
<ReactIcon iconSize={18} color="#60a5fa" />
|
title="Copy as React component"
|
||||||
<span>Copy JSX</span>
|
disabled={isLoading}
|
||||||
</button>
|
on:click={() => convertSvgReactComponent(true)}
|
||||||
<button
|
>
|
||||||
class={cn(buttonStyles, 'w-full rounded-md')}
|
<ReactIcon iconSize={18} color="#2563eb" />
|
||||||
title="Copy as Vue component"
|
<span>Copy TSX</span>
|
||||||
disabled={isLoading}
|
</button>
|
||||||
on:click={() => copySvgComponent(false, 'Vue')}
|
<button
|
||||||
>
|
class={cn(buttonStyles, 'w-full rounded-md')}
|
||||||
<VueIcon iconSize={18} />
|
title="Copy as React component"
|
||||||
<span>Copy JS</span>
|
disabled={isLoading}
|
||||||
</button>
|
on:click={() => convertSvgReactComponent(false)}
|
||||||
<button
|
>
|
||||||
class={cn(buttonStyles, 'w-full rounded-md')}
|
<ReactIcon iconSize={18} color="#60a5fa" />
|
||||||
title="Copy as Vue component"
|
<span>Copy JSX</span>
|
||||||
disabled={isLoading}
|
</button>
|
||||||
on:click={() => copySvgComponent(true, 'Vue')}
|
</section>
|
||||||
>
|
</Tabs.Content>
|
||||||
<VueIcon iconSize={18} />
|
<Tabs.Content value="svelte">
|
||||||
<span>Copy TS</span>
|
<section class="flex flex-col space-y-2">
|
||||||
</button>
|
<button
|
||||||
|
class={cn(buttonStyles, 'w-full rounded-md')}
|
||||||
|
title="Copy as Svelte component"
|
||||||
|
disabled={isLoading}
|
||||||
|
on:click={() => copySvgComponent(false, 'Svelte')}
|
||||||
|
>
|
||||||
|
<SvelteIcon iconSize={18} />
|
||||||
|
<span>Copy JS</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class={cn(buttonStyles, 'w-full rounded-md')}
|
class={cn(buttonStyles, 'w-full rounded-md')}
|
||||||
title="Copy as Svelte component"
|
title="Copy as Svelte component"
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
on:click={() => copySvgComponent(false, 'Svelte')}
|
on:click={() => copySvgComponent(true, 'Svelte')}
|
||||||
>
|
>
|
||||||
<SvelteIcon iconSize={18} />
|
<SvelteIcon iconSize={18} />
|
||||||
<span>Copy JS</span>
|
<span>Copy TS</span>
|
||||||
</button>
|
</button>
|
||||||
|
</section>
|
||||||
<button
|
</Tabs.Content>
|
||||||
class={cn(buttonStyles, 'w-full rounded-md')}
|
<Tabs.Content value="vue">
|
||||||
title="Copy as Svelte component"
|
<section class="flex flex-col space-y-2">
|
||||||
disabled={isLoading}
|
<button
|
||||||
on:click={() => copySvgComponent(true, 'Svelte')}
|
class={cn(buttonStyles, 'w-full rounded-md')}
|
||||||
>
|
title="Copy as Vue component"
|
||||||
<SvelteIcon iconSize={18} />
|
disabled={isLoading}
|
||||||
<span>Copy TS</span>
|
on:click={() => copySvgComponent(false, 'Vue')}
|
||||||
</button>
|
>
|
||||||
|
<VueIcon iconSize={18} />
|
||||||
|
<span>Copy JS</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class={cn(buttonStyles, 'w-full rounded-md')}
|
||||||
|
title="Copy as Vue component"
|
||||||
|
disabled={isLoading}
|
||||||
|
on:click={() => copySvgComponent(true, 'Vue')}
|
||||||
|
>
|
||||||
|
<VueIcon iconSize={18} />
|
||||||
|
<span>Copy TS</span>
|
||||||
|
</button>
|
||||||
|
</section>
|
||||||
|
</Tabs.Content>
|
||||||
|
</Tabs.Root>
|
||||||
</Popover.Content>
|
</Popover.Content>
|
||||||
</Popover.Root>
|
</Popover.Root>
|
||||||
|
Loading…
Reference in New Issue
Block a user