@nexub/react 6.3.0 → 6.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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "6.3.0",
2
+ "version": "6.4.0",
3
3
  "standard": "WCAG 2.2 Level AA",
4
4
  "method": {
5
5
  "automated": "axe-core rules tagged wcag2a, wcag2aa, wcag21a, wcag21aa and wcag22aa, run on every Storybook story in light and dark, and on open popups (menus, listboxes, dialogs), on every pull request; a new violation fails the build.",
@@ -42,6 +42,15 @@
42
42
  "keyboard": [],
43
43
  "screenReader": []
44
44
  },
45
+ {
46
+ "slug": "action-bar",
47
+ "name": "Action Bar",
48
+ "package": "@nexub/react",
49
+ "automated": "pass",
50
+ "exceptions": [],
51
+ "keyboard": [],
52
+ "screenReader": []
53
+ },
45
54
  {
46
55
  "slug": "alert-dialog",
47
56
  "name": "Alert Dialog",
@@ -925,6 +934,19 @@
925
934
  "keyboard": [],
926
935
  "screenReader": []
927
936
  },
937
+ {
938
+ "slug": "resizable-panels",
939
+ "name": "Resizable Panels",
940
+ "package": "@nexub/react",
941
+ "automated": "pass",
942
+ "exceptions": [],
943
+ "keyboard": [
944
+ "Arrow keys: Move the focused separator by 5%. Mirrored in RTL.",
945
+ "Home / End: To the smallest or largest size.",
946
+ "Enter: Back to the default split."
947
+ ],
948
+ "screenReader": []
949
+ },
928
950
  {
929
951
  "slug": "saved-views",
930
952
  "name": "Saved Views",
@@ -1067,6 +1089,15 @@
1067
1089
  "keyboard": [],
1068
1090
  "screenReader": []
1069
1091
  },
