@minimalstuff/ui 5.3.0 → 5.5.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.
package/README.md CHANGED
@@ -44,6 +44,30 @@ export function Root() {
44
44
 
45
45
  For French, pass the bundled preset: `<UIProvider labels={FRENCH_UI_LABELS}>` (import `FRENCH_UI_LABELS` from `@minimalstuff/ui`).
46
46
 
47
+ ### Toasts
48
+
49
+ Mount `<Toaster />` once at the app root, then call `toast()` from anywhere (event handlers, services, outside React).
50
+
51
+ ```tsx
52
+ import { Toaster, toast } from '@minimalstuff/ui';
53
+
54
+ export function Root() {
55
+ return (
56
+ <>
57
+ <App />
58
+ <Toaster position="bottom-right" />
59
+ </>
60
+ );
61
+ }
62
+
63
+ toast.success('Saved');
64
+ toast.error('Could not save', { description: 'Check your connection.' });
65
+ ```
66
+
67
+ Only the first mounted `Toaster` renders. Toasts sit above `Modal` and `Drawer`. Warning and error toasts, and toasts with an action, stay until dismissed, because a Modal's focus trap keeps toasts out of keyboard reach. Press F8 to jump to the toasts and F8 again to return to where you were; Escape closes the focused toast. F8 does nothing while a Modal or Drawer is open. Move the stack with the `--ms-toast-offset-bottom` and `--ms-toast-offset-top` CSS custom properties (default: 1rem plus the safe-area inset).
68
+
69
+ `ToastProvider` and `useToast()` still work but are deprecated: mount `<Toaster />` and call `toast()` instead.
70
+
47
71
  ### Dark mode
48
72
 
49
73
  Dark styles apply when `<html>` has the `dark` class. `useThemeStore` (and the `ThemeToggle` built on it) sets that class from the `light`, `dark` or `system` preference and keeps it in `localStorage`.
package/dist/index.d.ts CHANGED
@@ -14,6 +14,57 @@ import { RefObject } from 'react';
14
14
  import { StoreApi } from 'zustand';
15
15
  import { UseBoundStore } from 'zustand';
16
16
 
17
+ export declare function Alert({ tone, title, icon, children, actions, onDismiss, dismissLabel, radius, unstyled, className, ...props }: Readonly<AlertProps>): JSX.Element;
18
+
19
+ export declare interface AlertProps extends Omit<ComponentPropsWithRef<'div'>, 'title' | 'role'> {
20
+ /** Colour and default icon of the alert. Defaults to `'info'`. */
21
+ tone?: AlertTone;
22
+ /**
23
+ * Bold first line, rendered in a `<div>` and not a heading. For a real
24
+ * section heading, pass an `<h2>` to `<h6>` element.
25
+ */
26
+ title?: ReactNode;
27
+ /**
28
+ * UnoCSS icon class replacing the tone's default icon, or `false` for none.
29
+ * The icon is decorative (`aria-hidden`): state the tone in the text, never
30
+ * by colour alone.
31
+ */
32
+ icon?: string | false;
33
+ children?: ReactNode;
34
+ /**
35
+ * Buttons shown under the text. Recommended: a primary `Button`
36
+ * `variant="solid"` and a secondary `variant="outline"`, both with the
37
+ * tone's `color` (info: `primary`, success: `success`, warning: `warning`,
38
+ * danger: `danger`). Avoid `ghost` and `subtle`: a subtle fill equals the
39
+ * alert fill and is invisible at rest.
40
+ */
41
+ actions?: ReactNode;
42
+ /**
43
+ * Shows the close button and is called when it is clicked. The consumer
44
+ * moves focus once the alert is removed (for example to the next sensible
45
+ * element).
46
+ */
47
+ onDismiss?: () => void;
48
+ /** Accessible name of the close button. Defaults to `labels.close`. */
49
+ dismissLabel?: string;
50
+ /**
51
+ * No role by default: right for a box present from the first render.
52
+ * Use `role="alert"` for an error inserted after a user action, and
53
+ * `role="note"` for an aside. There is no `role="status"`: announce changes
54
+ * through a toast or a live region of your own.
55
+ */
56
+ role?: 'alert' | 'note';
57
+ /** Corner radius. `full` caps at `lg`. Defaults to `lg`. */
58
+ radius?: Radius;
59
+ /**
60
+ * Strips surface, border, padding, radius, font size, tone colours and the
61
+ * default icon. Keeps the layout, the bold title and the actions row.
62
+ */
63
+ unstyled?: boolean;
64
+ }
65
+
66
+ export declare type AlertTone = 'info' | 'success' | 'warning' | 'danger';
67
+
17
68
  /**
18
69
  * A thin application bar with a `start` slot on the left, a centered `title`
19
70
  * and an `end` slot on the right. It is a plain `<header>` (the `banner`
@@ -123,31 +174,31 @@ export { ButtonColor }
123
174
 
124
175
  export declare type ButtonProps = Omit<ComponentPropsWithRef<'button'>, 'children'> & {
125
176
  children: ReactNode;
126
- size?: ControlSize;
127
- className?: string;
128
- fullWidth?: boolean;
177
+ size?: ControlSize | undefined;
178
+ className?: string | undefined;
179
+ fullWidth?: boolean | undefined;
129
180
  /**
130
181
  * Shows a spinner, marks the button busy and blocks activation (click, Enter,
131
182
  * Space, form submit). Unlike `disabled`, the button keeps focus and stays in
132
183
  * the tab order, exposed as `aria-disabled`.
133
184
  */
134
- loading?: boolean;
185
+ loading?: boolean | undefined;
135
186
  /**
136
187
  * Turns the button into a toggle: sets `aria-pressed` and a pressed look (dark fill and inset ring).
137
188
  * Leave it `undefined` for a regular button (no attribute).
138
189
  */
139
- pressed?: boolean;
140
- startIcon?: string;
141
- endIcon?: string;
190
+ pressed?: boolean | undefined;
191
+ startIcon?: string | undefined;
192
+ endIcon?: string | undefined;
142
193
  } & ButtonStyle;
