@asanchez-sa/abby 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/components/alert/alert.d.ts +1 -1
  2. package/dist/components/alert/alert.js +2 -1
  3. package/dist/components/alert-dialog/alert-dialog.d.ts +10 -1
  4. package/dist/components/alert-dialog/alert-dialog.js +80 -3
  5. package/dist/components/badge/badge.d.ts +3 -2
  6. package/dist/components/badge/badge.js +27 -11
  7. package/dist/components/button/button.d.ts +1 -1
  8. package/dist/components/button/button.js +3 -2
  9. package/dist/components/calendar/calendar.d.ts +26 -5
  10. package/dist/components/calendar/calendar.js +387 -72
  11. package/dist/components/chart/chart.d.ts +76 -0
  12. package/dist/components/chart/chart.js +565 -0
  13. package/dist/components/chart/parts/axes.js +126 -0
  14. package/dist/components/chart/parts/frame.d.ts +31 -0
  15. package/dist/components/chart/parts/frame.js +278 -0
  16. package/dist/components/chart/parts/legend.d.ts +16 -0
  17. package/dist/components/chart/parts/legend.js +82 -0
  18. package/dist/components/chart/parts/points.d.ts +1 -0
  19. package/dist/components/chart/parts/points.js +139 -0
  20. package/dist/components/chart/parts/scale.js +139 -0
  21. package/dist/components/chart/parts/table.js +105 -0
  22. package/dist/components/chart/parts/types.d.ts +44 -0
  23. package/dist/components/chart/parts/types.js +8 -0
  24. package/dist/components/dialog/dialog.d.ts +9 -1
  25. package/dist/components/dialog/dialog.js +82 -3
  26. package/dist/components/field/field.d.ts +5 -1
  27. package/dist/components/field/field.js +25 -21
  28. package/dist/components/filter-chip/filter-chip.d.ts +36 -0
  29. package/dist/components/filter-chip/filter-chip.js +97 -0
  30. package/dist/components/graph/graph.d.ts +151 -0
  31. package/dist/components/graph/graph.js +959 -0
  32. package/dist/components/input/input.d.ts +8 -1
  33. package/dist/components/input/input.js +2 -2
  34. package/dist/components/meter/meter.d.ts +52 -3
  35. package/dist/components/meter/meter.js +535 -33
  36. package/dist/components/model-selector/model-selector.d.ts +38 -3
  37. package/dist/components/model-selector/model-selector.js +331 -73
  38. package/dist/components/note-editor/parts/suggestions.js +2 -2
  39. package/dist/components/number-input/number-input.d.ts +14 -3
  40. package/dist/components/number-input/number-input.js +193 -34
  41. package/dist/components/otp-input/otp-input.d.ts +6 -2
  42. package/dist/components/otp-input/otp-input.js +40 -20
  43. package/dist/components/sheet/sheet.js +1 -1
  44. package/dist/components/spinner/spinner.d.ts +7 -1
  45. package/dist/components/spinner/spinner.js +86 -26
  46. package/dist/components/switch/switch.d.ts +9 -2
  47. package/dist/components/switch/switch.js +23 -17
  48. package/dist/components/toast/toast.d.ts +19 -2
  49. package/dist/components/toast/toast.js +211 -49
  50. package/dist/components/toggle/toggle.d.ts +18 -4
  51. package/dist/components/toggle/toggle.js +167 -32
  52. package/dist/components/week-strip/week-strip.d.ts +27 -5
  53. package/dist/components/week-strip/week-strip.js +288 -134
  54. package/package.json +4 -1
  55. package/skills/agent-ready-ui/SKILL.md +1 -1
  56. package/skills/blocks/SKILL.md +1 -1
  57. package/skills/compose-screens/SKILL.md +97 -10
  58. package/skills/compose-screens/references/calendar-week.md +77 -0
  59. package/skills/compose-screens/references/charts-and-maps.md +183 -0
  60. package/skills/compose-screens/references/filter-chips.md +61 -0
  61. package/skills/compose-screens/references/number-units.md +52 -0
  62. package/skills/note-editor/SKILL.md +1 -1
  63. package/skills/note-status/SKILL.md +1 -1
  64. package/skills/setup/SKILL.md +1 -1
  65. package/skills/theming/SKILL.md +1 -1
