@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,170 @@
|
|
|
1
|
+
import { createStore, setup, sync } from "@ariakit/store";
|
|
2
|
+
import type { Store, StoreOptions, StoreProps } from "@ariakit/store";
|
|
3
|
+
import { applyState, defaultValue, UndoManager } from "@ariakit/utils";
|
|
4
|
+
import type { SetState } from "@ariakit/utils";
|
|
5
|
+
import type {
|
|
6
|
+
CompositeStoreFunctions,
|
|
7
|
+
CompositeStoreItem,
|
|
8
|
+
CompositeStoreOptions,
|
|
9
|
+
CompositeStoreState,
|
|
10
|
+
} from "../composite/composite-store.ts";
|
|
11
|
+
import { createCompositeStore } from "../composite/composite-store.ts";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates a tag store.
|
|
15
|
+
*/
|
|
16
|
+
export function createTagStore(props: TagStoreProps = {}): TagStore {
|
|
17
|
+
const syncState = props.store?.getState();
|
|
18
|
+
const composite = createCompositeStore(props);
|
|
19
|
+
|
|
20
|
+
const initialState: TagStoreState = {
|
|
21
|
+
...composite.getState(),
|
|
22
|
+
inputElement: defaultValue(syncState?.inputElement, null),
|
|
23
|
+
labelElement: defaultValue(syncState?.labelElement, null),
|
|
24
|
+
value: defaultValue(props.value, syncState?.value, props.defaultValue, ""),
|
|
25
|
+
values: defaultValue(
|
|
26
|
+
props.values,
|
|
27
|
+
syncState?.values,
|
|
28
|
+
props.defaultValues,
|
|
29
|
+
[],
|
|
30
|
+
),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const tag = createStore(initialState, composite, props.store);
|
|
34
|
+
|
|
35
|
+
// Set the input element as the default active element, that is, the element
|
|
36
|
+
// that will receive focus when the composite widget is focused.
|
|
37
|
+
setup(tag, () =>
|
|
38
|
+
sync(tag, ["inputElement", "activeId"], (state) => {
|
|
39
|
+
if (!state.inputElement) return;
|
|
40
|
+
if (state.activeId !== undefined) return;
|
|
41
|
+
tag.setState("activeId", state.inputElement.id);
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const setValues: TagStore["setValues"] = (values) => {
|
|
46
|
+
const { values: previousValues } = tag.getState();
|
|
47
|
+
void UndoManager.execute(() => {
|
|
48
|
+
let changed = true;
|
|
49
|
+
tag.setState("values", (prev) => {
|
|
50
|
+
const next = applyState(values, prev);
|
|
51
|
+
if (next === prev) {
|
|
52
|
+
changed = false;
|
|
53
|
+
}
|
|
54
|
+
return next;
|
|
55
|
+
});
|
|
56
|
+
if (!changed) return;
|
|
57
|
+
return () => {
|
|
58
|
+
tag.setState("values", previousValues);
|
|
59
|
+
composite.move(tag.getState().inputElement?.id);
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
...composite,
|
|
66
|
+
...tag,
|
|
67
|
+
setInputElement: (inputElement) =>
|
|
68
|
+
tag.setState("inputElement", inputElement),
|
|
69
|
+
|
|
70
|
+
setLabelElement: (labelElement) =>
|
|
71
|
+
tag.setState("labelElement", labelElement),
|
|
72
|
+
|
|
73
|
+
setValue: (value) => tag.setState("value", value),
|
|
74
|
+
|
|
75
|
+
resetValue: () => tag.setState("value", initialState.value),
|
|
76
|
+
|
|
77
|
+
setValues,
|
|
78
|
+
|
|
79
|
+
addValue: (value) => {
|
|
80
|
+
setValues((values) => {
|
|
81
|
+
if (values.includes(value)) return values;
|
|
82
|
+
return [...values, value];
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
removeValue: (value) =>
|
|
87
|
+
setValues((values) => values.filter((v) => v !== value)),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface TagStoreItem extends CompositeStoreItem {
|
|
92
|
+
value?: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface TagStoreState extends CompositeStoreState<TagStoreItem> {
|
|
96
|
+
/**
|
|
97
|
+
* The input element.
|
|
98
|
+
*/
|
|
99
|
+
inputElement: HTMLElement | null;
|
|
100
|
+
/**
|
|
101
|
+
* The label element.
|
|
102
|
+
*/
|
|
103
|
+
labelElement: HTMLElement | null;
|
|
104
|
+
/**
|
|
105
|
+
* The value of the tag input.
|
|
106
|
+
* @default ""
|
|
107
|
+
*/
|
|
108
|
+
value: string;
|
|
109
|
+
/**
|
|
110
|
+
* The values of the selected tags.
|
|
111
|
+
* @default []
|
|
112
|
+
*/
|
|
113
|
+
values: string[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface TagStoreFunctions extends CompositeStoreFunctions<TagStoreItem> {
|
|
117
|
+
/**
|
|
118
|
+
* Sets the `inputElement` state.
|
|
119
|
+
*/
|
|
120
|
+
setInputElement: SetState<TagStoreState["inputElement"]>;
|
|
121
|
+
/**
|
|
122
|
+
* Sets the `labelElement` state.
|
|
123
|
+
*/
|
|
124
|
+
setLabelElement: SetState<TagStoreState["labelElement"]>;
|
|
125
|
+
/**
|
|
126
|
+
* Sets the [`value`](https://ariakit.com/reference/tag-provider#value) state.
|
|
127
|
+
*/
|
|
128
|
+
setValue: SetState<TagStoreState["value"]>;
|
|
129
|
+
/**
|
|
130
|
+
* Resets the [`value`](https://ariakit.com/reference/tag-provider#value)
|
|
131
|
+
* state to its initial value.
|
|
132
|
+
*/
|
|
133
|
+
resetValue: () => void;
|
|
134
|
+
/**
|
|
135
|
+
* Sets the [`values`](https://ariakit.com/reference/tag-provider#values) state.
|
|
136
|
+
*/
|
|
137
|
+
setValues: SetState<TagStoreState["values"]>;
|
|
138
|
+
/**
|
|
139
|
+
* Add a new value to the
|
|
140
|
+
* [`values`](https://ariakit.com/reference/tag-provider#values) state if it
|
|
141
|
+
* doesn't already exist.
|
|
142
|
+
*/
|
|
143
|
+
addValue: (value: string) => void;
|
|
144
|
+
/**
|
|
145
|
+
* Remove a value from the
|
|
146
|
+
* [`values`](https://ariakit.com/reference/tag-provider#values) state.
|
|
147
|
+
*/
|
|
148
|
+
removeValue: (value: string) => void;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface TagStoreOptions
|
|
152
|
+
extends
|
|
153
|
+
StoreOptions<TagStoreState, "value" | "values">,
|
|
154
|
+
CompositeStoreOptions<TagStoreItem> {
|
|
155
|
+
/**
|
|
156
|
+
* The initial value of the tag input.
|
|
157
|
+
* @default ""
|
|
158
|
+
*/
|
|
159
|
+
defaultValue?: TagStoreState["value"];
|
|
160
|
+
/**
|
|
161
|
+
* The initial selected tag values.
|
|
162
|
+
* @default []
|
|
163
|
+
*/
|
|
164
|
+
defaultValues?: TagStoreState["values"];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface TagStoreProps
|
|
168
|
+
extends TagStoreOptions, StoreProps<TagStoreState> {}
|
|
169
|
+
|
|
170
|
+
export interface TagStore extends TagStoreFunctions, Store<TagStoreState> {}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Store, StoreOptions, StoreProps } from "@ariakit/store";
|
|
2
|
+
import { defaultValue } from "@ariakit/utils";
|
|
3
|
+
import type {
|
|
4
|
+
CompositeStoreFunctions,
|
|
5
|
+
CompositeStoreOptions,
|
|
6
|
+
CompositeStoreState,
|
|
7
|
+
} from "../composite/composite-store.ts";
|
|
8
|
+
import { createCompositeStore } from "../composite/composite-store.ts";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a toolbar store.
|
|
12
|
+
*/
|
|
13
|
+
export function createToolbarStore(
|
|
14
|
+
props: ToolbarStoreProps = {},
|
|
15
|
+
): ToolbarStore {
|
|
16
|
+
const syncState = props.store?.getState();
|
|
17
|
+
|
|
18
|
+
return createCompositeStore({
|
|
19
|
+
...props,
|
|
20
|
+
orientation: defaultValue(
|
|
21
|
+
props.orientation,
|
|
22
|
+
syncState?.orientation,
|
|
23
|
+
"horizontal" as const,
|
|
24
|
+
),
|
|
25
|
+
focusLoop: defaultValue(props.focusLoop, syncState?.focusLoop, true),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ToolbarStoreState extends CompositeStoreState {
|
|
30
|
+
/** @default "horizontal" */
|
|
31
|
+
orientation: CompositeStoreState["orientation"];
|
|
32
|
+
/** @default true */
|
|
33
|
+
focusLoop: CompositeStoreState["focusLoop"];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ToolbarStoreFunctions extends CompositeStoreFunctions {}
|
|
37
|
+
|
|
38
|
+
export interface ToolbarStoreOptions
|
|
39
|
+
extends
|
|
40
|
+
StoreOptions<ToolbarStoreState, "orientation" | "focusLoop">,
|
|
41
|
+
CompositeStoreOptions {}
|
|
42
|
+
|
|
43
|
+
export interface ToolbarStoreProps
|
|
44
|
+
extends ToolbarStoreOptions, StoreProps<ToolbarStoreState> {}
|
|
45
|
+
|
|
46
|
+
export interface ToolbarStore
|
|
47
|
+
extends ToolbarStoreFunctions, Store<ToolbarStoreState> {}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { createStore } from "@ariakit/store";
|
|
2
|
+
import type { Store, StoreOptions, StoreProps } from "@ariakit/store";
|
|
3
|
+
import { defaultValue } from "@ariakit/utils";
|
|
4
|
+
import type {
|
|
5
|
+
HovercardStoreFunctions,
|
|
6
|
+
HovercardStoreOptions,
|
|
7
|
+
HovercardStoreState,
|
|
8
|
+
} from "../hovercard/hovercard-store.ts";
|
|
9
|
+
import { createHovercardStore } from "../hovercard/hovercard-store.ts";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a tooltip store.
|
|
13
|
+
*/
|
|
14
|
+
export function createTooltipStore(
|
|
15
|
+
props: TooltipStoreProps = {},
|
|
16
|
+
): TooltipStore {
|
|
17
|
+
if (process.env.NODE_ENV !== "production") {
|
|
18
|
+
if (props.type === "label") {
|
|
19
|
+
console.warn(
|
|
20
|
+
"The `type` option on the tooltip store is deprecated.",
|
|
21
|
+
"Render a visually hidden label or use the `aria-label` or `aria-labelledby` attributes on the anchor element instead.",
|
|
22
|
+
"See https://ariakit.com/components/tooltip#tooltip-anchors-must-have-accessible-names",
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const syncState = props.store?.getState();
|
|
28
|
+
|
|
29
|
+
const hovercard = createHovercardStore({
|
|
30
|
+
...props,
|
|
31
|
+
placement: defaultValue(
|
|
32
|
+
props.placement,
|
|
33
|
+
syncState?.placement,
|
|
34
|
+
"top" as const,
|
|
35
|
+
),
|
|
36
|
+
hideTimeout: defaultValue(props.hideTimeout, syncState?.hideTimeout, 0),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const initialState: TooltipStoreState = {
|
|
40
|
+
...hovercard.getState(),
|
|
41
|
+
type: defaultValue(props.type, syncState?.type, "description" as const),
|
|
42
|
+
skipTimeout: defaultValue(props.skipTimeout, syncState?.skipTimeout, 300),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const tooltip = createStore(initialState, hovercard, props.store);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
...hovercard,
|
|
49
|
+
...tooltip,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface TooltipStoreState extends HovercardStoreState {
|
|
54
|
+
/** @default "top" */
|
|
55
|
+
placement: HovercardStoreState["placement"];
|
|
56
|
+
/** @default 0 */
|
|
57
|
+
hideTimeout?: HovercardStoreState["hideTimeout"];
|
|
58
|
+
/**
|
|
59
|
+
* Determines whether the tooltip is being used as a label or a description
|
|
60
|
+
* for the anchor element.
|
|
61
|
+
* @deprecated Render a visually hidden label or use the `aria-label` or
|
|
62
|
+
* `aria-labelledby` attributes on the anchor element instead.
|
|
63
|
+
* @default "description"
|
|
64
|
+
*/
|
|
65
|
+
type: "label" | "description";
|
|
66
|
+
/**
|
|
67
|
+
* The amount of time after a tooltip is hidden while all tooltips on the
|
|
68
|
+
* page can be shown immediately, without waiting for the show timeout.
|
|
69
|
+
* @default 300
|
|
70
|
+
*/
|
|
71
|
+
skipTimeout: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type TooltipStoreFunctions = HovercardStoreFunctions;
|
|
75
|
+
|
|
76
|
+
export interface TooltipStoreOptions
|
|
77
|
+
extends
|
|
78
|
+
StoreOptions<
|
|
79
|
+
TooltipStoreState,
|
|
80
|
+
| "type"
|
|
81
|
+
| "placement"
|
|
82
|
+
| "timeout"
|
|
83
|
+
| "showTimeout"
|
|
84
|
+
| "hideTimeout"
|
|
85
|
+
| "skipTimeout"
|
|
86
|
+
>,
|
|
87
|
+
HovercardStoreOptions {}
|
|
88
|
+
|
|
89
|
+
export interface TooltipStoreProps
|
|
90
|
+
extends TooltipStoreOptions, StoreProps<TooltipStoreState> {}
|
|
91
|
+
|
|
92
|
+
export interface TooltipStore
|
|
93
|
+
extends TooltipStoreFunctions, Store<TooltipStoreState> {}
|