@j2-health/design-system 0.6.1 → 0.6.3

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.
Files changed (50) hide show
  1. package/dist/index.cjs +7 -0
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +4 -1
  4. package/dist/index2.js +4 -1
  5. package/dist/src/components/bareButton/BareButton.cjs +31 -0
  6. package/dist/src/components/bareButton/BareButton.cjs.map +1 -0
  7. package/dist/src/components/bareButton/BareButton.d.ts +16 -0
  8. package/dist/src/components/bareButton/BareButton.js +29 -0
  9. package/dist/src/components/bareButton/BareButton.js.map +1 -0
  10. package/dist/src/components/bareButton/index.d.ts +1 -0
  11. package/dist/src/components/changeChip/ChangeChip.cjs +36 -30
  12. package/dist/src/components/changeChip/ChangeChip.cjs.map +1 -1
  13. package/dist/src/components/changeChip/ChangeChip.d.ts +22 -5
  14. package/dist/src/components/changeChip/ChangeChip.js +37 -31
  15. package/dist/src/components/changeChip/ChangeChip.js.map +1 -1
  16. package/dist/src/components/input/AntdInput.d.ts +10 -10
  17. package/dist/src/components/input/AntdSearchInput.d.ts +10 -10
  18. package/dist/src/components/stepDrawer/StepDrawer.cjs +89 -0
  19. package/dist/src/components/stepDrawer/StepDrawer.cjs.map +1 -0
  20. package/dist/src/components/stepDrawer/StepDrawer.d.ts +65 -0
  21. package/dist/src/components/stepDrawer/StepDrawer.js +88 -0
  22. package/dist/src/components/stepDrawer/StepDrawer.js.map +1 -0
  23. package/dist/src/components/stepDrawer/index.d.ts +1 -0
  24. package/dist/src/components/steps/Steps.cjs +4 -3
  25. package/dist/src/components/steps/Steps.cjs.map +1 -1
  26. package/dist/src/components/steps/Steps.d.ts +1 -1
  27. package/dist/src/components/steps/Steps.js +4 -3
  28. package/dist/src/components/steps/Steps.js.map +1 -1
  29. package/dist/src/components/steps/useSteps.cjs +2 -2
  30. package/dist/src/components/steps/useSteps.cjs.map +1 -1
  31. package/dist/src/components/steps/useSteps.js +2 -2
  32. package/dist/src/components/steps/useSteps.js.map +1 -1
  33. package/dist/src/components/swatch/Swatch.cjs +12 -6
  34. package/dist/src/components/swatch/Swatch.cjs.map +1 -1
  35. package/dist/src/components/swatch/Swatch.d.ts +10 -3
  36. package/dist/src/components/swatch/Swatch.js +12 -6
  37. package/dist/src/components/swatch/Swatch.js.map +1 -1
  38. package/dist/src/components/swatch/index.d.ts +1 -1
  39. package/dist/src/components/swatchStrip/SwatchStrip.cjs +67 -28
  40. package/dist/src/components/swatchStrip/SwatchStrip.cjs.map +1 -1
  41. package/dist/src/components/swatchStrip/SwatchStrip.d.ts +56 -5
  42. package/dist/src/components/swatchStrip/SwatchStrip.js +67 -28
  43. package/dist/src/components/swatchStrip/SwatchStrip.js.map +1 -1
  44. package/dist/src/components/swatchStrip/index.d.ts +1 -1
  45. package/dist/src/utils/useRender.cjs +76 -0
  46. package/dist/src/utils/useRender.cjs.map +1 -0
  47. package/dist/src/utils/useRender.d.ts +29 -0
  48. package/dist/src/utils/useRender.js +73 -0
  49. package/dist/src/utils/useRender.js.map +1 -0
  50. package/package.json +18 -19