143
194
 
144
195
  declare type ButtonStyle = {
145
196
  unstyled: true;
146
197
  } | {
147
- unstyled?: false;
148
- variant?: ButtonVariant;
149
- color?: ButtonColor;
150
- radius?: Radius;
198
+ unstyled?: false | undefined;
199
+ variant?: ButtonVariant | undefined;
200
+ color?: ButtonColor | undefined;
201
+ radius?: Radius | undefined;
151
202
  };
152
203
 
153
204
  export declare type ButtonVariant = 'solid' | 'outline' | 'ghost' | 'subtle';
@@ -479,23 +530,23 @@ export declare function IconButton(iconButtonProps: Readonly<IconButtonProps>):
479
530
  export declare type IconButtonProps = ComponentPropsWithRef<'button'> & {
480
531
  icon: string;
481
532
  'aria-label': string;
482
- size?: ControlSize;
533
+ size?: ControlSize | undefined;
483
534
  children?: ReactNode;
484
- tooltip?: IconButtonTooltip;
535
+ tooltip?: IconButtonTooltip | undefined;
485
536
  /**
486
537
  * Turns the button into a toggle: sets `aria-pressed` and a pressed look (dark fill and inset ring).
487
538
  * Leave it `undefined` for a regular button (no attribute).
488
539
  */
489
- pressed?: boolean;
540
+ pressed?: boolean | undefined;
490
541
  } & IconButtonStyle;
491
542
 
492
543
  declare type IconButtonStyle = {
493
544
  unstyled: true;
494
545
  } | {
495
- unstyled?: false;
496
- variant?: ButtonVariant;
497
- color?: ButtonColor;
498
- radius?: Radius;
546
+ unstyled?: false | undefined;
547
+ variant?: ButtonVariant | undefined;
548
+ color?: ButtonColor | undefined;
549
+ radius?: Radius | undefined;
499
550
  };
500
551
 
