@ariakit/react-core 0.4.4 → 0.4.5
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 +16 -0
- package/cjs/__chunks/{QUHFOHHT.cjs → 3HMQOCLF.cjs} +10 -27
- package/cjs/__chunks/{YO7LLGVA.cjs → AY5J25V7.cjs} +2 -2
- package/cjs/__chunks/{4XVTH6OR.cjs → DFXPO2ED.cjs} +2 -2
- package/cjs/__chunks/{HPNCFYQJ.cjs → GZ2NNSLV.cjs} +4 -4
- package/cjs/__chunks/ISJGSS4S.cjs +16 -0
- package/cjs/__chunks/{COWKMNMZ.cjs → N43E53E6.cjs} +3 -3
- package/cjs/__chunks/{54YZYOPA.cjs → NRPEUNJB.cjs} +2 -2
- package/cjs/__chunks/PVLZGFP6.cjs +34 -0
- package/cjs/__chunks/{ZTAE5B6W.cjs → QJDA4LG6.cjs} +19 -16
- package/cjs/__chunks/{NDVZ37O3.cjs → RG6U7KAS.cjs} +22 -4
- package/cjs/__chunks/YWAHOWYE.cjs +25 -0
- package/cjs/combobox/combobox-cancel.cjs +3 -3
- package/cjs/combobox/combobox-disclosure.cjs +3 -3
- package/cjs/combobox/combobox-item.cjs +19 -9
- package/cjs/combobox/combobox-item.d.cts +22 -12
- package/cjs/combobox/combobox-item.d.ts +22 -12
- package/cjs/combobox/combobox-popover.cjs +22 -15
- package/cjs/combobox/combobox-provider.cjs +3 -2
- package/cjs/combobox/combobox-store.cjs +6 -2
- package/cjs/combobox/combobox-store.d.cts +12 -4
- package/cjs/combobox/combobox-store.d.ts +12 -4
- package/cjs/combobox/combobox-value.cjs +32 -0
- package/cjs/combobox/combobox-value.d.cts +41 -0
- package/cjs/combobox/combobox-value.d.ts +41 -0
- package/cjs/combobox/combobox.cjs +66 -22
- package/cjs/composite/composite-item.cjs +3 -3
- package/cjs/composite/composite-overflow-disclosure.cjs +3 -3
- package/cjs/composite/composite-overflow.cjs +12 -12
- package/cjs/dialog/dialog-backdrop.cjs +3 -3
- package/cjs/dialog/dialog.cjs +11 -11
- package/cjs/dialog/dialog.d.cts +4 -0
- package/cjs/dialog/dialog.d.ts +4 -0
- package/cjs/dialog/utils/disable-tree.cjs +3 -3
- package/cjs/dialog/utils/use-prevent-body-scroll.cjs +3 -3
- package/cjs/form/form-checkbox.cjs +1 -1
- package/cjs/form/form-push.cjs +1 -1
- package/cjs/form/form-radio.cjs +4 -4
- package/cjs/hovercard/hovercard.cjs +13 -13
- package/cjs/menu/menu-item-checkbox.cjs +4 -4
- package/cjs/menu/menu-item-radio.cjs +7 -7
- package/cjs/menu/menu-item.cjs +4 -4
- package/cjs/menu/menu.cjs +14 -14
- package/cjs/popover/popover.cjs +12 -12
- package/cjs/radio/radio.cjs +4 -4
- package/cjs/select/select-item.cjs +4 -4
- package/cjs/select/select-popover.cjs +13 -13
- package/cjs/select/select-value.d.cts +8 -7
- package/cjs/select/select-value.d.ts +8 -7
- package/cjs/select/select.cjs +1 -1
- package/cjs/tab/tab-panel.cjs +2 -2
- package/cjs/tab/tab.cjs +7 -7
- package/cjs/tag/tag-context.cjs +25 -0
- package/cjs/tag/tag-context.d.cts +21 -0
- package/cjs/tag/tag-context.d.ts +21 -0
- package/cjs/tag/tag-input.cjs +191 -0
- package/cjs/tag/tag-input.d.cts +122 -0
- package/cjs/tag/tag-input.d.ts +122 -0
- package/cjs/tag/tag-list-label.cjs +56 -0
- package/cjs/tag/tag-list-label.d.cts +55 -0
- package/cjs/tag/tag-list-label.d.ts +55 -0
- package/cjs/tag/tag-list.cjs +141 -0
- package/cjs/tag/tag-list.d.cts +58 -0
- package/cjs/tag/tag-list.d.ts +58 -0
- package/cjs/tag/tag-provider.cjs +26 -0
- package/cjs/tag/tag-provider.d.cts +29 -0
- package/cjs/tag/tag-provider.d.ts +29 -0
- package/cjs/tag/tag-remove.cjs +119 -0
- package/cjs/tag/tag-remove.d.cts +67 -0
- package/cjs/tag/tag-remove.d.ts +67 -0
- package/cjs/tag/tag-store.cjs +15 -0
- package/cjs/tag/tag-store.d.cts +49 -0
- package/cjs/tag/tag-store.d.ts +49 -0
- package/cjs/tag/tag-value.cjs +29 -0
- package/cjs/tag/tag-value.d.cts +41 -0
- package/cjs/tag/tag-value.d.ts +41 -0
- package/cjs/tag/tag-values.cjs +29 -0
- package/cjs/tag/tag-values.d.cts +52 -0
- package/cjs/tag/tag-values.d.ts +52 -0
- package/cjs/tag/tag.cjs +130 -0
- package/cjs/tag/tag.d.cts +74 -0
- package/cjs/tag/tag.d.ts +74 -0
- package/cjs/tag/utils.cjs +8 -0
- package/cjs/tag/utils.d.cts +1 -0
- package/cjs/tag/utils.d.ts +1 -0
- package/cjs/toolbar/toolbar-container.cjs +4 -4
- package/cjs/toolbar/toolbar-input.cjs +4 -4
- package/cjs/toolbar/toolbar-item.cjs +4 -4
- package/cjs/tooltip/tooltip.cjs +14 -14
- package/combobox/combobox-value/package.json +8 -0
- package/esm/__chunks/{XEJ23EM6.js → 65LF6MEO.js} +2 -2
- package/esm/__chunks/{LTYEFENI.js → 6YVAEELE.js} +1 -1
- package/esm/__chunks/{ZFEEEZVE.js → DLLQM6DZ.js} +22 -4
- package/esm/__chunks/{IOUGWXY5.js → FGHVVLPU.js} +20 -17
- package/esm/__chunks/L7IM35RU.js +16 -0
- package/esm/__chunks/{NFPDVAAW.js → M354SEUF.js} +1 -1
- package/esm/__chunks/QNNHZL3W.js +25 -0
- package/esm/__chunks/{DSUHLHLE.js → QZJOXZKA.js} +1 -1
- package/esm/__chunks/{NHVUMSP7.js → UKDZLPKH.js} +1 -1
- package/esm/__chunks/{R33ISPJY.js → VGORKDMQ.js} +11 -28
- package/esm/__chunks/WYDDZRWN.js +34 -0
- package/esm/combobox/combobox-cancel.js +3 -3
- package/esm/combobox/combobox-disclosure.js +3 -3
- package/esm/combobox/combobox-item.d.ts +22 -12
- package/esm/combobox/combobox-item.js +19 -9
- package/esm/combobox/combobox-popover.js +20 -13
- package/esm/combobox/combobox-provider.js +2 -1
- package/esm/combobox/combobox-store.d.ts +12 -4
- package/esm/combobox/combobox-store.js +5 -1
- package/esm/combobox/combobox-value.d.ts +41 -0
- package/esm/combobox/combobox-value.js +32 -0
- package/esm/combobox/combobox.js +67 -23
- package/esm/composite/composite-item.js +2 -2
- package/esm/composite/composite-overflow-disclosure.js +2 -2
- package/esm/composite/composite-overflow.js +11 -11
- package/esm/dialog/dialog-backdrop.js +2 -2
- package/esm/dialog/dialog.d.ts +4 -0
- package/esm/dialog/dialog.js +10 -10
- package/esm/dialog/utils/disable-tree.js +2 -2
- package/esm/dialog/utils/use-prevent-body-scroll.js +2 -2
- package/esm/form/form-checkbox.js +1 -1
- package/esm/form/form-push.js +1 -1
- package/esm/form/form-radio.js +3 -3
- package/esm/hovercard/hovercard.js +12 -12
- package/esm/menu/menu-item-checkbox.js +3 -3
- package/esm/menu/menu-item-radio.js +5 -5
- package/esm/menu/menu-item.js +3 -3
- package/esm/menu/menu.js +12 -12
- package/esm/popover/popover.js +11 -11
- package/esm/radio/radio.js +3 -3
- package/esm/select/select-item.js +4 -4
- package/esm/select/select-popover.js +11 -11
- package/esm/select/select-value.d.ts +8 -7
- package/esm/select/select.js +1 -1
- package/esm/tab/tab-panel.js +3 -3
- package/esm/tab/tab.js +5 -5
- package/esm/tag/tag-context.d.ts +21 -0
- package/esm/tag/tag-context.js +25 -0
- package/esm/tag/tag-input.d.ts +122 -0
- package/esm/tag/tag-input.js +191 -0
- package/esm/tag/tag-list-label.d.ts +55 -0
- package/esm/tag/tag-list-label.js +56 -0
- package/esm/tag/tag-list.d.ts +58 -0
- package/esm/tag/tag-list.js +141 -0
- package/esm/tag/tag-provider.d.ts +29 -0
- package/esm/tag/tag-provider.js +26 -0
- package/esm/tag/tag-remove.d.ts +67 -0
- package/esm/tag/tag-remove.js +119 -0
- package/esm/tag/tag-store.d.ts +49 -0
- package/esm/tag/tag-store.js +15 -0
- package/esm/tag/tag-value.d.ts +41 -0
- package/esm/tag/tag-value.js +29 -0
- package/esm/tag/tag-values.d.ts +52 -0
- package/esm/tag/tag-values.js +29 -0
- package/esm/tag/tag.d.ts +74 -0
- package/esm/tag/tag.js +130 -0
- package/esm/tag/utils.d.ts +1 -0
- package/esm/tag/utils.js +8 -0
- package/esm/toolbar/toolbar-container.js +3 -3
- package/esm/toolbar/toolbar-input.js +3 -3
- package/esm/toolbar/toolbar-item.js +3 -3
- package/esm/tooltip/tooltip.js +12 -12
- package/package.json +86 -2
- package/tag/tag/package.json +8 -0
- package/tag/tag-context/package.json +8 -0
- package/tag/tag-input/package.json +8 -0
- package/tag/tag-list/package.json +8 -0
- package/tag/tag-list-label/package.json +8 -0
- package/tag/tag-provider/package.json +8 -0
- package/tag/tag-remove/package.json +8 -0
- package/tag/tag-store/package.json +8 -0
- package/tag/tag-value/package.json +8 -0
- package/tag/tag-values/package.json +8 -0
- package/tag/utils/package.json +8 -0
- package/cjs/__chunks/{37BRXQN7.cjs → BX2QEIBH.cjs} +3 -3
- package/cjs/__chunks/{PVYTX5U5.cjs → SL55T4ZB.cjs} +2 -2
- package/cjs/__chunks/{TSEXNK3K.cjs → VR6GCLOV.cjs} +2 -2
- package/esm/__chunks/{PTPUIM7N.js → 3TEK3C5Q.js} +3 -3
- package/esm/__chunks/{U2L67A6K.js → BC72XE6E.js} +3 -3
- package/esm/__chunks/{GOXKZAQI.js → CMFBAHKI.js} +3 -3
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ElementType, MouseEvent } from "react";
|
|
2
|
+
import type { BooleanOrCallback } from "@ariakit/core/utils/types";
|
|
3
|
+
import type { Options, Props } from "../utils/types.js";
|
|
4
|
+
import type { TagStore } from "./tag-store.js";
|
|
5
|
+
declare const TagName = "button";
|
|
6
|
+
type TagName = typeof TagName;
|
|
7
|
+
type HTMLType = HTMLElementTagNameMap[TagName];
|
|
8
|
+
/**
|
|
9
|
+
* Returns props to create a `TagRemove` component.
|
|
10
|
+
* @see https://ariakit.org/components/tag
|
|
11
|
+
* @example
|
|
12
|
+
* ```jsx
|
|
13
|
+
* const props = useTagRemove();
|
|
14
|
+
* <Role.button {...props} />
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const useTagRemove: import("../utils/types.js").Hook<"button", TagRemoveOptions<"button">>;
|
|
18
|
+
/**
|
|
19
|
+
* Renders a `Backspace` icon inside a
|
|
20
|
+
* [`Tag`](https://ariakit.org/reference/tag) component that removes the tag
|
|
21
|
+
* when clicked with a mouse.
|
|
22
|
+
* @see https://ariakit.org/components/tag
|
|
23
|
+
* @example
|
|
24
|
+
* ```jsx {9}
|
|
25
|
+
* <TagProvider>
|
|
26
|
+
* <TagListLabel>Invitees</TagListLabel>
|
|
27
|
+
* <TagList>
|
|
28
|
+
* <TagValues>
|
|
29
|
+
* {(values) =>
|
|
30
|
+
* values.map((value) => (
|
|
31
|
+
* <Tag key={value} value={value}>
|
|
32
|
+
* {value}
|
|
33
|
+
* <TagRemove />
|
|
34
|
+
* </Tag>
|
|
35
|
+
* ))
|
|
36
|
+
* }
|
|
37
|
+
* </TagValues>
|
|
38
|
+
* <TagInput />
|
|
39
|
+
* </TagList>
|
|
40
|
+
* </TagProvider>
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare const TagRemove: (props: TagRemoveProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
44
|
+
export interface TagRemoveOptions<_T extends ElementType = TagName> extends Options {
|
|
45
|
+
/**
|
|
46
|
+
* Object returned by the
|
|
47
|
+
* [`useTagStore`](https://ariakit.org/reference/use-tag-store) hook. If not
|
|
48
|
+
* provided, the closest
|
|
49
|
+
* [`TagProvider`](https://ariakit.org/reference/tag-provider) component's
|
|
50
|
+
* context will be used.
|
|
51
|
+
*/
|
|
52
|
+
store?: TagStore;
|
|
53
|
+
/**
|
|
54
|
+
* The value of the tag to remove. If not provided, the value will be inferred
|
|
55
|
+
* from the parent [`Tag`](https://ariakit.org/reference/tag) component.
|
|
56
|
+
*/
|
|
57
|
+
value?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Determines if the tag should be removed when clicked with a mouse. If a
|
|
60
|
+
* function is provided, it will be called with the click event and should
|
|
61
|
+
* return a boolean.
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
removeOnClick?: BooleanOrCallback<MouseEvent<HTMLType>>;
|
|
65
|
+
}
|
|
66
|
+
export type TagRemoveProps<T extends ElementType = TagName> = Props<T, TagRemoveOptions<T>>;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _YWAHOWYEcjs = require('../__chunks/YWAHOWYE.cjs');
|
|
6
|
+
require('../__chunks/4H5ZMMOI.cjs');
|
|
7
|
+
require('../__chunks/Q7DU7FP7.cjs');
|
|
8
|
+
require('../__chunks/GXMZA6DT.cjs');
|
|
9
|
+
require('../__chunks/TW3SFX4C.cjs');
|
|
10
|
+
require('../__chunks/CJDHQUBR.cjs');
|
|
11
|
+
require('../__chunks/AV6KTKLE.cjs');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
exports.useTagStore = _YWAHOWYEcjs.useTagStore; exports.useTagStoreProps = _YWAHOWYEcjs.useTagStoreProps;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as Core from "@ariakit/core/tag/tag-store";
|
|
2
|
+
import type { CompositeStoreFunctions, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
|
|
3
|
+
import type { Store } from "../utils/store.js";
|
|
4
|
+
export declare function useTagStoreProps<T extends Core.TagStore>(store: T, update: () => void, props: TagStoreProps): T;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a tag store to control the state of
|
|
7
|
+
* [Tag](https://ariakit.org/components/tag) components.
|
|
8
|
+
* @see https://ariakit.org/components/tag
|
|
9
|
+
* @example
|
|
10
|
+
* ```jsx
|
|
11
|
+
* const tag = useTagStore({ defaultValues: ["Apple", "Banana"]});
|
|
12
|
+
* const values = tag.useState("values");
|
|
13
|
+
*
|
|
14
|
+
* <TagList store={tag}>
|
|
15
|
+
* {values.map((value) => (
|
|
16
|
+
* <Tag key={value} value={value}>
|
|
17
|
+
* {value}
|
|
18
|
+
* <TagRemove />
|
|
19
|
+
* </Tag>
|
|
20
|
+
* ))}
|
|
21
|
+
* <TagInput />
|
|
22
|
+
* </TagList>
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function useTagStore(props?: TagStoreProps): TagStore;
|
|
26
|
+
export interface TagStoreItem extends Core.TagStoreItem {
|
|
27
|
+
}
|
|
28
|
+
export interface TagStoreState extends Core.TagStoreState, CompositeStoreState<TagStoreItem> {
|
|
29
|
+
}
|
|
30
|
+
export interface TagStoreFunctions extends Core.TagStoreFunctions, CompositeStoreFunctions<TagStoreItem> {
|
|
31
|
+
}
|
|
32
|
+
export interface TagStoreOptions extends Core.TagStoreOptions, CompositeStoreOptions<TagStoreItem> {
|
|
33
|
+
/**
|
|
34
|
+
* A callback that gets called when the
|
|
35
|
+
* [`value`](https://ariakit.org/reference/tag-provider#value) state
|
|
36
|
+
* changes.
|
|
37
|
+
*/
|
|
38
|
+
setValue?: (value: TagStoreState["value"]) => void;
|
|
39
|
+
/**
|
|
40
|
+
* A callback that gets called when the
|
|
41
|
+
* [`values`](https://ariakit.org/reference/tag-provider#values) state
|
|
42
|
+
* changes.
|
|
43
|
+
*/
|
|
44
|
+
setValues?: (values: TagStoreState["values"]) => void;
|
|
45
|
+
}
|
|
46
|
+
export interface TagStoreProps extends TagStoreOptions, Core.TagStoreProps {
|
|
47
|
+
}
|
|
48
|
+
export interface TagStore extends TagStoreFunctions, Store<Core.TagStore> {
|
|
49
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as Core from "@ariakit/core/tag/tag-store";
|
|
2
|
+
import type { CompositeStoreFunctions, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
|
|
3
|
+
import type { Store } from "../utils/store.js";
|
|
4
|
+
export declare function useTagStoreProps<T extends Core.TagStore>(store: T, update: () => void, props: TagStoreProps): T;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a tag store to control the state of
|
|
7
|
+
* [Tag](https://ariakit.org/components/tag) components.
|
|
8
|
+
* @see https://ariakit.org/components/tag
|
|
9
|
+
* @example
|
|
10
|
+
* ```jsx
|
|
11
|
+
* const tag = useTagStore({ defaultValues: ["Apple", "Banana"]});
|
|
12
|
+
* const values = tag.useState("values");
|
|
13
|
+
*
|
|
14
|
+
* <TagList store={tag}>
|
|
15
|
+
* {values.map((value) => (
|
|
16
|
+
* <Tag key={value} value={value}>
|
|
17
|
+
* {value}
|
|
18
|
+
* <TagRemove />
|
|
19
|
+
* </Tag>
|
|
20
|
+
* ))}
|
|
21
|
+
* <TagInput />
|
|
22
|
+
* </TagList>
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function useTagStore(props?: TagStoreProps): TagStore;
|
|
26
|
+
export interface TagStoreItem extends Core.TagStoreItem {
|
|
27
|
+
}
|
|
28
|
+
export interface TagStoreState extends Core.TagStoreState, CompositeStoreState<TagStoreItem> {
|
|
29
|
+
}
|
|
30
|
+
export interface TagStoreFunctions extends Core.TagStoreFunctions, CompositeStoreFunctions<TagStoreItem> {
|
|
31
|
+
}
|
|
32
|
+
export interface TagStoreOptions extends Core.TagStoreOptions, CompositeStoreOptions<TagStoreItem> {
|
|
33
|
+
/**
|
|
34
|
+
* A callback that gets called when the
|
|
35
|
+
* [`value`](https://ariakit.org/reference/tag-provider#value) state
|
|
36
|
+
* changes.
|
|
37
|
+
*/
|
|
38
|
+
setValue?: (value: TagStoreState["value"]) => void;
|
|
39
|
+
/**
|
|
40
|
+
* A callback that gets called when the
|
|
41
|
+
* [`values`](https://ariakit.org/reference/tag-provider#values) state
|
|
42
|
+
* changes.
|
|
43
|
+
*/
|
|
44
|
+
setValues?: (values: TagStoreState["values"]) => void;
|
|
45
|
+
}
|
|
46
|
+
export interface TagStoreProps extends TagStoreOptions, Core.TagStoreProps {
|
|
47
|
+
}
|
|
48
|
+
export interface TagStore extends TagStoreFunctions, Store<Core.TagStore> {
|
|
49
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _PVLZGFP6cjs = require('../__chunks/PVLZGFP6.cjs');
|
|
5
|
+
require('../__chunks/VPI3EKVY.cjs');
|
|
6
|
+
require('../__chunks/NEK2UEJN.cjs');
|
|
7
|
+
require('../__chunks/NGD3IQDB.cjs');
|
|
8
|
+
require('../__chunks/TW3SFX4C.cjs');
|
|
9
|
+
require('../__chunks/CJDHQUBR.cjs');
|
|
10
|
+
require('../__chunks/AV6KTKLE.cjs');
|
|
11
|
+
|
|
12
|
+
// src/tag/tag-value.tsx
|
|
13
|
+
var _misc = require('@ariakit/core/utils/misc');
|
|
14
|
+
function TagValue({ store, children } = {}) {
|
|
15
|
+
const context = _PVLZGFP6cjs.useTagContext.call(void 0, );
|
|
16
|
+
store = store || context;
|
|
17
|
+
_misc.invariant.call(void 0,
|
|
18
|
+
store,
|
|
19
|
+
process.env.NODE_ENV !== "production" && "TagValue must receive a `store` prop or be wrapped in a TagProvider component."
|
|
20
|
+
);
|
|
21
|
+
const value = store.useState("value");
|
|
22
|
+
if (children) {
|
|
23
|
+
return children(value);
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
exports.TagValue = TagValue;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { TagStore, TagStoreState } from "./tag-store.js";
|
|
3
|
+
/**
|
|
4
|
+
* Renders the current
|
|
5
|
+
* [`value`](https://ariakit.org/reference/use-tag-store#value) state in
|
|
6
|
+
* the [tag store](https://ariakit.org/reference/use-tag-store).
|
|
7
|
+
*
|
|
8
|
+
* As a value component, it doesn't render any DOM elements and therefore
|
|
9
|
+
* doesn't accept HTML props.
|
|
10
|
+
*
|
|
11
|
+
* It takes a
|
|
12
|
+
* [`children`](https://ariakit.org/reference/tag-value#children) function
|
|
13
|
+
* that gets called with the current value as an argument. This can be used as
|
|
14
|
+
* an uncontrolled API to render the tag value in a custom way.
|
|
15
|
+
* @see https://ariakit.org/components/tag
|
|
16
|
+
* @example
|
|
17
|
+
* ```jsx {3-5}
|
|
18
|
+
* <TagProvider>
|
|
19
|
+
* <TagInput />
|
|
20
|
+
* <TagValue>
|
|
21
|
+
* {(value) => `Current value: ${value}`}
|
|
22
|
+
* </TagValue>
|
|
23
|
+
* </TagProvider>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function TagValue({ store, children }?: TagValueProps): ReactNode;
|
|
27
|
+
export interface TagValueProps {
|
|
28
|
+
/**
|
|
29
|
+
* Object returned by the
|
|
30
|
+
* [`useTagStore`](https://ariakit.org/reference/use-tag-store)
|
|
31
|
+
* hook. If not provided, the closest
|
|
32
|
+
* [`TagProvider`](https://ariakit.org/reference/tag-provider)
|
|
33
|
+
* component's context will be used.
|
|
34
|
+
*/
|
|
35
|
+
store?: TagStore;
|
|
36
|
+
/**
|
|
37
|
+
* A function that gets called with the current value as an argument. It can
|
|
38
|
+
* be used to render the tag value in a custom way.
|
|
39
|
+
*/
|
|
40
|
+
children?: (value: TagStoreState["value"]) => ReactNode;
|
|
41
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { TagStore, TagStoreState } from "./tag-store.js";
|
|
3
|
+
/**
|
|
4
|
+
* Renders the current
|
|
5
|
+
* [`value`](https://ariakit.org/reference/use-tag-store#value) state in
|
|
6
|
+
* the [tag store](https://ariakit.org/reference/use-tag-store).
|
|
7
|
+
*
|
|
8
|
+
* As a value component, it doesn't render any DOM elements and therefore
|
|
9
|
+
* doesn't accept HTML props.
|
|
10
|
+
*
|
|
11
|
+
* It takes a
|
|
12
|
+
* [`children`](https://ariakit.org/reference/tag-value#children) function
|
|
13
|
+
* that gets called with the current value as an argument. This can be used as
|
|
14
|
+
* an uncontrolled API to render the tag value in a custom way.
|
|
15
|
+
* @see https://ariakit.org/components/tag
|
|
16
|
+
* @example
|
|
17
|
+
* ```jsx {3-5}
|
|
18
|
+
* <TagProvider>
|
|
19
|
+
* <TagInput />
|
|
20
|
+
* <TagValue>
|
|
21
|
+
* {(value) => `Current value: ${value}`}
|
|
22
|
+
* </TagValue>
|
|
23
|
+
* </TagProvider>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function TagValue({ store, children }?: TagValueProps): ReactNode;
|
|
27
|
+
export interface TagValueProps {
|
|
28
|
+
/**
|
|
29
|
+
* Object returned by the
|
|
30
|
+
* [`useTagStore`](https://ariakit.org/reference/use-tag-store)
|
|
31
|
+
* hook. If not provided, the closest
|
|
32
|
+
* [`TagProvider`](https://ariakit.org/reference/tag-provider)
|
|
33
|
+
* component's context will be used.
|
|
34
|
+
*/
|
|
35
|
+
store?: TagStore;
|
|
36
|
+
/**
|
|
37
|
+
* A function that gets called with the current value as an argument. It can
|
|
38
|
+
* be used to render the tag value in a custom way.
|
|
39
|
+
*/
|
|
40
|
+
children?: (value: TagStoreState["value"]) => ReactNode;
|
|
41
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _PVLZGFP6cjs = require('../__chunks/PVLZGFP6.cjs');
|
|
5
|
+
require('../__chunks/VPI3EKVY.cjs');
|
|
6
|
+
require('../__chunks/NEK2UEJN.cjs');
|
|
7
|
+
require('../__chunks/NGD3IQDB.cjs');
|
|
8
|
+
require('../__chunks/TW3SFX4C.cjs');
|
|
9
|
+
require('../__chunks/CJDHQUBR.cjs');
|
|
10
|
+
require('../__chunks/AV6KTKLE.cjs');
|
|
11
|
+
|
|
12
|
+
// src/tag/tag-values.tsx
|
|
13
|
+
var _misc = require('@ariakit/core/utils/misc');
|
|
14
|
+
function TagValues({ store, children } = {}) {
|
|
15
|
+
const context = _PVLZGFP6cjs.useTagContext.call(void 0, );
|
|
16
|
+
store = store || context;
|
|
17
|
+
_misc.invariant.call(void 0,
|
|
18
|
+
store,
|
|
19
|
+
process.env.NODE_ENV !== "production" && "TagValues must receive a `store` prop or be wrapped in a TagProvider component."
|
|
20
|
+
);
|
|
21
|
+
const values = store.useState("values");
|
|
22
|
+
if (children) {
|
|
23
|
+
return children(values);
|
|
24
|
+
}
|
|
25
|
+
return values;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
exports.TagValues = TagValues;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { TagStore, TagStoreState } from "./tag-store.js";
|
|
3
|
+
/**
|
|
4
|
+
* Renders the current
|
|
5
|
+
* [`values`](https://ariakit.org/reference/use-tag-store#values) state in the
|
|
6
|
+
* [tag store](https://ariakit.org/reference/use-tag-store).
|
|
7
|
+
*
|
|
8
|
+
* As a value component, it doesn't render any DOM elements and therefore
|
|
9
|
+
* doesn't accept HTML props.
|
|
10
|
+
*
|
|
11
|
+
* It takes a [`children`](https://ariakit.org/reference/tag-values#children)
|
|
12
|
+
* function that gets called with the current values as an argument. This can be
|
|
13
|
+
* used as an uncontrolled API to render
|
|
14
|
+
* [`Tag`](https://ariakit.org/reference/tag) components.
|
|
15
|
+
* @see https://ariakit.org/components/tag
|
|
16
|
+
* @example
|
|
17
|
+
* ```jsx {4-13}
|
|
18
|
+
* <TagProvider>
|
|
19
|
+
* <TagListLabel>Invitees</TagListLabel>
|
|
20
|
+
* <TagList>
|
|
21
|
+
* <TagValues>
|
|
22
|
+
* {(values) =>
|
|
23
|
+
* values.map((value) => (
|
|
24
|
+
* <Tag key={value} value={value}>
|
|
25
|
+
* {value}
|
|
26
|
+
* <TagRemove />
|
|
27
|
+
* </Tag>
|
|
28
|
+
* ))
|
|
29
|
+
* }
|
|
30
|
+
* </TagValues>
|
|
31
|
+
* <TagInput />
|
|
32
|
+
* </TagList>
|
|
33
|
+
* </TagProvider>
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function TagValues({ store, children }?: TagValuesProps): ReactNode;
|
|
37
|
+
export interface TagValuesProps {
|
|
38
|
+
/**
|
|
39
|
+
* Object returned by the
|
|
40
|
+
* [`useTagStore`](https://ariakit.org/reference/use-tag-store) hook. If not
|
|
41
|
+
* provided, the closest
|
|
42
|
+
* [`TagProvider`](https://ariakit.org/reference/tag-provider) component's
|
|
43
|
+
* context will be used.
|
|
44
|
+
*/
|
|
45
|
+
store?: TagStore;
|
|
46
|
+
/**
|
|
47
|
+
* A function that gets called with the current values as an argument. This
|
|
48
|
+
* can be used as an uncontrolled API to render
|
|
49
|
+
* [`Tag`](https://ariakit.org/reference/tag) components.
|
|
50
|
+
*/
|
|
51
|
+
children?: (values: TagStoreState["values"]) => ReactNode;
|
|
52
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { TagStore, TagStoreState } from "./tag-store.js";
|
|
3
|
+
/**
|
|
4
|
+
* Renders the current
|
|
5
|
+
* [`values`](https://ariakit.org/reference/use-tag-store#values) state in the
|
|
6
|
+
* [tag store](https://ariakit.org/reference/use-tag-store).
|
|
7
|
+
*
|
|
8
|
+
* As a value component, it doesn't render any DOM elements and therefore
|
|
9
|
+
* doesn't accept HTML props.
|
|
10
|
+
*
|
|
11
|
+
* It takes a [`children`](https://ariakit.org/reference/tag-values#children)
|
|
12
|
+
* function that gets called with the current values as an argument. This can be
|
|
13
|
+
* used as an uncontrolled API to render
|
|
14
|
+
* [`Tag`](https://ariakit.org/reference/tag) components.
|
|
15
|
+
* @see https://ariakit.org/components/tag
|
|
16
|
+
* @example
|
|
17
|
+
* ```jsx {4-13}
|
|
18
|
+
* <TagProvider>
|
|
19
|
+
* <TagListLabel>Invitees</TagListLabel>
|
|
20
|
+
* <TagList>
|
|
21
|
+
* <TagValues>
|
|
22
|
+
* {(values) =>
|
|
23
|
+
* values.map((value) => (
|
|
24
|
+
* <Tag key={value} value={value}>
|
|
25
|
+
* {value}
|
|
26
|
+
* <TagRemove />
|
|
27
|
+
* </Tag>
|
|
28
|
+
* ))
|
|
29
|
+
* }
|
|
30
|
+
* </TagValues>
|
|
31
|
+
* <TagInput />
|
|
32
|
+
* </TagList>
|
|
33
|
+
* </TagProvider>
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function TagValues({ store, children }?: TagValuesProps): ReactNode;
|
|
37
|
+
export interface TagValuesProps {
|
|
38
|
+
/**
|
|
39
|
+
* Object returned by the
|
|
40
|
+
* [`useTagStore`](https://ariakit.org/reference/use-tag-store) hook. If not
|
|
41
|
+
* provided, the closest
|
|
42
|
+
* [`TagProvider`](https://ariakit.org/reference/tag-provider) component's
|
|
43
|
+
* context will be used.
|
|
44
|
+
*/
|
|
45
|
+
store?: TagStore;
|
|
46
|
+
/**
|
|
47
|
+
* A function that gets called with the current values as an argument. This
|
|
48
|
+
* can be used as an uncontrolled API to render
|
|
49
|
+
* [`Tag`](https://ariakit.org/reference/tag) components.
|
|
50
|
+
*/
|
|
51
|
+
children?: (values: TagStoreState["values"]) => ReactNode;
|
|
52
|
+
}
|
package/cjs/tag/tag.cjs
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _3HMQOCLFcjs = require('../__chunks/3HMQOCLF.cjs');
|
|
5
|
+
require('../__chunks/HD5AHCRI.cjs');
|
|
6
|
+
require('../__chunks/U4NXCMZ3.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _ISJGSS4Scjs = require('../__chunks/ISJGSS4S.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _PVLZGFP6cjs = require('../__chunks/PVLZGFP6.cjs');
|
|
15
|
+
require('../__chunks/6ZZYUFPW.cjs');
|
|
16
|
+
require('../__chunks/VPI3EKVY.cjs');
|
|
17
|
+
require('../__chunks/NEK2UEJN.cjs');
|
|
18
|
+
require('../__chunks/FHRIPOYF.cjs');
|
|
19
|
+
require('../__chunks/75KXQZJX.cjs');
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
var _NGD3IQDBcjs = require('../__chunks/NGD3IQDB.cjs');
|
|
26
|
+
require('../__chunks/GXMZA6DT.cjs');
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
var _TW3SFX4Ccjs = require('../__chunks/TW3SFX4C.cjs');
|
|
33
|
+
require('../__chunks/CJDHQUBR.cjs');
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
var _AV6KTKLEcjs = require('../__chunks/AV6KTKLE.cjs');
|
|
39
|
+
|
|
40
|
+
// src/tag/tag.tsx
|
|
41
|
+
var _react = require('react');
|
|
42
|
+
var _misc = require('@ariakit/core/utils/misc');
|
|
43
|
+
var _platform = require('@ariakit/core/utils/platform');
|
|
44
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
45
|
+
var TagName = "div";
|
|
46
|
+
var useTag = _NGD3IQDBcjs.createHook.call(void 0, function useTag2(_a) {
|
|
47
|
+
var _b = _a, {
|
|
48
|
+
store,
|
|
49
|
+
value,
|
|
50
|
+
getItem: getItemProp,
|
|
51
|
+
removeOnKeyPress = true
|
|
52
|
+
} = _b, props = _AV6KTKLEcjs.__objRest.call(void 0, _b, [
|
|
53
|
+
"store",
|
|
54
|
+
"value",
|
|
55
|
+
"getItem",
|
|
56
|
+
"removeOnKeyPress"
|
|
57
|
+
]);
|
|
58
|
+
const context = _PVLZGFP6cjs.useTagContext.call(void 0, );
|
|
59
|
+
store = store || context;
|
|
60
|
+
_misc.invariant.call(void 0,
|
|
61
|
+
store,
|
|
62
|
+
process.env.NODE_ENV !== "production" && "Tag must be wrapped in a TagList component."
|
|
63
|
+
);
|
|
64
|
+
const id = _TW3SFX4Ccjs.useId.call(void 0, props.id);
|
|
65
|
+
const touchDevice = _ISJGSS4Scjs.useTouchDevice.call(void 0, );
|
|
66
|
+
const getItem = _react.useCallback.call(void 0,
|
|
67
|
+
(item) => {
|
|
68
|
+
const nextItem = _AV6KTKLEcjs.__spreadProps.call(void 0, _AV6KTKLEcjs.__spreadValues.call(void 0, {}, item), { value });
|
|
69
|
+
if (getItemProp) {
|
|
70
|
+
return getItemProp(nextItem);
|
|
71
|
+
}
|
|
72
|
+
return nextItem;
|
|
73
|
+
},
|
|
74
|
+
[value, getItemProp]
|
|
75
|
+
);
|
|
76
|
+
const onKeyDownProp = props.onKeyDown;
|
|
77
|
+
const removeOnKeyPressProp = _TW3SFX4Ccjs.useBooleanEvent.call(void 0, removeOnKeyPress);
|
|
78
|
+
const onKeyDown = _TW3SFX4Ccjs.useEvent.call(void 0, (event) => {
|
|
79
|
+
onKeyDownProp == null ? void 0 : onKeyDownProp(event);
|
|
80
|
+
if (event.defaultPrevented)
|
|
81
|
+
return;
|
|
82
|
+
const { inputElement } = store.getState();
|
|
83
|
+
const isBackspace = event.key === "Backspace";
|
|
84
|
+
const isRemoveKey = isBackspace || event.key === "Delete";
|
|
85
|
+
if (isRemoveKey && removeOnKeyPressProp(event)) {
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
store.removeValue(value);
|
|
88
|
+
const nextId = isBackspace ? store.previous() || store.next() : store.next();
|
|
89
|
+
store.move(nextId);
|
|
90
|
+
}
|
|
91
|
+
const isPrintableKey = !event.ctrlKey && !event.metaKey && event.key.length === 1;
|
|
92
|
+
const pc = !_platform.isApple.call(void 0, );
|
|
93
|
+
const v = event.key === "v" || event.key === "V";
|
|
94
|
+
const mod = pc ? event.ctrlKey : event.metaKey;
|
|
95
|
+
const isPaste = mod && v;
|
|
96
|
+
if (isPrintableKey || isPaste) {
|
|
97
|
+
inputElement == null ? void 0 : inputElement.focus();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const [removeId, setRemoveId] = _react.useState.call(void 0, );
|
|
101
|
+
props = _TW3SFX4Ccjs.useWrapElement.call(void 0,
|
|
102
|
+
props,
|
|
103
|
+
(element) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _PVLZGFP6cjs.TagValueContext.Provider, { value, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _PVLZGFP6cjs.TagRemoveIdContext.Provider, { value: setRemoveId, children: element }) }),
|
|
104
|
+
[value]
|
|
105
|
+
);
|
|
106
|
+
props = _AV6KTKLEcjs.__spreadProps.call(void 0, _AV6KTKLEcjs.__spreadValues.call(void 0, {
|
|
107
|
+
id,
|
|
108
|
+
role: !touchDevice ? "option" : "listitem",
|
|
109
|
+
children: value,
|
|
110
|
+
"aria-describedby": removeId
|
|
111
|
+
}, props), {
|
|
112
|
+
onKeyDown
|
|
113
|
+
});
|
|
114
|
+
props = _3HMQOCLFcjs.useCompositeItem.call(void 0, _AV6KTKLEcjs.__spreadProps.call(void 0, _AV6KTKLEcjs.__spreadValues.call(void 0, {
|
|
115
|
+
store
|
|
116
|
+
}, props), {
|
|
117
|
+
getItem
|
|
118
|
+
}));
|
|
119
|
+
return props;
|
|
120
|
+
});
|
|
121
|
+
var Tag = _NGD3IQDBcjs.memo.call(void 0,
|
|
122
|
+
_NGD3IQDBcjs.forwardRef.call(void 0, function Tag2(props) {
|
|
123
|
+
const htmlProps = useTag(props);
|
|
124
|
+
return _NGD3IQDBcjs.createElement.call(void 0, TagName, htmlProps);
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
exports.Tag = Tag; exports.useTag = useTag;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ElementType, KeyboardEvent } from "react";
|
|
2
|
+
import type { BooleanOrCallback } from "@ariakit/core/utils/types";
|
|
3
|
+
import type { CompositeItemOptions } from "../composite/composite-item.js";
|
|
4
|
+
import type { Props } from "../utils/types.js";
|
|
5
|
+
import type { TagStore } from "./tag-store.js";
|
|
6
|
+
declare const TagName = "div";
|
|
7
|
+
type TagName = typeof TagName;
|
|
8
|
+
type HTMLType = HTMLElementTagNameMap[TagName];
|
|
9
|
+
/**
|
|
10
|
+
* Returns props to create a `Tag` component.
|
|
11
|
+
* @see https://ariakit.org/components/tag
|
|
12
|
+
* @example
|
|
13
|
+
* ```jsx
|
|
14
|
+
* const props = useTag();
|
|
15
|
+
* <Role.div {...props} />
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const useTag: import("../utils/types.js").Hook<"div", TagOptions<"div">>;
|
|
19
|
+
/**
|
|
20
|
+
* Renders a tag element inside a
|
|
21
|
+
* [`TagList`](https://ariakit.org/reference/tag-list) wrapper.
|
|
22
|
+
*
|
|
23
|
+
* The user can remove the tag by pressing `Backspace` or `Delete` keys when the
|
|
24
|
+
* tag is focused. The
|
|
25
|
+
* [`removeOnKeyPress`](https://ariakit.org/reference/tag#removeonkeypress) prop
|
|
26
|
+
* can be used to disable this behavior.
|
|
27
|
+
*
|
|
28
|
+
* When a printable key is pressed, the focus is automatically moved to the
|
|
29
|
+
* input element.
|
|
30
|
+
* @see https://ariakit.org/components/tag
|
|
31
|
+
* @example
|
|
32
|
+
* ```jsx {7-10}
|
|
33
|
+
* <TagProvider>
|
|
34
|
+
* <TagListLabel>Invitees</TagListLabel>
|
|
35
|
+
* <TagList>
|
|
36
|
+
* <TagValues>
|
|
37
|
+
* {(values) =>
|
|
38
|
+
* values.map((value) => (
|
|
39
|
+
* <Tag key={value} value={value}>
|
|
40
|
+
* {value}
|
|
41
|
+
* <TagRemove />
|
|
42
|
+
* </Tag>
|
|
43
|
+
* ))
|
|
44
|
+
* }
|
|
45
|
+
* </TagValues>
|
|
46
|
+
* <TagInput />
|
|
47
|
+
* </TagList>
|
|
48
|
+
* </TagProvider>
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare const Tag: (props: TagProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
52
|
+
export interface TagOptions<T extends ElementType = TagName> extends CompositeItemOptions<T> {
|
|
53
|
+
/**
|
|
54
|
+
* Object returned by the
|
|
55
|
+
* [`useTagStore`](https://ariakit.org/reference/use-tag-store) hook. If not
|
|
56
|
+
* provided, the closest [`TagList`](https://ariakit.org/reference/tag-list)
|
|
57
|
+
* component's context will be used.
|
|
58
|
+
*/
|
|
59
|
+
store?: TagStore;
|
|
60
|
+
/**
|
|
61
|
+
* The unique value of the tag. This is automatically rendered as the tag's
|
|
62
|
+
* content if no children are provided.
|
|
63
|
+
*/
|
|
64
|
+
value: string;
|
|
65
|
+
/**
|
|
66
|
+
* Defines the behavior of the `Backspace` and `Delete` keys when the tag is
|
|
67
|
+
* focused. If `true`, the tag is removed. If it's a function, it's invoked
|
|
68
|
+
* with the key event and should return a boolean.
|
|
69
|
+
* @default true
|
|
70
|
+
*/
|
|
71
|
+
removeOnKeyPress?: BooleanOrCallback<KeyboardEvent<HTMLType>>;
|
|
72
|
+
}
|
|
73
|
+
export type TagProps<T extends ElementType = TagName> = Props<T, TagOptions<T>>;
|
|
74
|
+
export {};
|