@minimalstuff/ui 5.4.0 → 5.6.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';
@@ -294,6 +294,8 @@ export declare interface ChoiceOption {
294
294
  description?: string;
295
295
  icon?: string;
296
296
  disabled?: boolean;
297
+ /** BCP 47 language of `label` and `description`, set as their `lang` attribute when it differs from the page's. */
298
+ lang?: string;
297
299
  }
298
300
 
299
301
  export declare function ClientOnly({ children, fallback }: Readonly<ClientOnlyProps>): string | number | bigint | boolean | Iterable< ReactNode> | Promise<string | number | bigint | boolean | ReactPortal | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable< ReactNode> | null | undefined> | JSX.Element | null;
@@ -530,23 +532,23 @@ export declare function IconButton(iconButtonProps: Readonly<IconButtonProps>):
530
532
  export declare type IconButtonProps = ComponentPropsWithRef<'button'> & {
531
533
  icon: string;
532
534
  'aria-label': string;
533
- size?: ControlSize;
535
+ size?: ControlSize | undefined;
534
536
  children?: ReactNode;
535
- tooltip?: IconButtonTooltip;
537
+ tooltip?: IconButtonTooltip | undefined;
536
538
  /**
537
539
  * Turns the button into a toggle: sets `aria-pressed` and a pressed look (dark fill and inset ring).
538
540
  * Leave it `undefined` for a regular button (no attribute).
539
541
  */
540
- pressed?: boolean;
542
+ pressed?: boolean | undefined;
541
543
  } & IconButtonStyle;
542
544
 
543
545
  declare type IconButtonStyle = {
544
546
  unstyled: true;
545
547
  } | {
546
- unstyled?: false;
547
- variant?: ButtonVariant;
548
- color?: ButtonColor;
549
- radius?: Radius;
548
+ unstyled?: false | undefined;
549
+ variant?: ButtonVariant | undefined;
550
+ color?: ButtonColor | undefined;
551
+ radius?: Radius | undefined;
550
552
  };
551
553
 
552
554
  /**
@@ -903,6 +905,71 @@ export declare interface MultiComboboxProps {
903
905
 
904
906
  export declare type OptionLabelOverflow = 'wrap' | 'wrap-active' | 'truncate';
905
907
 
908
+ /**
909
+ * A non-modal panel anchored to `trigger` that holds free content (radio
910
+ * groups, a segmented control, a disclosure...). Unlike `Menu`, clicking
911
+ * inside never closes it: it closes on a second trigger click, Escape, a
912
+ * pointer down outside, or focus leaving the panel and the trigger.
913
+ *
914
+ * Focus moves into the panel on open and returns to the trigger after
915
+ * Escape or a close caused from inside; after an outside pointer down it
916
+ * stays on what the user clicked. Escape calls `event.preventDefault()`, so
917
+ * inside a `Modal` only the popover closes.
918
+ */
919
+ 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;
920
+
921
+ export declare type PopoverAlign = 'start' | 'center' | 'end';
922
+
923
+ declare interface PopoverBaseProps {
924
+ /** Cloned with a toggling `onClick`, `aria-haspopup="dialog"`, `aria-expanded` and `aria-controls`. */
925
+ trigger: ReactElement;
926
+ /** Free content: the panel stays open while the user interacts with it. */
927
+ children: ReactNode;
928
+ /** Controlled open state. While provided, the owner drives every change through `onOpenChange`. */
929
+ isOpen?: boolean;
930
+ defaultOpen?: boolean;
931
+ /** Fires once per open or close, whatever the cause (trigger, Escape, outside pointer, focus leaving, `disabled`). */
932
+ onOpenChange?: (isOpen: boolean) => void;
933
+ side?: PopoverSide;
934
+ align?: PopoverAlign;
935
+ /** Focused on open instead of the first tabbable element of the panel. */
936
+ initialFocusRef?: RefObject<HTMLElement | null>;
937
+ radius?: Radius;
938
+ className?: string;
939
+ /**
940
+ * Strips the panel's visual styling (border, background, shadow, blur,
941
+ * padding, radius, width bounds and the open/close animation). Positioning
942
+ * and the keyboard and focus handling stay. `radius` is ignored.
943
+ */
944
+ unstyled?: boolean;
945
+ /**
946
+ * Styles the floating panel (`role="dialog"`), with or without `unstyled`.
947
+ * Its position comes from inline floating styles: don't set
948
+ * `position`, `top` or `left` on it.
949
+ */
950
+ panelClassName?: string;
951
+ /**
952
+ * Keeps the popover closed (and closes it if open). The trigger itself is
953
+ * left alone: mark it `aria-disabled` or `disabled` yourself.
954
+ */
955
+ disabled?: boolean;
956
+ /** Attaches to the wrapper `<span>` around `trigger`, alongside the popover's own internal ref. */
957
+ ref?: Ref<HTMLSpanElement>;
958
+ }
959
+
960
+ declare type PopoverNameProps = {
961
+ 'aria-label': string;
962
+ 'aria-labelledby'?: string;
963
+ } | {
964
+ 'aria-labelledby': string;
965
+ 'aria-label'?: string;
966
+ };
967
+
968
+ /** The panel is a `role="dialog"`: it needs `aria-label` or `aria-labelledby`. */
969
+ export declare type PopoverProps = PopoverBaseProps & PopoverNameProps;
970
+
971
+ export declare type PopoverSide = 'top' | 'bottom' | 'left' | 'right';
972
+
906
973
  export declare type RadioOption = ChoiceOption;
