@hussmartinez/ui 0.8.0 → 0.10.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/dist/react.d.ts CHANGED
@@ -24,6 +24,7 @@ import { RefAttributes } from 'react';
24
24
  import { RefObject } from 'react';
25
25
  import type { ShortcutPart } from '@hussmartinez/sdk-core';
26
26
  import type { SVGProps } from 'react';
27
+ import { TextareaHTMLAttributes } from 'react';
27
28
 
28
29
  /**
29
30
  * The `add` icon: Lucide's `plus`.
@@ -175,6 +176,68 @@ export declare type ClassNames<Part extends string> = {
175
176
  */
176
177
  export declare function CloseIcon(props: IconProps): ReactElement;
177
178
 
179
+ /**
180
+ * A colour input: a hex field with a preview of the colour, and optional
181
+ * swatches to pick from. It works with the keyboard alone and doesn't use
182
+ * the browser's own colour picker, which differs between browsers and can't
183
+ * be themed or translated.
184
+ *
185
+ * - **The input** takes `#rrggbb`, `#rgb` or either without the `#`. Typing
186
+ * doesn't change the value: the text is committed on blur or Enter. Text
187
+ * that isn't a colour goes back to the last value, and Escape throws the
188
+ * typing away.
189
+ * - **The swatches** are a radio group: one Tab stop, and the arrow keys move
190
+ * and select. A swatch is checked while the value is its colour.
191
+ * - **The value** is always lowercase `#rrggbb`. With `name`, forms receive it.
192
+ *
193
+ * @example
194
+ * ```tsx
195
+ * <Field label={t("shape.fill")}>
196
+ * <ColorField
197
+ * value={fill}
198
+ * onValueChange={setFill}
199
+ * swatches={[
200
+ * { value: "#d92d20", label: t("colors.red") },
201
+ * { value: "#1570ef", label: t("colors.blue") },
202
+ * ]}
203
+ * />
204
+ * </Field>
205
+ * ```
206
+ *
207
+ * @public
208
+ */
209
+ export declare const ColorField: ForwardRefExoticComponent<ColorFieldProps & RefAttributes<HTMLDivElement>>;
210
+
211
+ /**
212
+ * The parts of a colour field that `classNames` can target.
213
+ *
214
+ * @public
215
+ */
216
+ export declare type ColorFieldPart = "root" | "control" | "preview" | "input" | "swatches" | "swatch";
217
+
218
+ /**
219
+ * Props of {@link ColorField}. Other props go to the hex input.
220
+ *
221
+ * @public
222
+ */
223
+ export declare interface ColorFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "className" | "type" | "value" | "defaultValue" | "onChange">, StyleProps<ColorFieldPart> {
224
+ /** The colour, as `#rrggbb`. With it, the field is controlled. */
225
+ readonly value?: string | undefined;
226
+ /** The first colour of an uncontrolled field. Defaults to `#000000`. */
227
+ readonly defaultValue?: string | undefined;
228
+ /** Called with the new colour, always as lowercase `#rrggbb`. */
229
+ readonly onValueChange?: ((value: string) => void) | undefined;
230
+ /** Colours to pick from, shown under the input. Leave it out for the input alone. */
231
+ readonly swatches?: readonly ColorSwatch[] | undefined;
232
+ /**
233
+ * The accessible name, such as "Fill". Leave it out inside a `Field`, or
234
+ * when a visible `<label>` points at the field's `id`.
235
+ */
236
+ readonly label?: string | undefined;
237
+ /** The word that follows the label in the swatch group's name. Defaults to "swatches". */
238
+ readonly swatchesLabel?: string | undefined;
239
+ }
240
+
178
241
  /**
179
242
  * How a subtree picks between light and dark: one of them, or whichever the
180
243
  * operating system prefers (`prefers-color-scheme`).
@@ -183,6 +246,18 @@ export declare function CloseIcon(props: IconProps): ReactElement;
183
246
  */
184
247
  export declare type ColorMode = "light" | "dark" | "system";
185
248
 