501
552
  /**
@@ -852,6 +903,71 @@ export declare interface MultiComboboxProps {
852
903
 
853
904
  export declare type OptionLabelOverflow = 'wrap' | 'wrap-active' | 'truncate';
854
905
 
906
+ /**
907
+ * A non-modal panel anchored to `trigger` that holds free content (radio
908
+ * groups, a segmented control, a disclosure...). Unlike `Menu`, clicking
909
+ * inside never closes it: it closes on a second trigger click, Escape, a
910
+ * pointer down outside, or focus leaving the panel and the trigger.
911
+ *
912
+ * Focus moves into the panel on open and returns to the trigger after
913
+ * Escape or a close caused from inside; after an outside pointer down it
914
+ * stays on what the user clicked. Escape calls `event.preventDefault()`, so
915
+ * inside a `Modal` only the popover closes.
916
+ */
917
+ export declare function Popover({ trigger, children, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, isOpen: controlledIsOpen, defaultOpen, onOpenChange, side, align, initialFocusRef, radius, unstyled, className, panelClassName, disabled, ref, }: Readonly<PopoverProps>): JSX.Element;
918
+
919
+ export declare type PopoverAlign = 'start' | 'center' | 'end';
920
+
921
+ declare interface PopoverBaseProps {
922
+ /** Cloned with a toggling `onClick`, `aria-haspopup="dialog"`, `aria-expanded` and `aria-controls`. */
923
+ trigger: ReactElement;
924
+ /** Free content: the panel stays open while the user interacts with it. */
925
+ children: ReactNode;
926
+ /** Controlled open state. While provided, the owner drives every change through `onOpenChange`. */
927
+ isOpen?: boolean;
928
+ defaultOpen?: boolean;
929
+ /** Fires once per open or close, whatever the cause (trigger, Escape, outside pointer, focus leaving, `disabled`). */
930
+ onOpenChange?: (isOpen: boolean) => void;
931
+ side?: PopoverSide;
932
+ align?: PopoverAlign;
933
+ /** Focused on open instead of the first tabbable element of the panel. */
934
+ initialFocusRef?: RefObject<HTMLElement | null>;
935
+ radius?: Radius;
936
+ className?: string;
937
+ /**
938
+ * Strips the panel's visual styling (border, background, shadow, blur,
939
+ * padding, radius, width bounds and the open/close animation). Positioning
940
+ * and the keyboard and focus handling stay. `radius` is ignored.
941
+ */
942
+ unstyled?: boolean;
943
+ /**
944
+ * Styles the floating panel (`role="dialog"`), with or without `unstyled`.
945
+ * Its position comes from inline floating styles: don't set
946
+ * `position`, `top` or `left` on it.
947
+ */
948
+ panelClassName?: string;
949
+ /**
950
+ * Keeps the popover closed (and closes it if open). The trigger itself is
951
+ * left alone: mark it `aria-disabled` or `disabled` yourself.
952
+ */
953
+ disabled?: boolean;
954
+ /** Attaches to the wrapper `<span>` around `trigger`, alongside the popover's own internal ref. */
955
+ ref?: Ref<HTMLSpanElement>;
956
+ }
957
+
958
+ declare type PopoverNameProps = {
959
+ 'aria-label': string;
960
+ 'aria-labelledby'?: string;
961
+ } | {
962
+ 'aria-labelledby': string;
963
+ 'aria-label'?: string;
964
+ };
965
+
966
+ /** The panel is a `role="dialog"`: it needs `aria-label` or `aria-labelledby`. */
967
+ export declare type PopoverProps = PopoverBaseProps & PopoverNameProps;
968
+
969
+ export declare type PopoverSide = 'top' | 'bottom' | 'left' | 'right';
970
+
855
971
  export declare type RadioOption = ChoiceOption;
856
972
 
857
973
  export declare function RadioOptions({ options, orientation, value, defaultValue, onChange, name: nameProp, label, error, required, disabled, radius, unstyled, className, wrapperClassName, id, 'aria-describedby': callerDescribedBy, ...props }: Readonly<RadioOptionsProps>): JSX.Element;
@@ -1132,6 +1248,128 @@ export declare interface ThemeToggleProps {
1132
1248
  tooltip?: IconButtonTooltip;
1133
1249
  }
1134
1250
 
