@rackbops/ui-react 0.2.38 → 0.2.40

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,38 @@
1
+ import { type HTMLAttributes, type RefAttributes } from "react";
2
+ import type { SemanticVariant } from "./feedback.js";
3
+ export interface ToastProps extends HTMLAttributes<HTMLDivElement>, RefAttributes<HTMLDivElement> {
4
+ /** Maps to `.rb-toast--{variant}` and picks the live-region role: `info`/`success`
5
+ * announce politely (`role="status"`), `warning`/`danger` assertively
6
+ * (`role="alert"`). Omitted, the toast is polite and carries no variant class. */
7
+ variant?: SemanticVariant;
8
+ /**
9
+ * When provided, renders a keyboard-focusable dismiss button (`.rb-toast__close`)
10
+ * that calls this. Omit for a toast the consumer removes on its own timer -- the
11
+ * primitive owns no queue or timer (the consumer does, as artifact-console's
12
+ * `useToasts` already did). A toast is never the only place an error is reported.
13
+ */
14
+ onDismiss?: () => void;
15
+ /** `aria-label` for the dismiss button; default `"Dismiss"`. */
16
+ dismissLabel?: string;
17
+ }
18
+ /**
19
+ * A transient notice (`.rb-toast`), rendered inside a `ToastRegion` stack. Its
20
+ * live-region role is chosen by `variant` (see above), so it announces once on
21
+ * insertion; the region itself is not a live region (that would double-announce).
22
+ *
23
+ * Entrance is a CSS transition, not a keyframe: the toast mounts with a
24
+ * `data-rb-enter` from-state that is cleared after the first paint so the
25
+ * transition plays. Under `prefers-reduced-motion` the per-theme
26
+ * `--rb-transition: 0s` token collapse makes it appear instantly -- it loses only
27
+ * its transition, nothing else.
28
+ */
29
+ export declare const Toast: import("react").ForwardRefExoticComponent<Omit<ToastProps, "ref"> & RefAttributes<HTMLDivElement>>;
30
+ export interface ToastRegionProps extends HTMLAttributes<HTMLDivElement>, RefAttributes<HTMLDivElement> {
31
+ }
32
+ /**
33
+ * The fixed stacking region (`.rb-toast-region`) that holds Toasts. Deliberately
34
+ * NOT a live region: each `Toast` announces itself (role by variant), and a polite
35
+ * region wrapping assertive children double-announces on some screen readers
36
+ * (the rule artifact-console's hand-rolled `ToastPortal` already documented).
37
+ */
38
+ export declare const ToastRegion: import("react").ForwardRefExoticComponent<Omit<ToastRegionProps, "ref"> & RefAttributes<HTMLDivElement>>;
package/dist/Toast.js ADDED
@@ -0,0 +1,46 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useEffect, useState, } from "react";
3
+ import { cx } from "./cx.js";
4
+ // Role by urgency (#211): info/success are polite confirmations ("Saved"),
5
+ // warning/danger interrupt. A variantless toast defaults to the polite role.
6
+ const ASSERTIVE = new Set(["warning", "danger"]);
7
+ /**
8
+ * A transient notice (`.rb-toast`), rendered inside a `ToastRegion` stack. Its
9
+ * live-region role is chosen by `variant` (see above), so it announces once on
10
+ * insertion; the region itself is not a live region (that would double-announce).
11
+ *
12
+ * Entrance is a CSS transition, not a keyframe: the toast mounts with a
13
+ * `data-rb-enter` from-state that is cleared after the first paint so the
14
+ * transition plays. Under `prefers-reduced-motion` the per-theme
15
+ * `--rb-transition: 0s` token collapse makes it appear instantly -- it loses only
16
+ * its transition, nothing else.
17
+ */
18
+ export const Toast = forwardRef(function Toast({ variant, onDismiss, dismissLabel = "Dismiss", className, children, ...rest }, ref) {
19
+ const [entering, setEntering] = useState(true);
20
+ useEffect(() => {
21
+ // A single frame after the first paint, drop the from-state so the CSS
22
+ // transition runs. cancelAnimationFrame on unmount so a toast removed before
23
+ // the frame fires never calls setState after unmount. Where there is no frame
24
+ // scheduler (jsdom, SSR-hydration shims, non-visual runtimes -- none of which
25
+ // paint anyway), show the toast immediately instead of throwing.
26
+ if (typeof requestAnimationFrame !== "function") {
27
+ setEntering(false);
28
+ return;
29
+ }
30
+ const id = requestAnimationFrame(() => setEntering(false));
31
+ return () => cancelAnimationFrame(id);
32
+ }, []);
33
+ const role = variant && ASSERTIVE.has(variant) ? "alert" : "status";
34
+ return (_jsxs("div", { ref: ref, role: role, "data-rb-enter": entering ? "" : undefined, className: cx("rb-toast", variant && `rb-toast--${variant}`, className), ...rest, children: [children, onDismiss && (_jsx("button", { type: "button", className: "rb-toast__close", "aria-label": dismissLabel, onClick: onDismiss, children: "×" }))] }));
35
+ });
36
+ Toast.displayName = "Toast";
37
+ /**
38
+ * The fixed stacking region (`.rb-toast-region`) that holds Toasts. Deliberately
39
+ * NOT a live region: each `Toast` announces itself (role by variant), and a polite
40
+ * region wrapping assertive children double-announces on some screen readers
41
+ * (the rule artifact-console's hand-rolled `ToastPortal` already documented).
42
+ */
43
+ export const ToastRegion = forwardRef(function ToastRegion({ className, ...rest }, ref) {
44
+ return _jsx("div", { ref: ref, className: cx("rb-toast-region", className), ...rest });
45
+ });
46
+ ToastRegion.displayName = "ToastRegion";
@@ -2,6 +2,12 @@ import { type HTMLAttributes, type ProgressHTMLAttributes, type ReactNode, type
2
2
  export type SemanticVariant = "info" | "success" | "warning" | "danger";
3
3
  export interface BadgeProps extends HTMLAttributes<HTMLSpanElement>, RefAttributes<HTMLSpanElement> {
4
4
  variant?: SemanticVariant;
5
+ /**
6
+ * Size. "md" maps to .rb-badge--md for a row-text-sized pill (inside a
7
+ * .rb-table row, next to 13px cell text); "sm" is the default and the
8
+ * compact chip every existing consumer already renders.
9
+ */
10
+ size?: "sm" | "md";
5
11
  }
6
12
  export declare const Badge: import("react").ForwardRefExoticComponent<Omit<BadgeProps, "ref"> & RefAttributes<HTMLSpanElement>>;
7
13
  export interface AlertProps extends Omit<HTMLAttributes<HTMLDivElement>, "title">, RefAttributes<HTMLDivElement> {
package/dist/feedback.js CHANGED
@@ -7,8 +7,8 @@ function styled(tag, cls, attrs = {}) {
7
7
  return createElement(tag, { ref, ...attrs, className: cx(cls, className), ...rest });
8
8
  });
9
9
  }