249
+ /**
250
+ * A colour a {@link ColorField} offers as a swatch.
251
+ *
252
+ * @public
253
+ */
254
+ export declare interface ColorSwatch {
255
+ /** The colour, as `#rrggbb` or `#rgb`. */
256
+ readonly value: string;
257
+ /** The swatch's accessible name, such as "Red". Use text from your message catalogue. */
258
+ readonly label: string;
259
+ }
260
+
186
261
  /**
187
262
  * The `crop` icon: Lucide's `crop`.
188
263
  *
@@ -551,7 +626,7 @@ export declare type IconComponent = (props: IconProps) => ReactElement;
551
626
  *
552
627
  * @public
553
628
  */
554
- export declare type IconName = "add" | "arrow" | "check" | "chevron-down" | "chevron-left" | "chevron-right" | "close" | "crop" | "delete" | "download" | "duplicate" | "ellipse" | "fade-in" | "fade-out" | "fit" | "flip-horizontal" | "flip-vertical" | "hidden" | "highlighter" | "info" | "layers" | "loop" | "menu" | "more" | "move-down" | "move-up" | "muted" | "open" | "page-add" | "page-grid" | "page-single" | "pan" | "pause" | "pen" | "play" | "rectangle" | "redact" | "redo" | "remove" | "rotate-left" | "rotate-right" | "search" | "select" | "skip-back" | "skip-forward" | "snap" | "split" | "stop" | "text" | "trim-end" | "trim-start" | "undo" | "upload" | "visible" | "volume" | "warning" | "zoom-in" | "zoom-out";
629
+ export declare type IconName = "add" | "arrow" | "check" | "chevron-down" | "chevron-left" | "chevron-right" | "close" | "crop" | "delete" | "download" | "duplicate" | "ellipse" | "fade-in" | "fade-out" | "fit" | "flip-horizontal" | "flip-vertical" | "hidden" | "highlighter" | "image" | "info" | "layers" | "loop" | "menu" | "more" | "move-down" | "move-up" | "muted" | "open" | "page-add" | "page-grid" | "page-single" | "pan" | "pause" | "pen" | "play" | "rectangle" | "redact" | "redo" | "remove" | "rotate-left" | "rotate-right" | "search" | "select" | "skip-back" | "skip-forward" | "snap" | "split" | "stop" | "text" | "trim-end" | "trim-start" | "undo" | "upload" | "visible" | "volume" | "warning" | "zoom-in" | "zoom-out";
555
630
 
556
631
  /**
557
632
  * Props of every icon. SVG attributes are passed through.
@@ -567,6 +642,13 @@ export declare interface IconProps extends Omit<SVGProps<SVGSVGElement>, "childr
567
642
  readonly label?: string | undefined;
568
643
  }
569
644
 
645
+ /**
646
+ * The `image` icon: Lucide's `image`.
647
+ *
648
+ * @public
649
+ */
650
+ export declare function ImageIcon(props: IconProps): ReactElement;
651
+
570
652
  /**
571
653
  * The `info` icon: Lucide's `info`.
572
654
  *
@@ -827,6 +909,131 @@ export declare function RedoIcon(props: IconProps): ReactElement;
827
909
  */
828
910
  export declare function RemoveIcon(props: IconProps): ReactElement;
829
911
 
