@sabrenski/spire-ui 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +233 -0
- package/dist/index.d.ts +4981 -0
- package/dist/spire-ui.css +1 -0
- package/dist/spire-ui.es.js +18403 -0
- package/dist/spire-ui.umd.js +45 -0
- package/package.json +83 -0
- package/src/components/Accordion/Accordion.test.ts +218 -0
- package/src/components/Accordion/AccordionContent.vue +112 -0
- package/src/components/Accordion/AccordionItem.vue +87 -0
- package/src/components/Accordion/AccordionRoot.vue +111 -0
- package/src/components/Accordion/AccordionTrigger.vue +125 -0
- package/src/components/Accordion/index.ts +11 -0
- package/src/components/Accordion/keys.ts +23 -0
- package/src/components/Avatar/Avatar.test.ts +181 -0
- package/src/components/Avatar/Avatar.vue +150 -0
- package/src/components/Avatar/index.ts +2 -0
- package/src/components/Badge/Badge.test.ts +141 -0
- package/src/components/Badge/Badge.vue +133 -0
- package/src/components/Badge/index.ts +2 -0
- package/src/components/BadgeContainer/BadgeContainer.test.ts +150 -0
- package/src/components/BadgeContainer/BadgeContainer.vue +90 -0
- package/src/components/BadgeContainer/index.ts +2 -0
- package/src/components/Breadcrumb/Breadcrumb.test.ts +342 -0
- package/src/components/Breadcrumb/BreadcrumbEllipsis.vue +96 -0
- package/src/components/Breadcrumb/BreadcrumbItem.vue +16 -0
- package/src/components/Breadcrumb/BreadcrumbLink.vue +67 -0
- package/src/components/Breadcrumb/BreadcrumbList.vue +20 -0
- package/src/components/Breadcrumb/BreadcrumbPage.vue +25 -0
- package/src/components/Breadcrumb/BreadcrumbRoot.vue +41 -0
- package/src/components/Breadcrumb/BreadcrumbSeparator.vue +63 -0
- package/src/components/Breadcrumb/index.ts +13 -0
- package/src/components/Breadcrumb/keys.ts +7 -0
- package/src/components/Button/Button.test.ts +231 -0
- package/src/components/Button/Button.vue +349 -0
- package/src/components/Button/index.ts +2 -0
- package/src/components/Callout/Callout.test.ts +260 -0
- package/src/components/Callout/Callout.vue +341 -0
- package/src/components/Callout/index.ts +2 -0
- package/src/components/Card/Card.test.ts +565 -0
- package/src/components/Card/Card.vue +209 -0
- package/src/components/Card/CardContent.vue +57 -0
- package/src/components/Card/CardFooter.vue +72 -0
- package/src/components/Card/CardHeader.vue +111 -0
- package/src/components/Card/CardImage.vue +124 -0
- package/src/components/Card/index.ts +14 -0
- package/src/components/Chart/BarChart.vue +208 -0
- package/src/components/Chart/BaseChart.vue +444 -0
- package/src/components/Chart/Chart.test.ts +359 -0
- package/src/components/Chart/DonutChart.vue +283 -0
- package/src/components/Chart/LineChart.vue +211 -0
- package/src/components/Chart/index.ts +20 -0
- package/src/components/Chart/useChartTheme.ts +192 -0
- package/src/components/Checkbox/Checkbox.test.ts +209 -0
- package/src/components/Checkbox/Checkbox.vue +285 -0
- package/src/components/Checkbox/index.ts +2 -0
- package/src/components/ChoiceChip/ChoiceChip.test.ts +142 -0
- package/src/components/ChoiceChip/ChoiceChip.vue +218 -0
- package/src/components/ChoiceChip/index.ts +2 -0
- package/src/components/ChoiceChipGroup/ChoiceChipGroup.test.ts +151 -0
- package/src/components/ChoiceChipGroup/ChoiceChipGroup.vue +70 -0
- package/src/components/ChoiceChipGroup/index.ts +2 -0
- package/src/components/ColorPicker/ColorArea.vue +159 -0
- package/src/components/ColorPicker/ColorPicker.test.ts +250 -0
- package/src/components/ColorPicker/ColorPicker.vue +339 -0
- package/src/components/ColorPicker/ColorSlider.vue +191 -0
- package/src/components/ColorPicker/index.ts +7 -0
- package/src/components/Combobox/Combobox.test.ts +891 -0
- package/src/components/Combobox/Combobox.vue +934 -0
- package/src/components/Combobox/index.ts +2 -0
- package/src/components/DataTable/DataTable.test.ts +1221 -0
- package/src/components/DataTable/DataTable.vue +1415 -0
- package/src/components/DataTable/index.ts +10 -0
- package/src/components/DatePicker/DatePicker.test.ts +625 -0
- package/src/components/DatePicker/DatePicker.vue +1586 -0
- package/src/components/DatePicker/index.ts +2 -0
- package/src/components/Drawer/Drawer.test.ts +336 -0
- package/src/components/Drawer/Drawer.vue +466 -0
- package/src/components/Drawer/index.ts +2 -0
- package/src/components/Dropdown/Dropdown.test.ts +607 -0
- package/src/components/Dropdown/Dropdown.vue +807 -0
- package/src/components/Dropdown/DropdownItem.vue +227 -0
- package/src/components/Dropdown/DropdownSeparator.vue +14 -0
- package/src/components/Dropdown/DropdownSub.vue +104 -0
- package/src/components/Dropdown/DropdownSubContent.vue +187 -0
- package/src/components/Dropdown/DropdownSubTrigger.vue +151 -0
- package/src/components/Dropdown/index.ts +14 -0
- package/src/components/EmptyState/EmptyState.test.ts +180 -0
- package/src/components/EmptyState/EmptyState.vue +137 -0
- package/src/components/EmptyState/index.ts +2 -0
- package/src/components/FileUpload/FileUpload.test.ts +1151 -0
- package/src/components/FileUpload/FileUpload.vue +1042 -0
- package/src/components/FileUpload/index.ts +2 -0
- package/src/components/Heading/Heading.test.ts +107 -0
- package/src/components/Heading/Heading.vue +67 -0
- package/src/components/Heading/index.ts +2 -0
- package/src/components/Icon/Icon.test.ts +157 -0
- package/src/components/Icon/Icon.vue +86 -0
- package/src/components/Icon/index.ts +2 -0
- package/src/components/Input/Input.test.ts +273 -0
- package/src/components/Input/Input.vue +388 -0
- package/src/components/Input/index.ts +2 -0
- package/src/components/Layout/Container.vue +67 -0
- package/src/components/Layout/Grid.vue +159 -0
- package/src/components/Layout/GridItem.vue +154 -0
- package/src/components/Layout/Layout.test.ts +202 -0
- package/src/components/Layout/Stack.vue +128 -0
- package/src/components/Layout/index.ts +9 -0
- package/src/components/Layout/keys.ts +7 -0
- package/src/components/Modal/Modal.test.ts +311 -0
- package/src/components/Modal/Modal.vue +336 -0
- package/src/components/Modal/index.ts +2 -0
- package/src/components/Pagination/Pagination.test.ts +303 -0
- package/src/components/Pagination/Pagination.vue +212 -0
- package/src/components/Pagination/index.ts +3 -0
- package/src/components/Pagination/utils.ts +86 -0
- package/src/components/Popover/Popover.test.ts +285 -0
- package/src/components/Popover/Popover.vue +441 -0
- package/src/components/Popover/index.ts +2 -0
- package/src/components/Progress/Progress.test.ts +361 -0
- package/src/components/Progress/Progress.vue +363 -0
- package/src/components/Progress/index.ts +7 -0
- package/src/components/Radio/Radio.test.ts +216 -0
- package/src/components/Radio/Radio.vue +214 -0
- package/src/components/Radio/index.ts +2 -0
- package/src/components/Rating/Rating.test.ts +319 -0
- package/src/components/Rating/Rating.vue +247 -0
- package/src/components/Rating/index.ts +2 -0
- package/src/components/SegmentedControl/SegmentedControl.test.ts +292 -0
- package/src/components/SegmentedControl/SegmentedControl.vue +288 -0
- package/src/components/SegmentedControl/index.ts +2 -0
- package/src/components/Select/Select.test.ts +589 -0
- package/src/components/Select/Select.vue +666 -0
- package/src/components/Select/index.ts +2 -0
- package/src/components/Sidebar/Sidebar.test.ts +301 -0
- package/src/components/Sidebar/SidebarGroup.vue +103 -0
- package/src/components/Sidebar/SidebarItem.vue +196 -0
- package/src/components/Sidebar/SidebarLayout.vue +42 -0
- package/src/components/Sidebar/SidebarRoot.vue +122 -0
- package/src/components/Sidebar/index.ts +11 -0
- package/src/components/Sidebar/keys.ts +14 -0
- package/src/components/Skeleton/Skeleton.test.ts +130 -0
- package/src/components/Skeleton/Skeleton.vue +104 -0
- package/src/components/Skeleton/index.ts +2 -0
- package/src/components/Slider/Slider.test.ts +416 -0
- package/src/components/Slider/Slider.vue +435 -0
- package/src/components/Slider/index.ts +2 -0
- package/src/components/Slider/utils.ts +91 -0
- package/src/components/Spinner/Spinner.test.ts +79 -0
- package/src/components/Spinner/Spinner.vue +159 -0
- package/src/components/Spinner/index.ts +2 -0
- package/src/components/SpireProvider/SpireProvider.vue +71 -0
- package/src/components/SpireProvider/index.ts +11 -0
- package/src/components/Stepper/Stepper.test.ts +221 -0
- package/src/components/Stepper/StepperContent.vue +51 -0
- package/src/components/Stepper/StepperItem.vue +89 -0
- package/src/components/Stepper/StepperRoot.vue +101 -0
- package/src/components/Stepper/StepperSeparator.vue +52 -0
- package/src/components/Stepper/StepperTrigger.vue +144 -0
- package/src/components/Stepper/index.ts +11 -0
- package/src/components/Stepper/keys.ts +27 -0
- package/src/components/Switch/Switch.test.ts +214 -0
- package/src/components/Switch/Switch.vue +235 -0
- package/src/components/Switch/index.ts +2 -0
- package/src/components/Tabs/Tabs.test.ts +363 -0
- package/src/components/Tabs/Tabs.vue +318 -0
- package/src/components/Tabs/index.ts +2 -0
- package/src/components/Text/Text.test.ts +154 -0
- package/src/components/Text/Text.vue +100 -0
- package/src/components/Text/index.ts +2 -0
- package/src/components/Textarea/Textarea.test.ts +432 -0
- package/src/components/Textarea/Textarea.vue +411 -0
- package/src/components/Textarea/index.ts +2 -0
- package/src/components/TimePicker/TimePicker.test.ts +352 -0
- package/src/components/TimePicker/TimePicker.vue +569 -0
- package/src/components/TimePicker/index.ts +2 -0
- package/src/components/Timeline/Timeline.test.ts +193 -0
- package/src/components/Timeline/Timeline.vue +111 -0
- package/src/components/Timeline/TimelineItem.vue +167 -0
- package/src/components/Timeline/index.ts +13 -0
- package/src/components/Timeline/keys.ts +21 -0
- package/src/components/Toast/ToastItem.test.ts +289 -0
- package/src/components/Toast/ToastItem.vue +370 -0
- package/src/components/Toast/ToastProvider.test.ts +158 -0
- package/src/components/Toast/ToastProvider.vue +181 -0
- package/src/components/Toast/index.ts +83 -0
- package/src/components/Toast/toastState.test.ts +165 -0
- package/src/components/Toast/toastState.ts +161 -0
- package/src/components/ToggleButton/ToggleButton.test.ts +166 -0
- package/src/components/ToggleButton/ToggleButton.vue +197 -0
- package/src/components/ToggleButton/index.ts +2 -0
- package/src/components/ToggleGroup/ToggleGroup.test.ts +181 -0
- package/src/components/ToggleGroup/ToggleGroup.vue +130 -0
- package/src/components/ToggleGroup/index.ts +2 -0
- package/src/components/Tooltip/Tooltip.test.ts +238 -0
- package/src/components/Tooltip/Tooltip.vue +217 -0
- package/src/components/Tooltip/index.ts +2 -0
- package/src/components/TreeView/TreeView.test.ts +357 -0
- package/src/components/TreeView/TreeView.vue +251 -0
- package/src/components/TreeView/TreeViewItem.vue +288 -0
- package/src/components/TreeView/index.ts +11 -0
- package/src/components/TreeView/keys.ts +35 -0
- package/src/composables/index.ts +12 -0
- package/src/composables/useClickOutside.ts +36 -0
- package/src/composables/useClipboard.ts +35 -0
- package/src/composables/useEventListener.ts +48 -0
- package/src/composables/useFocusTrap.ts +58 -0
- package/src/composables/useHoverReveal.ts +98 -0
- package/src/composables/useId.ts +10 -0
- package/src/composables/useMagnetic.ts +171 -0
- package/src/composables/useRelativePosition.ts +127 -0
- package/src/composables/useRipple.ts +146 -0
- package/src/composables/useScrollLock.ts +25 -0
- package/src/composables/useSpireConfig.ts +27 -0
- package/src/composables/useStagger.ts +224 -0
- package/src/config/icons.test.ts +115 -0
- package/src/config/icons.ts +170 -0
- package/src/index.ts +361 -0
- package/src/styles/depth.css +129 -0
- package/src/styles/effects.css +169 -0
- package/src/styles/fallback.css +152 -0
- package/src/styles/main.css +25 -0
- package/src/styles/mood.css +211 -0
- package/src/styles/motion.css +159 -0
- package/src/styles/reset.css +97 -0
- package/src/styles/theme.css +708 -0
- package/src/styles/tokens.css +183 -0
- package/src/utils/.gitkeep +0 -0
- package/src/utils/color.ts +277 -0
- package/src/utils/date.test.ts +522 -0
- package/src/utils/date.ts +380 -0
- package/src/utils/index.ts +23 -0
- package/src/utils/object.test.ts +80 -0
- package/src/utils/object.ts +25 -0
- package/src/utils/string.test.ts +64 -0
- package/src/utils/string.ts +32 -0
- package/src/utils/time.ts +156 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
ref,
|
|
4
|
+
computed,
|
|
5
|
+
inject,
|
|
6
|
+
onMounted,
|
|
7
|
+
onUnmounted,
|
|
8
|
+
type Component
|
|
9
|
+
} from 'vue'
|
|
10
|
+
import { dropdownContextKey, type DropdownContext } from './Dropdown.vue'
|
|
11
|
+
|
|
12
|
+
export interface DropdownItemProps {
|
|
13
|
+
/** Renders as RouterLink when provided */
|
|
14
|
+
to?: string | Record<string, unknown>
|
|
15
|
+
/** Renders as anchor when provided */
|
|
16
|
+
href?: string
|
|
17
|
+
/** Disabled state */
|
|
18
|
+
disabled?: boolean
|
|
19
|
+
/** Danger/destructive styling */
|
|
20
|
+
danger?: boolean
|
|
21
|
+
/** Leading icon */
|
|
22
|
+
icon?: Component
|
|
23
|
+
/** Keyboard shortcut hint */
|
|
24
|
+
shortcut?: string
|
|
25
|
+
/** Prevent menu from closing on click */
|
|
26
|
+
preventClose?: boolean
|
|
27
|
+
/** Show chevron indicator (for submenu triggers) */
|
|
28
|
+
chevron?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const props = withDefaults(defineProps<DropdownItemProps>(), {
|
|
32
|
+
disabled: false,
|
|
33
|
+
danger: false,
|
|
34
|
+
preventClose: false,
|
|
35
|
+
chevron: false
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const emit = defineEmits<{
|
|
39
|
+
click: [event: MouseEvent | KeyboardEvent]
|
|
40
|
+
}>()
|
|
41
|
+
|
|
42
|
+
const context = inject(dropdownContextKey)
|
|
43
|
+
const itemRef = ref<HTMLElement | null>(null)
|
|
44
|
+
|
|
45
|
+
const componentType = computed(() => {
|
|
46
|
+
if (props.to) return 'router-link'
|
|
47
|
+
if (props.href) return 'a'
|
|
48
|
+
return 'button'
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const componentProps = computed(() => {
|
|
52
|
+
const base: Record<string, unknown> = {
|
|
53
|
+
class: [
|
|
54
|
+
'ui-dropdown-item',
|
|
55
|
+
{
|
|
56
|
+
'ui-dropdown-item--disabled': props.disabled,
|
|
57
|
+
'ui-dropdown-item--danger': props.danger
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
role: 'menuitem',
|
|
61
|
+
tabindex: props.disabled ? -1 : 0
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (props.disabled) {
|
|
65
|
+
base['aria-disabled'] = 'true'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (componentType.value === 'router-link') {
|
|
69
|
+
base.to = props.to
|
|
70
|
+
} else if (componentType.value === 'a') {
|
|
71
|
+
base.href = props.href
|
|
72
|
+
base.target = '_blank'
|
|
73
|
+
base.rel = 'noopener noreferrer'
|
|
74
|
+
} else {
|
|
75
|
+
base.type = 'button'
|
|
76
|
+
base.disabled = props.disabled
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return base
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
function handleClick(event: MouseEvent) {
|
|
83
|
+
if (props.disabled) {
|
|
84
|
+
event.preventDefault()
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
emit('click', event)
|
|
89
|
+
|
|
90
|
+
if (!props.preventClose) {
|
|
91
|
+
context?.close()
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function handleKeydown(event: KeyboardEvent) {
|
|
96
|
+
if (props.disabled) return
|
|
97
|
+
|
|
98
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
99
|
+
event.preventDefault()
|
|
100
|
+
emit('click', event)
|
|
101
|
+
|
|
102
|
+
if (!props.preventClose) {
|
|
103
|
+
context?.close()
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
onMounted(() => {
|
|
109
|
+
if (itemRef.value) {
|
|
110
|
+
context?.registerItem(itemRef.value)
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
onUnmounted(() => {
|
|
115
|
+
if (itemRef.value) {
|
|
116
|
+
context?.unregisterItem(itemRef.value)
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
</script>
|
|
120
|
+
|
|
121
|
+
<template>
|
|
122
|
+
<component
|
|
123
|
+
:is="componentType"
|
|
124
|
+
ref="itemRef"
|
|
125
|
+
v-bind="componentProps"
|
|
126
|
+
@click="handleClick"
|
|
127
|
+
@keydown="handleKeydown"
|
|
128
|
+
>
|
|
129
|
+
<span v-if="icon" class="ui-dropdown-item__icon">
|
|
130
|
+
<component :is="icon" />
|
|
131
|
+
</span>
|
|
132
|
+
<span class="ui-dropdown-item__content">
|
|
133
|
+
<slot />
|
|
134
|
+
</span>
|
|
135
|
+
<span v-if="shortcut" class="ui-dropdown-item__shortcut">
|
|
136
|
+
{{ shortcut }}
|
|
137
|
+
</span>
|
|
138
|
+
<span v-if="chevron" class="ui-dropdown-item__chevron">
|
|
139
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
140
|
+
<path d="M9 18l6-6-6-6" />
|
|
141
|
+
</svg>
|
|
142
|
+
</span>
|
|
143
|
+
</component>
|
|
144
|
+
</template>
|
|
145
|
+
|
|
146
|
+
<style scoped>
|
|
147
|
+
.ui-dropdown-item {
|
|
148
|
+
display: flex;
|
|
149
|
+
align-items: center;
|
|
150
|
+
gap: var(--space-2);
|
|
151
|
+
width: 100%;
|
|
152
|
+
padding: var(--space-2) var(--space-2);
|
|
153
|
+
font-family: var(--font-sans);
|
|
154
|
+
font-size: var(--text-sm);
|
|
155
|
+
line-height: var(--leading-normal);
|
|
156
|
+
color: var(--dropdown-item-text);
|
|
157
|
+
background: transparent;
|
|
158
|
+
border: none;
|
|
159
|
+
border-radius: var(--radius-md);
|
|
160
|
+
cursor: pointer;
|
|
161
|
+
text-align: left;
|
|
162
|
+
text-decoration: none;
|
|
163
|
+
outline: none;
|
|
164
|
+
transition: background-color var(--duration-fast) var(--ease-default),
|
|
165
|
+
color var(--duration-fast) var(--ease-default);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.ui-dropdown-item:hover:not(.ui-dropdown-item--disabled),
|
|
169
|
+
.ui-dropdown-item:focus:not(.ui-dropdown-item--disabled) {
|
|
170
|
+
background-color: var(--dropdown-item-hover);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.ui-dropdown-item:focus-visible {
|
|
174
|
+
outline: 2px solid var(--focus-ring);
|
|
175
|
+
outline-offset: -2px;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.ui-dropdown-item--disabled {
|
|
179
|
+
color: var(--dropdown-item-disabled);
|
|
180
|
+
cursor: not-allowed;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.ui-dropdown-item--danger {
|
|
184
|
+
color: var(--dropdown-item-danger);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.ui-dropdown-item--danger:hover:not(.ui-dropdown-item--disabled),
|
|
188
|
+
.ui-dropdown-item--danger:focus:not(.ui-dropdown-item--disabled) {
|
|
189
|
+
background-color: var(--dropdown-item-danger-hover);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.ui-dropdown-item__icon {
|
|
193
|
+
display: flex;
|
|
194
|
+
align-items: center;
|
|
195
|
+
justify-content: center;
|
|
196
|
+
width: 16px;
|
|
197
|
+
height: 16px;
|
|
198
|
+
flex-shrink: 0;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.ui-dropdown-item__icon > :deep(svg) {
|
|
202
|
+
width: 100%;
|
|
203
|
+
height: 100%;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.ui-dropdown-item__content {
|
|
207
|
+
flex: 1;
|
|
208
|
+
min-width: 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.ui-dropdown-item__shortcut {
|
|
212
|
+
margin-left: auto;
|
|
213
|
+
padding-left: var(--space-4);
|
|
214
|
+
font-size: var(--text-xs);
|
|
215
|
+
color: var(--dropdown-item-shortcut);
|
|
216
|
+
flex-shrink: 0;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.ui-dropdown-item__chevron {
|
|
220
|
+
display: flex;
|
|
221
|
+
align-items: center;
|
|
222
|
+
justify-content: center;
|
|
223
|
+
margin-left: auto;
|
|
224
|
+
color: var(--dropdown-item-shortcut);
|
|
225
|
+
flex-shrink: 0;
|
|
226
|
+
}
|
|
227
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
</script>
|
|
3
|
+
|
|
4
|
+
<template>
|
|
5
|
+
<div class="ui-dropdown-separator" role="separator" />
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<style scoped>
|
|
9
|
+
.ui-dropdown-separator {
|
|
10
|
+
height: 1px;
|
|
11
|
+
margin: 2px 0;
|
|
12
|
+
background-color: var(--dropdown-separator);
|
|
13
|
+
}
|
|
14
|
+
</style>
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { InjectionKey } from 'vue'
|
|
3
|
+
|
|
4
|
+
export interface DropdownSubContext {
|
|
5
|
+
isOpen: { value: boolean }
|
|
6
|
+
triggerRef: { value: HTMLElement | null }
|
|
7
|
+
open: () => void
|
|
8
|
+
close: () => void
|
|
9
|
+
onTriggerKeydown: (e: KeyboardEvent) => void
|
|
10
|
+
scheduleClose: () => void
|
|
11
|
+
cancelClose: () => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const dropdownSubContextKey: InjectionKey<DropdownSubContext> = Symbol('dropdownSub')
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script setup lang="ts">
|
|
18
|
+
import { ref, provide, inject } from 'vue'
|
|
19
|
+
import { dropdownContextKey } from './Dropdown.vue'
|
|
20
|
+
|
|
21
|
+
const parentContext = inject(dropdownContextKey)
|
|
22
|
+
|
|
23
|
+
const isOpen = ref(false)
|
|
24
|
+
const triggerRef = ref<HTMLElement | null>(null)
|
|
25
|
+
const contentRef = ref<HTMLElement | null>(null)
|
|
26
|
+
|
|
27
|
+
let closeTimeout: ReturnType<typeof setTimeout> | null = null
|
|
28
|
+
|
|
29
|
+
function open() {
|
|
30
|
+
if (closeTimeout) {
|
|
31
|
+
clearTimeout(closeTimeout)
|
|
32
|
+
closeTimeout = null
|
|
33
|
+
}
|
|
34
|
+
isOpen.value = true
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function close() {
|
|
38
|
+
isOpen.value = false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function scheduleClose() {
|
|
42
|
+
if (closeTimeout) clearTimeout(closeTimeout)
|
|
43
|
+
closeTimeout = setTimeout(() => {
|
|
44
|
+
close()
|
|
45
|
+
}, 150)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function cancelClose() {
|
|
49
|
+
if (closeTimeout) {
|
|
50
|
+
clearTimeout(closeTimeout)
|
|
51
|
+
closeTimeout = null
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function onTriggerKeydown(e: KeyboardEvent) {
|
|
56
|
+
if (e.key === 'ArrowRight' || e.key === 'Enter') {
|
|
57
|
+
e.preventDefault()
|
|
58
|
+
e.stopPropagation()
|
|
59
|
+
open()
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function onContentKeydown(e: KeyboardEvent) {
|
|
64
|
+
if (e.key === 'ArrowLeft') {
|
|
65
|
+
e.preventDefault()
|
|
66
|
+
e.stopPropagation()
|
|
67
|
+
close()
|
|
68
|
+
triggerRef.value?.focus()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
provide(dropdownSubContextKey, {
|
|
73
|
+
isOpen,
|
|
74
|
+
triggerRef,
|
|
75
|
+
open,
|
|
76
|
+
close,
|
|
77
|
+
onTriggerKeydown,
|
|
78
|
+
scheduleClose,
|
|
79
|
+
cancelClose
|
|
80
|
+
} as DropdownSubContext)
|
|
81
|
+
|
|
82
|
+
defineExpose({
|
|
83
|
+
isOpen,
|
|
84
|
+
triggerRef,
|
|
85
|
+
contentRef,
|
|
86
|
+
open,
|
|
87
|
+
close,
|
|
88
|
+
scheduleClose,
|
|
89
|
+
cancelClose,
|
|
90
|
+
onContentKeydown
|
|
91
|
+
})
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<template>
|
|
95
|
+
<div class="ui-dropdown-sub">
|
|
96
|
+
<slot />
|
|
97
|
+
</div>
|
|
98
|
+
</template>
|
|
99
|
+
|
|
100
|
+
<style scoped>
|
|
101
|
+
.ui-dropdown-sub {
|
|
102
|
+
position: relative;
|
|
103
|
+
}
|
|
104
|
+
</style>
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
ref,
|
|
4
|
+
computed,
|
|
5
|
+
watch,
|
|
6
|
+
inject,
|
|
7
|
+
nextTick,
|
|
8
|
+
onMounted,
|
|
9
|
+
onUnmounted
|
|
10
|
+
} from 'vue'
|
|
11
|
+
import { dropdownSubContextKey } from './DropdownSub.vue'
|
|
12
|
+
|
|
13
|
+
const subContext = inject(dropdownSubContextKey)
|
|
14
|
+
|
|
15
|
+
const menuRef = ref<HTMLElement | null>(null)
|
|
16
|
+
const positionStyle = ref<{ top: string; left: string }>({ top: '0', left: '0' })
|
|
17
|
+
|
|
18
|
+
function handleMouseEnter() {
|
|
19
|
+
subContext?.cancelClose()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function handleMouseLeave() {
|
|
23
|
+
subContext?.scheduleClose()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getFocusableItems(): HTMLElement[] {
|
|
27
|
+
if (!menuRef.value) return []
|
|
28
|
+
return Array.from(
|
|
29
|
+
menuRef.value.querySelectorAll<HTMLElement>(
|
|
30
|
+
'button:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])'
|
|
31
|
+
)
|
|
32
|
+
).filter(el => el.getAttribute('aria-disabled') !== 'true')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function focusItem(index: number) {
|
|
36
|
+
const items = getFocusableItems()
|
|
37
|
+
if (items.length === 0) return
|
|
38
|
+
|
|
39
|
+
if (index < 0) index = items.length - 1
|
|
40
|
+
if (index >= items.length) index = 0
|
|
41
|
+
|
|
42
|
+
items[index].focus()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function handleKeydown(e: KeyboardEvent) {
|
|
46
|
+
const items = getFocusableItems()
|
|
47
|
+
const currentIndex = items.findIndex(el => el === document.activeElement)
|
|
48
|
+
|
|
49
|
+
switch (e.key) {
|
|
50
|
+
case 'ArrowDown':
|
|
51
|
+
e.preventDefault()
|
|
52
|
+
e.stopPropagation()
|
|
53
|
+
focusItem(currentIndex + 1)
|
|
54
|
+
break
|
|
55
|
+
case 'ArrowUp':
|
|
56
|
+
e.preventDefault()
|
|
57
|
+
e.stopPropagation()
|
|
58
|
+
focusItem(currentIndex - 1)
|
|
59
|
+
break
|
|
60
|
+
case 'Home':
|
|
61
|
+
e.preventDefault()
|
|
62
|
+
e.stopPropagation()
|
|
63
|
+
focusItem(0)
|
|
64
|
+
break
|
|
65
|
+
case 'End':
|
|
66
|
+
e.preventDefault()
|
|
67
|
+
e.stopPropagation()
|
|
68
|
+
focusItem(items.length - 1)
|
|
69
|
+
break
|
|
70
|
+
case 'ArrowLeft':
|
|
71
|
+
case 'Escape':
|
|
72
|
+
e.preventDefault()
|
|
73
|
+
e.stopPropagation()
|
|
74
|
+
subContext?.close()
|
|
75
|
+
subContext?.triggerRef.value?.focus()
|
|
76
|
+
break
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function updatePosition() {
|
|
81
|
+
const trigger = subContext?.triggerRef.value
|
|
82
|
+
const menu = menuRef.value
|
|
83
|
+
if (!trigger || !menu) return
|
|
84
|
+
|
|
85
|
+
const triggerRect = trigger.getBoundingClientRect()
|
|
86
|
+
const menuRect = menu.getBoundingClientRect()
|
|
87
|
+
const viewport = { width: window.innerWidth, height: window.innerHeight }
|
|
88
|
+
const gap = 4
|
|
89
|
+
|
|
90
|
+
let top = triggerRect.top
|
|
91
|
+
let left = triggerRect.right + gap
|
|
92
|
+
|
|
93
|
+
// Flip to left if no space on right
|
|
94
|
+
if (left + menuRect.width > viewport.width - 8) {
|
|
95
|
+
left = triggerRect.left - menuRect.width - gap
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Clamp vertical position
|
|
99
|
+
if (top + menuRect.height > viewport.height - 8) {
|
|
100
|
+
top = viewport.height - menuRect.height - 8
|
|
101
|
+
}
|
|
102
|
+
top = Math.max(8, top)
|
|
103
|
+
|
|
104
|
+
// Clamp horizontal position
|
|
105
|
+
left = Math.max(8, Math.min(left, viewport.width - menuRect.width - 8))
|
|
106
|
+
|
|
107
|
+
positionStyle.value = {
|
|
108
|
+
top: `${top}px`,
|
|
109
|
+
left: `${left}px`
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
watch(() => subContext?.isOpen.value, async (isOpen) => {
|
|
114
|
+
if (isOpen) {
|
|
115
|
+
await nextTick()
|
|
116
|
+
updatePosition()
|
|
117
|
+
// Focus first item
|
|
118
|
+
const firstItem = menuRef.value?.querySelector<HTMLElement>(
|
|
119
|
+
'button:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])'
|
|
120
|
+
)
|
|
121
|
+
firstItem?.focus()
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
onMounted(() => {
|
|
126
|
+
window.addEventListener('resize', updatePosition)
|
|
127
|
+
window.addEventListener('scroll', updatePosition, true)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
onUnmounted(() => {
|
|
131
|
+
window.removeEventListener('resize', updatePosition)
|
|
132
|
+
window.removeEventListener('scroll', updatePosition, true)
|
|
133
|
+
})
|
|
134
|
+
</script>
|
|
135
|
+
|
|
136
|
+
<template>
|
|
137
|
+
<Teleport to="body">
|
|
138
|
+
<Transition name="ui-dropdown-sub">
|
|
139
|
+
<div
|
|
140
|
+
v-if="subContext?.isOpen.value"
|
|
141
|
+
ref="menuRef"
|
|
142
|
+
class="ui-dropdown-sub-content"
|
|
143
|
+
role="menu"
|
|
144
|
+
:style="positionStyle"
|
|
145
|
+
@mouseenter="handleMouseEnter"
|
|
146
|
+
@mouseleave="handleMouseLeave"
|
|
147
|
+
@keydown="handleKeydown"
|
|
148
|
+
>
|
|
149
|
+
<slot />
|
|
150
|
+
</div>
|
|
151
|
+
</Transition>
|
|
152
|
+
</Teleport>
|
|
153
|
+
</template>
|
|
154
|
+
|
|
155
|
+
<style scoped>
|
|
156
|
+
.ui-dropdown-sub-content {
|
|
157
|
+
position: fixed;
|
|
158
|
+
z-index: calc(var(--z-dropdown, 50) + 1);
|
|
159
|
+
min-width: 160px;
|
|
160
|
+
padding: var(--space-1);
|
|
161
|
+
background: var(--dropdown-bg);
|
|
162
|
+
border: 1px solid var(--dropdown-border);
|
|
163
|
+
border-radius: var(--radius-lg);
|
|
164
|
+
box-shadow: var(--shadow-lg);
|
|
165
|
+
outline: none;
|
|
166
|
+
font-family: var(--font-sans);
|
|
167
|
+
display: flex;
|
|
168
|
+
flex-direction: column;
|
|
169
|
+
gap: 2px;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.ui-dropdown-sub-enter-active {
|
|
173
|
+
transition: opacity var(--duration-fast) var(--ease-default),
|
|
174
|
+
transform var(--duration-fast) var(--ease-default);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.ui-dropdown-sub-leave-active {
|
|
178
|
+
transition: opacity var(--duration-fast) var(--ease-default),
|
|
179
|
+
transform var(--duration-fast) var(--ease-default);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.ui-dropdown-sub-enter-from,
|
|
183
|
+
.ui-dropdown-sub-leave-to {
|
|
184
|
+
opacity: 0;
|
|
185
|
+
transform: translateX(-4px);
|
|
186
|
+
}
|
|
187
|
+
</style>
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
ref,
|
|
4
|
+
inject,
|
|
5
|
+
onMounted,
|
|
6
|
+
onUnmounted,
|
|
7
|
+
type Component
|
|
8
|
+
} from 'vue'
|
|
9
|
+
import { dropdownContextKey } from './Dropdown.vue'
|
|
10
|
+
import { dropdownSubContextKey } from './DropdownSub.vue'
|
|
11
|
+
|
|
12
|
+
export interface DropdownSubTriggerProps {
|
|
13
|
+
/** Disabled state */
|
|
14
|
+
disabled?: boolean
|
|
15
|
+
/** Leading icon */
|
|
16
|
+
icon?: Component
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const props = withDefaults(defineProps<DropdownSubTriggerProps>(), {
|
|
20
|
+
disabled: false
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const parentContext = inject(dropdownContextKey)
|
|
24
|
+
const subContext = inject(dropdownSubContextKey)
|
|
25
|
+
const triggerRef = ref<HTMLElement | null>(null)
|
|
26
|
+
|
|
27
|
+
function handleMouseEnter() {
|
|
28
|
+
if (props.disabled) return
|
|
29
|
+
subContext?.cancelClose()
|
|
30
|
+
subContext?.open()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function handleMouseLeave() {
|
|
34
|
+
if (props.disabled) return
|
|
35
|
+
subContext?.scheduleClose()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function handleKeydown(e: KeyboardEvent) {
|
|
39
|
+
if (props.disabled) return
|
|
40
|
+
subContext?.onTriggerKeydown(e)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
onMounted(() => {
|
|
44
|
+
if (triggerRef.value) {
|
|
45
|
+
parentContext?.registerItem(triggerRef.value)
|
|
46
|
+
if (subContext) {
|
|
47
|
+
subContext.triggerRef.value = triggerRef.value
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
onUnmounted(() => {
|
|
53
|
+
if (triggerRef.value) {
|
|
54
|
+
parentContext?.unregisterItem(triggerRef.value)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<template>
|
|
60
|
+
<button
|
|
61
|
+
ref="triggerRef"
|
|
62
|
+
type="button"
|
|
63
|
+
class="ui-dropdown-sub-trigger"
|
|
64
|
+
:class="{ 'ui-dropdown-sub-trigger--disabled': disabled }"
|
|
65
|
+
role="menuitem"
|
|
66
|
+
:aria-haspopup="true"
|
|
67
|
+
:aria-expanded="subContext?.isOpen.value"
|
|
68
|
+
:aria-disabled="disabled || undefined"
|
|
69
|
+
:tabindex="disabled ? -1 : 0"
|
|
70
|
+
:disabled="disabled"
|
|
71
|
+
@mouseenter="handleMouseEnter"
|
|
72
|
+
@mouseleave="handleMouseLeave"
|
|
73
|
+
@keydown="handleKeydown"
|
|
74
|
+
>
|
|
75
|
+
<span v-if="icon" class="ui-dropdown-sub-trigger__icon">
|
|
76
|
+
<component :is="icon" />
|
|
77
|
+
</span>
|
|
78
|
+
<span class="ui-dropdown-sub-trigger__content">
|
|
79
|
+
<slot />
|
|
80
|
+
</span>
|
|
81
|
+
<span class="ui-dropdown-sub-trigger__chevron">
|
|
82
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
83
|
+
<path d="M9 18l6-6-6-6" />
|
|
84
|
+
</svg>
|
|
85
|
+
</span>
|
|
86
|
+
</button>
|
|
87
|
+
</template>
|
|
88
|
+
|
|
89
|
+
<style scoped>
|
|
90
|
+
.ui-dropdown-sub-trigger {
|
|
91
|
+
display: flex;
|
|
92
|
+
align-items: center;
|
|
93
|
+
gap: var(--space-2);
|
|
94
|
+
width: 100%;
|
|
95
|
+
padding: var(--space-2) var(--space-2);
|
|
96
|
+
font-family: var(--font-sans);
|
|
97
|
+
font-size: var(--text-sm);
|
|
98
|
+
line-height: var(--leading-normal);
|
|
99
|
+
color: var(--dropdown-item-text);
|
|
100
|
+
background: transparent;
|
|
101
|
+
border: none;
|
|
102
|
+
border-radius: var(--radius-md);
|
|
103
|
+
cursor: pointer;
|
|
104
|
+
text-align: left;
|
|
105
|
+
outline: none;
|
|
106
|
+
transition: background-color var(--duration-fast) var(--ease-default);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.ui-dropdown-sub-trigger:hover:not(.ui-dropdown-sub-trigger--disabled),
|
|
110
|
+
.ui-dropdown-sub-trigger:focus:not(.ui-dropdown-sub-trigger--disabled) {
|
|
111
|
+
background-color: var(--dropdown-item-hover);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.ui-dropdown-sub-trigger:focus-visible {
|
|
115
|
+
outline: 2px solid var(--focus-ring);
|
|
116
|
+
outline-offset: -2px;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.ui-dropdown-sub-trigger--disabled {
|
|
120
|
+
color: var(--dropdown-item-disabled);
|
|
121
|
+
cursor: not-allowed;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.ui-dropdown-sub-trigger__icon {
|
|
125
|
+
display: flex;
|
|
126
|
+
align-items: center;
|
|
127
|
+
justify-content: center;
|
|
128
|
+
width: 16px;
|
|
129
|
+
height: 16px;
|
|
130
|
+
flex-shrink: 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.ui-dropdown-sub-trigger__icon > :deep(svg) {
|
|
134
|
+
width: 100%;
|
|
135
|
+
height: 100%;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.ui-dropdown-sub-trigger__content {
|
|
139
|
+
flex: 1;
|
|
140
|
+
min-width: 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.ui-dropdown-sub-trigger__chevron {
|
|
144
|
+
display: flex;
|
|
145
|
+
align-items: center;
|
|
146
|
+
justify-content: center;
|
|
147
|
+
margin-left: auto;
|
|
148
|
+
color: var(--dropdown-item-shortcut);
|
|
149
|
+
flex-shrink: 0;
|
|
150
|
+
}
|
|
151
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { default as Dropdown } from './Dropdown.vue'
|
|
2
|
+
export { default as DropdownItem } from './DropdownItem.vue'
|
|
3
|
+
export { default as DropdownSeparator } from './DropdownSeparator.vue'
|
|
4
|
+
export { default as DropdownSub } from './DropdownSub.vue'
|
|
5
|
+
export { default as DropdownSubTrigger } from './DropdownSubTrigger.vue'
|
|
6
|
+
export { default as DropdownSubContent } from './DropdownSubContent.vue'
|
|
7
|
+
export type {
|
|
8
|
+
DropdownProps,
|
|
9
|
+
DropdownPlacement,
|
|
10
|
+
DropdownContext
|
|
11
|
+
} from './Dropdown.vue'
|
|
12
|
+
export type { DropdownItemProps } from './DropdownItem.vue'
|
|
13
|
+
export type { DropdownSubContext } from './DropdownSub.vue'
|
|
14
|
+
export type { DropdownSubTriggerProps } from './DropdownSubTrigger.vue'
|