1092
+ {
1093
+ "slug": "stepper",
1094
+ "name": "Stepper",
1095
+ "package": "@nexub/react",
1096
+ "automated": "pass",
1097
+ "exceptions": [],
1098
+ "keyboard": [],
1099
+ "screenReader": []
1100
+ },
1070
1101
  {
1071
1102
  "slug": "streaming-text",
1072
1103
  "name": "Streaming Text",
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ export interface ActionBarProps extends React.HTMLAttributes<HTMLDivElement> {
3
+ /** Status on the start side, e.g. "Unsaved changes". Announced politely. */
4
+ message?: React.ReactNode;
5
+ /** Names the region. @default the message when it's a string */
6
+ 'aria-label'?: string;
7
+ }
8
+ /**
9
+ * Save / cancel that stay in view at the bottom of a long form or settings
10
+ * page. Put it last inside the scrolling area.
11
+ */
12
+ export declare const ActionBar: React.ForwardRefExoticComponent<ActionBarProps & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,27 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { cn } from "../../utils/cn.js";
4
+ import { floatingSurface } from "../../utils/surface.js";
5
+ const ActionBar = React.forwardRef(function ActionBar2({ message, className, children, "aria-label": ariaLabel, ...props }, ref) {
6
+ return /* @__PURE__ */ jsxs(
7
+ "div",
8
+ {
9
+ ref,
10
+ role: "region",
11
+ "aria-label": ariaLabel ?? (typeof message === "string" ? message : void 0),
12
+ className: cn(
13
+ floatingSurface,
14
+ "sticky bottom-4 z-10 flex flex-wrap items-center gap-3 px-4 py-2",
15
+ className
16
+ ),
17
+ ...props,
18
+ children: [
19
+ message !== void 0 && /* @__PURE__ */ jsx("span", { "aria-live": "polite", className: "me-auto text-label-lg text-[var(--color-on-surface)]", children: message }),
20
+ /* @__PURE__ */ jsx("div", { className: cn("flex flex-wrap items-center gap-2", message === void 0 && "ms-auto"), children })
21
+ ]
22
+ }
23
+ );
24
+ });
25
+ export {
26
+ ActionBar
27
+ };
@@ -0,0 +1,2 @@
1
+ export { ActionBar } from './ActionBar.js';
2
+ export type { ActionBarProps } from './ActionBar.js';
@@ -0,0 +1,4 @@
1
+ import { ActionBar } from "./ActionBar.js";
2
+ export {
3
+ ActionBar
4
+ };
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ export interface ResizablePanelsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
3
+ /** Side by side (`horizontal`) or stacked (`vertical`). @default 'horizontal' */
4
+ direction?: 'horizontal' | 'vertical';
5
+ /** One percentage per panel, adding up to 100. Persist them yourself. */
6
+ sizes?: number[];
7
+ defaultSizes?: number[];
8
+ onSizesChange?: (sizes: number[]) => void;
9
+ /** Smallest size per panel, in percent. @default 10 each */
10
+ minSizes?: number[];
11
+ /** Names each separator: "Resize panels" by default. */
12
+ handleLabel?: string;
13
+ /** The panels; a separator goes between each pair. */
14
+ children: React.ReactNode;
15
+ }
16
+ /**
17
+ * Panels with draggable separators (ARIA window splitter). Arrow keys move a
18
+ * focused separator by 5%, Home/End to its limits, and Enter resets the pair.
19
+ */
20
+ export declare function ResizablePanels({ direction, sizes: sizesProp, defaultSizes, onSizesChange, minSizes, handleLabel, className, children, ...props }: ResizablePanelsProps): React.JSX.Element;
@@ -0,0 +1,121 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { cn } from "../../utils/cn.js";
5
+ import { useControllableState } from "../../hooks/useControllableState.js";
6
+ import { useLocale, useNexubMessages } from "../NexubProvider/NexubProvider.js";
7
+ const STEP = 5;
8
+ function ResizablePanels({
9
+ direction = "horizontal",
10
+ sizes: sizesProp,
11
+ defaultSizes,
12
+ onSizesChange,
13
+ minSizes,
14
+ handleLabel,
15
+ className,
16
+ children,
17
+ ...props
18
+ }) {
19
+ const t = useNexubMessages();
20
+ const { dir } = useLocale();
21
+ const panels = React.Children.toArray(children);
22
+ const n = panels.length;
23
+ const even = Array.from({ length: n }, () => 100 / n);
24
+ const initial = defaultSizes ?? even;
25
+ const [sizes = even, setSizes] = useControllableState({
26
+ value: sizesProp,
27
+ defaultValue: initial,
28
+ onChange: onSizesChange
29
+ });
30
+ const rootRef = React.useRef(null);
31
+ const baseId = React.useId();
32
+ const horizontal = direction === "horizontal";
33
+ const min = (i) => minSizes?.[i] ?? 10;
34
+ const resize = (current, i, to) => {
35
+ const pair = current[i] + current[i + 1];
36
+ const a = Math.min(pair - min(i + 1), Math.max(min(i), to));
37
+ const next = [...current];
38
+ next[i] = Math.round(a * 100) / 100;
39
+ next[i + 1] = Math.round((pair - a) * 100) / 100;
40
+ setSizes(next);
41
+ };
42
+ const startDrag = (i, e) => {
43
+ const root = rootRef.current;
44
+ if (!root) return;
45
+ e.preventDefault();
46
+ const rect = root.getBoundingClientRect();
47
+ const total = horizontal ? rect.width : rect.height;
48
+ const origin = horizontal ? e.clientX : e.clientY;
49
+ const start = [...sizes];
50
+ const flip = horizontal && dir === "rtl" ? -1 : 1;
51
+ const onMove = (ev) => {
52
+ const pos = horizontal ? ev.clientX : ev.clientY;
53
+ resize(start, i, start[i] + (pos - origin) * flip / total * 100);
54
+ };
55
+ const onUp = () => {
56
+ window.removeEventListener("pointermove", onMove);
57
+ window.removeEventListener("pointerup", onUp);
58
+ };
59
+ window.addEventListener("pointermove", onMove);
60
+ window.addEventListener("pointerup", onUp);
61
+ };
62
+ const onKeyDown = (i, e) => {
63
+ const fwd = horizontal ? dir === "rtl" ? "ArrowLeft" : "ArrowRight" : "ArrowDown";
64
+ const back = horizontal ? dir === "rtl" ? "ArrowRight" : "ArrowLeft" : "ArrowUp";
65
+ const pair = sizes[i] + sizes[i + 1];
66
+ let to;
67
+ if (e.key === fwd) to = sizes[i] + STEP;
68
+ else if (e.key === back) to = sizes[i] - STEP;
69
+ else if (e.key === "Home") to = min(i);
70
+ else if (e.key === "End") to = pair - min(i + 1);
71
+ else if (e.key === "Enter") to = initial[i] / (initial[i] + initial[i + 1]) * pair;
72
+ if (to === void 0) return;
73
+ e.preventDefault();
74
+ resize(sizes, i, to);
75
+ };
76
+ return /* @__PURE__ */ jsx(
77
+ "div",
78
+ {
79
+ ref: rootRef,
80
+ className: cn("flex min-h-0 min-w-0", horizontal ? "flex-row" : "flex-col", className),
81
+ ...props,
82
+ children: panels.map((panel, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
83
+ /* @__PURE__ */ jsx(
84
+ "div",
85
+ {
86
+ id: `${baseId}-${i}`,
87
+ ref: (el) => {
88
+ if (el) el.style.flex = `${sizes[i] ?? 0} 1 0px`;
89
+ },
90
+ className: "min-h-0 min-w-0 overflow-auto",
91
+ children: panel
92
+ }
93
+ ),
94
+ i < n - 1 && /* @__PURE__ */ jsx(
95
+ "div",
96
+ {
97
+ role: "separator",
98
+ tabIndex: 0,
99
+ "aria-label": handleLabel ?? t.resizePanels,
100
+ "aria-controls": `${baseId}-${i}`,
101
+ "aria-orientation": horizontal ? "vertical" : "horizontal",
102
+ "aria-valuenow": Math.round(sizes[i]),
103
+ "aria-valuemin": min(i),
104
+ "aria-valuemax": Math.round(sizes[i] + sizes[i + 1] - min(i + 1)),
105
+ onPointerDown: (e) => startDrag(i, e),
106
+ onKeyDown: (e) => onKeyDown(i, e),
107
+ className: cn(
108
+ "relative shrink-0 touch-none bg-[var(--color-outline-variant)] outline-none",
109
+ // A wider invisible hit area around the 1px line.
110
+ horizontal ? "w-px cursor-col-resize before:absolute before:-inset-x-1.5 before:inset-y-0" : "h-px cursor-row-resize before:absolute before:inset-x-0 before:-inset-y-1.5",
111
+ "hover:bg-[var(--color-primary)] focus-visible:bg-[var(--color-primary)] focus-visible:shadow-[0_0_0_1px_var(--color-primary)]"
112
+ )
113
+ }
114
+ )
115
+ ] }, i))
116
+ }
117
+ );
118
+ }
119
+ export {
120
+ ResizablePanels
121
+ };
@@ -0,0 +1,2 @@
1
+ export { ResizablePanels } from './ResizablePanels.js';
2
+ export type { ResizablePanelsProps } from './ResizablePanels.js';
@@ -0,0 +1,4 @@
1
+ import { ResizablePanels } from "./ResizablePanels.js";
2
+ export {
3
+ ResizablePanels
4
+ };
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ export interface StepperStep {
3
+ id: string;
4
+ label: string;
5
+ description?: string;
6
+ }
7
+ export interface StepperProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {
8
+ steps: StepperStep[];
9
+ /** Index of the step being shown. */
10
+ current: number;
11
+ /** Indexes of finished steps. @default every step before `current` */
12
+ completed?: number[];
13
+ /**
14
+ * Makes steps clickable. Linear by default: finished steps, the current one
15
+ * and the first unfinished one can be reached; the rest wait.
16
+ */
17
+ onStepChange?: (index: number) => void;
18
+ /** Any step can be reached. */
19
+ nonLinear?: boolean;
20
+ /** @default 'horizontal' */
21
+ orientation?: 'horizontal' | 'vertical';
22
+ }
23
+ /**
24
+ * Progress through a multi-step flow. Validate each step (a `Form` per step
25
+ * works well) and move `current` forward from its submit.
26
+ */
27
+ export declare const Stepper: React.ForwardRefExoticComponent<StepperProps & React.RefAttributes<HTMLElement>>;
@@ -0,0 +1,74 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Check } from "@nexub/icons";
5
+ import { cn } from "../../utils/cn.js";
6
+ import { useNexubMessages } from "../NexubProvider/NexubProvider.js";
7
+ const Stepper = React.forwardRef(function Stepper2({ steps, current, completed: completedProp, onStepChange, nonLinear = false, orientation = "horizontal", className, ...props }, ref) {
8
+ const t = useNexubMessages();
9
+ const completed = new Set(completedProp ?? steps.slice(0, current).map((_, i) => i));
10
+ const firstOpen = steps.findIndex((_, i) => !completed.has(i));
11
+ const vertical = orientation === "vertical";
12
+ return /* @__PURE__ */ jsx("nav", { ref, className, ...props, children: /* @__PURE__ */ jsx("ol", { className: cn("m-0 flex list-none p-0", vertical ? "flex-col" : "flex-row items-start"), children: steps.map((step, i) => {
13
+ const done = completed.has(i);
14
+ const isCurrent = i === current;
15
+ const reachable = Boolean(onStepChange) && !isCurrent && (nonLinear || done || i === firstOpen);
16
+ const marker = /* @__PURE__ */ jsx(
17
+ "span",
18
+ {
19
+ "aria-hidden": "true",
20
+ className: cn(
21
+ "inline-flex size-8 shrink-0 items-center justify-center rounded-full text-label-md font-semibold",
22
+ done && !isCurrent ? "bg-[var(--color-primary)] text-[var(--color-on-primary)]" : isCurrent ? "border-2 border-[var(--color-primary)] bg-[var(--color-surface)] text-[var(--color-primary)]" : "border-2 border-[var(--color-outline-variant)] bg-[var(--color-surface)] text-[var(--color-on-surface-muted)]"
23
+ ),
24
+ children: done && !isCurrent ? /* @__PURE__ */ jsx(Check, { size: "xs" }) : i + 1
25
+ }
26
+ );
27
+ const text = /* @__PURE__ */ jsxs("span", { className: cn("flex min-w-0 flex-col gap-0.5", vertical ? "items-start text-start" : "items-center text-center"), children: [
28
+ /* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
29
+ t.stepOf(i + 1, steps.length),
30
+ ":"
31
+ ] }),
32
+ " ",
33
+ /* @__PURE__ */ jsx("span", { className: cn("text-label-lg font-medium", isCurrent || done ? "text-[var(--color-on-surface)]" : "text-[var(--color-on-surface-muted)]"), children: step.label }),
34
+ done && /* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
35
+ ", ",
36
+ t.stepCompleted
37
+ ] }),
38
+ step.description && /* @__PURE__ */ jsx("span", { className: "text-body-sm text-[var(--color-on-surface-muted)]", children: step.description })
39
+ ] });
40
+ const body = vertical ? /* @__PURE__ */ jsxs("span", { className: "flex gap-3", children: [
41
+ marker,
42
+ /* @__PURE__ */ jsx("span", { className: "pt-1", children: text })
43
+ ] }) : /* @__PURE__ */ jsxs("span", { className: "flex flex-col items-center gap-2 text-center", children: [
44
+ marker,
45
+ text
46
+ ] });
47
+ return /* @__PURE__ */ jsx(
48
+ "li",
49
+ {
50
+ "aria-current": isCurrent ? "step" : void 0,
51
+ className: cn(
52
+ "relative flex",
53
+ vertical ? "pb-6 last:pb-0" : "flex-1 justify-center",
54
+ // Connector to the next step.
55
+ i < steps.length - 1 && (vertical ? "after:absolute after:start-4 after:top-9 after:bottom-1 after:w-px" : "after:absolute after:top-4 after:start-[calc(50%+1.25rem)] after:end-[calc(-50%+1.25rem)] after:h-px"),
56
+ i < steps.length - 1 && (done ? "after:bg-[var(--color-primary)]" : "after:bg-[var(--color-outline-variant)]")
57
+ ),
58
+ children: reachable ? /* @__PURE__ */ jsx(
59
+ "button",
60
+ {
61
+ type: "button",
62
+ onClick: () => onStepChange(i),
63
+ className: "rounded-shape-control p-1 hover:bg-[var(--color-surface-container-high)]",
64
+ children: body
65
+ }
66
+ ) : /* @__PURE__ */ jsx("span", { className: "p-1", children: body })
67
+ },
68
+ step.id
69
+ );
70
+ }) }) });
71
+ });
72
+ export {
73
+ Stepper
74
+ };
@@ -0,0 +1,2 @@
1
+ export { Stepper } from './Stepper.js';
2
+ export type { StepperProps, StepperStep } from './Stepper.js';
@@ -0,0 +1,4 @@
1
+ import { Stepper } from "./Stepper.js";
2
+ export {
3
+ Stepper
4
+ };
package/dist/index.d.ts CHANGED
@@ -228,6 +228,12 @@ export { EventCalendar } from './components/EventCalendar/index.js';
228
228
  export type { EventCalendarProps, EventCalendarView, CalendarEvent, EventTone } from './components/EventCalendar/index.js';
