@eldrajs/ui 0.0.0 → 0.1.2
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/CHANGELOG.md +1725 -0
- package/LICENSE +21 -0
- package/README.md +3177 -2
- package/dist/VariantPicker-CKw8hmxt.js +9009 -0
- package/dist/componentNames.d.ts +19 -0
- package/dist/components/accordion/Accordion.vue.d.ts +18 -0
- package/dist/components/accordion/AccordionItem.vue.d.ts +26 -0
- package/dist/components/accordion/context.d.ts +20 -0
- package/dist/components/accordion/detailsExclusivity.d.ts +3 -0
- package/dist/components/accordion/heightTransition.d.ts +59 -0
- package/dist/components/accordion/types.d.ts +40 -0
- package/dist/components/avatar/Avatar.vue.d.ts +10 -0
- package/dist/components/avatar/AvatarGroup.vue.d.ts +7 -0
- package/dist/components/avatar/types.d.ts +61 -0
- package/dist/components/badge/Badge.vue.d.ts +24 -0
- package/dist/components/badge/StockBadge.vue.d.ts +10 -0
- package/dist/components/badge/types.d.ts +79 -0
- package/dist/components/breadcrumb/Breadcrumb.vue.d.ts +10 -0
- package/dist/components/breadcrumb/types.d.ts +53 -0
- package/dist/components/button/Button.vue.d.ts +37 -0
- package/dist/components/button/ButtonGroup.vue.d.ts +17 -0
- package/dist/components/button/types.d.ts +68 -0
- package/dist/components/card/ContentCard.vue.d.ts +36 -0
- package/dist/components/card/FeatureCard.vue.d.ts +27 -0
- package/dist/components/card/cueArrow.d.ts +10 -0
- package/dist/components/card/stretchedLink.d.ts +45 -0
- package/dist/components/card/types.d.ts +92 -0
- package/dist/components/carousel/Carousel.vue.d.ts +39 -0
- package/dist/components/carousel/types.d.ts +75 -0
- package/dist/components/carousel/useCarousel.d.ts +152 -0
- package/dist/components/checkbox/Checkbox.vue.d.ts +36 -0
- package/dist/components/checkbox/CheckboxGroup.vue.d.ts +16 -0
- package/dist/components/checkbox/types.d.ts +78 -0
- package/dist/components/chip/Chip.vue.d.ts +37 -0
- package/dist/components/chip/ChipGroup.vue.d.ts +21 -0
- package/dist/components/chip/context.d.ts +22 -0
- package/dist/components/chip/types.d.ts +84 -0
- package/dist/components/container/Container.vue.d.ts +18 -0
- package/dist/components/container/types.d.ts +17 -0
- package/dist/components/currency-input/CurrencyInput.vue.d.ts +17 -0
- package/dist/components/currency-input/types.d.ts +8 -0
- package/dist/components/dialog/Dialog.vue.d.ts +34 -0
- package/dist/components/dialog/types.d.ts +25 -0
- package/dist/components/drawer/Drawer.vue.d.ts +36 -0
- package/dist/components/drawer/types.d.ts +30 -0
- package/dist/components/empty-state/EditorPlaceholder.vue.d.ts +9 -0
- package/dist/components/empty-state/EmptyState.vue.d.ts +28 -0
- package/dist/components/empty-state/types.d.ts +59 -0
- package/dist/components/field-wrapper/FieldError.vue.d.ts +37 -0
- package/dist/components/field-wrapper/FieldWrapper.vue.d.ts +30 -0
- package/dist/components/field-wrapper/context.d.ts +44 -0
- package/dist/components/field-wrapper/types.d.ts +38 -0
- package/dist/components/filter-panel/FilterGroup.vue.d.ts +48 -0
- package/dist/components/filter-panel/FilterPanel.vue.d.ts +77 -0
- package/dist/components/filter-panel/Histogram.vue.d.ts +15 -0
- package/dist/components/filter-panel/facets/ColourFacet.vue.d.ts +12 -0
- package/dist/components/filter-panel/facets/ListFacet.vue.d.ts +12 -0
- package/dist/components/filter-panel/facets/RangeFacet.vue.d.ts +20 -0
- package/dist/components/filter-panel/facets/SizeFacet.vue.d.ts +12 -0
- package/dist/components/filter-panel/facets/ToggleFacet.vue.d.ts +12 -0
- package/dist/components/filter-panel/facets/shared.d.ts +39 -0
- package/dist/components/filter-panel/northwind.d.ts +32 -0
- package/dist/components/filter-panel/swatchInk.d.ts +50 -0
- package/dist/components/filter-panel/types.d.ts +183 -0
- package/dist/components/filter-panel/useFilterPanel.d.ts +230 -0
- package/dist/components/form-layout/FormLayout.vue.d.ts +36 -0
- package/dist/components/form-layout/context.d.ts +33 -0
- package/dist/components/form-layout/focusInvalid.d.ts +18 -0
- package/dist/components/form-layout/types.d.ts +52 -0
- package/dist/components/icon/Icon.vue.d.ts +8 -0
- package/dist/components/icon/types.d.ts +29 -0
- package/dist/components/image/Image.vue.d.ts +21 -0
- package/dist/components/image/types.d.ts +81 -0
- package/dist/components/input/Input.vue.d.ts +47 -0
- package/dist/components/input/classes.d.ts +110 -0
- package/dist/components/input/types.d.ts +55 -0
- package/dist/components/internal/ValueText.vue.d.ts +7 -0
- package/dist/components/lightbox/Lightbox.vue.d.ts +19 -0
- package/dist/components/lightbox/types.d.ts +47 -0
- package/dist/components/link/Link.vue.d.ts +23 -0
- package/dist/components/link/types.d.ts +40 -0
- package/dist/components/load-more/LoadMore.vue.d.ts +12 -0
- package/dist/components/load-more/types.d.ts +21 -0
- package/dist/components/logo-item/LogoItem.vue.d.ts +10 -0
- package/dist/components/logo-item/types.d.ts +37 -0
- package/dist/components/pagination/Pagination.vue.d.ts +15 -0
- package/dist/components/pagination/types.d.ts +51 -0
- package/dist/components/popover/Popover.vue.d.ts +31 -0
- package/dist/components/popover/types.d.ts +53 -0
- package/dist/components/price/Price.vue.d.ts +25 -0
- package/dist/components/price/types.d.ts +104 -0
- package/dist/components/product-card/ProductCard.vue.d.ts +22 -0
- package/dist/components/product-card/types.d.ts +123 -0
- package/dist/components/quantity-stepper/QuantityStepper.vue.d.ts +26 -0
- package/dist/components/quantity-stepper/types.d.ts +35 -0
- package/dist/components/radio/RadioGroup.vue.d.ts +38 -0
- package/dist/components/radio/types.d.ts +39 -0
- package/dist/components/range-slider/RangeSlider.vue.d.ts +70 -0
- package/dist/components/range-slider/types.d.ts +151 -0
- package/dist/components/range-slider/useRangeSlider.d.ts +106 -0
- package/dist/components/rating/Rating.vue.d.ts +22 -0
- package/dist/components/rating/RatingStars.vue.d.ts +16 -0
- package/dist/components/rating/types.d.ts +45 -0
- package/dist/components/search-bar/SearchBar.vue.d.ts +47 -0
- package/dist/components/search-bar/SearchResultsPanel.vue.d.ts +93 -0
- package/dist/components/search-bar/shortcutOwner.d.ts +39 -0
- package/dist/components/search-bar/types.d.ts +122 -0
- package/dist/components/search-modal/SearchModal.vue.d.ts +53 -0
- package/dist/components/search-modal/types.d.ts +59 -0
- package/dist/components/section/Section.vue.d.ts +21 -0
- package/dist/components/section/context.d.ts +23 -0
- package/dist/components/section/types.d.ts +34 -0
- package/dist/components/select/MultiSelect.vue.d.ts +62 -0
- package/dist/components/select/Select.vue.d.ts +57 -0
- package/dist/components/select/SelectPanel.vue.d.ts +97 -0
- package/dist/components/select/openRegistry.d.ts +11 -0
- package/dist/components/select/panelParts.d.ts +91 -0
- package/dist/components/select/types.d.ts +129 -0
- package/dist/components/select/useListbox.d.ts +106 -0
- package/dist/components/select/useOptionList.d.ts +61 -0
- package/dist/components/select/usePopover.d.ts +147 -0
- package/dist/components/skeleton/Skeleton.vue.d.ts +12 -0
- package/dist/components/skeleton/types.d.ts +38 -0
- package/dist/components/spinner/Spinner.vue.d.ts +3 -0
- package/dist/components/switch/Switch.vue.d.ts +30 -0
- package/dist/components/switch/types.d.ts +20 -0
- package/dist/components/tabs/Tab.vue.d.ts +17 -0
- package/dist/components/tabs/TabPanel.vue.d.ts +16 -0
- package/dist/components/tabs/Tabs.vue.d.ts +28 -0
- package/dist/components/tabs/context.d.ts +48 -0
- package/dist/components/tabs/types.d.ts +63 -0
- package/dist/components/textarea/Textarea.vue.d.ts +27 -0
- package/dist/components/textarea/supportsFieldSizing.d.ts +10 -0
- package/dist/components/textarea/types.d.ts +32 -0
- package/dist/components/toast/Toast.vue.d.ts +16 -0
- package/dist/components/toast/Toaster.vue.d.ts +13 -0
- package/dist/components/toast/types.d.ts +44 -0
- package/dist/components/tooltip/Tooltip.vue.d.ts +9 -0
- package/dist/components/tooltip/supportsFocusVisible.d.ts +17 -0
- package/dist/components/tooltip/types.d.ts +46 -0
- package/dist/components/unit-input/UnitInput.vue.d.ts +55 -0
- package/dist/components/unit-input/types.d.ts +68 -0
- package/dist/components/unit-input/undo-redo.d.ts +6 -0
- package/dist/components/variant-picker/VariantPicker.vue.d.ts +15 -0
- package/dist/components/variant-picker/types.d.ts +49 -0
- package/dist/components/visually-hidden/VisuallyHidden.vue.d.ts +18 -0
- package/dist/components/visually-hidden/types.d.ts +14 -0
- package/dist/composables/dialogStack.d.ts +52 -0
- package/dist/composables/teleportTarget.d.ts +79 -0
- package/dist/composables/useControllableModel.d.ts +16 -0
- package/dist/composables/useDialog.d.ts +84 -0
- package/dist/composables/useFloating.d.ts +82 -0
- package/dist/composables/useHeadingTag.d.ts +24 -0
- package/dist/composables/useLocale.d.ts +81 -0
- package/dist/composables/useMessages.d.ts +30 -0
- package/dist/composables/useOverlay.d.ts +88 -0
- package/dist/composables/useSlotPresence.d.ts +29 -0
- package/dist/composables/useToast.d.ts +53 -0
- package/dist/icons/paths.d.ts +10 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.js +12587 -0
- package/dist/listFormat-1UrH38f2.js +39 -0
- package/dist/messages/en-US.d.ts +485 -0
- package/dist/messages/index.d.ts +2 -0
- package/dist/messages/is-IS.d.ts +16 -0
- package/dist/messages/is-IS.js +169 -0
- package/dist/resolver.d.ts +43 -0
- package/dist/resolver.js +121 -0
- package/dist/style.css +5259 -0
- package/dist/tailwind.css +2057 -0
- package/dist/tokens.css +134 -0
- package/dist/utils/avatar.d.ts +15 -0
- package/dist/utils/color.d.ts +11 -0
- package/dist/utils/cssTiming.d.ts +40 -0
- package/dist/utils/cx.d.ts +31 -0
- package/dist/utils/date.d.ts +45 -0
- package/dist/utils/id.d.ts +36 -0
- package/dist/utils/listFormat.d.ts +22 -0
- package/dist/utils/mask.d.ts +48 -0
- package/dist/utils/number-format.d.ts +250 -0
- package/dist/utils/numeric-input.d.ts +42 -0
- package/dist/utils/rating.d.ts +26 -0
- package/dist/utils/ratio.d.ts +18 -0
- package/dist/utils/tagRecipe.d.ts +24 -0
- package/dist/utils/valueFade.d.ts +42 -0
- package/dist/vee-validate/FieldCheckbox.vue.d.ts +14 -0
- package/dist/vee-validate/FieldCheckboxGroup.vue.d.ts +14 -0
- package/dist/vee-validate/FieldCurrencyInput.vue.d.ts +14 -0
- package/dist/vee-validate/FieldInput.vue.d.ts +14 -0
- package/dist/vee-validate/FieldMultiSelect.vue.d.ts +14 -0
- package/dist/vee-validate/FieldQuantityStepper.vue.d.ts +14 -0
- package/dist/vee-validate/FieldRadioGroup.vue.d.ts +14 -0
- package/dist/vee-validate/FieldSearchBar.vue.d.ts +14 -0
- package/dist/vee-validate/FieldSelect.vue.d.ts +14 -0
- package/dist/vee-validate/FieldSwitch.vue.d.ts +14 -0
- package/dist/vee-validate/FieldTextarea.vue.d.ts +14 -0
- package/dist/vee-validate/FieldUnitInput.vue.d.ts +14 -0
- package/dist/vee-validate/FieldVariantPicker.vue.d.ts +14 -0
- package/dist/vee-validate/Form.vue.d.ts +27 -0
- package/dist/vee-validate/context.d.ts +48 -0
- package/dist/vee-validate/index.d.ts +27 -0
- package/dist/vee-validate/types.d.ts +115 -0
- package/dist/vee-validate/useFieldControl.d.ts +67 -0
- package/dist/vee-validate.js +1154 -0
- package/package.json +99 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { InjectionKey } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Presence marker a `Section` provides for its own subtree: `true`, never any other value — the
|
|
4
|
+
* only question anything downstream asks of it is "is there a `Section` ancestor here at all".
|
|
5
|
+
*
|
|
6
|
+
* `Section` itself is the one reader today: it injects this optionally, and when it finds one
|
|
7
|
+
* already provided it means a `Section` has been mounted inside another `Section`, which spec
|
|
8
|
+
* "Container and section" → Behaviour & motion rules out outright ("Sections are never nested
|
|
9
|
+
* inside another section... nest containers only for full-bleed media"). It warns in development
|
|
10
|
+
* rather than throwing, the same shape as every other dev-only guard in this package (see
|
|
11
|
+
* `Button.vue`'s `iconOnly`/`label` warning) — a caller notices in local development and it never
|
|
12
|
+
* breaks a build.
|
|
13
|
+
*
|
|
14
|
+
* Exported so a future component, or a consumer's own, can ask the same question: "am I inside a
|
|
15
|
+
* `Section`" without depending on the DOM (`closest('section')` breaks the moment a caller passes
|
|
16
|
+
* `as="div"` or `as="footer"`, and cannot see through a `<Teleport>`).
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { SECTION_KEY } from '@eldrajs/ui';
|
|
20
|
+
* const insideSection = inject(SECTION_KEY, undefined) === true;
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const SECTION_KEY: InjectionKey<true>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** The spec's five grounds (spec "Container and section" → Variants). */
|
|
2
|
+
export type SectionBackground = 'none' | 'surface' | 'surface-strong' | 'primary' | 'accent';
|
|
3
|
+
/** Vertical padding steps (spec "Container and section" → Sizes, Section spacing table). */
|
|
4
|
+
export type SectionSpacing = 'none' | 'sm' | 'md' | 'lg';
|
|
5
|
+
/** The parts a consumer can restyle through `classes`. Section has only the one. */
|
|
6
|
+
export type SectionPart = 'root';
|
|
7
|
+
export interface SectionProps {
|
|
8
|
+
/** Section ground. Defaults to `none`. */
|
|
9
|
+
background?: SectionBackground;
|
|
10
|
+
/** Vertical padding. Defaults to `md`. */
|
|
11
|
+
spacing?: SectionSpacing;
|
|
12
|
+
/**
|
|
13
|
+
* Id of the visible block heading, when the block has one — typically an `<h1>`/`<h2>` the block
|
|
14
|
+
* itself renders. Renders `aria-labelledby` and, with no `as` override, a `<section>`. Wins over
|
|
15
|
+
* `ariaLabel` when both are given.
|
|
16
|
+
*/
|
|
17
|
+
labelledBy?: string | null;
|
|
18
|
+
/**
|
|
19
|
+
* Used when the block has no visible heading. Renders `aria-label` and, with no `as` override, a
|
|
20
|
+
* `<section>`. With neither this nor `labelledBy`, the root is a plain `<div>` instead — the spec's
|
|
21
|
+
* "not a meaningful region" case. Named `ariaLabel`, not `label`: this is the section's accessible
|
|
22
|
+
* name only, never visible text (unlike `label` on `Badge`/`Checkbox`/`Select` and the rest of the
|
|
23
|
+
* package — see the README's "`ariaLabel` is always an accessible name" rule).
|
|
24
|
+
*/
|
|
25
|
+
ariaLabel?: string | null;
|
|
26
|
+
/** Per-part class overrides, merged with `tailwind-merge`. */
|
|
27
|
+
classes?: Partial<Record<SectionPart, string>>;
|
|
28
|
+
/**
|
|
29
|
+
* Render as a different tag instead of the automatic `<section>`/`<div>` choice — a `<header>` for
|
|
30
|
+
* the site header, a `<footer>` for the site footer, both already unique landmarks that need no
|
|
31
|
+
* name of their own. `aria-labelledby`/`aria-label` still apply when given, independent of the tag.
|
|
32
|
+
*/
|
|
33
|
+
as?: string;
|
|
34
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { MultiSelectPart, MultiSelectProps, SelectOption, SelectSize } from './types.js';
|
|
2
|
+
declare var __VLS_6: {
|
|
3
|
+
options: SelectOption[];
|
|
4
|
+
}, __VLS_28: {
|
|
5
|
+
option: SelectOption;
|
|
6
|
+
selected: boolean;
|
|
7
|
+
active: boolean;
|
|
8
|
+
}, __VLS_31: {}, __VLS_50: {
|
|
9
|
+
option: SelectOption;
|
|
10
|
+
};
|
|
11
|
+
type __VLS_Slots = {} & {
|
|
12
|
+
value?: (props: typeof __VLS_6) => any;
|
|
13
|
+
} & {
|
|
14
|
+
option?: (props: typeof __VLS_28) => any;
|
|
15
|
+
} & {
|
|
16
|
+
empty?: (props: typeof __VLS_31) => any;
|
|
17
|
+
} & {
|
|
18
|
+
tag?: (props: typeof __VLS_50) => any;
|
|
19
|
+
};
|
|
20
|
+
declare const __VLS_base: import('vue').DefineComponent<MultiSelectProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
21
|
+
clear: () => any;
|
|
22
|
+
search: (query: string) => any;
|
|
23
|
+
"update:modelValue": (value: string[]) => any;
|
|
24
|
+
open: () => any;
|
|
25
|
+
close: () => any;
|
|
26
|
+
change: (value: string[]) => any;
|
|
27
|
+
}, string, import('vue').PublicProps, Readonly<MultiSelectProps> & Readonly<{
|
|
28
|
+
onClear?: (() => any) | undefined;
|
|
29
|
+
onSearch?: ((query: string) => any) | undefined;
|
|
30
|
+
"onUpdate:modelValue"?: ((value: string[]) => any) | undefined;
|
|
31
|
+
onOpen?: (() => any) | undefined;
|
|
32
|
+
onClose?: (() => any) | undefined;
|
|
33
|
+
onChange?: ((value: string[]) => any) | undefined;
|
|
34
|
+
}>, {
|
|
35
|
+
size: SelectSize;
|
|
36
|
+
name: string;
|
|
37
|
+
classes: Partial<Record<MultiSelectPart, string>>;
|
|
38
|
+
modelValue: string[];
|
|
39
|
+
required: boolean;
|
|
40
|
+
placeholder: string;
|
|
41
|
+
id: string;
|
|
42
|
+
leadingIcon: import('../../index.js').IconComponent;
|
|
43
|
+
disabled: boolean;
|
|
44
|
+
invalid: boolean;
|
|
45
|
+
messages: Partial<import('../../index.js').UiMessages>;
|
|
46
|
+
describedBy: string;
|
|
47
|
+
readonly: boolean;
|
|
48
|
+
searchable: boolean;
|
|
49
|
+
searchPlaceholder: string;
|
|
50
|
+
placement: import('./types.js').SelectPlacement;
|
|
51
|
+
teleport: boolean | string;
|
|
52
|
+
showTags: boolean;
|
|
53
|
+
maxSummary: number;
|
|
54
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
55
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
56
|
+
declare const _default: typeof __VLS_export;
|
|
57
|
+
export default _default;
|
|
58
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
59
|
+
new (): {
|
|
60
|
+
$slots: S;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { SelectOption, SelectProps, SelectSize } from './types.js';
|
|
2
|
+
declare var __VLS_6: {
|
|
3
|
+
option: SelectOption;
|
|
4
|
+
}, __VLS_33: {
|
|
5
|
+
option: SelectOption;
|
|
6
|
+
selected: boolean;
|
|
7
|
+
active: boolean;
|
|
8
|
+
}, __VLS_36: {};
|
|
9
|
+
type __VLS_Slots = {} & {
|
|
10
|
+
value?: (props: typeof __VLS_6) => any;
|
|
11
|
+
} & {
|
|
12
|
+
option?: (props: typeof __VLS_33) => any;
|
|
13
|
+
} & {
|
|
14
|
+
empty?: (props: typeof __VLS_36) => any;
|
|
15
|
+
};
|
|
16
|
+
declare const __VLS_base: import('vue').DefineComponent<SelectProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
17
|
+
clear: () => any;
|
|
18
|
+
search: (query: string) => any;
|
|
19
|
+
"update:modelValue": (value: string) => any;
|
|
20
|
+
open: () => any;
|
|
21
|
+
close: () => any;
|
|
22
|
+
change: (value: string) => any;
|
|
23
|
+
}, string, import('vue').PublicProps, Readonly<SelectProps> & Readonly<{
|
|
24
|
+
onClear?: (() => any) | undefined;
|
|
25
|
+
onSearch?: ((query: string) => any) | undefined;
|
|
26
|
+
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
27
|
+
onOpen?: (() => any) | undefined;
|
|
28
|
+
onClose?: (() => any) | undefined;
|
|
29
|
+
onChange?: ((value: string) => any) | undefined;
|
|
30
|
+
}>, {
|
|
31
|
+
size: SelectSize;
|
|
32
|
+
name: string;
|
|
33
|
+
classes: Partial<Record<import('./types.js').SelectPart, string>>;
|
|
34
|
+
modelValue: string;
|
|
35
|
+
required: boolean;
|
|
36
|
+
placeholder: string;
|
|
37
|
+
id: string;
|
|
38
|
+
leadingIcon: import('../../index.js').IconComponent;
|
|
39
|
+
disabled: boolean;
|
|
40
|
+
invalid: boolean;
|
|
41
|
+
messages: Partial<import('../../index.js').UiMessages>;
|
|
42
|
+
describedBy: string;
|
|
43
|
+
clearable: boolean;
|
|
44
|
+
readonly: boolean;
|
|
45
|
+
searchable: boolean;
|
|
46
|
+
searchPlaceholder: string;
|
|
47
|
+
placement: import('./types.js').SelectPlacement;
|
|
48
|
+
teleport: boolean | string;
|
|
49
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
50
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
51
|
+
declare const _default: typeof __VLS_export;
|
|
52
|
+
export default _default;
|
|
53
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
54
|
+
new (): {
|
|
55
|
+
$slots: S;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { PanelClasses } from './panelParts.js';
|
|
2
|
+
import { SelectOption } from './types.js';
|
|
3
|
+
import { MatchParts, PanelSection } from './useOptionList.js';
|
|
4
|
+
/**
|
|
5
|
+
* The popover a `Select` and a `MultiSelect` both open: the search field, the listbox with its
|
|
6
|
+
* groups and option rows, and the empty state — plus a `footer` slot, which only a multi-select
|
|
7
|
+
* fills.
|
|
8
|
+
*
|
|
9
|
+
* It exists so that the two controls share one panel rather than two copies of the same markup.
|
|
10
|
+
* Everything it knows is a prop: it owns no open/closed state, no query, no value, and no keyboard
|
|
11
|
+
* (that is `useListbox`). What it does own is the DOM the parents cannot: the panel element and
|
|
12
|
+
* the search input, both exposed so the parent can position the one and focus the other, and the
|
|
13
|
+
* pointer-press guard that keeps a press inside the panel from blurring the focused element.
|
|
14
|
+
*
|
|
15
|
+
* `multiple` is the one behavioural switch, and it is the spec's own: a multi-select's rows carry a
|
|
16
|
+
* checkbox instead of a trailing check mark, and its listbox is `aria-multiselectable="true"`.
|
|
17
|
+
*/
|
|
18
|
+
type __VLS_Props = {
|
|
19
|
+
/**
|
|
20
|
+
* The panel element's own id, which is also its `data-eldra-overlay-owner`. `useOverlay`
|
|
21
|
+
* reads that attribute to recognise parts of an overlay that are not inside its content
|
|
22
|
+
* element — and, since this panel is normally teleported to `body`, it is what marks anything
|
|
23
|
+
* a consumer teleports out of the panel's own slots as still belonging to the overlay.
|
|
24
|
+
*/
|
|
25
|
+
panelId: string;
|
|
26
|
+
/** The listbox's id — what the trigger's `aria-controls` points at. */
|
|
27
|
+
listboxId: string;
|
|
28
|
+
/** The visible options, already filtered and bucketed into their groups. */
|
|
29
|
+
sections: PanelSection[];
|
|
30
|
+
/** Whether any option is visible at all. */
|
|
31
|
+
hasOptions: boolean;
|
|
32
|
+
/** Per option value, where the query matched its label. */
|
|
33
|
+
highlights: Map<string, MatchParts | null>;
|
|
34
|
+
/** The element id of a row, which is what `aria-activedescendant` points at. */
|
|
35
|
+
optionId: (value: string) => string;
|
|
36
|
+
/** The active row's value, or `undefined`. */
|
|
37
|
+
activeValue?: string;
|
|
38
|
+
/** Every selected value. A single select passes exactly one. */
|
|
39
|
+
selectedValues: string[];
|
|
40
|
+
/** Whether the search field shows, and what is in it. */
|
|
41
|
+
searchable: boolean;
|
|
42
|
+
query: string;
|
|
43
|
+
searchPlaceholder: string;
|
|
44
|
+
/** The empty state's text ("No matches for “teal”"). */
|
|
45
|
+
emptyText: string;
|
|
46
|
+
/** The visible label's id, for the listbox's own name; `fallbackLabel` when there is none. */
|
|
47
|
+
labelledBy?: string;
|
|
48
|
+
fallbackLabel?: string;
|
|
49
|
+
/** Checkbox rows and `aria-multiselectable="true"`. */
|
|
50
|
+
multiple?: boolean;
|
|
51
|
+
/** Inline position from `useFloating`, and the placement it resolved to. */
|
|
52
|
+
panelStyle?: Record<string, string>;
|
|
53
|
+
placement?: string;
|
|
54
|
+
classes?: PanelClasses;
|
|
55
|
+
};
|
|
56
|
+
declare var __VLS_1: {
|
|
57
|
+
option: SelectOption;
|
|
58
|
+
selected: boolean;
|
|
59
|
+
active: boolean;
|
|
60
|
+
}, __VLS_8: {}, __VLS_10: {};
|
|
61
|
+
type __VLS_Slots = {} & {
|
|
62
|
+
option?: (props: typeof __VLS_1) => any;
|
|
63
|
+
} & {
|
|
64
|
+
empty?: (props: typeof __VLS_8) => any;
|
|
65
|
+
} & {
|
|
66
|
+
footer?: (props: typeof __VLS_10) => any;
|
|
67
|
+
};
|
|
68
|
+
declare const __VLS_base: import('vue').DefineComponent<__VLS_Props, {
|
|
69
|
+
root: import('vue').Ref<HTMLElement | null, HTMLElement | null>;
|
|
70
|
+
searchInput: import('vue').Ref<HTMLInputElement | null, HTMLInputElement | null>;
|
|
71
|
+
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
72
|
+
select: (option: SelectOption) => any;
|
|
73
|
+
search: (query: string) => any;
|
|
74
|
+
keydown: (event: KeyboardEvent) => any;
|
|
75
|
+
activate: (value: string) => any;
|
|
76
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
77
|
+
onSelect?: ((option: SelectOption) => any) | undefined;
|
|
78
|
+
onSearch?: ((query: string) => any) | undefined;
|
|
79
|
+
onKeydown?: ((event: KeyboardEvent) => any) | undefined;
|
|
80
|
+
onActivate?: ((value: string) => any) | undefined;
|
|
81
|
+
}>, {
|
|
82
|
+
multiple: boolean;
|
|
83
|
+
classes: PanelClasses;
|
|
84
|
+
panelStyle: Record<string, string>;
|
|
85
|
+
labelledBy: string;
|
|
86
|
+
placement: string;
|
|
87
|
+
activeValue: string;
|
|
88
|
+
fallbackLabel: string;
|
|
89
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
90
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
91
|
+
declare const _default: typeof __VLS_export;
|
|
92
|
+
export default _default;
|
|
93
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
94
|
+
new (): {
|
|
95
|
+
$slots: S;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claim the slot and close whatever held it.
|
|
3
|
+
*
|
|
4
|
+
* The slot is reassigned *before* the previous popup is closed, so the `unregisterOpen` that
|
|
5
|
+
* closing triggers sees a slot that is no longer its own and leaves the new owner alone.
|
|
6
|
+
*/
|
|
7
|
+
export declare function registerOpen(close: () => void): void;
|
|
8
|
+
/** Release the slot, if it is still this popup's. */
|
|
9
|
+
export declare function unregisterOpen(close: () => void): void;
|
|
10
|
+
/** The currently open popup's close function, or `null`. Exposed for tests. */
|
|
11
|
+
export declare function currentOpen(): (() => void) | null;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { SelectOption, SelectPart } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The `classes` prop of any control in the select family.
|
|
4
|
+
*
|
|
5
|
+
* `MultiSelectPart` is a superset of `SelectPart`, so a multi-select's own `classes` object is
|
|
6
|
+
* assignable to this without a cast — and the panel parts are named the same in both controls,
|
|
7
|
+
* which is the point: a consumer styles `option` once and both controls take it.
|
|
8
|
+
*/
|
|
9
|
+
export type PanelClasses = Partial<Record<SelectPart, string>>;
|
|
10
|
+
/**
|
|
11
|
+
* Every class the **panel** of a select draws, in one place, because `Select` and `MultiSelect`
|
|
12
|
+
* draw the same panel. They are plain functions rather than computeds so that both `SelectPanel`
|
|
13
|
+
* (which renders the panel) and a trigger (which reuses an option's swatch and icon for the chosen
|
|
14
|
+
* option's mark) can call them.
|
|
15
|
+
*
|
|
16
|
+
* Each ends in `partClass`, so a consumer's per-part override merges over ours through
|
|
17
|
+
* `tailwind-merge` rather than landing beside it.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The popover (spec "Select" → Sizes, Popover row). Not a dialog: it is a non-modal popup
|
|
21
|
+
* (non-negotiable 2), positioned by `useFloating` against the trigger.
|
|
22
|
+
*
|
|
23
|
+
* It is **teleported** — to `body`, or to the open `<dialog>` the control sits in — so that no
|
|
24
|
+
* ancestor's `overflow: hidden` clips it and no later stacking context paints over it. `absolute`
|
|
25
|
+
* stays in the class list because it is what a `teleport: false` panel needs; the inline
|
|
26
|
+
* `position` `useFloating` writes (`fixed` once teleported) is on the element itself and wins
|
|
27
|
+
* over it either way. `z-popover` puts it over the sticky header, `overflow-hidden` keeps the
|
|
28
|
+
* search field's top corners on the popover's radius, and the list — not the panel — is what
|
|
29
|
+
* scrolls.
|
|
30
|
+
*
|
|
31
|
+
* Because the panel leaves the control's subtree, a consumer's `classes`/`data-part` styling still
|
|
32
|
+
* reaches it (both are on the element), but a **descendant selector rooted above the control does
|
|
33
|
+
* not**, and neither do custom properties set on a wrapper: set `--eldra-*` overrides on `:root`
|
|
34
|
+
* (or on the teleport target), which is what the README's Customisation section already asks for.
|
|
35
|
+
*/
|
|
36
|
+
export declare function panelClass(classes: PanelClasses | undefined): string;
|
|
37
|
+
/** Spec "Select" → Sizes, Search field: 2.5rem tall, text from 2.125rem, inset focus ring. */
|
|
38
|
+
export declare function searchClass(classes: PanelClasses | undefined): string;
|
|
39
|
+
export declare function listboxClass(classes: PanelClasses | undefined, hasOptions: boolean): string;
|
|
40
|
+
/** Spec: "Every group after the first gets a 1px `border` hairline and 0.25rem gap above it." */
|
|
41
|
+
export declare function groupClass(classes: PanelClasses | undefined, index: number): string;
|
|
42
|
+
export declare function groupLabelClass(classes: PanelClasses | undefined, index: number): string;
|
|
43
|
+
/**
|
|
44
|
+
* Spec "Select" → Sizes, Option row, and → States for active / selected / disabled.
|
|
45
|
+
*
|
|
46
|
+
* `multiple` is the one difference the spec draws between the two controls' rows: a multi-select's
|
|
47
|
+
* selection is carried by the filled box, so its label is "weight 500 (not 600)" (spec
|
|
48
|
+
* "Multi-select" → States, Option selected).
|
|
49
|
+
*/
|
|
50
|
+
export declare function optionClass(classes: PanelClasses | undefined, option: SelectOption, state: {
|
|
51
|
+
active: boolean;
|
|
52
|
+
selected: boolean;
|
|
53
|
+
multiple: boolean;
|
|
54
|
+
}): string;
|
|
55
|
+
export declare function optionLabelClass(classes: PanelClasses | undefined, option: SelectOption): string;
|
|
56
|
+
export declare function optionHintClass(classes: PanelClasses | undefined): string;
|
|
57
|
+
export declare function optionMetaClass(classes: PanelClasses | undefined, option: SelectOption): string;
|
|
58
|
+
export declare function optionSwatchClass(classes: PanelClasses | undefined): string;
|
|
59
|
+
export declare function optionIconClass(classes: PanelClasses | undefined): string;
|
|
60
|
+
/** Spec "Select" → States, Option selected: "check mark in `text` (never colour alone)". */
|
|
61
|
+
export declare function optionCheckClass(classes: PanelClasses | undefined): string;
|
|
62
|
+
/**
|
|
63
|
+
* A multi-select option's checkbox (spec "Multi-select" → Sizes, "Checkbox in option"): "1rem
|
|
64
|
+
* square, 1.5px `border-strong`, 0.25rem radius, `background` fill. Checked: `primary` fill and
|
|
65
|
+
* border with a `primary-contrast` tick."
|
|
66
|
+
*
|
|
67
|
+
* It is the `optionCheck` part — the same part a single select's check mark is — so "the mark that
|
|
68
|
+
* says this row is chosen" is one styling hook in both controls. The border width is `Checkbox`'s
|
|
69
|
+
* own `eldra-checkbox-border`, so a consumer that has restyled their checkboxes' boundary has
|
|
70
|
+
* restyled these; the radius is the spec's smaller 0.25rem, on its own variable.
|
|
71
|
+
*/
|
|
72
|
+
export declare function optionBoxClass(classes: PanelClasses | undefined, state: {
|
|
73
|
+
selected: boolean;
|
|
74
|
+
disabled: boolean;
|
|
75
|
+
}): string;
|
|
76
|
+
/** Spec "Select" → Sizes, Empty state: "0.875rem, `muted`, centred, padding 1rem 0.75rem". */
|
|
77
|
+
export declare function emptyClass(classes: PanelClasses | undefined): string;
|
|
78
|
+
/**
|
|
79
|
+
* The tick inside that box (spec "Multi-select" → Sizes: "a `primary-contrast` tick (0.25 × 0.5rem,
|
|
80
|
+
* 2px stroke)").
|
|
81
|
+
*
|
|
82
|
+
* The svg is drawn 0.5rem square — `size-2` on the 0.25rem spacing step — over an 8 × 8 viewBox,
|
|
83
|
+
* so one viewBox unit is one pixel of the drawn mark and `stroke-width="2"` is the spec's 2px.
|
|
84
|
+
* (The same relationship `Checkbox` has at its own larger size; a 10-unit viewBox squeezed into
|
|
85
|
+
* 0.5rem would render that same `2` as 1.6px.) The mark is Tabler's check at 3 : 2 — 0.5 × 0.375rem
|
|
86
|
+
* of ink rather than the spec's literal 0.5 × 0.25rem, which read flat (see `Checkbox.vue`).
|
|
87
|
+
*
|
|
88
|
+
* It is always rendered and scaled from 0, rather than added and removed, so it can grow in over
|
|
89
|
+
* `duration-fast` the way `Checkbox`'s does.
|
|
90
|
+
*/
|
|
91
|
+
export declare function optionTickClass(selected: boolean): string;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { UiMessages } from '../../composables/useMessages.js';
|
|
2
|
+
import { IconComponent } from '../icon/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* One option of a `Select`.
|
|
5
|
+
*
|
|
6
|
+
* Everything past `value`/`label` is the spec's "Rich options" variant: a `swatch` (a colour from
|
|
7
|
+
* product data), an `icon`, a `hint` line under the label, a `meta` note aligned to the end, and
|
|
8
|
+
* `disabled` for a sold-out choice — which the spec asks to *show*, struck through with its
|
|
9
|
+
* reason, rather than hide.
|
|
10
|
+
*/
|
|
11
|
+
export interface SelectOption {
|
|
12
|
+
/** The value posted, and the one `modelValue` holds when this option is chosen. */
|
|
13
|
+
value: string;
|
|
14
|
+
/** The visible label. Also what type-ahead and the search field match against. */
|
|
15
|
+
label: string;
|
|
16
|
+
/** Group heading this option belongs under. Builds an `<optgroup>` on the native select too. */
|
|
17
|
+
group?: string;
|
|
18
|
+
/** A secondary line under the label ("Next business day if ordered by 2pm"). */
|
|
19
|
+
hint?: string;
|
|
20
|
+
/** A note aligned to the end of the row ("In stock", "Only 2 left", "Sold out"). */
|
|
21
|
+
meta?: string;
|
|
22
|
+
/** The meta's tone. `muted` by default; `warning` and `danger` are weight 600. */
|
|
23
|
+
metaTone?: 'warning' | 'danger';
|
|
24
|
+
/** A colour from product data, drawn as a 1rem circle with a 1px inner edge. Any CSS colour. */
|
|
25
|
+
swatch?: string;
|
|
26
|
+
/** A decorative icon for this option, shown in the row and in the trigger when it is chosen. */
|
|
27
|
+
icon?: IconComponent;
|
|
28
|
+
/** Sold out / unavailable. Skipped by the arrow keys, cannot be chosen, struck through. */
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The parts a consumer can restyle through `classes`, named as the spec's anatomy names them.
|
|
33
|
+
*
|
|
34
|
+
* `optionIcon` is not in the anatomy's numbered list — the list names the option's contents in
|
|
35
|
+
* prose ("swatch, icon, label + hint, meta, check") — but it is a part all the same, and the
|
|
36
|
+
* trigger reuses `optionSwatch`/`optionIcon` for the chosen option's mark, so "an option's swatch"
|
|
37
|
+
* is styled once wherever it appears.
|
|
38
|
+
*
|
|
39
|
+
* `native` is the odd one out: it marks the hidden native `<select>` with a `data-part` so a test
|
|
40
|
+
* or a form helper can find it, but the element is `hidden`, so `classes.native` merges onto
|
|
41
|
+
* nothing and has no effect. Every other part takes classes.
|
|
42
|
+
*/
|
|
43
|
+
export type SelectPart = 'root' | 'trigger' | 'leadingIcon' | 'value' | 'placeholder' | 'chevron' | 'clearButton' | 'panel' | 'search' | 'listbox' | 'group' | 'groupLabel' | 'option' | 'optionLabel' | 'optionHint' | 'optionMeta' | 'optionSwatch' | 'optionIcon' | 'optionCheck' | 'empty' | 'native';
|
|
44
|
+
/** The shared control box, exactly as `Input`'s: 2rem, 2.5rem or 3rem tall. */
|
|
45
|
+
export type SelectSize = 'sm' | 'md' | 'lg';
|
|
46
|
+
/**
|
|
47
|
+
* `auto` opens below and flips above when there is no room; `above` always opens above (the
|
|
48
|
+
* spec's example is a footer's language selector, where below is off-screen by definition).
|
|
49
|
+
*/
|
|
50
|
+
export type SelectPlacement = 'auto' | 'above';
|
|
51
|
+
export interface SelectProps {
|
|
52
|
+
/** The selected value (two-way). `''` means nothing is selected. */
|
|
53
|
+
modelValue?: string;
|
|
54
|
+
/** The options. `group` builds headings here and `<optgroup>`s on the native select. */
|
|
55
|
+
options: SelectOption[];
|
|
56
|
+
/** Form field name, put on the hidden native `<select>`. */
|
|
57
|
+
name?: string;
|
|
58
|
+
/** The trigger's `id`. Comes from a `FieldWrapper` when there is one. */
|
|
59
|
+
id?: string;
|
|
60
|
+
/** One of the spec's three sizes. Defaults to `md`. */
|
|
61
|
+
size?: SelectSize;
|
|
62
|
+
/** Adds the search field. Defaults to `true` when there are more than 10 options. */
|
|
63
|
+
searchable?: boolean;
|
|
64
|
+
/** The search field's placeholder *and* its accessible name ("Search countries"). */
|
|
65
|
+
searchPlaceholder?: string;
|
|
66
|
+
/** Shows the clear button while there is a value. `Backspace`/`Delete` clear too. */
|
|
67
|
+
clearable?: boolean;
|
|
68
|
+
/** Shown in `muted` when there is no value. Never an option in the list. */
|
|
69
|
+
placeholder?: string;
|
|
70
|
+
/** A decorative icon at the start of the trigger. */
|
|
71
|
+
leadingIcon?: IconComponent;
|
|
72
|
+
/** Error state. Usually passed down from the `FieldWrapper`. */
|
|
73
|
+
invalid?: boolean;
|
|
74
|
+
/** Copied to the trigger as `aria-describedby`. Usually from the `FieldWrapper`. */
|
|
75
|
+
describedBy?: string;
|
|
76
|
+
/** `aria-required="true"` on the trigger and `required` on the native select. */
|
|
77
|
+
required?: boolean;
|
|
78
|
+
/** Not focusable, does not open. */
|
|
79
|
+
disabled?: boolean;
|
|
80
|
+
/** The value is readable but fixed: no chevron, does not open. */
|
|
81
|
+
readonly?: boolean;
|
|
82
|
+
/** `auto` (default) flips above when there is no room below; `above` always opens above. */
|
|
83
|
+
placement?: SelectPlacement;
|
|
84
|
+
/**
|
|
85
|
+
* Where the panel is rendered. `true` (default) teleports it to `document.body` — or to the
|
|
86
|
+
* open native `<dialog>` the control sits in, which renders in the browser's top layer and
|
|
87
|
+
* would otherwise cover it. A string is a CSS selector for your own target. `false` keeps the
|
|
88
|
+
* panel inside the control, which is only right when nothing above it clips or stacks over it.
|
|
89
|
+
*
|
|
90
|
+
* Read once, like `placement`.
|
|
91
|
+
*/
|
|
92
|
+
teleport?: boolean | string;
|
|
93
|
+
/** Message overrides for this control alone. */
|
|
94
|
+
messages?: Partial<UiMessages>;
|
|
95
|
+
/** Per-part class overrides, merged with `tailwind-merge`. */
|
|
96
|
+
classes?: Partial<Record<SelectPart, string>>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A `MultiSelect`'s parts: every part of a `Select` plus the ones only a multi-select draws.
|
|
100
|
+
*
|
|
101
|
+
* `optionCheck` is reused for an option's **checkbox** — it is the mark that says "this row is
|
|
102
|
+
* chosen" in both controls, so a consumer styles it once. The footer parts are not in the API contract's
|
|
103
|
+
* list but are in the spec's anatomy ("footer: live count · Clear (link button) · Done (primary
|
|
104
|
+
* sm)"), and a part the component draws and a consumer cannot reach is not a part.
|
|
105
|
+
*
|
|
106
|
+
* Two inherited names draw nothing here. `value` is a `Select`'s chosen-option row; a multi-select
|
|
107
|
+
* draws `summary` (the labels and the "+N" pill) in its place, so `classes.value` has no effect.
|
|
108
|
+
* `native` is a `data-part` marker on a `hidden` element in both controls, so `classes.native` has
|
|
109
|
+
* none either. Both are kept in the union rather than subtracted from it, so that one `classes`
|
|
110
|
+
* object can be handed to either control.
|
|
111
|
+
*/
|
|
112
|
+
export type MultiSelectPart = SelectPart | 'summary' | 'summaryMore' | 'tags' | 'tag' | 'tagRemove' | 'footer' | 'footerCount' | 'footerClear' | 'footerDone';
|
|
113
|
+
/**
|
|
114
|
+
* Everything a `Select` takes except the three the spec redefines: the value is a list, the
|
|
115
|
+
* placeholder's default is `"Any"` rather than `"Select"`, and there is no `clearable` — "the clear
|
|
116
|
+
* button is always available when something is selected".
|
|
117
|
+
*/
|
|
118
|
+
export interface MultiSelectProps extends Omit<SelectProps, 'modelValue' | 'placeholder' | 'clearable'> {
|
|
119
|
+
/** The selected values (two-way). `[]` means nothing is selected. */
|
|
120
|
+
modelValue?: string[];
|
|
121
|
+
/** Shown in `muted` when nothing is selected ("Any colour"). */
|
|
122
|
+
placeholder?: string;
|
|
123
|
+
/** The removable tag list under the control. `false` for compact toolbars. */
|
|
124
|
+
showTags?: boolean;
|
|
125
|
+
/** How many labels the trigger lists before the "+N" pill. Defaults to 2. */
|
|
126
|
+
maxSummary?: number;
|
|
127
|
+
/** Per-part class overrides, merged with `tailwind-merge`. */
|
|
128
|
+
classes?: Partial<Record<MultiSelectPart, string>>;
|
|
129
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* The least a listbox row has to be for this composable to move between rows. `Select`'s
|
|
4
|
+
* `SelectOption` is a superset of it, and `MultiSelect`'s will be too — which is the point: the
|
|
5
|
+
* keyboard lives here once, and each control supplies its own rows and its own idea of what
|
|
6
|
+
* choosing one means.
|
|
7
|
+
*/
|
|
8
|
+
export interface ListboxOption {
|
|
9
|
+
value: string;
|
|
10
|
+
label: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface UseListboxOptions<T extends ListboxOption = ListboxOption> {
|
|
14
|
+
/** The rows currently on screen, in DOM order, already filtered by any search query. */
|
|
15
|
+
options: () => T[];
|
|
16
|
+
/** Whether the popup is open. The keyboard table is two different tables either side of this. */
|
|
17
|
+
isOpen: () => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the control can open at all. Default `true`.
|
|
20
|
+
*
|
|
21
|
+
* A read-only or disabled select still has a focusable trigger, and the closed keyboard table
|
|
22
|
+
* `preventDefault()`s before it asks the caller to open — so without this the trigger swallowed
|
|
23
|
+
* `ArrowDown`, `Enter`, `Space` and every printable key and did nothing with them, which is a
|
|
24
|
+
* keyboard dead end on a control the user can still `Tab` to. When this says no, the closed table
|
|
25
|
+
* is not consulted at all: nothing is prevented and nothing becomes active.
|
|
26
|
+
*/
|
|
27
|
+
canOpen?: () => boolean;
|
|
28
|
+
/** Whether a search field is showing: it owns `Home`/`End`, `Space` and every printable key. */
|
|
29
|
+
searchable: () => boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The element id of a row, which is what `aria-activedescendant` points at. `undefined` for a
|
|
32
|
+
* value that has no row on screen — an active row the list has just dropped — so the caller can
|
|
33
|
+
* leave the attribute off rather than point it at an element that is not there.
|
|
34
|
+
*/
|
|
35
|
+
optionId: (value: string) => string | undefined;
|
|
36
|
+
/** Open the popup. `edge` is `'end'` for `ArrowUp` on a closed non-searchable trigger. */
|
|
37
|
+
open: (edge: 'start' | 'end') => void;
|
|
38
|
+
/** Close the popup without choosing anything. */
|
|
39
|
+
close: () => void;
|
|
40
|
+
/** Choose a row. Whether that also closes the popup is the caller's business, not ours. */
|
|
41
|
+
select: (option: T) => void;
|
|
42
|
+
/** `Backspace`/`Delete` on a closed trigger. Return `true` if the value was actually cleared. */
|
|
43
|
+
clear?: () => boolean;
|
|
44
|
+
/** Searchable + closed + a printable key: start the query with it. */
|
|
45
|
+
startQuery?: (character: string) => void;
|
|
46
|
+
/** `Escape` while open. Return `true` if a query was cleared, which consumes the key. */
|
|
47
|
+
escape?: () => boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface UseListboxReturn {
|
|
50
|
+
/** The active row's value — the one `aria-activedescendant` points at. */
|
|
51
|
+
activeValue: Ref<string | undefined>;
|
|
52
|
+
/** The active row's element id, or `undefined` when nothing is active. */
|
|
53
|
+
activeId: ComputedRef<string | undefined>;
|
|
54
|
+
/** Make a row active, e.g. because the pointer moved over it. */
|
|
55
|
+
setActive(value: string | undefined): void;
|
|
56
|
+
/** Make the given value active if it is selectable, else the first enabled row. */
|
|
57
|
+
activateFrom(value: string | undefined): void;
|
|
58
|
+
/** First / last enabled row. */
|
|
59
|
+
first(): void;
|
|
60
|
+
last(): void;
|
|
61
|
+
/** Move by `step` enabled rows, stopping at the ends (the spec: "it doesn't wrap"). */
|
|
62
|
+
move(step: number): void;
|
|
63
|
+
/** Choose the active row, if there is one and it can be chosen. */
|
|
64
|
+
selectActive(): void;
|
|
65
|
+
/** The whole keyboard table, both halves. Put it on the trigger and on the search field. */
|
|
66
|
+
onKeydown(event: KeyboardEvent): void;
|
|
67
|
+
/** Drop the type-ahead buffer (on open and on close, so a stale prefix never leaks). */
|
|
68
|
+
resetTypeahead(): void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Case- and diacritic-insensitive, so the spec's "'island' finds 'Ísland'" holds for type-ahead
|
|
72
|
+
* and for the search field alike. `NFD` splits a letter from its accent and the range drops the
|
|
73
|
+
* combining marks that are left.
|
|
74
|
+
*/
|
|
75
|
+
export declare function normalizeText(text: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* The keyboard and the active row of a listbox popup — everything in the design spec's Select →
|
|
78
|
+
* Keyboard tables that is not about *what* choosing a row does.
|
|
79
|
+
*
|
|
80
|
+
* It is separate from `Select.vue` on purpose. `MultiSelect` (the next component) has the same two
|
|
81
|
+
* keyboard tables with three differences — `Enter` toggles instead of choosing-and-closing,
|
|
82
|
+
* `Space` toggles, and the popup stays open — all of which are the caller's `select` callback and
|
|
83
|
+
* the caller's decision about closing. Everything else (arrow movement that skips disabled and
|
|
84
|
+
* filtered-out rows and stops at the ends, `PageUp`/`PageDown` by ten, `Home`/`End` unless a
|
|
85
|
+
* search field owns them, `Alt+ArrowUp`, `Escape` clearing a query before it closes, `Tab`
|
|
86
|
+
* closing without a choice, and type-ahead with a 0.6s buffer) is identical, and identical code
|
|
87
|
+
* that is written twice stops being identical.
|
|
88
|
+
*
|
|
89
|
+
* The composable owns no DOM. `aria-activedescendant` is `activeId`, which the caller binds to
|
|
90
|
+
* whichever element is focused — the trigger when there is no search field, the search field when
|
|
91
|
+
* there is — and scrolling the active row into view is the caller's, because only the caller knows
|
|
92
|
+
* which element a value maps to.
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* const listbox = useListbox({
|
|
96
|
+
* options: () => visibleOptions.value,
|
|
97
|
+
* isOpen: () => open.value,
|
|
98
|
+
* searchable: () => searchable.value,
|
|
99
|
+
* optionId: (value) => `${id.value}-option-${value}`,
|
|
100
|
+
* open: (edge) => openPanel(edge),
|
|
101
|
+
* close: () => closePanel(),
|
|
102
|
+
* select: (option) => choose(option.value),
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function useListbox<T extends ListboxOption>(options: UseListboxOptions<T>): UseListboxReturn;
|