@minimalstuff/ui 5.2.0 → 5.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.
package/README.md CHANGED
@@ -59,6 +59,28 @@ import { THEME_INIT_SCRIPT } from '@minimalstuff/ui';
59
59
  </head>;
60
60
  ```
61
61
 
62
+ #### Status bar and `theme-color`
63
+
64
+ To make the browser or installed PWA status bar follow the theme, add a `theme-color` meta with a `data-light` and a `data-dark` color. `THEME_INIT_SCRIPT` and `useThemeStore` copy the matching one into `content` every time the theme is applied (init, `setTheme`, OS change while on `system`, another tab). A meta without both attributes is left alone, and without such a meta nothing changes.
65
+
66
+ ```html
67
+ <head>
68
+ <meta
69
+ name="theme-color"
70
+ content="#ffffff"
71
+ data-light="#ffffff"
72
+ data-dark="#0b0b0b"
73
+ />
74
+ <script>
75
+ /* THEME_INIT_SCRIPT */
76
+ </script>
77
+ </head>
78
+ ```
79
+
80
+ - Put the meta before the script in `<head>`.
81
+ - Remove any other `theme-color` meta, notably ones with a `media` attribute: the first matching one wins.
82
+ - Keep the meta in the static HTML. A meta recreated by a `<head>` manager (Inertia `<Head>`, react-helmet) is not resynced.
83
+
62
84
  With a strict Content-Security-Policy, either add the script's SHA-256 hash to `script-src` (`'sha256-<hash>'`), or write `THEME_INIT_SCRIPT` to a file at build time and load it with `<script src>`. Compute the hash with:
63
85
 
64
86
  ```bash
@@ -88,6 +110,8 @@ pnpm verify
88
110
 
89
111
  `pnpm test:stories` runs the stories in a real browser and needs Playwright's Chromium once: `pnpm exec playwright install chromium`.
90
112
 
113
+ To change the library from a project that uses it, see [docs/developing_from_a_consumer.md](docs/developing_from_a_consumer.md).
114
+
91
115
  Releases follow [docs/releasing.md](docs/releasing.md). Changes are listed in the [CHANGELOG](CHANGELOG.md).
92
116
 
93
117
  ## Report a bug
package/dist/index.d.ts CHANGED
@@ -9,10 +9,62 @@ import { ReactElement } from 'react';
9
9
  import { ReactNode } from 'react';
10
10
  import { ReactPortal } from 'react';
11
11
  import { Ref } from 'react';
12
+ import { RefCallback } from 'react';
12
13
  import { RefObject } from 'react';
13
14
  import { StoreApi } from 'zustand';
14
15
  import { UseBoundStore } from 'zustand';
15
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
+
16
68
  /**
17
69
  * A thin application bar with a `start` slot on the left, a centered `title`
18
70
  * and an `end` slot on the right. It is a plain `<header>` (the `banner`
@@ -250,7 +302,7 @@ export declare interface ClientOnlyProps extends React.PropsWithChildren {
250
302
  fallback?: React.ReactNode;
251
303
  }
252
304
 
253
- export declare function Combobox({ options, filterOption, label, description, 'aria-label': ariaLabel, error, placeholder, noResultsText, clearLabel, radius, unstyled, disabled, required, className, wrapperClassName, value, defaultValue, onChange, id, }: Readonly<ComboboxProps>): JSX.Element;
305
+ export declare function Combobox({ options, filterOption, label, description, 'aria-label': ariaLabel, error, placeholder, noResultsText, clearLabel, radius, unstyled, disabled, required, className, wrapperClassName, dropdownClassName, optionLabelOverflow, value, defaultValue, onChange, id, }: Readonly<ComboboxProps>): JSX.Element;
254
306
 
255
307
  export declare interface ComboboxOption {
256
308
  value: string;
@@ -258,6 +310,7 @@ export declare interface ComboboxOption {
258
310
  }
259
311
 
260
312
  export declare interface ComboboxProps {
313
+ /** Long lists render faster when the array keeps the same identity between renders (memoize it), and when `optionLabelOverflow` is not `'wrap'`. */
261
314
  options: readonly ComboboxOption[];