229
229
  export { TreeView } from './components/TreeView/index.js';
230
230
  export type { TreeViewProps, TreeNode } from './components/TreeView/index.js';
231
+ export { ResizablePanels } from './components/ResizablePanels/index.js';
232
+ export type { ResizablePanelsProps } from './components/ResizablePanels/index.js';
233
+ export { Stepper } from './components/Stepper/index.js';
234
+ export type { StepperProps, StepperStep } from './components/Stepper/index.js';
235
+ export { ActionBar } from './components/ActionBar/index.js';
236
+ export type { ActionBarProps } from './components/ActionBar/index.js';
231
237
  export type { OTPInputProps } from './components/OTPInput/index.js';
232
238
  export { DatePicker } from './components/DatePicker/index.js';
233
239
  export type { DatePickerProps } from './components/DatePicker/index.js';
package/dist/index.js CHANGED
@@ -128,6 +128,9 @@ import { TimePicker } from "./components/TimePicker/index.js";
128
128
  import { DateTimePicker } from "./components/DateTimePicker/index.js";
129
129
  import { EventCalendar } from "./components/EventCalendar/index.js";
130
130
  import { TreeView } from "./components/TreeView/index.js";
131
+ import { ResizablePanels } from "./components/ResizablePanels/index.js";
132
+ import { Stepper } from "./components/Stepper/index.js";
133
+ import { ActionBar } from "./components/ActionBar/index.js";
131
134
  import { DatePicker } from "./components/DatePicker/index.js";
132
135
  import { DateRangePicker } from "./components/DateRangePicker/index.js";
133
136
  import { todayIn } from "./components/DateRangePicker/index.js";
@@ -135,6 +138,7 @@ import { ThemeProvider, ThemeScript, useTheme } from "./components/ThemeProvider
135
138
  import { Fade, Slide, Scale, Collapse, ListTransition, SkeletonSwap, usePrefersReducedMotion, Reveal, Float, Marquee } from "./components/Motion/index.js";
136
139
  export {
137
140
  Accordion,
141
+ ActionBar,
138
142
  Alert,
139
143
  AlertDialog,
140
144
  Amount,
@@ -239,6 +243,7 @@ export {
239
243
  RadioCardGroup,
240
244
  RadioGroup,
241
245
  Rating,
246
+ ResizablePanels,
242
247
  Reveal,
243
248
  SavedViews,
244
249
  Scale,
@@ -262,6 +267,7 @@ export {
262
267
  Spinner,
263
268
  SplitButton,
264
269
  Stack,
270
+ Stepper,
265
271
  StreamingText,
266
272
  Switch,
267
273
  Table,