907
974
 
908
975
  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 +1250,22 @@ export declare interface ThemeToggleProps {
1183
1250
  tooltip?: IconButtonTooltip;
1184
1251
  }
1185
1252
 
1253
+ /**
1254
+ * Shows a toast from anywhere (event handlers, services, outside React) and
1255
+ * returns its id. `toast(message)` shows an info toast; use `toast.success`,
1256
+ * `toast.warning` and `toast.error` for the other tones, and `toast.dismiss`
1257
+ * to close one or all. Mount `<Toaster />` once at the app root to render
1258
+ * them. Calling it on the server does nothing but return the id.
1259
+ */
1260
+ export declare const toast: ToastFunction;
1261
+
1186
1262
  export declare interface ToastAction {
1187
1263
  label: string;
1188
1264
  /** Runs on click, then the toast is dismissed. */
1189
1265
  onClick: () => void;
1190
1266
  }
1191
1267
 
1268
+ /** @deprecated Use `toast()` instead of `useToast()`. */
1192
1269
  export declare interface ToastApi {
1193
1270
  /** Shows a toast and returns its id. */
1194
1271
  show: (options: Readonly<ToastOptions>) => string;
@@ -1196,6 +1273,75 @@ export declare interface ToastApi {
1196
1273
  dismiss: (id: string) => void;
1197
1274
  }
1198
1275
 
1276
+ /**
1277
+ * Renders the toasts shown with `toast()`. Mount it once at the app root; only
1278
+ * the first mounted Toaster renders, any other warns in development and
1279
+ * renders nothing. It renders nothing on the server and on the first client
1280
+ * render. Toasts sit above `Modal` and `Drawer` (`z-[60]`) and never block
1281
+ * the page outside themselves. The stack scrolls when it is taller than the
1282
+ * viewport.
1283
+ *
1284
+ * Press F8 to jump to the toasts and F8 again to go back to where focus was;
1285
+ * Escape closes the focused toast. F8 is inactive while a Modal or Drawer is
1286
+ * open, and when no toast is open.
1287
+ *
1288
+ * While a Modal is open its Tab trap leaves the toasts unreachable by
1289
+ * keyboard. This is why warning and error toasts, and toasts with an action,
1290
+ * stay until dismissed.
1291
+ *
1292
+ * Unmounting the last Toaster empties the toast store in a microtask, so a
1293
+ * `toast()` called in the same synchronous turn right after unmounting it is
1294
+ * dropped.
1295
+ *
1296
+ * Offsets come from two CSS custom properties: `--ms-toast-offset-bottom`
1297
+ * and `--ms-toast-offset-top` (default: 1rem plus the safe-area inset).
1298
+ */
1299
+ export declare function Toaster(props: Readonly<ToasterProps>): JSX.Element | null;
1300
+
1301
+ export declare type ToasterPosition =
1302
+ | 'top-left'
1303
+ | 'top-center'
1304
+ | 'top-right'
1305
+ | 'bottom-left'
1306
+ | 'bottom-center'
1307
+ | 'bottom-right';
1308
+
1309
+ export declare interface ToasterProps {
1310
+ /** 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'`. */
1311
+ position?: ToasterPosition;
1312
+ /** Corner radius of every toast that sets none. `full` caps at `lg`. Defaults to `lg`. */
1313
+ radius?: Radius;
1314
+ /** 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. */
1315
+ unstyled?: boolean;
1316
+ }
1317
+
1318
+ export declare interface ToastFunction {
1319
+ /** Shows an info toast and returns its id. */
1320
+ (message: string, options?: Readonly<ToastMessageOptions>): string;
1321
+ /** Shows an info toast and returns its id. */
1322
+ info(message: string, options?: Readonly<ToastMessageOptions>): string;
1323
+ /** Shows a success toast and returns its id. */
1324
+ success(message: string, options?: Readonly<ToastMessageOptions>): string;
1325
+ /** Shows a warning toast and returns its id. It stays until dismissed unless a duration is given. */
1326
+ warning(message: string, options?: Readonly<ToastMessageOptions>): string;
1327
+ /** Shows an error toast and returns its id. It stays until dismissed unless a duration is given. */
1328
+ error(message: string, options?: Readonly<ToastMessageOptions>): string;
1329
+ /** Dismisses the toast with this id; an unknown id is ignored. Without id, dismisses every toast. */
1330
+ dismiss(id?: string): void;
1331
+ }
1332
+
1333
+ export declare interface ToastMessageOptions {
1334
+ /** Identifies the toast. Showing a toast with an id already in use replaces that toast in place, restarts its timer and announces it again. */
1335
+ id?: string;
1336
+ /** Secondary text shown under the message. */
1337
+ description?: string;
1338
+ /** 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. */
1339
+ duration?: number;
1340
+ /** Button shown in the toast; the toast is dismissed after it runs. */
1341
+ action?: ToastAction;
1342
+ }
1343
+
1344
+ /** @deprecated Use `toast()` and its `ToastMessageOptions`. */
1199
1345
  export declare interface ToastOptions {
1200
1346
  message: ReactNode;
1201
1347
  /** Defaults to `'info'`. `'error'` is announced assertively, the others politely. */
@@ -1213,19 +1359,17 @@ export declare interface ToastOptions {
1213
1359
  }
1214
1360
 
1215
1361
  /**
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.
1362
+ * @deprecated Mount `<Toaster />` once at the app root and call `toast()`
1363
+ * instead. Renders `children` followed by a default `<Toaster />`.
1222
1364
  */
1223
- export declare function ToastProvider({ children }: Readonly<ToastProviderProps>): JSX.Element;
1365
+ export declare const ToastProvider: ({ children }: Readonly<ToastProviderProps>) => JSX.Element;
1224
1366
 
1367
+ /** @deprecated Use `ToasterProps` and mount `<Toaster />`. */
1225
1368
  export declare interface ToastProviderProps {
1226
1369
  children: ReactNode;
1227
1370
  }
1228
1371
 
1372
+ /** @deprecated Use the `toast.info`, `toast.success`, `toast.warning` and `toast.error` functions. */
1229
1373
  export declare type ToastTone = 'info' | 'success' | 'error';
1230
1374
 
1231
1375
  /**
@@ -1444,6 +1588,12 @@ export declare type UseKeyboardScrollableReturn = {
1444
1588
 
1445
1589
  export declare const useThemeStore: UseBoundStore<StoreApi<ThemeStore>>;
1446
1590
 
1591
+ /**
1592
+ * @deprecated Call `toast()` from `@minimalstuff/ui` instead, and mount
1593
+ * `<Toaster />` once at the app root. Returns a constant `{ show, dismiss }`
1594
+ * that forwards to the same toast store; it no longer needs a `ToastProvider`
1595
+ * and no longer throws without one.
1596
+ */
1447
1597
  export declare function useToast(): ToastApi;
1448
1598
 
1449
1599
  /** Wraps `Component` so it only renders once the client has mounted. */