262
315
  /**
263
316
  * Decides whether an option matches the text typed in the field. Replaces
@@ -278,6 +331,19 @@ export declare interface ComboboxProps {
278
331
  required?: boolean;
279
332
  className?: string;
280
333
  wrapperClassName?: string;
334
+ /**
335
+ * Classes for the dropdown panel, applied last so they can override its
336
+ * defaults, for example a width wider than the field when option labels are
337
+ * long (`w-96`, `min-w-80`). The panel is kept inside the viewport.
338
+ */
339
+ dropdownClassName?: string;
340
+ /**
341
+ * How option labels that do not fit on one line are shown.
342
+ * - `'wrap'` (default): labels wrap; every option is rendered, so lists of thousands of options open slower.
343
+ * - `'wrap-active'`: labels are truncated with a native tooltip, except the active option, which wraps in full; long lists only render the visible options. Recommended for long lists.
344
+ * - `'truncate'`: every label is truncated with a native tooltip, the active one included; keyboard and zoom users can no longer read long labels (WCAG 1.4.10), use only for labels known to be short.
345
+ */
346
+ optionLabelOverflow?: OptionLabelOverflow;
281
347
  value?: string;
282
348
  defaultValue?: string;
283
349
  onChange?: (value: string) => void;
@@ -527,6 +593,15 @@ export declare interface KbdProps {
527
593
 
528
594
  export declare type KbdSize = ControlSize;
529
595
 
596
+ export declare type KeyboardScrollableProps = {
597
+ ref: RefCallback<HTMLElement>;
598
+ tabIndex?: 0;
599
+ role?: 'region';
600
+ 'aria-labelledby'?: string;
601
+ 'aria-label'?: string;
602
+ 'data-keyboard-scroll-region'?: true;
603
+ };
604
+
530
605
  /**
531
606
  * A dropdown anchored to `trigger` (e.g. a kebab `IconButton`): click to
532
607
  * open, click again/click outside/Escape to close, or ArrowDown/ArrowUp on
@@ -725,11 +800,15 @@ export declare interface ModalFooterProps {
725
800
 
726
801
  export declare type ModalHeight = 'auto' | 'fixed';
727
802
 
803
+ export declare type ModalPhoneLayout = 'center' | 'sheet';
804
+
728
805
  export declare type ModalProps = {
729
806
  children: ModalRenderProp;
730
807
  size?: ModalSize;
731
808
  /** `fixed` gives the dialog a stable height so it does not jump when content changes; the content area stops scrolling and a child with `flex-1 min-h-0 overflow-y-auto` scrolls on its own. */
732
809
  height?: ModalHeight;
810
+ /** `sheet` turns the dialog into a bottom sheet below the `sm` breakpoint (full width, flush with the bottom edge, only the top corners rounded, at most 85svh tall, bottom padding clearing the safe area, sliding up on open and down on close; plain fade under reduced motion). From `sm` up it renders as `center`. With `height="fixed"` the sheet is 85svh tall on phones. `unstyled` keeps the sheet position and size but drops radius and the slide. */
811
+ phoneLayout?: ModalPhoneLayout;
733
812
  radius?: Radius;
734
813
  className?: string;
735
814
  /** Applied to the `role=dialog` element. A `transform`, `filter` or `backdrop-filter` on the open panel makes it the containing block of `position: fixed` descendants, so Menus opened inside it get clipped. Keep these off the open state. Carries `data-state="open"` or `"closed"`, so `data-[state=closed]:` variants can animate it. Put your own transitions behind `motion-reduce:` variants, since `unstyled` drops the library's reduced-motion handling along with its animations. */
@@ -759,7 +838,7 @@ export declare type ModalSize = 'sm' | 'md' | 'lg' | 'xl';
759
838
  * pills opens a searchable dropdown of checkbox-style options. Selecting an
760
839
  * option never closes the dropdown, unlike the single-select `Combobox`.
761
840
  */
762
- export declare function MultiCombobox({ options, filterOption, label, description, 'aria-label': ariaLabel, error, placeholder, searchPlaceholder, noResultsText, clearLabel, clearText, maxSelectedValues, isOptionDisabled, maxDisplayedValues, formatOverflowCount, formatSelectedCount, formatMaxSelectedHint, radius, unstyled, disabled, required, className, wrapperClassName, values, defaultValues, onChange, onDropdownClose, id, }: Readonly<MultiComboboxProps>): ReactElement;
841
+ export declare function MultiCombobox({ options, filterOption, label, description, 'aria-label': ariaLabel, error, placeholder, searchPlaceholder, noResultsText, clearLabel, clearText, maxSelectedValues, isOptionDisabled, maxDisplayedValues, formatOverflowCount, formatSelectedCount, formatMaxSelectedHint, radius, unstyled, disabled, required, className, wrapperClassName, dropdownClassName, optionLabelOverflow, values, defaultValues, onChange, onDropdownClose, id, }: Readonly<MultiComboboxProps>): ReactElement;
763
842
 
764
843
  export declare interface MultiComboboxOption {
765
844
  value: string;
@@ -767,6 +846,7 @@ export declare interface MultiComboboxOption {
767
846
  }
768
847
 
769
848
  export declare interface MultiComboboxProps {
849
+ /** Long lists render faster when the array keeps the same identity between renders (memoize it), and when `optionLabelOverflow` is not `'wrap'`. */
770
850
  options: readonly MultiComboboxOption[];
771
851
  /**
772
852
  * Decides whether an option matches the text typed in the search field.
@@ -795,6 +875,19 @@ export declare interface MultiComboboxProps {
795
875
  required?: boolean;
796
876
  className?: string;
797
877
  wrapperClassName?: string;
878
+ /**
879
+ * Classes for the dropdown panel, applied last so they can override its
880
+ * defaults, for example a width wider than the field when option labels are
881
+ * long (`w-96`, `min-w-80`). The panel is kept inside the viewport.
882
+ */
883
+ dropdownClassName?: string;
884
+ /**
885
+ * How option labels that do not fit on one line are shown.
886
+ * - `'wrap'` (default): labels wrap; every option is rendered, so lists of thousands of options open slower.
887
+ * - `'wrap-active'`: labels are truncated with a native tooltip, except the active option, which wraps in full; long lists only render the visible options. Recommended for long lists.
888
+ * - `'truncate'`: every label is truncated with a native tooltip, the active one included; keyboard and zoom users can no longer read long labels (WCAG 1.4.10), use only for labels known to be short.
889
+ */
890
+ optionLabelOverflow?: OptionLabelOverflow;
798
891
  values?: readonly string[];
799
892
  defaultValues?: readonly string[];
800
893
  onChange?: (values: readonly string[]) => void;
@@ -808,6 +901,8 @@ export declare interface MultiComboboxProps {
808
901
  id?: string;
809
902
  }
810
903
 
904
+ export declare type OptionLabelOverflow = 'wrap' | 'wrap-active' | 'truncate';
905
+
811
906
  export declare type RadioOption = ChoiceOption;
812
907
 
813
908
  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;
@@ -955,7 +1050,7 @@ export declare function splitIntoHighlightSegments(
955
1050
  return segments;
956
1051
  }
957
1052
 
958
- export declare function Switch({ label, description, error, unstyled, fullWidth, className, wrapperClassName, checked, defaultChecked, onChange, id, 'aria-describedby': callerDescribedBy, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, ...props }: Readonly<SwitchProps>): JSX.Element;
1053
+ export declare function Switch({ label, description, error, unstyled, fullWidth, className, wrapperClassName, checked, defaultChecked, onChange, id, 'aria-describedby': callerDescribedBy, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, ref, ...props }: Readonly<SwitchProps>): JSX.Element;
959
1054
 
960
1055
  export declare interface SwitchProps extends Omit<ComponentPropsWithRef<'input'>, 'type' | 'className'> {
961
1056
  label?: string | ReactNode;
@@ -1052,7 +1147,10 @@ export declare type Theme = 'light' | 'dark' | 'system';
1052
1147
  * first paint, so a dark-mode visitor never sees a light flash. It mirrors
1053
1148
  * `useThemeStore`: the `dark` class is set for a stored `dark`, or for a
1054
1149
  * stored `system` (or a missing, invalid or unreadable value) while the OS
1055
- * prefers dark. Inline it in `<head>` before the stylesheet.
1150
+ * prefers dark. Every `<meta name="theme-color" data-light="..." data-dark="...">`
1151
+ * also gets its `content` set from `data-dark` or `data-light`; it must come
1152
+ * before this script in `<head>`. Inline the script in `<head>` before the
1153
+ * stylesheet.
1056
1154
  */
1057
1155
  export declare const THEME_INIT_SCRIPT: string;
1058
1156
 
@@ -1085,6 +1183,51 @@ export declare interface ThemeToggleProps {
1085
1183
  tooltip?: IconButtonTooltip;
1086
1184
  }
1087
1185
 
1186
+ export declare interface ToastAction {
1187
+ label: string;
1188
+ /** Runs on click, then the toast is dismissed. */
1189
+ onClick: () => void;
1190
+ }
1191
+
1192
+ export declare interface ToastApi {
1193
+ /** Shows a toast and returns its id. */
1194
+ show: (options: Readonly<ToastOptions>) => string;
1195
+ /** Dismisses the toast with this id; an unknown or already dismissed id is ignored. */
1196
+ dismiss: (id: string) => void;
1197
+ }
1198
+
1199
+ export declare interface ToastOptions {
1200
+ message: ReactNode;
1201
+ /** Defaults to `'info'`. `'error'` is announced assertively, the others politely. */
1202
+ tone?: ToastTone;
1203
+ /**
1204
+ * Milliseconds before the toast dismisses itself, counted only while it is
1205
+ * neither hovered nor focused. Defaults to 4000 (6000 for `'error'`). `0` or
1206
+ * `Infinity` keeps the toast until it is dismissed.
1207
+ */
1208
+ duration?: number;
1209
+ action?: ToastAction;
1210
+ radius?: Radius;
1211
+ /** 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. */
1212
+ unstyled?: boolean;
1213
+ }
1214
+
1215
+ /**
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.
1222
+ */
1223
+ export declare function ToastProvider({ children }: Readonly<ToastProviderProps>): JSX.Element;
1224
+
1225
+ export declare interface ToastProviderProps {
1226
+ children: ReactNode;
1227
+ }
1228
+
1229
+ export declare type ToastTone = 'info' | 'success' | 'error';
1230
+
1088
1231
  /**
1089
1232
  * A group of related controls with a single tab stop (WAI-ARIA toolbar).
1090
1233
  * Tab enters the toolbar on the last focused item (the first enabled one
@@ -1194,6 +1337,13 @@ export declare interface UILabels {
1194
1337
  * must add it, otherwise the English "Copy" is used.
1195
1338
  */
1196
1339
  copy?: string;
1340
+ /**
1341
+ * Accessible name of the region holding the `ToastProvider` toasts. Optional
1342
+ * like `copy`: the English "Notifications" is used when a label set omits it.
1343
+ */
1344
+ notifications?: string;
1345
+ /** Accessible name of the close button of a toast. Optional: the English "Close notification" is used when omitted. */
1346
+ closeNotification?: string;
1197
1347
  /** Screen-reader announcement of `CharacterCount` near and at the limit. */
1198
1348
  charactersRemaining: (remainingCount: number) => string;
1199
1349
  /** Accessible name of `ThemeToggle` for the current theme. */
@@ -1255,8 +1405,47 @@ export declare const useGlobalHotkeysStore: UseBoundStore<StoreApi<GlobalHotkeys
1255
1405
 
1256
1406
  export declare const useIsClient: () => boolean;
1257
1407
 
1408
+ /**
1409
+ * Makes a scroll container reachable by keyboard. When the container overflows
1410
+ * and holds nothing tabbable, `scrollableProps` gives it a tab stop, a
1411
+ * `region` role and an accessible name, and `focusClassName` a visible focus
1412
+ * outline. Otherwise only the `ref` is returned. Re-evaluated on resize and on
1413
+ * content changes; a container mounted after the first render is observed too.
1414
+ *
1415
+ * To combine `scrollableProps.ref` with your own ref, use a ref callback that
1416
+ * calls both.
1417
+ *
1418
+ * @example
1419
+ * const { scrollableProps, focusClassName } = useKeyboardScrollable({
1420
+ * label: 'Release notes',
1421
+ * })
1422
+ * return (
1423
+ * <div {...scrollableProps} className={cn('h-64 overflow-y-auto', focusClassName)}>
1424
+ * {content}
1425
+ * </div>
1426
+ * )
1427
+ */
1428
+ export declare function useKeyboardScrollable(options: Readonly<UseKeyboardScrollableOptions>): UseKeyboardScrollableReturn;
1429
+
1430
+ /** A scroll region must be named, exactly once: by `label` or by `labelledBy`. */
1431
+ export declare type UseKeyboardScrollableOptions = {
1432
+ label: string;
1433
+ labelledBy?: never;
1434
+ } | {
1435
+ labelledBy: string;
1436
+ label?: never;
1437
+ };
1438
+
1439
+ export declare type UseKeyboardScrollableReturn = {
1440
+ scrollableProps: KeyboardScrollableProps;
1441
+ /** Focus outline classes to add to the container's `className`; `undefined` when the container is not a tab stop. */
1442
+ focusClassName: string | undefined;
1443
+ };
1444
+
1258
1445
  export declare const useThemeStore: UseBoundStore<StoreApi<ThemeStore>>;
1259
1446
 
1447
+ export declare function useToast(): ToastApi;
1448
+
1260
1449
  /** Wraps `Component` so it only renders once the client has mounted. */
1261
1450
  export declare const withClientOnly: <TProps extends object>(Component: React.ComponentType<TProps>) => React.ComponentType<TProps>;
1262
1451
 
@@ -1268,3 +1457,10 @@ declare module 'vitest' {
1268
1457
  interface Assertion<T = unknown> extends AxeMatchers {}
1269
1458
  interface AsymmetricMatchersContaining extends AxeMatchers {}
1270
1459
  }
1460
+
1461
+ declare module 'vitest/browser' {
1462
+ interface BrowserCommands {
1463
+ /** Moves the real mouse cursor to a point outside the story document. */
1464
+ movePointerOutOfStory: () => Promise<void>;
1465
+ }
1466
+ }