1251
+ /**
1252
+ * Shows a toast from anywhere (event handlers, services, outside React) and
1253
+ * returns its id. `toast(message)` shows an info toast; use `toast.success`,
1254
+ * `toast.warning` and `toast.error` for the other tones, and `toast.dismiss`
1255
+ * to close one or all. Mount `<Toaster />` once at the app root to render
1256
+ * them. Calling it on the server does nothing but return the id.
1257
+ */
1258
+ export declare const toast: ToastFunction;
1259
+
1260
+ export declare interface ToastAction {
1261
+ label: string;
1262
+ /** Runs on click, then the toast is dismissed. */
1263
+ onClick: () => void;
1264
+ }
1265
+
1266
+ /** @deprecated Use `toast()` instead of `useToast()`. */
1267
+ export declare interface ToastApi {
1268
+ /** Shows a toast and returns its id. */
1269
+ show: (options: Readonly<ToastOptions>) => string;
1270
+ /** Dismisses the toast with this id; an unknown or already dismissed id is ignored. */
1271
+ dismiss: (id: string) => void;
1272
+ }
1273
+
1274
+ /**
1275
+ * Renders the toasts shown with `toast()`. Mount it once at the app root; only
1276
+ * the first mounted Toaster renders, any other warns in development and
1277
+ * renders nothing. It renders nothing on the server and on the first client
1278
+ * render. Toasts sit above `Modal` and `Drawer` (`z-[60]`) and never block
1279
+ * the page outside themselves. The stack scrolls when it is taller than the
1280
+ * viewport.
1281
+ *
1282
+ * Press F8 to jump to the toasts and F8 again to go back to where focus was;
1283
+ * Escape closes the focused toast. F8 is inactive while a Modal or Drawer is
1284
+ * open, and when no toast is open.
1285
+ *
1286
+ * While a Modal is open its Tab trap leaves the toasts unreachable by
1287
+ * keyboard. This is why warning and error toasts, and toasts with an action,
1288
+ * stay until dismissed.
1289
+ *
1290
+ * Unmounting the last Toaster empties the toast store in a microtask, so a
1291
+ * `toast()` called in the same synchronous turn right after unmounting it is
1292
+ * dropped.
1293
+ *
1294
+ * Offsets come from two CSS custom properties: `--ms-toast-offset-bottom`
1295
+ * and `--ms-toast-offset-top` (default: 1rem plus the safe-area inset).
1296
+ */
1297
+ export declare function Toaster(props: Readonly<ToasterProps>): JSX.Element | null;
1298
+
1299
+ export declare type ToasterPosition =
1300
+ | 'top-left'
1301
+ | 'top-center'
1302
+ | 'top-right'
1303
+ | 'bottom-left'
1304
+ | 'bottom-center'
1305
+ | 'bottom-right';
1306
+
1307
+ export declare interface ToasterProps {
1308
+ /** Where the stack sits from the `sm` breakpoint up; on phones it spans the full width at the top or the bottom. Defaults to `'bottom-right'`. */
1309
+ position?: ToasterPosition;
1310
+ /** Corner radius of every toast that sets none. `full` caps at `lg`. Defaults to `lg`. */
1311
+ radius?: Radius;
1312
+ /** Strips the library's styling (surface, border, shadow, radius, tone colours, animation, timer bar) from every toast that sets none, keeping layout, behaviour and the 24px minimum size of the close button. */
1313
+ unstyled?: boolean;
1314
+ }
1315
+
1316
+ export declare interface ToastFunction {
1317
+ /** Shows an info toast and returns its id. */
1318
+ (message: string, options?: Readonly<ToastMessageOptions>): string;
1319
+ /** Shows an info toast and returns its id. */
1320
+ info(message: string, options?: Readonly<ToastMessageOptions>): string;
1321
+ /** Shows a success toast and returns its id. */
1322
+ success(message: string, options?: Readonly<ToastMessageOptions>): string;
1323
+ /** Shows a warning toast and returns its id. It stays until dismissed unless a duration is given. */
1324
+ warning(message: string, options?: Readonly<ToastMessageOptions>): string;
1325
+ /** Shows an error toast and returns its id. It stays until dismissed unless a duration is given. */
1326
+ error(message: string, options?: Readonly<ToastMessageOptions>): string;
1327
+ /** Dismisses the toast with this id; an unknown id is ignored. Without id, dismisses every toast. */
1328
+ dismiss(id?: string): void;
1329
+ }
1330
+
1331
+ export declare interface ToastMessageOptions {
1332
+ /** Identifies the toast. Showing a toast with an id already in use replaces that toast in place, restarts its timer and announces it again. */
1333
+ id?: string;
1334
+ /** Secondary text shown under the message. */
1335
+ description?: string;
1336
+ /** Milliseconds before the toast dismisses itself. Defaults to 5000 for info and success; warning, error and any toast with an action stay until dismissed. An explicit value always wins; `0` or `Infinity` keeps the toast. Give a toast with an action a duration only when that action is also available elsewhere in the page. */
1337
+ duration?: number;
1338
+ /** Button shown in the toast; the toast is dismissed after it runs. */
1339
+ action?: ToastAction;
1340
+ }
1341
+
1342
+ /** @deprecated Use `toast()` and its `ToastMessageOptions`. */
1343
+ export declare interface ToastOptions {
1344
+ message: ReactNode;
1345
+ /** Defaults to `'info'`. `'error'` is announced assertively, the others politely. */
1346
+ tone?: ToastTone;
1347
+ /**
1348
+ * Milliseconds before the toast dismisses itself, counted only while it is
1349
+ * neither hovered nor focused. Defaults to 4000 (6000 for `'error'`). `0` or
1350
+ * `Infinity` keeps the toast until it is dismissed.
1351
+ */
1352
+ duration?: number;
1353
+ action?: ToastAction;
1354
+ radius?: Radius;
1355
+ /** Strips the library's visual styling (surface, border, shadow, radius, typography, tone colours, animation), keeping layout, behaviour and the 24px minimum size of the close button. `radius` is ignored. */
1356
+ unstyled?: boolean;
1357
+ }
1358
+
1359
+ /**
1360
+ * @deprecated Mount `<Toaster />` once at the app root and call `toast()`
1361
+ * instead. Renders `children` followed by a default `<Toaster />`.
1362
+ */
1363
+ export declare const ToastProvider: ({ children }: Readonly<ToastProviderProps>) => JSX.Element;
1364
+
1365
+ /** @deprecated Use `ToasterProps` and mount `<Toaster />`. */
1366
+ export declare interface ToastProviderProps {
1367
+ children: ReactNode;
1368
+ }
1369
+
1370
+ /** @deprecated Use the `toast.info`, `toast.success`, `toast.warning` and `toast.error` functions. */
1371
+ export declare type ToastTone = 'info' | 'success' | 'error';
1372
+
1135
1373
  /**
1136
1374
  * A group of related controls with a single tab stop (WAI-ARIA toolbar).
1137
1375
  * Tab enters the toolbar on the last focused item (the first enabled one
@@ -1241,6 +1479,13 @@ export declare interface UILabels {
1241
1479
  * must add it, otherwise the English "Copy" is used.
1242
1480
  */
