akar 1.19.0 → 1.21.0
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/dist/autocomplete/autocomplete-input.js +122 -0
- package/dist/autocomplete/autocomplete-input.js.map +1 -0
- package/dist/autocomplete/autocomplete-root.js +253 -0
- package/dist/autocomplete/autocomplete-root.js.map +1 -0
- package/dist/checkbox/checkbox-group-root.js +1 -1
- package/dist/checkbox/checkbox-root.js +1 -1
- package/dist/combobox/combobox-content-impl.js +9 -2
- package/dist/combobox/combobox-content-impl.js.map +1 -1
- package/dist/combobox/combobox-content.js +4 -0
- package/dist/combobox/combobox-content.js.map +1 -1
- package/dist/combobox/combobox-root.js +1 -1
- package/dist/composables/use-window-splitter-panel-group-behavior.js +13 -9
- package/dist/composables/use-window-splitter-panel-group-behavior.js.map +1 -1
- package/dist/constant/components.js +18 -0
- package/dist/constant/components.js.map +1 -1
- package/dist/constant.d.ts +1 -0
- package/dist/constant.d.ts.map +1 -1
- package/dist/date-field/date-field-root.js +1 -1
- package/dist/date-range-field/date-range-field-root.js +1 -1
- package/dist/dialog/dialog-content-impl.js +1 -1
- package/dist/hover-card/hover-card-content-impl.js +1 -1
- package/dist/index.d.ts +1976 -1780
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -47
- package/dist/listbox/listbox-root.js +1 -1
- package/dist/listbox/listbox-virtualizer.js +1 -1
- package/dist/menu/menu-content-impl.js +1 -1
- package/dist/menu/menu-item-impl.js +1 -1
- package/dist/namespaced/index.cjs +19 -0
- package/dist/namespaced/index.d.cts +20 -2
- package/dist/namespaced/index.d.mts +20 -2
- package/dist/namespaced/index.mjs +20 -2
- package/dist/popover/popover-content-impl.js +1 -1
- package/dist/radio-group/radio-group-root.js +1 -1
- package/dist/rating/rating-item-indicator.js +83 -0
- package/dist/rating/rating-item-indicator.js.map +1 -0
- package/dist/rating/rating-item.js +54 -0
- package/dist/rating/rating-item.js.map +1 -0
- package/dist/rating/rating-root.js +124 -0
- package/dist/rating/rating-root.js.map +1 -0
- package/dist/select/select-content-impl.js +1 -1
- package/dist/select/select-root.js +1 -1
- package/dist/select/select-trigger.js +1 -1
- package/dist/shared/use-id.js +7 -4
- package/dist/shared/use-id.js.map +1 -1
- package/dist/splitter/splitter-group.js +142 -29
- package/dist/splitter/splitter-group.js.map +1 -1
- package/dist/splitter/splitter-panel.js +7 -2
- package/dist/splitter/splitter-panel.js.map +1 -1
- package/dist/time-field/time-field-root.js +1 -1
- package/dist/toast/toast-announce.js +4 -1
- package/dist/toast/toast-announce.js.map +1 -1
- package/dist/toggle-group/toggle-group-root.js +1 -1
- package/dist/tooltip/tooltip-content-impl.js +26 -19
- package/dist/tooltip/tooltip-content-impl.js.map +1 -1
- package/dist/tooltip/tooltip-content.js +1 -2
- package/dist/tooltip/tooltip-content.js.map +1 -1
- package/dist/tooltip/tooltip-provider.js +7 -2
- package/dist/tooltip/tooltip-provider.js.map +1 -1
- package/dist/utils/storage.js +7 -1
- package/dist/utils/storage.js.map +1 -1
- package/dist/utils/units.js +82 -0
- package/dist/utils/units.js.map +1 -0
- package/package.json +1 -1
- package/src/autocomplete/autocomplete-input.vue +124 -0
- package/src/autocomplete/autocomplete-root.vue +292 -0
- package/src/autocomplete/index.ts +74 -0
- package/src/combobox/combobox-content-impl.vue +13 -1
- package/src/index.ts +2 -0
- package/src/rating/index.ts +3 -0
- package/src/rating/rating-item-indicator.vue +69 -0
- package/src/rating/rating-item.vue +58 -0
- package/src/rating/rating-root.vue +125 -0
- package/src/shared/use-id.ts +6 -8
- package/src/splitter/splitter-group.vue +248 -53
- package/src/splitter/splitter-panel.vue +12 -7
- package/src/splitter/utils/composables/use-window-splitter-panel-group-behavior.ts +18 -7
- package/src/splitter/utils/storage.ts +14 -0
- package/src/splitter/utils/units.ts +166 -0
- package/src/splitter/utils/validation.ts +3 -2
- package/src/toast/toast-announce.vue +4 -1
- package/src/tooltip/tooltip-content-impl.vue +18 -10
- package/src/tooltip/tooltip-content.vue +1 -3
- package/src/tooltip/tooltip-provider.vue +20 -3
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Ref } from 'vue';
|
|
3
|
+
import type { APrimitiveProps } from '../primitive';
|
|
4
|
+
import type { Direction, GenericComponentInstance } from '../shared/types';
|
|
5
|
+
import { createContext, useDirection, useFilter } from '../shared';
|
|
6
|
+
|
|
7
|
+
export interface AAutocompleteRootProps extends APrimitiveProps {
|
|
8
|
+
/** The controlled value of the Autocomplete (the input text). Can be bound with `v-model`. */
|
|
9
|
+
modelValue?: string;
|
|
10
|
+
/** The value of the autocomplete when initially rendered. Use when you do not need to control the state. */
|
|
11
|
+
defaultValue?: string;
|
|
12
|
+
/** The controlled open state of the Autocomplete. Can be bound with `v-model:open`. */
|
|
13
|
+
open?: boolean;
|
|
14
|
+
/** The open state of the autocomplete when it is initially rendered. Use when you do not need to control its open state. */
|
|
15
|
+
defaultOpen?: boolean;
|
|
16
|
+
/** When `true`, prevents the user from interacting with autocomplete */
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
/** The reading direction of the autocomplete when applicable. */
|
|
19
|
+
dir?: Direction;
|
|
20
|
+
/** The name of the field. Submitted with its owning form as part of a name/value pair. */
|
|
21
|
+
name?: string;
|
|
22
|
+
/** When `true`, indicates that the user must set the value before the owning form can be submitted. */
|
|
23
|
+
required?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to reset the searchTerm when the Autocomplete input blurred
|
|
26
|
+
* @defaultValue `false`
|
|
27
|
+
*/
|
|
28
|
+
resetSearchTermOnBlur?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to open the autocomplete when the input is focused
|
|
31
|
+
* @defaultValue `false`
|
|
32
|
+
*/
|
|
33
|
+
openOnFocus?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether to open the autocomplete when the input is clicked
|
|
36
|
+
* @defaultValue `false`
|
|
37
|
+
*/
|
|
38
|
+
openOnClick?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* When `true`, disable the default filters
|
|
41
|
+
*/
|
|
42
|
+
ignoreFilter?: boolean;
|
|
43
|
+
/** When `true`, hover over item will trigger highlight */
|
|
44
|
+
highlightOnHover?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type AAutocompleteRootEmits = {
|
|
48
|
+
/** Event handler called when the value changes. */
|
|
49
|
+
'update:modelValue': [value: string];
|
|
50
|
+
/** Event handler when highlighted element changes. */
|
|
51
|
+
'highlight': [payload: { ref: HTMLElement; value: string } | undefined];
|
|
52
|
+
/** Event handler called when the open state of the autocomplete changes. */
|
|
53
|
+
'update:open': [value: boolean];
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type AAutocompleteRootContext = {
|
|
57
|
+
modelValue: Ref<string>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const [
|
|
61
|
+
injectAAutocompleteRootContext,
|
|
62
|
+
provideAAutocompleteRootContext,
|
|
63
|
+
] = createContext<AAutocompleteRootContext>('AutocompleteRoot');
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<script setup lang="ts">
|
|
67
|
+
import { createEventHook, useVModel } from '@vueuse/core';
|
|
68
|
+
import { computed, getCurrentInstance, nextTick, onMounted, ref, toRefs } from 'vue';
|
|
69
|
+
import { provideComboboxRootContext } from '../combobox/combobox-root.vue';
|
|
70
|
+
import { AListboxRoot } from '../listbox';
|
|
71
|
+
import { APopperRoot } from '../popper';
|
|
72
|
+
import { usePrimitiveElement } from '../primitive';
|
|
73
|
+
|
|
74
|
+
const props = withDefaults(
|
|
75
|
+
defineProps<AAutocompleteRootProps>(),
|
|
76
|
+
{
|
|
77
|
+
open: undefined,
|
|
78
|
+
resetSearchTermOnBlur: false,
|
|
79
|
+
openOnFocus: false,
|
|
80
|
+
openOnClick: false,
|
|
81
|
+
highlightOnHover: true,
|
|
82
|
+
},
|
|
83
|
+
);
|
|
84
|
+
const emits = defineEmits<AAutocompleteRootEmits>();
|
|
85
|
+
|
|
86
|
+
defineSlots<{
|
|
87
|
+
default?: (props: {
|
|
88
|
+
/** Current open state */
|
|
89
|
+
open: typeof open.value;
|
|
90
|
+
/** Current active value */
|
|
91
|
+
modelValue: typeof modelValue.value;
|
|
92
|
+
}) => any;
|
|
93
|
+
}>();
|
|
94
|
+
|
|
95
|
+
const {
|
|
96
|
+
primitiveElement,
|
|
97
|
+
currentElement: parentElement,
|
|
98
|
+
} = usePrimitiveElement<GenericComponentInstance<typeof AListboxRoot>>();
|
|
99
|
+
const {
|
|
100
|
+
disabled,
|
|
101
|
+
ignoreFilter,
|
|
102
|
+
openOnFocus,
|
|
103
|
+
openOnClick,
|
|
104
|
+
dir: propDir,
|
|
105
|
+
highlightOnHover,
|
|
106
|
+
} = toRefs(props);
|
|
107
|
+
|
|
108
|
+
const dir = useDirection(propDir);
|
|
109
|
+
|
|
110
|
+
const modelValue = useVModel(props, 'modelValue', emits, {
|
|
111
|
+
defaultValue: props.defaultValue ?? '',
|
|
112
|
+
passive: (props.modelValue === undefined) as false,
|
|
113
|
+
}) as Ref<string>;
|
|
114
|
+
|
|
115
|
+
const open = useVModel(props, 'open', emits, {
|
|
116
|
+
defaultValue: props.defaultOpen,
|
|
117
|
+
passive: (props.open === undefined) as false,
|
|
118
|
+
}) as Ref<boolean>;
|
|
119
|
+
|
|
120
|
+
// Writable computed that converts any value to string for the ComboboxRootContext.
|
|
121
|
+
// This handles the case when ComboboxItem sets modelValue to a non-string value,
|
|
122
|
+
// or when ComboboxCancel resets modelValue to null.
|
|
123
|
+
const contextModelValue = computed({
|
|
124
|
+
get: () => modelValue.value,
|
|
125
|
+
set: (val: any) => {
|
|
126
|
+
if (val === null || val === undefined) {
|
|
127
|
+
modelValue.value = '';
|
|
128
|
+
} else {
|
|
129
|
+
modelValue.value = String(val);
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
async function onOpenChange(val: boolean) {
|
|
135
|
+
open.value = val;
|
|
136
|
+
|
|
137
|
+
if (val) {
|
|
138
|
+
// When opening, set filter to current text so items are filtered by what's in the input
|
|
139
|
+
filterSearch.value = modelValue.value || '';
|
|
140
|
+
|
|
141
|
+
await nextTick();
|
|
142
|
+
primitiveElement.value?.highlightSelected();
|
|
143
|
+
isUserInputted.value = true;
|
|
144
|
+
inputElement.value?.focus();
|
|
145
|
+
} else {
|
|
146
|
+
isUserInputted.value = false;
|
|
147
|
+
filterSearch.value = '';
|
|
148
|
+
setTimeout(() => {
|
|
149
|
+
// eslint-disable-next-line sonar/no-gratuitous-expressions
|
|
150
|
+
if (!val && props.resetSearchTermOnBlur) {
|
|
151
|
+
resetSearchTerm.trigger();
|
|
152
|
+
}
|
|
153
|
+
}, 1);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const resetSearchTerm = createEventHook();
|
|
158
|
+
const isUserInputted = ref(false);
|
|
159
|
+
const isVirtual = ref(false);
|
|
160
|
+
const inputElement = ref<HTMLInputElement>();
|
|
161
|
+
const triggerElement = ref<HTMLElement>();
|
|
162
|
+
|
|
163
|
+
const highlightedElement = computed(() => primitiveElement.value?.highlightedElement ?? undefined);
|
|
164
|
+
|
|
165
|
+
const allItems = ref<Map<string, string>>(new Map());
|
|
166
|
+
const allGroups = ref<Map<string, Set<string>>>(new Map());
|
|
167
|
+
|
|
168
|
+
const { contains } = useFilter({ sensitivity: 'base' });
|
|
169
|
+
|
|
170
|
+
const filterSearch = ref('');
|
|
171
|
+
|
|
172
|
+
const filterState = computed<{
|
|
173
|
+
count: number;
|
|
174
|
+
items: Map<string, number>;
|
|
175
|
+
groups: Set<string>;
|
|
176
|
+
}>((oldValue) => {
|
|
177
|
+
if (!filterSearch.value || props.ignoreFilter || isVirtual.value) {
|
|
178
|
+
return {
|
|
179
|
+
count: allItems.value.size,
|
|
180
|
+
items: oldValue?.items ?? new Map(),
|
|
181
|
+
groups: oldValue?.groups ?? new Set(allGroups.value.keys()),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
let itemCount = 0;
|
|
186
|
+
const filteredItems = new Map<string, number>();
|
|
187
|
+
const filteredGroups = new Set<string>();
|
|
188
|
+
|
|
189
|
+
for (const [id, value] of allItems.value) {
|
|
190
|
+
const score = contains({ string: value, substring: filterSearch.value });
|
|
191
|
+
filteredItems.set(id, score ? 1 : 0);
|
|
192
|
+
if (score) {
|
|
193
|
+
itemCount++;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
for (const [groupId, group] of allGroups.value) {
|
|
198
|
+
for (const itemId of group) {
|
|
199
|
+
if (filteredItems.get(itemId)! > 0) {
|
|
200
|
+
filteredGroups.add(groupId);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
count: itemCount,
|
|
208
|
+
items: filteredItems,
|
|
209
|
+
groups: filteredGroups,
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const inst = getCurrentInstance();
|
|
214
|
+
onMounted(() => {
|
|
215
|
+
if (inst?.exposed) {
|
|
216
|
+
inst.exposed.highlightItem = primitiveElement.value?.highlightItem;
|
|
217
|
+
inst.exposed.highlightFirstItem = primitiveElement.value?.highlightFirstItem;
|
|
218
|
+
inst.exposed.highlightSelected = primitiveElement.value?.highlightSelected;
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
defineExpose({
|
|
223
|
+
filtered: filterState,
|
|
224
|
+
highlightedElement,
|
|
225
|
+
highlightItem: primitiveElement.value?.highlightItem,
|
|
226
|
+
highlightFirstItem: primitiveElement.value?.highlightFirstItem,
|
|
227
|
+
highlightSelected: primitiveElement.value?.highlightSelected,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// Provide the Combobox context so all Combobox sub-components work inside Autocomplete
|
|
231
|
+
provideComboboxRootContext({
|
|
232
|
+
modelValue: contextModelValue as any,
|
|
233
|
+
multiple: ref(false),
|
|
234
|
+
disabled,
|
|
235
|
+
open,
|
|
236
|
+
onOpenChange,
|
|
237
|
+
contentId: '',
|
|
238
|
+
isUserInputted,
|
|
239
|
+
isVirtual,
|
|
240
|
+
inputElement,
|
|
241
|
+
highlightedElement,
|
|
242
|
+
onInputElementChange: (val) => {
|
|
243
|
+
inputElement.value = val;
|
|
244
|
+
},
|
|
245
|
+
triggerElement,
|
|
246
|
+
onTriggerElementChange: (val) => {
|
|
247
|
+
triggerElement.value = val;
|
|
248
|
+
},
|
|
249
|
+
parentElement,
|
|
250
|
+
resetSearchTermOnSelect: ref(false),
|
|
251
|
+
onResetSearchTerm: resetSearchTerm.on,
|
|
252
|
+
allItems,
|
|
253
|
+
allGroups,
|
|
254
|
+
filterSearch,
|
|
255
|
+
filterState,
|
|
256
|
+
ignoreFilter,
|
|
257
|
+
openOnFocus,
|
|
258
|
+
openOnClick,
|
|
259
|
+
resetModelValueOnClear: ref(true),
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// Provide autocomplete-specific context
|
|
263
|
+
provideAAutocompleteRootContext({
|
|
264
|
+
modelValue,
|
|
265
|
+
});
|
|
266
|
+
</script>
|
|
267
|
+
|
|
268
|
+
<template>
|
|
269
|
+
<APopperRoot>
|
|
270
|
+
<AListboxRoot
|
|
271
|
+
ref="primitiveElement"
|
|
272
|
+
v-bind="$attrs"
|
|
273
|
+
v-model="(contextModelValue as any)"
|
|
274
|
+
:style="{
|
|
275
|
+
pointerEvents: open ? 'auto' : undefined,
|
|
276
|
+
}"
|
|
277
|
+
:as="as"
|
|
278
|
+
:as-child="asChild"
|
|
279
|
+
:dir="dir"
|
|
280
|
+
:name="name"
|
|
281
|
+
:required="required"
|
|
282
|
+
:disabled="disabled"
|
|
283
|
+
:highlight-on-hover="highlightOnHover"
|
|
284
|
+
@highlight="emits('highlight', $event as any)"
|
|
285
|
+
>
|
|
286
|
+
<slot
|
|
287
|
+
:open="open"
|
|
288
|
+
:model-value="modelValue"
|
|
289
|
+
/>
|
|
290
|
+
</AListboxRoot>
|
|
291
|
+
</APopperRoot>
|
|
292
|
+
</template>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Re-export Combobox sub-components as Autocomplete equivalents.
|
|
2
|
+
// These components inject ComboboxRootContext which AutocompleteRoot provides.
|
|
3
|
+
export {
|
|
4
|
+
AComboboxAnchor as AAutocompleteAnchor,
|
|
5
|
+
type AComboboxAnchorProps as AAutocompleteAnchorProps,
|
|
6
|
+
} from '../combobox';
|
|
7
|
+
export {
|
|
8
|
+
AComboboxArrow as AAutocompleteArrow,
|
|
9
|
+
type AComboboxArrowProps as AAutocompleteArrowProps,
|
|
10
|
+
} from '../combobox';
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
AComboboxCancel as AAutocompleteCancel,
|
|
14
|
+
type AComboboxCancelProps as AAutocompleteCancelProps,
|
|
15
|
+
} from '../combobox';
|
|
16
|
+
export {
|
|
17
|
+
AComboboxContent as AAutocompleteContent,
|
|
18
|
+
type AComboboxContentEmits as AAutocompleteContentEmits,
|
|
19
|
+
type AComboboxContentProps as AAutocompleteContentProps,
|
|
20
|
+
} from '../combobox';
|
|
21
|
+
export {
|
|
22
|
+
AComboboxEmpty as AAutocompleteEmpty,
|
|
23
|
+
type AComboboxEmptyProps as AAutocompleteEmptyProps,
|
|
24
|
+
} from '../combobox';
|
|
25
|
+
export {
|
|
26
|
+
AComboboxGroup as AAutocompleteGroup,
|
|
27
|
+
type AComboboxGroupProps as AAutocompleteGroupProps,
|
|
28
|
+
} from '../combobox';
|
|
29
|
+
export {
|
|
30
|
+
AComboboxItem as AAutocompleteItem,
|
|
31
|
+
type AComboboxItemEmits as AAutocompleteItemEmits,
|
|
32
|
+
type AComboboxItemProps as AAutocompleteItemProps,
|
|
33
|
+
} from '../combobox';
|
|
34
|
+
export {
|
|
35
|
+
AComboboxItemIndicator as AAutocompleteItemIndicator,
|
|
36
|
+
type AComboboxItemIndicatorProps as AAutocompleteItemIndicatorProps,
|
|
37
|
+
} from '../combobox';
|
|
38
|
+
export {
|
|
39
|
+
AComboboxLabel as AAutocompleteLabel,
|
|
40
|
+
type AComboboxLabelProps as AAutocompleteLabelProps,
|
|
41
|
+
} from '../combobox';
|
|
42
|
+
export {
|
|
43
|
+
AComboboxPortal as AAutocompletePortal,
|
|
44
|
+
type AComboboxPortalProps as AAutocompletePortalProps,
|
|
45
|
+
} from '../combobox';
|
|
46
|
+
export {
|
|
47
|
+
AComboboxSeparator as AAutocompleteSeparator,
|
|
48
|
+
type AComboboxSeparatorProps as AAutocompleteSeparatorProps,
|
|
49
|
+
} from '../combobox';
|
|
50
|
+
export {
|
|
51
|
+
AComboboxTrigger as AAutocompleteTrigger,
|
|
52
|
+
type AComboboxTriggerProps as AAutocompleteTriggerProps,
|
|
53
|
+
} from '../combobox';
|
|
54
|
+
export {
|
|
55
|
+
AComboboxViewport as AAutocompleteViewport,
|
|
56
|
+
type AComboboxViewportProps as AAutocompleteViewportProps,
|
|
57
|
+
} from '../combobox';
|
|
58
|
+
export {
|
|
59
|
+
AComboboxVirtualizer as AAutocompleteVirtualizer,
|
|
60
|
+
type AComboboxVirtualizerProps as AAutocompleteVirtualizerProps,
|
|
61
|
+
} from '../combobox';
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
default as AAutocompleteInput,
|
|
65
|
+
type AAutocompleteInputEmits,
|
|
66
|
+
type AAutocompleteInputProps,
|
|
67
|
+
} from './autocomplete-input.vue';
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
default as AAutocompleteRoot,
|
|
71
|
+
type AAutocompleteRootEmits,
|
|
72
|
+
type AAutocompleteRootProps,
|
|
73
|
+
injectAAutocompleteRootContext,
|
|
74
|
+
} from './autocomplete-root.vue';
|
|
@@ -24,6 +24,11 @@ export interface ComboboxContentImplProps extends APopperContentProps, Dismissab
|
|
|
24
24
|
position?: 'inline' | 'popper';
|
|
25
25
|
/** The document.body will be lock, and scrolling will be disabled. */
|
|
26
26
|
bodyLock?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* When `true`, hides the content when there are no items matching the filter.
|
|
29
|
+
* @defaultValue false
|
|
30
|
+
*/
|
|
31
|
+
hideWhenEmpty?: boolean;
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
export const [
|
|
@@ -51,6 +56,11 @@ const emits = defineEmits<ComboboxContentImplEmits>();
|
|
|
51
56
|
const { position } = toRefs(props);
|
|
52
57
|
const rootContext = injectAComboboxRootContext();
|
|
53
58
|
|
|
59
|
+
const isEmpty = computed(() => rootContext.ignoreFilter.value
|
|
60
|
+
? rootContext.allItems.value.size === 0
|
|
61
|
+
: rootContext.filterState.value.count === 0,
|
|
62
|
+
);
|
|
63
|
+
|
|
54
64
|
const { forwardRef, currentElement } = useForwardExpose();
|
|
55
65
|
useBodyScrollLock(props.bodyLock);
|
|
56
66
|
useFocusGuards();
|
|
@@ -130,9 +140,11 @@ onUnmounted(() => {
|
|
|
130
140
|
:id="rootContext.contentId"
|
|
131
141
|
:ref="forwardRef"
|
|
132
142
|
:data-state="rootContext.open.value ? 'open' : 'closed'"
|
|
143
|
+
:data-empty="isEmpty ? '' : undefined"
|
|
133
144
|
:style="{
|
|
134
145
|
// flex layout so we can place the scroll buttons properly
|
|
135
|
-
|
|
146
|
+
// When hideWhenEmpty is true, hide the content when no items match
|
|
147
|
+
display: (props.hideWhenEmpty && isEmpty) ? 'none' : 'flex',
|
|
136
148
|
flexDirection: 'column',
|
|
137
149
|
// reset the outline by default as the content MAY get focused
|
|
138
150
|
outline: 'none',
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable perfectionist/sort-exports */
|
|
2
2
|
export * from './accordion';
|
|
3
|
+
export * from './autocomplete';
|
|
3
4
|
export * from './avatar';
|
|
4
5
|
export * from './alert-dialog';
|
|
5
6
|
export * from './calendar';
|
|
@@ -31,6 +32,7 @@ export { APrimitive, type APrimitiveAsTag, type APrimitiveProps, APrimitiveSlot
|
|
|
31
32
|
export * from './progress';
|
|
32
33
|
export * from './radio-group';
|
|
33
34
|
export * from './range-calendar';
|
|
35
|
+
export * from './rating';
|
|
34
36
|
export * from './roving-focus';
|
|
35
37
|
export * from './scroll-area';
|
|
36
38
|
export * from './select';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { APrimitiveProps } from '../primitive';
|
|
3
|
+
|
|
4
|
+
export interface ARatingItemProps extends APrimitiveProps {
|
|
5
|
+
step: number;
|
|
6
|
+
}
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script setup lang="ts">
|
|
10
|
+
import { useActiveElement } from '@vueuse/core';
|
|
11
|
+
import { computed } from 'vue';
|
|
12
|
+
import { ARadioGroupIndicator, ARadioGroupItem } from '../radio-group';
|
|
13
|
+
import { useForwardExpose } from '../shared';
|
|
14
|
+
import { injectARatingItemContext } from './rating-item.vue';
|
|
15
|
+
import { injectARatingRootContext } from './rating-root.vue';
|
|
16
|
+
|
|
17
|
+
const props = defineProps<ARatingItemProps>();
|
|
18
|
+
|
|
19
|
+
const rootContext = injectARatingRootContext();
|
|
20
|
+
const { currentElement, forwardRef } = useForwardExpose();
|
|
21
|
+
const activeElement = useActiveElement();
|
|
22
|
+
const itemContext = injectARatingItemContext();
|
|
23
|
+
|
|
24
|
+
const isActive = computed(() => {
|
|
25
|
+
return (
|
|
26
|
+
rootContext.hoveredRating.value > 0 && props.step <= rootContext.hoveredRating.value
|
|
27
|
+
) || (
|
|
28
|
+
rootContext.hoveredRating.value === 0 && props.step <= rootContext.modelValue.value
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const isVisible = computed(() => {
|
|
33
|
+
return activeElement.value === currentElement.value
|
|
34
|
+
|| rootContext.step.value === 1
|
|
35
|
+
|| props.step % 1 === 0
|
|
36
|
+
|| props.step === rootContext.hoveredRating.value
|
|
37
|
+
|| props.step === rootContext.modelValue.value;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function handleMouseEnter() {
|
|
41
|
+
rootContext.changeHoveredRating(props.step);
|
|
42
|
+
}
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<template>
|
|
46
|
+
<ARadioGroupItem
|
|
47
|
+
:ref="forwardRef"
|
|
48
|
+
:as="as"
|
|
49
|
+
:as-child="asChild"
|
|
50
|
+
:style="{
|
|
51
|
+
['--akar-rating-item-step-width']: `${((step % 1 || 1) * 100)}%`,
|
|
52
|
+
['--akar-rating-item-step-opacity']: isVisible ? 1 : 0,
|
|
53
|
+
['--akar-rating-item-step-z-index']: itemContext.steps.value.length - itemContext.steps.value.indexOf(step),
|
|
54
|
+
|
|
55
|
+
}"
|
|
56
|
+
:value="step"
|
|
57
|
+
:data-state="isActive ? 'active' : undefined"
|
|
58
|
+
:disabled="rootContext.disabled.value"
|
|
59
|
+
@select="rootContext.changeModelValue(step)"
|
|
60
|
+
@mouseenter="handleMouseEnter"
|
|
61
|
+
>
|
|
62
|
+
<ARadioGroupIndicator
|
|
63
|
+
force-mount
|
|
64
|
+
as-child
|
|
65
|
+
>
|
|
66
|
+
<slot />
|
|
67
|
+
</ARadioGroupIndicator>
|
|
68
|
+
</ARadioGroupItem>
|
|
69
|
+
</template>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ComputedRef } from 'vue';
|
|
3
|
+
import type { APrimitiveProps } from '../primitive';
|
|
4
|
+
import { createContext } from '../shared';
|
|
5
|
+
import { injectARatingRootContext } from './rating-root.vue';
|
|
6
|
+
|
|
7
|
+
interface ARatingItemContext {
|
|
8
|
+
steps: ComputedRef<Array<number>>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ARatingItemProps extends APrimitiveProps {
|
|
12
|
+
item: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const [
|
|
16
|
+
injectARatingItemContext,
|
|
17
|
+
provideARatingItemContext,
|
|
18
|
+
] = createContext<ARatingItemContext>('ARatingItem');
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script setup lang="ts">
|
|
22
|
+
import { computed } from 'vue';
|
|
23
|
+
import { APrimitive } from '../primitive';
|
|
24
|
+
|
|
25
|
+
const props = withDefaults(
|
|
26
|
+
defineProps<ARatingItemProps>(),
|
|
27
|
+
{ as: 'label' },
|
|
28
|
+
);
|
|
29
|
+
defineSlots<{
|
|
30
|
+
default?: (props: {
|
|
31
|
+
steps: Array<number>;
|
|
32
|
+
}) => any;
|
|
33
|
+
}>();
|
|
34
|
+
|
|
35
|
+
const rootContext = injectARatingRootContext();
|
|
36
|
+
|
|
37
|
+
const steps = computed(() => {
|
|
38
|
+
const groupStartValue = (props.item - 1);
|
|
39
|
+
const groupEndValue = props.item;
|
|
40
|
+
const stepSize = rootContext.step.value;
|
|
41
|
+
|
|
42
|
+
const numberOfSteps = Math.ceil((groupEndValue - groupStartValue) / stepSize);
|
|
43
|
+
|
|
44
|
+
return Array.from({ length: numberOfSteps }, (_, index) =>
|
|
45
|
+
Number((groupStartValue + (index + 1) * stepSize).toFixed(2)));
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
provideARatingItemContext({ steps });
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<template>
|
|
52
|
+
<APrimitive
|
|
53
|
+
:as="as"
|
|
54
|
+
:as-child="asChild"
|
|
55
|
+
>
|
|
56
|
+
<slot :steps="steps" />
|
|
57
|
+
</APrimitive>
|
|
58
|
+
</template>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ARadioGroupRootProps } from '../radio-group';
|
|
3
|
+
import { createContext, useForwardExpose } from '../shared';
|
|
4
|
+
|
|
5
|
+
export interface ARatingRootContext {
|
|
6
|
+
modelValue: Ref<number>;
|
|
7
|
+
items: ComputedRef<Array<number>>;
|
|
8
|
+
hoveredRating: Ref<number>;
|
|
9
|
+
disabled: Ref<boolean>;
|
|
10
|
+
step: Ref<number>;
|
|
11
|
+
changeModelValue: (rating: number) => void;
|
|
12
|
+
changeHoveredRating: (rating: number) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ARatingRootProps extends Omit<ARadioGroupRootProps, 'modelValue' | 'defaultValue'> {
|
|
16
|
+
/**
|
|
17
|
+
* The value of the tab that should be active when initially rendered. Use when you do not need to control the state of the tabs
|
|
18
|
+
*/
|
|
19
|
+
defaultValue?: number;
|
|
20
|
+
/** The controlled value of the tab to activate. Can be bind as `v-model`. */
|
|
21
|
+
modelValue?: number;
|
|
22
|
+
length?: number;
|
|
23
|
+
clearable?: boolean;
|
|
24
|
+
hoverable?: boolean;
|
|
25
|
+
step?: 1 | 0.5 | 0.25 | 0.1;
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
export type ARatingRootEmits = {
|
|
29
|
+
/** Event handler called when the value changes */
|
|
30
|
+
'update:modelValue': [payload: number];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const [
|
|
34
|
+
injectARatingRootContext,
|
|
35
|
+
provideARatingRootContext,
|
|
36
|
+
] = createContext<ARatingRootContext>('ARatingRoot');
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<script setup lang="ts">
|
|
40
|
+
import type { ComputedRef, Ref } from 'vue';
|
|
41
|
+
import { reactiveOmit, useVModel } from '@vueuse/core';
|
|
42
|
+
import { computed, ref, toRefs } from 'vue';
|
|
43
|
+
import { ARadioGroupRoot } from '../radio-group';
|
|
44
|
+
|
|
45
|
+
const props = withDefaults(
|
|
46
|
+
defineProps<ARatingRootProps>(),
|
|
47
|
+
{
|
|
48
|
+
orientation: 'horizontal',
|
|
49
|
+
length: 5,
|
|
50
|
+
step: 1,
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const emits = defineEmits<ARatingRootEmits>();
|
|
55
|
+
|
|
56
|
+
defineSlots<{
|
|
57
|
+
default?: (props: {
|
|
58
|
+
modelValue: number | undefined;
|
|
59
|
+
items: Array<number>;
|
|
60
|
+
}) => any;
|
|
61
|
+
}>();
|
|
62
|
+
|
|
63
|
+
const { length, disabled, clearable, hoverable, step } = toRefs(props);
|
|
64
|
+
|
|
65
|
+
useForwardExpose();
|
|
66
|
+
|
|
67
|
+
const modelValue = useVModel<ARatingRootProps, 'modelValue', 'update:modelValue'>(
|
|
68
|
+
props,
|
|
69
|
+
'modelValue',
|
|
70
|
+
emits,
|
|
71
|
+
{
|
|
72
|
+
defaultValue: props.defaultValue,
|
|
73
|
+
passive: (props.modelValue === undefined) as false,
|
|
74
|
+
},
|
|
75
|
+
) as Ref<number>;
|
|
76
|
+
|
|
77
|
+
const items = computed(() => {
|
|
78
|
+
return Array.from({ length: length.value }, (_, i) => i + 1);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const hoveredRating = ref<number>(0);
|
|
82
|
+
|
|
83
|
+
function changeModelValue(rating: number) {
|
|
84
|
+
if (disabled.value) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (clearable.value && modelValue.value === rating) {
|
|
89
|
+
hoveredRating.value = 0;
|
|
90
|
+
modelValue.value = 0;
|
|
91
|
+
} else {
|
|
92
|
+
modelValue.value = rating;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function changeHoveredRating(rating: number) {
|
|
97
|
+
if (disabled.value || !hoverable.value) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
hoveredRating.value = rating;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
provideARatingRootContext({
|
|
105
|
+
modelValue,
|
|
106
|
+
items,
|
|
107
|
+
hoveredRating,
|
|
108
|
+
disabled,
|
|
109
|
+
step,
|
|
110
|
+
changeModelValue,
|
|
111
|
+
changeHoveredRating,
|
|
112
|
+
});
|
|
113
|
+
</script>
|
|
114
|
+
|
|
115
|
+
<template>
|
|
116
|
+
<ARadioGroupRoot
|
|
117
|
+
v-bind="reactiveOmit(props, 'length', 'clearable', 'hoverable', 'step')"
|
|
118
|
+
:disabled="disabled"
|
|
119
|
+
>
|
|
120
|
+
<slot
|
|
121
|
+
:items="items"
|
|
122
|
+
:model-value="modelValue"
|
|
123
|
+
/>
|
|
124
|
+
</ARadioGroupRoot>
|
|
125
|
+
</template>
|
package/src/shared/use-id.ts
CHANGED
|
@@ -18,15 +18,13 @@ export function useId(deterministicId?: null | string | undefined, prefix = 'aka
|
|
|
18
18
|
return deterministicId;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
let id: string;
|
|
21
22
|
if (Object.hasOwn(vue, 'useId')) {
|
|
22
|
-
|
|
23
|
+
id = vue.useId?.();
|
|
24
|
+
} else {
|
|
25
|
+
const configProviderContext = injectAConfigProviderContext({ useId: undefined });
|
|
26
|
+
id = configProviderContext.useId?.() ?? `${++count}`;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (configProviderContext.useId) {
|
|
28
|
-
return `${prefix}-${configProviderContext.useId()}`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return `${prefix}-${++count}`;
|
|
29
|
+
return prefix ? `${prefix}-${id}` : id;
|
|
32
30
|
}
|