@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.
@@ -5,12 +5,14 @@ var UiError = class extends SdkError {
5
5
  };
6
6
  // src/messages/en.ts
7
7
  var uiMessages = /* @__PURE__ */ defineMessages({
8
+ "colorField.swatches": "swatches",
8
9
  "dialog.close": "Close",
9
10
  "fileDropZone.choose": "Choose a file",
10
11
  "fileDropZone.chooseMultiple": "Choose files",
11
12
  "fileDropZone.hint": "or drop it here",
12
13
  "fileDropZone.hintMultiple": "or drop them here",
13
14
  "progress.label": "Progress",
15
+ "reorderableList.moved": "{label} moved to position {position} of {count}",
14
16
  "spinner.label": "Loading",
15
17
  "errors.INVALID_THEME_TOKEN": "The theme setting {token} has a value that can't be used.",
16
18
  "errors.INVALID_THEME_SELECTOR": "The theme can't be applied to the selector {selector}."
@@ -40,4 +42,4 @@ function isThemePair(value) {
40
42
  }
41
43
  export { uiMessages as a, warnInDevelopment as i, cssWriterOf as n, UiError as o, registerTheme as r, isThemePair as t };
42
44
 
43
- //# sourceMappingURL=pair-DLVFV6vU.js.map
45
+ //# sourceMappingURL=pair-MeX064R6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pair-MeX064R6.js","names":[],"sources":["../../src/errors/ui-error.ts","../../src/messages/en.ts","../../src/internal/development.ts","../../src/theme/registry.ts","../../src/theme/pair.ts"],"sourcesContent":["import { SdkError } from \"@hussmartinez/sdk-core\";\n\n/**\n * Error codes of `@hussmartinez/ui`. They never change once released.\n *\n * - `INVALID_THEME_TOKEN`: a theme token has an unknown name, or a value that\n * isn't allowed for its type. `details` has `token`, `value` and `reason`.\n * - `INVALID_THEME_SELECTOR`: the selector passed to `themeToCss` isn't a\n * plain CSS selector. `details` has `selector` and `reason`.\n *\n * @public\n */\nexport type UiErrorCode = \"INVALID_THEME_TOKEN\" | \"INVALID_THEME_SELECTOR\";\n\n/**\n * The error `@hussmartinez/ui` throws, with a stable `code` and structured\n * `details`. Show users the text for its code from {@link uiMessages}, never\n * its `message`.\n *\n * @example\n * ```ts\n * try {\n * createTheme({ extends: \"light\", tokens: { \"color-accent\": brandColour } });\n * } catch (error) {\n * if (isSdkError(error, \"INVALID_THEME_TOKEN\")) {\n * // Ask for another colour.\n * }\n * }\n * ```\n *\n * @public\n */\nexport class UiError extends SdkError<UiErrorCode> {\n override readonly name = \"UiError\";\n}\n","import { defineMessages } from \"@hussmartinez/sdk-core\";\n\n/**\n * English text for `@hussmartinez/ui`'s error codes. Applications and SDKs\n * spread it into their catalogue, next to `sdkCoreMessages`, so\n * `messages.error()` can describe a `UiError`. Components add their\n * text here as they arrive.\n *\n * @example\n * ```ts\n * export const en = defineMessages({ ...sdkCoreMessages, ...uiMessages });\n * ```\n *\n * @public\n */\nexport const uiMessages = /* @__PURE__ */ defineMessages({\n \"colorField.swatches\": \"swatches\",\n \"dialog.close\": \"Close\",\n \"fileDropZone.choose\": \"Choose a file\",\n \"fileDropZone.chooseMultiple\": \"Choose files\",\n \"fileDropZone.hint\": \"or drop it here\",\n \"fileDropZone.hintMultiple\": \"or drop them here\",\n \"progress.label\": \"Progress\",\n \"reorderableList.moved\": \"{label} moved to position {position} of {count}\",\n \"spinner.label\": \"Loading\",\n \"errors.INVALID_THEME_TOKEN\": \"The theme setting {token} has a value that can't be used.\",\n \"errors.INVALID_THEME_SELECTOR\": \"The theme can't be applied to the selector {selector}.\",\n});\n","declare const process: { readonly env: { readonly NODE_ENV?: string } };\n\n/**\n * Whether development-only checks and warnings are on, as a runtime check.\n * The same pattern as sdk-core's.\n *\n * It keeps a forgotten guard from warning in production, but it can't make a\n * bundle smaller: a bundler can't see through a function call, so the\n * message passed to {@link warnInDevelopment} would still ship. Every call\n * site therefore also guards itself inline, with exactly this expression,\n * which bundlers fold away when they replace `process.env.NODE_ENV`:\n *\n * ```ts\n * if (typeof process !== \"undefined\" && process.env.NODE_ENV !== \"production\") {\n * warnInDevelopment(`…`);\n * }\n * ```\n *\n * `development.test.ts` checks every call site, and `build.test.ts` checks\n * that a production bundle drops the messages. Where nothing defines\n * `process`, such as a page loading the module directly, warnings are off.\n */\nexport function isDevelopment(): boolean {\n try {\n return process.env.NODE_ENV !== \"production\";\n } catch {\n return false;\n }\n}\n\n/**\n * Logs a development-only warning. Call it only inside the inline guard\n * shown on {@link isDevelopment}.\n *\n * @param message - What's wrong and how to fix it.\n */\nexport function warnInDevelopment(message: string): void {\n if (isDevelopment()) {\n // biome-ignore lint/suspicious/noConsole: development-only diagnostics are the purpose of this helper.\n console.warn(`[@hussmartinez/ui] ${message}`);\n }\n}\n","import type { Theme } from \"./types.js\";\n\n/** Writes validated themes as CSS. Lives in css-writer.ts. */\nexport type CssWriter = (light: Theme, dark: Theme | undefined, selector: string) => string;\n\n/**\n * Themes from `createTheme`, with the function that writes them as CSS.\n *\n * Kept apart from `createTheme` so `ThemeProvider` can apply themes without\n * importing the validator, the colour parser or the token data: an\n * application that only uses the built-in themes doesn't ship them.\n */\nconst writers = /* @__PURE__ */ new WeakMap<Theme, CssWriter>();\n\n/** Records a validated theme, and how to write it as CSS. */\nexport function registerTheme(theme: Theme, writer: CssWriter): void {\n writers.set(theme, writer);\n}\n\n/**\n * The CSS writer of a theme from `createTheme`, or `undefined` for anything\n * else, such as a theme parsed from JSON.\n */\nexport function cssWriterOf(theme: unknown): CssWriter | undefined {\n return typeof theme === \"object\" && theme !== null ? writers.get(theme as Theme) : undefined;\n}\n","import type { Theme, ThemePair } from \"./types.js\";\n\n/** Whether a value is a light and dark pair rather than a single theme. */\nexport function isThemePair(value: Theme | ThemePair): value is ThemePair {\n return typeof value === \"object\" && value !== null && \"light\" in value && \"dark\" in value;\n}\n"],"mappings":";;AAgCA,IAAa,UAAb,cAA6B,SAAsB;CACjD,OAAyB;AAC3B;;ACnBA,IAAa,aAA6B,+BAAe;CACvD,uBAAuB;CACvB,gBAAgB;CAChB,uBAAuB;CACvB,+BAA+B;CAC/B,qBAAqB;CACrB,6BAA6B;CAC7B,kBAAkB;CAClB,yBAAyB;CACzB,iBAAiB;CACjB,8BAA8B;CAC9B,iCAAiC;AACnC,CAAC;;ACLD,SAAgB,gBAAyB;CACvC,IAAI;EACF,OAAA,QAAA,IAAA,aAAgC;CAClC,QAAQ;EACN,OAAO;CACT;AACF;AAQA,SAAgB,kBAAkB,SAAuB;CACvD,IAAI,cAAc,GAEhB,QAAQ,KAAK,sBAAsB,SAAS;AAEhD;;AC7BA,IAAM,0BAA0B,IAAI,QAA0B;AAG9D,SAAgB,cAAc,OAAc,QAAyB;CACnE,QAAQ,IAAI,OAAO,MAAM;AAC3B;AAMA,SAAgB,YAAY,OAAuC;CACjE,OAAO,OAAO,UAAU,YAAY,UAAU,OAAO,QAAQ,IAAI,KAAc,IAAI,KAAA;AACrF;;ACtBA,SAAgB,YAAY,OAA8C;CACxE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,WAAW,SAAS,UAAU;AACtF"}
package/dist/styles.css CHANGED
@@ -1219,6 +1219,118 @@
1219
1219
  }
1220
1220
  }
