@traefik-labs/faency 13.4.0 → 13.5.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/components/AriaTable/AriaTable.cjs +15 -5
- package/dist/components/AriaTable/AriaTable.cjs.map +1 -1
- package/dist/components/AriaTable/AriaTable.js +16 -6
- package/dist/components/AriaTable/AriaTable.js.map +1 -1
- package/dist/components/CodeBlock/CodeBlock.cjs +2 -2
- package/dist/components/CodeBlock/CodeBlock.js +2 -2
- package/dist/components/CodeBlock/CodeBlock.vanilla.cjs +3 -3
- package/dist/components/CodeBlock/CodeBlock.vanilla.js +3 -3
- package/dist/components/DateTimePicker/DateTimePicker.cjs +1 -1
- package/dist/components/DateTimePicker/DateTimePicker.js +1 -1
- package/dist/components/Dialog/Dialog.cjs +1 -1
- package/dist/components/Dialog/Dialog.js +1 -1
- package/dist/components/Field/Field.cjs +80 -33
- package/dist/components/Field/Field.cjs.map +1 -1
- package/dist/components/Field/Field.js +80 -33
- package/dist/components/Field/Field.js.map +1 -1
- package/dist/components/Field/Field.vanilla.cjs +62 -32
- package/dist/components/Field/Field.vanilla.cjs.map +1 -1
- package/dist/components/Field/Field.vanilla.css.cjs +6 -0
- package/dist/components/Field/Field.vanilla.css.cjs.map +1 -1
- package/dist/components/Field/Field.vanilla.css.js +4 -1
- package/dist/components/Field/Field.vanilla.css.js.map +1 -1
- package/dist/components/Field/Field.vanilla.js +63 -33
- package/dist/components/Field/Field.vanilla.js.map +1 -1
- package/dist/components/Field/FieldContext.cjs +48 -10
- package/dist/components/Field/FieldContext.cjs.map +1 -1
- package/dist/components/Field/FieldContext.js +48 -10
- package/dist/components/Field/FieldContext.js.map +1 -1
- package/dist/components/List/List.cjs +1 -1
- package/dist/components/List/List.js +1 -1
- package/dist/components/Meter/Meter.vanilla.cjs +1 -1
- package/dist/components/Meter/Meter.vanilla.js +1 -1
- package/dist/components/NavigationTree/NavigationTreeItem.cjs +2 -2
- package/dist/components/NavigationTree/NavigationTreeItem.js +2 -2
- package/dist/components/RowLink/RowLink.cjs +35 -12
- package/dist/components/RowLink/RowLink.cjs.map +1 -1
- package/dist/components/RowLink/RowLink.js +34 -12
- package/dist/components/RowLink/RowLink.js.map +1 -1
- package/dist/components/Select/Select.cjs +1 -1
- package/dist/components/Select/Select.js +1 -1
- package/dist/components/Spinner/Spinner.vanilla.cjs +1 -1
- package/dist/components/Spinner/Spinner.vanilla.js +1 -1
- package/dist/components/Table/Table.cjs +13 -4
- package/dist/components/Table/Table.cjs.map +1 -1
- package/dist/components/Table/Table.js +13 -4
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/TextField/TextField.cjs +1 -1
- package/dist/components/TextField/TextField.js +1 -1
- package/dist/components/TextField/TextField.vanilla.cjs +1 -1
- package/dist/components/TextField/TextField.vanilla.js +1 -1
- package/dist/components/Textarea/Textarea.cjs +2 -2
- package/dist/components/Textarea/Textarea.js +2 -2
- package/dist/components/Textarea/Textarea.vanilla.cjs +2 -2
- package/dist/components/Textarea/Textarea.vanilla.js +2 -2
- package/dist/components/Toast/ToastProvider.vanilla.cjs +1 -1
- package/dist/components/Toast/ToastProvider.vanilla.js +1 -1
- package/dist/faency.css +1612 -1597
- package/dist/index.cjs +29 -29
- package/dist/index.d.ts +26 -7
- package/dist/index.js +29 -29
- package/dist/utils/warnOnce.cjs +13 -0
- package/dist/utils/warnOnce.cjs.map +1 -0
- package/dist/utils/warnOnce.js +13 -0
- package/dist/utils/warnOnce.js.map +1 -0
- package/package.json +10 -17
|
@@ -1,33 +1,45 @@
|
|
|
1
1
|
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_warnOnce = require("../../utils/warnOnce.cjs");
|
|
2
3
|
let react = require("react");
|
|
3
4
|
react = require_runtime.__toESM(react, 1);
|
|
4
5
|
// components/Field/FieldContext.ts
|
|
5
6
|
var FieldContext = react.default.createContext(null);
|
|
6
7
|
var useFieldContext = () => react.default.useContext(FieldContext);
|
|
7
8
|
var hasContent = (node) => node !== void 0 && node !== null && node !== false && node !== "";
|
|
8
|
-
var
|
|
9
|
+
var noop = () => {};
|
|
10
|
+
var MULTIPLE_CONTROLS_WARNING = "Field: more than one control is in this Field, and its label points to one of them only. Use group, or one Field per control.";
|
|
11
|
+
var useFieldRoot = ({ id, label, hint, description, error, invalid, disabled, messageSize, group = false }) => {
|
|
9
12
|
const outerContext = useFieldContext();
|
|
10
13
|
const generatedId = react.default.useId();
|
|
11
14
|
const hasLabel = typeof label === "function" || hasContent(label);
|
|
15
|
+
const hasHint = hasContent(hint);
|
|
16
|
+
const resolvedMessageSize = messageSize ?? outerContext?.messageSize ?? "0";
|
|
12
17
|
const hasDescription = hasContent(description);
|
|
13
18
|
const hasError = hasContent(error);
|
|
14
19
|
const isInvalid = Boolean(invalid) || hasError;
|
|
20
|
+
const isDisabled = Boolean(disabled) || Boolean(outerContext?.disabled);
|
|
15
21
|
const [control, setControl] = react.default.useState(null);
|
|
16
|
-
const
|
|
22
|
+
const controlsRef = react.default.useRef(/* @__PURE__ */ new Map());
|
|
23
|
+
const registerControl = react.default.useCallback((key, state) => {
|
|
24
|
+
const controls = controlsRef.current;
|
|
25
|
+
if (state) controls.set(key, state);
|
|
26
|
+
else controls.delete(key);
|
|
27
|
+
if (controls.size > 1) require_warnOnce.warnOnce(MULTIPLE_CONTROLS_WARNING);
|
|
28
|
+
const next = controls.values().next().value ?? null;
|
|
17
29
|
setControl((prev) => prev?.id === next?.id && prev?.disabled === next?.disabled && prev?.invalid === next?.invalid && prev?.labelable === next?.labelable ? prev : next);
|
|
18
30
|
}, []);
|
|
19
31
|
const controlId = control?.id ?? id ?? (hasLabel ? `${generatedId}-control` : void 0);
|
|
20
|
-
const labelFor = control
|
|
32
|
+
const labelFor = group ? void 0 : control ? control.labelable === false ? void 0 : controlId : id;
|
|
21
33
|
const [hasFocus, setHasFocus] = react.default.useState(false);
|
|
22
34
|
const onFocus = react.default.useCallback(() => setHasFocus(true), []);
|
|
23
35
|
const onBlur = react.default.useCallback(() => setHasFocus(false), []);
|
|
24
36
|
const labelVariant = react.default.useMemo(() => {
|
|
25
|
-
if (
|
|
37
|
+
if (isDisabled || control?.disabled) return "subtle";
|
|
26
38
|
if (isInvalid || control?.invalid) return "invalid";
|
|
27
39
|
if (hasFocus) return "contrast";
|
|
28
40
|
return "default";
|
|
29
41
|
}, [
|
|
30
|
-
|
|
42
|
+
isDisabled,
|
|
31
43
|
isInvalid,
|
|
32
44
|
hasFocus,
|
|
33
45
|
control?.disabled,
|
|
@@ -38,8 +50,10 @@ var useFieldRoot = ({ id, label, description, error, invalid, disabled }) => {
|
|
|
38
50
|
labelId: hasLabel ? `${generatedId}-label` : void 0,
|
|
39
51
|
descriptionId: hasDescription ? `${generatedId}-description` : void 0,
|
|
40
52
|
errorId: hasError ? `${generatedId}-error` : void 0,
|
|
53
|
+
hintId: hasHint ? `${generatedId}-hint` : void 0,
|
|
54
|
+
messageSize: resolvedMessageSize,
|
|
41
55
|
invalid: isInvalid,
|
|
42
|
-
disabled:
|
|
56
|
+
disabled: isDisabled,
|
|
43
57
|
registerControl
|
|
44
58
|
}), [
|
|
45
59
|
controlId,
|
|
@@ -47,15 +61,36 @@ var useFieldRoot = ({ id, label, description, error, invalid, disabled }) => {
|
|
|
47
61
|
hasLabel,
|
|
48
62
|
hasDescription,
|
|
49
63
|
hasError,
|
|
64
|
+
hasHint,
|
|
65
|
+
resolvedMessageSize,
|
|
50
66
|
isInvalid,
|
|
51
|
-
|
|
67
|
+
isDisabled,
|
|
52
68
|
registerControl
|
|
53
69
|
]);
|
|
70
|
+
const groupContext = react.default.useMemo(() => ({
|
|
71
|
+
messageSize: resolvedMessageSize,
|
|
72
|
+
invalid: false,
|
|
73
|
+
disabled: isDisabled,
|
|
74
|
+
registerControl: noop
|
|
75
|
+
}), [resolvedMessageSize, isDisabled]);
|
|
76
|
+
const groupProps = group ? {
|
|
77
|
+
role: "group",
|
|
78
|
+
"aria-labelledby": ownContext.labelId,
|
|
79
|
+
"aria-describedby": [
|
|
80
|
+
ownContext.errorId,
|
|
81
|
+
ownContext.descriptionId,
|
|
82
|
+
ownContext.hintId
|
|
83
|
+
].filter(Boolean).join(" ") || void 0
|
|
84
|
+
} : {};
|
|
54
85
|
return {
|
|
55
|
-
context: outerContext && !hasLabel && !hasDescription && !hasError ? outerContext : ownContext,
|
|
86
|
+
context: group ? groupContext : outerContext && !hasLabel && !hasHint && !hasDescription && !hasError ? outerContext : ownContext,
|
|
87
|
+
ids: ownContext,
|
|
88
|
+
groupProps,
|
|
89
|
+
messageSize: resolvedMessageSize,
|
|
56
90
|
labelFor,
|
|
57
91
|
labelVariant,
|
|
58
92
|
hasLabel,
|
|
93
|
+
hasHint,
|
|
59
94
|
hasDescription,
|
|
60
95
|
hasError,
|
|
61
96
|
onFocus,
|
|
@@ -69,20 +104,22 @@ var useFieldRoot = ({ id, label, description, error, invalid, disabled }) => {
|
|
|
69
104
|
*/
|
|
70
105
|
var useFieldControl = ({ id, invalid, disabled, "aria-describedby": describedBy, "aria-invalid": ariaInvalid, labelable = true }) => {
|
|
71
106
|
const field = useFieldContext();
|
|
107
|
+
const registrationId = react.default.useId();
|
|
72
108
|
const ownInvalid = Boolean(invalid || ariaInvalid === true || ariaInvalid === "true");
|
|
73
109
|
const isInvalid = ownInvalid || Boolean(field?.invalid);
|
|
74
110
|
const registerControl = field?.registerControl;
|
|
75
111
|
react.default.useEffect(() => {
|
|
76
112
|
if (!registerControl) return;
|
|
77
|
-
registerControl({
|
|
113
|
+
registerControl(registrationId, {
|
|
78
114
|
id,
|
|
79
115
|
disabled: Boolean(disabled),
|
|
80
116
|
invalid: ownInvalid,
|
|
81
117
|
labelable
|
|
82
118
|
});
|
|
83
|
-
return () => registerControl(null);
|
|
119
|
+
return () => registerControl(registrationId, null);
|
|
84
120
|
}, [
|
|
85
121
|
registerControl,
|
|
122
|
+
registrationId,
|
|
86
123
|
id,
|
|
87
124
|
disabled,
|
|
88
125
|
ownInvalid,
|
|
@@ -91,6 +128,7 @@ var useFieldControl = ({ id, invalid, disabled, "aria-describedby": describedBy,
|
|
|
91
128
|
const describedByIds = [
|
|
92
129
|
field?.errorId,
|
|
93
130
|
field?.descriptionId,
|
|
131
|
+
field?.hintId,
|
|
94
132
|
describedBy
|
|
95
133
|
].filter(Boolean).join(" ") || void 0;
|
|
96
134
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldContext.cjs","names":["React"],"sources":["../../../components/Field/FieldContext.ts"],"sourcesContent":["import React from 'react';\n\ntype FieldControlState = { id?: string; disabled: boolean; invalid: boolean; labelable: boolean };\n\nexport type FieldContextValue = {\n controlId?: string;\n labelId?: string;\n descriptionId?: string;\n errorId?: string;\n invalid: boolean;\n disabled: boolean;\n registerControl: (state: FieldControlState | null) => void;\n};\n\nexport const FieldContext = React.createContext<FieldContextValue | null>(null);\n\nexport const useFieldContext = () => React.useContext(FieldContext);\n\nexport type FieldControlOptions = {\n id?: string;\n invalid?: boolean;\n disabled?: boolean;\n 'aria-describedby'?: string;\n 'aria-invalid'?: React.AriaAttributes['aria-invalid'];\n /** Set to false when the control is not a labelable element, such as a radio group. */\n labelable?: boolean;\n};\n\nexport type FieldLabelVariant = 'invalid' | 'subtle' | 'contrast' | 'default';\n\nexport type FieldLabelProps = {\n variant: FieldLabelVariant;\n htmlFor?: string;\n id: string;\n};\n\nexport type FieldBaseProps = {\n id?: string;\n label?: React.ReactNode | ((props: FieldLabelProps) => React.ReactNode);\n description?: React.ReactNode;\n error?: React.ReactNode;\n invalid?: boolean;\n disabled?: boolean;\n announceError?: boolean;\n labelPosition?: 'top' | 'end';\n children?: React.ReactNode;\n};\n\nconst hasContent = (node: React.ReactNode) =>\n node !== undefined && node !== null && node !== false && node !== '';\n\nexport const useFieldRoot = ({\n id,\n label,\n description,\n error,\n invalid,\n disabled,\n}: FieldBaseProps) => {\n const outerContext = useFieldContext();\n const generatedId = React.useId();\n const hasLabel = typeof label === 'function' || hasContent(label);\n const hasDescription = hasContent(description);\n const hasError = hasContent(error);\n const isInvalid = Boolean(invalid) || hasError;\n\n const [control, setControl] = React.useState<FieldControlState | null>(null);\n const registerControl = React.useCallback((next: FieldControlState | null) => {\n setControl((prev) =>\n prev?.id === next?.id &&\n prev?.disabled === next?.disabled &&\n prev?.invalid === next?.invalid &&\n prev?.labelable === next?.labelable\n ? prev\n : next,\n );\n }, []);\n const controlId = control?.id ?? id ?? (hasLabel ? `${generatedId}-control` : undefined);\n const labelFor = control?.labelable === false ? undefined : controlId;\n\n const [hasFocus, setHasFocus] = React.useState(false);\n const onFocus = React.useCallback(() => setHasFocus(true), []);\n const onBlur = React.useCallback(() => setHasFocus(false), []);\n\n const labelVariant: FieldLabelVariant = React.useMemo(() => {\n if (disabled || control?.disabled) {\n return 'subtle';\n }\n if (isInvalid || control?.invalid) {\n return 'invalid';\n }\n if (hasFocus) {\n return 'contrast';\n }\n return 'default';\n }, [disabled, isInvalid, hasFocus, control?.disabled, control?.invalid]);\n\n const ownContext: FieldContextValue = React.useMemo(\n () => ({\n controlId,\n labelId: hasLabel ? `${generatedId}-label` : undefined,\n descriptionId: hasDescription ? `${generatedId}-description` : undefined,\n errorId: hasError ? `${generatedId}-error` : undefined,\n invalid: isInvalid,\n disabled: Boolean(disabled),\n registerControl,\n }),\n [\n controlId,\n generatedId,\n hasLabel,\n hasDescription,\n hasError,\n isInvalid,\n disabled,\n registerControl,\n ],\n );\n\n // A Field with no label, description or error inside another Field keeps the outer one.\n const context =\n outerContext && !hasLabel && !hasDescription && !hasError ? outerContext : ownContext;\n\n return { context, labelFor, labelVariant, hasLabel, hasDescription, hasError, onFocus, onBlur };\n};\n\n/**\n * Gives a form control the id, `aria-describedby`, `aria-invalid` and `disabled` of the `Field` around it,\n * and gives its own id, `disabled` and invalid state to that `Field`.\n * Outside a `Field`, it only sets `aria-invalid` from `invalid`.\n */\nexport const useFieldControl = ({\n id,\n invalid,\n disabled,\n 'aria-describedby': describedBy,\n 'aria-invalid': ariaInvalid,\n labelable = true,\n}: FieldControlOptions) => {\n const field = useFieldContext();\n const ownInvalid = Boolean(invalid || ariaInvalid === true || ariaInvalid === 'true');\n const isInvalid = ownInvalid || Boolean(field?.invalid);\n const registerControl = field?.registerControl;\n\n React.useEffect(() => {\n if (!registerControl) {\n return undefined;\n }\n registerControl({ id, disabled: Boolean(disabled), invalid: ownInvalid, labelable });\n return () => registerControl(null);\n }, [registerControl, id, disabled, ownInvalid, labelable]);\n const describedByIds =\n [field?.errorId, field?.descriptionId, describedBy].filter(Boolean).join(' ') || undefined;\n\n return {\n id: id ?? field?.controlId,\n labelId: field?.labelId,\n invalid: isInvalid,\n disabled: disabled || field?.disabled || undefined,\n 'aria-describedby': describedByIds,\n 'aria-invalid': isInvalid ? true : ariaInvalid,\n };\n};\n\nconst ANNOUNCE_DELAY = 1000;\n\n/**\n * Returns the text of the error, after the text of the label when there is one, once it has not\n * changed for a short time, so that a screen reader reads it after the echo of the typed text.\n */\nexport const useAnnouncedError = (enabled: boolean, errorId?: string, labelId?: string) => {\n const [announcedError, setAnnouncedError] = React.useState<string | null>(null);\n const lastTextRef = React.useRef<string | null | undefined>(undefined);\n const timeoutRef = React.useRef<ReturnType<typeof setTimeout>>();\n\n // Compares the rendered text, so that a new JSX error with the same text does not restart the delay.\n React.useEffect(() => {\n const text =\n (enabled && errorId && document.getElementById(errorId)?.textContent?.trim()) || null;\n if (text === lastTextRef.current) {\n return;\n }\n lastTextRef.current = text;\n clearTimeout(timeoutRef.current);\n timeoutRef.current = setTimeout(\n () => {\n const fieldName = labelId\n ? document.getElementById(labelId)?.textContent?.trim()\n : undefined;\n setAnnouncedError(text !== null && fieldName ? `${fieldName}: ${text}` : text);\n },\n text === null ? 0 : ANNOUNCE_DELAY,\n );\n });\n\n React.useEffect(\n () => () => {\n clearTimeout(timeoutRef.current);\n lastTextRef.current = undefined;\n },\n [],\n );\n\n return announcedError;\n};\n"],"mappings":";;;;AAcA,IAAa,eAAeA,MAAAA,QAA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;CAC9E,MAAM,cAAcA,MAAAA,QAAM,OAAkC,KAAA,CAAS;CACrE,MAAM,aAAaA,MAAAA,QAAM,OAAsC;CAG/D,MAAA,QAAM,gBAAgB;EACpB,MAAM,OACH,WAAW,WAAW,SAAS,eAAe,OAAO,CAAC,EAAE,aAAa,KAAK,KAAM;EACnF,IAAI,SAAS,YAAY,SACvB;EAEF,YAAY,UAAU;EACtB,aAAa,WAAW,OAAO;EAC/B,WAAW,UAAU,iBACb;GACJ,MAAM,YAAY,UACd,SAAS,eAAe,OAAO,CAAC,EAAE,aAAa,KAAK,IACpD,KAAA;GACJ,kBAAkB,SAAS,QAAQ,YAAY,GAAG,UAAU,IAAI,SAAS,IAAI;EAC/E,GACA,SAAS,OAAO,IAAI,cACtB;CACF,CAAC;CAED,MAAA,QAAM,sBACQ;EACV,aAAa,WAAW,OAAO;EAC/B,YAAY,UAAU,KAAA;CACxB,GACA,CAAC,CACH;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"FieldContext.cjs","names":["React"],"sources":["../../../components/Field/FieldContext.ts"],"sourcesContent":["import React from 'react';\n\nimport { warnOnce } from '../../utils/warnOnce';\n\ntype MessageSize = '0' | '1' | '2' | '3';\n\ntype FieldControlState = { id?: string; disabled: boolean; invalid: boolean; labelable: boolean };\n\nexport type FieldContextValue = {\n controlId?: string;\n labelId?: string;\n descriptionId?: string;\n errorId?: string;\n hintId?: string;\n messageSize: MessageSize;\n invalid: boolean;\n disabled: boolean;\n registerControl: (key: string, state: FieldControlState | null) => void;\n};\n\nexport const FieldContext = React.createContext<FieldContextValue | null>(null);\n\nexport const useFieldContext = () => React.useContext(FieldContext);\n\nexport type FieldControlOptions = {\n id?: string;\n invalid?: boolean;\n disabled?: boolean;\n 'aria-describedby'?: string;\n 'aria-invalid'?: React.AriaAttributes['aria-invalid'];\n /** Set to false when the control is not a labelable element, such as a radio group. */\n labelable?: boolean;\n};\n\nexport type FieldLabelVariant = 'invalid' | 'subtle' | 'contrast' | 'default';\n\nexport type FieldLabelProps = {\n variant: FieldLabelVariant;\n htmlFor?: string;\n id: string;\n};\n\nexport type FieldBaseProps = {\n id?: string;\n label?: React.ReactNode | ((props: FieldLabelProps) => React.ReactNode);\n /** Text under the label, for what the field is for. */\n hint?: React.ReactNode;\n description?: React.ReactNode;\n error?: React.ReactNode;\n invalid?: boolean;\n disabled?: boolean;\n announceError?: boolean;\n /** `start` puts the label and the hint in a column before the control, and wraps under it when space is short. */\n labelPosition?: 'top' | 'start' | 'end';\n /** The text size of the hint, the description and the error. A Field inside another Field takes its size. */\n messageSize?: MessageSize;\n /**\n * For a field of more than one control: the field becomes a group named by the label and described by\n * the hint, the description and the error. Give each control its own name, and its own error with an inner Field.\n */\n group?: boolean;\n children?: React.ReactNode;\n};\n\nconst hasContent = (node: React.ReactNode) =>\n node !== undefined && node !== null && node !== false && node !== '';\n\nconst noop = () => {};\n\nconst MULTIPLE_CONTROLS_WARNING =\n 'Field: more than one control is in this Field, and its label points to one of them only. Use group, or one Field per control.';\n\nexport const useFieldRoot = ({\n id,\n label,\n hint,\n description,\n error,\n invalid,\n disabled,\n messageSize,\n group = false,\n}: FieldBaseProps) => {\n const outerContext = useFieldContext();\n const generatedId = React.useId();\n const hasLabel = typeof label === 'function' || hasContent(label);\n const hasHint = hasContent(hint);\n const resolvedMessageSize = messageSize ?? outerContext?.messageSize ?? '0';\n const hasDescription = hasContent(description);\n const hasError = hasContent(error);\n const isInvalid = Boolean(invalid) || hasError;\n const isDisabled = Boolean(disabled) || Boolean(outerContext?.disabled);\n\n const [control, setControl] = React.useState<FieldControlState | null>(null);\n const controlsRef = React.useRef(new Map<string, FieldControlState>());\n const registerControl = React.useCallback((key: string, state: FieldControlState | null) => {\n const controls = controlsRef.current;\n if (state) {\n controls.set(key, state);\n } else {\n controls.delete(key);\n }\n if (controls.size > 1) {\n warnOnce(MULTIPLE_CONTROLS_WARNING);\n }\n const next = controls.values().next().value ?? null;\n setControl((prev) =>\n prev?.id === next?.id &&\n prev?.disabled === next?.disabled &&\n prev?.invalid === next?.invalid &&\n prev?.labelable === next?.labelable\n ? prev\n : next,\n );\n }, []);\n const controlId = control?.id ?? id ?? (hasLabel ? `${generatedId}-control` : undefined);\n // The label points to a control only once one is there, so it never points to a missing id.\n const labelFor = group\n ? undefined\n : control\n ? control.labelable === false\n ? undefined\n : controlId\n : id;\n\n const [hasFocus, setHasFocus] = React.useState(false);\n const onFocus = React.useCallback(() => setHasFocus(true), []);\n const onBlur = React.useCallback(() => setHasFocus(false), []);\n\n const labelVariant: FieldLabelVariant = React.useMemo(() => {\n if (isDisabled || control?.disabled) {\n return 'subtle';\n }\n if (isInvalid || control?.invalid) {\n return 'invalid';\n }\n if (hasFocus) {\n return 'contrast';\n }\n return 'default';\n }, [isDisabled, isInvalid, hasFocus, control?.disabled, control?.invalid]);\n\n const ownContext: FieldContextValue = React.useMemo(\n () => ({\n controlId,\n labelId: hasLabel ? `${generatedId}-label` : undefined,\n descriptionId: hasDescription ? `${generatedId}-description` : undefined,\n errorId: hasError ? `${generatedId}-error` : undefined,\n hintId: hasHint ? `${generatedId}-hint` : undefined,\n messageSize: resolvedMessageSize,\n invalid: isInvalid,\n disabled: isDisabled,\n registerControl,\n }),\n [\n controlId,\n generatedId,\n hasLabel,\n hasDescription,\n hasError,\n hasHint,\n resolvedMessageSize,\n isInvalid,\n isDisabled,\n registerControl,\n ],\n );\n\n // The controls of a group get only its disabled state: the group itself carries the name and the messages.\n const groupContext: FieldContextValue = React.useMemo(\n () => ({\n messageSize: resolvedMessageSize,\n invalid: false,\n disabled: isDisabled,\n registerControl: noop,\n }),\n [resolvedMessageSize, isDisabled],\n );\n\n const groupProps = group\n ? {\n role: 'group',\n 'aria-labelledby': ownContext.labelId,\n 'aria-describedby':\n [ownContext.errorId, ownContext.descriptionId, ownContext.hintId]\n .filter(Boolean)\n .join(' ') || undefined,\n }\n : {};\n\n // A Field with no label, hint, description or error inside another Field keeps the outer one.\n const context = group\n ? groupContext\n : outerContext && !hasLabel && !hasHint && !hasDescription && !hasError\n ? outerContext\n : ownContext;\n\n return {\n context,\n ids: ownContext,\n groupProps,\n messageSize: resolvedMessageSize,\n labelFor,\n labelVariant,\n hasLabel,\n hasHint,\n hasDescription,\n hasError,\n onFocus,\n onBlur,\n };\n};\n\n/**\n * Gives a form control the id, `aria-describedby`, `aria-invalid` and `disabled` of the `Field` around it,\n * and gives its own id, `disabled` and invalid state to that `Field`.\n * Outside a `Field`, it only sets `aria-invalid` from `invalid`.\n */\nexport const useFieldControl = ({\n id,\n invalid,\n disabled,\n 'aria-describedby': describedBy,\n 'aria-invalid': ariaInvalid,\n labelable = true,\n}: FieldControlOptions) => {\n const field = useFieldContext();\n const registrationId = React.useId();\n const ownInvalid = Boolean(invalid || ariaInvalid === true || ariaInvalid === 'true');\n const isInvalid = ownInvalid || Boolean(field?.invalid);\n const registerControl = field?.registerControl;\n\n React.useEffect(() => {\n if (!registerControl) {\n return undefined;\n }\n registerControl(registrationId, {\n id,\n disabled: Boolean(disabled),\n invalid: ownInvalid,\n labelable,\n });\n return () => registerControl(registrationId, null);\n }, [registerControl, registrationId, id, disabled, ownInvalid, labelable]);\n const describedByIds =\n [field?.errorId, field?.descriptionId, field?.hintId, describedBy].filter(Boolean).join(' ') ||\n undefined;\n\n return {\n id: id ?? field?.controlId,\n labelId: field?.labelId,\n invalid: isInvalid,\n disabled: disabled || field?.disabled || undefined,\n 'aria-describedby': describedByIds,\n 'aria-invalid': isInvalid ? true : ariaInvalid,\n };\n};\n\nconst ANNOUNCE_DELAY = 1000;\n\n/**\n * Returns the text of the error, after the text of the label when there is one, once it has not\n * changed for a short time, so that a screen reader reads it after the echo of the typed text.\n */\nexport const useAnnouncedError = (enabled: boolean, errorId?: string, labelId?: string) => {\n const [announcedError, setAnnouncedError] = React.useState<string | null>(null);\n const lastTextRef = React.useRef<string | null | undefined>(undefined);\n const timeoutRef = React.useRef<ReturnType<typeof setTimeout>>();\n\n // Compares the rendered text, so that a new JSX error with the same text does not restart the delay.\n React.useEffect(() => {\n const text =\n (enabled && errorId && document.getElementById(errorId)?.textContent?.trim()) || null;\n if (text === lastTextRef.current) {\n return;\n }\n lastTextRef.current = text;\n clearTimeout(timeoutRef.current);\n timeoutRef.current = setTimeout(\n () => {\n const fieldName = labelId\n ? document.getElementById(labelId)?.textContent?.trim()\n : undefined;\n setAnnouncedError(text !== null && fieldName ? `${fieldName}: ${text}` : text);\n },\n text === null ? 0 : ANNOUNCE_DELAY,\n );\n });\n\n React.useEffect(\n () => () => {\n clearTimeout(timeoutRef.current);\n lastTextRef.current = undefined;\n },\n [],\n );\n\n return announcedError;\n};\n"],"mappings":";;;;;AAoBA,IAAa,eAAeA,MAAAA,QAAM,cAAwC,IAAI;AAE9E,IAAa,wBAAwBA,MAAAA,QAAM,WAAW,YAAY;AA0ClE,IAAM,cAAc,SAClB,SAAS,KAAA,KAAa,SAAS,QAAQ,SAAS,SAAS,SAAS;AAEpE,IAAM,aAAa,CAAC;AAEpB,IAAM,4BACJ;AAEF,IAAa,gBAAgB,EAC3B,IACA,OACA,MACA,aACA,OACA,SACA,UACA,aACA,QAAQ,YACY;CACpB,MAAM,eAAe,gBAAgB;CACrC,MAAM,cAAcA,MAAAA,QAAM,MAAM;CAChC,MAAM,WAAW,OAAO,UAAU,cAAc,WAAW,KAAK;CAChE,MAAM,UAAU,WAAW,IAAI;CAC/B,MAAM,sBAAsB,eAAe,cAAc,eAAe;CACxE,MAAM,iBAAiB,WAAW,WAAW;CAC7C,MAAM,WAAW,WAAW,KAAK;CACjC,MAAM,YAAY,QAAQ,OAAO,KAAK;CACtC,MAAM,aAAa,QAAQ,QAAQ,KAAK,QAAQ,cAAc,QAAQ;CAEtE,MAAM,CAAC,SAAS,cAAcA,MAAAA,QAAM,SAAmC,IAAI;CAC3E,MAAM,cAAcA,MAAAA,QAAM,uBAAO,IAAI,IAA+B,CAAC;CACrE,MAAM,kBAAkBA,MAAAA,QAAM,aAAa,KAAa,UAAoC;EAC1F,MAAM,W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AAoB;EACpB,gBAAgB,YAAY,OAAO;CACrC;AACF;AAEA,IAAM,iBAAiB;;;;;AAMvB,IAAa,qBAAqB,SAAkB,SAAkB,YAAqB;CACzF,MAAM,CAAC,gBAAgB,qBAAqBA,MAAAA,QAAM,SAAwB,IAAI;CAC9E,MAAM,cAAcA,MAAAA,QAAM,OAAkC,KAAA,CAAS;CACrE,MAAM,aAAaA,MAAAA,QAAM,OAAsC;CAG/D,MAAA,QAAM,gBAAgB;EACpB,MAAM,OACH,WAAW,WAAW,SAAS,eAAe,OAAO,CAAC,EAAE,aAAa,KAAK,KAAM;EACnF,IAAI,SAAS,YAAY,SACvB;EAEF,YAAY,UAAU;EACtB,aAAa,WAAW,OAAO;EAC/B,WAAW,UAAU,iBACb;GACJ,MAAM,YAAY,UACd,SAAS,eAAe,OAAO,CAAC,EAAE,aAAa,KAAK,IACpD,KAAA;GACJ,kBAAkB,SAAS,QAAQ,YAAY,GAAG,UAAU,IAAI,SAAS,IAAI;EAC/E,GACA,SAAS,OAAO,IAAI,cACtB;CACF,CAAC;CAED,MAAA,QAAM,sBACQ;EACV,aAAa,WAAW,OAAO;EAC/B,YAAY,UAAU,KAAA;CACxB,GACA,CAAC,CACH;CAEA,OAAO;AACT"}
|
|
@@ -1,31 +1,43 @@
|
|
|
1
|
+
import { warnOnce } from "../../utils/warnOnce.js";
|
|
1
2
|
import React from "react";
|
|
2
3
|
// components/Field/FieldContext.ts
|
|
3
4
|
var FieldContext = React.createContext(null);
|
|
4
5
|
var useFieldContext = () => React.useContext(FieldContext);
|
|
5
6
|
var hasContent = (node) => node !== void 0 && node !== null && node !== false && node !== "";
|
|
6
|
-
var
|
|
7
|
+
var noop = () => {};
|
|
8
|
+
var MULTIPLE_CONTROLS_WARNING = "Field: more than one control is in this Field, and its label points to one of them only. Use group, or one Field per control.";
|
|
9
|
+
var useFieldRoot = ({ id, label, hint, description, error, invalid, disabled, messageSize, group = false }) => {
|
|
7
10
|
const outerContext = useFieldContext();
|
|
8
11
|
const generatedId = React.useId();
|
|
9
12
|
const hasLabel = typeof label === "function" || hasContent(label);
|
|
13
|
+
const hasHint = hasContent(hint);
|
|
14
|
+
const resolvedMessageSize = messageSize ?? outerContext?.messageSize ?? "0";
|
|
10
15
|
const hasDescription = hasContent(description);
|
|
11
16
|
const hasError = hasContent(error);
|
|
12
17
|
const isInvalid = Boolean(invalid) || hasError;
|
|
18
|
+
const isDisabled = Boolean(disabled) || Boolean(outerContext?.disabled);
|
|
13
19
|
const [control, setControl] = React.useState(null);
|
|
14
|
-
const
|
|
20
|
+
const controlsRef = React.useRef(/* @__PURE__ */ new Map());
|
|
21
|
+
const registerControl = React.useCallback((key, state) => {
|
|
22
|
+
const controls = controlsRef.current;
|
|
23
|
+
if (state) controls.set(key, state);
|
|
24
|
+
else controls.delete(key);
|
|
25
|
+
if (controls.size > 1) warnOnce(MULTIPLE_CONTROLS_WARNING);
|
|
26
|
+
const next = controls.values().next().value ?? null;
|
|
15
27
|
setControl((prev) => prev?.id === next?.id && prev?.disabled === next?.disabled && prev?.invalid === next?.invalid && prev?.labelable === next?.labelable ? prev : next);
|
|
16
28
|
}, []);
|
|
17
29
|
const controlId = control?.id ?? id ?? (hasLabel ? `${generatedId}-control` : void 0);
|
|
18
|
-
const labelFor = control
|
|
30
|
+
const labelFor = group ? void 0 : control ? control.labelable === false ? void 0 : controlId : id;
|
|
19
31
|
const [hasFocus, setHasFocus] = React.useState(false);
|
|
20
32
|
const onFocus = React.useCallback(() => setHasFocus(true), []);
|
|
21
33
|
const onBlur = React.useCallback(() => setHasFocus(false), []);
|
|
22
34
|
const labelVariant = React.useMemo(() => {
|
|
23
|
-
if (
|
|
35
|
+
if (isDisabled || control?.disabled) return "subtle";
|
|
24
36
|
if (isInvalid || control?.invalid) return "invalid";
|
|
25
37
|
if (hasFocus) return "contrast";
|
|
26
38
|
return "default";
|
|
27
39
|
}, [
|
|
28
|
-
|
|
40
|
+
isDisabled,
|
|
29
41
|
isInvalid,
|
|
30
42
|
hasFocus,
|
|
31
43
|
control?.disabled,
|
|
@@ -36,8 +48,10 @@ var useFieldRoot = ({ id, label, description, error, invalid, disabled }) => {
|
|
|
36
48
|
labelId: hasLabel ? `${generatedId}-label` : void 0,
|
|
37
49
|
descriptionId: hasDescription ? `${generatedId}-description` : void 0,
|
|
38
50
|
errorId: hasError ? `${generatedId}-error` : void 0,
|
|
51
|
+
hintId: hasHint ? `${generatedId}-hint` : void 0,
|
|
52
|
+
messageSize: resolvedMessageSize,
|
|
39
53
|
invalid: isInvalid,
|
|
40
|
-
disabled:
|
|
54
|
+
disabled: isDisabled,
|
|
41
55
|
registerControl
|
|
42
56
|
}), [
|
|
43
57
|
controlId,
|
|
@@ -45,15 +59,36 @@ var useFieldRoot = ({ id, label, description, error, invalid, disabled }) => {
|
|
|
45
59
|
hasLabel,
|
|
46
60
|
hasDescription,
|
|
47
61
|
hasError,
|
|
62
|
+
hasHint,
|
|
63
|
+
resolvedMessageSize,
|
|
48
64
|
isInvalid,
|
|
49
|
-
|
|
65
|
+
isDisabled,
|
|
50
66
|
registerControl
|
|
51
67
|
]);
|
|
68
|
+
const groupContext = React.useMemo(() => ({
|
|
69
|
+
messageSize: resolvedMessageSize,
|
|
70
|
+
invalid: false,
|
|
71
|
+
disabled: isDisabled,
|
|
72
|
+
registerControl: noop
|
|
73
|
+
}), [resolvedMessageSize, isDisabled]);
|
|
74
|
+
const groupProps = group ? {
|
|
75
|
+
role: "group",
|
|
76
|
+
"aria-labelledby": ownContext.labelId,
|
|
77
|
+
"aria-describedby": [
|
|
78
|
+
ownContext.errorId,
|
|
79
|
+
ownContext.descriptionId,
|
|
80
|
+
ownContext.hintId
|
|
81
|
+
].filter(Boolean).join(" ") || void 0
|
|
82
|
+
} : {};
|
|
52
83
|
return {
|
|
53
|
-
context: outerContext && !hasLabel && !hasDescription && !hasError ? outerContext : ownContext,
|
|
84
|
+
context: group ? groupContext : outerContext && !hasLabel && !hasHint && !hasDescription && !hasError ? outerContext : ownContext,
|
|
85
|
+
ids: ownContext,
|
|
86
|
+
groupProps,
|
|
87
|
+
messageSize: resolvedMessageSize,
|
|
54
88
|
labelFor,
|
|
55
89
|
labelVariant,
|
|
56
90
|
hasLabel,
|
|
91
|
+
hasHint,
|
|
57
92
|
hasDescription,
|
|
58
93
|
hasError,
|
|
59
94
|
onFocus,
|
|
@@ -67,20 +102,22 @@ var useFieldRoot = ({ id, label, description, error, invalid, disabled }) => {
|
|
|
67
102
|
*/
|
|
68
103
|
var useFieldControl = ({ id, invalid, disabled, "aria-describedby": describedBy, "aria-invalid": ariaInvalid, labelable = true }) => {
|
|
69
104
|
const field = useFieldContext();
|
|
105
|
+
const registrationId = React.useId();
|
|
70
106
|
const ownInvalid = Boolean(invalid || ariaInvalid === true || ariaInvalid === "true");
|
|
71
107
|
const isInvalid = ownInvalid || Boolean(field?.invalid);
|
|
72
108
|
const registerControl = field?.registerControl;
|
|
73
109
|
React.useEffect(() => {
|
|
74
110
|
if (!registerControl) return;
|
|
75
|
-
registerControl({
|
|
111
|
+
registerControl(registrationId, {
|
|
76
112
|
id,
|
|
77
113
|
disabled: Boolean(disabled),
|
|
78
114
|
invalid: ownInvalid,
|
|
79
115
|
labelable
|
|
80
116
|
});
|
|
81
|
-
return () => registerControl(null);
|
|
117
|
+
return () => registerControl(registrationId, null);
|
|
82
118
|
}, [
|
|
83
119
|
registerControl,
|
|
120
|
+
registrationId,
|
|
84
121
|
id,
|
|
85
122
|
disabled,
|
|
86
123
|
ownInvalid,
|
|
@@ -89,6 +126,7 @@ var useFieldControl = ({ id, invalid, disabled, "aria-describedby": describedBy,
|
|
|
89
126
|
const describedByIds = [
|
|
90
127
|
field?.errorId,
|
|
91
128
|
field?.descriptionId,
|
|
129
|
+
field?.hintId,
|
|
92
130
|
describedBy
|
|
93
131
|
].filter(Boolean).join(" ") || void 0;
|
|
94
132
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldContext.js","names":[],"sources":["../../../components/Field/FieldContext.ts"],"sourcesContent":["import React from 'react';\n\ntype FieldControlState = { id?: string; disabled: boolean; invalid: boolean; labelable: boolean };\n\nexport type FieldContextValue = {\n controlId?: string;\n labelId?: string;\n descriptionId?: string;\n errorId?: string;\n invalid: boolean;\n disabled: boolean;\n registerControl: (state: FieldControlState | null) => void;\n};\n\nexport const FieldContext = React.createContext<FieldContextValue | null>(null);\n\nexport const useFieldContext = () => React.useContext(FieldContext);\n\nexport type FieldControlOptions = {\n id?: string;\n invalid?: boolean;\n disabled?: boolean;\n 'aria-describedby'?: string;\n 'aria-invalid'?: React.AriaAttributes['aria-invalid'];\n /** Set to false when the control is not a labelable element, such as a radio group. */\n labelable?: boolean;\n};\n\nexport type FieldLabelVariant = 'invalid' | 'subtle' | 'contrast' | 'default';\n\nexport type FieldLabelProps = {\n variant: FieldLabelVariant;\n htmlFor?: string;\n id: string;\n};\n\nexport type FieldBaseProps = {\n id?: string;\n label?: React.ReactNode | ((props: FieldLabelProps) => React.ReactNode);\n description?: React.ReactNode;\n error?: React.ReactNode;\n invalid?: boolean;\n disabled?: boolean;\n announceError?: boolean;\n labelPosition?: 'top' | 'end';\n children?: React.ReactNode;\n};\n\nconst hasContent = (node: React.ReactNode) =>\n node !== undefined && node !== null && node !== false && node !== '';\n\nexport const useFieldRoot = ({\n id,\n label,\n description,\n error,\n invalid,\n disabled,\n}: FieldBaseProps) => {\n const outerContext = useFieldContext();\n const generatedId = React.useId();\n const hasLabel = typeof label === 'function' || hasContent(label);\n const hasDescription = hasContent(description);\n const hasError = hasContent(error);\n const isInvalid = Boolean(invalid) || hasError;\n\n const [control, setControl] = React.useState<FieldControlState | null>(null);\n const registerControl = React.useCallback((next: FieldControlState | null) => {\n setControl((prev) =>\n prev?.id === next?.id &&\n prev?.disabled === next?.disabled &&\n prev?.invalid === next?.invalid &&\n prev?.labelable === next?.labelable\n ? prev\n : next,\n );\n }, []);\n const controlId = control?.id ?? id ?? (hasLabel ? `${generatedId}-control` : undefined);\n const labelFor = control?.labelable === false ? undefined : controlId;\n\n const [hasFocus, setHasFocus] = React.useState(false);\n const onFocus = React.useCallback(() => setHasFocus(true), []);\n const onBlur = React.useCallback(() => setHasFocus(false), []);\n\n const labelVariant: FieldLabelVariant = React.useMemo(() => {\n if (disabled || control?.disabled) {\n return 'subtle';\n }\n if (isInvalid || control?.invalid) {\n return 'invalid';\n }\n if (hasFocus) {\n return 'contrast';\n }\n return 'default';\n }, [disabled, isInvalid, hasFocus, control?.disabled, control?.invalid]);\n\n const ownContext: FieldContextValue = React.useMemo(\n () => ({\n controlId,\n labelId: hasLabel ? `${generatedId}-label` : undefined,\n descriptionId: hasDescription ? `${generatedId}-description` : undefined,\n errorId: hasError ? `${generatedId}-error` : undefined,\n invalid: isInvalid,\n disabled: Boolean(disabled),\n registerControl,\n }),\n [\n controlId,\n generatedId,\n hasLabel,\n hasDescription,\n hasError,\n isInvalid,\n disabled,\n registerControl,\n ],\n );\n\n // A Field with no label, description or error inside another Field keeps the outer one.\n const context =\n outerContext && !hasLabel && !hasDescription && !hasError ? outerContext : ownContext;\n\n return { context, labelFor, labelVariant, hasLabel, hasDescription, hasError, onFocus, onBlur };\n};\n\n/**\n * Gives a form control the id, `aria-describedby`, `aria-invalid` and `disabled` of the `Field` around it,\n * and gives its own id, `disabled` and invalid state to that `Field`.\n * Outside a `Field`, it only sets `aria-invalid` from `invalid`.\n */\nexport const useFieldControl = ({\n id,\n invalid,\n disabled,\n 'aria-describedby': describedBy,\n 'aria-invalid': ariaInvalid,\n labelable = true,\n}: FieldControlOptions) => {\n const field = useFieldContext();\n const ownInvalid = Boolean(invalid || ariaInvalid === true || ariaInvalid === 'true');\n const isInvalid = ownInvalid || Boolean(field?.invalid);\n const registerControl = field?.registerControl;\n\n React.useEffect(() => {\n if (!registerControl) {\n return undefined;\n }\n registerControl({ id, disabled: Boolean(disabled), invalid: ownInvalid, labelable });\n return () => registerControl(null);\n }, [registerControl, id, disabled, ownInvalid, labelable]);\n const describedByIds =\n [field?.errorId, field?.descriptionId, describedBy].filter(Boolean).join(' ') || undefined;\n\n return {\n id: id ?? field?.controlId,\n labelId: field?.labelId,\n invalid: isInvalid,\n disabled: disabled || field?.disabled || undefined,\n 'aria-describedby': describedByIds,\n 'aria-invalid': isInvalid ? true : ariaInvalid,\n };\n};\n\nconst ANNOUNCE_DELAY = 1000;\n\n/**\n * Returns the text of the error, after the text of the label when there is one, once it has not\n * changed for a short time, so that a screen reader reads it after the echo of the typed text.\n */\nexport const useAnnouncedError = (enabled: boolean, errorId?: string, labelId?: string) => {\n const [announcedError, setAnnouncedError] = React.useState<string | null>(null);\n const lastTextRef = React.useRef<string | null | undefined>(undefined);\n const timeoutRef = React.useRef<ReturnType<typeof setTimeout>>();\n\n // Compares the rendered text, so that a new JSX error with the same text does not restart the delay.\n React.useEffect(() => {\n const text =\n (enabled && errorId && document.getElementById(errorId)?.textContent?.trim()) || null;\n if (text === lastTextRef.current) {\n return;\n }\n lastTextRef.current = text;\n clearTimeout(timeoutRef.current);\n timeoutRef.current = setTimeout(\n () => {\n const fieldName = labelId\n ? document.getElementById(labelId)?.textContent?.trim()\n : undefined;\n setAnnouncedError(text !== null && fieldName ? `${fieldName}: ${text}` : text);\n },\n text === null ? 0 : ANNOUNCE_DELAY,\n );\n });\n\n React.useEffect(\n () => () => {\n clearTimeout(timeoutRef.current);\n lastTextRef.current = undefined;\n },\n [],\n );\n\n return announcedError;\n};\n"],"mappings":";;AAcA,IAAa,eAAe,MAAM,cAAwC,IAAI;AAE9E,IAAa,wBAAwB,MAAM,WAAW,YAAY;AAgClE,IAAM,cAAc,SAClB,SAAS,KAAA,KAAa,SAAS,QAAQ,SAAS,SAAS,SAAS;AAEpE,IAAa,gBAAgB,EAC3B,IACA,OACA,aACA,OACA,SACA,eACoB;CACpB,MAAM,eAAe,gBAAgB;CACrC,MAAM,cAAc,MAAM,MAAM;CAChC,MAAM,WAAW,OAAO,UAAU,cAAc,WAAW,KAAK;CAChE,MAAM,iBAAiB,WAAW,WAA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;EAC/E,GACA,SAAS,OAAO,IAAI,cACtB;CACF,CAAC;CAED,MAAM,sBACQ;EACV,aAAa,WAAW,OAAO;EAC/B,YAAY,UAAU,KAAA;CACxB,GACA,CAAC,CACH;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"FieldContext.js","names":[],"sources":["../../../components/Field/FieldContext.ts"],"sourcesContent":["import React from 'react';\n\nimport { warnOnce } from '../../utils/warnOnce';\n\ntype MessageSize = '0' | '1' | '2' | '3';\n\ntype FieldControlState = { id?: string; disabled: boolean; invalid: boolean; labelable: boolean };\n\nexport type FieldContextValue = {\n controlId?: string;\n labelId?: string;\n descriptionId?: string;\n errorId?: string;\n hintId?: string;\n messageSize: MessageSize;\n invalid: boolean;\n disabled: boolean;\n registerControl: (key: string, state: FieldControlState | null) => void;\n};\n\nexport const FieldContext = React.createContext<FieldContextValue | null>(null);\n\nexport const useFieldContext = () => React.useContext(FieldContext);\n\nexport type FieldControlOptions = {\n id?: string;\n invalid?: boolean;\n disabled?: boolean;\n 'aria-describedby'?: string;\n 'aria-invalid'?: React.AriaAttributes['aria-invalid'];\n /** Set to false when the control is not a labelable element, such as a radio group. */\n labelable?: boolean;\n};\n\nexport type FieldLabelVariant = 'invalid' | 'subtle' | 'contrast' | 'default';\n\nexport type FieldLabelProps = {\n variant: FieldLabelVariant;\n htmlFor?: string;\n id: string;\n};\n\nexport type FieldBaseProps = {\n id?: string;\n label?: React.ReactNode | ((props: FieldLabelProps) => React.ReactNode);\n /** Text under the label, for what the field is for. */\n hint?: React.ReactNode;\n description?: React.ReactNode;\n error?: React.ReactNode;\n invalid?: boolean;\n disabled?: boolean;\n announceError?: boolean;\n /** `start` puts the label and the hint in a column before the control, and wraps under it when space is short. */\n labelPosition?: 'top' | 'start' | 'end';\n /** The text size of the hint, the description and the error. A Field inside another Field takes its size. */\n messageSize?: MessageSize;\n /**\n * For a field of more than one control: the field becomes a group named by the label and described by\n * the hint, the description and the error. Give each control its own name, and its own error with an inner Field.\n */\n group?: boolean;\n children?: React.ReactNode;\n};\n\nconst hasContent = (node: React.ReactNode) =>\n node !== undefined && node !== null && node !== false && node !== '';\n\nconst noop = () => {};\n\nconst MULTIPLE_CONTROLS_WARNING =\n 'Field: more than one control is in this Field, and its label points to one of them only. Use group, or one Field per control.';\n\nexport const useFieldRoot = ({\n id,\n label,\n hint,\n description,\n error,\n invalid,\n disabled,\n messageSize,\n group = false,\n}: FieldBaseProps) => {\n const outerContext = useFieldContext();\n const generatedId = React.useId();\n const hasLabel = typeof label === 'function' || hasContent(label);\n const hasHint = hasContent(hint);\n const resolvedMessageSize = messageSize ?? outerContext?.messageSize ?? '0';\n const hasDescription = hasContent(description);\n const hasError = hasContent(error);\n const isInvalid = Boolean(invalid) || hasError;\n const isDisabled = Boolean(disabled) || Boolean(outerContext?.disabled);\n\n const [control, setControl] = React.useState<FieldControlState | null>(null);\n const controlsRef = React.useRef(new Map<string, FieldControlState>());\n const registerControl = React.useCallback((key: string, state: FieldControlState | null) => {\n const controls = controlsRef.current;\n if (state) {\n controls.set(key, state);\n } else {\n controls.delete(key);\n }\n if (controls.size > 1) {\n warnOnce(MULTIPLE_CONTROLS_WARNING);\n }\n const next = controls.values().next().value ?? null;\n setControl((prev) =>\n prev?.id === next?.id &&\n prev?.disabled === next?.disabled &&\n prev?.invalid === next?.invalid &&\n prev?.labelable === next?.labelable\n ? prev\n : next,\n );\n }, []);\n const controlId = control?.id ?? id ?? (hasLabel ? `${generatedId}-control` : undefined);\n // The label points to a control only once one is there, so it never points to a missing id.\n const labelFor = group\n ? undefined\n : control\n ? control.labelable === false\n ? undefined\n : controlId\n : id;\n\n const [hasFocus, setHasFocus] = React.useState(false);\n const onFocus = React.useCallback(() => setHasFocus(true), []);\n const onBlur = React.useCallback(() => setHasFocus(false), []);\n\n const labelVariant: FieldLabelVariant = React.useMemo(() => {\n if (isDisabled || control?.disabled) {\n return 'subtle';\n }\n if (isInvalid || control?.invalid) {\n return 'invalid';\n }\n if (hasFocus) {\n return 'contrast';\n }\n return 'default';\n }, [isDisabled, isInvalid, hasFocus, control?.disabled, control?.invalid]);\n\n const ownContext: FieldContextValue = React.useMemo(\n () => ({\n controlId,\n labelId: hasLabel ? `${generatedId}-label` : undefined,\n descriptionId: hasDescription ? `${generatedId}-description` : undefined,\n errorId: hasError ? `${generatedId}-error` : undefined,\n hintId: hasHint ? `${generatedId}-hint` : undefined,\n messageSize: resolvedMessageSize,\n invalid: isInvalid,\n disabled: isDisabled,\n registerControl,\n }),\n [\n controlId,\n generatedId,\n hasLabel,\n hasDescription,\n hasError,\n hasHint,\n resolvedMessageSize,\n isInvalid,\n isDisabled,\n registerControl,\n ],\n );\n\n // The controls of a group get only its disabled state: the group itself carries the name and the messages.\n const groupContext: FieldContextValue = React.useMemo(\n () => ({\n messageSize: resolvedMessageSize,\n invalid: false,\n disabled: isDisabled,\n registerControl: noop,\n }),\n [resolvedMessageSize, isDisabled],\n );\n\n const groupProps = group\n ? {\n role: 'group',\n 'aria-labelledby': ownContext.labelId,\n 'aria-describedby':\n [ownContext.errorId, ownContext.descriptionId, ownContext.hintId]\n .filter(Boolean)\n .join(' ') || undefined,\n }\n : {};\n\n // A Field with no label, hint, description or error inside another Field keeps the outer one.\n const context = group\n ? groupContext\n : outerContext && !hasLabel && !hasHint && !hasDescription && !hasError\n ? outerContext\n : ownContext;\n\n return {\n context,\n ids: ownContext,\n groupProps,\n messageSize: resolvedMessageSize,\n labelFor,\n labelVariant,\n hasLabel,\n hasHint,\n hasDescription,\n hasError,\n onFocus,\n onBlur,\n };\n};\n\n/**\n * Gives a form control the id, `aria-describedby`, `aria-invalid` and `disabled` of the `Field` around it,\n * and gives its own id, `disabled` and invalid state to that `Field`.\n * Outside a `Field`, it only sets `aria-invalid` from `invalid`.\n */\nexport const useFieldControl = ({\n id,\n invalid,\n disabled,\n 'aria-describedby': describedBy,\n 'aria-invalid': ariaInvalid,\n labelable = true,\n}: FieldControlOptions) => {\n const field = useFieldContext();\n const registrationId = React.useId();\n const ownInvalid = Boolean(invalid || ariaInvalid === true || ariaInvalid === 'true');\n const isInvalid = ownInvalid || Boolean(field?.invalid);\n const registerControl = field?.registerControl;\n\n React.useEffect(() => {\n if (!registerControl) {\n return undefined;\n }\n registerControl(registrationId, {\n id,\n disabled: Boolean(disabled),\n invalid: ownInvalid,\n labelable,\n });\n return () => registerControl(registrationId, null);\n }, [registerControl, registrationId, id, disabled, ownInvalid, labelable]);\n const describedByIds =\n [field?.errorId, field?.descriptionId, field?.hintId, describedBy].filter(Boolean).join(' ') ||\n undefined;\n\n return {\n id: id ?? field?.controlId,\n labelId: field?.labelId,\n invalid: isInvalid,\n disabled: disabled || field?.disabled || undefined,\n 'aria-describedby': describedByIds,\n 'aria-invalid': isInvalid ? true : ariaInvalid,\n };\n};\n\nconst ANNOUNCE_DELAY = 1000;\n\n/**\n * Returns the text of the error, after the text of the label when there is one, once it has not\n * changed for a short time, so that a screen reader reads it after the echo of the typed text.\n */\nexport const useAnnouncedError = (enabled: boolean, errorId?: string, labelId?: string) => {\n const [announcedError, setAnnouncedError] = React.useState<string | null>(null);\n const lastTextRef = React.useRef<string | null | undefined>(undefined);\n const timeoutRef = React.useRef<ReturnType<typeof setTimeout>>();\n\n // Compares the rendered text, so that a new JSX error with the same text does not restart the delay.\n React.useEffect(() => {\n const text =\n (enabled && errorId && document.getElementById(errorId)?.textContent?.trim()) || null;\n if (text === lastTextRef.current) {\n return;\n }\n lastTextRef.current = text;\n clearTimeout(timeoutRef.current);\n timeoutRef.current = setTimeout(\n () => {\n const fieldName = labelId\n ? document.getElementById(labelId)?.textContent?.trim()\n : undefined;\n setAnnouncedError(text !== null && fieldName ? `${fieldName}: ${text}` : text);\n },\n text === null ? 0 : ANNOUNCE_DELAY,\n );\n });\n\n React.useEffect(\n () => () => {\n clearTimeout(timeoutRef.current);\n lastTextRef.current = undefined;\n },\n [],\n );\n\n return announcedError;\n};\n"],"mappings":";;;AAoBA,IAAa,eAAe,MAAM,cAAwC,IAAI;AAE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S,IAAI;EAC/E,GACA,SAAS,OAAO,IAAI,cACtB;CACF,CAAC;CAED,MAAM,sBACQ;EACV,aAAa,WAAW,OAAO;EAC/B,YAAY,UAAU,KAAA;CACxB,GACA,CAAC,CACH;CAEA,OAAO;AACT"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_stitches_config = require("../../stitches.config.cjs");
|
|
3
|
+
const require_Button = require("../Button/Button.cjs");
|
|
3
4
|
const require_Elevation = require("../Elevation/Elevation.cjs");
|
|
4
5
|
const require_Flex = require("../Flex/Flex.cjs");
|
|
5
|
-
const require_Button = require("../Button/Button.cjs");
|
|
6
6
|
let react = require("react");
|
|
7
7
|
react = require_runtime.__toESM(react, 1);
|
|
8
8
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { styled } from "../../stitches.config.js";
|
|
2
|
+
import { BUTTON_BASE_STYLES } from "../Button/Button.js";
|
|
2
3
|
import { elevationVariants } from "../Elevation/Elevation.js";
|
|
3
4
|
import { Flex } from "../Flex/Flex.js";
|
|
4
|
-
import { BUTTON_BASE_STYLES } from "../Button/Button.js";
|
|
5
5
|
import React, { createContext, useContext, useMemo } from "react";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
// components/List/List.tsx
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_resolveColor = require("../../styles/resolveColor.cjs");
|
|
3
2
|
const require_cssProps = require("../../styles/cssProps.cjs");
|
|
3
|
+
const require_resolveColor = require("../../styles/resolveColor.cjs");
|
|
4
4
|
const require_themeContext = require("../../styles/themeContext.cjs");
|
|
5
5
|
const require_Meter_vanilla_css = require("./Meter.vanilla.css.cjs");
|
|
6
6
|
let react = require("react");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { resolveColor } from "../../styles/resolveColor.js";
|
|
2
1
|
import { processCSSProp } from "../../styles/cssProps.js";
|
|
2
|
+
import { resolveColor } from "../../styles/resolveColor.js";
|
|
3
3
|
import { useVanillaExtractTheme } from "../../styles/themeContext.js";
|
|
4
4
|
import { root, segment, trackRecipe } from "./Meter.vanilla.css.js";
|
|
5
5
|
import { forwardRef } from "react";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_Box = require("../Box/Box.cjs");
|
|
3
3
|
const require_Flex = require("../Flex/Flex.cjs");
|
|
4
|
-
const require_Text = require("../Text/Text.cjs");
|
|
5
4
|
const require_Navigation = require("../Navigation/Navigation.cjs");
|
|
6
|
-
const
|
|
5
|
+
const require_Text = require("../Text/Text.cjs");
|
|
7
6
|
const require_NavigationTreeContainer = require("./NavigationTreeContainer.cjs");
|
|
7
|
+
const require_NavigationTreeContext = require("./NavigationTreeContext.cjs");
|
|
8
8
|
let react = require("react");
|
|
9
9
|
react = require_runtime.__toESM(react, 1);
|
|
10
10
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Box } from "../Box/Box.js";
|
|
2
2
|
import { Flex } from "../Flex/Flex.js";
|
|
3
|
-
import { Text } from "../Text/Text.js";
|
|
4
3
|
import { NavigationItem } from "../Navigation/Navigation.js";
|
|
5
|
-
import {
|
|
4
|
+
import { Text } from "../Text/Text.js";
|
|
6
5
|
import { NavigationTreeContainer } from "./NavigationTreeContainer.js";
|
|
6
|
+
import { useNavigationTree } from "./NavigationTreeContext.js";
|
|
7
7
|
import React, { useMemo, useState } from "react";
|
|
8
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
// components/NavigationTree/NavigationTreeItem.tsx
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_stitches_config = require("../../stitches.config.cjs");
|
|
3
|
+
const require_warnOnce = require("../../utils/warnOnce.cjs");
|
|
3
4
|
let react = require("react");
|
|
4
5
|
react = require_runtime.__toESM(react, 1);
|
|
5
6
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -24,6 +25,13 @@ var rowLinkStyles = {
|
|
|
24
25
|
outlineStyle: "solid",
|
|
25
26
|
outlineColor: "$focusOutline",
|
|
26
27
|
outlineOffset: "-2px"
|
|
28
|
+
},
|
|
29
|
+
[`&[${ROW_LINK_ATTRIBUTE}="click"]::after`]: { content: "none" },
|
|
30
|
+
[`&[${ROW_LINK_ATTRIBUTE}="click"]:focus-visible`]: {
|
|
31
|
+
outlineWidth: "2px",
|
|
32
|
+
outlineStyle: "solid",
|
|
33
|
+
outlineColor: "$focusOutline",
|
|
34
|
+
outlineOffset: "2px"
|
|
27
35
|
}
|
|
28
36
|
};
|
|
29
37
|
var StyledRowLink = require_stitches_config.styled("a", rowLinkStyles);
|
|
@@ -42,10 +50,10 @@ var rowLinkRowStyles = {
|
|
|
42
50
|
* A link that covers its whole table row, so that a click on the row opens it.
|
|
43
51
|
* Other links and buttons in the row stay above it.
|
|
44
52
|
*/
|
|
45
|
-
var RowLink = react.default.forwardRef(({ asChild, ...props }, forwardedRef) => {
|
|
53
|
+
var RowLink = react.default.forwardRef(({ asChild, overlay = true, ...props }, forwardedRef) => {
|
|
46
54
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(asChild ? StyledRowLinkSlot : StyledRowLink, {
|
|
47
55
|
ref: forwardedRef,
|
|
48
|
-
[ROW_LINK_ATTRIBUTE]: "",
|
|
56
|
+
[ROW_LINK_ATTRIBUTE]: overlay ? "" : "click",
|
|
49
57
|
...props
|
|
50
58
|
});
|
|
51
59
|
});
|
|
@@ -57,16 +65,8 @@ var isCellType = (type, cellType) => {
|
|
|
57
65
|
const cellClassName = cellType.className;
|
|
58
66
|
return internal?.type === cellType || !!cellClassName && className === cellClassName;
|
|
59
67
|
};
|
|
60
|
-
var warnedMessages = /* @__PURE__ */ new Set();
|
|
61
|
-
var warnOnce = (message) => {
|
|
62
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV === "production") return;
|
|
63
|
-
if (!warnedMessages.has(message)) {
|
|
64
|
-
warnedMessages.add(message);
|
|
65
|
-
console.warn(message);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
68
|
/** Puts the content of the `cellType` cell at `linkCell` in a `RowLink` to `href`. */
|
|
69
|
-
var withRowLink = (children, { href, linkAs: LinkComponent = "a", linkCell = 0, linkProps }, cellType) => {
|
|
69
|
+
var withRowLink = (children, { href, linkAs: LinkComponent = "a", linkCell = 0, linkProps, linkOverlay }, cellType) => {
|
|
70
70
|
if (href === void 0) return children;
|
|
71
71
|
let cellIndex = -1;
|
|
72
72
|
let linked = false;
|
|
@@ -77,6 +77,7 @@ var withRowLink = (children, { href, linkAs: LinkComponent = "a", linkCell = 0,
|
|
|
77
77
|
linked = true;
|
|
78
78
|
return (0, react.cloneElement)(child, void 0, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RowLink, {
|
|
79
79
|
asChild: true,
|
|
80
|
+
overlay: linkOverlay,
|
|
80
81
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LinkComponent, {
|
|
81
82
|
...linkProps,
|
|
82
83
|
href,
|
|
@@ -84,10 +85,32 @@ var withRowLink = (children, { href, linkAs: LinkComponent = "a", linkCell = 0,
|
|
|
84
85
|
})
|
|
85
86
|
}));
|
|
86
87
|
});
|
|
87
|
-
if (!linked) warnOnce(`Tr: the child at linkCell ${linkCell} is not a Td, so the row has no link. Use a Td for that cell, or put a RowLink in it.`);
|
|
88
|
+
if (!linked) require_warnOnce.warnOnce(`Tr: the child at linkCell ${linkCell} is not a Td, so the row has no link. Use a Td for that cell, or put a RowLink in it.`);
|
|
88
89
|
return mapped;
|
|
89
90
|
};
|
|
91
|
+
var NEW_TAB_PROTOCOLS = ["http:", "https:"];
|
|
92
|
+
var ROW_CLICK_CONTROLS = "a, button, input, select, textarea, label, summary, [role=\"button\"], [role=\"link\"], [role=\"checkbox\"], [role=\"switch\"], [role=\"menuitem\"], [tabindex]:not([tabindex=\"-1\"]), [contenteditable=\"true\"]";
|
|
93
|
+
/** Opens the `RowLink` without overlay of the row on a click or a middle click outside its controls. */
|
|
94
|
+
var openRowLink = (event) => {
|
|
95
|
+
const isAuxClick = event.type === "auxclick";
|
|
96
|
+
if (event.defaultPrevented || isAuxClick && event.button !== 1) return;
|
|
97
|
+
const row = event.currentTarget;
|
|
98
|
+
const target = event.target;
|
|
99
|
+
if (!(target instanceof Element) || !row.contains(target)) return;
|
|
100
|
+
const control = target.closest(ROW_CLICK_CONTROLS);
|
|
101
|
+
if (control && row.contains(control)) return;
|
|
102
|
+
const link = row.querySelector(`[${ROW_LINK_ATTRIBUTE}="click"]`);
|
|
103
|
+
if (!link) return;
|
|
104
|
+
const selection = window.getSelection();
|
|
105
|
+
if (selection && !selection.isCollapsed && row.contains(selection.anchorNode)) return;
|
|
106
|
+
if ((isAuxClick || event.metaKey || event.ctrlKey || event.shiftKey) && NEW_TAB_PROTOCOLS.includes(new URL(link.href, window.location.href).protocol)) {
|
|
107
|
+
window.open(link.href, "_blank", "noopener,noreferrer");
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
link.click();
|
|
111
|
+
};
|
|
90
112
|
exports.RowLink = RowLink;
|
|
113
|
+
exports.openRowLink = openRowLink;
|
|
91
114
|
exports.rowLinkRowStyles = rowLinkRowStyles;
|
|
92
115
|
exports.rowLinkTableStyles = rowLinkTableStyles;
|
|
93
116
|
exports.withRowLink = withRowLink;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RowLink.cjs","names":["styled","Slot","React","Children","isValidElement","cloneElement"],"sources":["../../../components/RowLink/RowLink.tsx"],"sourcesContent":["import { Slot } from '@radix-ui/react-slot';\nimport React, { Children, cloneElement, ElementType, isValidElement, ReactNode } from 'react';\n\nimport { CSS, styled } from '../../stitches.config';\n\nconst ROW_LINK_ATTRIBUTE = 'data-row-link';\nconst STITCHES_INTERNAL = Symbol.for('sxs.internal');\n\nconst ROW_LINK_Z_INDEX = 1;\nexport const ROW_LINK_CONTROL_Z_INDEX = 2;\nconst ROW_LINK_CONTROLS = `:where(a, button, input, select, textarea, [tabindex]):where(:not([${ROW_LINK_ATTRIBUTE}]))`;\n\nconst rowLinkStyles = {\n color: 'inherit',\n textDecoration: 'none',\n outline: 'none',\n\n '&::after': {\n content: '\"\"',\n position: 'absolute',\n inset: 0,\n zIndex: ROW_LINK_Z_INDEX,\n },\n\n '&:focus-visible::after': {\n outlineWidth: '2px',\n outlineStyle: 'solid',\n outlineColor: '$focusOutline',\n outlineOffset: '-2px',\n },\n};\n\nconst StyledRowLink = styled('a', rowLinkStyles);\nconst StyledRowLinkSlot = styled(Slot, rowLinkStyles);\n\n/** Styles for a table that can hold a `RowLink`. */\nexport const rowLinkTableStyles = {\n [`&:has([${ROW_LINK_ATTRIBUTE}])`]: {\n isolation: 'isolate',\n },\n};\n\n/** Styles for a table row that can hold a `RowLink`. */\nexport const rowLinkRowStyles = {\n [`&:has([${ROW_LINK_ATTRIBUTE}])`]: {\n position: 'relative',\n },\n // Not at zero specificity, so that it wins over the `all: unset` of controls such as Checkbox.\n [`&:has([${ROW_LINK_ATTRIBUTE}]) ${ROW_LINK_CONTROLS}`]: {\n position: 'relative',\n zIndex: ROW_LINK_CONTROL_Z_INDEX,\n },\n};\n\nexport type RowLinkProps = React.ComponentProps<typeof StyledRowLink> & {\n asChild?: boolean;\n css?: CSS;\n};\n\n/**\n * A link that covers its whole table row, so that a click on the row opens it.\n * Other links and buttons in the row stay above it.\n */\nexport const RowLink = React.forwardRef<HTMLAnchorElement, RowLinkProps>(\n ({ asChild, ...props }, forwardedRef) => {\n const Component = asChild ? StyledRowLinkSlot : StyledRowLink;\n\n return <Component
|
|
1
|
+
{"version":3,"file":"RowLink.cjs","names":["styled","Slot","React","Children","isValidElement","cloneElement"],"sources":["../../../components/RowLink/RowLink.tsx"],"sourcesContent":["import { Slot } from '@radix-ui/react-slot';\nimport React, { Children, cloneElement, ElementType, isValidElement, ReactNode } from 'react';\n\nimport { CSS, styled } from '../../stitches.config';\nimport { warnOnce } from '../../utils/warnOnce';\n\nconst ROW_LINK_ATTRIBUTE = 'data-row-link';\nconst STITCHES_INTERNAL = Symbol.for('sxs.internal');\n\nconst ROW_LINK_Z_INDEX = 1;\nexport const ROW_LINK_CONTROL_Z_INDEX = 2;\nconst ROW_LINK_CONTROLS = `:where(a, button, input, select, textarea, [tabindex]):where(:not([${ROW_LINK_ATTRIBUTE}]))`;\n\nconst rowLinkStyles = {\n color: 'inherit',\n textDecoration: 'none',\n outline: 'none',\n\n '&::after': {\n content: '\"\"',\n position: 'absolute',\n inset: 0,\n zIndex: ROW_LINK_Z_INDEX,\n },\n\n '&:focus-visible::after': {\n outlineWidth: '2px',\n outlineStyle: 'solid',\n outlineColor: '$focusOutline',\n outlineOffset: '-2px',\n },\n\n [`&[${ROW_LINK_ATTRIBUTE}=\"click\"]::after`]: {\n content: 'none',\n },\n\n [`&[${ROW_LINK_ATTRIBUTE}=\"click\"]:focus-visible`]: {\n outlineWidth: '2px',\n outlineStyle: 'solid',\n outlineColor: '$focusOutline',\n outlineOffset: '2px',\n },\n};\n\nconst StyledRowLink = styled('a', rowLinkStyles);\nconst StyledRowLinkSlot = styled(Slot, rowLinkStyles);\n\n/** Styles for a table that can hold a `RowLink`. */\nexport const rowLinkTableStyles = {\n [`&:has([${ROW_LINK_ATTRIBUTE}])`]: {\n isolation: 'isolate',\n },\n};\n\n/** Styles for a table row that can hold a `RowLink`. */\nexport const rowLinkRowStyles = {\n [`&:has([${ROW_LINK_ATTRIBUTE}])`]: {\n position: 'relative',\n },\n // Not at zero specificity, so that it wins over the `all: unset` of controls such as Checkbox.\n [`&:has([${ROW_LINK_ATTRIBUTE}]) ${ROW_LINK_CONTROLS}`]: {\n position: 'relative',\n zIndex: ROW_LINK_CONTROL_Z_INDEX,\n },\n};\n\nexport type RowLinkProps = React.ComponentProps<typeof StyledRowLink> & {\n asChild?: boolean;\n css?: CSS;\n /**\n * With `false`, the link does not cover the row. The row opens it on a click instead, so the text of the\n * row keeps its hover, for example a tooltip, and can be selected.\n */\n overlay?: boolean;\n};\n\n/**\n * A link that covers its whole table row, so that a click on the row opens it.\n * Other links and buttons in the row stay above it.\n */\nexport const RowLink = React.forwardRef<HTMLAnchorElement, RowLinkProps>(\n ({ asChild, overlay = true, ...props }, forwardedRef) => {\n const Component = asChild ? StyledRowLinkSlot : StyledRowLink;\n\n return (\n <Component\n ref={forwardedRef}\n {...{ [ROW_LINK_ATTRIBUTE]: overlay ? '' : 'click' }}\n {...props}\n />\n );\n },\n);\n\nRowLink.displayName = 'RowLink';\n\nexport type RowLinkShortcutProps = {\n href?: string;\n /**\n * The link component, for example a router link. It must pass its props and ref to its `<a>`,\n * and it must be defined outside render, or the link mounts again on each render.\n */\n linkAs?: ElementType;\n /** Other props for the link component, for example `{ returnTo }`. */\n linkProps?: Record<string, unknown>;\n /** The index of the cell that holds the link, among the direct children of the row. */\n linkCell?: number;\n /** With `false`, the link does not cover the row: see `overlay` on `RowLink`. */\n linkOverlay?: boolean;\n};\n\ntype StitchesType = { className?: string; [STITCHES_INTERNAL]?: { type?: unknown } };\n\n// A Stitches `styled(Td)` keeps the class name of a Stitches Td, or renders a component Td.\n// This reads Stitches 1.x internals; the styled Td tests catch a change in them.\nconst isCellType = (type: unknown, cellType: ElementType) => {\n if (type === cellType) {\n return true;\n }\n if (!type || (typeof type !== 'object' && typeof type !== 'function')) {\n return false;\n }\n const { className, [STITCHES_INTERNAL]: internal } = type as StitchesType;\n const cellClassName = (cellType as StitchesType).className;\n return internal?.type === cellType || (!!cellClassName && className === cellClassName);\n};\n\n/** Puts the content of the `cellType` cell at `linkCell` in a `RowLink` to `href`. */\nexport const withRowLink = (\n children: ReactNode,\n { href, linkAs: LinkComponent = 'a', linkCell = 0, linkProps, linkOverlay }: RowLinkShortcutProps,\n cellType: ElementType,\n) => {\n if (href === undefined) {\n return children;\n }\n\n let cellIndex = -1;\n let linked = false;\n // eslint-disable-next-line @eslint-react/no-children-map\n const mapped = Children.map(children, (child) => {\n if (!isValidElement<{ children?: ReactNode }>(child)) {\n return child;\n }\n cellIndex += 1;\n if (cellIndex !== linkCell || !isCellType(child.type, cellType)) {\n return child;\n }\n linked = true;\n // eslint-disable-next-line @eslint-react/no-clone-element\n return cloneElement(\n child,\n undefined,\n <RowLink asChild overlay={linkOverlay}>\n <LinkComponent {...linkProps} href={href}>\n {child.props.children}\n </LinkComponent>\n </RowLink>,\n );\n });\n\n if (!linked) {\n warnOnce(\n `Tr: the child at linkCell ${linkCell} is not a Td, so the row has no link. Use a Td for that cell, or put a RowLink in it.`,\n );\n }\n\n return mapped;\n};\n\n// Only a web page opens in a new tab, never a script URL such as javascript: or data:.\n// Other links, such as tel: or mailto:, open as on a plain click.\nconst NEW_TAB_PROTOCOLS = ['http:', 'https:'];\n\nconst ROW_CLICK_CONTROLS =\n 'a, button, input, select, textarea, label, summary, [role=\"button\"], [role=\"link\"], [role=\"checkbox\"], [role=\"switch\"], [role=\"menuitem\"], [tabindex]:not([tabindex=\"-1\"]), [contenteditable=\"true\"]';\n\n/** Opens the `RowLink` without overlay of the row on a click or a middle click outside its controls. */\nexport const openRowLink = <T extends HTMLElement>(event: React.MouseEvent<T>) => {\n const isAuxClick = event.type === 'auxclick';\n if (event.defaultPrevented || (isAuxClick && event.button !== 1)) {\n return;\n }\n const row = event.currentTarget;\n const target = event.target;\n // A portal, such as a row menu, sends its clicks to the row through React, but it is not in the row.\n if (!(target instanceof Element) || !row.contains(target)) {\n return;\n }\n const control = target.closest(ROW_CLICK_CONTROLS);\n if (control && row.contains(control)) {\n return;\n }\n const link = row.querySelector<HTMLAnchorElement>(`[${ROW_LINK_ATTRIBUTE}=\"click\"]`);\n if (!link) {\n return;\n }\n // A drag that selects text in the row is not a click on the row.\n const selection = window.getSelection();\n if (selection && !selection.isCollapsed && row.contains(selection.anchorNode)) {\n return;\n }\n const newTab = isAuxClick || event.metaKey || event.ctrlKey || event.shiftKey;\n if (newTab && NEW_TAB_PROTOCOLS.includes(new URL(link.href, window.location.href).protocol)) {\n window.open(link.href, '_blank', 'noopener,noreferrer');\n return;\n }\n link.click();\n};\n"],"mappings":";;;;;;;;AAMA,IAAM,qBAAqB;AAC3B,IAAM,oBAAoB,OAAO,IAAI,cAAc;AAEnD,IAAM,mBAAmB;AAEzB,IAAM,oBAAoB,sEAAsE,mBAAmB;AAEnH,IAAM,gBAAgB;CACpB,OAAO;CACP,gBAAgB;CAChB,SAAS;CAET,YAAY;EACV,SAAS;EACT,UAAU;EACV,OAAO;EACP,QAAQ;CACV;CAEA,0BAA0B;EACxB,cAAc;EACd,cAAc;EACd,cAAc;EACd,eAAe;CACjB;EAEC,KAAK,mBAAmB,oBAAoB,EAC3C,SAAS,OACX;EAEC,KAAK,mBAAmB,2BAA2B;EAClD,cAAc;EACd,cAAc;EACd,cAAc;EACd,eAAe;CACjB;AACF;AAEA,IAAM,gBAAgBA,wBAAAA,OAAO,KAAK,aAAa;AAC/C,IAAM,oBAAoBA,wBAAAA,OAAOC,qBAAAA,MAAM,aAAa;;AAGpD,IAAa,qBAAqB,GAC/B,UAAU,mBAAmB,MAAM,EAClC,WAAW,UACb,EACF;;AAGA,IAAa,mBAAmB;EAC7B,UAAU,mBAAmB,MAAM,EAClC,UAAU,WACZ;EAEC,UAAU,mBAAmB,KAAK,sBAAsB;EACvD,UAAU;EACV,QAAA;CACF;AACF;;;;;AAgBA,IAAa,UAAUC,MAAAA,QAAM,YAC1B,EAAE,SAAS,UAAU,MAAM,GAAG,SAAS,iBAAiB;CAGvD,OACE,iBAAA,GAAA,kBAAA,IAAA,CAHgB,UAAU,oBAAoB,eAG9C;EACE,KAAK;GACE,qBAAqB,UAAU,KAAK;EAC3C,GAAI;CACL,CAAA;AAEL,CACF;AAEA,QAAQ,cAAc;AAq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