forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBase.vue
More file actions
75 lines (70 loc) · 2.3 KB
/
Base.vue
File metadata and controls
75 lines (70 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<script setup lang="ts">
const props = withDefaults(
defineProps<{
'disabled'?: boolean
'type'?: 'button' | 'submit'
'variant'?: 'primary' | 'secondary'
'size'?: 'small' | 'medium'
'keyshortcut'?: string
/**
* Do not use this directly. Use keyshortcut instead; it generates the correct HTML and displays the shortcut in the UI.
*/
'aria-keyshortcuts'?: never
'classicon'?: string
}>(),
{
type: 'button',
variant: 'secondary',
size: 'medium',
},
)
const el = useTemplateRef('el')
defineExpose({
focus: () => el.value?.focus(),
getBoundingClientRect: () => el.value?.getBoundingClientRect(),
})
</script>
<template>
<button
ref="el"
class="rounded-md outline-none group"
:class="$attrs.class"
:type="props.type"
:disabled="
/**
* Unfortunately Vue _sometimes_ doesn't handle `disabled` correct,
* resulting in an invalid `disabled=false` attribute in the final HTML.
*
* This fixes this.
*/
disabled ? true : undefined
"
:aria-keyshortcuts="keyshortcut"
>
<span
class="group cursor-pointer inline-flex gap-x-1.5 relative items-center justify-center rounded-md hover:rounded-xl active:rounded-xl font-mono border border-solid transition-[background-color,color,border,outline] duration-200 transition-[border-radius_100ms] after:(content-[''] absolute inset--0.5 rounded-md) outline-transparent group-focus-visible:(outline-2 outline-accent outline-offset-2)"
:class="{
'text-sm px-4 py-2': size === 'medium',
'text-xs px-2 py-0.5': size === 'small',
'text-fg bg-transparent border-transparent hover:(bg-fg/10 border-fg/10)':
variant === 'secondary',
'text-bg bg-fg border-fg hover:(bg-fg/80)': variant === 'primary',
'opacity-40 cursor-not-allowed border-transparent': disabled,
}"
>
<span
v-if="classicon"
:class="[size === 'small' ? 'size-3' : 'size-4', classicon]"
aria-hidden="true"
/>
<slot />
<kbd
v-if="keyshortcut"
class="ms-2 inline-flex items-center justify-center w-4 h-4 text-xs text-fg bg-bg-muted border border-border rounded no-underline"
aria-hidden="true"
>
{{ keyshortcut }}
</kbd>
</span>
</button>
</template>