1221
1221
  }
1222
+ @layer hm.components {
1223
+ /*
1224
+ * A text field with several lines: text-field.css gives it the field's
1225
+ * size floor, focus ring, colours, border and states, and this adds what
1226
+ * lines of text need. Kept with unstyled.
1227
+ */
1228
+ .hm-text-area {
1229
+ max-inline-size: 100%;
1230
+ padding-block: var(--hm-text-area-padding-y, var(--hm-inset-tight));
1231
+ /* Taller only: a wider area would break the layout around it. */
1232
+ resize: vertical;
1233
+ /* An inline box would leave room for descenders under it. */
1234
+ vertical-align: top;
1235
+ }
1236
+
1237
+ /* Visual styles, dropped with unstyled. */
1238
+ .hm-text-area:not([data-hm-unstyled]) {
1239
+ line-height: var(--hm-line-height-body);
1240
+ }
1241
+ }
1242
+ @layer hm.components {
1243
+ /*
1244
+ * Layout, focus and target size: kept with unstyled, so the field stays
1245
+ * usable and accessible. The input is a text field, with its class and
1246
+ * tokens.
1247
+ */
1248
+ .hm-color-field {
1249
+ box-sizing: border-box;
1250
+ display: inline-grid;
1251
+ gap: var(--hm-color-field-gap, var(--hm-gap-tight));
1252
+ grid-template-columns: minmax(0, 1fr);
1253
+ }
1254
+
1255
+ .hm-color-field-control {
1256
+ display: flex;
1257
+ gap: var(--hm-color-field-gap, var(--hm-gap-tight));
1258
+ }
1259
+
1260
+ /* As wide as the input is tall, and stretched to its height. */
1261
+ .hm-color-field-preview {
1262
+ box-sizing: border-box;
1263
+ flex: none;
1264
+ inline-size: max(var(--hm-text-field-height, var(--hm-control-height)), var(--hm-target-size));
1265
+ }
1266
+
1267
+ .hm-color-field-input {
1268
+ flex: 1;
1269
+ }
1270
+
1271
+ .hm-color-field-swatches {
1272
+ display: flex;
1273
+ flex-wrap: wrap;
1274
+ gap: var(--hm-color-field-gap, var(--hm-gap-tight));
1275
+ }
1276
+
1277
+ /* The padding keeps the checked ring apart from the colour. */
1278
+ .hm-color-field-swatch {
1279
+ block-size: max(
1280
+ var(--hm-color-field-swatch-size, var(--hm-control-height-small)),
1281
+ var(--hm-target-size)
1282
+ );
1283
+ box-sizing: border-box;
1284
+ cursor: pointer;
1285
+ display: inline-flex;
1286
+ inline-size: max(
1287
+ var(--hm-color-field-swatch-size, var(--hm-control-height-small)),
1288
+ var(--hm-target-size)
1289
+ );
1290
+ padding: var(--hm-focus-ring-offset);
1291
+ }
1292
+
1293
+ .hm-color-field-swatch:focus-visible {
1294
+ outline: var(--hm-focus-ring);
1295
+ outline-offset: var(--hm-focus-ring-offset);
1296
+ }
1297
+
1298
+ .hm-color-field-swatch:disabled {
1299
+ cursor: not-allowed;
1300
+ }
1301
+
1302
+ .hm-color-field-swatch-fill {
1303
+ block-size: 100%;
1304
+ box-sizing: border-box;
1305
+ inline-size: 100%;
1306
+ }
1307
+
1308
+ /*
1309
+ * Visual styles, dropped with unstyled. Every colour has a border, so one
1310
+ * close to the surface's still shows its edge (WCAG 1.4.11).
1311
+ */
1312
+ .hm-color-field:not([data-hm-unstyled]) .hm-color-field-preview,
1313
+ .hm-color-field:not([data-hm-unstyled]) .hm-color-field-swatch-fill {
1314
+ border: var(--hm-border-width) solid
1315
+ var(--hm-color-field-swatch-border-color, var(--hm-color-border-strong));
1316
+ border-radius: var(--hm-color-field-swatch-radius, var(--hm-radius-control));
1317
+ }
1318
+
1319
+ .hm-color-field:not([data-hm-unstyled]) .hm-color-field-swatch {
1320
+ background: transparent;
1321
+ border: var(--hm-focus-ring-width) solid transparent;
1322
+ border-radius: var(--hm-color-field-swatch-radius, var(--hm-radius-control));
1323
+ }
1324
+
1325
+ /* The checked swatch has a ring, whatever its colour. */
1326
+ .hm-color-field:not([data-hm-unstyled]) .hm-color-field-swatch[aria-checked="true"] {
1327
+ border-color: var(--hm-color-field-swatch-checked-border-color, var(--hm-color-text));
1328
+ }
1329
+
1330
+ .hm-color-field:not([data-hm-unstyled]) .hm-color-field-swatch:disabled {
1331
+ opacity: var(--hm-opacity-disabled);
1332
+ }
1333
+ }
1222
1334
  @layer hm.components {
1223
1335
  .hm-spinner {
1224
1336
  block-size: var(--hm-spinner-size, var(--hm-icon-size));
@@ -1446,3 +1558,76 @@
1446
1558
  }
1447
1559
  }
