-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Done * update casing * format * Update snippet.svelte Prevent highlighting of $ * inverted, simplify, consistency, & tweaks * missed a few spots (due to the new hsl tokens) * thanks, @ieedan * mirror variants to the og --------- Co-authored-by: Davis SHYAKA <[email protected]>
- Loading branch information
1 parent
ccac8e8
commit 672f9fa
Showing
22 changed files
with
533 additions
and
315 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { tv, type VariantProps } from 'tailwind-variants'; | ||
import Snippet from './snippet.svelte'; | ||
|
||
export const snippet_variants = tv({ | ||
base: 'relative w-fit max-w-full rounded-md border bg-background-100 py-2.5 pl-3 pr-12', | ||
variants: { | ||
variant: { | ||
default: 'border-gray-alpha-400', | ||
success: 'bg-blue-100 text-blue-900', | ||
error: 'bg-red-100 text-red-900', | ||
warning: 'bg-amber-100 text-amber-900' | ||
} | ||
} | ||
}); | ||
|
||
export const copy_button_variants = tv({ | ||
base: 'absolute right-3 top-1/2 -translate-y-1/2 transition-opacity ease-in-out hover:text-opacity-80', | ||
variants: { | ||
variant: { | ||
default: 'text-gray-1000', | ||
success: 'text-blue-900', | ||
error: 'text-red-900', | ||
warning: 'text-amber-900' | ||
} | ||
} | ||
}); | ||
|
||
type Variant = VariantProps<typeof snippet_variants>['variant']; | ||
|
||
export type Props = { | ||
variant?: Variant; | ||
text: string | string[]; | ||
class?: string; | ||
prompt?: boolean; | ||
on_copy?: () => void; | ||
inverted?: boolean; | ||
}; | ||
|
||
export { Snippet }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<script lang="ts"> | ||
import { Icons } from '$lib/assets/icons'; | ||
import { cn } from '$lib/utils'; | ||
import { scale } from 'svelte/transition'; | ||
import { copy_button_variants, snippet_variants, type Props } from '.'; | ||
type $$Props = Props; | ||
export let text: $$Props['text']; | ||
export let prompt: $$Props['prompt'] = true; | ||
export let variant: $$Props['variant'] = 'default'; | ||
export let on_copy: $$Props['on_copy'] = undefined; | ||
export let inverted: $$Props['inverted'] = false; | ||
let class_name: $$Props['class'] = undefined; | ||
export { class_name as class }; | ||
let copied = false; | ||
async function copy_snippet() { | ||
if (typeof text == 'string') { | ||
await navigator.clipboard.writeText(text); | ||
} else { | ||
await navigator.clipboard.writeText(text.join('\n')); | ||
} | ||
copied = true; | ||
if (on_copy) { | ||
on_copy(); | ||
} | ||
setTimeout(() => (copied = false), 750); | ||
} | ||
</script> | ||
|
||
<div | ||
class={cn(snippet_variants({ variant, className: class_name }), { | ||
'bg-gray-1000 text-gray-100': inverted | ||
})} | ||
> | ||
{#if typeof text == 'string'} | ||
<pre | ||
class={cn('overflow-y-auto whitespace-nowrap text-left font-mono text-[13px] leading-5', { | ||
"before:content-['$']": prompt | ||
})}> | ||
{text} | ||
</pre> | ||
{:else} | ||
{#each text as line} | ||
<pre | ||
class={cn('overflow-y-auto whitespace-nowrap text-left font-mono text-[13px] leading-5', { | ||
"before:content-['$']": prompt | ||
})}> | ||
{line} | ||
</pre> | ||
{/each} | ||
{/if} | ||
|
||
<button | ||
on:click={copy_snippet} | ||
type="button" | ||
class={cn(copy_button_variants({ variant }), { | ||
'bg-gray-1000 text-gray-100': inverted | ||
})} | ||
> | ||
{#if copied} | ||
<div in:scale={{ start: 0.75, duration: 250 }}> | ||
<Icons.Check class="size-4" /> | ||
<span class="sr-only">Copied</span> | ||
</div> | ||
{:else} | ||
<div in:scale={{ start: 0.75, duration: 250 }}> | ||
<Icons.Copy class="size-4" /> | ||
<span class="sr-only">Copy</span> | ||
</div> | ||
{/if} | ||
</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,44 @@ | ||
<h1>snippet</h1> | ||
<script lang="ts"> | ||
import Demo from '$lib/components/shared/demo.svelte'; | ||
import PageWrapper from '$lib/components/shared/page-wrapper.svelte'; | ||
import Callback from './callback.svelte'; | ||
import callback_code from './callback.svelte?raw'; | ||
import Default from './default.svelte'; | ||
import default_code from './default.svelte?raw'; | ||
import Inverted from './inverted.svelte'; | ||
import inverted_code from './inverted.svelte?raw'; | ||
import Multiline from './multiline.svelte'; | ||
import multiline_code from './multiline.svelte?raw'; | ||
import NoPrompt from './no-prompt.svelte'; | ||
import no_prompt_code from './no-prompt.svelte?raw'; | ||
import Variants from './variants.svelte'; | ||
import variants_code from './variants.svelte?raw'; | ||
export let data; | ||
</script> | ||
|
||
<PageWrapper title={data.title} description={data.description}> | ||
<Demo id="default" code={default_code}> | ||
<Default /> | ||
</Demo> | ||
|
||
<Demo id="inverted" code={inverted_code}> | ||
<Inverted /> | ||
</Demo> | ||
|
||
<Demo id="multi-line" code={multiline_code}> | ||
<Multiline /> | ||
</Demo> | ||
|
||
<Demo id="no-prompt" code={no_prompt_code}> | ||
<NoPrompt /> | ||
</Demo> | ||
|
||
<Demo id="callback" code={callback_code}> | ||
<Callback /> | ||
</Demo> | ||
|
||
<Demo id="variants" code={variants_code}> | ||
<Variants /> | ||
</Demo> | ||
</PageWrapper> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { MetaTagsProps } from 'svelte-meta-tags'; | ||
|
||
export function load() { | ||
const title = 'Snippet'; | ||
const description = 'Display a snippet of copyable code for the command line.'; | ||
|
||
const pageMetaTags = Object.freeze({ | ||
title, | ||
description, | ||
openGraph: { | ||
title, | ||
description | ||
} | ||
}) satisfies MetaTagsProps; | ||
|
||
return { | ||
pageMetaTags, | ||
title, | ||
description | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script lang="ts"> | ||
import { Snippet } from '$lib/components/ui/snippet'; | ||
</script> | ||
|
||
<Snippet | ||
on_copy={() => alert('You copied the text!')} | ||
text="pnpm create svelte@latest" | ||
class="w-[300px]" | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script lang="ts"> | ||
import { Snippet } from '$lib/components/ui/snippet'; | ||
</script> | ||
|
||
<Snippet text="pnpm create svelte@latest" class="w-[300px]" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script lang="ts"> | ||
import { Snippet } from '$lib/components/ui/snippet'; | ||
</script> | ||
|
||
<Snippet inverted text="pnpm create svelte@latest" class="w-[300px]" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script lang="ts"> | ||
import { Snippet } from '$lib/components/ui/snippet'; | ||
</script> | ||
|
||
<Snippet text={['cd project', 'now']} class="w-full" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script lang="ts"> | ||
import { Snippet } from '$lib/components/ui/snippet'; | ||
</script> | ||
|
||
<Snippet prompt={false} text="pnpm create svelte@latest" class="w-[300px]" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script lang="ts"> | ||
import { Snippet } from '$lib/components/ui/snippet'; | ||
</script> | ||
|
||
<div class="grid gap-3"> | ||
<Snippet variant="success" text="pnpm create svelte@latest" class="w-[300px]" /> | ||
<Snippet variant="error" text="pnpm create svelte@latest" class="w-[300px]" /> | ||
<Snippet variant="warning" text="pnpm create svelte@latest" class="w-[300px]" /> | ||
</div> |
Oops, something went wrong.