-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Davis SHYAKA <87414827+davis-shyaka@users.noreply.github.com>
- Loading branch information
1 parent
64514fe
commit dc5e273
Showing
8 changed files
with
173 additions
and
2 deletions.
There are no files selected for viewing
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,90 @@ | ||
import { browser } from '$app/environment'; | ||
import { type VariantProps, tv } from 'tailwind-variants'; | ||
|
||
export { default as Kbd } from './kbd.svelte'; | ||
|
||
export const kbd_variants = tv({ | ||
base: 'ml-1 inline-flex h-6 min-w-6 items-center justify-center gap-1 rounded bg-background-100 px-1.5 font-medium text-gray-1000 shadow-shadow-border', | ||
variants: { | ||
size: { | ||
sm: '[&>span]:text-xs', | ||
md: '[&>span]:text-sm' | ||
} | ||
}, | ||
defaultVariants: { | ||
size: 'md' | ||
} | ||
}); | ||
|
||
type Size = VariantProps<typeof kbd_variants>['size']; | ||
|
||
export function is_mac_os() { | ||
if (!browser) return false; | ||
return navigator.userAgent.includes('Macintosh'); | ||
} | ||
|
||
export const keys_map = { | ||
meta: is_mac_os() ? '⌘' : 'Ctrl', | ||
shift: is_mac_os() ? '⇧' : 'Shift', | ||
option: is_mac_os() ? '⌥' : 'Alt', | ||
control: is_mac_os() ? '⌃' : 'Ctrl', | ||
delete: is_mac_os() ? '⌫' : 'Del', | ||
return: is_mac_os() ? '⏎' : 'Enter', | ||
enter: is_mac_os() ? '⏎' : 'Enter', | ||
escape: is_mac_os() ? '⎋' : 'Esc', | ||
left: '←', | ||
up: '↑', | ||
right: '→', | ||
down: '↓', | ||
home: is_mac_os() ? '⇱' : 'Home', | ||
end: is_mac_os() ? '⇲' : 'End', | ||
pageup: is_mac_os() ? '⇞' : 'PgUp', | ||
pagedown: is_mac_os() ? '⇟' : 'PgDn', | ||
'[': '[', | ||
']': ']', | ||
tab: 'tab', | ||
a: 'a', | ||
b: 'b', | ||
c: 'c', | ||
d: 'd', | ||
e: 'e', | ||
f: 'f', | ||
g: 'g', | ||
h: 'h', | ||
i: 'i', | ||
j: 'j', | ||
k: 'k', | ||
l: 'l', | ||
m: 'm', | ||
n: 'n', | ||
o: 'o', | ||
p: 'p', | ||
q: 'q', | ||
r: 'r', | ||
s: 's', | ||
t: 't', | ||
u: 'u', | ||
v: 'v', | ||
w: 'w', | ||
x: 'x', | ||
y: 'y', | ||
z: 'z', | ||
0: '0', | ||
1: '1', | ||
2: '2', | ||
3: '3', | ||
4: '4', | ||
5: '5', | ||
6: '6', | ||
7: '7', | ||
8: '8', | ||
9: '9', | ||
space: is_mac_os() ? '␣' : 'Space', | ||
'/': '/', | ||
'\\': '\\' | ||
} as const; | ||
|
||
export type Props = { | ||
size?: Size; | ||
keys: (keyof typeof keys_map)[]; | ||
}; |
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,17 @@ | ||
<script lang="ts"> | ||
import { cn } from '$lib/utils.js'; | ||
import { type Props, kbd_variants, keys_map } from './index.js'; | ||
type $$Props = Props; | ||
let class_name: string | undefined | null = undefined; | ||
export let size: $$Props['size'] = 'md'; | ||
export let keys: (keyof typeof keys_map)[]; | ||
export { class_name as class }; | ||
</script> | ||
|
||
<kbd class={cn(kbd_variants({ size, className: class_name }))} {...$$restProps}> | ||
{#each keys as key, i} | ||
<span>{keys_map[key]}</span> | ||
{/each} | ||
</kbd> |
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,26 @@ | ||
<h1>keyboard-input</h1> | ||
<script lang="ts"> | ||
import Demo from '$lib/components/shared/demo.svelte'; | ||
import PageWrapper from '$lib/components/shared/page-wrapper.svelte'; | ||
import Combination from './combination.svelte'; | ||
import combination_code from './combination.svelte?raw'; | ||
import Modifiers from './modifiers.svelte'; | ||
import modifiers_code from './modifiers.svelte?raw'; | ||
import Small from './small.svelte'; | ||
import small_code from './small.svelte?raw'; | ||
export let data; | ||
</script> | ||
|
||
<PageWrapper title={data.title} description={data.description}> | ||
<Demo id="modifiers" code={modifiers_code}> | ||
<Modifiers /> | ||
</Demo> | ||
|
||
<Demo id="combination" code={combination_code}> | ||
<Combination /> | ||
</Demo> | ||
|
||
<Demo id="small" code={small_code}> | ||
<Small /> | ||
</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 = 'Keyboard Input'; | ||
const description = 'Display keyboard input that triggers an action.'; | ||
|
||
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,5 @@ | ||
<script lang="ts"> | ||
import { Kbd } from '$lib/components/ui/kbd'; | ||
</script> | ||
|
||
<Kbd keys={['meta', 'shift']} /> |
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,8 @@ | ||
<script lang="ts"> | ||
import { Kbd } from '$lib/components/ui/kbd'; | ||
</script> | ||
|
||
<Kbd keys={['meta']} /> | ||
<Kbd keys={['shift']} /> | ||
<Kbd keys={['option']} /> | ||
<Kbd keys={['control']} /> |
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 { Kbd } from '$lib/components/ui/kbd'; | ||
</script> | ||
|
||
<Kbd keys={['/']} size="sm" /> |