@@ -0,0 +1,105 @@
1
+ "use client";
2
+ import { stackTotal } from "./scale.js";
3
+ import { c } from "react/compiler-runtime";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ // src/components/chart/parts/table.tsx
6
+ /**
7
+ * The same data as a table, hidden from sight: categories down, series across.
8
+ * The bars give each value one at a time; this is how a screen reader reads
9
+ * the whole chart. It has one row per category, whatever the data holds.
10
+ */
11
+ function ChartTable(t0) {
12
+ const $ = c(27);
13
+ const { rows, series, categoryHeader, missing, format, name, totalHeader } = t0;
14
+ let t1;
15
+ if ($[0] !== categoryHeader) {
16
+ t1 = /* @__PURE__ */ jsx("th", {
17
+ scope: "col",
18
+ children: categoryHeader
19
+ });
20
+ $[0] = categoryHeader;
21
+ $[1] = t1;
22
+ } else t1 = $[1];
23
+ let t2;
24
+ if ($[2] !== series) {
25
+ t2 = series.map(_temp);
26
+ $[2] = series;
27
+ $[3] = t2;
28
+ } else t2 = $[3];
29
+ let t3;
30
+ if ($[4] !== totalHeader) {
31
+ t3 = totalHeader === void 0 ? null : /* @__PURE__ */ jsx("th", {
32
+ scope: "col",
33
+ children: totalHeader
34
+ });
35
+ $[4] = totalHeader;
36
+ $[5] = t3;
37
+ } else t3 = $[5];
38
+ let t4;
39
+ if ($[6] !== t1 || $[7] !== t2 || $[8] !== t3) {
40
+ t4 = /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
41
+ t1,
42
+ t2,
43
+ t3
44
+ ] }) });
45
+ $[6] = t1;
46
+ $[7] = t2;
47
+ $[8] = t3;
48
+ $[9] = t4;
49
+ } else t4 = $[9];
50
+ let t5;
51
+ if ($[10] !== format || $[11] !== missing || $[12] !== rows || $[13] !== series || $[14] !== totalHeader) {
52
+ let t6;
53
+ if ($[16] !== format || $[17] !== missing || $[18] !== series || $[19] !== totalHeader) {
54
+ t6 = (row, index) => /* @__PURE__ */ jsxs("tr", { children: [
55
+ /* @__PURE__ */ jsx("th", {
56
+ scope: "row",
57
+ children: row.label
58
+ }),
59
+ series.map((each_0) => /* @__PURE__ */ jsx("td", { children: format(row.values[each_0.key], missing) }, each_0.key)),
60
+ totalHeader === void 0 ? null : /* @__PURE__ */ jsx("td", { children: format(stackTotal(row, series), missing) })
61
+ ] }, `${row.id ?? row.label}-${index}`);
62
+ $[16] = format;
63
+ $[17] = missing;
64
+ $[18] = series;
65
+ $[19] = totalHeader;
66
+ $[20] = t6;
67
+ } else t6 = $[20];
68
+ t5 = rows.map(t6);
69
+ $[10] = format;
70
+ $[11] = missing;
71
+ $[12] = rows;
72
+ $[13] = series;
73
+ $[14] = totalHeader;
74
+ $[15] = t5;
75
+ } else t5 = $[15];
76
+ let t6;
77
+ if ($[21] !== t5) {
78
+ t6 = /* @__PURE__ */ jsx("tbody", { children: t5 });
79
+ $[21] = t5;
80
+ $[22] = t6;
81
+ } else t6 = $[22];
82
+ let t7;
83
+ if ($[23] !== name || $[24] !== t4 || $[25] !== t6) {
84
+ t7 = /* @__PURE__ */ jsx("div", {
85
+ "data-slot": "chart-table",
86
+ className: "sr-only",
87
+ children: /* @__PURE__ */ jsxs("table", {
88
+ ...name,
89
+ children: [t4, t6]
90
+ })
91
+ });
92
+ $[23] = name;
93
+ $[24] = t4;
94
+ $[25] = t6;
95
+ $[26] = t7;
96
+ } else t7 = $[26];
97
+ return t7;
98
+ }
99
+ function _temp(each) {
100
+ return /* @__PURE__ */ jsx("th", {
101
+ scope: "col",
102
+ children: each.name
103
+ }, each.key);
104
+ }
105
+ export { ChartTable };
@@ -0,0 +1,44 @@
1
+ /** A theme color token a series can take by name. */
2
+ export type ChartToken = "chart-1" | "chart-2" | "chart-3" | "chart-4" | "chart-5" | "primary" | "muted" | "warning" | "success" | "destructive";
3
+ /** A token, or any CSS color the app passes (an area's color, `var(--area)`). */
4
+ export type ChartColor = ChartToken | (string & {});
5
+ export type ChartSeries = {
6
+ /** The key of this series' value in each row's `values`. */
7
+ key: string;
8
+ /** The name read in the tooltip, the table and the screen reader. */
9
+ name: string;
10
+ /** Defaults to `chart-1` … `chart-5`, in the order of `series`. */
11
+ color?: ChartColor;
12
+ /**
13
+ * `forecast` draws what hasn't happened yet: a dashed outline over a faint
14
+ * fill. It shares the column of the first series instead of taking one.
15
+ */
16
+ variant?: "default" | "forecast";
17
+ };
18
+ export type ChartRow = {
19
+ /** The category's text: the x label, and the start of a bar's name. */
20
+ label: string;
21
+ /** Identifies the category for `highlight`. Defaults to `label`. */
22
+ id?: string;
23
+ /** One value per series key. A missing or `null` value draws no bar. */
24
+ values: Record<string, number | null | undefined>;
25
+ };
26
+ /** A chart is named by one of these, and it's required. */
27
+ export type ChartName = {
28
+ "aria-label": string;
29
+ "aria-labelledby"?: undefined;
30
+ } | {
31
+ "aria-label"?: undefined;
32
+ "aria-labelledby": string;
33
+ };
34
+ /** The texts a chart shows when the app doesn't replace them. */
35
+ export type ChartTexts = {
36
+ /** Shown instead of the plot when `data` is empty. */
37
+ empty?: string;
38
+ /** The header of the table's first column. */
39
+ categoryHeader?: string;
40
+ /** What the table shows for a value that is missing. */
41
+ missing?: string;
42
+ /** The header of the table's total column, when the bars are stacked. */
43
+ totalHeader?: string;
44
+ };
@@ -0,0 +1,8 @@
1
+ // src/components/chart/parts/types.ts
2
+ const defaultTexts = {
3
+ empty: "No data",
4
+ categoryHeader: "Category",
5
+ missing: "No value",
6
+ totalHeader: "Total"
7
+ };
8
+ export { defaultTexts };
@@ -1,3 +1,4 @@
1
+ import { VariantProps } from "../../utilities/cn/index.js";
1
2
  import { ButtonLook } from "../button/button.js";