@@ -0,0 +1,89 @@
1
+ const require_Button = require("../button/Button.cjs");
2
+ const require_Drawer = require("../drawer/Drawer.cjs");
3
+ const require_Steps = require("../steps/Steps.cjs");
4
+ let react = require("react");
5
+ let react_jsx_runtime = require("react/jsx-runtime");
6
+ //#region src/components/stepDrawer/StepDrawer.tsx
7
+ var SlotContext = (0, react.createContext)({
8
+ primary: null,
9
+ extra: null
10
+ });
11
+ /**
12
+ * The footer's primary-action slot and the header's extra slot, for steps that
13
+ * build their own buttons from state the drawer's parent cannot reach. Portal
14
+ * into them with `createPortal`. A flow whose buttons are available where the
15
+ * drawer is rendered passes `primaryAction` / `extraContent` instead.
16
+ *
17
+ * Use one or the other on a given step. The header slot only exists while
18
+ * `extraContent` is empty, but the footer slot is always there, so a step that
19
+ * portals its primary action needs the flow to pass no `primaryAction`.
20
+ */
21
+ var useStepDrawerSlots = () => (0, react.useContext)(SlotContext);
22
+ /**
23
+ * A full-page multi-step drawer: bottom placement, a numbered step bar that
24
+ * shows progress but cannot be clicked, and a right-aligned footer. Navigation
25
+ * is footer-only. There is no Cancel button: leaving goes through `onClose`,
26
+ * from the close control or Esc.
27
+ *
28
+ * The flow owns everything that gates a step. There is deliberately no
29
+ * `canProceed` prop: whether the primary action is disabled, or clickable and
30
+ * revealing errors, is up to the node passed as `primaryAction`.
31
+ */
32
+ function StepDrawer({ open, onClose, title, labels, current, onBack, primaryAction, extraContent, bodyClassName = "h-full overflow-y-auto", destroyOnHidden, afterOpenChange, children }) {
33
+ const [primarySlot, setPrimarySlot] = (0, react.useState)(null);
34
+ const [extraSlot, setExtraSlot] = (0, react.useState)(null);
35
+ const slots = (0, react.useMemo)(() => ({
36
+ primary: primarySlot,
37
+ extra: extraSlot
38
+ }), [primarySlot, extraSlot]);
39
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Drawer.Drawer, {
40
+ open,
41
+ onClose,
42
+ title,
43
+ placement: "bottom",
44
+ fillPage: true,
45
+ destroyOnHidden,
46
+ afterOpenChange,
47
+ extraContent: extraContent || /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ref: setExtraSlot }),
48
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
49
+ className: "flex w-full justify-end gap-2",
50
+ children: [
51
+ onBack && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Button.Button, {
52
+ size: "large",
53
+ onClick: onBack,
54
+ children: "Go back"
55
+ }),
56
+ primaryAction,
57
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
58
+ ref: setPrimarySlot,
59
+ className: "contents"
60
+ })
61
+ ]
62
+ }),
63
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SlotContext.Provider, {
64
+ value: slots,
65
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
66
+ className: bodyClassName,
67
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
68
+ className: "flex w-full justify-center py-8",
69
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
70
+ className: "w-2/3 max-w-4xl",
71
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Steps.Steps, {
72
+ items: labels.map((label, index) => ({
73
+ title: index + 1,
74
+ description: label
75
+ })),
76
+ dot: true,
77
+ current
78
+ })
79
+ })
80
+ }), children]
81
+ })
82
+ })
83
+ });
84
+ }
85
+ //#endregion
86
+ exports.StepDrawer = StepDrawer;
87
+ exports.useStepDrawerSlots = useStepDrawerSlots;
88
+
89
+ //# sourceMappingURL=StepDrawer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StepDrawer.cjs","names":["createContext","useContext","useState","useMemo","Drawer","Button","Steps"],"sources":["../../../../src/components/stepDrawer/StepDrawer.tsx"],"sourcesContent":["import {\n createContext,\n useContext,\n useMemo,\n useState,\n type ReactNode,\n} from 'react'\nimport { Button } from '../button'\nimport { Drawer } from '../drawer'\nimport { Steps } from '../steps'\n\ntype StepDrawerSlots = {\n primary: HTMLElement | null\n extra: HTMLElement | null\n}\n\nconst SlotContext = createContext<StepDrawerSlots>({\n primary: null,\n extra: null,\n})\n\n/**\n * The footer's primary-action slot and the header's extra slot, for steps that\n * build their own buttons from state the drawer's parent cannot reach. Portal\n * into them with `createPortal`. A flow whose buttons are available where the\n * drawer is rendered passes `primaryAction` / `extraContent` instead.\n *\n * Use one or the other on a given step. The header slot only exists while\n * `extraContent` is empty, but the footer slot is always there, so a step that\n * portals its primary action needs the flow to pass no `primaryAction`.\n */\nexport const useStepDrawerSlots = () => useContext(SlotContext)\n\nexport type StepDrawerProps = {\n open: boolean\n onClose: () => void\n title: ReactNode\n /** One label per step, shown under its number in the step bar. */\n labels: string[]\n /** Zero-based index of the step on screen. The drawer never changes it. */\n current: number\n /**\n * Renders a Go back button in the footer. Omit it on a step with nowhere to\n * return to, which is usually the first. A flow whose first step does have\n * somewhere to return to passes a handler there too.\n */\n onBack?: () => void\n /** The footer's main button, such as Next or Submit. */\n primaryAction?: ReactNode\n /**\n * Content in the header, left of the close control. While it is empty\n * (any falsy value, such as the `false` from `cond && <X />`) the header\n * holds the extra slot instead.\n */\n extraContent?: ReactNode\n /**\n * Classes for the body around the step bar and content. Replaces the\n * default `h-full overflow-y-auto`, so a step that scrolls its own content\n * can pass `h-full` alone.\n */\n bodyClassName?: string\n destroyOnHidden?: boolean\n /**\n * Fires once the open or close animation has finished. A flow that resets\n * state on close wants this rather than `open`, which flips while the panel\n * is still on screen.\n */\n afterOpenChange?: (open: boolean) => void\n children: ReactNode\n}\n\n/**\n * A full-page multi-step drawer: bottom placement, a numbered step bar that\n * shows progress but cannot be clicked, and a right-aligned footer. Navigation\n * is footer-only. There is no Cancel button: leaving goes through `onClose`,\n * from the close control or Esc.\n *\n * The flow owns everything that gates a step. There is deliberately no\n * `canProceed` prop: whether the primary action is disabled, or clickable and\n * revealing errors, is up to the node passed as `primaryAction`.\n */\nexport function StepDrawer({\n open,\n onClose,\n title,\n labels,\n current,\n onBack,\n primaryAction,\n extraContent,\n bodyClassName = 'h-full overflow-y-auto',\n destroyOnHidden,\n afterOpenChange,\n children,\n}: StepDrawerProps) {\n const [primarySlot, setPrimarySlot] = useState<HTMLDivElement | null>(null)\n const [extraSlot, setExtraSlot] = useState<HTMLDivElement | null>(null)\n const slots = useMemo(\n () => ({ primary: primarySlot, extra: extraSlot }),\n [primarySlot, extraSlot]\n )\n\n return (\n <Drawer\n open={open}\n onClose={onClose}\n title={title}\n placement=\"bottom\"\n fillPage\n destroyOnHidden={destroyOnHidden}\n afterOpenChange={afterOpenChange}\n // Unlike the footer slot below, this one is either/or: the header sits in\n // an antd `Space`, which gives every child its own gap, so an unused slot\n // would push the close control across.\n extraContent={extraContent || <div ref={setExtraSlot} />}\n footer={\n <div className=\"flex w-full justify-end gap-2\">\n {/* The group is right-anchored, so a missing Go back leaves the\n primary action where it was rather than shifting it. */}\n {onBack && (\n <Button size=\"large\" onClick={onBack}>\n Go back\n </Button>\n )}\n {primaryAction}\n {/* `contents` keeps the empty slot out of the flex row, so a flow can\n pass `primaryAction` on some steps and portal into the slot on\n others without the unused one opening a gap. */}\n <div ref={setPrimarySlot} className=\"contents\" />\n </div>\n }\n >\n <SlotContext.Provider value={slots}>\n <div className={bodyClassName}>\n <div className=\"flex w-full justify-center py-8\">\n <div className=\"w-2/3 max-w-4xl\">\n {/* `current` without `setCurrent` renders the bar read-only. */}\n <Steps\n items={labels.map((label, index) => ({\n title: index + 1,\n description: label,\n }))}\n dot\n current={current}\n />\n </div>\n </div>\n {children}\n </div>\n </SlotContext.Provider>\n </Drawer>\n )\n}\n"],"mappings":";;;;;;AAgBA,IAAM,eAAA,GAAcA,MAAAA,cAAAA,CAA+B;CACjD,SAAS;CACT,OAAO;AACT,CAAC;;;;;;;;;;;AAYD,IAAa,4BAAA,GAA2BC,MAAAA,WAAAA,CAAW,WAAW;;;;;;;;;;;AAkD9D,SAAgB,WAAW,EACzB,MACA,SACA,OACA,QACA,SACA,QACA,eACA,cACA,gBAAgB,0BAChB,iBACA,iBACA,YACkB;CAClB,MAAM,CAAC,aAAa,mBAAA,GAAkBC,MAAAA,SAAAA,CAAgC,IAAI;CAC1E,MAAM,CAAC,WAAW,iBAAA,GAAgBA,MAAAA,SAAAA,CAAgC,IAAI;CACtE,MAAM,SAAA,GAAQC,MAAAA,QAAAA,QACL;EAAE,SAAS;EAAa,OAAO;CAAU,IAChD,CAAC,aAAa,SAAS,CACzB;CAEA,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,eAAAA,QAAD;EACQ;EACG;EACF;EACP,WAAU;EACV,UAAA;EACiB;EACA;EAIjB,cAAc,gBAAgB,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD,EAAK,KAAK,aAAe,CAAA;EACvD,QACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IAGG,UACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,eAAAA,QAAD;KAAQ,MAAK;KAAQ,SAAS;KAAQ,UAAA;IAE9B,CAAA;IAET;IAID,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;KAAK,KAAK;KAAgB,WAAU;IAAY,CAAA;GAC7C;;EAGP,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,YAAY,UAAb;GAAsB,OAAO;GAC3B,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;IAAK,WAAW;IAAhB,UAAA,CACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;KAAK,WAAU;KACb,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;MAAK,WAAU;MAEb,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,OAAD;OACE,OAAO,OAAO,KAAK,OAAO,WAAW;QACnC,OAAO,QAAQ;QACf,aAAa;OACf,EAAE;OACF,KAAA;OACS;MACV,CAAA;KACE,CAAA;IACF,CAAA,GACJ,QACE;;EACe,CAAA;CAChB,CAAA;AAEZ"}
@@ -0,0 +1,65 @@
1
+ import { ReactNode } from 'react';
2
+ type StepDrawerSlots = {
3
+ primary: HTMLElement | null;
4
+ extra: HTMLElement | null;
5
+ };
6
+ /**
7
+ * The footer's primary-action slot and the header's extra slot, for steps that
8
+ * build their own buttons from state the drawer's parent cannot reach. Portal
9
+ * into them with `createPortal`. A flow whose buttons are available where the
10
+ * drawer is rendered passes `primaryAction` / `extraContent` instead.
11
+ *
12
+ * Use one or the other on a given step. The header slot only exists while
13
+ * `extraContent` is empty, but the footer slot is always there, so a step that
14
+ * portals its primary action needs the flow to pass no `primaryAction`.
15
+ */
16
+ export declare const useStepDrawerSlots: () => StepDrawerSlots;
17
+ export type StepDrawerProps = {
18
+ open: boolean;
19
+ onClose: () => void;
20
+ title: ReactNode;
21
+ /** One label per step, shown under its number in the step bar. */
22
+ labels: string[];
23
+ /** Zero-based index of the step on screen. The drawer never changes it. */
24
+ current: number;
25
+ /**
26
+ * Renders a Go back button in the footer. Omit it on a step with nowhere to
27
+ * return to, which is usually the first. A flow whose first step does have
28
+ * somewhere to return to passes a handler there too.
29
+ */
30
+ onBack?: () => void;
31
+ /** The footer's main button, such as Next or Submit. */
32
+ primaryAction?: ReactNode;
33
+ /**
34
+ * Content in the header, left of the close control. While it is empty
35
+ * (any falsy value, such as the `false` from `cond && <X />`) the header
36
+ * holds the extra slot instead.
37
+ */
38
+ extraContent?: ReactNode;
39
+ /**
40
+ * Classes for the body around the step bar and content. Replaces the
41
+ * default `h-full overflow-y-auto`, so a step that scrolls its own content
42
+ * can pass `h-full` alone.
43
+ */
44
+ bodyClassName?: string;
45
+ destroyOnHidden?: boolean;
46
+ /**
47
+ * Fires once the open or close animation has finished. A flow that resets
48
+ * state on close wants this rather than `open`, which flips while the panel
49
+ * is still on screen.
50
+ */
51
+ afterOpenChange?: (open: boolean) => void;
52
+ children: ReactNode;
53
+ };
54
+ /**
55
+ * A full-page multi-step drawer: bottom placement, a numbered step bar that
56
+ * shows progress but cannot be clicked, and a right-aligned footer. Navigation
57
+ * is footer-only. There is no Cancel button: leaving goes through `onClose`,
58
+ * from the close control or Esc.
59
+ *
60
+ * The flow owns everything that gates a step. There is deliberately no
61
+ * `canProceed` prop: whether the primary action is disabled, or clickable and
62
+ * revealing errors, is up to the node passed as `primaryAction`.
63
+ */
64
+ export declare function StepDrawer({ open, onClose, title, labels, current, onBack, primaryAction, extraContent, bodyClassName, destroyOnHidden, afterOpenChange, children, }: StepDrawerProps): import('react').JSX.Element;
65
+ export {};
@@ -0,0 +1,88 @@
1
+ import { Button } from "../button/Button.js";
2
+ import { Drawer } from "../drawer/Drawer.js";
3
+ import { Steps } from "../steps/Steps.js";
4
+ import { createContext, useContext, useMemo, useState } from "react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ //#region src/components/stepDrawer/StepDrawer.tsx
7
+ var SlotContext = createContext({
8
+ primary: null,
9
+ extra: null
10
+ });
11
+ /**
12
+ * The footer's primary-action slot and the header's extra slot, for steps that
13
+ * build their own buttons from state the drawer's parent cannot reach. Portal
14
+ * into them with `createPortal`. A flow whose buttons are available where the
15
+ * drawer is rendered passes `primaryAction` / `extraContent` instead.
16
+ *
17
+ * Use one or the other on a given step. The header slot only exists while
18
+ * `extraContent` is empty, but the footer slot is always there, so a step that
19
+ * portals its primary action needs the flow to pass no `primaryAction`.
20
+ */
21
+ var useStepDrawerSlots = () => useContext(SlotContext);
22
+ /**
23
+ * A full-page multi-step drawer: bottom placement, a numbered step bar that
24
+ * shows progress but cannot be clicked, and a right-aligned footer. Navigation
25
+ * is footer-only. There is no Cancel button: leaving goes through `onClose`,
26
+ * from the close control or Esc.
27
+ *
28
+ * The flow owns everything that gates a step. There is deliberately no
29
+ * `canProceed` prop: whether the primary action is disabled, or clickable and
30
+ * revealing errors, is up to the node passed as `primaryAction`.
31
+ */
32
+ function StepDrawer({ open, onClose, title, labels, current, onBack, primaryAction, extraContent, bodyClassName = "h-full overflow-y-auto", destroyOnHidden, afterOpenChange, children }) {
33
+ const [primarySlot, setPrimarySlot] = useState(null);
34
+ const [extraSlot, setExtraSlot] = useState(null);
35
+ const slots = useMemo(() => ({
36
+ primary: primarySlot,
37
+ extra: extraSlot
38
+ }), [primarySlot, extraSlot]);
39
+ return /* @__PURE__ */ jsx(Drawer, {
40
+ open,
41
+ onClose,
42
+ title,
43
+ placement: "bottom",
44
+ fillPage: true,
45
+ destroyOnHidden,
46
+ afterOpenChange,
47
+ extraContent: extraContent || /* @__PURE__ */ jsx("div", { ref: setExtraSlot }),
48
+ footer: /* @__PURE__ */ jsxs("div", {
49
+ className: "flex w-full justify-end gap-2",
50
+ children: [
51
+ onBack && /* @__PURE__ */ jsx(Button, {
52
+ size: "large",
53
+ onClick: onBack,
54
+ children: "Go back"
55
+ }),
56
+ primaryAction,
57
+ /* @__PURE__ */ jsx("div", {
58
+ ref: setPrimarySlot,
59
+ className: "contents"
60
+ })
61
+ ]
62
+ }),
63
+ children: /* @__PURE__ */ jsx(SlotContext.Provider, {
64
+ value: slots,
65
+ children: /* @__PURE__ */ jsxs("div", {
66
+ className: bodyClassName,
67
+ children: [/* @__PURE__ */ jsx("div", {
68
+ className: "flex w-full justify-center py-8",
69
+ children: /* @__PURE__ */ jsx("div", {
70
+ className: "w-2/3 max-w-4xl",
71
+ children: /* @__PURE__ */ jsx(Steps, {
72
+ items: labels.map((label, index) => ({
73
+ title: index + 1,
74
+ description: label
75
+ })),
76
+ dot: true,
77
+ current
78
+ })
79
+ })
80
+ }), children]
81
+ })
82
+ })
83
+ });
84
+ }
85
+ //#endregion
86
+ export { StepDrawer, useStepDrawerSlots };
87
+
88
+ //# sourceMappingURL=StepDrawer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StepDrawer.js","names":[],"sources":["../../../../src/components/stepDrawer/StepDrawer.tsx"],"sourcesContent":["import {\n createContext,\n useContext,\n useMemo,\n useState,\n type ReactNode,\n} from 'react'\nimport { Button } from '../button'\nimport { Drawer } from '../drawer'\nimport { Steps } from '../steps'\n\ntype StepDrawerSlots = {\n primary: HTMLElement | null\n extra: HTMLElement | null\n}\n\nconst SlotContext = createContext<StepDrawerSlots>({\n primary: null,\n extra: null,\n})\n\n/**\n * The footer's primary-action slot and the header's extra slot, for steps that\n * build their own buttons from state the drawer's parent cannot reach. Portal\n * into them with `createPortal`. A flow whose buttons are available where the\n * drawer is rendered passes `primaryAction` / `extraContent` instead.\n *\n * Use one or the other on a given step. The header slot only exists while\n * `extraContent` is empty, but the footer slot is always there, so a step that\n * portals its primary action needs the flow to pass no `primaryAction`.\n */\nexport const useStepDrawerSlots = () => useContext(SlotContext)\n\nexport type StepDrawerProps = {\n open: boolean\n onClose: () => void\n title: ReactNode\n /** One label per step, shown under its number in the step bar. */\n labels: string[]\n /** Zero-based index of the step on screen. The drawer never changes it. */\n current: number\n /**\n * Renders a Go back button in the footer. Omit it on a step with nowhere to\n * return to, which is usually the first. A flow whose first step does have\n * somewhere to return to passes a handler there too.\n */\n onBack?: () => void\n /** The footer's main button, such as Next or Submit. */\n primaryAction?: ReactNode\n /**\n * Content in the header, left of the close control. While it is empty\n * (any falsy value, such as the `false` from `cond && <X />`) the header\n * holds the extra slot instead.\n */\n extraContent?: ReactNode\n /**\n * Classes for the body around the step bar and content. Replaces the\n * default `h-full overflow-y-auto`, so a step that scrolls its own content\n * can pass `h-full` alone.\n */\n bodyClassName?: string\n destroyOnHidden?: boolean\n /**\n * Fires once the open or close animation has finished. A flow that resets\n * state on close wants this rather than `open`, which flips while the panel\n * is still on screen.\n */\n afterOpenChange?: (open: boolean) => void\n children: ReactNode\n}\n\n/**\n * A full-page multi-step drawer: bottom placement, a numbered step bar that\n * shows progress but cannot be clicked, and a right-aligned footer. Navigation\n * is footer-only. There is no Cancel button: leaving goes through `onClose`,\n * from the close control or Esc.\n *\n * The flow owns everything that gates a step. There is deliberately no\n * `canProceed` prop: whether the primary action is disabled, or clickable and\n * revealing errors, is up to the node passed as `primaryAction`.\n */\nexport function StepDrawer({\n open,\n onClose,\n title,\n labels,\n current,\n onBack,\n primaryAction,\n extraContent,\n bodyClassName = 'h-full overflow-y-auto',\n destroyOnHidden,\n afterOpenChange,\n children,\n}: StepDrawerProps) {\n const [primarySlot, setPrimarySlot] = useState<HTMLDivElement | null>(null)\n const [extraSlot, setExtraSlot] = useState<HTMLDivElement | null>(null)\n const slots = useMemo(\n () => ({ primary: primarySlot, extra: extraSlot }),\n [primarySlot, extraSlot]\n )\n\n return (\n <Drawer\n open={open}\n onClose={onClose}\n title={title}\n placement=\"bottom\"\n fillPage\n destroyOnHidden={destroyOnHidden}\n afterOpenChange={afterOpenChange}\n // Unlike the footer slot below, this one is either/or: the header sits in\n // an antd `Space`, which gives every child its own gap, so an unused slot\n // would push the close control across.\n extraContent={extraContent || <div ref={setExtraSlot} />}\n footer={\n <div className=\"flex w-full justify-end gap-2\">\n {/* The group is right-anchored, so a missing Go back leaves the\n primary action where it was rather than shifting it. */}\n {onBack && (\n <Button size=\"large\" onClick={onBack}>\n Go back\n </Button>\n )}\n {primaryAction}\n {/* `contents` keeps the empty slot out of the flex row, so a flow can\n pass `primaryAction` on some steps and portal into the slot on\n others without the unused one opening a gap. */}\n <div ref={setPrimarySlot} className=\"contents\" />\n </div>\n }\n >\n <SlotContext.Provider value={slots}>\n <div className={bodyClassName}>\n <div className=\"flex w-full justify-center py-8\">\n <div className=\"w-2/3 max-w-4xl\">\n {/* `current` without `setCurrent` renders the bar read-only. */}\n <Steps\n items={labels.map((label, index) => ({\n title: index + 1,\n description: label,\n }))}\n dot\n current={current}\n />\n </div>\n </div>\n {children}\n </div>\n </SlotContext.Provider>\n </Drawer>\n )\n}\n"],"mappings":";;;;;;AAgBA,IAAM,cAAc,cAA+B;CACjD,SAAS;CACT,OAAO;AACT,CAAC;;;;;;;;;;;AAYD,IAAa,2BAA2B,WAAW,WAAW;;;;;;;;;;;AAkD9D,SAAgB,WAAW,EACzB,MACA,SACA,OACA,QACA,SACA,QACA,eACA,cACA,gBAAgB,0BAChB,iBACA,iBACA,YACkB;CAClB,MAAM,CAAC,aAAa,kBAAkB,SAAgC,IAAI;CAC1E,MAAM,CAAC,WAAW,gBAAgB,SAAgC,IAAI;CACtE,MAAM,QAAQ,eACL;EAAE,SAAS;EAAa,OAAO;CAAU,IAChD,CAAC,aAAa,SAAS,CACzB;CAEA,OACE,oBAAC,QAAD;EACQ;EACG;EACF;EACP,WAAU;EACV,UAAA;EACiB;EACA;EAIjB,cAAc,gBAAgB,oBAAC,OAAD,EAAK,KAAK,aAAe,CAAA;EACvD,QACE,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IAGG,UACC,oBAAC,QAAD;KAAQ,MAAK;KAAQ,SAAS;KAAQ,UAAA;IAE9B,CAAA;IAET;IAID,oBAAC,OAAD;KAAK,KAAK;KAAgB,WAAU;IAAY,CAAA;GAC7C;;EAGP,UAAA,oBAAC,YAAY,UAAb;GAAsB,OAAO;GAC3B,UAAA,qBAAC,OAAD;IAAK,WAAW;IAAhB,UAAA,CACE,oBAAC,OAAD;KAAK,WAAU;KACb,UAAA,oBAAC,OAAD;MAAK,WAAU;MAEb,UAAA,oBAAC,OAAD;OACE,OAAO,OAAO,KAAK,OAAO,WAAW;QACnC,OAAO,QAAQ;QACf,aAAa;OACf,EAAE;OACF,KAAA;OACS;MACV,CAAA;KACE,CAAA;IACF,CAAA,GACJ,QACE;;EACe,CAAA;CAChB,CAAA;AAEZ"}
@@ -0,0 +1 @@
1
+ export { StepDrawer, useStepDrawerSlots, type StepDrawerProps, } from './StepDrawer.js';
@@ -8,22 +8,23 @@ let react_jsx_runtime = require("react/jsx-runtime");
8
8
  let classnames = require("classnames");