10
- export const Badge = forwardRef(function Badge({ variant, className, ...rest }, ref) {
11
- return (_jsx("span", { ref: ref, className: cx("rb-badge", variant && `rb-badge--${variant}`, className), ...rest }));
10
+ export const Badge = forwardRef(function Badge({ variant, size = "sm", className, ...rest }, ref) {
11
+ return (_jsx("span", { ref: ref, className: cx("rb-badge", variant && `rb-badge--${variant}`, size === "md" && "rb-badge--md", className), ...rest }));
12
12
  });
13
13
  Badge.displayName = "Badge";
14
14
  /** A status banner (.rb-alert); `role="alert"` announces it to screen readers on mount/update. */
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { NavRail, type NavRailProps, type NavRailItem } from "./NavRail.js";
6
6
  export { Input, Textarea, Select, Label, Field, Checkbox, Radio, Switch, type InputProps, type TextareaProps, type SelectProps, type LabelProps, type FieldProps, type ChoiceProps, } from "./form.js";
7
7
  export { Badge, Alert, Progress, Spinner, type BadgeProps, type AlertProps, type ProgressProps, type SpinnerProps, type SemanticVariant, } from "./feedback.js";
8
8
  export { Dialog, type DialogProps } from "./Dialog.js";
9
+ export { Toast, ToastRegion, type ToastProps, type ToastRegionProps } from "./Toast.js";
9
10
  export { Tabs, type TabsProps, type TabItem } from "./Tabs.js";
10
11
  export { Stepper, type StepperProps, type StepperStep } from "./Stepper.js";
11
12
  export { DataTable, type DataTableProps, type DataTableColumn } from "./DataTable.js";
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export { NavRail } from "./NavRail.js";
6
6
  export { Input, Textarea, Select, Label, Field, Checkbox, Radio, Switch, } from "./form.js";
7
7
  export { Badge, Alert, Progress, Spinner, } from "./feedback.js";
8
8
  export { Dialog } from "./Dialog.js";
9
+ export { Toast, ToastRegion } from "./Toast.js";
9
10
  export { Tabs } from "./Tabs.js";
10
11
  export { Stepper } from "./Stepper.js";
11
12
  export { DataTable } from "./DataTable.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rackbops/ui-react",
3
- "version": "0.2.38",
3
+ "version": "0.2.40",
4
4
  "description": "React components styled by @rackbops/styles rackbops themes.",
5
5
  "license": "MIT",
6
6
  "repository": {