@krak-stack/registry 0.2.2 → 0.3.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.
@@ -0,0 +1,37 @@
1
+ import { type ComponentProps, type ReactNode } from "react";
2
+ export type StepperStep = {
3
+ id: string;
4
+ label: string;
5
+ description?: string;
6
+ icon?: ReactNode;
7
+ state?: "upcoming" | "completed" | "error";
8
+ disabled?: boolean;
9
+ disabledReason?: string;
10
+ };
11
+ export type StepperMessages = {
12
+ label: string;
13
+ progress: (current: number, total: number) => string;
14
+ completed: string;
15
+ error: string;
16
+ };
17
+ export type StepperMessageTranslations = Partial<Record<string, Partial<StepperMessages>>>;
18
+ export type StepperProps = Omit<ComponentProps<"nav">, "children"> & {
19
+ steps: readonly StepperStep[];
20
+ currentStep: string;
21
+ onStepSelect?: (step: StepperStep) => void;
22
+ variant?: "labelled" | "segmented" | "underline";
23
+ orientation?: "horizontal" | "vertical" | "responsive";
24
+ locale?: string;
25
+ messages?: StepperMessageTranslations;
26
+ };
27
+ /** Controlled progress navigation, not a form or workflow engine. */
28
+ export declare const Stepper: ({ steps, currentStep, onStepSelect, variant, orientation, locale: localeOverride, messages, className, "aria-label": ariaLabel, ...props }: StepperProps) => import("react").JSX.Element | null;
29
+ export type StepperContentProps = ComponentProps<"div"> & {
30
+ step: string;
31
+ direction?: "forward" | "backward" | "none";
32
+ animate?: boolean;
33
+ /** Opt in only when the router does not already manage content focus. */
34
+ focusTarget?: string;
35
+ };
36
+ /** Keeps content mounted; callers own field state and route transitions. */
37
+ export declare const StepperContent: ({ step, direction, animate, focusTarget, children, className, ...props }: StepperContentProps) => import("react").JSX.Element;
@@ -0,0 +1,244 @@
1
+ // ../../src/components/ui/stepper.tsx
2
+ import { Check, CircleAlert } from "lucide-react";
3
+ import {
4
+ Component,
5
+ useLayoutEffect,
6
+ useRef
7
+ } from "react";
8
+ import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
9
+
10
+ // ../../src/lib/utils.ts
11
+ import { cn } from "cn";
12
+
13
+ // ../../src/components/ui/stepper.tsx
14
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
15
+ var defaults = {
16
+ en: {
17
+ label: "Progress",
18
+ progress: (current, total) => `Step ${current} of ${total}`,
19
+ completed: "Completed",
20
+ error: "Needs attention"
21
+ },
22
+ fr: {
23
+ label: "Progression",
24
+ progress: (current, total) => `Étape ${current} sur ${total}`,
25
+ completed: "Terminée",
26
+ error: "À vérifier"
27
+ }
28
+ };
29
+ var Stepper = ({
30
+ steps,
31
+ currentStep,
32
+ onStepSelect,
33
+ variant = "labelled",
34
+ orientation = "horizontal",
35
+ locale: localeOverride,
36
+ messages,
37
+ className,
38
+ "aria-label": ariaLabel,
39
+ ...props
40
+ }) => {
41
+ const locale = useKrakstackLocale(localeOverride);
42
+ const base = locale.split("-")[0] ?? locale;
43
+ const labels = {
44
+ ...base === "fr" ? defaults.fr : defaults.en,
45
+ ...messages?.[base],
46
+ ...messages?.[locale]
47
+ };
48
+ const currentIndex = steps.findIndex((step) => step.id === currentStep);
49
+ if (steps.length === 0 || currentIndex < 0)
50
+ return null;
51
+ return /* @__PURE__ */ jsxs("nav", {
52
+ ...props,
53
+ "aria-label": ariaLabel ?? labels.label,
54
+ "data-slot": "stepper",
55
+ "data-variant": variant,
56
+ "data-orientation": orientation,
57
+ className: cn("min-w-0", className),
58
+ children: [
59
+ /* @__PURE__ */ jsx("p", {
60
+ "aria-live": "polite",
61
+ "aria-atomic": "true",
62
+ className: "sr-only",
63
+ children: labels.progress(currentIndex + 1, steps.length)
64
+ }),
65
+ /* @__PURE__ */ jsx("ol", {
66
+ className: cn("flex gap-2", variant === "underline" && "flex-wrap gap-x-6 gap-y-1", variant === "underline" && orientation === "horizontal" && "justify-center", orientation === "vertical" && "flex-col", orientation === "responsive" && "lg:flex-col"),
67
+ children: steps.map((step, index) => {
68
+ const active = step.id === currentStep;
69
+ const state = step.state ?? "upcoming";
70
+ const content = /* @__PURE__ */ jsxs(Fragment, {
71
+ children: [
72
+ variant === "segmented" ? /* @__PURE__ */ jsx("span", {
73
+ "aria-hidden": "true",
74
+ className: cn("bg-muted block h-1.5 w-full rounded-full motion-safe:transition-colors motion-safe:duration-150", state === "completed" && "bg-primary/50", active && "bg-primary", state === "error" && "bg-destructive")
75
+ }) : variant === "labelled" ? /* @__PURE__ */ jsx("span", {
76
+ "aria-hidden": "true",
77
+ className: cn("flex size-8 shrink-0 items-center justify-center rounded-full border text-xs font-medium motion-safe:transition-colors motion-safe:duration-150 [&_svg]:size-4", state === "completed" && "border-primary/30 bg-primary/10 text-primary", active && "border-primary bg-primary text-primary-foreground", state === "error" && "border-destructive text-destructive"),
78
+ children: state === "error" ? /* @__PURE__ */ jsx(CircleAlert, {}) : state === "completed" && !active ? /* @__PURE__ */ jsx(Check, {}) : step.icon ?? index + 1
79
+ }) : null,
80
+ /* @__PURE__ */ jsxs("span", {
81
+ className: cn("min-w-0 break-words", variant === "segmented" && "sr-only", orientation === "responsive" && variant === "labelled" && "sr-only lg:not-sr-only"),
82
+ children: [
83
+ /* @__PURE__ */ jsx("span", {
84
+ className: "block",
85
+ children: step.label
86
+ }),
87
+ step.description ? /* @__PURE__ */ jsx("span", {
88
+ className: "text-muted-foreground block text-xs font-normal",
89
+ children: step.description
90
+ }) : null,
91
+ state !== "upcoming" ? /* @__PURE__ */ jsxs("span", {
92
+ className: "sr-only",
93
+ children: [
94
+ " — ",
95
+ labels[state]
96
+ ]
97
+ }) : null,
98
+ step.disabledReason ? /* @__PURE__ */ jsx("span", {
99
+ className: "text-muted-foreground block text-xs font-normal",
100
+ children: step.disabledReason
101
+ }) : null
102
+ ]
103
+ })
104
+ ]
105
+ });
106
+ const itemClassName = cn("text-muted-foreground flex min-h-11 w-full min-w-0 items-center rounded-md text-sm", variant === "labelled" && orientation === "horizontal" ? "flex-col gap-2 text-center sm:flex-row sm:gap-3 sm:text-left" : "gap-3 text-left", variant === "labelled" && "px-2 py-2", orientation === "responsive" && "justify-center lg:justify-start", variant === "underline" && "w-auto justify-start rounded-none border-b-2 border-transparent py-3 text-left motion-safe:transition-colors motion-safe:duration-150", variant === "underline" && active && "border-foreground", active && "text-foreground font-medium", state === "error" && "text-destructive");
107
+ return /* @__PURE__ */ jsx("li", {
108
+ "data-state": state,
109
+ className: cn("min-w-0", variant !== "underline" && "flex-1"),
110
+ children: onStepSelect ? /* @__PURE__ */ jsx("button", {
111
+ type: "button",
112
+ "aria-current": active ? "step" : undefined,
113
+ "aria-disabled": step.disabled || undefined,
114
+ title: step.disabledReason ?? step.label,
115
+ className: cn(itemClassName, "focus-visible:ring-ring hover:bg-muted/50 focus-visible:ring-2 focus-visible:outline-none aria-disabled:cursor-not-allowed aria-disabled:opacity-60"),
116
+ onClick: () => {
117
+ if (!step.disabled && !active)
118
+ onStepSelect(step);
119
+ },
120
+ children: content
121
+ }) : /* @__PURE__ */ jsx("div", {
122
+ "aria-current": active ? "step" : undefined,
123
+ className: itemClassName,
124
+ children: content
125
+ })
126
+ }, step.id);
127
+ })
128
+ })
129
+ ]
130
+ });
131
+ };
132
+
133
+ class StepperPanel extends Component {
134
+ getSnapshotBeforeUpdate(previous) {
135
+ if (!this.props.animate || previous.step === this.props.step)
136
+ return null;
137
+ const copy = this.props.panelRef.current?.cloneNode(true);
138
+ return copy instanceof HTMLElement ? copy : null;
139
+ }
140
+ componentDidUpdate(_previous, _state, snapshot) {
141
+ this.props.snapshotRef.current = snapshot;
142
+ }
143
+ render() {
144
+ return /* @__PURE__ */ jsx("div", {
145
+ ref: this.props.panelRef,
146
+ "data-slot": "stepper-panel",
147
+ className: "flow-root min-w-0",
148
+ children: this.props.children
149
+ });
150
+ }
151
+ }
152
+ var StepperContent = ({
153
+ step,
154
+ direction = "none",
155
+ animate = false,
156
+ focusTarget,
157
+ children,
158
+ className,
159
+ ...props
160
+ }) => {
161
+ const content = useRef(null);
162
+ const panel = useRef(null);
163
+ const exit = useRef(null);
164
+ const snapshot = useRef(null);
165
+ const previousStep = useRef(step);
166
+ useLayoutEffect(() => {
167
+ if (previousStep.current === step)
168
+ return;
169
+ previousStep.current = step;
170
+ const element = content.current;
171
+ const animatedPanel = panel.current;
172
+ if (!element || !animatedPanel)
173
+ return;
174
+ if (focusTarget)
175
+ animatedPanel.querySelector(focusTarget)?.focus({ preventScroll: true });
176
+ if (!animate || direction === "none" || !animatedPanel.animate || window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)
177
+ return;
178
+ const animation = animatedPanel.animate([
179
+ {
180
+ transform: `translateX(${direction === "forward" ? "100%" : "-100%"})`
181
+ },
182
+ { transform: "translateX(0)" }
183
+ ], {
184
+ duration: 500,
185
+ easing: "cubic-bezier(0.4, 0, 0.2, 1)"
186
+ });
187
+ const outgoing = snapshot.current;
188
+ const exitElement = exit.current;
189
+ let exitAnimation;
190
+ if (outgoing && exitElement) {
191
+ outgoing.dataset.slot = "stepper-exiting-panel";
192
+ for (const node of outgoing.querySelectorAll("[id], [name]")) {
193
+ node.removeAttribute("id");
194
+ node.removeAttribute("name");
195
+ }
196
+ for (const node of outgoing.querySelectorAll("input, select, textarea, button")) {
197
+ node.setAttribute("disabled", "");
198
+ }
199
+ exitElement.replaceChildren(outgoing);
200
+ exitAnimation = animatedPanel.animate.call(outgoing, [
201
+ { transform: "translateX(0)" },
202
+ {
203
+ transform: `translateX(${direction === "forward" ? "-100%" : "100%"})`
204
+ }
205
+ ], {
206
+ duration: 500,
207
+ easing: "cubic-bezier(0.4, 0, 0.2, 1)",
208
+ fill: "forwards"
209
+ });
210
+ exitAnimation.onfinish = () => exitElement.replaceChildren();
211
+ }
212
+ return () => {
213
+ animation.cancel();
214
+ exitAnimation?.cancel();
215
+ exitElement?.replaceChildren();
216
+ };
217
+ }, [step, direction, animate, focusTarget]);
218
+ return /* @__PURE__ */ jsxs("div", {
219
+ ...props,
220
+ ref: content,
221
+ "data-slot": "stepper-content",
222
+ className: cn("relative min-w-0", animate && "overflow-x-clip", className),
223
+ children: [
224
+ /* @__PURE__ */ jsx("div", {
225
+ ref: exit,
226
+ "data-slot": "stepper-exit",
227
+ inert: true,
228
+ "aria-hidden": "true",
229
+ className: "pointer-events-none absolute inset-0 overflow-hidden"
230
+ }),
231
+ /* @__PURE__ */ jsx(StepperPanel, {
232
+ step,
233
+ animate,
234
+ panelRef: panel,
235
+ snapshotRef: snapshot,
236
+ children
237
+ })
238
+ ]
239
+ });
240
+ };
241
+ export {
242
+ Stepper,
243
+ StepperContent
244
+ };
@@ -158,7 +158,7 @@ var VirtualizedComboboxList = ({
158
158
  }));