1243
1481
  copy?: string;
1482
+ /**
1483
+ * Accessible name of the region holding the `ToastProvider` toasts. Optional
1484
+ * like `copy`: the English "Notifications" is used when a label set omits it.
1485
+ */
1486
+ notifications?: string;
1487
+ /** Accessible name of the close button of a toast. Optional: the English "Close notification" is used when omitted. */
1488
+ closeNotification?: string;
1244
1489
  /** Screen-reader announcement of `CharacterCount` near and at the limit. */
1245
1490
  charactersRemaining: (remainingCount: number) => string;
1246
1491
  /** Accessible name of `ThemeToggle` for the current theme. */
@@ -1341,6 +1586,14 @@ export declare type UseKeyboardScrollableReturn = {
1341
1586
 
1342
1587
  export declare const useThemeStore: UseBoundStore<StoreApi<ThemeStore>>;
1343
1588
 
1589
+ /**
1590
+ * @deprecated Call `toast()` from `@minimalstuff/ui` instead, and mount
1591
+ * `<Toaster />` once at the app root. Returns a constant `{ show, dismiss }`
1592
+ * that forwards to the same toast store; it no longer needs a `ToastProvider`
1593
+ * and no longer throws without one.
1594
+ */
1595
+ export declare function useToast(): ToastApi;
1596
+
1344
1597
  /** Wraps `Component` so it only renders once the client has mounted. */
1345
1598
  export declare const withClientOnly: <TProps extends object>(Component: React.ComponentType<TProps>) => React.ComponentType<TProps>;
1346
1599