@minimalstuff/ui 5.4.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
@@ -174,31 +174,31 @@ export { ButtonColor }
174
174
 
175
175
  export declare type ButtonProps = Omit<ComponentPropsWithRef<'button'>, 'children'> & {
176
176
  children: ReactNode;
177
- size?: ControlSize;
178
- className?: string;
179
- fullWidth?: boolean;
177
+ size?: ControlSize | undefined;
178
+ className?: string | undefined;
179
+ fullWidth?: boolean | undefined;
180
180
  /**
181
181
  * Shows a spinner, marks the button busy and blocks activation (click, Enter,
182
182
  * Space, form submit). Unlike `disabled`, the button keeps focus and stays in
183
183
  * the tab order, exposed as `aria-disabled`.
184
184
  */
185
- loading?: boolean;
185
+ loading?: boolean | undefined;
186
186
  /**
187
187
  * Turns the button into a toggle: sets `aria-pressed` and a pressed look (dark fill and inset ring).
188
188
  * Leave it `undefined` for a regular button (no attribute).
189
189
  */
190
- pressed?: boolean;
191
- startIcon?: string;
192
- endIcon?: string;
190
+ pressed?: boolean | undefined;
191
+ startIcon?: string | undefined;
192
+ endIcon?: string | undefined;
193
193
  } & ButtonStyle;
194
194
 
195
195
  declare type ButtonStyle = {
196
196
  unstyled: true;
197
197
  } | {
198
- unstyled?: false;
199
- variant?: ButtonVariant;
200
- color?: ButtonColor;
201
- radius?: Radius;
198
+ unstyled?: false | undefined;
199
+ variant?: ButtonVariant | undefined;
200
+ color?: ButtonColor | undefined;
201
+ radius?: Radius | undefined;
202
202
  };
203
203
 
204
204
  export declare type ButtonVariant = 'solid' | 'outline' | 'ghost' | 'subtle';
@@ -530,23 +530,23 @@ export declare function IconButton(iconButtonProps: Readonly<IconButtonProps>):
530
530
  export declare type IconButtonProps = ComponentPropsWithRef<'button'> & {
531
531
  icon: string;
532
532
  'aria-label': string;
533
- size?: ControlSize;
533
+ size?: ControlSize | undefined;
534
534
  children?: ReactNode;
535
- tooltip?: IconButtonTooltip;
535
+ tooltip?: IconButtonTooltip | undefined;
536
536
  /**
537
537
  * Turns the button into a toggle: sets `aria-pressed` and a pressed look (dark fill and inset ring).
538
538
  * Leave it `undefined` for a regular button (no attribute).
539
539
  */
540
- pressed?: boolean;
540
+ pressed?: boolean | undefined;
541
541
  } & IconButtonStyle;
542
542
 
543
543
  declare type IconButtonStyle = {
544
544
  unstyled: true;
545
545
  } | {
546
- unstyled?: false;
547
- variant?: ButtonVariant;
548
- color?: ButtonColor;
549
- radius?: Radius;
546
+ unstyled?: false | undefined;
547
+ variant?: ButtonVariant | undefined;
548
+ color?: ButtonColor | undefined;
549
+ radius?: Radius | undefined;
550
550
  };
551
551
 
552
552
  /**
@@ -903,6 +903,71 @@ export declare interface MultiComboboxProps {
903
903
 
904
904
  export declare type OptionLabelOverflow = 'wrap' | 'wrap-active' | 'truncate';
905
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
+
906
971
  export declare type RadioOption = ChoiceOption;
907
972
 
908
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;
@@ -1183,12 +1248,22 @@ export declare interface ThemeToggleProps {
1183
1248
  tooltip?: IconButtonTooltip;
1184
1249
  }
1185
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
+
1186
1260
  export declare interface ToastAction {
1187
1261
  label: string;
1188
1262
  /** Runs on click, then the toast is dismissed. */
1189
1263
  onClick: () => void;
1190
1264
  }
1191
1265
 
1266
+ /** @deprecated Use `toast()` instead of `useToast()`. */
1192
1267
  export declare interface ToastApi {
1193
1268
  /** Shows a toast and returns its id. */
1194
1269
  show: (options: Readonly<ToastOptions>) => string;
@@ -1196,6 +1271,75 @@ export declare interface ToastApi {
1196
1271
  dismiss: (id: string) => void;
1197
1272
  }
1198
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`. */
1199
1343
  export declare interface ToastOptions {
1200
1344
  message: ReactNode;
1201
1345
  /** Defaults to `'info'`. `'error'` is announced assertively, the others politely. */
@@ -1213,19 +1357,17 @@ export declare interface ToastOptions {
1213
1357
  }
1214
1358
 
1215
1359
  /**
1216
- * Provides `useToast()` and renders the toast region (bottom-center on phones,
1217
- * bottom-right from the `sm` breakpoint) through a portal on `document.body`,
1218
- * above modals and drawers. Raise it above a bottom bar with the
1219
- * `--ms-toast-offset-bottom` CSS custom property (default: 1rem plus the
1220
- * safe-area inset). Info and success toasts are announced politely, errors
1221
- * assertively; errors stack below the other toasts.
1360
+ * @deprecated Mount `<Toaster />` once at the app root and call `toast()`
1361
+ * instead. Renders `children` followed by a default `<Toaster />`.
1222
1362
  */
1223
- export declare function ToastProvider({ children }: Readonly<ToastProviderProps>): JSX.Element;
1363
+ export declare const ToastProvider: ({ children }: Readonly<ToastProviderProps>) => JSX.Element;
1224
1364
 
1365
+ /** @deprecated Use `ToasterProps` and mount `<Toaster />`. */
1225
1366
  export declare interface ToastProviderProps {
1226
1367
  children: ReactNode;
1227
1368
  }
1228
1369
 
1370
+ /** @deprecated Use the `toast.info`, `toast.success`, `toast.warning` and `toast.error` functions. */
1229
1371
  export declare type ToastTone = 'info' | 'success' | 'error';
1230
1372
 
1231
1373
  /**
@@ -1444,6 +1586,12 @@ export declare type UseKeyboardScrollableReturn = {
1444
1586
 
1445
1587
  export declare const useThemeStore: UseBoundStore<StoreApi<ThemeStore>>;
1446
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
+ */
1447
1595
  export declare function useToast(): ToastApi;
1448
1596
 
1449
1597
  /** Wraps `Component` so it only renders once the client has mounted. */