2
3
  import { ComponentProps } from "react";
3
4
  import { DialogBackdrop as DialogBackdrop$1, DialogClose as DialogClose$1, DialogContent as DialogContent$1, DialogDescription as DialogDescription$1, DialogProps, DialogShortcut as DialogShortcut$1, DialogTitle as DialogTitle$1, DialogTrigger as DialogTrigger$1, createDialogController } from "@ui-sdk/react/dialog";
@@ -6,9 +7,16 @@ type DialogTriggerProps = ComponentProps<typeof DialogTrigger$1> & ButtonLook;
6
7
  declare function DialogTrigger({ variant, size, className, ...props }: DialogTriggerProps): import("react").JSX.Element;
7
8
  declare function DialogBackdrop({ className, ...props }: ComponentProps<typeof DialogBackdrop$1>): import("react").JSX.Element;
8
9
  declare function DialogContent({ className, ...props }: ComponentProps<typeof DialogContent$1>): import("react").JSX.Element;
10
+ /** The title and description, stacked 6px apart as in Alma's dialogs. */
11
+ declare function DialogHeader({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
12
+ declare const dialogFooterVariants: (props?: ({
13
+ variant?: "default" | "inline" | null | undefined;
14
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
15
+ type DialogFooterProps = ComponentProps<"div"> & VariantProps<typeof dialogFooterVariants>;
16
+ declare function DialogFooter({ className, variant, ...props }: DialogFooterProps): import("react").JSX.Element;
9
17
  declare function DialogTitle({ className, ...props }: ComponentProps<typeof DialogTitle$1>): import("react").JSX.Element;
10
18
  declare function DialogDescription({ className, ...props }: ComponentProps<typeof DialogDescription$1>): import("react").JSX.Element;
11
19
  type DialogCloseProps = ComponentProps<typeof DialogClose$1> & ButtonLook;
12
20
  declare function DialogClose({ variant, size, className, ...props }: DialogCloseProps): import("react").JSX.Element;
13
21
  declare function DialogShortcut({ className, ...props }: ComponentProps<typeof DialogShortcut$1>): import("react").JSX.Element;
14
- export { Dialog, DialogBackdrop, DialogClose, type DialogCloseProps, DialogContent, DialogDescription, type DialogProps, DialogShortcut, DialogTitle, DialogTrigger, type DialogTriggerProps, createDialogController };
22
+ export { Dialog, DialogBackdrop, DialogClose, type DialogCloseProps, DialogContent, DialogDescription, DialogFooter, type DialogFooterProps, DialogHeader, type DialogProps, DialogShortcut, DialogTitle, DialogTrigger, type DialogTriggerProps, createDialogController, dialogFooterVariants };
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { cnState } from "../../utilities/cn/index.js";
2
+ import { cn, cnState, cva } from "../../utilities/cn/index.js";
3
3
  import { buttonLook } from "../button/button.js";
4
4
  import { c } from "react/compiler-runtime";
5
5
  import { jsx } from "react/jsx-runtime";
@@ -104,7 +104,7 @@ function DialogContent(t0) {
104
104
  let t1;
105
105
  if ($[3] !== className) {
106
106
  t1 = cnState([
107
- "grid gap-4 bg-popover p-4 text-sm text-popover-foreground shadow-lg ring-1 ring-foreground/10 outline-none",
107
+ "grid gap-4 bg-popover p-(--dialog-padding) text-sm [--dialog-padding:--spacing(4)] text-popover-foreground shadow-lg ring-1 ring-foreground/10 outline-none",
108
108
  "data-[presentation=dialog]:popup-motion data-[presentation=dialog]:fixed data-[presentation=dialog]:inset-0 data-[presentation=dialog]:m-auto data-[presentation=dialog]:h-fit data-[presentation=dialog]:max-h-[calc(100%-2rem)] data-[presentation=dialog]:w-full data-[presentation=dialog]:max-w-[calc(100%-2rem)] data-[presentation=dialog]:overflow-y-auto data-[presentation=dialog]:rounded-2xl data-[presentation=dialog]:[--popup-duration:var(--transition-duration-modal)] data-[presentation=dialog]:data-starting-style:scale-[0.96] data-[presentation=dialog]:data-closed:scale-[0.96] data-[presentation=dialog]:sm:max-w-sm",
109
109
  "data-[presentation=sheet]:rounded-t-2xl"
110
110
  ], className);
@@ -123,6 +123,85 @@ function DialogContent(t0) {
123
123
  } else t2 = $[7];
124
124
  return t2;
125
125
  }
126
+ /** The title and description, stacked 6px apart as in Alma's dialogs. */
127
+ function DialogHeader(t0) {
128
+ const $ = c(8);
129
+ let className;
130
+ let props;
131
+ if ($[0] !== t0) {
132
+ ({className, ...props} = t0);
133
+ $[0] = t0;
134
+ $[1] = className;
135
+ $[2] = props;
136
+ } else {
137
+ className = $[1];
138
+ props = $[2];
139
+ }
140
+ let t1;
141
+ if ($[3] !== className) {
142
+ t1 = cn("flex flex-col gap-1.5", className);
143
+ $[3] = className;
144
+ $[4] = t1;
145
+ } else t1 = $[4];
146
+ let t2;
147
+ if ($[5] !== props || $[6] !== t1) {
148
+ t2 = /* @__PURE__ */ jsx("div", {
149
+ "data-slot": "dialog-header",
150
+ className: t1,
151
+ ...props
152
+ });
153
+ $[5] = props;
154
+ $[6] = t1;
155
+ $[7] = t2;
156
+ } else t2 = $[7];
157
+ return t2;
158
+ }
159
+ const dialogFooterVariants = cva("flex flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-end", {
160
+ variants: { variant: {
161
+ default: "-mx-(--dialog-padding) -mb-(--dialog-padding) border-t bg-muted/70 px-(--dialog-padding) py-3.5 dark:bg-background/60",
162
+ inline: ""
163
+ } },
164
+ defaultVariants: { variant: "default" }
165
+ });
166
+ function DialogFooter(t0) {
167
+ const $ = c(11);
168
+ let className;
169
+ let props;
170
+ let variant;
171
+ if ($[0] !== t0) {
172
+ ({className, variant, ...props} = t0);
173
+ $[0] = t0;
174
+ $[1] = className;
175
+ $[2] = props;
176
+ $[3] = variant;
177
+ } else {
178
+ className = $[1];
179
+ props = $[2];
180
+ variant = $[3];
181
+ }
182
+ const t1 = variant ?? "default";
183
+ let t2;
184
+ if ($[4] !== className || $[5] !== variant) {
185
+ t2 = cn(dialogFooterVariants({ variant }), className);
186
+ $[4] = className;
187
+ $[5] = variant;
188
+ $[6] = t2;
189
+ } else t2 = $[6];
190
+ let t3;
191
+ if ($[7] !== props || $[8] !== t1 || $[9] !== t2) {
192
+ t3 = /* @__PURE__ */ jsx("div", {
193
+ "data-slot": "dialog-footer",
194
+ "data-variant": t1,
195
+ className: t2,
196
+ ...props
197
+ });
198
+ $[7] = props;
199
+ $[8] = t1;
200
+ $[9] = t2;
201
+ $[10] = t3;
202
+ } else t3 = $[10];
203
+ return t3;
204
+ }
126
205
  function DialogTitle(t0) {
127
206
  const $ = c(8);
128
207
  let className;
@@ -258,4 +337,4 @@ function DialogShortcut(t0) {
258
337
  } else t2 = $[7];
259
338
  return t2;
260
339
  }
261
- export { Dialog, DialogBackdrop, DialogClose, DialogContent, DialogDescription, DialogShortcut, DialogTitle, DialogTrigger, createDialogController };
340
+ export { Dialog, DialogBackdrop, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogShortcut, DialogTitle, DialogTrigger, createDialogController, dialogFooterVariants };
@@ -6,7 +6,11 @@ declare function FieldLabel({ className, ...props }: ComponentProps<typeof Field
6
6
  * A control ui-sdk doesn't ship, like a native `<select>`. An agent can't
7
7
  * fill it: use `Input` or another of abby's controls where there is one.
8
8
  */
9
- declare function FieldControl({ className, ...props }: ComponentProps<typeof FieldControl$1>): import("react").JSX.Element;
9
+ type FieldControlProps = Omit<ComponentProps<typeof FieldControl$1>, "size"> & {
10
+ /** `lg` is `Input`'s large size: the 44px of `Button`'s `lg`, with 15px text from `md` up. */
11
+ size?: "default" | "lg";
12
+ };
13
+ declare function FieldControl({ className, size, ...props }: FieldControlProps): import("react").JSX.Element;
10
14
  declare function FieldDescription({ className, ...props }: ComponentProps<typeof FieldDescription$1>): import("react").JSX.Element;
11
15
  declare function FieldError({ className, ...props }: ComponentProps<typeof FieldError$1>): import("react").JSX.Element;
12
16
  declare function FieldSet({ className, ...props }: ComponentProps<typeof FieldSet$1>): import("react").JSX.Element;
@@ -68,40 +68,44 @@ function FieldLabel(t0) {
68
68
  } else t2 = $[7];
69
69
  return t2;
70
70
  }
71
- /**
72
- * A control ui-sdk doesn't ship, like a native `<select>`. An agent can't
73
- * fill it: use `Input` or another of abby's controls where there is one.
74
- */
75
71
  function FieldControl(t0) {
76
- const $ = c(8);
72
+ const $ = c(11);
77
73
  let className;
78
74
  let props;
75
+ let t1;
79
76
  if ($[0] !== t0) {
80
- ({className, ...props} = t0);
77
+ ({className, size: t1, ...props} = t0);
81
78
  $[0] = t0;
82
79
  $[1] = className;
83
80
  $[2] = props;
81
+ $[3] = t1;
84
82
  } else {
85
83
  className = $[1];
86
84
  props = $[2];
85
+ t1 = $[3];
87
86
  }
88
- let t1;
89
- if ($[3] !== className) {
90
- t1 = cnState(inputClasses, className);
91
- $[3] = className;
92
- $[4] = t1;
93
- } else t1 = $[4];
94
- let t2;
95
- if ($[5] !== props || $[6] !== t1) {
96
- t2 = /* @__PURE__ */ jsx(FieldControl$1, {
97
- className: t1,
87
+ const size = t1 === void 0 ? "default" : t1;
88
+ const t2 = size === "lg" && "h-11 px-4.5 md:text-heading-3 md:font-normal";
89
+ let t3;
90
+ if ($[4] !== className || $[5] !== t2) {
91
+ t3 = cnState([inputClasses, t2], className);
92
+ $[4] = className;
93
+ $[5] = t2;
94
+ $[6] = t3;
95
+ } else t3 = $[6];
96
+ let t4;
97
+ if ($[7] !== props || $[8] !== size || $[9] !== t3) {
98
+ t4 = /* @__PURE__ */ jsx(FieldControl$1, {
99
+ "data-size": size,
100
+ className: t3,
98
101
  ...props
99
102
  });
100
- $[5] = props;
101
- $[6] = t1;
102
- $[7] = t2;
103
- } else t2 = $[7];
104
- return t2;
103
+ $[7] = props;
104
+ $[8] = size;
105
+ $[9] = t3;
106
+ $[10] = t4;
107
+ } else t4 = $[10];
108
+ return t4;
105
109
  }
106
110
  function FieldDescription(t0) {
107
111
  const $ = c(8);
@@ -0,0 +1,36 @@
1
+ import { ChangeDetails } from "../../core/ui-sdk.js";
2
+ import "../../core/index.js";
3
+ import { ComponentProps } from "react";
4
+ type FilterChipItem = string | {
5
+ value: string;
6
+ label: string;
7
+ disabled?: boolean;
8
+ };
9
+ type FilterChipProps = Omit<ComponentProps<"div">, "onChange" | "children" | "defaultValue"> & {
10
+ /** The options, one of them chosen. A string is an option whose label and value match. */
11
+ items: FilterChipItem[];
12
+ /** The chosen value. */
13
+ value?: string;
14
+ defaultValue?: string;
15
+ /** Runs when a choice wants to change. `details.cancel()` keeps the current one. */
16
+ onValueChange?: (value: string, details: ChangeDetails<string>) => void;
17
+ /** The value that means "no filter". The chip is active while the value is any other. */
18
+ allValue: string;
19
+ /** What the filter is, in grey before the value: "Persona". Its colon is yours to write. */
20
+ prefix?: string;
21
+ /** Draws a chevron after the value. */
22
+ chevron?: boolean;
23
+ /** A CSS color, the area's, for the small square before the value while the chip is active. */
24
+ color?: string;
25
+ /**
26
+ * Shows a × while the chip is active. The × goes back to `allValue` through
27
+ * `onValueChange` (reason `"clear-press"`, which can cancel it), controlled
28
+ * or not, and then runs `onClear`.
29
+ */
30
+ onClear?: () => void;
31
+ /** The × button's name. Give each chip its own when a page holds several. */
32
+ clearLabel?: string;
33
+ disabled?: boolean;
34
+ };
35
+ declare function FilterChip({ items, value, defaultValue, onValueChange, allValue, prefix, chevron, color, onClear, clearLabel, disabled, className, ...props }: FilterChipProps): import("react").JSX.Element;
36
+ export { FilterChip, type FilterChipItem, type FilterChipProps };
@@ -0,0 +1,97 @@
1
+ "use client";
2
+ import { cn } from "../../utilities/cn/index.js";
3
+ import { Button } from "../button/button.js";
4
+ import { Icon } from "../icon/icon.js";
5
+ import { Menu, MenuContent, MenuItemIndicator, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "../menu/menu.js";
6
+ import { useState } from "react";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ import { ArrowDown01Icon, Cancel01Icon } from "@hugeicons/core-free-icons";
9
+ // src/components/filter-chip/filter-chip.tsx
10
+ const trigger = [
11
+ "flex h-full min-w-0 flex-1 cursor-pointer items-center gap-1.5 rounded-full ps-2.5 pe-2.5 text-sm outline-none select-none",
12
+ "transition-colors motion-reduce:transition-none hover:bg-accent data-open:bg-accent",
13
+ "disabled:pointer-events-none"
14
+ ];
15
+ function FilterChip({ items, value, defaultValue, onValueChange, allValue, prefix, chevron, color, onClear, clearLabel = "Clear filter", disabled, className, ...props }) {
16
+ const [own, setOwn] = useState(defaultValue ?? allValue);
17
+ const current = value ?? own;
18
+ const options = items.map((item) => typeof item === "string" ? {
19
+ value: item,
20
+ label: item
21
+ } : item);
22
+ const label = options.find((option) => option.value === current)?.label ?? current;
23
+ const active = current !== allValue;
24
+ function clear(event, press) {
25
+ let canceled = false;
26
+ const details = {
27
+ reason: "clear-press",
28
+ event: event.nativeEvent,
29
+ source: press.source,
30
+ cancel: () => {
31
+ canceled = true;
32
+ },
33
+ get canceled() {
34
+ return canceled;
35
+ }
36
+ };
37
+ onValueChange?.(allValue, details);
38
+ if (details.canceled) return;
39
+ setOwn(allValue);
40
+ onClear?.();
41
+ }
42
+ return /* @__PURE__ */ jsxs("div", {
43
+ "data-slot": "filter-chip",
44
+ "data-active": active ? "" : void 0,
45
+ "data-disabled": disabled ? "" : void 0,
46
+ className: cn("inline-flex h-7 max-w-full items-center rounded-full border border-input text-sm text-foreground transition-colors focus-ring-within motion-reduce:transition-none data-active:border-ring data-disabled:opacity-50", className),
47
+ ...props,
48
+ children: [/* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsxs(MenuTrigger, {
49
+ disabled,
50
+ className: cn(trigger),
51
+ children: [
52
+ prefix && /* @__PURE__ */ jsxs("span", {
53
+ className: "shrink-0 text-muted-foreground",
54
+ children: [prefix, " "]
55
+ }),
56
+ active && color && /* @__PURE__ */ jsx("span", {
57
+ "aria-hidden": "true",
58
+ "data-slot": "filter-chip-color",
59
+ className: "size-2 shrink-0 rounded-2xs",
60
+ style: { backgroundColor: color }
61
+ }),
62
+ /* @__PURE__ */ jsx("span", {
63
+ className: cn("truncate", active && "font-medium"),
64
+ children: label
65
+ }),
66
+ chevron && /* @__PURE__ */ jsx(Icon, {
67
+ icon: ArrowDown01Icon,
68
+ className: "size-2.5 text-muted-foreground"
69
+ })
70
+ ]
71
+ }), /* @__PURE__ */ jsx(MenuContent, { children: /* @__PURE__ */ jsx(MenuRadioGroup, {
72
+ value: current,
73
+ onValueChange: (next, details_0) => {
74
+ onValueChange?.(next, details_0);
75
+ if (!details_0.canceled) setOwn(next);
76
+ },
77
+ children: options.map((option_0) => /* @__PURE__ */ jsxs(MenuRadioItem, {
78
+ value: option_0.value,
79
+ disabled: option_0.disabled,
80
+ closeOnSelect: true,
81
+ children: [option_0.label, /* @__PURE__ */ jsx(MenuItemIndicator, {})]
82
+ }, option_0.value))
83
+ }) })] }), active && onClear && /* @__PURE__ */ jsx(Button, {
84
+ variant: "ghost",
85
+ size: "icon-xs",
86
+ "aria-label": clearLabel,
87
+ disabled,
88
+ onClick: clear,
89
+ className: "me-px shrink-0",
90
+ children: /* @__PURE__ */ jsx(Icon, {
91
+ icon: Cancel01Icon,
92
+ className: "size-3"
93
+ })
94
+ })]
95
+ });
96
+ }
97
+ export { FilterChip };
@@ -0,0 +1,151 @@
1
+ import { ChangeDetails, PartProps } from "../../core/ui-sdk.js";
2
+ import "../../core/index.js";
3
+ import { ReactNode } from "react";
4
+ /** The colors a node's swatch can take. A swatch never says something by color alone: the name does. */
5
+ type GraphTone = "chart-1" | "chart-2" | "chart-3" | "chart-4" | "chart-5";
6
+ /** How a line looks: `solid`, `dashed` (weaker) or `warning` (dashed and amber, for a clash). */
7
+ type GraphEdgeVariant = "solid" | "dashed" | "warning";
8
+ type GraphNodeData = {
9
+ /** Unique within the graph. A repeated id is ignored. */
10
+ id: string;
11
+ /** What the node says, and its accessible name. */
12
+ name: string;
13
+ /** The node's center, in map units (px at zoom 1). Larger `y` is farther down. */
14
+ x: number;
15
+ y: number;
16
+ /** A swatch before `meta`. */
17
+ color?: GraphTone;
18
+ /** A second, quieter line, like who wrote it and when. */
19
+ meta?: string;
20
+ /** The node the map is about: wider, with a firmer edge. */
21
+ current?: boolean;
22
+ /** A node that was replaced: its name is struck through and faded. */
23
+ replaced?: boolean;
24
+ };
25
+ type GraphEdgeData = {
26
+ /** The id of the node the line starts at. */
27
+ from: string;
28
+ /** The id of the node the line ends at. */
29
+ to: string;
30
+ /** Said on the line, and in the text list: "Contradicts". */
31
+ label?: string;
32
+ /** The line's width in px, 1.2 by default. Under 1.2 the line is fainter. */
33
+ weight?: number;
34
+ /** `solid` by default. */
35
+ variant?: GraphEdgeVariant;
36
+ };
37
+ type GraphChangeReason = "item-press" | "imperative";
38
+ /** Drives a graph from anywhere. Pass it as the `controller` prop. */
39
+ type GraphController = {
40
+ /** The selected node's id, or `null`. */
41
+ getSelected: () => string | null;
42
+ /** Selects a node, or clears the selection with `null`. False when the node doesn't exist or the app refused it. */
43
+ setSelected: (id: string | null) => boolean;
44
+ /** The zoom now, from 0.5 to 2. */
45
+ getZoom: () => number;
46
+ /** Zooms in a step. */
47
+ zoomIn: () => boolean;
48
+ /** Zooms out a step. */
49
+ zoomOut: () => boolean;
50
+ /** Focuses a node, or the one with the tab stop. */
51
+ focus: (id?: string) => void;
52
+ };
53
+ type GraphOptions = {
54
+ /** The selected node's id, or `null`. Pass it to control the graph. */
55
+ selected?: string | null;
56
+ /** The node selected at first, when uncontrolled. */
57
+ defaultSelected?: string | null;
58
+ /** Runs when a node is pressed, with Enter too, or a controller or agent selects one. `details.cancel()` keeps the selection. */
59
+ onSelectedChange?: (id: string | null, details: ChangeDetails<GraphChangeReason>) => void;
60
+ /** The points. The app places them: this component never moves them. */
61
+ nodes?: readonly GraphNodeData[];
62
+ /** The lines. One that names a node that isn't in `nodes`, or the same one twice, is ignored. */
63
+ edges?: readonly GraphEdgeData[];
64
+ /** Drives the graph from anywhere. Create one with `createGraphController()`. */
65
+ controller?: GraphController;
66
+ };
67
+ type GraphRootState = {
68
+ selected: string | null;
69
+ zoom: number;
70
+ };
71
+ type GraphNodeState = {
72
+ id: string;
73
+ node: GraphNodeData;
74
+ selected: boolean;
75
+ };
76
+ type GraphZoomState = {
77
+ /** Whether the zoom is already at its limit in this direction. */
78
+ disabled: boolean;
79
+ };
80
+ /** Drives a graph from anywhere: pass it as `controller`. */
81
+ declare function createGraphController(): GraphController;
82
+ /**
83
+ * The graph's state and the methods that change it, for a component inside
84
+ * `Graph`. It re-renders when the state changes.
85
+ */
86
+ declare function useGraph(): {
87
+ selected: string | null;
88
+ zoom: number;
89
+ nodes: GraphNodeData[];
90
+ edges: GraphEdgeData[];
91
+ setSelected: (id: string | null) => boolean;
92
+ zoomIn: () => boolean;
93
+ zoomOut: () => boolean;
94
+ focus: (id?: string) => void;
95
+ };
96
+ type GraphProps = GraphOptions & Omit<PartProps<"div", GraphRootState>, "defaultValue"> & {
97
+ /** Names the graph for screen readers and agents. Set it in the page's language. */
98
+ label?: string;
99
+ };
100
+ /** Without children it renders the canvas, the zoom buttons, the legend and the text list. */
101
+ declare function Graph({ selected, defaultSelected, onSelectedChange, nodes, edges, controller, label, className, children, ...props }: GraphProps): import("react").JSX.Element | null;
102
+ /**
103
+ * The map: the lines and their labels under the nodes. It scrolls when the
104
+ * zoomed map is bigger than its box. The box takes its height from `className`.
105
+ */
106
+ declare function GraphCanvas({ className, children }: {
107
+ className?: string;
108
+ children?: ReactNode;
109
+ }): import("react").JSX.Element;
110
+ type GraphNodeProps = Omit<PartProps<"button", GraphNodeState>, "value"> & {
111
+ /** The node's id. */
112
+ value: string;
113
+ };
114
+ /**
115
+ * One node, a button named by the node's name. Without children it draws the
116
+ * name and, under it, the swatch and `meta`. A `value` that isn't in `nodes`
117
+ * draws nothing, so an app's own list can lag a render behind.
118
+ */
119
+ declare function GraphNode(props: GraphNodeProps): import("react").JSX.Element | null;
120
+ type GraphZoomProps = {
121
+ className?: string;
122
+ /** The zoom-in button's accessible name. Set it in the page's language. */
123
+ zoomInLabel?: string;
124
+ /** The zoom-out button's accessible name. Set it in the page's language. */
125
+ zoomOutLabel?: string;
126
+ };
127
+ /** The + and − buttons, stacked at the map's end corner. The keys + and − zoom too. */
128
+ declare function GraphZoom({ className, zoomInLabel, zoomOutLabel }: GraphZoomProps): import("react").JSX.Element;
129
+ type GraphLegendProps = {
130
+ className?: string;
131
+ /** The styles to name, in order. All three by default. */
132
+ variants?: readonly GraphEdgeVariant[];
133
+ /** What each style means. Set them in the page's language. */
134
+ labels?: Partial<Record<GraphEdgeVariant, ReactNode>>;
135
+ /** The legend's accessible name. */
136
+ label?: string;
137
+ };
138
+ /** Names each line style with a sample of it, at the map's start corner. */
139
+ declare function GraphLegend({ className, variants, labels, label }: GraphLegendProps): import("react").JSX.Element;
140
+ type GraphListProps = {
141
+ /** What a node without a label on its lines says: "Related to". */
142
+ relatedLabel?: string;
143
+ /** The list's accessible name. */
144
+ label?: string;
145
+ };
146
+ /**
147
+ * The same map as text, for people who read it with a screen reader: every
148
+ * node once, with its lines as "Contradicts: Other node". Hidden from sight.
149
+ */
150
+ declare function GraphList({ relatedLabel, label }: GraphListProps): import("react").JSX.Element;
151
+ export { Graph, GraphCanvas, type GraphChangeReason, type GraphController, type GraphEdgeData, type GraphEdgeVariant, GraphLegend, type GraphLegendProps, GraphList, type GraphListProps, GraphNode, type GraphNodeData, type GraphNodeProps, type GraphNodeState, type GraphOptions, type GraphProps, type GraphRootState, type GraphTone, GraphZoom, type GraphZoomProps, type GraphZoomState, createGraphController, useGraph };