@namroodinc/liquid-editorial 0.6.4 → 0.6.6
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/README.md +81 -1
- package/UPGRADING.md +160 -0
- package/dist/chunks/{Avatar-BTKqaJLP.cjs → Avatar-B_2lI7fS.cjs} +2 -2
- package/dist/chunks/{Avatar-BTKqaJLP.cjs.map → Avatar-B_2lI7fS.cjs.map} +1 -1
- package/dist/chunks/{Avatar-C1q2AUD-.js → Avatar-DdFEOumt.js} +3 -3
- package/dist/chunks/{Avatar-C1q2AUD-.js.map → Avatar-DdFEOumt.js.map} +1 -1
- package/dist/chunks/{Board-z688-51u.js → Board-B8wK079I.js} +2 -2
- package/dist/chunks/{Board-z688-51u.js.map → Board-B8wK079I.js.map} +1 -1
- package/dist/chunks/{Board-CUt4j2-8.cjs → Board-CMf5Azt0.cjs} +2 -2
- package/dist/chunks/{Board-CUt4j2-8.cjs.map → Board-CMf5Azt0.cjs.map} +1 -1
- package/dist/chunks/{ColourField-BwDb7ydB.js → ColourField-DC6cLb9h.js} +7 -3
- package/dist/chunks/ColourField-DC6cLb9h.js.map +1 -0
- package/dist/chunks/ColourField-NnFxLEsh.cjs +2 -0
- package/dist/chunks/ColourField-NnFxLEsh.cjs.map +1 -0
- package/dist/chunks/DatePicker-01sor8iD.cjs +2 -0
- package/dist/chunks/DatePicker-01sor8iD.cjs.map +1 -0
- package/dist/chunks/{DatePicker-C1zcScC3.js → DatePicker-DJAqXUDJ.js} +2 -2
- package/dist/chunks/DatePicker-DJAqXUDJ.js.map +1 -0
- package/dist/chunks/EntryPicker-CR8Phuzl.js +180 -0
- package/dist/chunks/EntryPicker-CR8Phuzl.js.map +1 -0
- package/dist/chunks/EntryPicker-D7JIgx23.cjs +2 -0
- package/dist/chunks/EntryPicker-D7JIgx23.cjs.map +1 -0
- package/dist/chunks/{FormEditor-C4PJu7ZF.js → FormEditor-BSfxVqLn.js} +192 -146
- package/dist/chunks/FormEditor-BSfxVqLn.js.map +1 -0
- package/dist/chunks/FormEditor-DNcSAnRF.cjs +2 -0
- package/dist/chunks/FormEditor-DNcSAnRF.cjs.map +1 -0
- package/dist/chunks/Message-CaX8Y1Xb.js +74 -0
- package/dist/chunks/Message-CaX8Y1Xb.js.map +1 -0
- package/dist/chunks/Message-DU31JAb3.cjs +2 -0
- package/dist/chunks/Message-DU31JAb3.cjs.map +1 -0
- package/dist/chunks/{RichTextEditor-DEJ-u-ZR.js → RichTextEditor-CNkwWist.js} +2 -2
- package/dist/chunks/{RichTextEditor-DEJ-u-ZR.js.map → RichTextEditor-CNkwWist.js.map} +1 -1
- package/dist/chunks/{RichTextEditor-Ddk7qaqg.cjs → RichTextEditor-DAnjElUO.cjs} +2 -2
- package/dist/chunks/{RichTextEditor-Ddk7qaqg.cjs.map → RichTextEditor-DAnjElUO.cjs.map} +1 -1
- package/dist/chunks/context-BONPXF-V.cjs.map +1 -1
- package/dist/chunks/context-CXvOl4Kt.js.map +1 -1
- package/dist/chunks/frame-BBVQTBcX.cjs +2 -0
- package/dist/chunks/frame-BBVQTBcX.cjs.map +1 -0
- package/dist/chunks/frame-De6IuTQz.js +189 -0
- package/dist/chunks/frame-De6IuTQz.js.map +1 -0
- package/dist/chunks/group-Bj9ZKc0R.cjs +2 -0
- package/dist/chunks/group-Bj9ZKc0R.cjs.map +1 -0
- package/dist/chunks/group-Ckz4Xya-.js +34 -0
- package/dist/chunks/group-Ckz4Xya-.js.map +1 -0
- package/dist/chunks/limit-BX6-o1a2.cjs +2 -0
- package/dist/chunks/limit-BX6-o1a2.cjs.map +1 -0
- package/dist/chunks/limit-ChteDN4T.js +18 -0
- package/dist/chunks/limit-ChteDN4T.js.map +1 -0
- package/dist/chunks/mergeRefs-C6_5pADN.js +19 -0
- package/dist/chunks/mergeRefs-C6_5pADN.js.map +1 -0
- package/dist/chunks/mergeRefs-CZ-SArlE.cjs +2 -0
- package/dist/chunks/mergeRefs-CZ-SArlE.cjs.map +1 -0
- package/dist/chunks/useLimit-BOmHKdJE.js +73 -0
- package/dist/chunks/useLimit-BOmHKdJE.js.map +1 -0
- package/dist/chunks/useLimit-DXe_VmYl.cjs +2 -0
- package/dist/chunks/useLimit-DXe_VmYl.cjs.map +1 -0
- package/dist/chunks/{useTooltip-D6cJji8v.js → useTooltip-C5gvEoYk.js} +2 -1
- package/dist/chunks/{useTooltip-D6cJji8v.js.map → useTooltip-C5gvEoYk.js.map} +1 -1
- package/dist/chunks/{useTooltip-CCf79zE9.cjs → useTooltip-bTE_a2Xn.cjs} +2 -2
- package/dist/chunks/{useTooltip-CCf79zE9.cjs.map → useTooltip-bTE_a2Xn.cjs.map} +1 -1
- package/dist/components/AppShell/index.cjs +1 -1
- package/dist/components/AppShell/index.js +1 -1
- package/dist/components/Avatar/index.cjs +1 -1
- package/dist/components/Avatar/index.js +1 -1
- package/dist/components/Banner/index.cjs +2 -0
- package/dist/components/Banner/index.cjs.map +1 -0
- package/dist/components/Banner/index.d.cts +6 -0
- package/dist/components/Banner/index.d.cts.map +1 -0
- package/dist/components/Banner/index.d.ts +6 -0
- package/dist/components/Banner/index.d.ts.map +1 -0
- package/dist/components/Banner/index.js +18 -0
- package/dist/components/Banner/index.js.map +1 -0
- package/dist/components/Banner/style.css +6 -0
- package/dist/components/Board/index.cjs +1 -1
- package/dist/components/Board/index.js +1 -1
- package/dist/components/Choice/index.cjs +1 -1
- package/dist/components/Choice/index.js +1 -1
- package/dist/components/ColourField/index.cjs +1 -1
- package/dist/components/ColourField/index.js +1 -1
- package/dist/components/DatePicker/index.cjs +1 -1
- package/dist/components/DatePicker/index.js +1 -1
- package/dist/components/Drawer/index.cjs +1 -1
- package/dist/components/Drawer/index.cjs.map +1 -1
- package/dist/components/Drawer/index.js +6 -2
- package/dist/components/Drawer/index.js.map +1 -1
- package/dist/components/EditLayout/index.cjs +1 -1
- package/dist/components/EditLayout/index.js +1 -1
- package/dist/components/EntryPicker/index.cjs +1 -2
- package/dist/components/EntryPicker/index.d.cts.map +1 -1
- package/dist/components/EntryPicker/index.d.ts.map +1 -1
- package/dist/components/EntryPicker/index.js +1 -171
- package/dist/components/EntryPicker/limit.d.cts +8 -0
- package/dist/components/EntryPicker/limit.d.cts.map +1 -0
- package/dist/components/EntryPicker/limit.d.ts +8 -0
- package/dist/components/EntryPicker/limit.d.ts.map +1 -0
- package/dist/components/Field/context.d.cts +6 -0
- package/dist/components/Field/context.d.cts.map +1 -1
- package/dist/components/Field/context.d.ts +6 -0
- package/dist/components/Field/context.d.ts.map +1 -1
- package/dist/components/Field/frame.d.cts +1 -1
- package/dist/components/Field/frame.d.cts.map +1 -1
- package/dist/components/Field/frame.d.ts +1 -1
- package/dist/components/Field/frame.d.ts.map +1 -1
- package/dist/components/Field/group.d.cts +1 -1
- package/dist/components/Field/group.d.cts.map +1 -1
- package/dist/components/Field/group.d.ts +1 -1
- package/dist/components/Field/group.d.ts.map +1 -1
- package/dist/components/Field/header.d.cts +12 -0
- package/dist/components/Field/header.d.cts.map +1 -0
- package/dist/components/Field/header.d.ts +12 -0
- package/dist/components/Field/header.d.ts.map +1 -0
- package/dist/components/Field/index.cjs +1 -1
- package/dist/components/Field/index.cjs.map +1 -1
- package/dist/components/Field/index.d.cts +1 -1
- package/dist/components/Field/index.d.cts.map +1 -1
- package/dist/components/Field/index.d.ts +1 -1
- package/dist/components/Field/index.d.ts.map +1 -1
- package/dist/components/Field/index.js +1 -1
- package/dist/components/Field/index.js.map +1 -1
- package/dist/components/Field/limit-reading.d.cts +12 -0
- package/dist/components/Field/limit-reading.d.cts.map +1 -0
- package/dist/components/Field/limit-reading.d.ts +12 -0
- package/dist/components/Field/limit-reading.d.ts.map +1 -0
- package/dist/components/Field/limit.d.cts +8 -0
- package/dist/components/Field/limit.d.cts.map +1 -0
- package/dist/components/Field/limit.d.ts +8 -0
- package/dist/components/Field/limit.d.ts.map +1 -0
- package/dist/components/Field/style.css +77 -0
- package/dist/components/Field/types.d.cts +12 -1
- package/dist/components/Field/types.d.cts.map +1 -1
- package/dist/components/Field/types.d.ts +12 -1
- package/dist/components/Field/types.d.ts.map +1 -1
- package/dist/components/Field/useLimit.d.cts +18 -0
- package/dist/components/Field/useLimit.d.cts.map +1 -0
- package/dist/components/Field/useLimit.d.ts +18 -0
- package/dist/components/Field/useLimit.d.ts.map +1 -0
- package/dist/components/FormEditor/README.md +62 -0
- package/dist/components/FormEditor/control.d.cts.map +1 -1
- package/dist/components/FormEditor/control.d.ts.map +1 -1
- package/dist/components/FormEditor/index.cjs +1 -1
- package/dist/components/FormEditor/index.d.cts.map +1 -1
- package/dist/components/FormEditor/index.d.ts.map +1 -1
- package/dist/components/FormEditor/index.js +1 -1
- package/dist/components/FormEditor/model.d.cts +21 -8
- package/dist/components/FormEditor/model.d.cts.map +1 -1
- package/dist/components/FormEditor/model.d.ts +21 -8
- package/dist/components/FormEditor/model.d.ts.map +1 -1
- package/dist/components/Menu/index.cjs +1 -1
- package/dist/components/Menu/index.cjs.map +1 -1
- package/dist/components/Menu/index.js +1 -1
- package/dist/components/Menu/index.js.map +1 -1
- package/dist/components/Modal/index.cjs +1 -1
- package/dist/components/Modal/index.cjs.map +1 -1
- package/dist/components/Modal/index.js +6 -2
- package/dist/components/Modal/index.js.map +1 -1
- package/dist/components/Popover/index.cjs +1 -1
- package/dist/components/Popover/index.js +1 -1
- package/dist/components/Popover/style.css +2 -1
- package/dist/components/Popover/useTooltip.d.cts.map +1 -1
- package/dist/components/Popover/useTooltip.d.ts.map +1 -1
- package/dist/components/RichTextEditor/index.cjs +1 -1
- package/dist/components/RichTextEditor/index.js +1 -1
- package/dist/components/SearchField/index.cjs +1 -1
- package/dist/components/SearchField/index.cjs.map +1 -1
- package/dist/components/SearchField/index.d.cts.map +1 -1
- package/dist/components/SearchField/index.d.ts.map +1 -1
- package/dist/components/SearchField/index.js +27 -22
- package/dist/components/SearchField/index.js.map +1 -1
- package/dist/components/Select/index.cjs +1 -1
- package/dist/components/Select/index.cjs.map +1 -1
- package/dist/components/Select/index.js +1 -1
- package/dist/components/Select/index.js.map +1 -1
- package/dist/components/SelectionCard/index.cjs +1 -1
- package/dist/components/SelectionCard/index.js +1 -1
- package/dist/components/SortableList/index.cjs +1 -1
- package/dist/components/SortableList/index.js +1 -1
- package/dist/components/Table/index.cjs +1 -1
- package/dist/components/Table/index.cjs.map +1 -1
- package/dist/components/Table/index.js +1 -1
- package/dist/components/Table/index.js.map +1 -1
- package/dist/components/TagsInput/index.cjs +1 -1
- package/dist/components/TagsInput/index.cjs.map +1 -1
- package/dist/components/TagsInput/index.d.cts.map +1 -1
- package/dist/components/TagsInput/index.d.ts.map +1 -1
- package/dist/components/TagsInput/index.js +36 -30
- package/dist/components/TagsInput/index.js.map +1 -1
- package/dist/components/TextField/index.cjs +1 -1
- package/dist/components/TextField/index.cjs.map +1 -1
- package/dist/components/TextField/index.d.cts.map +1 -1
- package/dist/components/TextField/index.d.ts.map +1 -1
- package/dist/components/TextField/index.js +35 -20
- package/dist/components/TextField/index.js.map +1 -1
- package/dist/components/Time/index.cjs +1 -1
- package/dist/components/Time/index.js +2 -2
- package/dist/components/Toast/index.cjs +1 -1
- package/dist/components/Toast/index.cjs.map +1 -1
- package/dist/components/Toast/index.d.cts.map +1 -1
- package/dist/components/Toast/index.d.ts.map +1 -1
- package/dist/components/Toast/index.js +35 -60
- package/dist/components/Toast/index.js.map +1 -1
- package/dist/components/Toast/style.css +5 -50
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -16
- package/dist/internal/Message.d.cts +23 -0
- package/dist/internal/Message.d.cts.map +1 -0
- package/dist/internal/Message.d.ts +23 -0
- package/dist/internal/Message.d.ts.map +1 -0
- package/dist/internal/mergeRefs.d.cts +5 -1
- package/dist/internal/mergeRefs.d.cts.map +1 -1
- package/dist/internal/mergeRefs.d.ts +5 -1
- package/dist/internal/mergeRefs.d.ts.map +1 -1
- package/dist/message.css +122 -0
- package/dist/styles.css +2 -0
- package/dist/tokens.css +36 -12
- package/package.json +1 -1
- package/dist/chunks/ColourField-Bk5O632x.cjs +0 -2
- package/dist/chunks/ColourField-Bk5O632x.cjs.map +0 -1
- package/dist/chunks/ColourField-BwDb7ydB.js.map +0 -1
- package/dist/chunks/DatePicker-BVsloqVY.cjs +0 -2
- package/dist/chunks/DatePicker-BVsloqVY.cjs.map +0 -1
- package/dist/chunks/DatePicker-C1zcScC3.js.map +0 -1
- package/dist/chunks/FormEditor-C4PJu7ZF.js.map +0 -1
- package/dist/chunks/FormEditor-Dd44EMp_.cjs +0 -2
- package/dist/chunks/FormEditor-Dd44EMp_.cjs.map +0 -1
- package/dist/chunks/frame-Bs_jaQRw.js +0 -70
- package/dist/chunks/frame-Bs_jaQRw.js.map +0 -1
- package/dist/chunks/frame-CNxvbg0D.cjs +0 -2
- package/dist/chunks/frame-CNxvbg0D.cjs.map +0 -1
- package/dist/chunks/group-CzbacuAY.js +0 -29
- package/dist/chunks/group-CzbacuAY.js.map +0 -1
- package/dist/chunks/group-pKDQtq-9.cjs +0 -2
- package/dist/chunks/group-pKDQtq-9.cjs.map +0 -1
- package/dist/chunks/mergeRefs-Bc3qS0Tt.cjs +0 -2
- package/dist/chunks/mergeRefs-Bc3qS0Tt.cjs.map +0 -1
- package/dist/chunks/mergeRefs-DGM402mE.js +0 -10
- package/dist/chunks/mergeRefs-DGM402mE.js.map +0 -1
- package/dist/components/EntryPicker/index.cjs.map +0 -1
- package/dist/components/EntryPicker/index.js.map +0 -1
|
@@ -1,48 +1,53 @@
|
|
|
1
1
|
import { t as e } from "../../chunks/Icon-spaFBU4S.js";
|
|
2
2
|
import { Button as t } from "../Button/index.js";
|
|
3
|
+
import { t as n } from "../../chunks/mergeRefs-C6_5pADN.js";
|
|
3
4
|
/* empty css */
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { n as r } from "../../chunks/useLimit-BOmHKdJE.js";
|
|
6
|
+
import { FieldAffix as i } from "../FieldAffix/index.js";
|
|
7
|
+
import { forwardRef as a, useMemo as o, useRef as s } from "react";
|
|
8
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
7
9
|
//#region src/components/SearchField/index.tsx
|
|
8
|
-
var
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
var l = a(function({ size: a = "md", isDisabled: l = !1, onClear: u, className: d, placeholder: f = "Search", value: p, disabled: m, onKeyDown: h, ...g }, _) {
|
|
11
|
+
let v = s(null), y = o(() => n(v, _), [_]);
|
|
12
|
+
r(v, {
|
|
13
|
+
...g,
|
|
14
|
+
value: p
|
|
15
|
+
});
|
|
16
|
+
let b = p !== void 0 && String(p).length > 0;
|
|
17
|
+
return /* @__PURE__ */ c(i, {
|
|
18
|
+
className: d,
|
|
19
|
+
lead: /* @__PURE__ */ c(e, {
|
|
13
20
|
name: "search",
|
|
14
21
|
size: 16
|
|
15
22
|
}),
|
|
16
23
|
isTrailInteractive: !0,
|
|
17
|
-
trail:
|
|
24
|
+
trail: b && u ? /* @__PURE__ */ c(t, {
|
|
18
25
|
variant: "simple",
|
|
19
26
|
size: "xs",
|
|
20
27
|
isIconOnly: !0,
|
|
21
28
|
iconStart: "x",
|
|
22
29
|
"aria-label": "Clear search",
|
|
23
|
-
isDisabled:
|
|
30
|
+
isDisabled: l || m,
|
|
24
31
|
onClick: () => {
|
|
25
|
-
|
|
32
|
+
u(), v.current?.focus();
|
|
26
33
|
}
|
|
27
34
|
}) : void 0,
|
|
28
|
-
children: /* @__PURE__ */
|
|
29
|
-
ref:
|
|
30
|
-
h.current = e, typeof m == "function" ? m(e) : m && (m.current = e);
|
|
31
|
-
},
|
|
35
|
+
children: /* @__PURE__ */ c("input", {
|
|
36
|
+
ref: y,
|
|
32
37
|
type: "search",
|
|
33
|
-
value:
|
|
34
|
-
placeholder:
|
|
35
|
-
disabled:
|
|
36
|
-
"data-size":
|
|
38
|
+
value: p,
|
|
39
|
+
placeholder: f,
|
|
40
|
+
disabled: l || m,
|
|
41
|
+
"data-size": a,
|
|
37
42
|
className: "ds-field-skin ds-search__input",
|
|
38
43
|
onKeyDown: (e) => {
|
|
39
|
-
e.key === "Escape" &&
|
|
44
|
+
e.key === "Escape" && u && u(), h?.(e);
|
|
40
45
|
},
|
|
41
|
-
...
|
|
46
|
+
...g
|
|
42
47
|
})
|
|
43
48
|
});
|
|
44
49
|
});
|
|
45
50
|
//#endregion
|
|
46
|
-
export {
|
|
51
|
+
export { l as SearchField };
|
|
47
52
|
|
|
48
53
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Icon","SearchField","forwardRef","rest","
|
|
1
|
+
{"version":3,"file":"index.js","names":["Icon","mergeRefs","useTextLimit","SearchField","forwardRef","rest","inputRef","useRef","mergedRef","useMemo","ref","hasValue","value","FieldAffix","onClear","Button","isDisabled","disabled","size","event","onKeyDown"],"sources":["../../../src/components/SearchField/index.tsx"],"sourcesContent":["import { forwardRef, useMemo, useRef, type InputHTMLAttributes } from \"react\";\nimport { Icon } from \"../Icon\";\nimport { Button } from \"../Button\";\nimport { FieldAffix } from \"../FieldAffix\";\nimport type { FieldSize } from \"../Field\";\nimport { useTextLimit } from \"../Field/useLimit\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nexport interface SearchFieldProps extends Omit<\n InputHTMLAttributes<HTMLInputElement>,\n \"size\" | \"type\"\n> {\n size?: FieldSize;\n isDisabled?: boolean;\n /** Fired by the clear button and by Escape. */\n onClear?: () => void;\n}\n\n/** A filter over a collection. Carries the glyph, and clears without a Save. */\nexport const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(function SearchField(\n {\n size = \"md\",\n isDisabled = false,\n onClear,\n className,\n placeholder = \"Search\",\n value,\n disabled,\n onKeyDown,\n ...rest\n },\n ref,\n) {\n const inputRef = useRef<HTMLInputElement | null>(null);\n const mergedRef = useMemo(() => mergeRefs(inputRef, ref), [ref]);\n useTextLimit(inputRef, { ...rest, value });\n const hasValue = value !== undefined ? String(value).length > 0 : false;\n\n return (\n <FieldAffix\n className={className}\n lead={\n <Icon\n name=\"search\"\n size={16}\n />\n }\n isTrailInteractive\n trail={\n hasValue && onClear ? (\n <Button\n variant=\"simple\"\n size=\"xs\"\n isIconOnly\n iconStart=\"x\"\n aria-label=\"Clear search\"\n isDisabled={isDisabled || disabled}\n onClick={() => {\n onClear();\n inputRef.current?.focus();\n }}\n />\n ) : undefined\n }\n >\n <input\n ref={mergedRef}\n type=\"search\"\n value={value}\n placeholder={placeholder}\n disabled={isDisabled || disabled}\n data-size={size}\n className=\"ds-field-skin ds-search__input\"\n onKeyDown={(event) => {\n if (event.key === \"Escape\" && onClear) {\n onClear();\n }\n onKeyDown?.(event);\n }}\n {...rest}\n />\n </FieldAffix>\n );\n});\n"],"mappings":";;;;;;;;;AAqBA,IAAaG,IAAcC,EAA+C,SACxE,EACE,UAAO,MACP,gBAAa,IACb,YACA,cACA,iBAAc,UACd,UACA,aACA,cACA,GAAGC,KAEL,GACA;CACA,IAAMC,IAAWC,EAAgC,IAAI,GAC/CC,IAAYC,QAAcR,EAAUK,GAAUI,CAAG,GAAG,CAACA,CAAG,CAAC;CAC/D,EAAaJ,GAAU;EAAE,GAAGD;EAAM;CAAM,CAAC;CACzC,IAAMM,IAAWC,MAAU,KAAA,KAAY,OAAOA,CAAK,CAAC,CAAC,SAAS;CAE9D,OACE,kBAACC,GAAD;EACa;EACX,MACE,kBAACb,GAAD;GACE,MAAK;GACL,MAAM;EACP,CAAA;EAEH,oBAAA;EACA,OACEW,KAAYG,IACV,kBAACC,GAAD;GACE,SAAQ;GACR,MAAK;GACL,YAAA;GACA,WAAU;GACV,cAAW;GACX,YAAYC,KAAcC;GAC1B,eAAe;IAEb,AADAH,EAAQ,GACRR,EAAS,SAAS,MAAM;GAC1B;EACD,CAAA,IACC,KAAA;EAGN,UAAA,kBAAC,SAAD;GACE,KAAKE;GACL,MAAK;GACE;GACM;GACb,UAAUQ,KAAcC;GACxB,aAAWC;GACX,WAAU;GACV,YAAY,MAAU;IAIpB,AAHIC,EAAM,QAAQ,YAAYL,KAC5BA,EAAQ,GAEVM,IAAYD,CAAK;GACnB;GACA,GAAId;EACL,CAAA;CACS,CAAA;AAEhB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-WOhlu6Rp.cjs"),t=require("../Button/index.cjs");;/* empty css */const n=require("../Popover/index.cjs");let r=require("react"),i=require("react/jsx-runtime");function a(...e){return e.filter(Boolean).join(` `)}var o=(0,r.forwardRef)(function({options:o,value:s,defaultValue:c,onValueChange:l,placeholder:u=`Select an option`,size:d=`md`,isDisabled:f=!1,isInvalid:p=!1,"aria-invalid":m,required:h,menuPlacement:g=`bottom`,className:_,disabled:v,onClick:y,onKeyDown:b,...x},S){let[C,w]=(0,r.useState)(c??``),T=s??C,[E,D]=(0,r.useState)(!1),[O,k]=(0,r.useState)(0),A=(0,r.useRef)(null),j=(0,r.useRef)(null),M=(0,r.useRef)(null),N=(0,r.useId)(),P=f||v,F=E&&!P,I=o.find(e=>e.value===T),L=o.filter(e=>!e.isDisabled),R=(0,r.useCallback)(e=>{s===void 0&&w(e),l?.(e),D(!1)},[l,s]);(0,r.useEffect)(()=>{if(!F)return;let e=o.findIndex(e=>e.value===T&&!e.isDisabled);k(e<0?o.indexOf(L[0]):e);let t=e=>{let t=e.target;!A.current?.contains(t)&&!M.current?.contains(t)&&D(!1)};return document.addEventListener(`mousedown`,t),()=>document.removeEventListener(`mousedown`,t)},[F]),(0,r.useEffect)(()=>{F&&(M.current?.querySelectorAll(`[role='option']`)[O])?.scrollIntoView({block:`nearest`})},[O,F]);let z=e=>{let t=o.map((e,t)=>({option:e,index:t})).filter(e=>!e.option.isDisabled);if(t.length===0)return;let n=t[(t.findIndex(e=>e.index===O)+e+t.length)%t.length];k(n.index)},B=e=>{switch(e.key){case`Escape`:e.preventDefault(),D(!1),j.current?.focus();break;case`Tab`:D(!1);break;case`ArrowDown`:case`ArrowUp`:e.preventDefault(),z(e.key===`ArrowDown`?1:-1);break;case`Home`:case`End`:{e.preventDefault();let t=e.key===`Home`?L[0]:L[L.length-1];t&&k(o.indexOf(t));break}case`Enter`:case` `:{e.preventDefault();let t=o[O];t&&!t.isDisabled&&R(t.value);break}}},V=e=>{P||(F?B(e):[`ArrowDown`,`ArrowUp`,`Enter`,` `].includes(e.key)&&(e.preventDefault(),D(!0)))};return(0,i.jsxs)(`div`,{className:`ds-select-root`,ref:A,children:[(0,i.jsxs)(t.Button,{ref:e=>{j.current=e,typeof S==`function`?S(e):S&&(S.current=e)},size:d,role:`combobox`,"aria-required":h||void 0,"aria-haspopup":`listbox`,"aria-expanded":F,"aria-controls":F?N:void 0,"aria-activedescendant":F&&o[O]&&!o[O].isDisabled?`${N}-option-${O}`:void 0,"aria-invalid":p||m||void 0,isDisabled:P,"data-placeholder":I?void 0:``,className:a(`ds-field-skin`,`ds-select`,_),onClick:e=>{y?.(e),e.defaultPrevented||D(e=>!e)},onKeyDown:e=>{b?.(e),e.defaultPrevented||V(e)},...x,children:[(0,i.jsx)(`span`,{className:`ds-select__value`,children:I?I.label:u}),(0,i.jsx)(e.t,{name:`chevron-down`,size:16,className:`ds-select__chevron`})]}),(0,i.jsx)(n.Popover,{anchorRef:j,isOpen:F,align:`start`,placement:g,matchAnchorWidth:!0,panelRef:M,id:N,role:`listbox`,"aria-label":x[`aria-labelledby`]?void 0:x[`aria-label`]??u,"aria-labelledby":x[`aria-labelledby`],className:`ds-surface-raised ds-select__menu`,children:(0,i.jsx)(`div`,{onKeyDown:V,onPointerDown:e=>e.preventDefault(),children:o.map((n,r)=>(0,i.jsxs)(t.Button,{variant:r===O?`active`:`simple`,size:`sm`,isDisabled:n.isDisabled,tabIndex:-1,id:`${N}-option-${r}`,role:`option`,"aria-selected":n.value===T,"aria-disabled":n.isDisabled||void 0,"data-active":r===O||void 0,className:`ds-select__option`,onMouseEnter:()=>!n.isDisabled&&k(r),onClick:()=>{n.isDisabled||(R(n.value),j.current?.focus())},children:[(0,i.jsxs)(`span`,{className:`ds-select__option-body`,children:[(0,i.jsx)(`span`,{className:`ds-select__option-label`,children:n.label}),n.description&&(0,i.jsx)(`span`,{className:`ds-select__option-description`,children:n.description})]}),n.value===T&&(0,i.jsx)(e.t,{name:`check`,size:16})]},n.value))})})]})});exports.Select=o;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-WOhlu6Rp.cjs"),t=require("../Button/index.cjs");;/* empty css */const n=require("../Popover/index.cjs");let r=require("react"),i=require("react/jsx-runtime");function a(...e){return e.filter(Boolean).join(` `)}var o=(0,r.forwardRef)(function({options:o,value:s,defaultValue:c,onValueChange:l,placeholder:u=`Select an option`,size:d=`md`,isDisabled:f=!1,isInvalid:p=!1,"aria-invalid":m,required:h,menuPlacement:g=`bottom`,className:_,disabled:v,onClick:y,onKeyDown:b,...x},S){let[C,w]=(0,r.useState)(c??``),T=s??C,[E,D]=(0,r.useState)(!1),[O,k]=(0,r.useState)(0),A=(0,r.useRef)(null),j=(0,r.useRef)(null),M=(0,r.useRef)(null),N=(0,r.useId)(),P=f||v,F=E&&!P,I=o.find(e=>e.value===T),L=o.filter(e=>!e.isDisabled),R=(0,r.useCallback)(e=>{s===void 0&&w(e),l?.(e),D(!1)},[l,s]);(0,r.useEffect)(()=>{if(!F)return;let e=o.findIndex(e=>e.value===T&&!e.isDisabled);k(e<0?o.indexOf(L[0]):e);let t=e=>{let t=e.target;!A.current?.contains(t)&&!M.current?.contains(t)&&D(!1)};return document.addEventListener(`mousedown`,t),()=>document.removeEventListener(`mousedown`,t)},[F]),(0,r.useEffect)(()=>{F&&(M.current?.querySelectorAll(`[role='option']`)[O])?.scrollIntoView({block:`nearest`})},[O,F]);let z=e=>{let t=o.map((e,t)=>({option:e,index:t})).filter(e=>!e.option.isDisabled);if(t.length===0)return;let n=t[(t.findIndex(e=>e.index===O)+e+t.length)%t.length];k(n.index)},B=e=>{switch(e.key){case`Escape`:e.preventDefault(),D(!1),j.current?.focus();break;case`Tab`:D(!1);break;case`ArrowDown`:case`ArrowUp`:e.preventDefault(),z(e.key===`ArrowDown`?1:-1);break;case`Home`:case`End`:{e.preventDefault();let t=e.key===`Home`?L[0]:L[L.length-1];t&&k(o.indexOf(t));break}case`Enter`:case` `:{e.preventDefault();let t=o[O];t&&!t.isDisabled&&R(t.value);break}}},V=e=>{P||(F?B(e):[`ArrowDown`,`ArrowUp`,`Enter`,` `].includes(e.key)&&(e.preventDefault(),D(!0)))};return(0,i.jsxs)(`div`,{className:`ds-select-root`,ref:A,children:[(0,i.jsxs)(t.Button,{ref:e=>{j.current=e,typeof S==`function`?S(e):S&&(S.current=e)},size:d,role:`combobox`,"aria-required":h||void 0,"aria-haspopup":`listbox`,"aria-expanded":F,"aria-controls":F?N:void 0,"aria-activedescendant":F&&o[O]&&!o[O].isDisabled?`${N}-option-${O}`:void 0,"aria-invalid":p||m||void 0,isDisabled:P,"data-placeholder":I?void 0:``,className:a(`ds-field-skin`,`ds-select`,_),onClick:e=>{y?.(e),e.defaultPrevented||D(e=>!e)},onKeyDown:e=>{b?.(e),e.defaultPrevented||V(e)},...x,children:[(0,i.jsx)(`span`,{className:`ds-select__value`,children:I?I.label:u}),(0,i.jsx)(e.t,{name:`chevron-down`,size:16,className:`ds-select__chevron`})]}),(0,i.jsx)(n.Popover,{anchorRef:j,isOpen:F,align:`start`,placement:g,matchAnchorWidth:!0,panelRef:M,id:N,role:`listbox`,"aria-label":x[`aria-labelledby`]?void 0:x[`aria-label`]??u,"aria-labelledby":x[`aria-labelledby`],className:`ds-surface-raised ds-field-surface ds-select__menu`,children:(0,i.jsx)(`div`,{onKeyDown:V,onPointerDown:e=>e.preventDefault(),children:o.map((n,r)=>(0,i.jsxs)(t.Button,{variant:r===O?`active`:`simple`,size:`sm`,isDisabled:n.isDisabled,tabIndex:-1,id:`${N}-option-${r}`,role:`option`,"aria-selected":n.value===T,"aria-disabled":n.isDisabled||void 0,"data-active":r===O||void 0,className:`ds-select__option`,onMouseEnter:()=>!n.isDisabled&&k(r),onClick:()=>{n.isDisabled||(R(n.value),j.current?.focus())},children:[(0,i.jsxs)(`span`,{className:`ds-select__option-body`,children:[(0,i.jsx)(`span`,{className:`ds-select__option-label`,children:n.label}),n.description&&(0,i.jsx)(`span`,{className:`ds-select__option-description`,children:n.description})]}),n.value===T&&(0,i.jsx)(e.t,{name:`check`,size:16})]},n.value))})})]})});exports.Select=o;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["forwardRef","useState","useRef","useId","useCallback","Button","Icon","Popover","require_Icon","require_components_Button_index","require_components_Popover_index","react","react_jsx_runtime","cx","parts","Select","ariaInvalid","rest","internal","setInternal","defaultValue","current","value","isOpen","setOpen","activeIndex","setActiveIndex","rootRef","triggerRef","listRef","listId","effectiveDisabled","isDisabled","disabled","isVisible","selected","options","option","enabled","commit","next","onValueChange","index","onPointerDown","target","event","step","order","o","delta","handleListKeyDown","pick","handleKeyDown","node","ref","required","isInvalid","className","onClick","open","onKeyDown","placeholder","menuPlacement"],"sources":["../../../src/components/Select/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n type ButtonHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport { Button } from \"../Button\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport type { FieldSize } from \"../Field\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface SelectOption {\n value: string;\n label: string;\n /** Secondary line under the label. */\n description?: string;\n isDisabled?: boolean;\n}\n\nexport interface SelectProps extends Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n \"value\" | \"defaultValue\" | \"onChange\"\n> {\n required?: boolean;\n options: SelectOption[];\n /** Controlled value. Leave undefined to let the select hold its own. */\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n placeholder?: string;\n size?: FieldSize;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Preferred side of the menu; flips when space requires it. */\n menuPlacement?: PopoverPlacement;\n}\n\n/**\n * One value out of a known list. Wears the field skin, opens a listbox: arrows\n * walk the options, Enter commits, Escape closes without changing anything.\n */\nexport const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select(\n {\n options,\n value,\n defaultValue,\n onValueChange,\n placeholder = \"Select an option\",\n size = \"md\",\n isDisabled = false,\n isInvalid = false,\n \"aria-invalid\": ariaInvalid,\n required,\n menuPlacement = \"bottom\",\n className,\n disabled,\n onClick,\n onKeyDown,\n ...rest\n },\n ref,\n) {\n const [internal, setInternal] = useState(defaultValue ?? \"\");\n const current = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [activeIndex, setActiveIndex] = useState(0);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const listId = useId();\n const effectiveDisabled = isDisabled || disabled;\n const isVisible = isOpen && !effectiveDisabled;\n\n const selected = options.find((option) => option.value === current);\n const enabled = options.filter((option) => !option.isDisabled);\n\n const commit = useCallback(\n (next: string) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n },\n [onValueChange, value],\n );\n\n useEffect(() => {\n if (!isVisible) {\n return;\n }\n const index = options.findIndex((option) => option.value === current && !option.isDisabled);\n setActiveIndex(index < 0 ? options.indexOf(enabled[0]!) : index);\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isVisible]);\n\n useEffect(() => {\n if (!isVisible) {\n return;\n }\n const activeOption =\n listRef.current?.querySelectorAll<HTMLElement>(\"[role='option']\")[activeIndex];\n activeOption?.scrollIntoView({ block: \"nearest\" });\n }, [activeIndex, isVisible]);\n\n const step = (delta: number) => {\n const order = options\n .map((option, index) => ({ option, index }))\n .filter((o) => !o.option.isDisabled);\n if (order.length === 0) {\n return;\n }\n const at = order.findIndex((o) => o.index === activeIndex);\n const next = order[(at + delta + order.length) % order.length]!;\n setActiveIndex(next.index);\n };\n\n const handleListKeyDown = (event: React.KeyboardEvent) => {\n switch (event.key) {\n case \"Escape\":\n // Claims Escape so an enclosing Drawer stays open.\n event.preventDefault();\n setOpen(false);\n triggerRef.current?.focus();\n break;\n case \"Tab\":\n setOpen(false);\n break;\n case \"ArrowDown\":\n case \"ArrowUp\":\n event.preventDefault();\n step(event.key === \"ArrowDown\" ? 1 : -1);\n break;\n case \"Home\":\n case \"End\": {\n event.preventDefault();\n const pick = event.key === \"Home\" ? enabled[0] : enabled[enabled.length - 1];\n if (pick) {\n setActiveIndex(options.indexOf(pick));\n }\n break;\n }\n case \"Enter\":\n case \" \": {\n event.preventDefault();\n const option = options[activeIndex];\n if (option && !option.isDisabled) {\n commit(option.value);\n }\n break;\n }\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (effectiveDisabled) {\n return;\n }\n if (isVisible) {\n handleListKeyDown(event);\n } else if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(event.key)) {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n return (\n <div\n className=\"ds-select-root\"\n ref={rootRef}\n >\n <Button\n ref={(node) => {\n triggerRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }}\n size={size}\n role=\"combobox\"\n aria-required={required || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={isVisible}\n aria-controls={isVisible ? listId : undefined}\n aria-activedescendant={\n isVisible && options[activeIndex] && !options[activeIndex].isDisabled\n ? `${listId}-option-${activeIndex}`\n : undefined\n }\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={effectiveDisabled}\n data-placeholder={selected ? undefined : \"\"}\n className={cx(\"ds-field-skin\", \"ds-select\", className)}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) {\n setOpen((open) => !open);\n }\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) {\n handleKeyDown(event);\n }\n }}\n {...rest}\n >\n <span className=\"ds-select__value\">{selected ? selected.label : placeholder}</span>\n <Icon\n name=\"chevron-down\"\n size={16}\n className=\"ds-select__chevron\"\n />\n </Button>\n <Popover\n anchorRef={triggerRef}\n isOpen={isVisible}\n align=\"start\"\n placement={menuPlacement}\n matchAnchorWidth\n panelRef={listRef}\n id={listId}\n role=\"listbox\"\n aria-label={rest[\"aria-labelledby\"] ? undefined : (rest[\"aria-label\"] ?? placeholder)}\n aria-labelledby={rest[\"aria-labelledby\"]}\n className=\"ds-surface-raised ds-select__menu\"\n >\n <div\n onKeyDown={handleKeyDown}\n onPointerDown={(event) => event.preventDefault()}\n >\n {options.map((option, index) => (\n <Button\n key={option.value}\n variant={index === activeIndex ? \"active\" : \"simple\"}\n size=\"sm\"\n isDisabled={option.isDisabled}\n tabIndex={-1}\n id={`${listId}-option-${index}`}\n role=\"option\"\n aria-selected={option.value === current}\n aria-disabled={option.isDisabled || undefined}\n data-active={index === activeIndex || undefined}\n className=\"ds-select__option\"\n onMouseEnter={() => !option.isDisabled && setActiveIndex(index)}\n onClick={() => {\n if (!option.isDisabled) {\n commit(option.value);\n triggerRef.current?.focus();\n }\n }}\n >\n <span className=\"ds-select__option-body\">\n <span className=\"ds-select__option-label\">{option.label}</span>\n {option.description && (\n <span className=\"ds-select__option-description\">{option.description}</span>\n )}\n </span>\n {option.value === current && (\n <Icon\n name=\"check\"\n size={16}\n />\n )}\n </Button>\n ))}\n </div>\n </Popover>\n </div>\n );\n});\n"],"mappings":"A,+RAgBA,SAASa,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAgCA,IAAaC,GAAA,EAASf,EAAAA,WAAAA,CAA2C,SAC/D,CACE,UACA,QACA,eACA,gBACA,cAAc,mBACd,OAAO,KACP,aAAa,GACb,YAAY,GACZ,eAAgBgB,EAChB,WACA,gBAAgB,SAChB,YACA,WACA,UACA,YACA,GAAGC,GAEL,EACA,CACA,GAAM,CAACC,EAAUC,IAAA,EAAelB,EAAAA,SAAAA,CAASmB,GAAgB,EAAE,EACrDC,EAAUC,GAASJ,EACnB,CAACK,EAAQC,IAAA,EAAWvB,EAAAA,SAAAA,CAAS,EAAK,EAClC,CAACwB,EAAaC,IAAA,EAAkBzB,EAAAA,SAAAA,CAAS,CAAC,EAC1C0B,GAAA,EAAUzB,EAAAA,OAAAA,CAA8B,IAAI,EAC5C0B,GAAA,EAAa1B,EAAAA,OAAAA,CAAiC,IAAI,EAClD2B,GAAA,EAAU3B,EAAAA,OAAAA,CAA8B,IAAI,EAC5C4B,GAAA,EAAS3B,EAAAA,MAAAA,CAAM,EACf4B,EAAoBC,GAAcC,EAClCC,EAAYX,GAAU,CAACQ,EAEvBI,EAAWC,EAAQ,KAAM,GAAWC,EAAO,QAAUhB,CAAO,EAC5DiB,EAAUF,EAAQ,OAAQ,GAAW,CAACC,EAAO,UAAU,EAEvDE,GAAA,EAASnC,EAAAA,YAAAA,CACZ,GAAiB,CACZkB,IAAU,IAAA,IACZH,EAAYqB,CAAI,EAElBC,IAAgBD,CAAI,EACpBhB,EAAQ,EAAK,CACf,EACA,CAACiB,EAAenB,CAAK,CACvB,GAEA,EAAAX,EAAA,UAAA,KAAgB,CACd,GAAI,CAACuB,EACH,OAEF,IA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CAACN,EAAAA,EAAD,CACE,KAAK,QACL,KAAM,EACP,CAAA,CAEG,CA/BD,EAAA+B,EAAO,KA+BN,CACT,CACE,CAAA,CACE,CAAA,CACN,C,EAET,CAAC,E"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["forwardRef","useState","useRef","useId","useCallback","Button","Icon","Popover","require_Icon","require_components_Button_index","require_components_Popover_index","react","react_jsx_runtime","cx","parts","Select","ariaInvalid","rest","internal","setInternal","defaultValue","current","value","isOpen","setOpen","activeIndex","setActiveIndex","rootRef","triggerRef","listRef","listId","effectiveDisabled","isDisabled","disabled","isVisible","selected","options","option","enabled","commit","next","onValueChange","index","onPointerDown","target","event","step","order","o","delta","handleListKeyDown","pick","handleKeyDown","node","ref","required","isInvalid","className","onClick","open","onKeyDown","placeholder","menuPlacement"],"sources":["../../../src/components/Select/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n type ButtonHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport { Button } from \"../Button\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport type { FieldSize } from \"../Field\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface SelectOption {\n value: string;\n label: string;\n /** Secondary line under the label. */\n description?: string;\n isDisabled?: boolean;\n}\n\nexport interface SelectProps extends Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n \"value\" | \"defaultValue\" | \"onChange\"\n> {\n required?: boolean;\n options: SelectOption[];\n /** Controlled value. Leave undefined to let the select hold its own. */\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n placeholder?: string;\n size?: FieldSize;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Preferred side of the menu; flips when space requires it. */\n menuPlacement?: PopoverPlacement;\n}\n\n/**\n * One value out of a known list. Wears the field skin, opens a listbox: arrows\n * walk the options, Enter commits, Escape closes without changing anything.\n */\nexport const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select(\n {\n options,\n value,\n defaultValue,\n onValueChange,\n placeholder = \"Select an option\",\n size = \"md\",\n isDisabled = false,\n isInvalid = false,\n \"aria-invalid\": ariaInvalid,\n required,\n menuPlacement = \"bottom\",\n className,\n disabled,\n onClick,\n onKeyDown,\n ...rest\n },\n ref,\n) {\n const [internal, setInternal] = useState(defaultValue ?? \"\");\n const current = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [activeIndex, setActiveIndex] = useState(0);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const listId = useId();\n const effectiveDisabled = isDisabled || disabled;\n const isVisible = isOpen && !effectiveDisabled;\n\n const selected = options.find((option) => option.value === current);\n const enabled = options.filter((option) => !option.isDisabled);\n\n const commit = useCallback(\n (next: string) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n },\n [onValueChange, value],\n );\n\n useEffect(() => {\n if (!isVisible) {\n return;\n }\n const index = options.findIndex((option) => option.value === current && !option.isDisabled);\n setActiveIndex(index < 0 ? options.indexOf(enabled[0]!) : index);\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isVisible]);\n\n useEffect(() => {\n if (!isVisible) {\n return;\n }\n const activeOption =\n listRef.current?.querySelectorAll<HTMLElement>(\"[role='option']\")[activeIndex];\n activeOption?.scrollIntoView({ block: \"nearest\" });\n }, [activeIndex, isVisible]);\n\n const step = (delta: number) => {\n const order = options\n .map((option, index) => ({ option, index }))\n .filter((o) => !o.option.isDisabled);\n if (order.length === 0) {\n return;\n }\n const at = order.findIndex((o) => o.index === activeIndex);\n const next = order[(at + delta + order.length) % order.length]!;\n setActiveIndex(next.index);\n };\n\n const handleListKeyDown = (event: React.KeyboardEvent) => {\n switch (event.key) {\n case \"Escape\":\n // Claims Escape so an enclosing Drawer stays open.\n event.preventDefault();\n setOpen(false);\n triggerRef.current?.focus();\n break;\n case \"Tab\":\n setOpen(false);\n break;\n case \"ArrowDown\":\n case \"ArrowUp\":\n event.preventDefault();\n step(event.key === \"ArrowDown\" ? 1 : -1);\n break;\n case \"Home\":\n case \"End\": {\n event.preventDefault();\n const pick = event.key === \"Home\" ? enabled[0] : enabled[enabled.length - 1];\n if (pick) {\n setActiveIndex(options.indexOf(pick));\n }\n break;\n }\n case \"Enter\":\n case \" \": {\n event.preventDefault();\n const option = options[activeIndex];\n if (option && !option.isDisabled) {\n commit(option.value);\n }\n break;\n }\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (effectiveDisabled) {\n return;\n }\n if (isVisible) {\n handleListKeyDown(event);\n } else if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(event.key)) {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n return (\n <div\n className=\"ds-select-root\"\n ref={rootRef}\n >\n <Button\n ref={(node) => {\n triggerRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }}\n size={size}\n role=\"combobox\"\n aria-required={required || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={isVisible}\n aria-controls={isVisible ? listId : undefined}\n aria-activedescendant={\n isVisible && options[activeIndex] && !options[activeIndex].isDisabled\n ? `${listId}-option-${activeIndex}`\n : undefined\n }\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={effectiveDisabled}\n data-placeholder={selected ? undefined : \"\"}\n className={cx(\"ds-field-skin\", \"ds-select\", className)}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) {\n setOpen((open) => !open);\n }\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) {\n handleKeyDown(event);\n }\n }}\n {...rest}\n >\n <span className=\"ds-select__value\">{selected ? selected.label : placeholder}</span>\n <Icon\n name=\"chevron-down\"\n size={16}\n className=\"ds-select__chevron\"\n />\n </Button>\n <Popover\n anchorRef={triggerRef}\n isOpen={isVisible}\n align=\"start\"\n placement={menuPlacement}\n matchAnchorWidth\n panelRef={listRef}\n id={listId}\n role=\"listbox\"\n aria-label={rest[\"aria-labelledby\"] ? undefined : (rest[\"aria-label\"] ?? placeholder)}\n aria-labelledby={rest[\"aria-labelledby\"]}\n className=\"ds-surface-raised ds-field-surface ds-select__menu\"\n >\n <div\n onKeyDown={handleKeyDown}\n onPointerDown={(event) => event.preventDefault()}\n >\n {options.map((option, index) => (\n <Button\n key={option.value}\n variant={index === activeIndex ? \"active\" : \"simple\"}\n size=\"sm\"\n isDisabled={option.isDisabled}\n tabIndex={-1}\n id={`${listId}-option-${index}`}\n role=\"option\"\n aria-selected={option.value === current}\n aria-disabled={option.isDisabled || undefined}\n data-active={index === activeIndex || undefined}\n className=\"ds-select__option\"\n onMouseEnter={() => !option.isDisabled && setActiveIndex(index)}\n onClick={() => {\n if (!option.isDisabled) {\n commit(option.value);\n triggerRef.current?.focus();\n }\n }}\n >\n <span className=\"ds-select__option-body\">\n <span className=\"ds-select__option-label\">{option.label}</span>\n {option.description && (\n <span className=\"ds-select__option-description\">{option.description}</span>\n )}\n </span>\n {option.value === current && (\n <Icon\n name=\"check\"\n size={16}\n />\n )}\n </Button>\n ))}\n </div>\n </Popover>\n </div>\n );\n});\n"],"mappings":"A,+RAgBA,SAASa,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAgCA,IAAaC,GAAA,EAASf,EAAAA,WAAAA,CAA2C,SAC/D,CACE,UACA,QACA,eACA,gBACA,cAAc,mBACd,OAAO,KACP,aAAa,GACb,YAAY,GAC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zE,kBAAiB5C,EAAK,mBACtB,UAAU,qDAEV,UAAA,EAAAL,EAAA,IAAA,CAAC,MAAD,CACE,UAAWwC,EACX,cAAgB,GAAUP,EAAM,eAAe,EAE9C,SAAAT,EAAQ,KAAK,EAAQ,KACpB,EAAAxB,EAAA,KAAA,CAACP,EAAAA,OAAD,CAEE,QAASqC,IAAUjB,EAAc,SAAW,SAC5C,KAAK,KACL,WAAYY,EAAO,WACnB,SAAU,GACV,GAAI,GAAGP,EAAO,UAAUY,IACxB,KAAK,SACL,gBAAeL,EAAO,QAAUhB,EAChC,gBAAegB,EAAO,YAAc,IAAA,GACpC,cAAaK,IAAUjB,GAAe,IAAA,GACtC,UAAU,oBACV,iBAAoB,CAACY,EAAO,YAAcX,EAAegB,CAAK,EAC9D,YAAe,CACRL,EAAO,aACVE,EAAOF,EAAO,KAAK,EACnBT,EAAW,SAAS,MAAM,EAE9B,EAlBF,SAAA,EAoBE,EAAAhB,EAAA,KAAA,CAAC,OAAD,CAAM,UAAU,yBAAhB,SAAA,EACE,EAAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAU,0BAA2B,SAAAyB,EAAO,KAAY,CAAA,EAC7DA,EAAO,cACN,EAAAzB,EAAA,IAAA,CAAC,OAAD,CAAM,UAAU,gCAAiC,SAAAyB,EAAO,WAAkB,CAAA,CAExE,CACL,CAAA,EAAAA,EAAO,QAAUhB,IAChB,EAAAT,EAAA,IAAA,CAACN,EAAAA,EAAD,CACE,KAAK,QACL,KAAM,EACP,CAAA,CAEG,CA/BD,EAAA+B,EAAO,KA+BN,CACT,CACE,CAAA,CACE,CAAA,CACN,C,EAET,CAAC,E"}
|
|
@@ -111,7 +111,7 @@ var f = r(function({ options: r, value: f, defaultValue: p, onValueChange: m, pl
|
|
|
111
111
|
role: "listbox",
|
|
112
112
|
"aria-label": E["aria-labelledby"] ? void 0 : E["aria-label"] ?? h,
|
|
113
113
|
"aria-labelledby": E["aria-labelledby"],
|
|
114
|
-
className: "ds-surface-raised ds-select__menu",
|
|
114
|
+
className: "ds-surface-raised ds-field-surface ds-select__menu",
|
|
115
115
|
children: /* @__PURE__ */ l("div", {
|
|
116
116
|
onKeyDown: K,
|
|
117
117
|
onPointerDown: (e) => e.preventDefault(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Icon","cx","parts","Select","forwardRef","ariaInvalid","rest","internal","setInternal","useState","defaultValue","current","value","isOpen","setOpen","activeIndex","setActiveIndex","rootRef","useRef","triggerRef","listRef","listId","useId","effectiveDisabled","isDisabled","disabled","isVisible","selected","options","option","enabled","commit","useCallback","next","onValueChange","useEffect","index","onPointerDown","target","event","step","order","o","delta","handleListKeyDown","pick","handleKeyDown","Button","node","ref","required","isInvalid","className","onClick","open","onKeyDown","placeholder","Popover","menuPlacement"],"sources":["../../../src/components/Select/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n type ButtonHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport { Button } from \"../Button\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport type { FieldSize } from \"../Field\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface SelectOption {\n value: string;\n label: string;\n /** Secondary line under the label. */\n description?: string;\n isDisabled?: boolean;\n}\n\nexport interface SelectProps extends Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n \"value\" | \"defaultValue\" | \"onChange\"\n> {\n required?: boolean;\n options: SelectOption[];\n /** Controlled value. Leave undefined to let the select hold its own. */\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n placeholder?: string;\n size?: FieldSize;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Preferred side of the menu; flips when space requires it. */\n menuPlacement?: PopoverPlacement;\n}\n\n/**\n * One value out of a known list. Wears the field skin, opens a listbox: arrows\n * walk the options, Enter commits, Escape closes without changing anything.\n */\nexport const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select(\n {\n options,\n value,\n defaultValue,\n onValueChange,\n placeholder = \"Select an option\",\n size = \"md\",\n isDisabled = false,\n isInvalid = false,\n \"aria-invalid\": ariaInvalid,\n required,\n menuPlacement = \"bottom\",\n className,\n disabled,\n onClick,\n onKeyDown,\n ...rest\n },\n ref,\n) {\n const [internal, setInternal] = useState(defaultValue ?? \"\");\n const current = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [activeIndex, setActiveIndex] = useState(0);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const listId = useId();\n const effectiveDisabled = isDisabled || disabled;\n const isVisible = isOpen && !effectiveDisabled;\n\n const selected = options.find((option) => option.value === current);\n const enabled = options.filter((option) => !option.isDisabled);\n\n const commit = useCallback(\n (next: string) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n },\n [onValueChange, value],\n );\n\n useEffect(() => {\n if (!isVisible) {\n return;\n }\n const index = options.findIndex((option) => option.value === current && !option.isDisabled);\n setActiveIndex(index < 0 ? options.indexOf(enabled[0]!) : index);\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isVisible]);\n\n useEffect(() => {\n if (!isVisible) {\n return;\n }\n const activeOption =\n listRef.current?.querySelectorAll<HTMLElement>(\"[role='option']\")[activeIndex];\n activeOption?.scrollIntoView({ block: \"nearest\" });\n }, [activeIndex, isVisible]);\n\n const step = (delta: number) => {\n const order = options\n .map((option, index) => ({ option, index }))\n .filter((o) => !o.option.isDisabled);\n if (order.length === 0) {\n return;\n }\n const at = order.findIndex((o) => o.index === activeIndex);\n const next = order[(at + delta + order.length) % order.length]!;\n setActiveIndex(next.index);\n };\n\n const handleListKeyDown = (event: React.KeyboardEvent) => {\n switch (event.key) {\n case \"Escape\":\n // Claims Escape so an enclosing Drawer stays open.\n event.preventDefault();\n setOpen(false);\n triggerRef.current?.focus();\n break;\n case \"Tab\":\n setOpen(false);\n break;\n case \"ArrowDown\":\n case \"ArrowUp\":\n event.preventDefault();\n step(event.key === \"ArrowDown\" ? 1 : -1);\n break;\n case \"Home\":\n case \"End\": {\n event.preventDefault();\n const pick = event.key === \"Home\" ? enabled[0] : enabled[enabled.length - 1];\n if (pick) {\n setActiveIndex(options.indexOf(pick));\n }\n break;\n }\n case \"Enter\":\n case \" \": {\n event.preventDefault();\n const option = options[activeIndex];\n if (option && !option.isDisabled) {\n commit(option.value);\n }\n break;\n }\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (effectiveDisabled) {\n return;\n }\n if (isVisible) {\n handleListKeyDown(event);\n } else if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(event.key)) {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n return (\n <div\n className=\"ds-select-root\"\n ref={rootRef}\n >\n <Button\n ref={(node) => {\n triggerRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }}\n size={size}\n role=\"combobox\"\n aria-required={required || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={isVisible}\n aria-controls={isVisible ? listId : undefined}\n aria-activedescendant={\n isVisible && options[activeIndex] && !options[activeIndex].isDisabled\n ? `${listId}-option-${activeIndex}`\n : undefined\n }\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={effectiveDisabled}\n data-placeholder={selected ? undefined : \"\"}\n className={cx(\"ds-field-skin\", \"ds-select\", className)}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) {\n setOpen((open) => !open);\n }\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) {\n handleKeyDown(event);\n }\n }}\n {...rest}\n >\n <span className=\"ds-select__value\">{selected ? selected.label : placeholder}</span>\n <Icon\n name=\"chevron-down\"\n size={16}\n className=\"ds-select__chevron\"\n />\n </Button>\n <Popover\n anchorRef={triggerRef}\n isOpen={isVisible}\n align=\"start\"\n placement={menuPlacement}\n matchAnchorWidth\n panelRef={listRef}\n id={listId}\n role=\"listbox\"\n aria-label={rest[\"aria-labelledby\"] ? undefined : (rest[\"aria-label\"] ?? placeholder)}\n aria-labelledby={rest[\"aria-labelledby\"]}\n className=\"ds-surface-raised ds-select__menu\"\n >\n <div\n onKeyDown={handleKeyDown}\n onPointerDown={(event) => event.preventDefault()}\n >\n {options.map((option, index) => (\n <Button\n key={option.value}\n variant={index === activeIndex ? \"active\" : \"simple\"}\n size=\"sm\"\n isDisabled={option.isDisabled}\n tabIndex={-1}\n id={`${listId}-option-${index}`}\n role=\"option\"\n aria-selected={option.value === current}\n aria-disabled={option.isDisabled || undefined}\n data-active={index === activeIndex || undefined}\n className=\"ds-select__option\"\n onMouseEnter={() => !option.isDisabled && setActiveIndex(index)}\n onClick={() => {\n if (!option.isDisabled) {\n commit(option.value);\n triggerRef.current?.focus();\n }\n }}\n >\n <span className=\"ds-select__option-body\">\n <span className=\"ds-select__option-label\">{option.label}</span>\n {option.description && (\n <span className=\"ds-select__option-description\">{option.description}</span>\n )}\n </span>\n {option.value === current && (\n <Icon\n name=\"check\"\n size={16}\n />\n )}\n </Button>\n ))}\n </div>\n </Popover>\n </div>\n );\n});\n"],"mappings":";;;;;;;AAgBA,SAASC,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAgCA,IAAaC,IAASC,EAA2C,SAC/D,EACE,YACA,UACA,iBACA,kBACA,iBAAc,oBACd,UAAO,MACP,gBAAa,IACb,eAAY,IACZ,gBAAgBC,GAChB,aACA,m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iBAAeP,EAAO,UAAUlB;KAChC,iBAAekB,EAAO,cAAc,KAAA;KACpC,eAAaO,MAAUrB,KAAe,KAAA;KACtC,WAAU;KACV,oBAAoB,CAACc,EAAO,cAAcb,EAAeoB,CAAK;KAC9D,eAAe;MACb,AAAKP,EAAO,eACVE,EAAOF,EAAO,KAAK,GACnBV,EAAW,SAAS,MAAM;KAE9B;KAlBF,UAAA,CAoBE,kBAAC,QAAD;MAAM,WAAU;MAAhB,UAAA,CACE,kBAAC,QAAD;OAAM,WAAU;OAA2B,UAAAU,EAAO;MAAY,CAAA,GAC7DA,EAAO,eACN,kBAAC,QAAD;OAAM,WAAU;OAAiC,UAAAA,EAAO;MAAkB,CAAA,CAExE;KACL,CAAA,GAAAA,EAAO,UAAUlB,KAChB,kBAACX,GAAD;MACE,MAAK;MACL,MAAM;KACP,CAAA,CAEG;IA/BD,GAAA6B,EAAO,KA+BN,CACT;GACE,CAAA;EACE,CAAA,CACN;;AAET,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Icon","cx","parts","Select","forwardRef","ariaInvalid","rest","internal","setInternal","useState","defaultValue","current","value","isOpen","setOpen","activeIndex","setActiveIndex","rootRef","useRef","triggerRef","listRef","listId","useId","effectiveDisabled","isDisabled","disabled","isVisible","selected","options","option","enabled","commit","useCallback","next","onValueChange","useEffect","index","onPointerDown","target","event","step","order","o","delta","handleListKeyDown","pick","handleKeyDown","Button","node","ref","required","isInvalid","className","onClick","open","onKeyDown","placeholder","Popover","menuPlacement"],"sources":["../../../src/components/Select/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n type ButtonHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport { Button } from \"../Button\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport type { FieldSize } from \"../Field\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface SelectOption {\n value: string;\n label: string;\n /** Secondary line under the label. */\n description?: string;\n isDisabled?: boolean;\n}\n\nexport interface SelectProps extends Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n \"value\" | \"defaultValue\" | \"onChange\"\n> {\n required?: boolean;\n options: SelectOption[];\n /** Controlled value. Leave undefined to let the select hold its own. */\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n placeholder?: string;\n size?: FieldSize;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Preferred side of the menu; flips when space requires it. */\n menuPlacement?: PopoverPlacement;\n}\n\n/**\n * One value out of a known list. Wears the field skin, opens a listbox: arrows\n * walk the options, Enter commits, Escape closes without changing anything.\n */\nexport const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select(\n {\n options,\n value,\n defaultValue,\n onValueChange,\n placeholder = \"Select an option\",\n size = \"md\",\n isDisabled = false,\n isInvalid = false,\n \"aria-invalid\": ariaInvalid,\n required,\n menuPlacement = \"bottom\",\n className,\n disabled,\n onClick,\n onKeyDown,\n ...rest\n },\n ref,\n) {\n const [internal, setInternal] = useState(defaultValue ?? \"\");\n const current = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [activeIndex, setActiveIndex] = useState(0);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const listId = useId();\n const effectiveDisabled = isDisabled || disabled;\n const isVisible = isOpen && !effectiveDisabled;\n\n const selected = options.find((option) => option.value === current);\n const enabled = options.filter((option) => !option.isDisabled);\n\n const commit = useCallback(\n (next: string) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n },\n [onValueChange, value],\n );\n\n useEffect(() => {\n if (!isVisible) {\n return;\n }\n const index = options.findIndex((option) => option.value === current && !option.isDisabled);\n setActiveIndex(index < 0 ? options.indexOf(enabled[0]!) : index);\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isVisible]);\n\n useEffect(() => {\n if (!isVisible) {\n return;\n }\n const activeOption =\n listRef.current?.querySelectorAll<HTMLElement>(\"[role='option']\")[activeIndex];\n activeOption?.scrollIntoView({ block: \"nearest\" });\n }, [activeIndex, isVisible]);\n\n const step = (delta: number) => {\n const order = options\n .map((option, index) => ({ option, index }))\n .filter((o) => !o.option.isDisabled);\n if (order.length === 0) {\n return;\n }\n const at = order.findIndex((o) => o.index === activeIndex);\n const next = order[(at + delta + order.length) % order.length]!;\n setActiveIndex(next.index);\n };\n\n const handleListKeyDown = (event: React.KeyboardEvent) => {\n switch (event.key) {\n case \"Escape\":\n // Claims Escape so an enclosing Drawer stays open.\n event.preventDefault();\n setOpen(false);\n triggerRef.current?.focus();\n break;\n case \"Tab\":\n setOpen(false);\n break;\n case \"ArrowDown\":\n case \"ArrowUp\":\n event.preventDefault();\n step(event.key === \"ArrowDown\" ? 1 : -1);\n break;\n case \"Home\":\n case \"End\": {\n event.preventDefault();\n const pick = event.key === \"Home\" ? enabled[0] : enabled[enabled.length - 1];\n if (pick) {\n setActiveIndex(options.indexOf(pick));\n }\n break;\n }\n case \"Enter\":\n case \" \": {\n event.preventDefault();\n const option = options[activeIndex];\n if (option && !option.isDisabled) {\n commit(option.value);\n }\n break;\n }\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (effectiveDisabled) {\n return;\n }\n if (isVisible) {\n handleListKeyDown(event);\n } else if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(event.key)) {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n return (\n <div\n className=\"ds-select-root\"\n ref={rootRef}\n >\n <Button\n ref={(node) => {\n triggerRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }}\n size={size}\n role=\"combobox\"\n aria-required={required || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={isVisible}\n aria-controls={isVisible ? listId : undefined}\n aria-activedescendant={\n isVisible && options[activeIndex] && !options[activeIndex].isDisabled\n ? `${listId}-option-${activeIndex}`\n : undefined\n }\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={effectiveDisabled}\n data-placeholder={selected ? undefined : \"\"}\n className={cx(\"ds-field-skin\", \"ds-select\", className)}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) {\n setOpen((open) => !open);\n }\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) {\n handleKeyDown(event);\n }\n }}\n {...rest}\n >\n <span className=\"ds-select__value\">{selected ? selected.label : placeholder}</span>\n <Icon\n name=\"chevron-down\"\n size={16}\n className=\"ds-select__chevron\"\n />\n </Button>\n <Popover\n anchorRef={triggerRef}\n isOpen={isVisible}\n align=\"start\"\n placement={menuPlacement}\n matchAnchorWidth\n panelRef={listRef}\n id={listId}\n role=\"listbox\"\n aria-label={rest[\"aria-labelledby\"] ? undefined : (rest[\"aria-label\"] ?? placeholder)}\n aria-labelledby={rest[\"aria-labelledby\"]}\n className=\"ds-surface-raised ds-field-surface ds-select__menu\"\n >\n <div\n onKeyDown={handleKeyDown}\n onPointerDown={(event) => event.preventDefault()}\n >\n {options.map((option, index) => (\n <Button\n key={option.value}\n variant={index === activeIndex ? \"active\" : \"simple\"}\n size=\"sm\"\n isDisabled={option.isDisabled}\n tabIndex={-1}\n id={`${listId}-option-${index}`}\n role=\"option\"\n aria-selected={option.value === current}\n aria-disabled={option.isDisabled || undefined}\n data-active={index === activeIndex || undefined}\n className=\"ds-select__option\"\n onMouseEnter={() => !option.isDisabled && setActiveIndex(index)}\n onClick={() => {\n if (!option.isDisabled) {\n commit(option.value);\n triggerRef.current?.focus();\n }\n }}\n >\n <span className=\"ds-select__option-body\">\n <span className=\"ds-select__option-label\">{option.label}</span>\n {option.description && (\n <span className=\"ds-select__option-description\">{option.description}</span>\n )}\n </span>\n {option.value === current && (\n <Icon\n name=\"check\"\n size={16}\n />\n )}\n </Button>\n ))}\n </div>\n </Popover>\n </div>\n );\n});\n"],"mappings":";;;;;;;AAgBA,SAASC,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAgCA,IAAaC,IAASC,EAA2C,SAC/D,EACE,YACA,UACA,iBACA,kBACA,iBAAc,oBACd,UAAO,MACP,gBAAa,IACb,eAAY,IACZ,gBAAgBC,GAChB,aACA,mBAAgB,UAChB,cACA,aACA,YACA,cACA,GAAGC,KAEL,GACA;CACA,IAAM,CAACC,GAAUC,KAAeC,EAASC,KAAgB,EAAE,GACrDC,IAAUC,KAASL,GACnB,CAACM,GAAQC,KAAWL,EAAS,EAAK,GAClC,CAACM,GAAaC,KAAkBP,EAAS,CAAC,GAC1CQ,IAAUC,EAA8B,IAAI,GAC5CC,IAAaD,EAAiC,IAAI,GAClDE,IAAUF,EAA8B,IAAI,GAC5CG,IAASC,EAAM,GACfC,IAAoBC,KAAcC,GAClCC,IAAYb,KAAU,CAACU,GAEvBI,IAAWC,EAAQ,MAAM,MAAWC,EAAO,UAAUlB,CAAO,GAC5DmB,IAAUF,EAAQ,QAAQ,MAAW,CAACC,EAAO,UAAU,GAEvDE,IAASC,GACZ,MAAiB;EAKhB,AAJIpB,MAAU,KAAA,KACZJ,EAAYyB,CAAI,GAElBC,IAAgBD,CAAI,GACpBnB,EAAQ,EAAK;CACf,GACA,CAACoB,GAAetB,CAAK,CACvB;CAmBA,AAjBAuB,QAAgB;EACd,IAAI,CAACT,GACH;EAEF,IAAMU,IAAQR,EAAQ,WAAW,MAAWC,EAAO,UAAUlB,KAAW,CAACkB,EAAO,UAAU;EAC1F,EAAeO,IAAQ,IAAIR,EAAQ,QAA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D;GACE,WAAWtC;GACX,QAAQO;GACR,OAAM;GACN,WAAWgC;GACX,kBAAA;GACA,UAAUtC;GACV,IAAIC;GACJ,MAAK;GACL,cAAYf,EAAK,qBAAqB,KAAA,IAAaA,EAAK,iBAAiBkD;GACzE,mBAAiBlD,EAAK;GACtB,WAAU;GAEV,UAAA,kBAAC,OAAD;IACE,WAAWwC;IACX,gBAAgB,MAAUP,EAAM,eAAe;IAE9C,UAAAX,EAAQ,KAAK,GAAQ,MACpB,kBAACmB,GAAD;KAEE,SAASX,MAAUrB,IAAc,WAAW;KAC5C,MAAK;KACL,YAAYc,EAAO;KACnB,UAAU;KACV,IAAI,GAAGR,EAAO,UAAUe;KACxB,MAAK;KACL,iBAAeP,EAAO,UAAUlB;KAChC,iBAAekB,EAAO,cAAc,KAAA;KACpC,eAAaO,MAAUrB,KAAe,KAAA;KACtC,WAAU;KACV,oBAAoB,CAACc,EAAO,cAAcb,EAAeoB,CAAK;KAC9D,eAAe;MACb,AAAKP,EAAO,eACVE,EAAOF,EAAO,KAAK,GACnBV,EAAW,SAAS,MAAM;KAE9B;KAlBF,UAAA,CAoBE,kBAAC,QAAD;MAAM,WAAU;MAAhB,UAAA,CACE,kBAAC,QAAD;OAAM,WAAU;OAA2B,UAAAU,EAAO;MAAY,CAAA,GAC7DA,EAAO,eACN,kBAAC,QAAD;OAAM,WAAU;OAAiC,UAAAA,EAAO;MAAkB,CAAA,CAExE;KACL,CAAA,GAAAA,EAAO,UAAUlB,KAChB,kBAACX,GAAD;MACE,MAAK;MACL,MAAM;KACP,CAAA,CAEG;IA/BD,GAAA6B,EAAO,KA+BN,CACT;GACE,CAAA;EACE,CAAA,CACN;;AAET,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/group-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/group-Bj9ZKc0R.cjs"),t=require("../Grid/index.cjs");let n=require("react"),r=require("react/jsx-runtime");function i({kind:e,title:t,description:n,children:i,className:a,inputProps:o,inputRef:s}){return(0,r.jsxs)(`label`,{className:[`ds-selection-card`,a].filter(Boolean).join(` `),children:[(0,r.jsx)(`input`,{ref:s,type:e,"data-kind":e,className:`ds-selection-card__control`,...o}),(0,r.jsxs)(`span`,{className:`ds-selection-card__text`,children:[(0,r.jsx)(`span`,{className:`ds-selection-card__title`,children:t}),n&&(0,r.jsx)(`span`,{className:`ds-selection-card__description`,children:n}),i&&(0,r.jsx)(`span`,{className:`ds-selection-card__extra`,children:i})]})]})}var a=(0,n.forwardRef)(function({title:e,description:t,children:n,className:a,...o},s){return(0,r.jsx)(i,{kind:`checkbox`,title:e,description:t,className:a,inputProps:o,inputRef:s,children:n})}),o=(0,n.forwardRef)(function({title:e,description:t,children:n,className:a,...o},s){return(0,r.jsx)(i,{kind:`radio`,title:e,description:t,className:a,inputProps:o,inputRef:s,children:n})});function s({label:n,columns:i=2,gap:a=`md`,children:o,className:s,...c}){return(0,r.jsx)(e.t,{...c,label:n,className:[`ds-selection-card-group`,s].filter(Boolean).join(` `),children:(0,r.jsx)(t.Grid,{columns:i,gap:a,className:`ds-selection-card-group__grid ds-field-group-grid`,style:{"--field-group-columns":i},children:o})})}exports.CheckboxCard=a,exports.RadioCard=o,exports.SelectionCardGroup=s;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-WOhlu6Rp.cjs"),t=require("../Button/index.cjs"),n=require("../../chunks/mergeRefs-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-WOhlu6Rp.cjs"),t=require("../Button/index.cjs"),n=require("../../chunks/mergeRefs-CZ-SArlE.cjs");let r=require("react"),i=require("react/jsx-runtime"),a=require("@dnd-kit/core"),o=require("@dnd-kit/modifiers"),s=require("@dnd-kit/sortable"),c=require("@dnd-kit/utilities");function l(e){return(0,r.isValidElement)(e)&&typeof e.props.id==`string`}var u=(0,r.createContext)({isDisabled:!1,hasOverlay:!1});function d(e){e?.setAttribute(`inert`,``)}function f(){let{active:e,activeNodeRect:t,measureDroppableContainers:n}=(0,a.useDndContext)(),i=e?.id,o=t?.width,s=t?.height,c=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(i==null||o===void 0){c.current=null;return}let e=`${o}x${s}`;c.current!==null&&c.current!==e&&n([]),c.current=e},[i,o,s,n]),null}var p=(0,r.forwardRef)(function({items:t,onReorder:n,isDisabled:c=!1,onDragStart:p,onDragEnd:m,onDragCancel:h,renderDragOverlay:g,className:_,children:v,...y},b){let x=(0,r.useId)(),[S,C]=(0,r.useState)(null),[w,T]=(0,r.useState)(t),[E,D]=(0,r.useState)(t);t!==E&&t.join(`\0`)!==E.join(`\0`)&&(D(t),T(t));let O=(0,a.useSensors)((0,a.useSensor)(a.PointerSensor,{activationConstraint:{distance:4}}),(0,a.useSensor)(a.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),k=(0,r.useCallback)(e=>{let t=String(e.active.id);C(t),p?.(t)},[p]);(0,r.useEffect)(()=>{if(!S)return;let e=e=>{e.code===`Escape`&&e.preventDefault()};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[S]);let A=(0,r.useCallback)(e=>{C(null);let{active:t,over:r}=e;if(m?.(String(t.id)),c||!r||t.id===r.id)return;let i=w.indexOf(String(t.id)),a=w.indexOf(String(r.id));if(i<0||a<0)return;let o=(0,s.arrayMove)(w,i,a);T(o),n?.(o)},[w,n,c,m]),j=r.Children.toArray(v),M=new Map(j.filter(l).map(e=>[e.props.id,e])),N=[...w.flatMap(e=>M.get(e)??[]),...j.filter(e=>!l(e)||!w.includes(e.props.id))],P=g!==void 0,F=(0,r.useMemo)(()=>({isDisabled:c,hasOverlay:P}),[c,P]);return(0,i.jsxs)(a.DndContext,{id:`ds-sortable-list-${x}`,sensors:O,collisionDetection:a.closestCenter,modifiers:[o.restrictToVerticalAxis],onDragStart:k,onDragEnd:A,onDragCancel:e=>{C(null),h?.(String(e.active.id))},children:[(0,i.jsx)(f,{}),(0,i.jsx)(s.SortableContext,{items:w,strategy:s.verticalListSortingStrategy,children:(0,i.jsx)(u.Provider,{value:F,children:(0,i.jsx)(`ul`,{ref:b,className:[`ds-sortable-list`,_].filter(Boolean).join(` `),...y,children:N})})}),g&&(0,i.jsx)(a.DragOverlay,{className:`ds-sortable-overlay`,style:{height:`auto`},children:S?(0,i.jsxs)(`div`,{className:`ds-sortable-item`,"data-overlay":!0,"aria-hidden":`true`,ref:d,children:[(0,i.jsx)(`span`,{className:`ds-sortable-item__handle`,"aria-hidden":`true`,children:(0,i.jsx)(e.t,{name:`grip-vertical`})}),(0,i.jsx)(`div`,{className:`ds-sortable-item__content`,children:g(S)})]}):null})]})}),m=(0,r.forwardRef)(function({id:e,label:a,action:o,isDisabled:l=!1,className:d,children:f,...p},m){let h=(0,r.useContext)(u),g=l||h.isDisabled,{attributes:_,listeners:v,setNodeRef:y,transform:b,transition:x,isDragging:S}=(0,s.useSortable)({id:e,disabled:g});return(0,i.jsxs)(`li`,{ref:n.t(y,m),style:{transform:c.CSS.Translate.toString(b),transition:x},className:[`ds-sortable-item`,d].filter(Boolean).join(` `),"data-dragging":S?h.hasOverlay?`placeholder`:`lifted`:void 0,...p,children:[(0,i.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`grip-vertical`,className:`ds-sortable-item__handle`,"aria-label":a?`Move ${a}`:`Move item`,isDisabled:g,isFocusableWhenDisabled:!0,..._,...v}),(0,i.jsx)(`div`,{className:`ds-sortable-item__content`,children:f}),o&&(0,i.jsx)(`div`,{className:`ds-sortable-item__action`,children:o})]})});exports.SortableList=p,exports.SortableListItem=m;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as e } from "../../chunks/Icon-spaFBU4S.js";
|
|
2
2
|
import { Button as t } from "../Button/index.js";
|
|
3
|
-
import { t as n } from "../../chunks/mergeRefs-
|
|
3
|
+
import { t as n } from "../../chunks/mergeRefs-C6_5pADN.js";
|
|
4
4
|
import { Children as r, createContext as i, forwardRef as a, isValidElement as o, useCallback as s, useContext as c, useEffect as l, useId as u, useMemo as d, useRef as f, useState as p } from "react";
|
|
5
5
|
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
6
6
|
import { DndContext as g, DragOverlay as _, KeyboardSensor as v, PointerSensor as y, closestCenter as b, useDndContext as x, useSensor as S, useSensors as C } from "@dnd-kit/core";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-WOhlu6Rp.cjs");let t=require("react"),n=require("react/jsx-runtime");function r(...e){return e.filter(Boolean).join(` `)}var i=(0,t.forwardRef)(function({className:e,children:t,...i},a){return(0,n.jsx)(`div`,{ref:a,className:r(`ds-table-frame`,e),...i,children:t})}),a=(0,t.forwardRef)(function({start:e,end:t,className:i,...a},o){return(0,n.jsxs)(`div`,{ref:o,className:r(`ds-table-toolbar`,i),...a,children:[(0,n.jsx)(`div`,{className:`ds-table-toolbar__group`,children:e}),(0,n.jsx)(`div`,{className:`ds-table-toolbar__group`,children:t})]})});function o(e){return t.Children.toArray(e).some(e=>(0,t.isValidElement)(e)&&(e.type!==t.Fragment||o(e.props.children)))}var s=(0,t.createContext)({emptyMessage:`No data found.`}),c=(0,t.forwardRef)(function({emptyMessage:e=`No data found.`,isEmpty:t,className:i,children:a,...o},c){return(0,n.jsx)(s.Provider,{value:{emptyMessage:e,isEmpty:t},children:(0,n.jsx)(`div`,{className:`ds-table-frame__scroll`,children:(0,n.jsx)(`table`,{...o,ref:c,className:r(`ds-table`,i),children:a})})})}),l=(0,t.forwardRef)(function({className:e,...t},r){return(0,n.jsx)(`thead`,{ref:r,className:e,...t})}),u=(0,t.forwardRef)(function({className:e,children:r,...i},a){let{emptyMessage:c,isEmpty:l}=(0,t.useContext)(s);return(0,n.jsx)(`tbody`,{ref:a,className:e,...i,children:l??!o(r)?(0,n.jsx)(d,{children:(0,n.jsx)(p,{colSpan:1e3,className:`ds-table__empty-cell`,children:(0,n.jsx)(m,{title:c,role:`status`})})}):r})}),d=(0,t.forwardRef)(function({isSelected:e=!1,isInteractive:t=!1,className:r,...i},a){return(0,n.jsx)(`tr`,{ref:a,"data-selected":e||void 0,"data-interactive":t||void 0,tabIndex:t?0:void 0,className:r,...i})}),f=(0,t.forwardRef)(function({align:e=`start`,width:t=`auto`,className:r,...i},a){return(0,n.jsx)(`th`,{ref:a,scope:`col`,"data-align":e,"data-width":t,className:r,...i})}),p=(0,t.forwardRef)(function({align:e=`start`,width:t=`auto`,emphasis:r=`default`,className:i,...a},o){return(0,n.jsx)(`td`,{ref:o,"data-align":e,"data-width":t,"data-emphasis":r==="default"?void 0:r,className:i,...a})}),m=(0,t.forwardRef)(function({icon:t=`info`,title:i=`No data found.`,description:a,action:o,className:s,...c},l){return(0,n.jsxs)(`div`,{ref:l,className:r(`ds-table-empty`,s),...c,children:[(0,n.jsx)(e.t,{name:t,size:24}),(0,n.jsx)(`span`,{style:{color:`var(--color-text)`,fontWeight:`var(--font-weight-bold)`},children:i}),a&&(0,n.jsx)(`span`,{children:a}),o]})});exports.Table=c,exports.TableBody=u,exports.TableCell=p,exports.TableEmpty=m,exports.TableFrame=i,exports.TableHead=l,exports.TableHeaderCell=f,exports.TableRow=d,exports.TableToolbar=a;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-WOhlu6Rp.cjs");let t=require("react"),n=require("react/jsx-runtime");function r(...e){return e.filter(Boolean).join(` `)}var i=(0,t.forwardRef)(function({className:e,children:t,...i},a){return(0,n.jsx)(`div`,{ref:a,className:r(`ds-table-frame`,`ds-field-surface`,e),...i,children:t})}),a=(0,t.forwardRef)(function({start:e,end:t,className:i,...a},o){return(0,n.jsxs)(`div`,{ref:o,className:r(`ds-table-toolbar`,i),...a,children:[(0,n.jsx)(`div`,{className:`ds-table-toolbar__group`,children:e}),(0,n.jsx)(`div`,{className:`ds-table-toolbar__group`,children:t})]})});function o(e){return t.Children.toArray(e).some(e=>(0,t.isValidElement)(e)&&(e.type!==t.Fragment||o(e.props.children)))}var s=(0,t.createContext)({emptyMessage:`No data found.`}),c=(0,t.forwardRef)(function({emptyMessage:e=`No data found.`,isEmpty:t,className:i,children:a,...o},c){return(0,n.jsx)(s.Provider,{value:{emptyMessage:e,isEmpty:t},children:(0,n.jsx)(`div`,{className:`ds-table-frame__scroll`,children:(0,n.jsx)(`table`,{...o,ref:c,className:r(`ds-table`,i),children:a})})})}),l=(0,t.forwardRef)(function({className:e,...t},r){return(0,n.jsx)(`thead`,{ref:r,className:e,...t})}),u=(0,t.forwardRef)(function({className:e,children:r,...i},a){let{emptyMessage:c,isEmpty:l}=(0,t.useContext)(s);return(0,n.jsx)(`tbody`,{ref:a,className:e,...i,children:l??!o(r)?(0,n.jsx)(d,{children:(0,n.jsx)(p,{colSpan:1e3,className:`ds-table__empty-cell`,children:(0,n.jsx)(m,{title:c,role:`status`})})}):r})}),d=(0,t.forwardRef)(function({isSelected:e=!1,isInteractive:t=!1,className:r,...i},a){return(0,n.jsx)(`tr`,{ref:a,"data-selected":e||void 0,"data-interactive":t||void 0,tabIndex:t?0:void 0,className:r,...i})}),f=(0,t.forwardRef)(function({align:e=`start`,width:t=`auto`,className:r,...i},a){return(0,n.jsx)(`th`,{ref:a,scope:`col`,"data-align":e,"data-width":t,className:r,...i})}),p=(0,t.forwardRef)(function({align:e=`start`,width:t=`auto`,emphasis:r=`default`,className:i,...a},o){return(0,n.jsx)(`td`,{ref:o,"data-align":e,"data-width":t,"data-emphasis":r==="default"?void 0:r,className:i,...a})}),m=(0,t.forwardRef)(function({icon:t=`info`,title:i=`No data found.`,description:a,action:o,className:s,...c},l){return(0,n.jsxs)(`div`,{ref:l,className:r(`ds-table-empty`,s),...c,children:[(0,n.jsx)(e.t,{name:t,size:24}),(0,n.jsx)(`span`,{style:{color:`var(--color-text)`,fontWeight:`var(--font-weight-bold)`},children:i}),a&&(0,n.jsx)(`span`,{children:a}),o]})});exports.Table=c,exports.TableBody=u,exports.TableCell=p,exports.TableEmpty=m,exports.TableFrame=i,exports.TableHead=l,exports.TableHeaderCell=f,exports.TableRow=d,exports.TableToolbar=a;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["forwardRef","Children","isValidElement","Fragment","createContext","useContext","Icon","require_Icon","react","react_jsx_runtime","cx","parts","TableFrame","rest","className","TableToolbar","start","end","hasBodyContent","children","child","TableContext","Table","TableHead","TableBody","isEmpty","TableRow","TableCell","TableEmpty","emptyMessage","isSelected","isInteractive","TableHeaderCell","align","width","emphasis","icon","title","description","action"],"sources":["../../../src/components/Table/index.tsx"],"sourcesContent":["import {\n Children,\n Fragment,\n createContext,\n forwardRef,\n isValidElement,\n useContext,\n type HTMLAttributes,\n type ReactNode,\n type TableHTMLAttributes,\n type TdHTMLAttributes,\n type ThHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport type { IconName } from \"../Icon/icons\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface TableFrameProps extends HTMLAttributes<HTMLDivElement> {\n children?: ReactNode;\n}\n\n/** The 3px collection frame every table, list and board sits inside. */\nexport const TableFrame = forwardRef<HTMLDivElement, TableFrameProps>(function TableFrame(\n { className, children, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-frame\", className)}\n {...rest}\n >\n {children}\n </div>\n );\n});\n\nexport interface TableToolbarProps extends HTMLAttributes<HTMLDivElement> {\n /** Left side — usually a select-all checkbox, a title and a count badge. */\n start?: ReactNode;\n /** Right side — filters and the one primary action. */\n end?: ReactNode;\n}\n\n/** The band above the rules: selection, title, count, filters, primary action. */\nexport const TableToolbar = forwardRef<HTMLDivElement, TableToolbarProps>(function TableToolbar(\n { start, end, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-toolbar\", className)}\n {...rest}\n >\n <div className=\"ds-table-toolbar__group\">{start}</div>\n <div className=\"ds-table-toolbar__group\">{end}</div>\n </div>\n );\n});\n\nexport interface TableProps extends TableHTMLAttributes<HTMLTableElement> {\n /** Message shown when a body has no rows. */\n emptyMessage?: string;\n /** Override empty-child detection when rows are rendered by custom components. */\n isEmpty?: boolean;\n children?: ReactNode;\n}\n\nfunction hasBodyContent(children: ReactNode): boolean {\n return Children.toArray(children).some(\n (child) =>\n isValidElement<{ children?: ReactNode }>(child) &&\n (child.type !== Fragment || hasBodyContent(child.props.children)),\n );\n}\n\nconst TableContext = createContext<{\n emptyMessage: string;\n isEmpty?: boolean;\n}>({ emptyMessage: \"No data found.\" });\n\n/** The rules layer. Always render it inside a `TableFrame`. */\nexport const Table = forwardRef<HTMLTableElement, TableProps>(function Table(\n { emptyMessage = \"No data found.\", isEmpty, className, children, ...rest },\n ref,\n) {\n return (\n <TableContext.Provider value={{ emptyMessage, isEmpty }}>\n <div className=\"ds-table-frame__scroll\">\n <table\n {...rest}\n ref={ref}\n className={cx(\"ds-table\", className)}\n >\n {children}\n </table>\n </div>\n </TableContext.Provider>\n );\n});\n\nexport const TableHead = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableHead({ className, ...rest }, ref) {\n return (\n <thead\n ref={ref}\n className={className}\n {...rest}\n />\n );\n});\n\nexport const TableBody = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableBody({ className, children, ...rest }, ref) {\n const { emptyMessage, isEmpty } = useContext(TableContext);\n return (\n <tbody\n ref={ref}\n className={className}\n {...rest}\n >\n {(isEmpty ?? !hasBodyContent(children)) ? (\n <TableRow>\n {/* HTML's maximum span covers the row without inspecting columns. */}\n <TableCell\n colSpan={1000}\n className=\"ds-table__empty-cell\"\n >\n <TableEmpty\n title={emptyMessage}\n role=\"status\"\n />\n </TableCell>\n </TableRow>\n ) : (\n children\n )}\n </tbody>\n );\n});\n\nexport interface TableRowProps extends HTMLAttributes<HTMLTableRowElement> {\n /** Paints the soft fill and the solid rail. Never changes the row's size. */\n isSelected?: boolean;\n /** Marks the row clickable: hover fill plus a pointer cursor. */\n isInteractive?: boolean;\n}\n\nexport const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(function TableRow(\n { isSelected = false, isInteractive = false, className, ...rest },\n ref,\n) {\n return (\n <tr\n ref={ref}\n data-selected={isSelected || undefined}\n data-interactive={isInteractive || undefined}\n tabIndex={isInteractive ? 0 : undefined}\n className={className}\n {...rest}\n />\n );\n});\n\nexport type TableAlign = \"start\" | \"end\";\nexport type TableCellWidth = \"auto\" | \"control\";\n\nexport interface TableHeaderCellProps extends Omit<\n ThHTMLAttributes<HTMLTableCellElement>,\n \"align\"\n> {\n align?: TableAlign;\n width?: TableCellWidth;\n}\n\nexport const TableHeaderCell = forwardRef<HTMLTableCellElement, TableHeaderCellProps>(\n function TableHeaderCell({ align = \"start\", width = \"auto\", className, ...rest }, ref) {\n return (\n <th\n ref={ref}\n scope=\"col\"\n data-align={align}\n data-width={width}\n className={className}\n {...rest}\n />\n );\n },\n);\n\nexport type TableCellEmphasis = \"default\" | \"primary\" | \"muted\";\n\nexport interface TableCellProps extends Omit<TdHTMLAttributes<HTMLTableCellElement>, \"align\"> {\n align?: TableAlign;\n width?: TableCellWidth;\n /** `primary` is the row's identity cell — one per row, never two. */\n emphasis?: TableCellEmphasis;\n}\n\nexport const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(function TableCell(\n { align = \"start\", width = \"auto\", emphasis = \"default\", className, ...rest },\n ref,\n) {\n return (\n <td\n ref={ref}\n data-align={align}\n data-width={width}\n data-emphasis={emphasis === \"default\" ? undefined : emphasis}\n className={className}\n {...rest}\n />\n );\n});\n\nexport interface TableEmptyProps extends HTMLAttributes<HTMLDivElement> {\n icon?: IconName;\n title?: string;\n description?: string;\n /** One action at most — the thing that ends the empty state. */\n action?: ReactNode;\n}\n\n/** What the frame shows when the collection has no rows. */\nexport const TableEmpty = forwardRef<HTMLDivElement, TableEmptyProps>(function TableEmpty(\n { icon = \"info\", title = \"No data found.\", description, action, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-empty\", className)}\n {...rest}\n >\n <Icon\n name={icon}\n size={24}\n />\n <span style={{ color: \"var(--color-text)\", fontWeight: \"var(--font-weight-bold)\" }}>\n {title}\n </span>\n {description && <span>{description}</span>}\n {action}\n </div>\n );\n});\n"],"mappings":"A,2KAiBA,SAASU,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAOA,IAAaC,GAAA,EAAaZ,EAAAA,WAAAA,CAA4C,SACpE,CAAE,YAAW,WAAU,GAAGa,GAC1B,EACA,CACA,OACE,EAAAJ,EAAA,IAAA,CAAC,MAAD,CACO,MACL,UAAWC,EAAG,iBAAkBI,CAAS,EACzC,GAAID,EAEH,UACE,CAAA,CAET,CAAC,EAUYE,GAAA,EAAef,EAAAA,WAAAA,CAA8C,SACxE,CAAE,QAAO,MAAK,YAAW,GAAGa,GAC5B,EACA,CACA,OACE,EAAAJ,EAAA,KAAA,CAAC,MAAD,CACO,MACL,UAAWC,EAAG,mBAAoBI,CAAS,EAC3C,GAAID,EAHN,SAAA,EAKE,EAAAJ,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,0BAA2B,SAAAO,CAAW,CAAA,GACrD,EAAAP,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,0BAA2B,SAAAQ,CAAS,CAAA,CAChD,C,EAET,CAAC,EAUD,SAASC,EAAe,EAA8B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AO,CAAE,MAAO,oBAAqB,WAAY,yBAA0B,EAC9E,SAAA4B,CACG,CAAA,EACLC,IAAe,EAAA7B,EAAA,IAAA,CAAC,OAAD,CAAA,SAAO6B,CAAkB,CAAA,EACxCC,CACE,C,EAET,CAAC,E"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["forwardRef","Children","isValidElement","Fragment","createContext","useContext","Icon","require_Icon","react","react_jsx_runtime","cx","parts","TableFrame","rest","className","TableToolbar","start","end","hasBodyContent","children","child","TableContext","Table","TableHead","TableBody","isEmpty","TableRow","TableCell","TableEmpty","emptyMessage","isSelected","isInteractive","TableHeaderCell","align","width","emphasis","icon","title","description","action"],"sources":["../../../src/components/Table/index.tsx"],"sourcesContent":["import {\n Children,\n Fragment,\n createContext,\n forwardRef,\n isValidElement,\n useContext,\n type HTMLAttributes,\n type ReactNode,\n type TableHTMLAttributes,\n type TdHTMLAttributes,\n type ThHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport type { IconName } from \"../Icon/icons\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface TableFrameProps extends HTMLAttributes<HTMLDivElement> {\n children?: ReactNode;\n}\n\n/** The 3px collection frame every table, list and board sits inside. */\nexport const TableFrame = forwardRef<HTMLDivElement, TableFrameProps>(function TableFrame(\n { className, children, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-frame\", \"ds-field-surface\", className)}\n {...rest}\n >\n {children}\n </div>\n );\n});\n\nexport interface TableToolbarProps extends HTMLAttributes<HTMLDivElement> {\n /** Left side — usually a select-all checkbox, a title and a count badge. */\n start?: ReactNode;\n /** Right side — filters and the one primary action. */\n end?: ReactNode;\n}\n\n/** The band above the rules: selection, title, count, filters, primary action. */\nexport const TableToolbar = forwardRef<HTMLDivElement, TableToolbarProps>(function TableToolbar(\n { start, end, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-toolbar\", className)}\n {...rest}\n >\n <div className=\"ds-table-toolbar__group\">{start}</div>\n <div className=\"ds-table-toolbar__group\">{end}</div>\n </div>\n );\n});\n\nexport interface TableProps extends TableHTMLAttributes<HTMLTableElement> {\n /** Message shown when a body has no rows. */\n emptyMessage?: string;\n /** Override empty-child detection when rows are rendered by custom components. */\n isEmpty?: boolean;\n children?: ReactNode;\n}\n\nfunction hasBodyContent(children: ReactNode): boolean {\n return Children.toArray(children).some(\n (child) =>\n isValidElement<{ children?: ReactNode }>(child) &&\n (child.type !== Fragment || hasBodyContent(child.props.children)),\n );\n}\n\nconst TableContext = createContext<{\n emptyMessage: string;\n isEmpty?: boolean;\n}>({ emptyMessage: \"No data found.\" });\n\n/** The rules layer. Always render it inside a `TableFrame`. */\nexport const Table = forwardRef<HTMLTableElement, TableProps>(function Table(\n { emptyMessage = \"No data found.\", isEmpty, className, children, ...rest },\n ref,\n) {\n return (\n <TableContext.Provider value={{ emptyMessage, isEmpty }}>\n <div className=\"ds-table-frame__scroll\">\n <table\n {...rest}\n ref={ref}\n className={cx(\"ds-table\", className)}\n >\n {children}\n </table>\n </div>\n </TableContext.Provider>\n );\n});\n\nexport const TableHead = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableHead({ className, ...rest }, ref) {\n return (\n <thead\n ref={ref}\n className={className}\n {...rest}\n />\n );\n});\n\nexport const TableBody = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableBody({ className, children, ...rest }, ref) {\n const { emptyMessage, isEmpty } = useContext(TableContext);\n return (\n <tbody\n ref={ref}\n className={className}\n {...rest}\n >\n {(isEmpty ?? !hasBodyContent(children)) ? (\n <TableRow>\n {/* HTML's maximum span covers the row without inspecting columns. */}\n <TableCell\n colSpan={1000}\n className=\"ds-table__empty-cell\"\n >\n <TableEmpty\n title={emptyMessage}\n role=\"status\"\n />\n </TableCell>\n </TableRow>\n ) : (\n children\n )}\n </tbody>\n );\n});\n\nexport interface TableRowProps extends HTMLAttributes<HTMLTableRowElement> {\n /** Paints the soft fill and the solid rail. Never changes the row's size. */\n isSelected?: boolean;\n /** Marks the row clickable: hover fill plus a pointer cursor. */\n isInteractive?: boolean;\n}\n\nexport const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(function TableRow(\n { isSelected = false, isInteractive = false, className, ...rest },\n ref,\n) {\n return (\n <tr\n ref={ref}\n data-selected={isSelected || undefined}\n data-interactive={isInteractive || undefined}\n tabIndex={isInteractive ? 0 : undefined}\n className={className}\n {...rest}\n />\n );\n});\n\nexport type TableAlign = \"start\" | \"end\";\nexport type TableCellWidth = \"auto\" | \"control\";\n\nexport interface TableHeaderCellProps extends Omit<\n ThHTMLAttributes<HTMLTableCellElement>,\n \"align\"\n> {\n align?: TableAlign;\n width?: TableCellWidth;\n}\n\nexport const TableHeaderCell = forwardRef<HTMLTableCellElement, TableHeaderCellProps>(\n function TableHeaderCell({ align = \"start\", width = \"auto\", className, ...rest }, ref) {\n return (\n <th\n ref={ref}\n scope=\"col\"\n data-align={align}\n data-width={width}\n className={className}\n {...rest}\n />\n );\n },\n);\n\nexport type TableCellEmphasis = \"default\" | \"primary\" | \"muted\";\n\nexport interface TableCellProps extends Omit<TdHTMLAttributes<HTMLTableCellElement>, \"align\"> {\n align?: TableAlign;\n width?: TableCellWidth;\n /** `primary` is the row's identity cell — one per row, never two. */\n emphasis?: TableCellEmphasis;\n}\n\nexport const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(function TableCell(\n { align = \"start\", width = \"auto\", emphasis = \"default\", className, ...rest },\n ref,\n) {\n return (\n <td\n ref={ref}\n data-align={align}\n data-width={width}\n data-emphasis={emphasis === \"default\" ? undefined : emphasis}\n className={className}\n {...rest}\n />\n );\n});\n\nexport interface TableEmptyProps extends HTMLAttributes<HTMLDivElement> {\n icon?: IconName;\n title?: string;\n description?: string;\n /** One action at most — the thing that ends the empty state. */\n action?: ReactNode;\n}\n\n/** What the frame shows when the collection has no rows. */\nexport const TableEmpty = forwardRef<HTMLDivElement, TableEmptyProps>(function TableEmpty(\n { icon = \"info\", title = \"No data found.\", description, action, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-empty\", className)}\n {...rest}\n >\n <Icon\n name={icon}\n size={24}\n />\n <span style={{ color: \"var(--color-text)\", fontWeight: \"var(--font-weight-bold)\" }}>\n {title}\n </span>\n {description && <span>{description}</span>}\n {action}\n </div>\n );\n});\n"],"mappings":"A,2KAiBA,SAASU,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAOA,IAAaC,GAAA,EAAaZ,EAAAA,WAAAA,CAA4C,SACpE,CAAE,YAAW,WAAU,GAAGa,GAC1B,EACA,CACA,OACE,EAAAJ,EAAA,IAAA,CAAC,MAAD,CACO,MACL,UAAWC,EAAG,iBAAkB,mBAAoBI,CAAS,EAC7D,GAAID,EAEH,UACE,CAAA,CAET,CAAC,EAUYE,GAAA,EAAef,EAAAA,WAAAA,CAA8C,SACxE,CAAE,QAAO,MAAK,YAAW,GAAGa,GAC5B,EACA,CACA,OACE,EAAAJ,EAAA,KAAA,CAAC,MAAD,CACO,MACL,UAAWC,EAAG,mBAAoBI,CAAS,EAC3C,GAAID,EAHN,SAAA,EAKE,EAAAJ,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,0BAA2B,SAAAO,CAAW,CAAA,GACrD,EAAAP,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,0BAA2B,SAAAQ,CAAS,CAAA,CAChD,C,EAET,CAAC,EAUD,SAASC,EAAe,EAA8B,CACpD,OAAOjB,EAAAA,SAAS,QAAQkB,CAAQ,CAAC,CAAC,KAC/B,IAAA,EACCjB,EAAAA,eAAAA,CAAyCkB,CAAK,IAC7CA,EAAM,OAASjB,EAAAA,UAAYe,EAAeE,EAAM,MAAM,QAAQ,EACnE,CACF,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1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Icon","cx","parts","TableFrame","forwardRef","rest","className","TableToolbar","start","end","hasBodyContent","Children","children","isValidElement","child","Fragment","TableContext","createContext","Table","TableHead","TableBody","useContext","isEmpty","TableRow","TableCell","TableEmpty","emptyMessage","isSelected","isInteractive","TableHeaderCell","align","width","emphasis","icon","title","description","action"],"sources":["../../../src/components/Table/index.tsx"],"sourcesContent":["import {\n Children,\n Fragment,\n createContext,\n forwardRef,\n isValidElement,\n useContext,\n type HTMLAttributes,\n type ReactNode,\n type TableHTMLAttributes,\n type TdHTMLAttributes,\n type ThHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport type { IconName } from \"../Icon/icons\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface TableFrameProps extends HTMLAttributes<HTMLDivElement> {\n children?: ReactNode;\n}\n\n/** The 3px collection frame every table, list and board sits inside. */\nexport const TableFrame = forwardRef<HTMLDivElement, TableFrameProps>(function TableFrame(\n { className, children, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-frame\", className)}\n {...rest}\n >\n {children}\n </div>\n );\n});\n\nexport interface TableToolbarProps extends HTMLAttributes<HTMLDivElement> {\n /** Left side — usually a select-all checkbox, a title and a count badge. */\n start?: ReactNode;\n /** Right side — filters and the one primary action. */\n end?: ReactNode;\n}\n\n/** The band above the rules: selection, title, count, filters, primary action. */\nexport const TableToolbar = forwardRef<HTMLDivElement, TableToolbarProps>(function TableToolbar(\n { start, end, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-toolbar\", className)}\n {...rest}\n >\n <div className=\"ds-table-toolbar__group\">{start}</div>\n <div className=\"ds-table-toolbar__group\">{end}</div>\n </div>\n );\n});\n\nexport interface TableProps extends TableHTMLAttributes<HTMLTableElement> {\n /** Message shown when a body has no rows. */\n emptyMessage?: string;\n /** Override empty-child detection when rows are rendered by custom components. */\n isEmpty?: boolean;\n children?: ReactNode;\n}\n\nfunction hasBodyContent(children: ReactNode): boolean {\n return Children.toArray(children).some(\n (child) =>\n isValidElement<{ children?: ReactNode }>(child) &&\n (child.type !== Fragment || hasBodyContent(child.props.children)),\n );\n}\n\nconst TableContext = createContext<{\n emptyMessage: string;\n isEmpty?: boolean;\n}>({ emptyMessage: \"No data found.\" });\n\n/** The rules layer. Always render it inside a `TableFrame`. */\nexport const Table = forwardRef<HTMLTableElement, TableProps>(function Table(\n { emptyMessage = \"No data found.\", isEmpty, className, children, ...rest },\n ref,\n) {\n return (\n <TableContext.Provider value={{ emptyMessage, isEmpty }}>\n <div className=\"ds-table-frame__scroll\">\n <table\n {...rest}\n ref={ref}\n className={cx(\"ds-table\", className)}\n >\n {children}\n </table>\n </div>\n </TableContext.Provider>\n );\n});\n\nexport const TableHead = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableHead({ className, ...rest }, ref) {\n return (\n <thead\n ref={ref}\n className={className}\n {...rest}\n />\n );\n});\n\nexport const TableBody = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableBody({ className, children, ...rest }, ref) {\n const { emptyMessage, isEmpty } = useContext(TableContext);\n return (\n <tbody\n ref={ref}\n className={className}\n {...rest}\n >\n {(isEmpty ?? !hasBodyContent(children)) ? (\n <TableRow>\n {/* HTML's maximum span covers the row without inspecting columns. */}\n <TableCell\n colSpan={1000}\n className=\"ds-table__empty-cell\"\n >\n <TableEmpty\n title={emptyMessage}\n role=\"status\"\n />\n </TableCell>\n </TableRow>\n ) : (\n children\n )}\n </tbody>\n );\n});\n\nexport interface TableRowProps extends HTMLAttributes<HTMLTableRowElement> {\n /** Paints the soft fill and the solid rail. Never changes the row's size. */\n isSelected?: boolean;\n /** Marks the row clickable: hover fill plus a pointer cursor. */\n isInteractive?: boolean;\n}\n\nexport const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(function TableRow(\n { isSelected = false, isInteractive = false, className, ...rest },\n ref,\n) {\n return (\n <tr\n ref={ref}\n data-selected={isSelected || undefined}\n data-interactive={isInteractive || undefined}\n tabIndex={isInteractive ? 0 : undefined}\n className={className}\n {...rest}\n />\n );\n});\n\nexport type TableAlign = \"start\" | \"end\";\nexport type TableCellWidth = \"auto\" | \"control\";\n\nexport interface TableHeaderCellProps extends Omit<\n ThHTMLAttributes<HTMLTableCellElement>,\n \"align\"\n> {\n align?: TableAlign;\n width?: TableCellWidth;\n}\n\nexport const TableHeaderCell = forwardRef<HTMLTableCellElement, TableHeaderCellProps>(\n function TableHeaderCell({ align = \"start\", width = \"auto\", className, ...rest }, ref) {\n return (\n <th\n ref={ref}\n scope=\"col\"\n data-align={align}\n data-width={width}\n className={className}\n {...rest}\n />\n );\n },\n);\n\nexport type TableCellEmphasis = \"default\" | \"primary\" | \"muted\";\n\nexport interface TableCellProps extends Omit<TdHTMLAttributes<HTMLTableCellElement>, \"align\"> {\n align?: TableAlign;\n width?: TableCellWidth;\n /** `primary` is the row's identity cell — one per row, never two. */\n emphasis?: TableCellEmphasis;\n}\n\nexport const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(function TableCell(\n { align = \"start\", width = \"auto\", emphasis = \"default\", className, ...rest },\n ref,\n) {\n return (\n <td\n ref={ref}\n data-align={align}\n data-width={width}\n data-emphasis={emphasis === \"default\" ? undefined : emphasis}\n className={className}\n {...rest}\n />\n );\n});\n\nexport interface TableEmptyProps extends HTMLAttributes<HTMLDivElement> {\n icon?: IconName;\n title?: string;\n description?: string;\n /** One action at most — the thing that ends the empty state. */\n action?: ReactNode;\n}\n\n/** What the frame shows when the collection has no rows. */\nexport const TableEmpty = forwardRef<HTMLDivElement, TableEmptyProps>(function TableEmpty(\n { icon = \"info\", title = \"No data found.\", description, action, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-empty\", className)}\n {...rest}\n >\n <Icon\n name={icon}\n size={24}\n />\n <span style={{ color: \"var(--color-text)\", fontWeight: \"var(--font-weight-bold)\" }}>\n {title}\n </span>\n {description && <span>{description}</span>}\n {action}\n </div>\n );\n});\n"],"mappings":";;;;AAiBA,SAASC,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAOA,IAAaC,IAAaC,EAA4C,SACpE,EAAE,cAAW,aAAU,GAAGC,KAC1B,GACA;CACA,OACE,kBAAC,OAAD;EACO;EACL,WAAWJ,EAAG,
|
|
1
|
+
{"version":3,"file":"index.js","names":["Icon","cx","parts","TableFrame","forwardRef","rest","className","TableToolbar","start","end","hasBodyContent","Children","children","isValidElement","child","Fragment","TableContext","createContext","Table","TableHead","TableBody","useContext","isEmpty","TableRow","TableCell","TableEmpty","emptyMessage","isSelected","isInteractive","TableHeaderCell","align","width","emphasis","icon","title","description","action"],"sources":["../../../src/components/Table/index.tsx"],"sourcesContent":["import {\n Children,\n Fragment,\n createContext,\n forwardRef,\n isValidElement,\n useContext,\n type HTMLAttributes,\n type ReactNode,\n type TableHTMLAttributes,\n type TdHTMLAttributes,\n type ThHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport type { IconName } from \"../Icon/icons\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface TableFrameProps extends HTMLAttributes<HTMLDivElement> {\n children?: ReactNode;\n}\n\n/** The 3px collection frame every table, list and board sits inside. */\nexport const TableFrame = forwardRef<HTMLDivElement, TableFrameProps>(function TableFrame(\n { className, children, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-frame\", \"ds-field-surface\", className)}\n {...rest}\n >\n {children}\n </div>\n );\n});\n\nexport interface TableToolbarProps extends HTMLAttributes<HTMLDivElement> {\n /** Left side — usually a select-all checkbox, a title and a count badge. */\n start?: ReactNode;\n /** Right side — filters and the one primary action. */\n end?: ReactNode;\n}\n\n/** The band above the rules: selection, title, count, filters, primary action. */\nexport const TableToolbar = forwardRef<HTMLDivElement, TableToolbarProps>(function TableToolbar(\n { start, end, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-toolbar\", className)}\n {...rest}\n >\n <div className=\"ds-table-toolbar__group\">{start}</div>\n <div className=\"ds-table-toolbar__group\">{end}</div>\n </div>\n );\n});\n\nexport interface TableProps extends TableHTMLAttributes<HTMLTableElement> {\n /** Message shown when a body has no rows. */\n emptyMessage?: string;\n /** Override empty-child detection when rows are rendered by custom components. */\n isEmpty?: boolean;\n children?: ReactNode;\n}\n\nfunction hasBodyContent(children: ReactNode): boolean {\n return Children.toArray(children).some(\n (child) =>\n isValidElement<{ children?: ReactNode }>(child) &&\n (child.type !== Fragment || hasBodyContent(child.props.children)),\n );\n}\n\nconst TableContext = createContext<{\n emptyMessage: string;\n isEmpty?: boolean;\n}>({ emptyMessage: \"No data found.\" });\n\n/** The rules layer. Always render it inside a `TableFrame`. */\nexport const Table = forwardRef<HTMLTableElement, TableProps>(function Table(\n { emptyMessage = \"No data found.\", isEmpty, className, children, ...rest },\n ref,\n) {\n return (\n <TableContext.Provider value={{ emptyMessage, isEmpty }}>\n <div className=\"ds-table-frame__scroll\">\n <table\n {...rest}\n ref={ref}\n className={cx(\"ds-table\", className)}\n >\n {children}\n </table>\n </div>\n </TableContext.Provider>\n );\n});\n\nexport const TableHead = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableHead({ className, ...rest }, ref) {\n return (\n <thead\n ref={ref}\n className={className}\n {...rest}\n />\n );\n});\n\nexport const TableBody = forwardRef<\n HTMLTableSectionElement,\n HTMLAttributes<HTMLTableSectionElement>\n>(function TableBody({ className, children, ...rest }, ref) {\n const { emptyMessage, isEmpty } = useContext(TableContext);\n return (\n <tbody\n ref={ref}\n className={className}\n {...rest}\n >\n {(isEmpty ?? !hasBodyContent(children)) ? (\n <TableRow>\n {/* HTML's maximum span covers the row without inspecting columns. */}\n <TableCell\n colSpan={1000}\n className=\"ds-table__empty-cell\"\n >\n <TableEmpty\n title={emptyMessage}\n role=\"status\"\n />\n </TableCell>\n </TableRow>\n ) : (\n children\n )}\n </tbody>\n );\n});\n\nexport interface TableRowProps extends HTMLAttributes<HTMLTableRowElement> {\n /** Paints the soft fill and the solid rail. Never changes the row's size. */\n isSelected?: boolean;\n /** Marks the row clickable: hover fill plus a pointer cursor. */\n isInteractive?: boolean;\n}\n\nexport const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(function TableRow(\n { isSelected = false, isInteractive = false, className, ...rest },\n ref,\n) {\n return (\n <tr\n ref={ref}\n data-selected={isSelected || undefined}\n data-interactive={isInteractive || undefined}\n tabIndex={isInteractive ? 0 : undefined}\n className={className}\n {...rest}\n />\n );\n});\n\nexport type TableAlign = \"start\" | \"end\";\nexport type TableCellWidth = \"auto\" | \"control\";\n\nexport interface TableHeaderCellProps extends Omit<\n ThHTMLAttributes<HTMLTableCellElement>,\n \"align\"\n> {\n align?: TableAlign;\n width?: TableCellWidth;\n}\n\nexport const TableHeaderCell = forwardRef<HTMLTableCellElement, TableHeaderCellProps>(\n function TableHeaderCell({ align = \"start\", width = \"auto\", className, ...rest }, ref) {\n return (\n <th\n ref={ref}\n scope=\"col\"\n data-align={align}\n data-width={width}\n className={className}\n {...rest}\n />\n );\n },\n);\n\nexport type TableCellEmphasis = \"default\" | \"primary\" | \"muted\";\n\nexport interface TableCellProps extends Omit<TdHTMLAttributes<HTMLTableCellElement>, \"align\"> {\n align?: TableAlign;\n width?: TableCellWidth;\n /** `primary` is the row's identity cell — one per row, never two. */\n emphasis?: TableCellEmphasis;\n}\n\nexport const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(function TableCell(\n { align = \"start\", width = \"auto\", emphasis = \"default\", className, ...rest },\n ref,\n) {\n return (\n <td\n ref={ref}\n data-align={align}\n data-width={width}\n data-emphasis={emphasis === \"default\" ? undefined : emphasis}\n className={className}\n {...rest}\n />\n );\n});\n\nexport interface TableEmptyProps extends HTMLAttributes<HTMLDivElement> {\n icon?: IconName;\n title?: string;\n description?: string;\n /** One action at most — the thing that ends the empty state. */\n action?: ReactNode;\n}\n\n/** What the frame shows when the collection has no rows. */\nexport const TableEmpty = forwardRef<HTMLDivElement, TableEmptyProps>(function TableEmpty(\n { icon = \"info\", title = \"No data found.\", description, action, className, ...rest },\n ref,\n) {\n return (\n <div\n ref={ref}\n className={cx(\"ds-table-empty\", className)}\n {...rest}\n >\n <Icon\n name={icon}\n size={24}\n />\n <span style={{ color: \"var(--color-text)\", fontWeight: \"var(--font-weight-bold)\" }}>\n {title}\n </span>\n {description && <span>{description}</span>}\n {action}\n </div>\n );\n});\n"],"mappings":";;;;AAiBA,SAASC,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAOA,IAAaC,IAAaC,EAA4C,SACpE,EAAE,cAAW,aAAU,GAAGC,KAC1B,GACA;CACA,OACE,kBAAC,OAAD;EACO;EACL,WAAWJ,EAAG,kBAAkB,oBAAoBK,CAAS;EAC7D,GAAID;EAEH;CACE,CAAA;AAET,CAAC,GAUYE,IAAeH,EAA8C,SACxE,EAAE,UAAO,QAAK,cAAW,GAAGC,KAC5B,GACA;CACA,OACE,kBAAC,OAAD;EACO;EACL,WAAWJ,EAAG,oBAAoBK,CAAS;EAC3C,GAAID;EAHN,UAAA,CAKE,kBAAC,OAAD;GAAK,WAAU;GAA2B,UAAAG;EAAW,CAAA,GACrD,kBAAC,OAAD;GAAK,WAAU;GAA2B,UAAAC;EAAS,CAAA,CAChD;;AAET,CAAC;AAUD,SAASC,EAAe,GAA8B;CACpD,OAAOC,EAAS,QAAQC,CAAQ,CAAC,CAAC,MAC/B,MACCC,EAAyCC,CAAK,MAC7CA,EAAM,SAASC,KAAYL,EAAeI,EAAM,MAAM,QAAQ,EACnE;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,kBAAC,MAAD;EACO;EACL,OAAM;EACN,cAAYyB;EACZ,cAAYC;EACD;EACX,GAAI1B;CACL,CAAA;AAEL,CACF,GAWamB,IAAYpB,EAAiD,SACxE,EAAE,WAAQ,SAAS,WAAQ,QAAQ,cAAW,WAAW,cAAW,GAAGC,KACvE,GACA;CACA,OACE,kBAAC,MAAD;EACO;EACL,cAAYyB;EACZ,cAAYC;EACZ,iBAAeC,MAAa,YAAY,KAAA,IAAYA;EACzC;EACX,GAAI3B;CACL,CAAA;AAEL,CAAC,GAWYoB,IAAarB,EAA4C,SACpE,EAAE,UAAO,QAAQ,WAAQ,kBAAkB,gBAAa,WAAQ,cAAW,GAAGC,KAC9E,GACA;CACA,OACE,kBAAC,OAAD;EACO;EACL,WAAWJ,EAAG,kBAAkBK,CAAS;EACzC,GAAID;EAHN,UAAA;GAKE,kBAACL,GAAD;IACE,MAAMiC;IACN,MAAM;GACP,CAAA;GACD,kBAAC,QAAD;IAAM,OAAO;KAAE,OAAO;KAAqB,YAAY;IAA0B;IAC9E,UAAAC;GACG,CAAA;GACLC,KAAe,kBAAC,QAAD,EAAA,UAAOA,EAAkB,CAAA;GACxCC;EACE;;AAET,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../Button/index.cjs");;/* empty css */
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../Button/index.cjs");;/* empty css */const t=require("../../chunks/useLimit-DXe_VmYl.cjs");let n=require("react"),r=require("react/jsx-runtime");function i(...e){return e.filter(Boolean).join(` `)}var a=(0,n.forwardRef)(function({value:a,defaultValue:o=[],onValueChange:s,placeholder:c=`Add a tag`,size:l=`md`,max:u,isDisabled:d=!1,isInvalid:f=!1,required:p,"aria-invalid":m,className:h,...g},_){let[v,y]=(0,n.useState)(o),b=a??v;t.t(g,u===void 0?void 0:{count:b.length,max:u});let[x,S]=(0,n.useState)(``),C=(0,n.useRef)(null),w=e=>{a===void 0&&y(e),s?.(e)},T=e=>{let t=e.trim();t&&!b.includes(t)&&(u!==void 0&&b.length>=u||w([...b,t]))};return(0,r.jsxs)(`div`,{className:i(`ds-field-skin`,`ds-tags`,h),"data-size":l,"data-disabled":d||void 0,"aria-invalid":f||m||void 0,onClick:()=>C.current?.focus(),children:[b.map(t=>(0,r.jsxs)(`span`,{className:`ds-tags__tag`,children:[t,(0,r.jsx)(e.Button,{variant:`simple`,size:`xs`,isIconOnly:!0,iconStart:`x`,"aria-label":`Remove ${t}`,isDisabled:d,onClick:e=>{e.stopPropagation(),w(b.filter(e=>e!==t))}})]},t)),(0,r.jsx)(`input`,{ref:e=>{C.current=e,typeof _==`function`?_(e):_&&(_.current=e)},type:`text`,className:`ds-tags__input`,value:x,placeholder:b.length===0?c:``,disabled:d,"aria-invalid":f||m||void 0,"aria-required":p||void 0,onChange:e=>S(e.target.value),onKeyDown:e=>{e.key===`Enter`||e.key===`,`?(e.preventDefault(),T(x),S(``)):e.key===`Backspace`&&x===``&&b.length>0&&w(b.slice(0,-1))},onBlur:()=>{T(x),S(``)},...g})]})});exports.TagsInput=a;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["forwardRef","useState","useRef","Button","require_components_Button_index","react","react_jsx_runtime","cx","parts","TagsInput","ariaInvalid","rest","internal","setInternal","defaultValue","current","value","draft","setDraft","inputRef","commit","next","onValueChange","add","tag","raw","
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["forwardRef","useState","useRef","Button","require_components_Button_index","require_useLimit","react","react_jsx_runtime","cx","parts","TagsInput","ariaInvalid","rest","internal","setInternal","defaultValue","current","value","max","draft","setDraft","inputRef","commit","next","onValueChange","add","tag","raw","className","size","isDisabled","isInvalid","event","item","node","ref","placeholder","required"],"sources":["../../../src/components/TagsInput/index.tsx"],"sourcesContent":["import { forwardRef, useRef, useState, type KeyboardEvent } from \"react\";\nimport { Button } from \"../Button\";\nimport type { FieldBinding, FieldSize } from \"../Field\";\nimport { useReportedLimit } from \"../Field/useLimit\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface TagsInputProps extends FieldBinding {\n value?: string[];\n defaultValue?: string[];\n onValueChange?: (value: string[]) => void;\n placeholder?: string;\n size?: FieldSize;\n /** Stop accepting new tags past this count. */\n max?: number;\n isDisabled?: boolean;\n isInvalid?: boolean;\n className?: string;\n}\n\n/**\n * Free-text keywords. Enter or comma commits a tag, Backspace on an empty\n * input removes the last one. Tags are plain strings — never status tones.\n */\nexport const TagsInput = forwardRef<HTMLInputElement, TagsInputProps>(function TagsInput(\n {\n value,\n defaultValue = [],\n onValueChange,\n placeholder = \"Add a tag\",\n size = \"md\",\n max,\n isDisabled = false,\n isInvalid = false,\n required,\n \"aria-invalid\": ariaInvalid,\n className,\n ...rest\n },\n ref,\n) {\n const [internal, setInternal] = useState<string[]>(defaultValue);\n const current = value ?? internal;\n useReportedLimit(rest, max === undefined ? undefined : { count: current.length, max });\n const [draft, setDraft] = useState(\"\");\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n const commit = (next: string[]) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n\n const add = (raw: string) => {\n const tag = raw.trim();\n if (!tag || current.includes(tag)) {\n return;\n }\n if (max !== undefined && current.length >= max) {\n return;\n }\n commit([...current, tag]);\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === \"Enter\" || event.key === \",\") {\n event.preventDefault();\n add(draft);\n setDraft(\"\");\n } else if (event.key === \"Backspace\" && draft === \"\" && current.length > 0) {\n commit(current.slice(0, -1));\n }\n };\n\n return (\n <div\n className={cx(\"ds-field-skin\", \"ds-tags\", className)}\n data-size={size}\n data-disabled={isDisabled || undefined}\n aria-invalid={isInvalid || ariaInvalid || undefined}\n onClick={() => inputRef.current?.focus()}\n >\n {current.map((tag) => (\n <span\n key={tag}\n className=\"ds-tags__tag\"\n >\n {tag}\n <Button\n variant=\"simple\"\n size=\"xs\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${tag}`}\n isDisabled={isDisabled}\n onClick={(event) => {\n event.stopPropagation();\n commit(current.filter((item) => item !== tag));\n }}\n />\n </span>\n ))}\n <input\n ref={(node) => {\n inputRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }}\n type=\"text\"\n className=\"ds-tags__input\"\n value={draft}\n placeholder={current.length === 0 ? placeholder : \"\"}\n disabled={isDisabled}\n aria-invalid={isInvalid || ariaInvalid || undefined}\n aria-required={required || undefined}\n onChange={(event) => setDraft(event.target.value)}\n onKeyDown={onKeyDown}\n onBlur={() => {\n add(draft);\n setDraft(\"\");\n }}\n {...rest}\n />\n </div>\n );\n});\n"],"mappings":"A,iQAOA,SAASQ,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAmBA,IAAaC,GAAA,EAAYV,EAAAA,WAAAA,CAA6C,SACpE,CACE,QACA,eAAe,CAAC,EAChB,gBACA,cAAc,YACd,OAAO,KACP,MACA,aAAa,GACb,YAAY,GACZ,WACA,eAAgBW,EAChB,YACA,GAAGC,GAEL,EACA,CACA,GAAM,CAACC,EAAUC,IAAA,EAAeb,EAAAA,SAAAA,CAAmBc,CAAY,EACzDC,EAAUC,GAASJ,EACzBR,EAAA,EAAiBO,EAAMM,IAAQ,IAAA,GAAY,IAAA,GAAY,CAAE,MAAOF,EAAQ,OAAQ,KAAI,CAAC,EACrF,GAAM,CAACG,EAAOC,IAAA,EAAYnB,EAAAA,SAAAA,CAAS,EAAE,EAC/BoB,GAAA,EAAWnB,EAAAA,OAAAA,CAAgC,IAAI,EAE/CoB,EAAU,GAAmB,CAC7BL,IAAU,IAAA,IACZH,EAAYS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MAAQ,aAAeb,IAAU,IAAMH,EAAQ,OAAS,GACvEM,EAAON,EAAQ,MAAM,EAAG,EAAE,CAAC,CAE/B,EAgDM,WAAc,CACZS,EAAIN,CAAK,EACTC,EAAS,EAAE,CACb,EACA,GAAIR,CACL,CAAA,CACE,C,EAET,CAAC,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/TagsInput/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/TagsInput/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAExD,OAAO,oBAAoB,CAAC;AAC5B,OAAO,aAAa,CAAC;AAMrB,MAAM,WAAW,cAAe,SAAQ,YAAY;IAClD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,6GAyGpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/TagsInput/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/TagsInput/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAExD,OAAO,oBAAoB,CAAC;AAC5B,OAAO,aAAa,CAAC;AAMrB,MAAM,WAAW,cAAe,SAAQ,YAAY;IAClD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,6GAyGpB,CAAC"}
|