9
9
  classnames = require_runtime.__toESM(classnames, 1);
10
10
  //#region src/components/steps/Steps.tsx
11
- var Steps = ({ items, current, setCurrent, dot = false, direction, orientation, size, labelPlacement, titlePlacement, ...props }) => {
11
+ var Steps = ({ items, current, setCurrent, dot = false, direction, orientation, size, labelPlacement, titlePlacement, className, ...props }) => {
12
12
  const isVertical = (orientation ?? direction) === "vertical";
13
13
  const totalSteps = items?.length || 0;
14
+ const isReadOnly = current !== void 0 && setCurrent === void 0;
14
15
  const { current: currentStep, setCurrent: setCurrentStep } = require_useSteps.useSteps({
15
16
  current,
16
17
  setCurrent,
17
18
  totalSteps
18
19
  });
19
20
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Steps, {
20
- className: "j2Steps",
21
21
  ...props,
22
+ className: (0, classnames.default)("j2Steps", className),
22
23
  orientation: orientation ?? direction,
23
24
  titlePlacement: titlePlacement ?? labelPlacement,
24
25
  size: size === "default" ? "medium" : size,
25
26
  current: currentStep,
26
- onChange: (curr) => setCurrentStep(curr),
27
+ onChange: isReadOnly ? void 0 : (curr) => setCurrentStep(curr),
27
28
  ...dot && { type: "dot" },
28
29
  items: items?.map((item, index) => {
29
30
  const { description, ...restItem } = item;
@@ -1 +1 @@
1
- {"version":3,"file":"Steps.cjs","names":["useSteps","AntdSteps","cx","CheckIcon"],"sources":["../../../../src/components/steps/Steps.tsx"],"sourcesContent":["import { Steps as AntdSteps, StepsProps } from 'antd'\nimport './Steps.css'\nimport { CheckIcon } from '@phosphor-icons/react'\nimport cx from 'classnames'\nimport { useSteps } from './useSteps'\n\ntype AllProps = StepsProps & {\n items: NonNullable<StepsProps['items']>\n dot?: boolean\n current?: number\n setCurrent?: (current: number) => void\n}\n\ntype Props = Expand<AllProps>\n\nexport const Steps = ({\n items,\n current,\n setCurrent,\n dot = false,\n direction,\n orientation,\n size,\n labelPlacement,\n titlePlacement,\n ...props\n}: Props) => {\n const isVertical = (orientation ?? direction) === 'vertical'\n const totalSteps = items?.length || 0\n\n const { current: currentStep, setCurrent: setCurrentStep } = useSteps({\n current,\n setCurrent,\n totalSteps,\n })\n\n return (\n <AntdSteps\n className=\"j2Steps\"\n {...props}\n orientation={orientation ?? direction}\n titlePlacement={titlePlacement ?? labelPlacement}\n size={size === 'default' ? 'medium' : size}\n current={currentStep}\n onChange={(curr) => setCurrentStep(curr)}\n {...(dot && { type: 'dot' })}\n items={items?.map((item, index) => {\n const { description, ...restItem } = item\n return {\n ...restItem,\n content: item.content ?? description,\n icon:\n !dot && currentStep > index ? (\n <div\n className={cx(\n `check-${size === 'small' ? 'small' : 'medium'}`,\n isVertical ? `vertical-check-icon` : `check-icon`\n )}\n >\n <CheckIcon size={16} />\n </div>\n ) : (\n item.icon\n ),\n }\n })}\n />\n )\n}\n"],"mappings":";;;;;;;;;;AAeA,IAAa,SAAS,EACpB,OACA,SACA,YACA,MAAM,OACN,WACA,aACA,MACA,gBACA,gBACA,GAAG,YACQ;CACX,MAAM,cAAc,eAAe,eAAe;CAClD,MAAM,aAAa,OAAO,UAAU;CAEpC,MAAM,EAAE,SAAS,aAAa,YAAY,mBAAmBA,iBAAAA,SAAS;EACpE;EACA;EACA;CACF,CAAC;CAED,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,KAAAA,OAAD;EACE,WAAU;EACV,GAAI;EACJ,aAAa,eAAe;EAC5B,gBAAgB,kBAAkB;EAClC,MAAM,SAAS,YAAY,WAAW;EACtC,SAAS;EACT,WAAW,SAAS,eAAe,IAAI;EACvC,GAAK,OAAO,EAAE,MAAM,MAAM;EAC1B,OAAO,OAAO,KAAK,MAAM,UAAU;GACjC,MAAM,EAAE,aAAa,GAAG,aAAa;GACrC,OAAO;IACL,GAAG;IACH,SAAS,KAAK,WAAW;IACzB,MACE,CAAC,OAAO,cAAc,QACpB,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;KACE,YAAA,GAAWC,WAAAA,QAAAA,CACT,SAAS,SAAS,UAAU,UAAU,YACtC,aAAa,wBAAwB,YACvC;KAEA,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,WAAD,EAAW,MAAM,GAAK,CAAA;IACnB,CAAA,IAEL,KAAK;GAEX;EACF,CAAC;CACF,CAAA;AAEL"}
1
+ {"version":3,"file":"Steps.cjs","names":["useSteps","AntdSteps","cx","CheckIcon"],"sources":["../../../../src/components/steps/Steps.tsx"],"sourcesContent":["import { Steps as AntdSteps, StepsProps } from 'antd'\nimport './Steps.css'\nimport { CheckIcon } from '@phosphor-icons/react'\nimport cx from 'classnames'\nimport { useSteps } from './useSteps'\n\ntype AllProps = StepsProps & {\n items: NonNullable<StepsProps['items']>\n dot?: boolean\n current?: number\n setCurrent?: (current: number) => void\n}\n\ntype Props = Expand<AllProps>\n\nexport const Steps = ({\n items,\n current,\n setCurrent,\n dot = false,\n direction,\n orientation,\n size,\n labelPlacement,\n titlePlacement,\n className,\n ...props\n}: Props) => {\n const isVertical = (orientation ?? direction) === 'vertical'\n const totalSteps = items?.length || 0\n // antd only makes a step clickable when `onChange` is set, so a controlled\n // bar with no setter renders read-only rather than inert-but-clickable.\n const isReadOnly = current !== undefined && setCurrent === undefined\n\n const { current: currentStep, setCurrent: setCurrentStep } = useSteps({\n current,\n setCurrent,\n totalSteps,\n })\n\n return (\n <AntdSteps\n {...props}\n className={cx('j2Steps', className)}\n orientation={orientation ?? direction}\n titlePlacement={titlePlacement ?? labelPlacement}\n size={size === 'default' ? 'medium' : size}\n current={currentStep}\n onChange={isReadOnly ? undefined : (curr) => setCurrentStep(curr)}\n {...(dot && { type: 'dot' })}\n items={items?.map((item, index) => {\n const { description, ...restItem } = item\n return {\n ...restItem,\n content: item.content ?? description,\n icon:\n !dot && currentStep > index ? (\n <div\n className={cx(\n `check-${size === 'small' ? 'small' : 'medium'}`,\n isVertical ? `vertical-check-icon` : `check-icon`\n )}\n >\n <CheckIcon size={16} />\n </div>\n ) : (\n item.icon\n ),\n }\n })}\n />\n )\n}\n"],"mappings":";;;;;;;;;;AAeA,IAAa,SAAS,EACpB,OACA,SACA,YACA,MAAM,OACN,WACA,aACA,MACA,gBACA,gBACA,WACA,GAAG,YACQ;CACX,MAAM,cAAc,eAAe,eAAe;CAClD,MAAM,aAAa,OAAO,UAAU;CAGpC,MAAM,aAAa,YAAY,KAAA,KAAa,eAAe,KAAA;CAE3D,MAAM,EAAE,SAAS,aAAa,YAAY,mBAAmBA,iBAAAA,SAAS;EACpE;EACA;EACA;CACF,CAAC;CAED,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,KAAAA,OAAD;EACE,GAAI;EACJ,YAAA,GAAWC,WAAAA,QAAAA,CAAG,WAAW,SAAS;EAClC,aAAa,eAAe;EAC5B,gBAAgB,kBAAkB;EAClC,MAAM,SAAS,YAAY,WAAW;EACtC,SAAS;EACT,UAAU,aAAa,KAAA,KAAa,SAAS,eAAe,IAAI;EAChE,GAAK,OAAO,EAAE,MAAM,MAAM;EAC1B,OAAO,OAAO,KAAK,MAAM,UAAU;GACjC,MAAM,EAAE,aAAa,GAAG,aAAa;GACrC,OAAO;IACL,GAAG;IACH,SAAS,KAAK,WAAW;IACzB,MACE,CAAC,OAAO,cAAc,QACpB,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;KACE,YAAA,GAAWA,WAAAA,QAAAA,CACT,SAAS,SAAS,UAAU,UAAU,YACtC,aAAa,wBAAwB,YACvC;KAEA,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,WAAD,EAAW,MAAM,GAAK,CAAA;IACnB,CAAA,IAEL,KAAK;GAEX;EACF,CAAC;CACF,CAAA;AAEL"}
@@ -6,5 +6,5 @@ type AllProps = StepsProps & {
6
6
  setCurrent?: (current: number) => void;
7
7
  };
8
8
  type Props = Expand<AllProps>;
9
- export declare const Steps: ({ items, current, setCurrent, dot, direction, orientation, size, labelPlacement, titlePlacement, ...props }: Props) => import('react').JSX.Element;
9
+ export declare const Steps: ({ items, current, setCurrent, dot, direction, orientation, size, labelPlacement, titlePlacement, className, ...props }: Props) => import('react').JSX.Element;
10
10
  export {};
@@ -5,22 +5,23 @@ import { CheckIcon } from "@phosphor-icons/react";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  import cx from "classnames";
7
7
  //#region src/components/steps/Steps.tsx
8
- var Steps$1 = ({ items, current, setCurrent, dot = false, direction, orientation, size, labelPlacement, titlePlacement, ...props }) => {
8
+ var Steps$1 = ({ items, current, setCurrent, dot = false, direction, orientation, size, labelPlacement, titlePlacement, className, ...props }) => {
9
9
  const isVertical = (orientation ?? direction) === "vertical";
10
10
  const totalSteps = items?.length || 0;
11
+ const isReadOnly = current !== void 0 && setCurrent === void 0;
11
12
  const { current: currentStep, setCurrent: setCurrentStep } = useSteps({
12
13
  current,
13
14
  setCurrent,
14
15
  totalSteps
15
16
  });
16
17
  return /* @__PURE__ */ jsx(Steps, {
17
- className: "j2Steps",
18
18
  ...props,
19
+ className: cx("j2Steps", className),
19
20
  orientation: orientation ?? direction,
20
21
  titlePlacement: titlePlacement ?? labelPlacement,
21
22
  size: size === "default" ? "medium" : size,
22
23
  current: currentStep,
23
- onChange: (curr) => setCurrentStep(curr),
24
+ onChange: isReadOnly ? void 0 : (curr) => setCurrentStep(curr),
24
25
  ...dot && { type: "dot" },
25
26
  items: items?.map((item, index) => {
26
27
  const { description, ...restItem } = item;
@@ -1 +1 @@
1
- {"version":3,"file":"Steps.js","names":["Steps","AntdSteps"],"sources":["../../../../src/components/steps/Steps.tsx"],"sourcesContent":["import { Steps as AntdSteps, StepsProps } from 'antd'\nimport './Steps.css'\nimport { CheckIcon } from '@phosphor-icons/react'\nimport cx from 'classnames'\nimport { useSteps } from './useSteps'\n\ntype AllProps = StepsProps & {\n items: NonNullable<StepsProps['items']>\n dot?: boolean\n current?: number\n setCurrent?: (current: number) => void\n}\n\ntype Props = Expand<AllProps>\n\nexport const Steps = ({\n items,\n current,\n setCurrent,\n dot = false,\n direction,\n orientation,\n size,\n labelPlacement,\n titlePlacement,\n ...props\n}: Props) => {\n const isVertical = (orientation ?? direction) === 'vertical'\n const totalSteps = items?.length || 0\n\n const { current: currentStep, setCurrent: setCurrentStep } = useSteps({\n current,\n setCurrent,\n totalSteps,\n })\n\n return (\n <AntdSteps\n className=\"j2Steps\"\n {...props}\n orientation={orientation ?? direction}\n titlePlacement={titlePlacement ?? labelPlacement}\n size={size === 'default' ? 'medium' : size}\n current={currentStep}\n onChange={(curr) => setCurrentStep(curr)}\n {...(dot && { type: 'dot' })}\n items={items?.map((item, index) => {\n const { description, ...restItem } = item\n return {\n ...restItem,\n content: item.content ?? description,\n icon:\n !dot && currentStep > index ? (\n <div\n className={cx(\n `check-${size === 'small' ? 'small' : 'medium'}`,\n isVertical ? `vertical-check-icon` : `check-icon`\n )}\n >\n <CheckIcon size={16} />\n </div>\n ) : (\n item.icon\n ),\n }\n })}\n />\n )\n}\n"],"mappings":";;;;;;;AAeA,IAAaA,WAAS,EACpB,OACA,SACA,YACA,MAAM,OACN,WACA,aACA,MACA,gBACA,gBACA,GAAG,YACQ;CACX,MAAM,cAAc,eAAe,eAAe;CAClD,MAAM,aAAa,OAAO,UAAU;CAEpC,MAAM,EAAE,SAAS,aAAa,YAAY,mBAAmB,SAAS;EACpE;EACA;EACA;CACF,CAAC;CAED,OACE,oBAACC,OAAD;EACE,WAAU;EACV,GAAI;EACJ,aAAa,eAAe;EAC5B,gBAAgB,kBAAkB;EAClC,MAAM,SAAS,YAAY,WAAW;EACtC,SAAS;EACT,WAAW,SAAS,eAAe,IAAI;EACvC,GAAK,OAAO,EAAE,MAAM,MAAM;EAC1B,OAAO,OAAO,KAAK,MAAM,UAAU;GACjC,MAAM,EAAE,aAAa,GAAG,aAAa;GACrC,OAAO;IACL,GAAG;IACH,SAAS,KAAK,WAAW;IACzB,MACE,CAAC,OAAO,cAAc,QACpB,oBAAC,OAAD;KACE,WAAW,GACT,SAAS,SAAS,UAAU,UAAU,YACtC,aAAa,wBAAwB,YACvC;KAEA,UAAA,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA;IACnB,CAAA,IAEL,KAAK;GAEX;EACF,CAAC;CACF,CAAA;AAEL"}
1
+ {"version":3,"file":"Steps.js","names":["Steps","AntdSteps"],"sources":["../../../../src/components/steps/Steps.tsx"],"sourcesContent":["import { Steps as AntdSteps, StepsProps } from 'antd'\nimport './Steps.css'\nimport { CheckIcon } from '@phosphor-icons/react'\nimport cx from 'classnames'\nimport { useSteps } from './useSteps'\n\ntype AllProps = StepsProps & {\n items: NonNullable<StepsProps['items']>\n dot?: boolean\n current?: number\n setCurrent?: (current: number) => void\n}\n\ntype Props = Expand<AllProps>\n\nexport const Steps = ({\n items,\n current,\n setCurrent,\n dot = false,\n direction,\n orientation,\n size,\n labelPlacement,\n titlePlacement,\n className,\n ...props\n}: Props) => {\n const isVertical = (orientation ?? direction) === 'vertical'\n const totalSteps = items?.length || 0\n // antd only makes a step clickable when `onChange` is set, so a controlled\n // bar with no setter renders read-only rather than inert-but-clickable.\n const isReadOnly = current !== undefined && setCurrent === undefined\n\n const { current: currentStep, setCurrent: setCurrentStep } = useSteps({\n current,\n setCurrent,\n totalSteps,\n })\n\n return (\n <AntdSteps\n {...props}\n className={cx('j2Steps', className)}\n orientation={orientation ?? direction}\n titlePlacement={titlePlacement ?? labelPlacement}\n size={size === 'default' ? 'medium' : size}\n current={currentStep}\n onChange={isReadOnly ? undefined : (curr) => setCurrentStep(curr)}\n {...(dot && { type: 'dot' })}\n items={items?.map((item, index) => {\n const { description, ...restItem } = item\n return {\n ...restItem,\n content: item.content ?? description,\n icon:\n !dot && currentStep > index ? (\n <div\n className={cx(\n `check-${size === 'small' ? 'small' : 'medium'}`,\n isVertical ? `vertical-check-icon` : `check-icon`\n )}\n >\n <CheckIcon size={16} />\n </div>\n ) : (\n item.icon\n ),\n }\n })}\n />\n )\n}\n"],"mappings":";;;;;;;AAeA,IAAaA,WAAS,EACpB,OACA,SACA,YACA,MAAM,OACN,WACA,aACA,MACA,gBACA,gBACA,WACA,GAAG,YACQ;CACX,MAAM,cAAc,eAAe,eAAe;CAClD,MAAM,aAAa,OAAO,UAAU;CAGpC,MAAM,aAAa,YAAY,KAAA,KAAa,eAAe,KAAA;CAE3D,MAAM,EAAE,SAAS,aAAa,YAAY,mBAAmB,SAAS;EACpE;EACA;EACA;CACF,CAAC;CAED,OACE,oBAACC,OAAD;EACE,GAAI;EACJ,WAAW,GAAG,WAAW,SAAS;EAClC,aAAa,eAAe;EAC5B,gBAAgB,kBAAkB;EAClC,MAAM,SAAS,YAAY,WAAW;EACtC,SAAS;EACT,UAAU,aAAa,KAAA,KAAa,SAAS,eAAe,IAAI;EAChE,GAAK,OAAO,EAAE,MAAM,MAAM;EAC1B,OAAO,OAAO,KAAK,MAAM,UAAU;GACjC,MAAM,EAAE,aAAa,GAAG,aAAa;GACrC,OAAO;IACL,GAAG;IACH,SAAS,KAAK,WAAW;IACzB,MACE,CAAC,OAAO,cAAc,QACpB,oBAAC,OAAD;KACE,WAAW,GACT,SAAS,SAAS,UAAU,UAAU,YACtC,aAAa,wBAAwB,YACvC;KAEA,UAAA,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA;IACnB,CAAA,IAEL,KAAK;GAEX;EACF,CAAC;CACF,CAAA;AAEL"}
@@ -2,10 +2,10 @@ let react = require("react");
2
2
  //#region src/components/steps/useSteps.ts
3
3
  var useSteps = ({ current, setCurrent, totalSteps, initialStep = 0 }) => {
4
4
  const [internalCurrent, setInternalCurrent] = (0, react.useState)(initialStep);
5
- const isControlled = current !== void 0 && setCurrent !== void 0;
5
+ const isControlled = current !== void 0;
6
6
  const currentStep = isControlled ? current : internalCurrent;
7
7
  const handleSetCurrent = (0, react.useCallback)((newCurrent) => {
8
- if (isControlled) setCurrent(newCurrent);
8
+ if (isControlled) setCurrent?.(newCurrent);
9
9
  else setInternalCurrent(newCurrent);
10
10
  }, [isControlled, setCurrent]);
11
11
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"useSteps.cjs","names":["useState","useCallback"],"sources":["../../../../src/components/steps/useSteps.ts"],"sourcesContent":["import { useState, useCallback } from 'react'\n\ninterface UseStepsOptions {\n current?: number\n setCurrent?: (current: number) => void\n totalSteps: number\n initialStep?: number\n}\n\nexport const useSteps = ({\n current,\n setCurrent,\n totalSteps,\n initialStep = 0,\n}: UseStepsOptions) => {\n const [internalCurrent, setInternalCurrent] = useState(initialStep)\n\n const isControlled = current !== undefined && setCurrent !== undefined\n const currentStep = isControlled ? current : internalCurrent\n\n const handleSetCurrent = useCallback(\n (newCurrent: number) => {\n if (isControlled) {\n setCurrent!(newCurrent)\n } else {\n setInternalCurrent(newCurrent)\n }\n },\n [isControlled, setCurrent]\n )\n\n const next = useCallback(() => {\n if (currentStep < totalSteps - 1) {\n handleSetCurrent(currentStep + 1)\n }\n }, [currentStep, totalSteps, handleSetCurrent])\n\n const previous = useCallback(() => {\n if (currentStep > 0) {\n handleSetCurrent(currentStep - 1)\n }\n }, [currentStep, handleSetCurrent])\n\n const goToStep = useCallback(\n (step: number) => {\n if (step >= 0 && step < totalSteps) {\n handleSetCurrent(step)\n }\n },\n [totalSteps, handleSetCurrent]\n )\n\n const cancel = useCallback(() => {\n handleSetCurrent(initialStep)\n }, [handleSetCurrent, initialStep])\n\n return {\n next,\n previous,\n goToStep,\n cancel,\n current: currentStep,\n setCurrent: handleSetCurrent,\n canGoNext: currentStep < totalSteps - 1,\n canGoPrevious: currentStep > 0,\n }\n}\n"],"mappings":";;AASA,IAAa,YAAY,EACvB,SACA,YACA,YACA,cAAc,QACO;CACrB,MAAM,CAAC,iBAAiB,uBAAA,GAAsBA,MAAAA,SAAAA,CAAS,WAAW;CAElE,MAAM,eAAe,YAAY,KAAA,KAAa,eAAe,KAAA;CAC7D,MAAM,cAAc,eAAe,UAAU;CAE7C,MAAM,oBAAA,GAAmBC,MAAAA,YAAAA,EACtB,eAAuB;EACtB,IAAI,cACF,WAAY,UAAU;OAEtB,mBAAmB,UAAU;CAEjC,GACA,CAAC,cAAc,UAAU,CAC3B;CA2BA,OAAO;EACL,OAAA,GA1BWA,MAAAA,YAAAA,OAAkB;GAC7B,IAAI,cAAc,aAAa,GAC7B,iBAAiB,cAAc,CAAC;EAEpC,GAAG;GAAC;GAAa;GAAY;EAAgB,CAsB3C;EACA,WAAA,GArBeA,MAAAA,YAAAA,OAAkB;GACjC,IAAI,cAAc,GAChB,iBAAiB,cAAc,CAAC;EAEpC,GAAG,CAAC,aAAa,gBAAgB,CAiB/B;EACA,WAAA,GAhBeA,MAAAA,YAAAA,EACd,SAAiB;GAChB,IAAI,QAAQ,KAAK,OAAO,YACtB,iBAAiB,IAAI;EAEzB,GACA,CAAC,YAAY,gBAAgB,CAU7B;EACA,SAAA,GARaA,MAAAA,YAAAA,OAAkB;GAC/B,iBAAiB,WAAW;EAC9B,GAAG,CAAC,kBAAkB,WAAW,CAM/B;EACA,SAAS;EACT,YAAY;EACZ,WAAW,cAAc,aAAa;EACtC,eAAe,cAAc;CAC/B;AACF"}
1
+ {"version":3,"file":"useSteps.cjs","names":["useState","useCallback"],"sources":["../../../../src/components/steps/useSteps.ts"],"sourcesContent":["import { useState, useCallback } from 'react'\n\ninterface UseStepsOptions {\n current?: number\n setCurrent?: (current: number) => void\n totalSteps: number\n initialStep?: number\n}\n\nexport const useSteps = ({\n current,\n setCurrent,\n totalSteps,\n initialStep = 0,\n}: UseStepsOptions) => {\n const [internalCurrent, setInternalCurrent] = useState(initialStep)\n\n // `current` alone makes the steps controlled. Without `setCurrent` they are\n // read-only: navigation is a no-op and the parent moves `current` itself.\n const isControlled = current !== undefined\n const currentStep = isControlled ? current : internalCurrent\n\n const handleSetCurrent = useCallback(\n (newCurrent: number) => {\n if (isControlled) {\n setCurrent?.(newCurrent)\n } else {\n setInternalCurrent(newCurrent)\n }\n },\n [isControlled, setCurrent]\n )\n\n const next = useCallback(() => {\n if (currentStep < totalSteps - 1) {\n handleSetCurrent(currentStep + 1)\n }\n }, [currentStep, totalSteps, handleSetCurrent])\n\n const previous = useCallback(() => {\n if (currentStep > 0) {\n handleSetCurrent(currentStep - 1)\n }\n }, [currentStep, handleSetCurrent])\n\n const goToStep = useCallback(\n (step: number) => {\n if (step >= 0 && step < totalSteps) {\n handleSetCurrent(step)\n }\n },\n [totalSteps, handleSetCurrent]\n )\n\n const cancel = useCallback(() => {\n handleSetCurrent(initialStep)\n }, [handleSetCurrent, initialStep])\n\n return {\n next,\n previous,\n goToStep,\n cancel,\n current: currentStep,\n setCurrent: handleSetCurrent,\n canGoNext: currentStep < totalSteps - 1,\n canGoPrevious: currentStep > 0,\n }\n}\n"],"mappings":";;AASA,IAAa,YAAY,EACvB,SACA,YACA,YACA,cAAc,QACO;CACrB,MAAM,CAAC,iBAAiB,uBAAA,GAAsBA,MAAAA,SAAAA,CAAS,WAAW;CAIlE,MAAM,eAAe,YAAY,KAAA;CACjC,MAAM,cAAc,eAAe,UAAU;CAE7C,MAAM,oBAAA,GAAmBC,MAAAA,YAAAA,EACtB,eAAuB;EACtB,IAAI,cACF,aAAa,UAAU;OAEvB,mBAAmB,UAAU;CAEjC,GACA,CAAC,cAAc,UAAU,CAC3B;CA2BA,OAAO;EACL,OAAA,GA1BWA,MAAAA,YAAAA,OAAkB;GAC7B,IAAI,cAAc,aAAa,GAC7B,iBAAiB,cAAc,CAAC;EAEpC,GAAG;GAAC;GAAa;GAAY;EAAgB,CAsB3C;EACA,WAAA,GArBeA,MAAAA,YAAAA,OAAkB;GACjC,IAAI,cAAc,GAChB,iBAAiB,cAAc,CAAC;EAEpC,GAAG,CAAC,aAAa,gBAAgB,CAiB/B;EACA,WAAA,GAhBeA,MAAAA,YAAAA,EACd,SAAiB;GAChB,IAAI,QAAQ,KAAK,OAAO,YACtB,iBAAiB,IAAI;EAEzB,GACA,CAAC,YAAY,gBAAgB,CAU7B;EACA,SAAA,GARaA,MAAAA,YAAAA,OAAkB;GAC/B,iBAAiB,WAAW;EAC9B,GAAG,CAAC,kBAAkB,WAAW,CAM/B;EACA,SAAS;EACT,YAAY;EACZ,WAAW,cAAc,aAAa;EACtC,eAAe,cAAc;CAC/B;AACF"}
@@ -2,10 +2,10 @@ import { useCallback, useState } from "react";
2
2
  //#region src/components/steps/useSteps.ts
3
3
  var useSteps = ({ current, setCurrent, totalSteps, initialStep = 0 }) => {
4
4
  const [internalCurrent, setInternalCurrent] = useState(initialStep);
5
- const isControlled = current !== void 0 && setCurrent !== void 0;
5
+ const isControlled = current !== void 0;
6
6
  const currentStep = isControlled ? current : internalCurrent;
7
7
  const handleSetCurrent = useCallback((newCurrent) => {
8
- if (isControlled) setCurrent(newCurrent);
8
+ if (isControlled) setCurrent?.(newCurrent);
9
9
  else setInternalCurrent(newCurrent);
10
10
  }, [isControlled, setCurrent]);
11
11
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"useSteps.js","names":[],"sources":["../../../../src/components/steps/useSteps.ts"],"sourcesContent":["import { useState, useCallback } from 'react'\n\ninterface UseStepsOptions {\n current?: number\n setCurrent?: (current: number) => void\n totalSteps: number\n initialStep?: number\n}\n\nexport const useSteps = ({\n current,\n setCurrent,\n totalSteps,\n initialStep = 0,\n}: UseStepsOptions) => {\n const [internalCurrent, setInternalCurrent] = useState(initialStep)\n\n const isControlled = current !== undefined && setCurrent !== undefined\n const currentStep = isControlled ? current : internalCurrent\n\n const handleSetCurrent = useCallback(\n (newCurrent: number) => {\n if (isControlled) {\n setCurrent!(newCurrent)\n } else {\n setInternalCurrent(newCurrent)\n }\n },\n [isControlled, setCurrent]\n )\n\n const next = useCallback(() => {\n if (currentStep < totalSteps - 1) {\n handleSetCurrent(currentStep + 1)\n }\n }, [currentStep, totalSteps, handleSetCurrent])\n\n const previous = useCallback(() => {\n if (currentStep > 0) {\n handleSetCurrent(currentStep - 1)\n }\n }, [currentStep, handleSetCurrent])\n\n const goToStep = useCallback(\n (step: number) => {\n if (step >= 0 && step < totalSteps) {\n handleSetCurrent(step)\n }\n },\n [totalSteps, handleSetCurrent]\n )\n\n const cancel = useCallback(() => {\n handleSetCurrent(initialStep)\n }, [handleSetCurrent, initialStep])\n\n return {\n next,\n previous,\n goToStep,\n cancel,\n current: currentStep,\n setCurrent: handleSetCurrent,\n canGoNext: currentStep < totalSteps - 1,\n canGoPrevious: currentStep > 0,\n }\n}\n"],"mappings":";;AASA,IAAa,YAAY,EACvB,SACA,YACA,YACA,cAAc,QACO;CACrB,MAAM,CAAC,iBAAiB,sBAAsB,SAAS,WAAW;CAElE,MAAM,eAAe,YAAY,KAAA,KAAa,eAAe,KAAA;CAC7D,MAAM,cAAc,eAAe,UAAU;CAE7C,MAAM,mBAAmB,aACtB,eAAuB;EACtB,IAAI,cACF,WAAY,UAAU;OAEtB,mBAAmB,UAAU;CAEjC,GACA,CAAC,cAAc,UAAU,CAC3B;CA2BA,OAAO;EACL,MA1BW,kBAAkB;GAC7B,IAAI,cAAc,aAAa,GAC7B,iBAAiB,cAAc,CAAC;EAEpC,GAAG;GAAC;GAAa;GAAY;EAAgB,CAsB3C;EACA,UArBe,kBAAkB;GACjC,IAAI,cAAc,GAChB,iBAAiB,cAAc,CAAC;EAEpC,GAAG,CAAC,aAAa,gBAAgB,CAiB/B;EACA,UAhBe,aACd,SAAiB;GAChB,IAAI,QAAQ,KAAK,OAAO,YACtB,iBAAiB,IAAI;EAEzB,GACA,CAAC,YAAY,gBAAgB,CAU7B;EACA,QARa,kBAAkB;GAC/B,iBAAiB,WAAW;EAC9B,GAAG,CAAC,kBAAkB,WAAW,CAM/B;EACA,SAAS;EACT,YAAY;EACZ,WAAW,cAAc,aAAa;EACtC,eAAe,cAAc;CAC/B;AACF"}
1
+ {"version":3,"file":"useSteps.js","names":[],"sources":["../../../../src/components/steps/useSteps.ts"],"sourcesContent":["import { useState, useCallback } from 'react'\n\ninterface UseStepsOptions {\n current?: number\n setCurrent?: (current: number) => void\n totalSteps: number\n initialStep?: number\n}\n\nexport const useSteps = ({\n current,\n setCurrent,\n totalSteps,\n initialStep = 0,\n}: UseStepsOptions) => {\n const [internalCurrent, setInternalCurrent] = useState(initialStep)\n\n // `current` alone makes the steps controlled. Without `setCurrent` they are\n // read-only: navigation is a no-op and the parent moves `current` itself.\n const isControlled = current !== undefined\n const currentStep = isControlled ? current : internalCurrent\n\n const handleSetCurrent = useCallback(\n (newCurrent: number) => {\n if (isControlled) {\n setCurrent?.(newCurrent)\n } else {\n setInternalCurrent(newCurrent)\n }\n },\n [isControlled, setCurrent]\n )\n\n const next = useCallback(() => {\n if (currentStep < totalSteps - 1) {\n handleSetCurrent(currentStep + 1)\n }\n }, [currentStep, totalSteps, handleSetCurrent])\n\n const previous = useCallback(() => {\n if (currentStep > 0) {\n handleSetCurrent(currentStep - 1)\n }\n }, [currentStep, handleSetCurrent])\n\n const goToStep = useCallback(\n (step: number) => {\n if (step >= 0 && step < totalSteps) {\n handleSetCurrent(step)\n }\n },\n [totalSteps, handleSetCurrent]\n )\n\n const cancel = useCallback(() => {\n handleSetCurrent(initialStep)\n }, [handleSetCurrent, initialStep])\n\n return {\n next,\n previous,\n goToStep,\n cancel,\n current: currentStep,\n setCurrent: handleSetCurrent,\n canGoNext: currentStep < totalSteps - 1,\n canGoPrevious: currentStep > 0,\n }\n}\n"],"mappings":";;AASA,IAAa,YAAY,EACvB,SACA,YACA,YACA,cAAc,QACO;CACrB,MAAM,CAAC,iBAAiB,sBAAsB,SAAS,WAAW;CAIlE,MAAM,eAAe,YAAY,KAAA;CACjC,MAAM,cAAc,eAAe,UAAU;CAE7C,MAAM,mBAAmB,aACtB,eAAuB;EACtB,IAAI,cACF,aAAa,UAAU;OAEvB,mBAAmB,UAAU;CAEjC,GACA,CAAC,cAAc,UAAU,CAC3B;CA2BA,OAAO;EACL,MA1BW,kBAAkB;GAC7B,IAAI,cAAc,aAAa,GAC7B,iBAAiB,cAAc,CAAC;EAEpC,GAAG;GAAC;GAAa;GAAY;EAAgB,CAsB3C;EACA,UArBe,kBAAkB;GACjC,IAAI,cAAc,GAChB,iBAAiB,cAAc,CAAC;EAEpC,GAAG,CAAC,aAAa,gBAAgB,CAiB/B;EACA,UAhBe,aACd,SAAiB;GAChB,IAAI,QAAQ,KAAK,OAAO,YACtB,iBAAiB,IAAI;EAEzB,GACA,CAAC,YAAY,gBAAgB,CAU7B;EACA,QARa,kBAAkB;GAC/B,iBAAiB,WAAW;EAC9B,GAAG,CAAC,kBAAkB,WAAW,CAM/B;EACA,SAAS;EACT,YAAY;EACZ,WAAW,cAAc,aAAa;EACtC,eAAe,cAAc;CAC/B;AACF"}
@@ -4,25 +4,30 @@ let classnames = require("classnames");
4
4
  classnames = require_runtime.__toESM(classnames, 1);
5
5
  //#region src/components/swatch/Swatch.tsx
6
6
  /**
7
- * A small color square for keys, legends and inline indicators.
7
+ * A small color square for keys, legends and inline indicators. Other span
8
+ * attributes land on the square, e.g. `role="img"` and an `aria-label` for
9
+ * one shown on its own.
8
10
  */
9
- var Swatch = ({ color = "var(--j2-color-primary)", variant = "solid", tint, stroke, size = 16, radius = 4, className }) => {
10
- const style = {
11
+ var Swatch = ({ color = "var(--j2-color-primary)", variant = "solid", tint, stroke, size = 16, radius = 4, className, style, ...props }) => {
12
+ const box = {
13
+ ...style,
11
14
  width: size,
12
15
  height: size,
13
16
  borderRadius: radius
14
17
  };
15
18
  if (variant === "solid") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
19
+ ...props,
16
20
  className: (0, classnames.default)("block shrink-0", className),
17
21
  style: {
18
- ...style,
22
+ ...box,
19
23
  background: color
20
24
  }
21
25
  });
22
26
  if (variant === "hatched") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
27
+ ...props,
23
28
  className: (0, classnames.default)("block shrink-0 overflow-hidden border", className),
24
29
  style: {
25
- ...style,
30
+ ...box,
26
31
  borderColor: color,
27
32
  background: tint ?? `color-mix(in srgb, ${color} 10%, white)`
28
33
  },
@@ -40,8 +45,9 @@ var Swatch = ({ color = "var(--j2-color-primary)", variant = "solid", tint, stro
40
45
  })
41
46
  });
42
47
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
48
+ ...props,
43
49
  className: (0, classnames.default)("block shrink-0 border border-j2-border bg-white", className),
44
- style
50
+ style: box
45
51
  });
46
52
  };
47
53
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"Swatch.cjs","names":["cx"],"sources":["../../../../src/components/swatch/Swatch.tsx"],"sourcesContent":["import cx from 'classnames'\n\nexport type SwatchProps = {\n /** Any CSS color, e.g. `'var(--j2-color-interval-7-7)'`. */\n color?: string\n /**\n * - `'solid'`: filled with `color`.\n * - `'hatched'`: a light fill, a `color` border and a diagonal stroke. For\n * a softer version of the same meaning as solid.\n * - `'outline'`: an empty square with a neutral border. For \"none\".\n */\n variant?: 'solid' | 'hatched' | 'outline'\n /** The hatched variant's light fill. Defaults to `color` at 10%. */\n tint?: string\n /** The hatched variant's stroke. Defaults to `color`. */\n stroke?: string\n /** Side in px. */\n size?: number\n /** Corner radius in px. */\n radius?: number\n className?: string\n}\n\n/**\n * A small color square for keys, legends and inline indicators.\n */\nexport const Swatch = ({\n color = 'var(--j2-color-primary)',\n variant = 'solid',\n tint,\n stroke,\n size = 16,\n radius = 4,\n className,\n}: SwatchProps) => {\n const style: React.CSSProperties = {\n width: size,\n height: size,\n borderRadius: radius,\n }\n\n if (variant === 'solid') {\n return (\n <span\n className={cx('block shrink-0', className)}\n style={{ ...style, background: color }}\n />\n )\n }\n\n if (variant === 'hatched') {\n return (\n <span\n className={cx('block shrink-0 overflow-hidden border', className)}\n style={{\n ...style,\n borderColor: color,\n background: tint ?? `color-mix(in srgb, ${color} 10%, white)`,\n }}\n >\n <svg viewBox=\"0 0 16 16\" className=\"block h-full w-full\">\n <line\n x1=\"0\"\n y1=\"16\"\n x2=\"16\"\n y2=\"0\"\n stroke={stroke ?? color}\n strokeWidth=\"1.5\"\n />\n </svg>\n </span>\n )\n }\n\n return (\n <span\n className={cx(\n 'block shrink-0 border border-j2-border bg-white',\n className\n )}\n style={style}\n />\n )\n}\n"],"mappings":";;;;;;;;AA0BA,IAAa,UAAU,EACrB,QAAQ,2BACR,UAAU,SACV,MACA,QACA,OAAO,IACP,SAAS,GACT,gBACiB;CACjB,MAAM,QAA6B;EACjC,OAAO;EACP,QAAQ;EACR,cAAc;CAChB;CAEA,IAAI,YAAY,SACd,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;EACE,YAAA,GAAWA,WAAAA,QAAAA,CAAG,kBAAkB,SAAS;EACzC,OAAO;GAAE,GAAG;GAAO,YAAY;EAAM;CACtC,CAAA;CAIL,IAAI,YAAY,WACd,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;EACE,YAAA,GAAWA,WAAAA,QAAAA,CAAG,yCAAyC,SAAS;EAChE,OAAO;GACL,GAAG;GACH,aAAa;GACb,YAAY,QAAQ,sBAAsB,MAAM;EAClD;EAEA,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;GAAK,SAAQ;GAAY,WAAU;GACjC,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;IACE,IAAG;IACH,IAAG;IACH,IAAG;IACH,IAAG;IACH,QAAQ,UAAU;IAClB,aAAY;GACb,CAAA;EACE,CAAA;CACD,CAAA;CAIV,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;EACE,YAAA,GAAWA,WAAAA,QAAAA,CACT,mDACA,SACF;EACO;CACR,CAAA;AAEL"}
1
+ {"version":3,"file":"Swatch.cjs","names":["cx"],"sources":["../../../../src/components/swatch/Swatch.tsx"],"sourcesContent":["import cx from 'classnames'\n\n/**\n * How a swatch looks. Other components take this for a nested `swatch` prop,\n * where span attributes would land on the wrong element.\n */\nexport type SwatchVisualProps = {\n /** Any CSS color, e.g. `'var(--j2-color-interval-7-7)'`. */\n color?: string\n /**\n * - `'solid'`: filled with `color`.\n * - `'hatched'`: a light fill, a `color` border and a diagonal stroke. For\n * a softer version of the same meaning as solid.\n * - `'outline'`: an empty square with a neutral border. For \"none\".\n */\n variant?: 'solid' | 'hatched' | 'outline'\n /** The hatched variant's light fill. Defaults to `color` at 10%. */\n tint?: string\n /** The hatched variant's stroke. Defaults to `color`. */\n stroke?: string\n /** Side in px. */\n size?: number\n /** Corner radius in px. */\n radius?: number\n className?: string\n}\n\nexport type SwatchProps = SwatchVisualProps &\n Omit<React.HTMLAttributes<HTMLSpanElement>, 'color'>\n\n/**\n * A small color square for keys, legends and inline indicators. Other span\n * attributes land on the square, e.g. `role=\"img\"` and an `aria-label` for\n * one shown on its own.\n */\nexport const Swatch = ({\n color = 'var(--j2-color-primary)',\n variant = 'solid',\n tint,\n stroke,\n size = 16,\n radius = 4,\n className,\n style,\n ...props\n}: SwatchProps) => {\n const box: React.CSSProperties = {\n ...style,\n width: size,\n height: size,\n borderRadius: radius,\n }\n\n if (variant === 'solid') {\n return (\n <span\n {...props}\n className={cx('block shrink-0', className)}\n style={{ ...box, background: color }}\n />\n )\n }\n\n if (variant === 'hatched') {\n return (\n <span\n {...props}\n className={cx('block shrink-0 overflow-hidden border', className)}\n style={{\n ...box,\n borderColor: color,\n background: tint ?? `color-mix(in srgb, ${color} 10%, white)`,\n }}\n >\n <svg viewBox=\"0 0 16 16\" className=\"block h-full w-full\">\n <line\n x1=\"0\"\n y1=\"16\"\n x2=\"16\"\n y2=\"0\"\n stroke={stroke ?? color}\n strokeWidth=\"1.5\"\n />\n </svg>\n </span>\n )\n }\n\n return (\n <span\n {...props}\n className={cx(\n 'block shrink-0 border border-j2-border bg-white',\n className\n )}\n style={box}\n />\n )\n}\n"],"mappings":";;;;;;;;;;AAmCA,IAAa,UAAU,EACrB,QAAQ,2BACR,UAAU,SACV,MACA,QACA,OAAO,IACP,SAAS,GACT,WACA,OACA,GAAG,YACc;CACjB,MAAM,MAA2B;EAC/B,GAAG;EACH,OAAO;EACP,QAAQ;EACR,cAAc;CAChB;CAEA,IAAI,YAAY,SACd,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;EACE,GAAI;EACJ,YAAA,GAAWA,WAAAA,QAAAA,CAAG,kBAAkB,SAAS;EACzC,OAAO;GAAE,GAAG;GAAK,YAAY;EAAM;CACpC,CAAA;CAIL,IAAI,YAAY,WACd,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;EACE,GAAI;EACJ,YAAA,GAAWA,WAAAA,QAAAA,CAAG,yCAAyC,SAAS;EAChE,OAAO;GACL,GAAG;GACH,aAAa;GACb,YAAY,QAAQ,sBAAsB,MAAM;EAClD;EAEA,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;GAAK,SAAQ;GAAY,WAAU;GACjC,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;IACE,IAAG;IACH,IAAG;IACH,IAAG;IACH,IAAG;IACH,QAAQ,UAAU;IAClB,aAAY;GACb,CAAA;EACE,CAAA;CACD,CAAA;CAIV,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;EACE,GAAI;EACJ,YAAA,GAAWA,WAAAA,QAAAA,CACT,mDACA,SACF;EACA,OAAO;CACR,CAAA;AAEL"}
@@ -1,4 +1,8 @@
1
- export type SwatchProps = {
1
+ /**
2
+ * How a swatch looks. Other components take this for a nested `swatch` prop,
3
+ * where span attributes would land on the wrong element.
4
+ */
5
+ export type SwatchVisualProps = {
2
6
  /** Any CSS color, e.g. `'var(--j2-color-interval-7-7)'`. */
3
7
  color?: string;
4
8
  /**
@@ -18,7 +22,10 @@ export type SwatchProps = {
18
22
  radius?: number;
19
23
  className?: string;
20
24
  };
25
+ export type SwatchProps = SwatchVisualProps & Omit<React.HTMLAttributes<HTMLSpanElement>, 'color'>;
21
26
  /**
22
- * A small color square for keys, legends and inline indicators.
27
+ * A small color square for keys, legends and inline indicators. Other span
28
+ * attributes land on the square, e.g. `role="img"` and an `aria-label` for
29
+ * one shown on its own.
23
30
  */
24
- export declare const Swatch: ({ color, variant, tint, stroke, size, radius, className, }: SwatchProps) => import('react').JSX.Element;
31
+ export declare const Swatch: ({ color, variant, tint, stroke, size, radius, className, style, ...props }: SwatchProps) => import('react').JSX.Element;
@@ -2,25 +2,30 @@ import { jsx } from "react/jsx-runtime";
2
2
  import cx from "classnames";
3
3
  //#region src/components/swatch/Swatch.tsx
4
4
  /**
5
- * A small color square for keys, legends and inline indicators.
5
+ * A small color square for keys, legends and inline indicators. Other span
6
+ * attributes land on the square, e.g. `role="img"` and an `aria-label` for
7
+ * one shown on its own.
6
8
  */
7
- var Swatch = ({ color = "var(--j2-color-primary)", variant = "solid", tint, stroke, size = 16, radius = 4, className }) => {
8
- const style = {
9
+ var Swatch = ({ color = "var(--j2-color-primary)", variant = "solid", tint, stroke, size = 16, radius = 4, className, style, ...props }) => {
10
+ const box = {
11
+ ...style,
9
12
  width: size,
10
13
  height: size,
11
14
  borderRadius: radius
12
15
  };
13
16
  if (variant === "solid") return /* @__PURE__ */ jsx("span", {
17
+ ...props,
14
18
  className: cx("block shrink-0", className),
15
19
  style: {
16
- ...style,
20
+ ...box,
17
21
  background: color
18
22
  }
19
23
  });
20
24
  if (variant === "hatched") return /* @__PURE__ */ jsx("span", {
25
+ ...props,
21
26
  className: cx("block shrink-0 overflow-hidden border", className),
22
27
  style: {
23
- ...style,
28
+ ...box,
24
29
  borderColor: color,
25
30
  background: tint ?? `color-mix(in srgb, ${color} 10%, white)`
26
31
  },
@@ -38,8 +43,9 @@ var Swatch = ({ color = "var(--j2-color-primary)", variant = "solid", tint, stro
38
43
  })
39
44
  });
40
45
  return /* @__PURE__ */ jsx("span", {
46
+ ...props,
41
47
  className: cx("block shrink-0 border border-j2-border bg-white", className),
42
- style
48
+ style: box
43
49
  });
44
50
  };
45
51
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"Swatch.js","names":[],"sources":["../../../../src/components/swatch/Swatch.tsx"],"sourcesContent":["import cx from 'classnames'\n\nexport type SwatchProps = {\n /** Any CSS color, e.g. `'var(--j2-color-interval-7-7)'`. */\n color?: string\n /**\n * - `'solid'`: filled with `color`.\n * - `'hatched'`: a light fill, a `color` border and a diagonal stroke. For\n * a softer version of the same meaning as solid.\n * - `'outline'`: an empty square with a neutral border. For \"none\".\n */\n variant?: 'solid' | 'hatched' | 'outline'\n /** The hatched variant's light fill. Defaults to `color` at 10%. */\n tint?: string\n /** The hatched variant's stroke. Defaults to `color`. */\n stroke?: string\n /** Side in px. */\n size?: number\n /** Corner radius in px. */\n radius?: number\n className?: string\n}\n\n/**\n * A small color square for keys, legends and inline indicators.\n */\nexport const Swatch = ({\n color = 'var(--j2-color-primary)',\n variant = 'solid',\n tint,\n stroke,\n size = 16,\n radius = 4,\n className,\n}: SwatchProps) => {\n const style: React.CSSProperties = {\n width: size,\n height: size,\n borderRadius: radius,\n }\n\n if (variant === 'solid') {\n return (\n <span\n className={cx('block shrink-0', className)}\n style={{ ...style, background: color }}\n />\n )\n }\n\n if (variant === 'hatched') {\n return (\n <span\n className={cx('block shrink-0 overflow-hidden border', className)}\n style={{\n ...style,\n borderColor: color,\n background: tint ?? `color-mix(in srgb, ${color} 10%, white)`,\n }}\n >\n <svg viewBox=\"0 0 16 16\" className=\"block h-full w-full\">\n <line\n x1=\"0\"\n y1=\"16\"\n x2=\"16\"\n y2=\"0\"\n stroke={stroke ?? color}\n strokeWidth=\"1.5\"\n />\n </svg>\n </span>\n )\n }\n\n return (\n <span\n className={cx(\n 'block shrink-0 border border-j2-border bg-white',\n className\n )}\n style={style}\n />\n )\n}\n"],"mappings":";;;;;;AA0BA,IAAa,UAAU,EACrB,QAAQ,2BACR,UAAU,SACV,MACA,QACA,OAAO,IACP,SAAS,GACT,gBACiB;CACjB,MAAM,QAA6B;EACjC,OAAO;EACP,QAAQ;EACR,cAAc;CAChB;CAEA,IAAI,YAAY,SACd,OACE,oBAAC,QAAD;EACE,WAAW,GAAG,kBAAkB,SAAS;EACzC,OAAO;GAAE,GAAG;GAAO,YAAY;EAAM;CACtC,CAAA;CAIL,IAAI,YAAY,WACd,OACE,oBAAC,QAAD;EACE,WAAW,GAAG,yCAAyC,SAAS;EAChE,OAAO;GACL,GAAG;GACH,aAAa;GACb,YAAY,QAAQ,sBAAsB,MAAM;EAClD;EAEA,UAAA,oBAAC,OAAD;GAAK,SAAQ;GAAY,WAAU;GACjC,UAAA,oBAAC,QAAD;IACE,IAAG;IACH,IAAG;IACH,IAAG;IACH,IAAG;IACH,QAAQ,UAAU;IAClB,aAAY;GACb,CAAA;EACE,CAAA;CACD,CAAA;CAIV,OACE,oBAAC,QAAD;EACE,WAAW,GACT,mDACA,SACF;EACO;CACR,CAAA;AAEL"}
1
+ {"version":3,"file":"Swatch.js","names":[],"sources":["../../../../src/components/swatch/Swatch.tsx"],"sourcesContent":["import cx from 'classnames'\n\n/**\n * How a swatch looks. Other components take this for a nested `swatch` prop,\n * where span attributes would land on the wrong element.\n */\nexport type SwatchVisualProps = {\n /** Any CSS color, e.g. `'var(--j2-color-interval-7-7)'`. */\n color?: string\n /**\n * - `'solid'`: filled with `color`.\n * - `'hatched'`: a light fill, a `color` border and a diagonal stroke. For\n * a softer version of the same meaning as solid.\n * - `'outline'`: an empty square with a neutral border. For \"none\".\n */\n variant?: 'solid' | 'hatched' | 'outline'\n /** The hatched variant's light fill. Defaults to `color` at 10%. */\n tint?: string\n /** The hatched variant's stroke. Defaults to `color`. */\n stroke?: string\n /** Side in px. */\n size?: number\n /** Corner radius in px. */\n radius?: number\n className?: string\n}\n\nexport type SwatchProps = SwatchVisualProps &\n Omit<React.HTMLAttributes<HTMLSpanElement>, 'color'>\n\n/**\n * A small color square for keys, legends and inline indicators. Other span\n * attributes land on the square, e.g. `role=\"img\"` and an `aria-label` for\n * one shown on its own.\n */\nexport const Swatch = ({\n color = 'var(--j2-color-primary)',\n variant = 'solid',\n tint,\n stroke,\n size = 16,\n radius = 4,\n className,\n style,\n ...props\n}: SwatchProps) => {\n const box: React.CSSProperties = {\n ...style,\n width: size,\n height: size,\n borderRadius: radius,\n }\n\n if (variant === 'solid') {\n return (\n <span\n {...props}\n className={cx('block shrink-0', className)}\n style={{ ...box, background: color }}\n />\n )\n }\n\n if (variant === 'hatched') {\n return (\n <span\n {...props}\n className={cx('block shrink-0 overflow-hidden border', className)}\n style={{\n ...box,\n borderColor: color,\n background: tint ?? `color-mix(in srgb, ${color} 10%, white)`,\n }}\n >\n <svg viewBox=\"0 0 16 16\" className=\"block h-full w-full\">\n <line\n x1=\"0\"\n y1=\"16\"\n x2=\"16\"\n y2=\"0\"\n stroke={stroke ?? color}\n strokeWidth=\"1.5\"\n />\n </svg>\n </span>\n )\n }\n\n return (\n <span\n {...props}\n className={cx(\n 'block shrink-0 border border-j2-border bg-white',\n className\n )}\n style={box}\n />\n )\n}\n"],"mappings":";;;;;;;;AAmCA,IAAa,UAAU,EACrB,QAAQ,2BACR,UAAU,SACV,MACA,QACA,OAAO,IACP,SAAS,GACT,WACA,OACA,GAAG,YACc;CACjB,MAAM,MAA2B;EAC/B,GAAG;EACH,OAAO;EACP,QAAQ;EACR,cAAc;CAChB;CAEA,IAAI,YAAY,SACd,OACE,oBAAC,QAAD;EACE,GAAI;EACJ,WAAW,GAAG,kBAAkB,SAAS;EACzC,OAAO;GAAE,GAAG;GAAK,YAAY;EAAM;CACpC,CAAA;CAIL,IAAI,YAAY,WACd,OACE,oBAAC,QAAD;EACE,GAAI;EACJ,WAAW,GAAG,yCAAyC,SAAS;EAChE,OAAO;GACL,GAAG;GACH,aAAa;GACb,YAAY,QAAQ,sBAAsB,MAAM;EAClD;EAEA,UAAA,oBAAC,OAAD;GAAK,SAAQ;GAAY,WAAU;GACjC,UAAA,oBAAC,QAAD;IACE,IAAG;IACH,IAAG;IACH,IAAG;IACH,IAAG;IACH,QAAQ,UAAU;IAClB,aAAY;GACb,CAAA;EACE,CAAA;CACD,CAAA;CAIV,OACE,oBAAC,QAAD;EACE,GAAI;EACJ,WAAW,GACT,mDACA,SACF;EACA,OAAO;CACR,CAAA;AAEL"}
@@ -1 +1 @@
1
- export { Swatch, type SwatchProps } from './Swatch.js';
1
+ export { Swatch, type SwatchProps, type SwatchVisualProps } from './Swatch.js';