@ariakit/components 0.1.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/CHANGELOG.md +19 -0
- package/dist/checkbox/checkbox-store.d.ts +47 -0
- package/dist/checkbox/checkbox-store.d.ts.map +1 -0
- package/dist/checkbox/checkbox-store.js +16 -0
- package/dist/checkbox/checkbox-store.js.map +1 -0
- package/dist/collection/collection-store.d.ts +2 -0
- package/dist/collection/collection-store.js +132 -0
- package/dist/collection/collection-store.js.map +1 -0
- package/dist/collection-store-yNe83BiS.d.ts +81 -0
- package/dist/collection-store-yNe83BiS.d.ts.map +1 -0
- package/dist/combobox/combobox-store.d.ts +150 -0
- package/dist/combobox/combobox-store.d.ts.map +1 -0
- package/dist/combobox/combobox-store.js +83 -0
- package/dist/combobox/combobox-store.js.map +1 -0
- package/dist/composite/composite-overflow-store.d.ts +16 -0
- package/dist/composite/composite-overflow-store.d.ts.map +1 -0
- package/dist/composite/composite-overflow-store.js +12 -0
- package/dist/composite/composite-overflow-store.js.map +1 -0
- package/dist/composite/composite-store.d.ts +2 -0
- package/dist/composite/composite-store.js +167 -0
- package/dist/composite/composite-store.js.map +1 -0
- package/dist/composite-store-B-iDEtZZ.d.ts +331 -0
- package/dist/composite-store-B-iDEtZZ.d.ts.map +1 -0
- package/dist/dialog/dialog-store.d.ts +2 -0
- package/dist/dialog/dialog-store.js +12 -0
- package/dist/dialog/dialog-store.js.map +1 -0
- package/dist/dialog-store-BOLvw2IX.d.ts +16 -0
- package/dist/dialog-store-BOLvw2IX.d.ts.map +1 -0
- package/dist/disclosure/disclosure-store.d.ts +2 -0
- package/dist/disclosure/disclosure-store.js +47 -0
- package/dist/disclosure/disclosure-store.js.map +1 -0
- package/dist/disclosure-store-xKlQffR0.d.ts +142 -0
- package/dist/disclosure-store-xKlQffR0.d.ts.map +1 -0
- package/dist/form/form-store.d.ts +247 -0
- package/dist/form/form-store.d.ts.map +1 -0
- package/dist/form/form-store.js +211 -0
- package/dist/form/form-store.js.map +1 -0
- package/dist/form/types.d.ts +37 -0
- package/dist/form/types.d.ts.map +1 -0
- package/dist/form/types.js +0 -0
- package/dist/hovercard/hovercard-store.d.ts +65 -0
- package/dist/hovercard/hovercard-store.d.ts.map +1 -0
- package/dist/hovercard/hovercard-store.js +31 -0
- package/dist/hovercard/hovercard-store.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/menu/menu-bar-store.d.ts +16 -0
- package/dist/menu/menu-bar-store.d.ts.map +1 -0
- package/dist/menu/menu-bar-store.js +12 -0
- package/dist/menu/menu-bar-store.js.map +1 -0
- package/dist/menu/menu-store.d.ts +100 -0
- package/dist/menu/menu-store.d.ts.map +1 -0
- package/dist/menu/menu-store.js +74 -0
- package/dist/menu/menu-store.js.map +1 -0
- package/dist/menubar/menubar-store.d.ts +2 -0
- package/dist/menubar/menubar-store.js +24 -0
- package/dist/menubar/menubar-store.js.map +1 -0
- package/dist/menubar-store-CD3YDYfW.d.ts +16 -0
- package/dist/menubar-store-CD3YDYfW.d.ts.map +1 -0
- package/dist/popover/popover-store.d.ts +2 -0
- package/dist/popover/popover-store.js +44 -0
- package/dist/popover/popover-store.js.map +1 -0
- package/dist/popover-store-DoCiTmUQ.d.ts +106 -0
- package/dist/popover-store-DoCiTmUQ.d.ts.map +1 -0
- package/dist/radio/radio-store.d.ts +42 -0
- package/dist/radio/radio-store.d.ts.map +1 -0
- package/dist/radio/radio-store.js +27 -0
- package/dist/radio/radio-store.js.map +1 -0
- package/dist/select/select-store.d.ts +116 -0
- package/dist/select/select-store.d.ts.map +1 -0
- package/dist/select/select-store.js +93 -0
- package/dist/select/select-store.js.map +1 -0
- package/dist/tab/tab-store.d.ts +127 -0
- package/dist/tab/tab-store.d.ts.map +1 -0
- package/dist/tab/tab-store.js +107 -0
- package/dist/tab/tab-store.js.map +1 -0
- package/dist/tag/tag-store.d.ts +2 -0
- package/dist/tag/tag-store.js +60 -0
- package/dist/tag/tag-store.js.map +1 -0
- package/dist/tag-store-D47X5_zA.d.ts +83 -0
- package/dist/tag-store-D47X5_zA.d.ts.map +1 -0
- package/dist/toolbar/toolbar-store.d.ts +21 -0
- package/dist/toolbar/toolbar-store.d.ts.map +1 -0
- package/dist/toolbar/toolbar-store.js +18 -0
- package/dist/toolbar/toolbar-store.js.map +1 -0
- package/dist/tooltip/tooltip-store.d.ts +35 -0
- package/dist/tooltip/tooltip-store.d.ts.map +1 -0
- package/dist/tooltip/tooltip-store.js +29 -0
- package/dist/tooltip/tooltip-store.js.map +1 -0
- package/license +21 -0
- package/package.json +121 -0
- package/readme.md +19 -0
- package/src/checkbox/checkbox-store.ts +93 -0
- package/src/collection/collection-store.ts +301 -0
- package/src/combobox/combobox-store.ts +382 -0
- package/src/composite/composite-overflow-store.ts +30 -0
- package/src/composite/composite-store.ts +711 -0
- package/src/dialog/dialog-store.ts +26 -0
- package/src/disclosure/disclosure-store.ts +226 -0
- package/src/form/form-store.ts +608 -0
- package/src/form/types.ts +44 -0
- package/src/hovercard/hovercard-store.ts +112 -0
- package/src/index.ts +1 -0
- package/src/menu/menu-bar-store.ts +28 -0
- package/src/menu/menu-store.ts +263 -0
- package/src/menubar/menubar-store.ts +51 -0
- package/src/popover/popover-store.ts +170 -0
- package/src/radio/radio-store.ts +80 -0
- package/src/select/select-store.ts +323 -0
- package/src/tab/tab-store.ts +330 -0
- package/src/tag/tag-store.ts +170 -0
- package/src/toolbar/toolbar-store.ts +47 -0
- package/src/tooltip/tooltip-store.ts +93 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-store.js","names":[],"sources":["../../src/select/select-store.ts"],"sourcesContent":["import {\n batch,\n createStore,\n mergeStore,\n omit,\n setup,\n sync,\n throwOnConflictingProps,\n} from \"@ariakit/store\";\nimport type { Store, StoreOptions, StoreProps } from \"@ariakit/store\";\nimport { toArray, defaultValue } from \"@ariakit/utils\";\nimport type { PickRequired, SetState } from \"@ariakit/utils\";\nimport type { ComboboxStore } from \"../combobox/combobox-store.ts\";\nimport type {\n CompositeStoreFunctions,\n CompositeStoreItem,\n CompositeStoreOptions,\n CompositeStoreState,\n} from \"../composite/composite-store.ts\";\nimport { createCompositeStore } from \"../composite/composite-store.ts\";\nimport type {\n PopoverStoreFunctions,\n PopoverStoreOptions,\n PopoverStoreState,\n} from \"../popover/popover-store.ts\";\nimport { createPopoverStore } from \"../popover/popover-store.ts\";\n\ntype MutableValue<T extends SelectStoreValue = SelectStoreValue> =\n T extends string ? string : T;\n\nexport function createSelectStore<\n T extends SelectStoreValue = SelectStoreValue,\n>(\n props: PickRequired<SelectStoreProps<T>, \"value\" | \"defaultValue\">,\n): SelectStore<T>;\n\nexport function createSelectStore(props?: SelectStoreProps): SelectStore;\n\nexport function createSelectStore({\n combobox,\n ...props\n}: SelectStoreProps = {}): SelectStore {\n const store = mergeStore(\n props.store,\n omit(combobox, [\n \"value\",\n \"items\",\n \"renderedItems\",\n \"baseElement\",\n \"arrowElement\",\n \"anchorElement\",\n \"contentElement\",\n \"popoverElement\",\n \"disclosureElement\",\n ]),\n );\n\n throwOnConflictingProps(props, store);\n\n const syncState = store.getState();\n\n const composite = createCompositeStore({\n ...props,\n store,\n virtualFocus: defaultValue(\n props.virtualFocus,\n syncState.virtualFocus,\n true,\n ),\n includesBaseElement: defaultValue(\n props.includesBaseElement,\n syncState.includesBaseElement,\n false,\n ),\n activeId: defaultValue(\n props.activeId,\n syncState.activeId,\n props.defaultActiveId,\n null,\n ),\n orientation: defaultValue(\n props.orientation,\n syncState.orientation,\n \"vertical\" as const,\n ),\n });\n\n const popover = createPopoverStore({\n ...props,\n store,\n placement: defaultValue(\n props.placement,\n syncState.placement,\n \"bottom-start\" as const,\n ),\n });\n\n const initialValue = new String(\"\") as \"\";\n\n const initialState: SelectStoreState = {\n ...composite.getState(),\n ...popover.getState(),\n value: defaultValue(\n props.value,\n syncState.value,\n props.defaultValue,\n initialValue,\n ),\n setValueOnMove: defaultValue(\n props.setValueOnMove,\n syncState.setValueOnMove,\n false,\n ),\n labelElement: defaultValue(syncState.labelElement, null),\n selectElement: defaultValue(syncState.selectElement, null),\n listElement: defaultValue(syncState.listElement, null),\n };\n\n const select = createStore(initialState, composite, popover, store);\n\n // Automatically sets the default value if it's not set.\n setup(select, () =>\n sync(select, [\"value\", \"items\"], (state) => {\n if (state.value !== initialValue) return;\n if (!state.items.length) return;\n const item = state.items.find(\n (item) => !item.disabled && item.value != null,\n );\n if (item?.value == null) return;\n select.setState(\"value\", item.value);\n }),\n );\n\n // Resets the active id to its initial state when the popover is hidden. This\n // guarantees that the active id won't be pointing to another item when the\n // popover is shown again, which would cause the selected item to not be\n // auto-focused. See test \"clicking on different tab and clicking outside\n // resets the selected tab\".\n setup(select, () =>\n sync(select, [\"mounted\"], (state) => {\n if (state.mounted) return;\n select.setState(\"activeId\", initialState.activeId);\n }),\n );\n\n // Sets the active id when the value changes and the popover is hidden.\n setup(select, () =>\n sync(select, [\"mounted\", \"items\", \"value\"], (state) => {\n // TODO: Revisit this. See test \"open with keyboard, then try to open\n // again\". Probably deprecate together with using ComboboxProvider as a\n // parent of SelectProvider.\n if (combobox) return;\n if (state.mounted) return;\n const values = toArray(state.value);\n const lastValue = values[values.length - 1];\n if (lastValue == null) return;\n const item = state.items.find(\n (item) => !item.disabled && item.value === lastValue,\n );\n if (!item) return;\n select.setState(\"activeId\", item.id);\n }),\n );\n\n // Sets the select value when the active item changes by moving (which usually\n // happens when moving to an item using the keyboard).\n setup(select, () =>\n batch(select, [\"setValueOnMove\", \"moves\"], (state) => {\n const { mounted, value, activeId } = select.getState();\n if (!state.setValueOnMove && mounted) return;\n if (Array.isArray(value)) return;\n if (!state.moves) return;\n if (!activeId) return;\n const item = composite.item(activeId);\n if (!item || item.disabled || item.value == null) return;\n select.setState(\"value\", item.value);\n }),\n );\n\n return {\n ...composite,\n ...popover,\n ...select,\n combobox,\n setValue: (value) => select.setState(\"value\", value),\n setLabelElement: (element) => select.setState(\"labelElement\", element),\n setSelectElement: (element) => select.setState(\"selectElement\", element),\n setListElement: (element) => select.setState(\"listElement\", element),\n };\n}\n\nexport type SelectStoreValue = string | readonly string[];\n\nexport interface SelectStoreItem extends CompositeStoreItem {\n value?: string;\n}\n\nexport interface SelectStoreState<T extends SelectStoreValue = SelectStoreValue>\n extends CompositeStoreState<SelectStoreItem>, PopoverStoreState {\n /** @default true */\n virtualFocus: CompositeStoreState<SelectStoreItem>[\"virtualFocus\"];\n /** @default null */\n activeId: CompositeStoreState<SelectStoreItem>[\"activeId\"];\n /** @default \"vertical\" */\n orientation: CompositeStoreState<SelectStoreItem>[\"orientation\"];\n /** @default \"bottom-start\" */\n placement: PopoverStoreState[\"placement\"];\n /**\n * The select value.\n *\n * Live examples:\n * - [Form with Select](https://ariakit.com/examples/form-select)\n * - [Select Grid](https://ariakit.com/examples/select-grid)\n * - [Select with custom\n * items](https://ariakit.com/examples/select-item-custom)\n * - [Multi-Select](https://ariakit.com/examples/select-multiple)\n * - [Toolbar with Select](https://ariakit.com/examples/toolbar-select)\n * - [Select with Next.js App\n * Router](https://ariakit.com/examples/select-next-router)\n */\n value: MutableValue<T>;\n /**\n * Whether the select\n * [`value`](https://ariakit.com/reference/select-provider#value) should be\n * set when the active item changes by moving (which usually happens when\n * moving to an item using the keyboard).\n *\n * Live examples:\n * - [Select Grid](https://ariakit.com/examples/select-grid)\n * - [Select with custom\n * items](https://ariakit.com/examples/select-item-custom)\n * @default false\n */\n setValueOnMove: boolean;\n /**\n * The select label element.\n */\n labelElement: HTMLElement | null;\n /**\n * The select button element.\n *\n * Live examples:\n * - [Form with Select](https://ariakit.com/examples/form-select)\n */\n selectElement: HTMLElement | null;\n /**\n * The select list element.\n */\n listElement: HTMLElement | null;\n}\n\nexport interface SelectStoreFunctions<\n T extends SelectStoreValue = SelectStoreValue,\n>\n extends\n Pick<SelectStoreOptions<T>, \"combobox\">,\n CompositeStoreFunctions<SelectStoreItem>,\n PopoverStoreFunctions {\n /**\n * Sets the [`value`](https://ariakit.com/reference/select-provider#value)\n * state.\n * @example\n * store.setValue(\"Apple\");\n * store.setValue([\"Apple\", \"Banana\"]);\n * store.setValue((value) => value === \"Apple\" ? \"Banana\" : \"Apple\"));\n */\n setValue: SetState<SelectStoreState<T>[\"value\"]>;\n /**\n * Sets the `labelElement` state.\n */\n setLabelElement: SetState<SelectStoreState<T>[\"labelElement\"]>;\n /**\n * Sets the `selectElement` state.\n */\n setSelectElement: SetState<SelectStoreState<T>[\"selectElement\"]>;\n /**\n * Sets the `listElement` state.\n */\n setListElement: SetState<SelectStoreState<T>[\"listElement\"]>;\n}\n\nexport interface SelectStoreOptions<\n T extends SelectStoreValue = SelectStoreValue,\n>\n extends\n StoreOptions<\n SelectStoreState<T>,\n | \"virtualFocus\"\n | \"activeId\"\n | \"orientation\"\n | \"placement\"\n | \"value\"\n | \"setValueOnMove\"\n >,\n CompositeStoreOptions<SelectStoreItem>,\n PopoverStoreOptions {\n /**\n * A reference to a combobox store. This is used when combining the combobox\n * with a select (e.g., select with a search input). The stores will share the\n * same state.\n */\n combobox?: ComboboxStore | null;\n /**\n * The default value. If not set, the first non-disabled item will be used.\n *\n * Live examples:\n * - [Form with Select](https://ariakit.com/examples/form-select)\n * - [Animated Select](https://ariakit.com/examples/select-animated)\n * - [Select with Combobox](https://ariakit.com/examples/select-combobox)\n * - [SelectGroup](https://ariakit.com/examples/select-group)\n * - [Select with Next.js App\n * Router](https://ariakit.com/examples/select-next-router)\n * - [Select with Combobox and\n * Tabs](https://ariakit.com/examples/select-combobox-tab)\n */\n defaultValue?: SelectStoreState<T>[\"value\"];\n}\n\nexport interface SelectStoreProps<T extends SelectStoreValue = SelectStoreValue>\n extends SelectStoreOptions<T>, StoreProps<SelectStoreState<T>> {}\n\nexport interface SelectStore<T extends SelectStoreValue = SelectStoreValue>\n extends SelectStoreFunctions<T>, Store<SelectStoreState<T>> {}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { r as CollectionStoreItem, t as CollectionStore } from "../collection-store-yNe83BiS.js";
|
|
2
|
+
import { i as CompositeStoreOptions, n as CompositeStoreFunctions, r as CompositeStoreItem, s as CompositeStoreState, t as CompositeStore } from "../composite-store-B-iDEtZZ.js";
|
|
3
|
+
import { ComboboxStore } from "../combobox/combobox-store.js";
|
|
4
|
+
import { SelectStore } from "../select/select-store.js";
|
|
5
|
+
import { Store, StoreOptions, StoreProps } from "@ariakit/store";
|
|
6
|
+
import { SetState } from "@ariakit/utils";
|
|
7
|
+
|
|
8
|
+
//#region src/tab/tab-store.d.ts
|
|
9
|
+
declare function createTabStore({
|
|
10
|
+
composite: parentComposite,
|
|
11
|
+
combobox,
|
|
12
|
+
...props
|
|
13
|
+
}?: TabStoreProps): TabStore;
|
|
14
|
+
interface TabStoreItem extends CompositeStoreItem {
|
|
15
|
+
dimmed?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface TabStorePanel extends CollectionStoreItem {
|
|
18
|
+
tabId?: string | null;
|
|
19
|
+
}
|
|
20
|
+
interface TabStoreState extends CompositeStoreState<TabStoreItem> {
|
|
21
|
+
/** @default "horizontal" */
|
|
22
|
+
orientation: CompositeStoreState<TabStoreItem>["orientation"];
|
|
23
|
+
/** @default true */
|
|
24
|
+
focusLoop: CompositeStoreState<TabStoreItem>["focusLoop"];
|
|
25
|
+
/**
|
|
26
|
+
* The id of the tab whose panel is currently visible. If it's `undefined`, it
|
|
27
|
+
* will be automatically set to the first enabled tab.
|
|
28
|
+
*
|
|
29
|
+
* Live examples:
|
|
30
|
+
* - [Tab with React Router](https://ariakit.com/examples/tab-react-router)
|
|
31
|
+
* - [Combobox with Tabs](https://ariakit.com/examples/combobox-tabs)
|
|
32
|
+
* - [Select with Combobox and
|
|
33
|
+
* Tabs](https://ariakit.com/examples/select-combobox-tab)
|
|
34
|
+
* - [Command Menu with
|
|
35
|
+
* Tabs](https://ariakit.com/examples/dialog-combobox-tab-command-menu)
|
|
36
|
+
*/
|
|
37
|
+
selectedId: TabStoreState["activeId"];
|
|
38
|
+
/**
|
|
39
|
+
* Determines if the tab should be selected when it receives focus. If set to
|
|
40
|
+
* `false`, the tab will only be selected upon clicking, not when using arrow
|
|
41
|
+
* keys to shift focus.
|
|
42
|
+
*
|
|
43
|
+
* Live examples:
|
|
44
|
+
* - [Tab with React Router](https://ariakit.com/examples/tab-react-router)
|
|
45
|
+
* - [Select with Combobox and
|
|
46
|
+
* Tabs](https://ariakit.com/examples/select-combobox-tab)
|
|
47
|
+
* @default true
|
|
48
|
+
*/
|
|
49
|
+
selectOnMove?: boolean;
|
|
50
|
+
}
|
|
51
|
+
interface TabStoreFunctions extends CompositeStoreFunctions<TabStoreItem> {
|
|
52
|
+
/**
|
|
53
|
+
* Sets the
|
|
54
|
+
* [`selectedId`](https://ariakit.com/reference/tab-provider#selectedid) state
|
|
55
|
+
* without moving focus. If you want to move focus, use the
|
|
56
|
+
* [`select`](https://ariakit.com/reference/use-tab-store#select) function
|
|
57
|
+
* instead.
|
|
58
|
+
* @example
|
|
59
|
+
* // Selects the tab with id "tab-1"
|
|
60
|
+
* store.setSelectedId("tab-1");
|
|
61
|
+
* // Toggles between "tab-1" and "tab-2"
|
|
62
|
+
* store.setSelectedId((id) => id === "tab-1" ? "tab-2" : "tab-1"));
|
|
63
|
+
* // Selects the first tab
|
|
64
|
+
* store.setSelectedId(store.first());
|
|
65
|
+
* // Selects the next tab
|
|
66
|
+
* store.setSelectedId(store.next());
|
|
67
|
+
*/
|
|
68
|
+
setSelectedId: SetState<TabStoreState["selectedId"]>;
|
|
69
|
+
/**
|
|
70
|
+
* A collection store containing the tab panels.
|
|
71
|
+
*
|
|
72
|
+
* Live examples:
|
|
73
|
+
* - [Animated TabPanel](https://ariakit.com/examples/tab-panel-animated)
|
|
74
|
+
*/
|
|
75
|
+
panels: CollectionStore<TabStorePanel>;
|
|
76
|
+
/**
|
|
77
|
+
* Selects the tab for the given id and moves focus to it. If you want to set
|
|
78
|
+
* the [`selectedId`](https://ariakit.com/reference/tab-provider#selectedid)
|
|
79
|
+
* state without moving focus, use the
|
|
80
|
+
* [`setSelectedId`](https://ariakit.com/reference/use-tab-store#setselectedid-1)
|
|
81
|
+
* function instead.
|
|
82
|
+
* @example
|
|
83
|
+
* // Selects the tab with id "tab-1"
|
|
84
|
+
* store.select("tab-1");
|
|
85
|
+
* // Selects the first tab
|
|
86
|
+
* store.select(store.first());
|
|
87
|
+
* // Selects the next tab
|
|
88
|
+
* store.select(store.next());
|
|
89
|
+
*/
|
|
90
|
+
select: TabStore["move"];
|
|
91
|
+
}
|
|
92
|
+
interface TabStoreOptions extends StoreOptions<TabStoreState, "orientation" | "focusLoop" | "selectedId" | "selectOnMove">, CompositeStoreOptions<TabStoreItem> {
|
|
93
|
+
/**
|
|
94
|
+
* A reference to another [composite
|
|
95
|
+
* store](https://ariakit.com/reference/use-composite-store). This is used when
|
|
96
|
+
* rendering tabs as part of another composite widget such as
|
|
97
|
+
* [Combobox](https://ariakit.com/components/combobox) or
|
|
98
|
+
* [Select](https://ariakit.com/components/select). The stores will share the
|
|
99
|
+
* same state.
|
|
100
|
+
*/
|
|
101
|
+
composite?: CompositeStore | SelectStore | null;
|
|
102
|
+
/**
|
|
103
|
+
* A reference to a [combobox
|
|
104
|
+
* store](https://ariakit.com/reference/use-combobox-store). This is used when
|
|
105
|
+
* rendering tabs inside a
|
|
106
|
+
* [Combobox](https://ariakit.com/components/combobox).
|
|
107
|
+
*/
|
|
108
|
+
combobox?: ComboboxStore | null;
|
|
109
|
+
/**
|
|
110
|
+
* The id of the tab whose panel is currently visible. If it's `undefined`, it
|
|
111
|
+
* will be automatically set to the first enabled tab.
|
|
112
|
+
*
|
|
113
|
+
* Live examples:
|
|
114
|
+
* - [Combobox with Tabs](https://ariakit.com/examples/combobox-tabs)
|
|
115
|
+
* - [Animated TabPanel](https://ariakit.com/examples/tab-panel-animated)
|
|
116
|
+
* - [Select with Combobox and
|
|
117
|
+
* Tabs](https://ariakit.com/examples/select-combobox-tab)
|
|
118
|
+
* - [Command Menu with
|
|
119
|
+
* Tabs](https://ariakit.com/examples/dialog-combobox-tab-command-menu)
|
|
120
|
+
*/
|
|
121
|
+
defaultSelectedId?: TabStoreState["selectedId"];
|
|
122
|
+
}
|
|
123
|
+
interface TabStoreProps extends TabStoreOptions, StoreProps<TabStoreState> {}
|
|
124
|
+
interface TabStore extends TabStoreFunctions, Store<TabStoreState> {}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { TabStore, TabStoreFunctions, TabStoreItem, TabStoreOptions, TabStorePanel, TabStoreProps, TabStoreState, createTabStore };
|
|
127
|
+
//# sourceMappingURL=tab-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tab-store.d.ts","names":["Store","StoreOptions","StoreProps","SetState","CollectionStore","CollectionStoreItem","ComboboxStore","CompositeStore","CompositeStoreFunctions","CompositeStoreItem","CompositeStoreOptions","CompositeStoreState","SelectStore","createTabStore","parentComposite","combobox","TabStoreProps","TabStore","composite","props","TabStoreItem","dimmed","TabStorePanel","tabId","TabStoreState","orientation","focusLoop","selectedId","selectOnMove","TabStoreFunctions","setSelectedId","panels","select","TabStoreOptions","defaultSelectedId"],"sources":["../../src/tab/tab-store.d.ts"],"mappings":";;;;;;;;iBAMwBa,cAAAA,CAAAA;EAAiBK,SAAAA,EAAWJ,eAAAA;EAAiBC,QAAAA;EAAAA,GAAaI;AAAAA,IAAUH,aAAAA,GAAgBC,QAAAA;AAAAA,UAC3FG,YAAAA,SAAqBX,kBAAkB;EACpDY,MAAM;AAAA;AAAA,UAEOC,aAAAA,SAAsBjB,mBAAmB;EACtDkB,KAAK;AAAA;AAAA,UAEQC,aAAAA,SAAsBb,mBAAAA,CAAoBS,YAAAA;EAPiDH;EASxGQ,WAAAA,EAAad,mBAAAA,CAAoBS,YAAAA;EAT+E;EAWhHM,SAAAA,EAAWf,mBAAAA,CAAoBS,YAAAA;EAXiBN;;;;;;;AAAgE;AACpH;;;;EAuBIa,UAAAA,EAAYH,aAAAA;EApBCF;;;;AACR;AAET;;;;;;EA6BIM,YAAAA;AAAAA;AAAAA,UAEaC,iBAAAA,SAA0BrB,uBAAAA,CAAwBY,YAAAA;EA/B5BT;;;;;;;;;;;;;;;AA6BvB;EAmBZmB,aAAAA,EAAe3B,QAAAA,CAASqB,aAAAA;EAjBM;;;;;;EAwB9BO,MAAAA,EAAQ3B,eAAAA,CAAgBkB,aAAAA;EAehBL;;;;;;;;;;;;;;EAARe,MAAAA,EAAQf,QAAAA;AAAAA;AAAAA,UAEKgB,eAAAA,SAAwBhC,YAAAA,CAAauB,aAAAA,gEAA6Ed,qBAAAA,CAAsBU,YAAAA;EAAzH;;;;;;;;EAS5BF,SAAAA,GAAYX,cAAAA,GAAiBK,WAAAA;EATkGF;;;;;;EAgB/HK,QAAAA,GAAWT,aAAAA;EAPXY;;;;;;;;AAoBiC;AAErC;;;EAFIgB,iBAAAA,GAAoBV,aAAAA;AAAAA;AAAAA,UAEPR,aAAAA,SAAsBiB,eAAAA,EAAiB/B,UAAAA,CAAWsB,aAAAA;AAAAA,UAElDP,QAAAA,SAAiBY,iBAAAA,EAAmB7B,KAAAA,CAAMwB,aAAAA"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createCollectionStore } from "../collection/collection-store.js";
|
|
2
|
+
import { createCompositeStore } from "../composite/composite-store.js";
|
|
3
|
+
import { batch, createStore, mergeStore, omit, setup, sync } from "@ariakit/store";
|
|
4
|
+
import { chain, defaultValue } from "@ariakit/utils";
|
|
5
|
+
//#region src/tab/tab-store.ts
|
|
6
|
+
function createTabStore({ composite: parentComposite, combobox, ...props } = {}) {
|
|
7
|
+
const independentKeys = [
|
|
8
|
+
"items",
|
|
9
|
+
"renderedItems",
|
|
10
|
+
"moves",
|
|
11
|
+
"orientation",
|
|
12
|
+
"virtualFocus",
|
|
13
|
+
"includesBaseElement",
|
|
14
|
+
"baseElement",
|
|
15
|
+
"focusLoop",
|
|
16
|
+
"focusShift",
|
|
17
|
+
"focusWrap"
|
|
18
|
+
];
|
|
19
|
+
const store = mergeStore(props.store, omit(parentComposite, independentKeys), omit(combobox, independentKeys));
|
|
20
|
+
const syncState = store?.getState();
|
|
21
|
+
const composite = createCompositeStore({
|
|
22
|
+
...props,
|
|
23
|
+
store,
|
|
24
|
+
includesBaseElement: defaultValue(props.includesBaseElement, syncState?.includesBaseElement, false),
|
|
25
|
+
orientation: defaultValue(props.orientation, syncState?.orientation, "horizontal"),
|
|
26
|
+
focusLoop: defaultValue(props.focusLoop, syncState?.focusLoop, true)
|
|
27
|
+
});
|
|
28
|
+
const panels = createCollectionStore();
|
|
29
|
+
const tab = createStore({
|
|
30
|
+
...composite.getState(),
|
|
31
|
+
selectedId: defaultValue(props.selectedId, syncState?.selectedId, props.defaultSelectedId),
|
|
32
|
+
selectOnMove: defaultValue(props.selectOnMove, syncState?.selectOnMove, true)
|
|
33
|
+
}, composite, store);
|
|
34
|
+
setup(tab, () => sync(tab, ["moves"], () => {
|
|
35
|
+
const { activeId, selectOnMove } = tab.getState();
|
|
36
|
+
if (!selectOnMove) return;
|
|
37
|
+
if (!activeId) return;
|
|
38
|
+
const tabItem = composite.item(activeId);
|
|
39
|
+
if (!tabItem) return;
|
|
40
|
+
if (tabItem.dimmed) return;
|
|
41
|
+
if (tabItem.disabled) return;
|
|
42
|
+
tab.setState("selectedId", tabItem.id);
|
|
43
|
+
}));
|
|
44
|
+
let syncActiveId = true;
|
|
45
|
+
setup(tab, () => batch(tab, ["selectedId"], (state, prev) => {
|
|
46
|
+
if (!syncActiveId) {
|
|
47
|
+
syncActiveId = true;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (parentComposite && state.selectedId === prev.selectedId) return;
|
|
51
|
+
tab.setState("activeId", state.selectedId);
|
|
52
|
+
}));
|
|
53
|
+
setup(tab, () => sync(tab, ["selectedId", "renderedItems"], (state) => {
|
|
54
|
+
if (state.selectedId !== void 0) return;
|
|
55
|
+
const { activeId, renderedItems } = tab.getState();
|
|
56
|
+
const tabItem = composite.item(activeId);
|
|
57
|
+
if (tabItem && !tabItem.disabled && !tabItem.dimmed) tab.setState("selectedId", tabItem.id);
|
|
58
|
+
else {
|
|
59
|
+
const tabItem = renderedItems.find((item) => !item.disabled && !item.dimmed);
|
|
60
|
+
tab.setState("selectedId", tabItem?.id);
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
setup(tab, () => sync(tab, ["renderedItems"], (state) => {
|
|
64
|
+
const tabs = state.renderedItems;
|
|
65
|
+
if (!tabs.length) return;
|
|
66
|
+
return sync(panels, ["renderedItems"], (state) => {
|
|
67
|
+
const items = state.renderedItems;
|
|
68
|
+
if (!items.some((panel) => !panel.tabId)) return;
|
|
69
|
+
items.forEach((panel, i) => {
|
|
70
|
+
if (panel.tabId) return;
|
|
71
|
+
const tabItem = tabs[i];
|
|
72
|
+
if (!tabItem) return;
|
|
73
|
+
panels.renderItem({
|
|
74
|
+
...panel,
|
|
75
|
+
tabId: tabItem.id
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}));
|
|
80
|
+
let selectedIdFromSelectedValue = null;
|
|
81
|
+
setup(tab, () => {
|
|
82
|
+
const backupSelectedId = () => {
|
|
83
|
+
selectedIdFromSelectedValue = tab.getState().selectedId;
|
|
84
|
+
};
|
|
85
|
+
const restoreSelectedId = () => {
|
|
86
|
+
syncActiveId = false;
|
|
87
|
+
tab.setState("selectedId", selectedIdFromSelectedValue);
|
|
88
|
+
};
|
|
89
|
+
if (parentComposite && "setSelectElement" in parentComposite) return chain(sync(parentComposite, ["value"], backupSelectedId), sync(parentComposite, ["mounted"], restoreSelectedId));
|
|
90
|
+
if (!combobox) return;
|
|
91
|
+
return chain(sync(combobox, ["selectedValue"], backupSelectedId), sync(combobox, ["mounted"], restoreSelectedId));
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
...composite,
|
|
95
|
+
...tab,
|
|
96
|
+
panels,
|
|
97
|
+
setSelectedId: (id) => tab.setState("selectedId", id),
|
|
98
|
+
select: (id) => {
|
|
99
|
+
tab.setState("selectedId", id);
|
|
100
|
+
composite.move(id);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { createTabStore };
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=tab-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tab-store.js","names":[],"sources":["../../src/tab/tab-store.ts"],"sourcesContent":["import {\n batch,\n createStore,\n mergeStore,\n omit,\n setup,\n sync,\n} from \"@ariakit/store\";\nimport type { Store, StoreOptions, StoreProps } from \"@ariakit/store\";\nimport { chain, defaultValue } from \"@ariakit/utils\";\nimport type { SetState } from \"@ariakit/utils\";\nimport type {\n CollectionStore,\n CollectionStoreItem,\n} from \"../collection/collection-store.ts\";\nimport { createCollectionStore } from \"../collection/collection-store.ts\";\nimport type { ComboboxStore } from \"../combobox/combobox-store.ts\";\nimport type {\n CompositeStore,\n CompositeStoreFunctions,\n CompositeStoreItem,\n CompositeStoreOptions,\n CompositeStoreState,\n} from \"../composite/composite-store.ts\";\nimport { createCompositeStore } from \"../composite/composite-store.ts\";\nimport type { SelectStore } from \"../select/select-store.ts\";\n\nexport function createTabStore({\n composite: parentComposite,\n combobox,\n ...props\n}: TabStoreProps = {}): TabStore {\n const independentKeys = [\n \"items\",\n \"renderedItems\",\n \"moves\",\n \"orientation\",\n \"virtualFocus\",\n \"includesBaseElement\",\n \"baseElement\",\n \"focusLoop\",\n \"focusShift\",\n \"focusWrap\",\n ] as const;\n\n const store = mergeStore(\n props.store,\n omit(parentComposite, independentKeys),\n omit(combobox, independentKeys),\n );\n const syncState = store?.getState();\n\n const composite = createCompositeStore({\n ...props,\n store,\n // We need to explicitly set the default value of `includesBaseElement` to\n // `false` since we don't want the composite store to default it to `true`\n // when the activeId state is null, which could be the case when rendering\n // combobox with tab.\n includesBaseElement: defaultValue(\n props.includesBaseElement,\n syncState?.includesBaseElement,\n false,\n ),\n orientation: defaultValue(\n props.orientation,\n syncState?.orientation,\n \"horizontal\" as const,\n ),\n focusLoop: defaultValue(props.focusLoop, syncState?.focusLoop, true),\n });\n\n const panels = createCollectionStore<TabStorePanel>();\n\n const initialState: TabStoreState = {\n ...composite.getState(),\n selectedId: defaultValue(\n props.selectedId,\n syncState?.selectedId,\n props.defaultSelectedId,\n ),\n selectOnMove: defaultValue(\n props.selectOnMove,\n syncState?.selectOnMove,\n true,\n ),\n };\n const tab = createStore(initialState, composite, store);\n\n // Selects the active tab when selectOnMove is true. Since we're listening to\n // the moves state, but not the activeId state, this callback will run only\n // when there's a move, which is usually triggered by moving through the tabs\n // using the keyboard.\n setup(tab, () =>\n sync(tab, [\"moves\"], () => {\n const { activeId, selectOnMove } = tab.getState();\n if (!selectOnMove) return;\n if (!activeId) return;\n const tabItem = composite.item(activeId);\n if (!tabItem) return;\n if (tabItem.dimmed) return;\n if (tabItem.disabled) return;\n tab.setState(\"selectedId\", tabItem.id);\n }),\n );\n\n let syncActiveId = true;\n\n // Keep activeId in sync with selectedId.\n setup(tab, () =>\n batch(tab, [\"selectedId\"], (state, prev) => {\n // There are cases where we don't want to sync activeId with selectedId.\n // For example, restoring the selectedId from a select or combobox\n // selected value. In those cases, we set syncActiveId to false.\n if (!syncActiveId) {\n syncActiveId = true;\n return;\n }\n // If there's a parent composite widget, we don't need to sync the\n // activeId state with the initial selectedId state. The parent composite\n // widget should handle the initial activeId state.\n if (parentComposite && state.selectedId === prev.selectedId) return;\n tab.setState(\"activeId\", state.selectedId);\n }),\n );\n\n // Automatically set selectedId if it's undefined.\n setup(tab, () =>\n sync(tab, [\"selectedId\", \"renderedItems\"], (state) => {\n if (state.selectedId !== undefined) return;\n // First, we try to set selectedId based on the current active tab.\n const { activeId, renderedItems } = tab.getState();\n const tabItem = composite.item(activeId);\n if (tabItem && !tabItem.disabled && !tabItem.dimmed) {\n tab.setState(\"selectedId\", tabItem.id);\n }\n // If there's no active tab or the active tab is dimmed, we get the\n // first enabled tab instead.\n else {\n const tabItem = renderedItems.find(\n (item) => !item.disabled && !item.dimmed,\n );\n tab.setState(\"selectedId\", tabItem?.id);\n }\n }),\n );\n\n // Keep panels tabIds in sync with the current tabs.\n setup(tab, () =>\n sync(tab, [\"renderedItems\"], (state) => {\n const tabs = state.renderedItems;\n if (!tabs.length) return;\n return sync(panels, [\"renderedItems\"], (state) => {\n const items = state.renderedItems;\n const hasOrphanPanels = items.some((panel) => !panel.tabId);\n if (!hasOrphanPanels) return;\n items.forEach((panel, i) => {\n if (panel.tabId) return;\n const tabItem = tabs[i];\n if (!tabItem) return;\n panels.renderItem({ ...panel, tabId: tabItem.id });\n });\n });\n }),\n );\n\n // Preserve the selected tab when a select or combobox value is selected\n // within the tab panel.\n let selectedIdFromSelectedValue: string | null | undefined = null;\n\n setup(tab, () => {\n const backupSelectedId = () => {\n selectedIdFromSelectedValue = tab.getState().selectedId;\n };\n const restoreSelectedId = () => {\n // We set syncActiveId to false to prevent the activeId state from being\n // set to the selectedId state since this is just a restoration of the\n // selectedId state from a select or combobox selected value.\n syncActiveId = false;\n tab.setState(\"selectedId\", selectedIdFromSelectedValue);\n };\n if (parentComposite && \"setSelectElement\" in parentComposite) {\n return chain(\n sync(parentComposite, [\"value\"], backupSelectedId),\n sync(parentComposite, [\"mounted\"], restoreSelectedId),\n );\n }\n if (!combobox) return;\n return chain(\n sync(combobox, [\"selectedValue\"], backupSelectedId),\n sync(combobox, [\"mounted\"], restoreSelectedId),\n );\n });\n\n return {\n ...composite,\n ...tab,\n panels,\n setSelectedId: (id) => tab.setState(\"selectedId\", id),\n select: (id) => {\n tab.setState(\"selectedId\", id);\n composite.move(id);\n },\n };\n}\n\nexport interface TabStoreItem extends CompositeStoreItem {\n dimmed?: boolean;\n}\n\nexport interface TabStorePanel extends CollectionStoreItem {\n tabId?: string | null;\n}\n\nexport interface TabStoreState extends CompositeStoreState<TabStoreItem> {\n /** @default \"horizontal\" */\n orientation: CompositeStoreState<TabStoreItem>[\"orientation\"];\n /** @default true */\n focusLoop: CompositeStoreState<TabStoreItem>[\"focusLoop\"];\n /**\n * The id of the tab whose panel is currently visible. If it's `undefined`, it\n * will be automatically set to the first enabled tab.\n *\n * Live examples:\n * - [Tab with React Router](https://ariakit.com/examples/tab-react-router)\n * - [Combobox with Tabs](https://ariakit.com/examples/combobox-tabs)\n * - [Select with Combobox and\n * Tabs](https://ariakit.com/examples/select-combobox-tab)\n * - [Command Menu with\n * Tabs](https://ariakit.com/examples/dialog-combobox-tab-command-menu)\n */\n selectedId: TabStoreState[\"activeId\"];\n /**\n * Determines if the tab should be selected when it receives focus. If set to\n * `false`, the tab will only be selected upon clicking, not when using arrow\n * keys to shift focus.\n *\n * Live examples:\n * - [Tab with React Router](https://ariakit.com/examples/tab-react-router)\n * - [Select with Combobox and\n * Tabs](https://ariakit.com/examples/select-combobox-tab)\n * @default true\n */\n selectOnMove?: boolean;\n}\n\nexport interface TabStoreFunctions extends CompositeStoreFunctions<TabStoreItem> {\n /**\n * Sets the\n * [`selectedId`](https://ariakit.com/reference/tab-provider#selectedid) state\n * without moving focus. If you want to move focus, use the\n * [`select`](https://ariakit.com/reference/use-tab-store#select) function\n * instead.\n * @example\n * // Selects the tab with id \"tab-1\"\n * store.setSelectedId(\"tab-1\");\n * // Toggles between \"tab-1\" and \"tab-2\"\n * store.setSelectedId((id) => id === \"tab-1\" ? \"tab-2\" : \"tab-1\"));\n * // Selects the first tab\n * store.setSelectedId(store.first());\n * // Selects the next tab\n * store.setSelectedId(store.next());\n */\n setSelectedId: SetState<TabStoreState[\"selectedId\"]>;\n /**\n * A collection store containing the tab panels.\n *\n * Live examples:\n * - [Animated TabPanel](https://ariakit.com/examples/tab-panel-animated)\n */\n panels: CollectionStore<TabStorePanel>;\n /**\n * Selects the tab for the given id and moves focus to it. If you want to set\n * the [`selectedId`](https://ariakit.com/reference/tab-provider#selectedid)\n * state without moving focus, use the\n * [`setSelectedId`](https://ariakit.com/reference/use-tab-store#setselectedid-1)\n * function instead.\n * @example\n * // Selects the tab with id \"tab-1\"\n * store.select(\"tab-1\");\n * // Selects the first tab\n * store.select(store.first());\n * // Selects the next tab\n * store.select(store.next());\n */\n select: TabStore[\"move\"];\n}\n\nexport interface TabStoreOptions\n extends\n StoreOptions<\n TabStoreState,\n \"orientation\" | \"focusLoop\" | \"selectedId\" | \"selectOnMove\"\n >,\n CompositeStoreOptions<TabStoreItem> {\n /**\n * A reference to another [composite\n * store](https://ariakit.com/reference/use-composite-store). This is used when\n * rendering tabs as part of another composite widget such as\n * [Combobox](https://ariakit.com/components/combobox) or\n * [Select](https://ariakit.com/components/select). The stores will share the\n * same state.\n */\n composite?: CompositeStore | SelectStore | null;\n /**\n * A reference to a [combobox\n * store](https://ariakit.com/reference/use-combobox-store). This is used when\n * rendering tabs inside a\n * [Combobox](https://ariakit.com/components/combobox).\n */\n combobox?: ComboboxStore | null;\n /**\n * The id of the tab whose panel is currently visible. If it's `undefined`, it\n * will be automatically set to the first enabled tab.\n *\n * Live examples:\n * - [Combobox with Tabs](https://ariakit.com/examples/combobox-tabs)\n * - [Animated TabPanel](https://ariakit.com/examples/tab-panel-animated)\n * - [Select with Combobox and\n * Tabs](https://ariakit.com/examples/select-combobox-tab)\n * - [Command Menu with\n * Tabs](https://ariakit.com/examples/dialog-combobox-tab-command-menu)\n */\n defaultSelectedId?: TabStoreState[\"selectedId\"];\n}\n\nexport interface TabStoreProps\n extends TabStoreOptions, StoreProps<TabStoreState> {}\n\nexport interface TabStore extends TabStoreFunctions, Store<TabStoreState> {}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as TagStoreProps, i as TagStoreOptions, n as TagStoreFunctions, o as TagStoreState, r as TagStoreItem, s as createTagStore, t as TagStore } from "../tag-store-D47X5_zA.js";
|
|
2
|
+
export { TagStore, TagStoreFunctions, TagStoreItem, TagStoreOptions, TagStoreProps, TagStoreState, createTagStore };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createCompositeStore } from "../composite/composite-store.js";
|
|
2
|
+
import { createStore, setup, sync } from "@ariakit/store";
|
|
3
|
+
import { UndoManager, applyState, defaultValue } from "@ariakit/utils";
|
|
4
|
+
//#region src/tag/tag-store.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a tag store.
|
|
7
|
+
*/
|
|
8
|
+
function createTagStore(props = {}) {
|
|
9
|
+
const syncState = props.store?.getState();
|
|
10
|
+
const composite = createCompositeStore(props);
|
|
11
|
+
const initialState = {
|
|
12
|
+
...composite.getState(),
|
|
13
|
+
inputElement: defaultValue(syncState?.inputElement, null),
|
|
14
|
+
labelElement: defaultValue(syncState?.labelElement, null),
|
|
15
|
+
value: defaultValue(props.value, syncState?.value, props.defaultValue, ""),
|
|
16
|
+
values: defaultValue(props.values, syncState?.values, props.defaultValues, [])
|
|
17
|
+
};
|
|
18
|
+
const tag = createStore(initialState, composite, props.store);
|
|
19
|
+
setup(tag, () => sync(tag, ["inputElement", "activeId"], (state) => {
|
|
20
|
+
if (!state.inputElement) return;
|
|
21
|
+
if (state.activeId !== void 0) return;
|
|
22
|
+
tag.setState("activeId", state.inputElement.id);
|
|
23
|
+
}));
|
|
24
|
+
const setValues = (values) => {
|
|
25
|
+
const { values: previousValues } = tag.getState();
|
|
26
|
+
UndoManager.execute(() => {
|
|
27
|
+
let changed = true;
|
|
28
|
+
tag.setState("values", (prev) => {
|
|
29
|
+
const next = applyState(values, prev);
|
|
30
|
+
if (next === prev) changed = false;
|
|
31
|
+
return next;
|
|
32
|
+
});
|
|
33
|
+
if (!changed) return;
|
|
34
|
+
return () => {
|
|
35
|
+
tag.setState("values", previousValues);
|
|
36
|
+
composite.move(tag.getState().inputElement?.id);
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
...composite,
|
|
42
|
+
...tag,
|
|
43
|
+
setInputElement: (inputElement) => tag.setState("inputElement", inputElement),
|
|
44
|
+
setLabelElement: (labelElement) => tag.setState("labelElement", labelElement),
|
|
45
|
+
setValue: (value) => tag.setState("value", value),
|
|
46
|
+
resetValue: () => tag.setState("value", initialState.value),
|
|
47
|
+
setValues,
|
|
48
|
+
addValue: (value) => {
|
|
49
|
+
setValues((values) => {
|
|
50
|
+
if (values.includes(value)) return values;
|
|
51
|
+
return [...values, value];
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
removeValue: (value) => setValues((values) => values.filter((v) => v !== value))
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { createTagStore };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=tag-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag-store.js","names":[],"sources":["../../src/tag/tag-store.ts"],"sourcesContent":["import { createStore, setup, sync } from \"@ariakit/store\";\nimport type { Store, StoreOptions, StoreProps } from \"@ariakit/store\";\nimport { applyState, defaultValue, UndoManager } from \"@ariakit/utils\";\nimport type { SetState } from \"@ariakit/utils\";\nimport type {\n CompositeStoreFunctions,\n CompositeStoreItem,\n CompositeStoreOptions,\n CompositeStoreState,\n} from \"../composite/composite-store.ts\";\nimport { createCompositeStore } from \"../composite/composite-store.ts\";\n\n/**\n * Creates a tag store.\n */\nexport function createTagStore(props: TagStoreProps = {}): TagStore {\n const syncState = props.store?.getState();\n const composite = createCompositeStore(props);\n\n const initialState: TagStoreState = {\n ...composite.getState(),\n inputElement: defaultValue(syncState?.inputElement, null),\n labelElement: defaultValue(syncState?.labelElement, null),\n value: defaultValue(props.value, syncState?.value, props.defaultValue, \"\"),\n values: defaultValue(\n props.values,\n syncState?.values,\n props.defaultValues,\n [],\n ),\n };\n\n const tag = createStore(initialState, composite, props.store);\n\n // Set the input element as the default active element, that is, the element\n // that will receive focus when the composite widget is focused.\n setup(tag, () =>\n sync(tag, [\"inputElement\", \"activeId\"], (state) => {\n if (!state.inputElement) return;\n if (state.activeId !== undefined) return;\n tag.setState(\"activeId\", state.inputElement.id);\n }),\n );\n\n const setValues: TagStore[\"setValues\"] = (values) => {\n const { values: previousValues } = tag.getState();\n void UndoManager.execute(() => {\n let changed = true;\n tag.setState(\"values\", (prev) => {\n const next = applyState(values, prev);\n if (next === prev) {\n changed = false;\n }\n return next;\n });\n if (!changed) return;\n return () => {\n tag.setState(\"values\", previousValues);\n composite.move(tag.getState().inputElement?.id);\n };\n });\n };\n\n return {\n ...composite,\n ...tag,\n setInputElement: (inputElement) =>\n tag.setState(\"inputElement\", inputElement),\n\n setLabelElement: (labelElement) =>\n tag.setState(\"labelElement\", labelElement),\n\n setValue: (value) => tag.setState(\"value\", value),\n\n resetValue: () => tag.setState(\"value\", initialState.value),\n\n setValues,\n\n addValue: (value) => {\n setValues((values) => {\n if (values.includes(value)) return values;\n return [...values, value];\n });\n },\n\n removeValue: (value) =>\n setValues((values) => values.filter((v) => v !== value)),\n };\n}\n\nexport interface TagStoreItem extends CompositeStoreItem {\n value?: string;\n}\n\nexport interface TagStoreState extends CompositeStoreState<TagStoreItem> {\n /**\n * The input element.\n */\n inputElement: HTMLElement | null;\n /**\n * The label element.\n */\n labelElement: HTMLElement | null;\n /**\n * The value of the tag input.\n * @default \"\"\n */\n value: string;\n /**\n * The values of the selected tags.\n * @default []\n */\n values: string[];\n}\n\nexport interface TagStoreFunctions extends CompositeStoreFunctions<TagStoreItem> {\n /**\n * Sets the `inputElement` state.\n */\n setInputElement: SetState<TagStoreState[\"inputElement\"]>;\n /**\n * Sets the `labelElement` state.\n */\n setLabelElement: SetState<TagStoreState[\"labelElement\"]>;\n /**\n * Sets the [`value`](https://ariakit.com/reference/tag-provider#value) state.\n */\n setValue: SetState<TagStoreState[\"value\"]>;\n /**\n * Resets the [`value`](https://ariakit.com/reference/tag-provider#value)\n * state to its initial value.\n */\n resetValue: () => void;\n /**\n * Sets the [`values`](https://ariakit.com/reference/tag-provider#values) state.\n */\n setValues: SetState<TagStoreState[\"values\"]>;\n /**\n * Add a new value to the\n * [`values`](https://ariakit.com/reference/tag-provider#values) state if it\n * doesn't already exist.\n */\n addValue: (value: string) => void;\n /**\n * Remove a value from the\n * [`values`](https://ariakit.com/reference/tag-provider#values) state.\n */\n removeValue: (value: string) => void;\n}\n\nexport interface TagStoreOptions\n extends\n StoreOptions<TagStoreState, \"value\" | \"values\">,\n CompositeStoreOptions<TagStoreItem> {\n /**\n * The initial value of the tag input.\n * @default \"\"\n */\n defaultValue?: TagStoreState[\"value\"];\n /**\n * The initial selected tag values.\n * @default []\n */\n defaultValues?: TagStoreState[\"values\"];\n}\n\nexport interface TagStoreProps\n extends TagStoreOptions, StoreProps<TagStoreState> {}\n\nexport interface TagStore extends TagStoreFunctions, Store<TagStoreState> {}\n"],"mappings":";;;;;;;AAeA,SAAgB,eAAe,QAAuB,CAAC,GAAa;CAClE,MAAM,YAAY,MAAM,OAAO,SAAS;CACxC,MAAM,YAAY,qBAAqB,KAAK;CAE5C,MAAM,eAA8B;EAClC,GAAG,UAAU,SAAS;EACtB,cAAc,aAAa,WAAW,cAAc,IAAI;EACxD,cAAc,aAAa,WAAW,cAAc,IAAI;EACxD,OAAO,aAAa,MAAM,OAAO,WAAW,OAAO,MAAM,cAAc,EAAE;EACzE,QAAQ,aACN,MAAM,QACN,WAAW,QACX,MAAM,eACN,CAAC,CACH;CACF;CAEA,MAAM,MAAM,YAAY,cAAc,WAAW,MAAM,KAAK;CAI5D,MAAM,WACJ,KAAK,KAAK,CAAC,gBAAgB,UAAU,IAAI,UAAU;EACjD,IAAI,CAAC,MAAM,cAAc;EACzB,IAAI,MAAM,aAAa,KAAA,GAAW;EAClC,IAAI,SAAS,YAAY,MAAM,aAAa,EAAE;CAChD,CAAC,CACH;CAEA,MAAM,aAAoC,WAAW;EACnD,MAAM,EAAE,QAAQ,mBAAmB,IAAI,SAAS;EAChD,YAAiB,cAAc;GAC7B,IAAI,UAAU;GACd,IAAI,SAAS,WAAW,SAAS;IAC/B,MAAM,OAAO,WAAW,QAAQ,IAAI;IACpC,IAAI,SAAS,MACX,UAAU;IAEZ,OAAO;GACT,CAAC;GACD,IAAI,CAAC,SAAS;GACd,aAAa;IACX,IAAI,SAAS,UAAU,cAAc;IACrC,UAAU,KAAK,IAAI,SAAS,EAAE,cAAc,EAAE;GAChD;EACF,CAAC;CACH;CAEA,OAAO;EACL,GAAG;EACH,GAAG;EACH,kBAAkB,iBAChB,IAAI,SAAS,gBAAgB,YAAY;EAE3C,kBAAkB,iBAChB,IAAI,SAAS,gBAAgB,YAAY;EAE3C,WAAW,UAAU,IAAI,SAAS,SAAS,KAAK;EAEhD,kBAAkB,IAAI,SAAS,SAAS,aAAa,KAAK;EAE1D;EAEA,WAAW,UAAU;GACnB,WAAW,WAAW;IACpB,IAAI,OAAO,SAAS,KAAK,GAAG,OAAO;IACnC,OAAO,CAAC,GAAG,QAAQ,KAAK;GAC1B,CAAC;EACH;EAEA,cAAc,UACZ,WAAW,WAAW,OAAO,QAAQ,MAAM,MAAM,KAAK,CAAC;CAC3D;AACF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { i as CompositeStoreOptions, n as CompositeStoreFunctions, r as CompositeStoreItem, s as CompositeStoreState } from "./composite-store-B-iDEtZZ.js";
|
|
2
|
+
import { Store, StoreOptions, StoreProps } from "@ariakit/store";
|
|
3
|
+
import { SetState } from "@ariakit/utils";
|
|
4
|
+
|
|
5
|
+
//#region src/tag/tag-store.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a tag store.
|
|
8
|
+
*/
|
|
9
|
+
declare function createTagStore(props?: TagStoreProps): TagStore;
|
|
10
|
+
interface TagStoreItem extends CompositeStoreItem {
|
|
11
|
+
value?: string;
|
|
12
|
+
}
|
|
13
|
+
interface TagStoreState extends CompositeStoreState<TagStoreItem> {
|
|
14
|
+
/**
|
|
15
|
+
* The input element.
|
|
16
|
+
*/
|
|
17
|
+
inputElement: HTMLElement | null;
|
|
18
|
+
/**
|
|
19
|
+
* The label element.
|
|
20
|
+
*/
|
|
21
|
+
labelElement: HTMLElement | null;
|
|
22
|
+
/**
|
|
23
|
+
* The value of the tag input.
|
|
24
|
+
* @default ""
|
|
25
|
+
*/
|
|
26
|
+
value: string;
|
|
27
|
+
/**
|
|
28
|
+
* The values of the selected tags.
|
|
29
|
+
* @default []
|
|
30
|
+
*/
|
|
31
|
+
values: string[];
|
|
32
|
+
}
|
|
33
|
+
interface TagStoreFunctions extends CompositeStoreFunctions<TagStoreItem> {
|
|
34
|
+
/**
|
|
35
|
+
* Sets the `inputElement` state.
|
|
36
|
+
*/
|
|
37
|
+
setInputElement: SetState<TagStoreState["inputElement"]>;
|
|
38
|
+
/**
|
|
39
|
+
* Sets the `labelElement` state.
|
|
40
|
+
*/
|
|
41
|
+
setLabelElement: SetState<TagStoreState["labelElement"]>;
|
|
42
|
+
/**
|
|
43
|
+
* Sets the [`value`](https://ariakit.com/reference/tag-provider#value) state.
|
|
44
|
+
*/
|
|
45
|
+
setValue: SetState<TagStoreState["value"]>;
|
|
46
|
+
/**
|
|
47
|
+
* Resets the [`value`](https://ariakit.com/reference/tag-provider#value)
|
|
48
|
+
* state to its initial value.
|
|
49
|
+
*/
|
|
50
|
+
resetValue: () => void;
|
|
51
|
+
/**
|
|
52
|
+
* Sets the [`values`](https://ariakit.com/reference/tag-provider#values) state.
|
|
53
|
+
*/
|
|
54
|
+
setValues: SetState<TagStoreState["values"]>;
|
|
55
|
+
/**
|
|
56
|
+
* Add a new value to the
|
|
57
|
+
* [`values`](https://ariakit.com/reference/tag-provider#values) state if it
|
|
58
|
+
* doesn't already exist.
|
|
59
|
+
*/
|
|
60
|
+
addValue: (value: string) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Remove a value from the
|
|
63
|
+
* [`values`](https://ariakit.com/reference/tag-provider#values) state.
|
|
64
|
+
*/
|
|
65
|
+
removeValue: (value: string) => void;
|
|
66
|
+
}
|
|
67
|
+
interface TagStoreOptions extends StoreOptions<TagStoreState, "value" | "values">, CompositeStoreOptions<TagStoreItem> {
|
|
68
|
+
/**
|
|
69
|
+
* The initial value of the tag input.
|
|
70
|
+
* @default ""
|
|
71
|
+
*/
|
|
72
|
+
defaultValue?: TagStoreState["value"];
|
|
73
|
+
/**
|
|
74
|
+
* The initial selected tag values.
|
|
75
|
+
* @default []
|
|
76
|
+
*/
|
|
77
|
+
defaultValues?: TagStoreState["values"];
|
|
78
|
+
}
|
|
79
|
+
interface TagStoreProps extends TagStoreOptions, StoreProps<TagStoreState> {}
|
|
80
|
+
interface TagStore extends TagStoreFunctions, Store<TagStoreState> {}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { TagStoreProps as a, TagStoreOptions as i, TagStoreFunctions as n, TagStoreState as o, TagStoreItem as r, createTagStore as s, TagStore as t };
|
|
83
|
+
//# sourceMappingURL=tag-store-D47X5_zA.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag-store-D47X5_zA.d.ts","names":["Store","StoreOptions","StoreProps","SetState","CompositeStoreFunctions","CompositeStoreItem","CompositeStoreOptions","CompositeStoreState","createTagStore","TagStoreProps","TagStore","props","TagStoreItem","value","TagStoreState","HTMLElement","inputElement","labelElement","values","TagStoreFunctions","setInputElement","setLabelElement","setValue","resetValue","setValues","addValue","removeValue","TagStoreOptions","defaultValue","defaultValues"],"sources":["../src/tag/tag-store.d.ts"],"mappings":";;;;;;;AAMA;iBAAwBQ,cAAAA,CAAeG,KAAAA,GAAQF,aAAAA,GAAgBC,QAAQ;AAAA,UACtDE,YAAAA,SAAqBP,kBAAkB;EACpDQ,KAAK;AAAA;AAAA,UAEQC,aAAAA,SAAsBP,mBAAAA,CAAoBK,YAAAA;EAJIF;;AAAQ;EAQnEM,YAAAA,EAAcD,WAAAA;EAPW;;;EAWzBE,YAAAA,EAAcF,WAAAA;EARDD;;;;EAabD,KAAAA;EALcE;;;;EAUdG,MAAAA;AAAAA;AAAAA,UAEaC,iBAAAA,SAA0Bf,uBAAAA,CAAwBQ,YAAAA;EAhBjDG;;;EAoBdK,eAAAA,EAAiBjB,QAAAA,CAASW,aAAAA;EAN1BI;;AAAM;EAUNG,eAAAA,EAAiBlB,QAAAA,CAASW,aAAAA;EARI;;;EAY9BQ,QAAAA,EAAUnB,QAAAA,CAASW,aAAAA;EARFX;;;;EAajBoB,UAAAA;EAIoBT;;;EAApBU,SAAAA,EAAWrB,QAAAA,CAASW,aAAAA;EArB0C;;;;;EA2B9DW,QAAAA,GAAWZ,KAAAA;EAnBXQ;;;;EAwBAK,WAAAA,GAAcb,KAAAA;AAAAA;AAAAA,UAEDc,eAAAA,SAAwB1B,YAAAA,CAAaa,aAAAA,uBAAoCR,qBAAAA,CAAsBM,YAAAA;EAb5GY;;;;EAkBAI,YAAAA,GAAed,aAAAA;EAPfY;;;AAA2B;EAY3BG,aAAAA,GAAgBf,aAAAA;AAAAA;AAAAA,UAEHL,aAAAA,SAAsBkB,eAAAA,EAAiBzB,UAAAA,CAAWY,aAAAA;AAAAA,UAElDJ,QAAAA,SAAiBS,iBAAAA,EAAmBnB,KAAAA,CAAMc,aAAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { i as CompositeStoreOptions, n as CompositeStoreFunctions, s as CompositeStoreState } from "../composite-store-B-iDEtZZ.js";
|
|
2
|
+
import { Store, StoreOptions, StoreProps } from "@ariakit/store";
|
|
3
|
+
|
|
4
|
+
//#region src/toolbar/toolbar-store.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a toolbar store.
|
|
7
|
+
*/
|
|
8
|
+
declare function createToolbarStore(props?: ToolbarStoreProps): ToolbarStore;
|
|
9
|
+
interface ToolbarStoreState extends CompositeStoreState {
|
|
10
|
+
/** @default "horizontal" */
|
|
11
|
+
orientation: CompositeStoreState["orientation"];
|
|
12
|
+
/** @default true */
|
|
13
|
+
focusLoop: CompositeStoreState["focusLoop"];
|
|
14
|
+
}
|
|
15
|
+
interface ToolbarStoreFunctions extends CompositeStoreFunctions {}
|
|
16
|
+
interface ToolbarStoreOptions extends StoreOptions<ToolbarStoreState, "orientation" | "focusLoop">, CompositeStoreOptions {}
|
|
17
|
+
interface ToolbarStoreProps extends ToolbarStoreOptions, StoreProps<ToolbarStoreState> {}
|
|
18
|
+
interface ToolbarStore extends ToolbarStoreFunctions, Store<ToolbarStoreState> {}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ToolbarStore, ToolbarStoreFunctions, ToolbarStoreOptions, ToolbarStoreProps, ToolbarStoreState, createToolbarStore };
|
|
21
|
+
//# sourceMappingURL=toolbar-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolbar-store.d.ts","names":["Store","StoreOptions","StoreProps","CompositeStoreFunctions","CompositeStoreOptions","CompositeStoreState","createToolbarStore","ToolbarStoreProps","ToolbarStore","props","ToolbarStoreState","orientation","focusLoop","ToolbarStoreFunctions","ToolbarStoreOptions"],"sources":["../../src/toolbar/toolbar-store.d.ts"],"mappings":";;;;;;AAKA;iBAAwBM,kBAAAA,CAAmBG,KAAAA,GAAQF,iBAAAA,GAAoBC,YAAY;AAAA,UAClEE,iBAAAA,SAA0BL,mBAAAA;EADwC;EAG/EM,WAAAA,EAAaN,mBAAAA;EAH0BI;EAKvCG,SAAAA,EAAWP,mBAAAA;AAAAA;AAAAA,UAEEQ,qBAAAA,SAA8BV,uBAAuB;AAAA,UAErDW,mBAAAA,SAA4Bb,YAAAA,CAAaS,iBAAAA,gCAAiDN,qBAAAA;AAAAA,UAE1FG,iBAAAA,SAA0BO,mBAAAA,EAAqBZ,UAAAA,CAAWQ,iBAAAA;AAAAA,UAE1DF,YAAAA,SAAqBK,qBAAAA,EAAuBb,KAAAA,CAAMU,iBAAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createCompositeStore } from "../composite/composite-store.js";
|
|
2
|
+
import { defaultValue } from "@ariakit/utils";
|
|
3
|
+
//#region src/toolbar/toolbar-store.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a toolbar store.
|
|
6
|
+
*/
|
|
7
|
+
function createToolbarStore(props = {}) {
|
|
8
|
+
const syncState = props.store?.getState();
|
|
9
|
+
return createCompositeStore({
|
|
10
|
+
...props,
|
|
11
|
+
orientation: defaultValue(props.orientation, syncState?.orientation, "horizontal"),
|
|
12
|
+
focusLoop: defaultValue(props.focusLoop, syncState?.focusLoop, true)
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { createToolbarStore };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=toolbar-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolbar-store.js","names":[],"sources":["../../src/toolbar/toolbar-store.ts"],"sourcesContent":["import type { Store, StoreOptions, StoreProps } from \"@ariakit/store\";\nimport { defaultValue } from \"@ariakit/utils\";\nimport type {\n CompositeStoreFunctions,\n CompositeStoreOptions,\n CompositeStoreState,\n} from \"../composite/composite-store.ts\";\nimport { createCompositeStore } from \"../composite/composite-store.ts\";\n\n/**\n * Creates a toolbar store.\n */\nexport function createToolbarStore(\n props: ToolbarStoreProps = {},\n): ToolbarStore {\n const syncState = props.store?.getState();\n\n return createCompositeStore({\n ...props,\n orientation: defaultValue(\n props.orientation,\n syncState?.orientation,\n \"horizontal\" as const,\n ),\n focusLoop: defaultValue(props.focusLoop, syncState?.focusLoop, true),\n });\n}\n\nexport interface ToolbarStoreState extends CompositeStoreState {\n /** @default \"horizontal\" */\n orientation: CompositeStoreState[\"orientation\"];\n /** @default true */\n focusLoop: CompositeStoreState[\"focusLoop\"];\n}\n\nexport interface ToolbarStoreFunctions extends CompositeStoreFunctions {}\n\nexport interface ToolbarStoreOptions\n extends\n StoreOptions<ToolbarStoreState, \"orientation\" | \"focusLoop\">,\n CompositeStoreOptions {}\n\nexport interface ToolbarStoreProps\n extends ToolbarStoreOptions, StoreProps<ToolbarStoreState> {}\n\nexport interface ToolbarStore\n extends ToolbarStoreFunctions, Store<ToolbarStoreState> {}\n"],"mappings":";;;;;;AAYA,SAAgB,mBACd,QAA2B,CAAC,GACd;CACd,MAAM,YAAY,MAAM,OAAO,SAAS;CAExC,OAAO,qBAAqB;EAC1B,GAAG;EACH,aAAa,aACX,MAAM,aACN,WAAW,aACX,YACF;EACA,WAAW,aAAa,MAAM,WAAW,WAAW,WAAW,IAAI;CACrE,CAAC;AACH"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { HovercardStoreFunctions, HovercardStoreOptions, HovercardStoreState } from "../hovercard/hovercard-store.js";
|
|
2
|
+
import { Store, StoreOptions, StoreProps } from "@ariakit/store";
|
|
3
|
+
|
|
4
|
+
//#region src/tooltip/tooltip-store.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a tooltip store.
|
|
7
|
+
*/
|
|
8
|
+
declare function createTooltipStore(props?: TooltipStoreProps): TooltipStore;
|
|
9
|
+
interface TooltipStoreState extends HovercardStoreState {
|
|
10
|
+
/** @default "top" */
|
|
11
|
+
placement: HovercardStoreState["placement"];
|
|
12
|
+
/** @default 0 */
|
|
13
|
+
hideTimeout?: HovercardStoreState["hideTimeout"];
|
|
14
|
+
/**
|
|
15
|
+
* Determines whether the tooltip is being used as a label or a description
|
|
16
|
+
* for the anchor element.
|
|
17
|
+
* @deprecated Render a visually hidden label or use the `aria-label` or
|
|
18
|
+
* `aria-labelledby` attributes on the anchor element instead.
|
|
19
|
+
* @default "description"
|
|
20
|
+
*/
|
|
21
|
+
type: "label" | "description";
|
|
22
|
+
/**
|
|
23
|
+
* The amount of time after a tooltip is hidden while all tooltips on the
|
|
24
|
+
* page can be shown immediately, without waiting for the show timeout.
|
|
25
|
+
* @default 300
|
|
26
|
+
*/
|
|
27
|
+
skipTimeout: number;
|
|
28
|
+
}
|
|
29
|
+
type TooltipStoreFunctions = HovercardStoreFunctions;
|
|
30
|
+
interface TooltipStoreOptions extends StoreOptions<TooltipStoreState, "type" | "placement" | "timeout" | "showTimeout" | "hideTimeout" | "skipTimeout">, HovercardStoreOptions {}
|
|
31
|
+
interface TooltipStoreProps extends TooltipStoreOptions, StoreProps<TooltipStoreState> {}
|
|
32
|
+
interface TooltipStore extends TooltipStoreFunctions, Store<TooltipStoreState> {}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { TooltipStore, TooltipStoreFunctions, TooltipStoreOptions, TooltipStoreProps, TooltipStoreState, createTooltipStore };
|
|
35
|
+
//# sourceMappingURL=tooltip-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip-store.d.ts","names":["Store","StoreOptions","StoreProps","HovercardStoreFunctions","HovercardStoreOptions","HovercardStoreState","createTooltipStore","TooltipStoreProps","TooltipStore","props","TooltipStoreState","placement","hideTimeout","type","skipTimeout","TooltipStoreFunctions","TooltipStoreOptions"],"sources":["../../src/tooltip/tooltip-store.d.ts"],"mappings":";;;;;;AAKA;iBAAwBM,kBAAAA,CAAmBG,KAAAA,GAAQF,iBAAAA,GAAoBC,YAAY;AAAA,UAClEE,iBAAAA,SAA0BL,mBAAAA;EADwC;EAG/EM,SAAAA,EAAWN,mBAAAA;EAH4BI;EAKvCG,WAAAA,GAAcP,mBAAAA;EALiE;AAAA;AACnF;;;;;EAYIQ,IAAAA;EAZ0D;;;;;EAkB1DC,WAAAA;AAAAA;AAAAA,KAEQC,qBAAAA,GAAwBZ,uBAAuB;AAAA,UAC1Ca,mBAAAA,SAA4Bf,YAAAA,CAAaS,iBAAAA,qFAAsGN,qBAAAA;AAAAA,UAE/IG,iBAAAA,SAA0BS,mBAAAA,EAAqBd,UAAAA,CAAWQ,iBAAAA;AAAAA,UAE1DF,YAAAA,SAAqBO,qBAAAA,EAAuBf,KAAAA,CAAMU,iBAAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createHovercardStore } from "../hovercard/hovercard-store.js";
|
|
2
|
+
import { createStore } from "@ariakit/store";
|
|
3
|
+
import { defaultValue } from "@ariakit/utils";
|
|
4
|
+
//#region src/tooltip/tooltip-store.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a tooltip store.
|
|
7
|
+
*/
|
|
8
|
+
function createTooltipStore(props = {}) {
|
|
9
|
+
if (props.type === "label") console.warn("The `type` option on the tooltip store is deprecated.", "Render a visually hidden label or use the `aria-label` or `aria-labelledby` attributes on the anchor element instead.", "See https://ariakit.com/components/tooltip#tooltip-anchors-must-have-accessible-names");
|
|
10
|
+
const syncState = props.store?.getState();
|
|
11
|
+
const hovercard = createHovercardStore({
|
|
12
|
+
...props,
|
|
13
|
+
placement: defaultValue(props.placement, syncState?.placement, "top"),
|
|
14
|
+
hideTimeout: defaultValue(props.hideTimeout, syncState?.hideTimeout, 0)
|
|
15
|
+
});
|
|
16
|
+
const tooltip = createStore({
|
|
17
|
+
...hovercard.getState(),
|
|
18
|
+
type: defaultValue(props.type, syncState?.type, "description"),
|
|
19
|
+
skipTimeout: defaultValue(props.skipTimeout, syncState?.skipTimeout, 300)
|
|
20
|
+
}, hovercard, props.store);
|
|
21
|
+
return {
|
|
22
|
+
...hovercard,
|
|
23
|
+
...tooltip
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { createTooltipStore };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=tooltip-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip-store.js","names":[],"sources":["../../src/tooltip/tooltip-store.ts"],"sourcesContent":["import { createStore } from \"@ariakit/store\";\nimport type { Store, StoreOptions, StoreProps } from \"@ariakit/store\";\nimport { defaultValue } from \"@ariakit/utils\";\nimport type {\n HovercardStoreFunctions,\n HovercardStoreOptions,\n HovercardStoreState,\n} from \"../hovercard/hovercard-store.ts\";\nimport { createHovercardStore } from \"../hovercard/hovercard-store.ts\";\n\n/**\n * Creates a tooltip store.\n */\nexport function createTooltipStore(\n props: TooltipStoreProps = {},\n): TooltipStore {\n if (process.env.NODE_ENV !== \"production\") {\n if (props.type === \"label\") {\n console.warn(\n \"The `type` option on the tooltip store is deprecated.\",\n \"Render a visually hidden label or use the `aria-label` or `aria-labelledby` attributes on the anchor element instead.\",\n \"See https://ariakit.com/components/tooltip#tooltip-anchors-must-have-accessible-names\",\n );\n }\n }\n\n const syncState = props.store?.getState();\n\n const hovercard = createHovercardStore({\n ...props,\n placement: defaultValue(\n props.placement,\n syncState?.placement,\n \"top\" as const,\n ),\n hideTimeout: defaultValue(props.hideTimeout, syncState?.hideTimeout, 0),\n });\n\n const initialState: TooltipStoreState = {\n ...hovercard.getState(),\n type: defaultValue(props.type, syncState?.type, \"description\" as const),\n skipTimeout: defaultValue(props.skipTimeout, syncState?.skipTimeout, 300),\n };\n\n const tooltip = createStore(initialState, hovercard, props.store);\n\n return {\n ...hovercard,\n ...tooltip,\n };\n}\n\nexport interface TooltipStoreState extends HovercardStoreState {\n /** @default \"top\" */\n placement: HovercardStoreState[\"placement\"];\n /** @default 0 */\n hideTimeout?: HovercardStoreState[\"hideTimeout\"];\n /**\n * Determines whether the tooltip is being used as a label or a description\n * for the anchor element.\n * @deprecated Render a visually hidden label or use the `aria-label` or\n * `aria-labelledby` attributes on the anchor element instead.\n * @default \"description\"\n */\n type: \"label\" | \"description\";\n /**\n * The amount of time after a tooltip is hidden while all tooltips on the\n * page can be shown immediately, without waiting for the show timeout.\n * @default 300\n */\n skipTimeout: number;\n}\n\nexport type TooltipStoreFunctions = HovercardStoreFunctions;\n\nexport interface TooltipStoreOptions\n extends\n StoreOptions<\n TooltipStoreState,\n | \"type\"\n | \"placement\"\n | \"timeout\"\n | \"showTimeout\"\n | \"hideTimeout\"\n | \"skipTimeout\"\n >,\n HovercardStoreOptions {}\n\nexport interface TooltipStoreProps\n extends TooltipStoreOptions, StoreProps<TooltipStoreState> {}\n\nexport interface TooltipStore\n extends TooltipStoreFunctions, Store<TooltipStoreState> {}\n"],"mappings":";;;;;;;AAaA,SAAgB,mBACd,QAA2B,CAAC,GACd;CAEZ,IAAI,MAAM,SAAS,SACjB,QAAQ,KACN,yDACA,yHACA,uFACF;CAIJ,MAAM,YAAY,MAAM,OAAO,SAAS;CAExC,MAAM,YAAY,qBAAqB;EACrC,GAAG;EACH,WAAW,aACT,MAAM,WACN,WAAW,WACX,KACF;EACA,aAAa,aAAa,MAAM,aAAa,WAAW,aAAa,CAAC;CACxE,CAAC;CAQD,MAAM,UAAU,YAAY;EAL1B,GAAG,UAAU,SAAS;EACtB,MAAM,aAAa,MAAM,MAAM,WAAW,MAAM,aAAsB;EACtE,aAAa,aAAa,MAAM,aAAa,WAAW,aAAa,GAAG;CAGnC,GAAG,WAAW,MAAM,KAAK;CAEhE,OAAO;EACL,GAAG;EACH,GAAG;CACL;AACF"}
|
package/license
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Ariakit FZ-LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|