1448
1560
  }
1561
+ @layer hm.components {
1562
+ /*
1563
+ * Layout, focus and target size: kept with unstyled, so the list stays
1564
+ * usable and accessible.
1565
+ */
1566
+ .hm-reorderable-list {
1567
+ box-sizing: border-box;
1568
+ display: grid;
1569
+ gap: var(--hm-reorderable-list-gap, var(--hm-gap-tight));
1570
+ grid-template-columns: minmax(0, 1fr);
1571
+ }
1572
+
1573
+ .hm-reorderable-list-row {
1574
+ align-items: center;
1575
+ box-sizing: border-box;
1576
+ display: flex;
1577
+ gap: var(--hm-reorderable-list-gap, var(--hm-gap-tight));
1578
+ min-block-size: max(
1579
+ var(--hm-reorderable-list-row-height, var(--hm-control-height)),
1580
+ var(--hm-target-size)
1581
+ );
1582
+ }
1583
+
1584
+ /* The item fills its row, so the whole row selects it. */
1585
+ .hm-reorderable-list-item {
1586
+ align-items: center;
1587
+ align-self: stretch;
1588
+ box-sizing: border-box;
1589
+ cursor: pointer;
1590
+ display: flex;
1591
+ flex: 1;
1592
+ gap: var(--hm-control-gap);
1593
+ min-inline-size: 0;
1594
+ padding-inline: var(--hm-reorderable-list-row-padding-x, var(--hm-control-padding-x));
1595
+ user-select: none;
1596
+ }
1597
+
1598
+ /* Inside the cell, so a scrolling panel around the list can't clip it. */
1599
+ .hm-reorderable-list-item:focus-visible {
1600
+ outline: var(--hm-focus-ring);
1601
+ outline-offset: calc(var(--hm-focus-ring-width) * -1);
1602
+ }
1603
+
1604
+ .hm-reorderable-list-control {
1605
+ display: flex;
1606
+ flex: none;
1607
+ }
1608
+
1609
+ /* Visual styles, dropped with unstyled. */
1610
+ .hm-reorderable-list:not([data-hm-unstyled]) .hm-reorderable-list-row:not([data-hm-unstyled]) {
1611
+ border: var(--hm-border-width) solid transparent;
1612
+ border-radius: var(--hm-reorderable-list-row-radius, var(--hm-radius-control));
1613
+ color: var(--hm-reorderable-list-row-fg, var(--hm-color-text));
1614
+ font-family: var(--hm-font-family);
1615
+ font-size: var(--hm-font-size-body);
1616
+ letter-spacing: var(--hm-letter-spacing);
1617
+ line-height: var(--hm-line-height-tight);
1618
+ }
1619
+
1620
+ /* Selection shows as a boundary too, not only as a colour (WCAG 1.4.11). */
1621
+ .hm-reorderable-list:not([data-hm-unstyled])
1622
+ .hm-reorderable-list-row[aria-selected="true"]:not([data-hm-unstyled]) {
1623
+ background: var(--hm-reorderable-list-row-selected-bg, var(--hm-color-accent-subtle));
1624
+ border-color: var(--hm-reorderable-list-row-selected-border-color, var(--hm-color-accent));
1625
+ }
1626
+
1627
+ @media (hover: hover) {
1628
+ .hm-reorderable-list:not([data-hm-unstyled])
1629
+ .hm-reorderable-list-row:not([aria-selected="true"], [data-hm-unstyled]):hover {
1630
+ background: var(--hm-reorderable-list-row-bg-hover, var(--hm-color-control-hover));
1631
+ }
1632
+ }
1633
+ }
package/dist/ui.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}.";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hussmartinez/ui",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Design system of the @hussmartinez SDK family: tokens, themes, base styles and accessible React components.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"pair-DLVFV6vU.js","names":[],"sources":["../../src/errors/ui-error.ts","../../src/messages/en.ts","../../src/internal/development.ts","../../src/theme/registry.ts","../../src/theme/pair.ts"],"sourcesContent":["import { SdkError } from \"@hussmartinez/sdk-core\";\n\n/**\n * Error codes of `@hussmartinez/ui`. They never change once released.\n *\n * - `INVALID_THEME_TOKEN`: a theme token has an unknown name, or a value that\n * isn't allowed for its type. `details` has `token`, `value` and `reason`.\n * - `INVALID_THEME_SELECTOR`: the selector passed to `themeToCss` isn't a\n * plain CSS selector. `details` has `selector` and `reason`.\n *\n * @public\n */\nexport type UiErrorCode = \"INVALID_THEME_TOKEN\" | \"INVALID_THEME_SELECTOR\";\n\n/**\n * The error `@hussmartinez/ui` throws, with a stable `code` and structured\n * `details`. Show users the text for its code from {@link uiMessages}, never\n * its `message`.\n *\n * @example\n * ```ts\n * try {\n * createTheme({ extends: \"light\", tokens: { \"color-accent\": brandColour } });\n * } catch (error) {\n * if (isSdkError(error, \"INVALID_THEME_TOKEN\")) {\n * // Ask for another colour.\n * }\n * }\n * ```\n *\n * @public\n */\nexport class UiError extends SdkError<UiErrorCode> {\n override readonly name = \"UiError\";\n}\n","import { defineMessages } from \"@hussmartinez/sdk-core\";\n\n/**\n * English text for `@hussmartinez/ui`'s error codes. Applications and SDKs\n * spread it into their catalogue, next to `sdkCoreMessages`, so\n * `messages.error()` can describe a `UiError`. Components add their\n * text here as they arrive.\n *\n * @example\n * ```ts\n * export const en = defineMessages({ ...sdkCoreMessages, ...uiMessages });\n * ```\n *\n * @public\n */\nexport const uiMessages = /* @__PURE__ */ defineMessages({\n \"dialog.close\": \"Close\",\n \"fileDropZone.choose\": \"Choose a file\",\n \"fileDropZone.chooseMultiple\": \"Choose files\",\n \"fileDropZone.hint\": \"or drop it here\",\n \"fileDropZone.hintMultiple\": \"or drop them here\",\n \"progress.label\": \"Progress\",\n \"spinner.label\": \"Loading\",\n \"errors.INVALID_THEME_TOKEN\": \"The theme setting {token} has a value that can't be used.\",\n \"errors.INVALID_THEME_SELECTOR\": \"The theme can't be applied to the selector {selector}.\",\n});\n","declare const process: { readonly env: { readonly NODE_ENV?: string } };\n\n/**\n * Whether development-only checks and warnings are on, as a runtime check.\n * The same pattern as sdk-core's.\n *\n * It keeps a forgotten guard from warning in production, but it can't make a\n * bundle smaller: a bundler can't see through a function call, so the\n * message passed to {@link warnInDevelopment} would still ship. Every call\n * site therefore also guards itself inline, with exactly this expression,\n * which bundlers fold away when they replace `process.env.NODE_ENV`:\n *\n * ```ts\n * if (typeof process !== \"undefined\" && process.env.NODE_ENV !== \"production\") {\n * warnInDevelopment(`…`);\n * }\n * ```\n *\n * `development.test.ts` checks every call site, and `build.test.ts` checks\n * that a production bundle drops the messages. Where nothing defines\n * `process`, such as a page loading the module directly, warnings are off.\n */\nexport function isDevelopment(): boolean {\n try {\n return process.env.NODE_ENV !== \"production\";\n } catch {\n return false;\n }\n}\n\n/**\n * Logs a development-only warning. Call it only inside the inline guard\n * shown on {@link isDevelopment}.\n *\n * @param message - What's wrong and how to fix it.\n */\nexport function warnInDevelopment(message: string): void {\n if (isDevelopment()) {\n // biome-ignore lint/suspicious/noConsole: development-only diagnostics are the purpose of this helper.\n console.warn(`[@hussmartinez/ui] ${message}`);\n }\n}\n","import type { Theme } from \"./types.js\";\n\n/** Writes validated themes as CSS. Lives in css-writer.ts. */\nexport type CssWriter = (light: Theme, dark: Theme | undefined, selector: string) => string;\n\n/**\n * Themes from `createTheme`, with the function that writes them as CSS.\n *\n * Kept apart from `createTheme` so `ThemeProvider` can apply themes without\n * importing the validator, the colour parser or the token data: an\n * application that only uses the built-in themes doesn't ship them.\n */\nconst writers = /* @__PURE__ */ new WeakMap<Theme, CssWriter>();\n\n/** Records a validated theme, and how to write it as CSS. */\nexport function registerTheme(theme: Theme, writer: CssWriter): void {\n writers.set(theme, writer);\n}\n\n/**\n * The CSS writer of a theme from `createTheme`, or `undefined` for anything\n * else, such as a theme parsed from JSON.\n */\nexport function cssWriterOf(theme: unknown): CssWriter | undefined {\n return typeof theme === \"object\" && theme !== null ? writers.get(theme as Theme) : undefined;\n}\n","import type { Theme, ThemePair } from \"./types.js\";\n\n/** Whether a value is a light and dark pair rather than a single theme. */\nexport function isThemePair(value: Theme | ThemePair): value is ThemePair {\n return typeof value === \"object\" && value !== null && \"light\" in value && \"dark\" in value;\n}\n"],"mappings":";;AAgCA,IAAa,UAAb,cAA6B,SAAsB;CACjD,OAAyB;AAC3B;;ACnBA,IAAa,aAA6B,+BAAe;CACvD,gBAAgB;CAChB,uBAAuB;CACvB,+BAA+B;CAC/B,qBAAqB;CACrB,6BAA6B;CAC7B,kBAAkB;CAClB,iBAAiB;CACjB,8BAA8B;CAC9B,iCAAiC;AACnC,CAAC;;ACHD,SAAgB,gBAAyB;CACvC,IAAI;EACF,OAAA,QAAA,IAAA,aAAgC;CAClC,QAAQ;EACN,OAAO;CACT;AACF;AAQA,SAAgB,kBAAkB,SAAuB;CACvD,IAAI,cAAc,GAEhB,QAAQ,KAAK,sBAAsB,SAAS;AAEhD;;AC7BA,IAAM,0BAA0B,IAAI,QAA0B;AAG9D,SAAgB,cAAc,OAAc,QAAyB;CACnE,QAAQ,IAAI,OAAO,MAAM;AAC3B;AAMA,SAAgB,YAAY,OAAuC;CACjE,OAAO,OAAO,UAAU,YAAY,UAAU,OAAO,QAAQ,IAAI,KAAc,IAAI,KAAA;AACrF;;ACtBA,SAAgB,YAAY,OAA8C;CACxE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,WAAW,SAAS,UAAU;AACtF"}