@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,285 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, watch, onMounted } from 'vue'
|
|
3
|
+
import { useId } from '../../composables'
|
|
4
|
+
|
|
5
|
+
export interface CheckboxProps {
|
|
6
|
+
/** Checked state (v-model) */
|
|
7
|
+
modelValue?: boolean
|
|
8
|
+
/** Indeterminate state (partial selection) */
|
|
9
|
+
indeterminate?: boolean
|
|
10
|
+
/** Checkbox size */
|
|
11
|
+
size?: 'sm' | 'md' | 'lg'
|
|
12
|
+
/** Disabled state */
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
/** Visible label text */
|
|
15
|
+
label?: string
|
|
16
|
+
/** Description text below label */
|
|
17
|
+
description?: string
|
|
18
|
+
/** HTML name for form submission */
|
|
19
|
+
name?: string
|
|
20
|
+
/** Value attribute for form submission */
|
|
21
|
+
value?: string
|
|
22
|
+
/** ID for label association */
|
|
23
|
+
id?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const props = withDefaults(defineProps<CheckboxProps>(), {
|
|
27
|
+
modelValue: false,
|
|
28
|
+
indeterminate: false,
|
|
29
|
+
size: 'md',
|
|
30
|
+
disabled: false
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const emit = defineEmits<{
|
|
34
|
+
(e: 'update:modelValue', value: boolean): void
|
|
35
|
+
(e: 'change', value: boolean): void
|
|
36
|
+
}>()
|
|
37
|
+
|
|
38
|
+
const inputRef = ref<HTMLInputElement | null>(null)
|
|
39
|
+
|
|
40
|
+
const uid = useId('checkbox')
|
|
41
|
+
const checkboxId = computed(() => props.id || uid)
|
|
42
|
+
|
|
43
|
+
watch(
|
|
44
|
+
() => props.indeterminate,
|
|
45
|
+
(val) => {
|
|
46
|
+
if (inputRef.value) {
|
|
47
|
+
inputRef.value.indeterminate = val
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
onMounted(() => {
|
|
53
|
+
if (inputRef.value && props.indeterminate) {
|
|
54
|
+
inputRef.value.indeterminate = true
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
function handleChange(event: Event) {
|
|
59
|
+
const target = event.target as HTMLInputElement
|
|
60
|
+
emit('update:modelValue', target.checked)
|
|
61
|
+
emit('change', target.checked)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const checkPathLength = 24
|
|
65
|
+
const indeterminatePathLength = 10
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<template>
|
|
69
|
+
<label
|
|
70
|
+
class="ui-checkbox"
|
|
71
|
+
:class="[
|
|
72
|
+
`ui-checkbox--${size}`,
|
|
73
|
+
{
|
|
74
|
+
'ui-checkbox--disabled': disabled,
|
|
75
|
+
'ui-checkbox--checked': modelValue,
|
|
76
|
+
'ui-checkbox--indeterminate': indeterminate
|
|
77
|
+
}
|
|
78
|
+
]"
|
|
79
|
+
>
|
|
80
|
+
<input
|
|
81
|
+
ref="inputRef"
|
|
82
|
+
:id="checkboxId"
|
|
83
|
+
type="checkbox"
|
|
84
|
+
:checked="modelValue"
|
|
85
|
+
:disabled="disabled"
|
|
86
|
+
:name="name"
|
|
87
|
+
:value="value"
|
|
88
|
+
class="ui-checkbox__input"
|
|
89
|
+
@change="handleChange"
|
|
90
|
+
/>
|
|
91
|
+
|
|
92
|
+
<span class="ui-checkbox__box" aria-hidden="true">
|
|
93
|
+
<svg
|
|
94
|
+
v-if="modelValue && !indeterminate"
|
|
95
|
+
class="ui-checkbox__icon ui-checkbox__check"
|
|
96
|
+
viewBox="0 0 16 16"
|
|
97
|
+
fill="none"
|
|
98
|
+
stroke="currentColor"
|
|
99
|
+
stroke-width="2"
|
|
100
|
+
stroke-linecap="round"
|
|
101
|
+
stroke-linejoin="round"
|
|
102
|
+
>
|
|
103
|
+
<path
|
|
104
|
+
d="M3.5 8.5L6.5 11.5L12.5 4.5"
|
|
105
|
+
:stroke-dasharray="checkPathLength"
|
|
106
|
+
:stroke-dashoffset="0"
|
|
107
|
+
/>
|
|
108
|
+
</svg>
|
|
109
|
+
|
|
110
|
+
<svg
|
|
111
|
+
v-else-if="indeterminate"
|
|
112
|
+
class="ui-checkbox__icon ui-checkbox__indeterminate"
|
|
113
|
+
viewBox="0 0 16 16"
|
|
114
|
+
fill="none"
|
|
115
|
+
stroke="currentColor"
|
|
116
|
+
stroke-width="2"
|
|
117
|
+
stroke-linecap="round"
|
|
118
|
+
>
|
|
119
|
+
<path
|
|
120
|
+
d="M4 8H12"
|
|
121
|
+
:stroke-dasharray="indeterminatePathLength"
|
|
122
|
+
:stroke-dashoffset="0"
|
|
123
|
+
/>
|
|
124
|
+
</svg>
|
|
125
|
+
</span>
|
|
126
|
+
|
|
127
|
+
<span v-if="label || description" class="ui-checkbox__content">
|
|
128
|
+
<span v-if="label" class="ui-checkbox__label">{{ label }}</span>
|
|
129
|
+
<span v-if="description" class="ui-checkbox__description">{{ description }}</span>
|
|
130
|
+
</span>
|
|
131
|
+
</label>
|
|
132
|
+
</template>
|
|
133
|
+
|
|
134
|
+
<style scoped>
|
|
135
|
+
.ui-checkbox {
|
|
136
|
+
display: inline-flex;
|
|
137
|
+
align-items: flex-start;
|
|
138
|
+
gap: var(--space-2);
|
|
139
|
+
cursor: pointer;
|
|
140
|
+
font-family: var(--font-sans);
|
|
141
|
+
-webkit-tap-highlight-color: transparent;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.ui-checkbox--disabled {
|
|
145
|
+
cursor: not-allowed;
|
|
146
|
+
opacity: 0.5;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.ui-checkbox__input {
|
|
150
|
+
position: absolute;
|
|
151
|
+
width: 1px;
|
|
152
|
+
height: 1px;
|
|
153
|
+
padding: 0;
|
|
154
|
+
margin: -1px;
|
|
155
|
+
overflow: hidden;
|
|
156
|
+
clip: rect(0, 0, 0, 0);
|
|
157
|
+
white-space: nowrap;
|
|
158
|
+
border: 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.ui-checkbox__box {
|
|
162
|
+
position: relative;
|
|
163
|
+
display: flex;
|
|
164
|
+
align-items: center;
|
|
165
|
+
justify-content: center;
|
|
166
|
+
flex-shrink: 0;
|
|
167
|
+
border: 2px solid var(--checkbox-border);
|
|
168
|
+
border-radius: var(--radius-sm);
|
|
169
|
+
background-color: var(--checkbox-bg);
|
|
170
|
+
transition:
|
|
171
|
+
background-color var(--duration-fast) var(--ease-default),
|
|
172
|
+
border-color var(--duration-fast) var(--ease-default),
|
|
173
|
+
box-shadow var(--duration-fast) var(--ease-default);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.ui-checkbox--checked .ui-checkbox__box,
|
|
177
|
+
.ui-checkbox--indeterminate .ui-checkbox__box {
|
|
178
|
+
background-color: var(--checkbox-checked-bg);
|
|
179
|
+
border-color: var(--checkbox-checked-bg);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.ui-checkbox:not(.ui-checkbox--disabled):hover .ui-checkbox__box {
|
|
183
|
+
border-color: var(--checkbox-border-hover);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.ui-checkbox--checked:not(.ui-checkbox--disabled):hover .ui-checkbox__box,
|
|
187
|
+
.ui-checkbox--indeterminate:not(.ui-checkbox--disabled):hover .ui-checkbox__box {
|
|
188
|
+
background-color: var(--checkbox-checked-hover);
|
|
189
|
+
border-color: var(--checkbox-checked-hover);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.ui-checkbox__input:focus-visible + .ui-checkbox__box {
|
|
193
|
+
outline: 2px solid var(--ring-color);
|
|
194
|
+
outline-offset: 2px;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.ui-checkbox--sm .ui-checkbox__box {
|
|
198
|
+
width: 1rem;
|
|
199
|
+
height: 1rem;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.ui-checkbox--md .ui-checkbox__box {
|
|
203
|
+
width: 1.25rem;
|
|
204
|
+
height: 1.25rem;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.ui-checkbox--lg .ui-checkbox__box {
|
|
208
|
+
width: 1.5rem;
|
|
209
|
+
height: 1.5rem;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.ui-checkbox__icon {
|
|
213
|
+
position: absolute;
|
|
214
|
+
color: var(--checkbox-check);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.ui-checkbox--sm .ui-checkbox__icon {
|
|
218
|
+
width: 0.75rem;
|
|
219
|
+
height: 0.75rem;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.ui-checkbox--md .ui-checkbox__icon {
|
|
223
|
+
width: 1rem;
|
|
224
|
+
height: 1rem;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.ui-checkbox--lg .ui-checkbox__icon {
|
|
228
|
+
width: 1.25rem;
|
|
229
|
+
height: 1.25rem;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.ui-checkbox__check path {
|
|
233
|
+
stroke-dashoffset: 24;
|
|
234
|
+
animation: checkbox-draw 0.2s var(--ease-out-expo) forwards;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
@keyframes checkbox-draw {
|
|
238
|
+
to {
|
|
239
|
+
stroke-dashoffset: 0;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.ui-checkbox__indeterminate path {
|
|
244
|
+
stroke-dashoffset: 10;
|
|
245
|
+
animation: checkbox-dash 0.15s var(--ease-out-expo) forwards;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
@keyframes checkbox-dash {
|
|
249
|
+
to {
|
|
250
|
+
stroke-dashoffset: 0;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.ui-checkbox__content {
|
|
255
|
+
display: flex;
|
|
256
|
+
flex-direction: column;
|
|
257
|
+
gap: var(--space-1);
|
|
258
|
+
padding-top: 1px;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.ui-checkbox__label {
|
|
262
|
+
font-size: var(--text-sm);
|
|
263
|
+
font-weight: var(--font-medium);
|
|
264
|
+
color: var(--checkbox-label);
|
|
265
|
+
line-height: var(--leading-tight);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.ui-checkbox__description {
|
|
269
|
+
font-size: var(--text-xs);
|
|
270
|
+
color: var(--checkbox-description);
|
|
271
|
+
line-height: var(--leading-normal);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.ui-checkbox--sm .ui-checkbox__label {
|
|
275
|
+
font-size: var(--text-xs);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.ui-checkbox--lg .ui-checkbox__label {
|
|
279
|
+
font-size: var(--text-md);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.ui-checkbox--lg .ui-checkbox__description {
|
|
283
|
+
font-size: var(--text-sm);
|
|
284
|
+
}
|
|
285
|
+
</style>
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import ChoiceChip from './ChoiceChip.vue'
|
|
4
|
+
|
|
5
|
+
describe('ChoiceChip', () => {
|
|
6
|
+
describe('Rendering', () => {
|
|
7
|
+
it('renders as a label element', () => {
|
|
8
|
+
const wrapper = mount(ChoiceChip, {
|
|
9
|
+
props: { label: 'Option' }
|
|
10
|
+
})
|
|
11
|
+
expect(wrapper.find('label').exists()).toBe(true)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('renders hidden checkbox input', () => {
|
|
15
|
+
const wrapper = mount(ChoiceChip, {
|
|
16
|
+
props: { label: 'Option' }
|
|
17
|
+
})
|
|
18
|
+
expect(wrapper.find('input[type="checkbox"]').exists()).toBe(true)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('renders label text', () => {
|
|
22
|
+
const wrapper = mount(ChoiceChip, {
|
|
23
|
+
props: { label: 'Category' }
|
|
24
|
+
})
|
|
25
|
+
expect(wrapper.find('.ui-choice-chip__label').text()).toBe('Category')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('renders check container', () => {
|
|
29
|
+
const wrapper = mount(ChoiceChip, {
|
|
30
|
+
props: { label: 'Option' }
|
|
31
|
+
})
|
|
32
|
+
expect(wrapper.find('.ui-choice-chip__check').exists()).toBe(true)
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
describe('Standalone v-model', () => {
|
|
37
|
+
it('is unchecked when modelValue is false', () => {
|
|
38
|
+
const wrapper = mount(ChoiceChip, {
|
|
39
|
+
props: { label: 'Option', modelValue: false }
|
|
40
|
+
})
|
|
41
|
+
const input = wrapper.find('input')
|
|
42
|
+
expect((input.element as HTMLInputElement).checked).toBe(false)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('is checked when modelValue is true', () => {
|
|
46
|
+
const wrapper = mount(ChoiceChip, {
|
|
47
|
+
props: { label: 'Option', modelValue: true }
|
|
48
|
+
})
|
|
49
|
+
const input = wrapper.find('input')
|
|
50
|
+
expect((input.element as HTMLInputElement).checked).toBe(true)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('applies selected class when checked', () => {
|
|
54
|
+
const wrapper = mount(ChoiceChip, {
|
|
55
|
+
props: { label: 'Option', modelValue: true }
|
|
56
|
+
})
|
|
57
|
+
expect(wrapper.find('.ui-choice-chip').classes()).toContain('ui-choice-chip--selected')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('emits update:modelValue on change', async () => {
|
|
61
|
+
const wrapper = mount(ChoiceChip, {
|
|
62
|
+
props: { label: 'Option', modelValue: false }
|
|
63
|
+
})
|
|
64
|
+
await wrapper.find('input').trigger('change')
|
|
65
|
+
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([true])
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('emits change event on change', async () => {
|
|
69
|
+
const wrapper = mount(ChoiceChip, {
|
|
70
|
+
props: { label: 'Option', modelValue: false }
|
|
71
|
+
})
|
|
72
|
+
await wrapper.find('input').trigger('change')
|
|
73
|
+
expect(wrapper.emitted('change')?.[0]).toEqual([true])
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('toggles from true to false', async () => {
|
|
77
|
+
const wrapper = mount(ChoiceChip, {
|
|
78
|
+
props: { label: 'Option', modelValue: true }
|
|
79
|
+
})
|
|
80
|
+
await wrapper.find('input').trigger('change')
|
|
81
|
+
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([false])
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
describe('Disabled state', () => {
|
|
86
|
+
it('applies disabled attribute to input', () => {
|
|
87
|
+
const wrapper = mount(ChoiceChip, {
|
|
88
|
+
props: { label: 'Option', disabled: true }
|
|
89
|
+
})
|
|
90
|
+
expect(wrapper.find('input').attributes('disabled')).toBeDefined()
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('applies disabled class', () => {
|
|
94
|
+
const wrapper = mount(ChoiceChip, {
|
|
95
|
+
props: { label: 'Option', disabled: true }
|
|
96
|
+
})
|
|
97
|
+
expect(wrapper.find('.ui-choice-chip').classes()).toContain('ui-choice-chip--disabled')
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('does not emit events when disabled', async () => {
|
|
101
|
+
const wrapper = mount(ChoiceChip, {
|
|
102
|
+
props: { label: 'Option', disabled: true, modelValue: false }
|
|
103
|
+
})
|
|
104
|
+
await wrapper.find('input').trigger('change')
|
|
105
|
+
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
describe('Icon support', () => {
|
|
110
|
+
const mockIcon = { render: () => null }
|
|
111
|
+
|
|
112
|
+
it('renders icon when provided', () => {
|
|
113
|
+
const wrapper = mount(ChoiceChip, {
|
|
114
|
+
props: { label: 'Option', icon: mockIcon }
|
|
115
|
+
})
|
|
116
|
+
expect(wrapper.findComponent({ name: 'Icon' }).exists()).toBe(true)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('does not render icon when not provided', () => {
|
|
120
|
+
const wrapper = mount(ChoiceChip, {
|
|
121
|
+
props: { label: 'Option' }
|
|
122
|
+
})
|
|
123
|
+
expect(wrapper.find('.ui-choice-chip__icon').exists()).toBe(false)
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
describe('Accessibility', () => {
|
|
128
|
+
it('input is visually hidden but accessible', () => {
|
|
129
|
+
const wrapper = mount(ChoiceChip, {
|
|
130
|
+
props: { label: 'Option' }
|
|
131
|
+
})
|
|
132
|
+
expect(wrapper.find('.ui-choice-chip__input').exists()).toBe(true)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it('check icon has aria-hidden', () => {
|
|
136
|
+
const wrapper = mount(ChoiceChip, {
|
|
137
|
+
props: { label: 'Option' }
|
|
138
|
+
})
|
|
139
|
+
expect(wrapper.find('.ui-choice-chip__check').attributes('aria-hidden')).toBe('true')
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
})
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, inject } from 'vue'
|
|
3
|
+
import Icon from '../Icon/Icon.vue'
|
|
4
|
+
import type { IconInput } from '../Icon/Icon.vue'
|
|
5
|
+
import { useId } from '../../composables'
|
|
6
|
+
|
|
7
|
+
export interface ChoiceChipProps {
|
|
8
|
+
/** Selected state for standalone usage (v-model) */
|
|
9
|
+
modelValue?: boolean
|
|
10
|
+
/** Value for group usage */
|
|
11
|
+
value?: string | number
|
|
12
|
+
/** Chip label text */
|
|
13
|
+
label: string
|
|
14
|
+
/** Optional leading icon */
|
|
15
|
+
icon?: IconInput
|
|
16
|
+
/** Disabled state */
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const props = withDefaults(defineProps<ChoiceChipProps>(), {
|
|
21
|
+
disabled: false
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const emit = defineEmits<{
|
|
25
|
+
(e: 'update:modelValue', value: boolean): void
|
|
26
|
+
(e: 'change', value: boolean): void
|
|
27
|
+
}>()
|
|
28
|
+
|
|
29
|
+
const groupContext = inject<{
|
|
30
|
+
modelValue: { value: (string | number)[] | string | number | undefined }
|
|
31
|
+
toggle: (value: string | number) => void
|
|
32
|
+
type: 'single' | 'multiple'
|
|
33
|
+
disabled?: boolean
|
|
34
|
+
} | null>('choiceChipGroup', null)
|
|
35
|
+
|
|
36
|
+
const isInGroup = computed(() => groupContext !== null && props.value !== undefined)
|
|
37
|
+
|
|
38
|
+
const effectiveDisabled = computed(() => props.disabled || groupContext?.disabled)
|
|
39
|
+
|
|
40
|
+
const isSelected = computed(() => {
|
|
41
|
+
if (isInGroup.value && groupContext && props.value !== undefined) {
|
|
42
|
+
const groupValue = groupContext.modelValue.value
|
|
43
|
+
if (Array.isArray(groupValue)) {
|
|
44
|
+
return groupValue.includes(props.value)
|
|
45
|
+
}
|
|
46
|
+
return groupValue === props.value
|
|
47
|
+
}
|
|
48
|
+
return props.modelValue ?? false
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const chipId = useId('chip')
|
|
52
|
+
|
|
53
|
+
function handleChange() {
|
|
54
|
+
if (effectiveDisabled.value) return
|
|
55
|
+
|
|
56
|
+
if (isInGroup.value && groupContext && props.value !== undefined) {
|
|
57
|
+
groupContext.toggle(props.value)
|
|
58
|
+
} else {
|
|
59
|
+
const newValue = !props.modelValue
|
|
60
|
+
emit('update:modelValue', newValue)
|
|
61
|
+
emit('change', newValue)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<template>
|
|
67
|
+
<label
|
|
68
|
+
class="ui-choice-chip"
|
|
69
|
+
:class="{
|
|
70
|
+
'ui-choice-chip--selected': isSelected,
|
|
71
|
+
'ui-choice-chip--disabled': effectiveDisabled
|
|
72
|
+
}"
|
|
73
|
+
>
|
|
74
|
+
<input
|
|
75
|
+
:id="chipId"
|
|
76
|
+
type="checkbox"
|
|
77
|
+
:checked="isSelected"
|
|
78
|
+
:disabled="effectiveDisabled"
|
|
79
|
+
class="ui-choice-chip__input"
|
|
80
|
+
@change="handleChange"
|
|
81
|
+
/>
|
|
82
|
+
|
|
83
|
+
<span class="ui-choice-chip__check" aria-hidden="true">
|
|
84
|
+
<svg
|
|
85
|
+
class="ui-choice-chip__check-icon"
|
|
86
|
+
viewBox="0 0 16 16"
|
|
87
|
+
fill="none"
|
|
88
|
+
stroke="currentColor"
|
|
89
|
+
stroke-width="2.5"
|
|
90
|
+
stroke-linecap="round"
|
|
91
|
+
stroke-linejoin="round"
|
|
92
|
+
>
|
|
93
|
+
<path d="M3.5 8.5L6.5 11L12.5 5" />
|
|
94
|
+
</svg>
|
|
95
|
+
</span>
|
|
96
|
+
|
|
97
|
+
<Icon v-if="icon" :icon="icon" class="ui-choice-chip__icon" />
|
|
98
|
+
|
|
99
|
+
<span class="ui-choice-chip__label">{{ label }}</span>
|
|
100
|
+
</label>
|
|
101
|
+
</template>
|
|
102
|
+
|
|
103
|
+
<style scoped>
|
|
104
|
+
.ui-choice-chip {
|
|
105
|
+
display: inline-flex;
|
|
106
|
+
align-items: center;
|
|
107
|
+
gap: var(--space-2);
|
|
108
|
+
height: 32px;
|
|
109
|
+
padding: 0 var(--space-3);
|
|
110
|
+
background: var(--chip-bg);
|
|
111
|
+
border: 1px solid var(--chip-border);
|
|
112
|
+
border-radius: var(--radius-full);
|
|
113
|
+
font-family: var(--font-sans);
|
|
114
|
+
font-size: var(--text-sm);
|
|
115
|
+
font-weight: var(--font-medium);
|
|
116
|
+
color: var(--chip-text);
|
|
117
|
+
cursor: pointer;
|
|
118
|
+
transition:
|
|
119
|
+
background-color var(--duration-fast) var(--ease-default),
|
|
120
|
+
border-color var(--duration-fast) var(--ease-default),
|
|
121
|
+
color var(--duration-fast) var(--ease-default);
|
|
122
|
+
-webkit-tap-highlight-color: transparent;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.ui-choice-chip__input {
|
|
126
|
+
position: absolute;
|
|
127
|
+
width: 1px;
|
|
128
|
+
height: 1px;
|
|
129
|
+
padding: 0;
|
|
130
|
+
margin: -1px;
|
|
131
|
+
overflow: hidden;
|
|
132
|
+
clip: rect(0, 0, 0, 0);
|
|
133
|
+
white-space: nowrap;
|
|
134
|
+
border: 0;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.ui-choice-chip:not(.ui-choice-chip--disabled):hover {
|
|
138
|
+
background: var(--chip-bg-hover);
|
|
139
|
+
border-color: var(--chip-border-hover);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.ui-choice-chip:not(.ui-choice-chip--disabled):active {
|
|
143
|
+
background: var(--chip-bg-active);
|
|
144
|
+
border-color: var(--chip-border-active);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.ui-choice-chip--selected {
|
|
148
|
+
background: var(--chip-bg-selected);
|
|
149
|
+
border-color: var(--chip-border-selected);
|
|
150
|
+
color: var(--chip-text-selected);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.ui-choice-chip--selected:not(.ui-choice-chip--disabled):hover {
|
|
154
|
+
background: var(--chip-bg-selected-hover);
|
|
155
|
+
border-color: var(--chip-border-selected-hover);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.ui-choice-chip--selected:not(.ui-choice-chip--disabled):active {
|
|
159
|
+
background: var(--chip-bg-selected-active);
|
|
160
|
+
border-color: var(--chip-border-selected-active);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.ui-choice-chip__input:focus-visible + .ui-choice-chip__check {
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.ui-choice-chip:has(.ui-choice-chip__input:focus-visible) {
|
|
167
|
+
outline: 2px solid var(--ring-color);
|
|
168
|
+
outline-offset: 2px;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.ui-choice-chip--disabled {
|
|
172
|
+
opacity: 0.5;
|
|
173
|
+
cursor: not-allowed;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.ui-choice-chip__check {
|
|
177
|
+
display: flex;
|
|
178
|
+
align-items: center;
|
|
179
|
+
justify-content: center;
|
|
180
|
+
width: 0;
|
|
181
|
+
margin-right: calc(-1 * var(--space-2));
|
|
182
|
+
overflow: hidden;
|
|
183
|
+
transition:
|
|
184
|
+
width var(--duration-fast) var(--ease-out-expo),
|
|
185
|
+
margin var(--duration-fast) var(--ease-out-expo);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.ui-choice-chip--selected .ui-choice-chip__check {
|
|
189
|
+
width: 1rem;
|
|
190
|
+
margin-right: 0;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.ui-choice-chip__check-icon {
|
|
194
|
+
width: 0.875rem;
|
|
195
|
+
height: 0.875rem;
|
|
196
|
+
flex-shrink: 0;
|
|
197
|
+
opacity: 0;
|
|
198
|
+
transform: scale(0.5);
|
|
199
|
+
transition:
|
|
200
|
+
opacity var(--duration-fast) var(--ease-default),
|
|
201
|
+
transform var(--duration-fast) var(--ease-out-back);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.ui-choice-chip--selected .ui-choice-chip__check-icon {
|
|
205
|
+
opacity: 1;
|
|
206
|
+
transform: scale(1);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.ui-choice-chip__icon {
|
|
210
|
+
width: 1rem;
|
|
211
|
+
height: 1rem;
|
|
212
|
+
flex-shrink: 0;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.ui-choice-chip__label {
|
|
216
|
+
white-space: nowrap;
|
|
217
|
+
}
|
|
218
|
+
</style>
|