159
159
  const selectedEntries = itemEntries.filter(({ item }) => selectedValues.has(item.value));
160
160
  const availableEntries = itemEntries.filter(({ item }) => !selectedValues.has(item.value));
161
- const entries = filteredItems.length === 0 ? [] : groupSelections ? [
161
+ const entries = groupSelections ? [
162
162
  ...selectedEntries.length > 0 ? [
163
163
  {
164
164
  kind: "group",
@@ -277,7 +277,7 @@ var VirtualizedComboboxContent = ({
277
277
  side: "bottom",
278
278
  sideOffset: 6,
279
279
  children: /* @__PURE__ */ jsxs(ComboboxPrimitive.Popup, {
280
- className: cn("bg-popover text-popover-foreground ring-foreground/10 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-in-95 relative flex max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) flex-col overflow-hidden rounded-md shadow-md ring-1 duration-100", contentClassName),
280
+ className: cn("relative flex max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) flex-col overflow-hidden rounded-md bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-in-95", contentClassName),
281
281
  children: [
282
282
  /* @__PURE__ */ jsx4("div", {
283
283
  className: "min-w-0 shrink-0 p-1 pb-0",
@@ -1449,7 +1449,9 @@ var DateInput = Schema2.Union([
1449
1449
  Schema2.Int,
1450
1450
  CalendarDate,
1451
1451
  InstantString
1452
- ]).annotate({ identifier: "DataTableDateInput" });
1452
+ ]).annotate({
1453
+ identifier: "DataTableDateInput"
1454
+ });
1453
1455
  var decodeDateInput = Schema2.decodeUnknownOption(DateInput);
1454
1456
  var resolveDate = (value, type) => Option2.getOrUndefined(Option2.flatMap(decodeDateInput(value), (input) => {
1455
1457
  const calendarOnly = Schema2.is(CalendarDate)(input);
@@ -1851,7 +1853,7 @@ var renderCell = (row, column, locale = "en", labels = dataTableMessages(locale)
1851
1853
  return /* @__PURE__ */ jsx15(DataTableReferenceCell, {
1852
1854
  item: colDef.typeOptions.getItem(row.data),
1853
1855
  emptyLabel: colDef.typeOptions.emptyLabel,
1854
- imageVariant: colDef.typeOptions.imageVariant
1856
+ ...colDef.typeOptions.imageVariant ? { imageVariant: colDef.typeOptions.imageVariant } : {}
1855
1857
  });
1856
1858
  }
1857
1859
  if (colDef.type === "number") {
@@ -2417,21 +2419,26 @@ var FilterEditor = ({
2417
2419
  event.preventDefault();
2418
2420
  if (kind === "text")
2419
2421
  apply({ id: column.id, kind, operator, value: primary.trim() });
2420
- else if (kind === "date")
2421
- apply({
2422
- id: column.id,
2423
- kind,
2424
- from: primary || undefined,
2425
- to: secondary || undefined
2426
- });
2427
- else {
2422
+ else if (kind === "date") {
2423
+ const draft = { id: column.id, kind };
2424
+ if (primary)
2425
+ draft.from = primary;
2426
+ if (secondary)
2427
+ draft.to = secondary;
2428
+ apply(draft);
2429
+ } else {
2428
2430
  const min = primary ? Schema2.decodeOption(Schema2.FiniteFromString)(primary) : Option2.some(undefined);
2429
2431
  const max = secondary ? Schema2.decodeOption(Schema2.FiniteFromString)(secondary) : Option2.some(undefined);
2430
2432
  if (Option2.isNone(min) || Option2.isNone(max)) {
2431
2433
  setInvalid(true);
2432
2434
  return;
2433
2435
  }
2434
- apply({ id: column.id, kind, min: min.value, max: max.value });
2436
+ const draft = { id: column.id, kind };
2437
+ if (min.value !== undefined)
2438
+ draft.min = min.value;
2439
+ if (max.value !== undefined)
2440
+ draft.max = max.value;
2441
+ apply(draft);
2435
2442
  }
2436
2443
  },
2437
2444
  children: [
@@ -1453,7 +1453,9 @@ var DateInput = Schema2.Union([
1453
1453
  Schema2.Int,
1454
1454
  CalendarDate,
1455
1455
  InstantString
1456
- ]).annotate({ identifier: "DataTableDateInput" });
1456
+ ]).annotate({
1457
+ identifier: "DataTableDateInput"
1458
+ });
1457
1459
  var decodeDateInput = Schema2.decodeUnknownOption(DateInput);
1458
1460
  var resolveDate = (value, type) => Option2.getOrUndefined(Option2.flatMap(decodeDateInput(value), (input) => {
1459
1461
  const calendarOnly = Schema2.is(CalendarDate)(input);
@@ -1855,7 +1857,7 @@ var renderCell = (row, column, locale = "en", labels = dataTableMessages(locale)
1855
1857
  return /* @__PURE__ */ jsx15(DataTableReferenceCell, {
1856
1858
  item: colDef.typeOptions.getItem(row.data),
1857
1859
  emptyLabel: colDef.typeOptions.emptyLabel,
1858
- imageVariant: colDef.typeOptions.imageVariant
1860
+ ...colDef.typeOptions.imageVariant ? { imageVariant: colDef.typeOptions.imageVariant } : {}
1859
1861
  });
1860
1862
  }
1861
1863
  if (colDef.type === "number") {
@@ -2421,21 +2423,26 @@ var FilterEditor = ({
2421
2423
  event.preventDefault();
2422
2424
  if (kind === "text")
2423
2425
  apply({ id: column.id, kind, operator, value: primary.trim() });
2424
- else if (kind === "date")
2425
- apply({
2426
- id: column.id,
2427
- kind,
2428
- from: primary || undefined,
2429
- to: secondary || undefined
2430
- });
2431
- else {
2426
+ else if (kind === "date") {
2427
+ const draft = { id: column.id, kind };
2428
+ if (primary)
2429
+ draft.from = primary;
2430
+ if (secondary)
2431
+ draft.to = secondary;
2432
+ apply(draft);
2433
+ } else {
2432
2434
  const min = primary ? Schema2.decodeOption(Schema2.FiniteFromString)(primary) : Option2.some(undefined);
2433
2435
  const max = secondary ? Schema2.decodeOption(Schema2.FiniteFromString)(secondary) : Option2.some(undefined);
2434
2436
  if (Option2.isNone(min) || Option2.isNone(max)) {
2435
2437
  setInvalid(true);
2436
2438
  return;
2437
2439
  }
2438
- apply({ id: column.id, kind, min: min.value, max: max.value });
2440
+ const draft = { id: column.id, kind };
2441
+ if (min.value !== undefined)
2442
+ draft.min = min.value;
2443
+ if (max.value !== undefined)
2444
+ draft.max = max.value;
2445
+ apply(draft);
2439
2446
  }
2440
2447
  },
2441
2448
  children: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/registry",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Tree-shakable KrakStack components and Effect services.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -160,6 +160,10 @@
160
160
  "types": "./dist/components/ui/copy-button.d.ts",
161
161
  "import": "./dist/components/ui/copy-button.js"
162
162
  },
163
+ "./stepper": {
164
+ "types": "./dist/components/ui/stepper.d.ts",
165
+ "import": "./dist/components/ui/stepper.js"
166
+ },
163
167
  "./color-picker": {
164
168
  "types": "./dist/components/ui/color-picker.d.ts",
165
169
  "import": "./dist/components/ui/color-picker.js"
@@ -188,9 +192,9 @@
188
192
  "types": "./dist/components/ui/form.d.ts",
189
193
  "import": "./dist/components/ui/form.js"
190
194
  },
191
- "./google-map": {
192
- "types": "./dist/components/ui/google-map.d.ts",
193
- "import": "./dist/components/ui/google-map.js"
195
+ "./map-menu": {
196
+ "types": "./dist/components/ui/map-menu.d.ts",
197
+ "import": "./dist/components/ui/map-menu.js"
194
198
  },
195
199
  "./icon-input": {
196
200
  "types": "./dist/components/ui/icon-input.d.ts",