912
+ /**
913
+ * A list whose items the user selects, reorders and removes, with one Tab
914
+ * stop and room for controls in each row (docs/adr/0009). It's a WAI-ARIA
915
+ * grid with one column of rows.
916
+ *
917
+ * - **↑ and ↓** move between rows and select; with Ctrl or ⌘, they move
918
+ * without selecting. **← and →**, Home and End move between a row's
919
+ * cells. Ctrl or ⌘ with Home or End goes to the first or last row.
920
+ * Space or Enter on an item selects it.
921
+ * - **Alt+↑ and Alt+↓** (Option on macOS) move the focused item, through
922
+ * `onMove`. **Delete and Backspace** remove it, through `onRemove`.
923
+ * - **You own the order.** The list calls `onMove` and `onRemove`, and you
924
+ * render the result. Focus stays with a moved item, and goes to the next
925
+ * one after a removal.
926
+ * - **Offer buttons too.** The keys are an addition: also render buttons
927
+ * that move the selected item, for touch and for people who don't know
928
+ * the keys, and name the keys on them with `aria-keyshortcuts`.
929
+ *
930
+ * @example
931
+ * ```tsx
932
+ * <ReorderableList
933
+ * label={t("layers.label")}
934
+ * selectedId={selected}
935
+ * onSelectedChange={setSelected}
936
+ * onMove={(id, toIndex) => session.moveLayer(id, toIndex)}
937
+ * onRemove={(id) => session.deleteLayer(id)}
938
+ * >
939
+ * {layers.map((layer) => (
940
+ * <ReorderableListItem
941
+ * key={layer.id}
942
+ * id={layer.id}
943
+ * label={layer.name}
944
+ * controls={[
945
+ * <ToggleButton
946
+ * key="visible"
947
+ * variant="quiet"
948
+ * label={t("layers.visible")}
949
+ * icon={<VisibleIcon />}
950
+ * pressed={layer.visible}
951
+ * onPressedChange={(visible) => session.showLayer(layer.id, visible)}
952
+ * />,
953
+ * ]}
954
+ * >
955
+ * {layer.name}
956
+ * </ReorderableListItem>
957
+ * ))}
958
+ * </ReorderableList>
959
+ * ```
960
+ *
961
+ * @public
962
+ */
963
+ export declare const ReorderableList: ForwardRefExoticComponent<ReorderableListProps & RefAttributes<HTMLDivElement>>;
964
+
965
+ /**
966
+ * An item of a {@link ReorderableList}: a row with the item's content, and a
967
+ * cell for each of its `controls`.
968
+ *
969
+ * @public
970
+ */
971
+ export declare const ReorderableListItem: ForwardRefExoticComponent<ReorderableListItemProps & RefAttributes<HTMLDivElement>>;
972
+
973
+ /**
974
+ * The parts of a reorderable list's item that `classNames` can target.
975
+ *
976
+ * @public
977
+ */
978
+ export declare type ReorderableListItemPart = "root" | "item" | "control";
979
+
980
+ /**
981
+ * Props of {@link ReorderableListItem}.
982
+ *
983
+ * @public
984
+ */
985
+ export declare interface ReorderableListItemProps extends Omit<HTMLAttributes<HTMLDivElement>, "className" | "role" | "id">, StyleProps<ReorderableListItemPart> {
986
+ /** Identifies the item in `selectedId`, `onMove` and `onRemove`. Unique in the list. */
987
+ readonly id: string;
988
+ /**
989
+ * The item's accessible name, such as a layer's name. Start it with the
990
+ * text the item shows, if it shows any.
991
+ */
992
+ readonly label: string;
993
+ /**
994
+ * The item's controls, such as a visibility toggle: one focusable control
995
+ * each, in its own cell. A control that can't act should stay focusable,
996
+ * as `focusableWhenDisabled` makes a button.
997
+ */
998
+ readonly controls?: readonly ReactNode[] | undefined;
999
+ /** What the item shows. */
1000
+ readonly children?: ReactNode;
1001
+ }
1002
+
1003
+ /**
1004
+ * Props of {@link ReorderableList}.
1005
+ *
1006
+ * @public
1007
+ */
1008
+ export declare interface ReorderableListProps extends Omit<HTMLAttributes<HTMLDivElement>, "className" | "role">, StyleProps<"root"> {
1009
+ /** The list's accessible name, such as "Layers". Required. */
1010
+ readonly label: string;
1011
+ /** The selected item's `id`, or `null` for none. */
1012
+ readonly selectedId?: string | null | undefined;
1013
+ /** Called with an item's `id` when the user selects it. */
1014
+ readonly onSelectedChange?: ((id: string) => void) | undefined;
1015
+ /**
1016
+ * Called when the user moves an item with Alt+↑ or Alt+↓ (Option on
1017
+ * macOS), with its `id` and the position it should have, counted from 0.
1018
+ * Render the items in the new order, or leave them when the move isn't
1019
+ * allowed. Without it, the list doesn't reorder.
1020
+ */
1021
+ readonly onMove?: ((id: string, toIndex: number) => void) | undefined;
1022
+ /**
1023
+ * Called when the user presses Delete or Backspace on an item, with its
1024
+ * `id`. Render the items without it. Without it, the keys do nothing.
1025
+ */
1026
+ readonly onRemove?: ((id: string) => void) | undefined;
1027
+ /**
1028
+ * Whether the list announces a move to screen readers, through the
1029
+ * closest `AnnouncerProvider`. Defaults to `true`; pass `false` when you
1030
+ * announce it in your own words.
1031
+ */
1032
+ readonly announceMoves?: boolean | undefined;
1033
+ /** The items: {@link ReorderableListItem} elements, in the order shown. */
1034
+ readonly children?: ReactNode;
1035
+ }
1036
+
830
1037
  /**
831
1038
  * The `rotate-left` icon: Lucide's `rotate-ccw`.
832
1039
  *
@@ -1064,6 +1271,43 @@ export declare interface StyleProps<Part extends string> {
1064
1271
  readonly unstyled?: boolean | undefined;
1065
1272
  }
1066
1273
 
1274
+ /**
1275
+ * A multi-line text input, styled like `TextField`, with its tokens. `rows`
1276
+ * sets its height, three by default, and the user can drag it taller. Inside
1277
+ * a `Field`, it takes the field's label, description and error.
1278
+ *
1279
+ * Enter adds a line, so it doesn't submit a form. Its value separates lines
1280
+ * with `\n`, whatever was pasted.
1281
+ *
1282
+ * @example
1283
+ * ```tsx
1284
+ * <Field label={t("text.content")}>
1285
+ * <TextArea value={text} onValueChange={setText} rows={4} />
1286
+ * </Field>
1287
+ * ```
1288
+ *
1289
+ * @public
1290
+ */
1291
+ export declare const TextArea: ForwardRefExoticComponent<TextAreaProps & RefAttributes<HTMLTextAreaElement>>;
1292
+
1293
+ /**
1294
+ * Props of {@link TextArea}. Native textarea props are passed through, so it
1295
+ * works controlled with `value` and `onChange`, or uncontrolled with
1296
+ * `defaultValue`.
1297
+ *
1298
+ * @public
1299
+ */
1300
+ export declare interface TextAreaProps extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, "className">, StyleProps<"root"> {
1301
+ /** Called with the new text as it changes, as well as `onChange`. */
1302
+ readonly onValueChange?: ((value: string) => void) | undefined;
1303
+ /**
1304
+ * The accessible name, such as "Caption". Leave it out inside a `Field`,
1305
+ * or when a visible `<label>` points at the field's `id`, or
1306
+ * `aria-labelledby` names it.
1307
+ */
1308
+ readonly label?: string | undefined;
1309
+ }
1310
+
1067
1311
  /**
1068
1312
  * A single-line text input, styled like the family's other fields. Inside a
1069
1313
  * `Field`, it takes the field's label, description and error.
@@ -1480,12 +1724,14 @@ export declare type UiMessages = Messages<typeof uiMessages>;
1480
1724
  * @public
1481
1725
  */
1482
1726
  export declare const uiMessages: {
1727
+ readonly "colorField.swatches": "swatches";
1483
1728
  readonly "dialog.close": "Close";
1484
1729
  readonly "fileDropZone.choose": "Choose a file";
1485
1730
  readonly "fileDropZone.chooseMultiple": "Choose files";
1486
1731
  readonly "fileDropZone.hint": "or drop it here";
1487
1732
  readonly "fileDropZone.hintMultiple": "or drop them here";
1488
1733
  readonly "progress.label": "Progress";
1734
+ readonly "reorderableList.moved": "{label} moved to position {position} of {count}";
1489
1735
  readonly "spinner.label": "Loading";
1490
1736
  readonly "errors.INVALID_THEME_TOKEN": "The theme setting {token} has a value that can't be used.";
1491
1737
  readonly "errors.INVALID_THEME_SELECTOR": "The theme can't be applied to the selector {selector}.";