@hussmartinez/ui 0.8.0 → 0.9.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 +3 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +113 -0
- package/dist/react.js +227 -33
- package/dist/react.js.map +1 -1
- package/dist/shared/{pair-DLVFV6vU.js → pair-pt-vUVwu.js} +2 -1
- package/dist/shared/pair-pt-vUVwu.js.map +1 -0
- package/dist/styles.css +112 -0
- package/dist/ui.d.ts +113 -0
- package/package.json +1 -1
- package/dist/shared/pair-DLVFV6vU.js.map +0 -1
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
|
*
|
|
@@ -1064,6 +1139,43 @@ export declare interface StyleProps<Part extends string> {
|
|
|
1064
1139
|
readonly unstyled?: boolean | undefined;
|
|
1065
1140
|
}
|
|
1066
1141
|
|
|
1142
|
+
/**
|
|
1143
|
+
* A multi-line text input, styled like `TextField`, with its tokens. `rows`
|
|
1144
|
+
* sets its height, three by default, and the user can drag it taller. Inside
|
|
1145
|
+
* a `Field`, it takes the field's label, description and error.
|
|
1146
|
+
*
|
|
1147
|
+
* Enter adds a line, so it doesn't submit a form. Its value separates lines
|
|
1148
|
+
* with `\n`, whatever was pasted.
|
|
1149
|
+
*
|
|
1150
|
+
* @example
|
|
1151
|
+
* ```tsx
|
|
1152
|
+
* <Field label={t("text.content")}>
|
|
1153
|
+
* <TextArea value={text} onValueChange={setText} rows={4} />
|
|
1154
|
+
* </Field>
|
|
1155
|
+
* ```
|
|
1156
|
+
*
|
|
1157
|
+
* @public
|
|
1158
|
+
*/
|
|
1159
|
+
export declare const TextArea: ForwardRefExoticComponent<TextAreaProps & RefAttributes<HTMLTextAreaElement>>;
|
|
1160
|
+
|
|
1161
|
+
/**
|
|
1162
|
+
* Props of {@link TextArea}. Native textarea props are passed through, so it
|
|
1163
|
+
* works controlled with `value` and `onChange`, or uncontrolled with
|
|
1164
|
+
* `defaultValue`.
|
|
1165
|
+
*
|
|
1166
|
+
* @public
|
|
1167
|
+
*/
|
|
1168
|
+
export declare interface TextAreaProps extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, "className">, StyleProps<"root"> {
|
|
1169
|
+
/** Called with the new text as it changes, as well as `onChange`. */
|
|
1170
|
+
readonly onValueChange?: ((value: string) => void) | undefined;
|
|
1171
|
+
/**
|
|
1172
|
+
* The accessible name, such as "Caption". Leave it out inside a `Field`,
|
|
1173
|
+
* or when a visible `<label>` points at the field's `id`, or
|
|
1174
|
+
* `aria-labelledby` names it.
|
|
1175
|
+
*/
|
|
1176
|
+
readonly label?: string | undefined;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1067
1179
|
/**
|
|
1068
1180
|
* A single-line text input, styled like the family's other fields. Inside a
|
|
1069
1181
|
* `Field`, it takes the field's label, description and error.
|
|
@@ -1480,6 +1592,7 @@ export declare type UiMessages = Messages<typeof uiMessages>;
|
|
|
1480
1592
|
* @public
|
|
1481
1593
|
*/
|
|
1482
1594
|
export declare const uiMessages: {
|
|
1595
|
+
readonly "colorField.swatches": "swatches";
|
|
1483
1596
|
readonly "dialog.close": "Close";
|
|
1484
1597
|
readonly "fileDropZone.choose": "Choose a file";
|
|
1485
1598
|
readonly "fileDropZone.chooseMultiple": "Choose files";
|
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { a as uiMessages, i as warnInDevelopment, n as cssWriterOf, o as UiError, t as isThemePair } from "./shared/pair-
|
|
2
|
+
import { a as uiMessages, i as warnInDevelopment, n as cssWriterOf, o as UiError, t as isThemePair } from "./shared/pair-pt-vUVwu.js";
|
|
3
3
|
import { createMessages, platformOf, sdkCoreMessages } from "@hussmartinez/sdk-core";
|
|
4
4
|
import { cloneElement, createContext, forwardRef, isValidElement, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore, version } from "react";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -9,7 +9,7 @@ var REGISTRY = /* @__PURE__ */ Symbol.for("@hussmartinez/ui");
|
|
|
9
9
|
var THIS_COPY = {};
|
|
10
10
|
var checked = false;
|
|
11
11
|
function ownVersion() {
|
|
12
|
-
return "0.
|
|
12
|
+
return "0.9.0";
|
|
13
13
|
}
|
|
14
14
|
function checkSingleCopy() {
|
|
15
15
|
if (checked || !(typeof process !== "undefined" && process.env.NODE_ENV !== "production")) return;
|
|
@@ -144,6 +144,39 @@ var IconButton = /* @__PURE__ */ forwardRef(function IconButton({ label, icon, c
|
|
|
144
144
|
startIcon: icon
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
|
+
// src/components/field/field-context.ts
|
|
148
|
+
var FieldContext = /* @__PURE__ */ createContext(void 0);
|
|
149
|
+
var FieldLabelContext = /* @__PURE__ */ createContext(void 0);
|
|
150
|
+
function useFieldLabelId() {
|
|
151
|
+
return useContext(FieldLabelContext);
|
|
152
|
+
}
|
|
153
|
+
function useFieldControl() {
|
|
154
|
+
checkSingleCopy();
|
|
155
|
+
return useContext(FieldContext);
|
|
156
|
+
}
|
|
157
|
+
function joinIds(...ids) {
|
|
158
|
+
const joined = ids.filter(Boolean).join(" ");
|
|
159
|
+
return joined === "" ? void 0 : joined;
|
|
160
|
+
}
|
|
161
|
+
function useFieldProps(own, label) {
|
|
162
|
+
const field = useFieldControl();
|
|
163
|
+
if (!field) return {
|
|
164
|
+
id: own.id,
|
|
165
|
+
"aria-describedby": own["aria-describedby"],
|
|
166
|
+
"aria-invalid": own["aria-invalid"]
|
|
167
|
+
};
|
|
168
|
+
if (label !== void 0 || own["aria-label"] !== void 0) {
|
|
169
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("A control inside Field has its own label or aria-label, which replaces the field's visible label for screen readers. Leave it out, and set Field's label instead.");
|
|
170
|
+
}
|
|
171
|
+
if (own.id !== void 0 && own.id !== field.id) {
|
|
172
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("A control inside Field has its own id, so the field's label doesn't point at it. Pass the id to Field's controlId instead.");
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
id: own.id ?? field.id,
|
|
176
|
+
"aria-describedby": joinIds(field["aria-describedby"], own["aria-describedby"]),
|
|
177
|
+
"aria-invalid": own["aria-invalid"] ?? field["aria-invalid"]
|
|
178
|
+
};
|
|
179
|
+
}
|
|
147
180
|
// src/components/messages/UiMessagesProvider.tsx
|
|
148
181
|
var UiMessagesContext = /* @__PURE__ */ createContext(void 0);
|
|
149
182
|
var english;
|
|
@@ -174,6 +207,170 @@ function useUiLocale() {
|
|
|
174
207
|
checkSingleCopy();
|
|
175
208
|
return useContext(UiMessagesContext)?.locale ?? "en";
|
|
176
209
|
}
|
|
210
|
+
// src/components/color-field/ColorField.tsx
|
|
211
|
+
var HEX = /^#?(?:([0-9a-f]{3})|([0-9a-f]{6}))$/i;
|
|
212
|
+
function parseHex(text) {
|
|
213
|
+
const match = HEX.exec(text.trim());
|
|
214
|
+
if (!match) return;
|
|
215
|
+
return `#${(match[2] ?? match[1].replace(/./g, "$&$&")).toLowerCase()}`;
|
|
216
|
+
}
|
|
217
|
+
function Fill({ color, className }) {
|
|
218
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
219
|
+
className,
|
|
220
|
+
viewBox: "0 0 1 1",
|
|
221
|
+
preserveAspectRatio: "none",
|
|
222
|
+
"aria-hidden": "true",
|
|
223
|
+
focusable: "false",
|
|
224
|
+
children: /* @__PURE__ */ jsx("rect", {
|
|
225
|
+
width: "1",
|
|
226
|
+
height: "1",
|
|
227
|
+
fill: color
|
|
228
|
+
})
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
var ColorField = /* @__PURE__ */ forwardRef(function ColorField({ value: controlled, defaultValue, onValueChange, swatches, label, swatchesLabel, name, form, disabled, className, classNames, unstyled, onBlur, onKeyDown, ...props }, ref) {
|
|
232
|
+
const [uncontrolled, setUncontrolled] = useState(() => parseHex(defaultValue ?? "") ?? "#000000");
|
|
233
|
+
const [draft, setDraft] = useState(null);
|
|
234
|
+
const value = (controlled === void 0 ? void 0 : parseHex(controlled)) ?? uncontrolled;
|
|
235
|
+
const generated = useId();
|
|
236
|
+
const ownLabelId = `${generated}-label`;
|
|
237
|
+
const swatchesLabelId = `${generated}-swatches`;
|
|
238
|
+
const fieldLabelId = useFieldLabelId();
|
|
239
|
+
const swatchesText = useUiText("colorField.swatches");
|
|
240
|
+
const fieldProps = useFieldProps(props, label);
|
|
241
|
+
if (label === void 0 && !props["aria-label"] && !props["aria-labelledby"] && fieldProps.id === void 0) {
|
|
242
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("ColorField needs an accessible name: pass label, or put it in a Field. Use text from your message catalogue.");
|
|
243
|
+
}
|
|
244
|
+
const options = [];
|
|
245
|
+
for (const swatch of swatches ?? []) {
|
|
246
|
+
const color = parseHex(swatch.value);
|
|
247
|
+
if (color === void 0) {
|
|
248
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment(`ColorField skipped the swatch "${swatch.label}": its value isn't a colour such as #1570ef.`);
|
|
249
|
+
} else if (!options.some((option) => option.value === color)) options.push({
|
|
250
|
+
value: color,
|
|
251
|
+
label: swatch.label
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
const tabStop = options.find((option) => option.value === value) ?? options[0];
|
|
255
|
+
const commit = (next) => {
|
|
256
|
+
setDraft(null);
|
|
257
|
+
if (next === value) return;
|
|
258
|
+
if (controlled === void 0) setUncontrolled(next);
|
|
259
|
+
onValueChange?.(next);
|
|
260
|
+
};
|
|
261
|
+
const commitDraft = () => {
|
|
262
|
+
if (draft === null) return;
|
|
263
|
+
const parsed = parseHex(draft);
|
|
264
|
+
if (parsed === void 0) setDraft(null);
|
|
265
|
+
else commit(parsed);
|
|
266
|
+
};
|
|
267
|
+
const handleChange = (event) => {
|
|
268
|
+
setDraft(event.currentTarget.value);
|
|
269
|
+
};
|
|
270
|
+
const handleBlur = (event) => {
|
|
271
|
+
commitDraft();
|
|
272
|
+
onBlur?.(event);
|
|
273
|
+
};
|
|
274
|
+
const handleKeyDown = (event) => {
|
|
275
|
+
onKeyDown?.(event);
|
|
276
|
+
if (event.defaultPrevented || event.nativeEvent.isComposing) return;
|
|
277
|
+
if (event.key === "Enter") flushSync(commitDraft);
|
|
278
|
+
else if (event.key === "Escape" && draft !== null) {
|
|
279
|
+
event.preventDefault();
|
|
280
|
+
setDraft(null);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
const handleSwatchKeyDown = (event) => {
|
|
284
|
+
const step = event.key === "ArrowRight" || event.key === "ArrowDown" ? 1 : event.key === "ArrowLeft" || event.key === "ArrowUp" ? -1 : 0;
|
|
285
|
+
if (step === 0 || options.length === 0 || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
|
|
288
|
+
const horizontal = event.key === "ArrowRight" || event.key === "ArrowLeft";
|
|
289
|
+
const direction = rtl && horizontal ? -step : step;
|
|
290
|
+
const focused = options.findIndex((option) => option.value === event.target.dataset["hmValue"]);
|
|
291
|
+
const next = options[(Math.max(0, focused) + direction + options.length) % options.length];
|
|
292
|
+
if (next) {
|
|
293
|
+
commit(next.value);
|
|
294
|
+
event.currentTarget.querySelector(`[data-hm-value="${CSS.escape(next.value)}"]`)?.focus();
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
const groupLabelIds = [fieldLabelId ?? (label === void 0 ? props["aria-labelledby"] : ownLabelId), swatchesLabelId].filter(Boolean).join(" ");
|
|
298
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
299
|
+
ref,
|
|
300
|
+
className: cx("hm-color-field", classNames?.root, className),
|
|
301
|
+
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
302
|
+
children: [
|
|
303
|
+
/* @__PURE__ */ jsxs("div", {
|
|
304
|
+
className: cx("hm-color-field-control", classNames?.control),
|
|
305
|
+
children: [/* @__PURE__ */ jsx(Fill, {
|
|
306
|
+
color: value,
|
|
307
|
+
className: cx("hm-color-field-preview", classNames?.preview)
|
|
308
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
309
|
+
...props,
|
|
310
|
+
...fieldProps,
|
|
311
|
+
type: "text",
|
|
312
|
+
autoComplete: props.autoComplete ?? "off",
|
|
313
|
+
autoCapitalize: props.autoCapitalize ?? "off",
|
|
314
|
+
autoCorrect: props.autoCorrect ?? "off",
|
|
315
|
+
spellCheck: props.spellCheck ?? false,
|
|
316
|
+
maxLength: props.maxLength ?? 7,
|
|
317
|
+
disabled,
|
|
318
|
+
value: draft ?? value,
|
|
319
|
+
"aria-label": label ?? props["aria-label"],
|
|
320
|
+
className: cx("hm-text-field", "hm-color-field-input", classNames?.input),
|
|
321
|
+
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
322
|
+
onChange: handleChange,
|
|
323
|
+
onBlur: handleBlur,
|
|
324
|
+
onKeyDown: handleKeyDown
|
|
325
|
+
})]
|
|
326
|
+
}),
|
|
327
|
+
options.length === 0 ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
328
|
+
label === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
329
|
+
id: ownLabelId,
|
|
330
|
+
hidden: true,
|
|
331
|
+
children: label
|
|
332
|
+
}),
|
|
333
|
+
/* @__PURE__ */ jsx("span", {
|
|
334
|
+
id: swatchesLabelId,
|
|
335
|
+
hidden: true,
|
|
336
|
+
children: swatchesLabel ?? swatchesText
|
|
337
|
+
}),
|
|
338
|
+
/* @__PURE__ */ jsx("div", {
|
|
339
|
+
role: "radiogroup",
|
|
340
|
+
"aria-labelledby": groupLabelIds,
|
|
341
|
+
"aria-disabled": disabled ? true : void 0,
|
|
342
|
+
className: cx("hm-color-field-swatches", classNames?.swatches),
|
|
343
|
+
onKeyDown: handleSwatchKeyDown,
|
|
344
|
+
children: options.map((option) => {
|
|
345
|
+
const checked = option.value === value;
|
|
346
|
+
return /* @__PURE__ */ jsx("button", {
|
|
347
|
+
type: "button",
|
|
348
|
+
role: "radio",
|
|
349
|
+
"aria-checked": checked,
|
|
350
|
+
"aria-label": option.label,
|
|
351
|
+
disabled,
|
|
352
|
+
tabIndex: option === tabStop ? 0 : -1,
|
|
353
|
+
"data-hm-value": option.value,
|
|
354
|
+
className: cx("hm-color-field-swatch", classNames?.swatch),
|
|
355
|
+
onClick: () => commit(option.value),
|
|
356
|
+
children: /* @__PURE__ */ jsx(Fill, {
|
|
357
|
+
color: option.value,
|
|
358
|
+
className: "hm-color-field-swatch-fill"
|
|
359
|
+
})
|
|
360
|
+
}, option.value);
|
|
361
|
+
})
|
|
362
|
+
})
|
|
363
|
+
] }),
|
|
364
|
+
name === void 0 ? null : /* @__PURE__ */ jsx("input", {
|
|
365
|
+
type: "hidden",
|
|
366
|
+
name,
|
|
367
|
+
form,
|
|
368
|
+
disabled,
|
|
369
|
+
value
|
|
370
|
+
})
|
|
371
|
+
]
|
|
372
|
+
});
|
|
373
|
+
});
|
|
177
374
|
// src/components/dialog/CloseIcon.tsx
|
|
178
375
|
function CloseIcon$1() {
|
|
179
376
|
return /* @__PURE__ */ jsx("svg", {
|
|
@@ -287,39 +484,11 @@ var Dialog = /* @__PURE__ */ forwardRef(function Dialog({ open, onOpenChange, ti
|
|
|
287
484
|
]
|
|
288
485
|
});
|
|
289
486
|
});
|
|
290
|
-
// src/components/field/field-context.ts
|
|
291
|
-
var FieldContext = /* @__PURE__ */ createContext(void 0);
|
|
292
|
-
function useFieldControl() {
|
|
293
|
-
checkSingleCopy();
|
|
294
|
-
return useContext(FieldContext);
|
|
295
|
-
}
|
|
296
|
-
function joinIds(...ids) {
|
|
297
|
-
const joined = ids.filter(Boolean).join(" ");
|
|
298
|
-
return joined === "" ? void 0 : joined;
|
|
299
|
-
}
|
|
300
|
-
function useFieldProps(own, label) {
|
|
301
|
-
const field = useFieldControl();
|
|
302
|
-
if (!field) return {
|
|
303
|
-
id: own.id,
|
|
304
|
-
"aria-describedby": own["aria-describedby"],
|
|
305
|
-
"aria-invalid": own["aria-invalid"]
|
|
306
|
-
};
|
|
307
|
-
if (label !== void 0 || own["aria-label"] !== void 0) {
|
|
308
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("A control inside Field has its own label or aria-label, which replaces the field's visible label for screen readers. Leave it out, and set Field's label instead.");
|
|
309
|
-
}
|
|
310
|
-
if (own.id !== void 0 && own.id !== field.id) {
|
|
311
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("A control inside Field has its own id, so the field's label doesn't point at it. Pass the id to Field's controlId instead.");
|
|
312
|
-
}
|
|
313
|
-
return {
|
|
314
|
-
id: own.id ?? field.id,
|
|
315
|
-
"aria-describedby": joinIds(field["aria-describedby"], own["aria-describedby"]),
|
|
316
|
-
"aria-invalid": own["aria-invalid"] ?? field["aria-invalid"]
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
487
|
// src/components/field/Field.tsx
|
|
320
488
|
var Field = /* @__PURE__ */ forwardRef(function Field({ label, description, error, controlId, className, classNames, unstyled, children, ...props }, ref) {
|
|
321
489
|
const generated = useId();
|
|
322
490
|
const id = controlId ?? `${generated}-control`;
|
|
491
|
+
const labelId = `${generated}-label`;
|
|
323
492
|
const descriptionId = `${generated}-description`;
|
|
324
493
|
const errorId = `${generated}-error`;
|
|
325
494
|
const hasDescription = description != null && description !== false;
|
|
@@ -336,6 +505,7 @@ var Field = /* @__PURE__ */ forwardRef(function Field({ label, description, erro
|
|
|
336
505
|
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
337
506
|
children: [
|
|
338
507
|
/* @__PURE__ */ jsx("label", {
|
|
508
|
+
id: labelId,
|
|
339
509
|
htmlFor: id,
|
|
340
510
|
className: cx("hm-field-label", classNames?.label),
|
|
341
511
|
children: label
|
|
@@ -347,7 +517,10 @@ var Field = /* @__PURE__ */ forwardRef(function Field({ label, description, erro
|
|
|
347
517
|
}) : null,
|
|
348
518
|
/* @__PURE__ */ jsx(FieldContext.Provider, {
|
|
349
519
|
value: control,
|
|
350
|
-
children:
|
|
520
|
+
children: /* @__PURE__ */ jsx(FieldLabelContext.Provider, {
|
|
521
|
+
value: labelId,
|
|
522
|
+
children: typeof children === "function" ? children(control) : children
|
|
523
|
+
})
|
|
351
524
|
}),
|
|
352
525
|
hasError ? /* @__PURE__ */ jsx("div", {
|
|
353
526
|
id: errorId,
|
|
@@ -800,6 +973,27 @@ var Spinner = /* @__PURE__ */ forwardRef(function Spinner({ label, className, cl
|
|
|
800
973
|
"data-hm-unstyled": unstyledAttribute(unstyled)
|
|
801
974
|
});
|
|
802
975
|
});
|
|
976
|
+
// src/components/text-area/TextArea.tsx
|
|
977
|
+
var TextArea = /* @__PURE__ */ forwardRef(function TextArea({ rows = 3, onValueChange, onChange, label, className, classNames, unstyled, ...props }, ref) {
|
|
978
|
+
const fieldProps = useFieldProps(props, label);
|
|
979
|
+
if (label === void 0 && !props["aria-label"] && !props["aria-labelledby"] && fieldProps.id === void 0) {
|
|
980
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("TextArea needs an accessible name: pass label, or put it in a Field. Use text from your message catalogue.");
|
|
981
|
+
}
|
|
982
|
+
const handleChange = (event) => {
|
|
983
|
+
onChange?.(event);
|
|
984
|
+
onValueChange?.(event.currentTarget.value);
|
|
985
|
+
};
|
|
986
|
+
return /* @__PURE__ */ jsx("textarea", {
|
|
987
|
+
...props,
|
|
988
|
+
...fieldProps,
|
|
989
|
+
ref,
|
|
990
|
+
rows,
|
|
991
|
+
"aria-label": label ?? props["aria-label"],
|
|
992
|
+
className: cx("hm-text-field", "hm-text-area", classNames?.root, className),
|
|
993
|
+
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
994
|
+
onChange: handleChange
|
|
995
|
+
});
|
|
996
|
+
});
|
|
803
997
|
// src/components/text-field/TextField.tsx
|
|
804
998
|
var TextField = /* @__PURE__ */ forwardRef(function TextField({ type = "text", onValueChange, onChange, label, className, classNames, unstyled, ...props }, ref) {
|
|
805
999
|
const fieldProps = useFieldProps(props, label);
|
|
@@ -1605,6 +1799,6 @@ function ThemeProvider(props) {
|
|
|
1605
1799
|
}), children]
|
|
1606
1800
|
});
|
|
1607
1801
|
}
|
|
1608
|
-
export { AddIcon, AnnouncerProvider, ArrowIcon, Button, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CloseIcon, CropIcon, DeleteIcon, Dialog, DownloadIcon, DuplicateIcon, EllipseIcon, FadeInIcon, FadeOutIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, HiddenIcon, HighlighterIcon, IconButton, InfoIcon, LayersIcon, LoopIcon, MenuIcon, MoreIcon, MoveDownIcon, MoveUpIcon, MutedIcon, NumberField, OpenIcon, PageAddIcon, PageGridIcon, PageSingleIcon, PanIcon, PauseIcon, PenIcon, PlayIcon, ProgressBar, RectangleIcon, RedactIcon, RedoIcon, RemoveIcon, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, SelectIcon, SkipBackIcon, SkipForwardIcon, Slider, SnapIcon, Spinner, SplitIcon, StopIcon, TextField, TextIcon, ThemeProvider, ToggleButton, Toolbar, ToolbarGroup, ToolbarSeparator, Tooltip, TrimEndIcon, TrimStartIcon, UiMessagesProvider, UndoIcon, UploadIcon, VisibleIcon, VisuallyHidden, VolumeIcon, WarningIcon, ZoomInIcon, ZoomOutIcon, uiMessages, useAnnounce, usePlatform, useUiMessages };
|
|
1802
|
+
export { AddIcon, AnnouncerProvider, ArrowIcon, Button, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CloseIcon, ColorField, CropIcon, DeleteIcon, Dialog, DownloadIcon, DuplicateIcon, EllipseIcon, FadeInIcon, FadeOutIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, HiddenIcon, HighlighterIcon, IconButton, InfoIcon, LayersIcon, LoopIcon, MenuIcon, MoreIcon, MoveDownIcon, MoveUpIcon, MutedIcon, NumberField, OpenIcon, PageAddIcon, PageGridIcon, PageSingleIcon, PanIcon, PauseIcon, PenIcon, PlayIcon, ProgressBar, RectangleIcon, RedactIcon, RedoIcon, RemoveIcon, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, SelectIcon, SkipBackIcon, SkipForwardIcon, Slider, SnapIcon, Spinner, SplitIcon, StopIcon, TextArea, TextField, TextIcon, ThemeProvider, ToggleButton, Toolbar, ToolbarGroup, ToolbarSeparator, Tooltip, TrimEndIcon, TrimStartIcon, UiMessagesProvider, UndoIcon, UploadIcon, VisibleIcon, VisuallyHidden, VolumeIcon, WarningIcon, ZoomInIcon, ZoomOutIcon, uiMessages, useAnnounce, usePlatform, useUiMessages };
|
|
1609
1803
|
|
|
1610
1804
|
//# sourceMappingURL=react.js.map
|