@traefik-labs/faency 13.3.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/Alert/Alert.cjs.map +1 -1
- package/dist/components/Alert/Alert.js.map +1 -1
- 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/Badge/Badge.vanilla.css.cjs.map +1 -1
- package/dist/components/Badge/Badge.vanilla.css.js.map +1 -1
- package/dist/components/Card/Card.cjs.map +1 -1
- package/dist/components/Card/Card.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/Combobox/Combobox.vanilla.cjs +170 -0
- package/dist/components/Combobox/Combobox.vanilla.cjs.map +1 -0
- package/dist/components/Combobox/Combobox.vanilla.css.cjs +33 -0
- package/dist/components/Combobox/Combobox.vanilla.css.cjs.map +1 -0
- package/dist/components/Combobox/Combobox.vanilla.css.js +29 -0
- package/dist/components/Combobox/Combobox.vanilla.css.js.map +1 -0
- package/dist/components/Combobox/Combobox.vanilla.js +167 -0
- package/dist/components/Combobox/Combobox.vanilla.js.map +1 -0
- 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 +74 -0
- package/dist/components/Meter/Meter.vanilla.cjs.map +1 -0
- package/dist/components/Meter/Meter.vanilla.css.cjs +26 -0
- package/dist/components/Meter/Meter.vanilla.css.cjs.map +1 -0
- package/dist/components/Meter/Meter.vanilla.css.js +21 -0
- package/dist/components/Meter/Meter.vanilla.css.js.map +1 -0
- package/dist/components/Meter/Meter.vanilla.js +72 -0
- package/dist/components/Meter/Meter.vanilla.js.map +1 -0
- 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/SegmentedControl/SegmentedControl.vanilla.cjs +57 -0
- package/dist/components/SegmentedControl/SegmentedControl.vanilla.cjs.map +1 -0
- package/dist/components/SegmentedControl/SegmentedControl.vanilla.css.cjs +35 -0
- package/dist/components/SegmentedControl/SegmentedControl.vanilla.css.cjs.map +1 -0
- package/dist/components/SegmentedControl/SegmentedControl.vanilla.css.js +34 -0
- package/dist/components/SegmentedControl/SegmentedControl.vanilla.css.js.map +1 -0
- package/dist/components/SegmentedControl/SegmentedControl.vanilla.js +53 -0
- package/dist/components/SegmentedControl/SegmentedControl.vanilla.js.map +1 -0
- package/dist/components/Select/Select.cjs +1 -1
- package/dist/components/Select/Select.js +1 -1
- package/dist/components/Spinner/Spinner.vanilla.cjs +50 -0
- package/dist/components/Spinner/Spinner.vanilla.cjs.map +1 -0
- package/dist/components/Spinner/Spinner.vanilla.css.cjs +21 -0
- package/dist/components/Spinner/Spinner.vanilla.css.cjs.map +1 -0
- package/dist/components/Spinner/Spinner.vanilla.css.js +19 -0
- package/dist/components/Spinner/Spinner.vanilla.css.js.map +1 -0
- package/dist/components/Spinner/Spinner.vanilla.js +48 -0
- package/dist/components/Spinner/Spinner.vanilla.js.map +1 -0
- package/dist/components/SplitLayout/SplitLayout.vanilla.cjs +214 -0
- package/dist/components/SplitLayout/SplitLayout.vanilla.cjs.map +1 -0
- package/dist/components/SplitLayout/SplitLayout.vanilla.css.cjs +14 -0
- package/dist/components/SplitLayout/SplitLayout.vanilla.css.cjs.map +1 -0
- package/dist/components/SplitLayout/SplitLayout.vanilla.css.js +10 -0
- package/dist/components/SplitLayout/SplitLayout.vanilla.css.js.map +1 -0
- package/dist/components/SplitLayout/SplitLayout.vanilla.js +210 -0
- package/dist/components/SplitLayout/SplitLayout.vanilla.js.map +1 -0
- 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/Toast.vanilla.cjs +96 -0
- package/dist/components/Toast/Toast.vanilla.cjs.map +1 -0
- package/dist/components/Toast/Toast.vanilla.css.cjs +44 -0
- package/dist/components/Toast/Toast.vanilla.css.cjs.map +1 -0
- package/dist/components/Toast/Toast.vanilla.css.js +37 -0
- package/dist/components/Toast/Toast.vanilla.css.js.map +1 -0
- package/dist/components/Toast/Toast.vanilla.js +90 -0
- package/dist/components/Toast/Toast.vanilla.js.map +1 -0
- package/dist/components/Toast/ToastProvider.vanilla.cjs +98 -0
- package/dist/components/Toast/ToastProvider.vanilla.cjs.map +1 -0
- package/dist/components/Toast/ToastProvider.vanilla.js +94 -0
- package/dist/components/Toast/ToastProvider.vanilla.js.map +1 -0
- package/dist/faency.css +3315 -2335
- package/dist/index.cjs +55 -32
- package/dist/index.d.ts +809 -14
- package/dist/index.js +41 -33
- package/dist/styles/cssProps.cjs +3 -10
- package/dist/styles/cssProps.cjs.map +1 -1
- package/dist/styles/cssProps.js +3 -10
- package/dist/styles/cssProps.js.map +1 -1
- package/dist/styles/resolveColor.cjs +18 -0
- package/dist/styles/resolveColor.cjs.map +1 -0
- package/dist/styles/resolveColor.js +18 -0
- package/dist/styles/resolveColor.js.map +1 -0
- package/dist/styles/themes.css.cjs.map +1 -1
- package/dist/styles/themes.css.js.map +1 -1
- package/dist/styles/tokens.css.cjs +484 -0
- package/dist/styles/tokens.css.cjs.map +1 -0
- package/dist/styles/tokens.css.js +484 -0
- package/dist/styles/tokens.css.js.map +1 -0
- 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 +12 -25
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_Box = require("../Box/Box.cjs");
|
|
3
|
-
const require_Text = require("../Text/Text.cjs");
|
|
4
3
|
const require_Label = require("../Label/Label.cjs");
|
|
5
|
-
const
|
|
4
|
+
const require_Text = require("../Text/Text.cjs");
|
|
6
5
|
const require_VisuallyHidden = require("../VisuallyHidden/VisuallyHidden.cjs");
|
|
6
|
+
const require_FieldContext = require("./FieldContext.cjs");
|
|
7
7
|
let react = require("react");
|
|
8
8
|
react = require_runtime.__toESM(react, 1);
|
|
9
9
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -11,56 +11,106 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
11
11
|
var MESSAGE_CSS = {
|
|
12
12
|
display: "block",
|
|
13
13
|
m: 0,
|
|
14
|
-
mt: "$1"
|
|
14
|
+
mt: "$1",
|
|
15
|
+
lineHeight: 1.4
|
|
16
|
+
};
|
|
17
|
+
var COMPACT_LABEL_CSS = { lineHeight: 1.4 };
|
|
18
|
+
var HINT_ABOVE_CONTROL_CSS = {
|
|
19
|
+
...MESSAGE_CSS,
|
|
20
|
+
mb: "$2"
|
|
21
|
+
};
|
|
22
|
+
var START_ROW_CSS = {
|
|
23
|
+
display: "flex",
|
|
24
|
+
flexWrap: "wrap",
|
|
25
|
+
alignItems: "baseline",
|
|
26
|
+
columnGap: "$5",
|
|
27
|
+
rowGap: "$2"
|
|
28
|
+
};
|
|
29
|
+
var START_LABEL_CSS = {
|
|
30
|
+
flex: "1 1 0",
|
|
31
|
+
minWidth: "10rem"
|
|
32
|
+
};
|
|
33
|
+
var START_CONTROL_CSS = {
|
|
34
|
+
flex: "2 1 0",
|
|
35
|
+
minWidth: "16rem"
|
|
15
36
|
};
|
|
16
37
|
/**
|
|
17
|
-
* Gives a label, a description and an error to the one form control inside it.
|
|
18
|
-
*
|
|
38
|
+
* Gives a label, a hint, a description and an error to the one form control inside it.
|
|
39
|
+
* For more than one control, use `group`.
|
|
19
40
|
*/
|
|
20
|
-
var Field = ({ label, description, error, announceError, labelPosition = "top", children, css, ...props }) => {
|
|
21
|
-
const { context, labelFor, labelVariant, hasLabel, hasDescription, hasError, onFocus, onBlur } = require_FieldContext.useFieldRoot({
|
|
41
|
+
var Field = ({ label, hint, description, error, announceError, labelPosition = "top", children, css, ...props }) => {
|
|
42
|
+
const { context, ids, groupProps, messageSize, labelFor, labelVariant, hasLabel, hasHint, hasDescription, hasError, onFocus, onBlur } = require_FieldContext.useFieldRoot({
|
|
22
43
|
label,
|
|
44
|
+
hint,
|
|
23
45
|
description,
|
|
24
46
|
error,
|
|
25
47
|
...props
|
|
26
48
|
});
|
|
27
|
-
const announcedError = require_FieldContext.useAnnouncedError(Boolean(announceError), hasError ?
|
|
49
|
+
const announcedError = require_FieldContext.useAnnouncedError(Boolean(announceError), hasError ? ids.errorId : void 0, ids.labelId);
|
|
28
50
|
const labelNode = react.default.useMemo(() => {
|
|
29
|
-
if (!hasLabel || !
|
|
51
|
+
if (!hasLabel || !ids.labelId) return null;
|
|
30
52
|
if (typeof label === "function") return label({
|
|
31
53
|
variant: labelVariant,
|
|
32
54
|
htmlFor: labelFor,
|
|
33
|
-
id:
|
|
55
|
+
id: ids.labelId
|
|
34
56
|
});
|
|
35
57
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Label.Label, {
|
|
36
58
|
variant: labelVariant,
|
|
37
59
|
htmlFor: labelFor,
|
|
38
|
-
id:
|
|
60
|
+
id: ids.labelId,
|
|
61
|
+
css: hasHint || labelPosition === "start" ? COMPACT_LABEL_CSS : void 0,
|
|
39
62
|
children: label
|
|
40
63
|
});
|
|
41
64
|
}, [
|
|
42
65
|
hasLabel,
|
|
66
|
+
hasHint,
|
|
43
67
|
label,
|
|
68
|
+
labelPosition,
|
|
44
69
|
labelVariant,
|
|
45
70
|
labelFor,
|
|
46
|
-
|
|
71
|
+
ids.labelId
|
|
47
72
|
]);
|
|
48
|
-
const
|
|
73
|
+
const hintNode = hasHint && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Text.Text, {
|
|
74
|
+
as: "p",
|
|
75
|
+
id: ids.hintId,
|
|
76
|
+
size: messageSize,
|
|
77
|
+
variant: "subtle",
|
|
78
|
+
css: labelPosition === "top" ? HINT_ABOVE_CONTROL_CSS : MESSAGE_CSS,
|
|
79
|
+
children: hint
|
|
80
|
+
});
|
|
81
|
+
const messages = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [hasDescription && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Text.Text, {
|
|
49
82
|
as: "p",
|
|
50
|
-
id:
|
|
51
|
-
size:
|
|
83
|
+
id: ids.descriptionId,
|
|
84
|
+
size: messageSize,
|
|
85
|
+
variant: "subtle",
|
|
86
|
+
css: MESSAGE_CSS,
|
|
87
|
+
children: description
|
|
88
|
+
}), hasError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Text.Text, {
|
|
89
|
+
as: "p",
|
|
90
|
+
id: ids.errorId,
|
|
91
|
+
size: messageSize,
|
|
52
92
|
variant: "invalid",
|
|
53
93
|
css: MESSAGE_CSS,
|
|
54
94
|
children: error
|
|
55
|
-
});
|
|
95
|
+
})] });
|
|
56
96
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_FieldContext.FieldContext.Provider, {
|
|
57
97
|
value: context,
|
|
58
98
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Box.Box, {
|
|
59
|
-
css
|
|
99
|
+
css: labelPosition === "start" ? {
|
|
100
|
+
...START_ROW_CSS,
|
|
101
|
+
...css
|
|
102
|
+
} : css,
|
|
60
103
|
onFocus,
|
|
61
104
|
onBlur,
|
|
62
|
-
|
|
63
|
-
|
|
105
|
+
...groupProps,
|
|
106
|
+
children: [labelPosition === "start" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Box.Box, {
|
|
107
|
+
css: START_LABEL_CSS,
|
|
108
|
+
children: [labelNode, hintNode]
|
|
109
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Box.Box, {
|
|
110
|
+
css: START_CONTROL_CSS,
|
|
111
|
+
children: [children, messages]
|
|
112
|
+
})] }) : labelPosition === "end" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
113
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Box.Box, {
|
|
64
114
|
css: {
|
|
65
115
|
display: "flex",
|
|
66
116
|
alignItems: "center",
|
|
@@ -68,21 +118,18 @@ var Field = ({ label, description, error, announceError, labelPosition = "top",
|
|
|
68
118
|
"& > [role=\"switch\"]": { m: 0 }
|
|
69
119
|
},
|
|
70
120
|
children: [children, labelNode]
|
|
71
|
-
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [labelNode, children] }),
|
|
72
|
-
hasDescription && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Text.Text, {
|
|
73
|
-
as: "p",
|
|
74
|
-
id: context.descriptionId,
|
|
75
|
-
size: "0",
|
|
76
|
-
variant: "subtle",
|
|
77
|
-
css: MESSAGE_CSS,
|
|
78
|
-
children: description
|
|
79
121
|
}),
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
122
|
+
hintNode,
|
|
123
|
+
messages
|
|
124
|
+
] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
125
|
+
labelNode,
|
|
126
|
+
hintNode,
|
|
127
|
+
children,
|
|
128
|
+
messages
|
|
129
|
+
] }), announceError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_VisuallyHidden.VisuallyHidden, {
|
|
130
|
+
"aria-live": "polite",
|
|
131
|
+
children: announcedError
|
|
132
|
+
})]
|
|
86
133
|
})
|
|
87
134
|
});
|
|
88
135
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.cjs","names":["useFieldRoot","useAnnouncedError","React","Label","Text","
|
|
1
|
+
{"version":3,"file":"Field.cjs","names":["useFieldRoot","useAnnouncedError","React","Label","Text","_Fragment","FieldContext","Box","VisuallyHidden"],"sources":["../../../components/Field/Field.tsx"],"sourcesContent":["import React from 'react';\n\nimport { CSS } from '../../stitches.config';\nimport { Box } from '../Box';\nimport { Label } from '../Label';\nimport { Text } from '../Text';\nimport { VisuallyHidden } from '../VisuallyHidden';\nimport { FieldBaseProps, FieldContext, useAnnouncedError, useFieldRoot } from './FieldContext';\n\nexport type FieldProps = FieldBaseProps & { css?: CSS };\n\nconst MESSAGE_CSS = { display: 'block', m: 0, mt: '$1', lineHeight: 1.4 };\n// The tall line of a label makes room for a control right under it. Before a hint or beside a control, it is a gap.\nconst COMPACT_LABEL_CSS = { lineHeight: 1.4 };\nconst HINT_ABOVE_CONTROL_CSS = { ...MESSAGE_CSS, mb: '$2' };\n\nconst START_ROW_CSS = {\n display: 'flex',\n flexWrap: 'wrap',\n alignItems: 'baseline',\n columnGap: '$5',\n rowGap: '$2',\n};\nconst START_LABEL_CSS = { flex: '1 1 0', minWidth: '10rem' };\nconst START_CONTROL_CSS = { flex: '2 1 0', minWidth: '16rem' };\n\n/**\n * Gives a label, a hint, a description and an error to the one form control inside it.\n * For more than one control, use `group`.\n */\nexport const Field = ({\n label,\n hint,\n description,\n error,\n announceError,\n labelPosition = 'top',\n children,\n css,\n ...props\n}: FieldProps) => {\n const {\n context,\n ids,\n groupProps,\n messageSize,\n labelFor,\n labelVariant,\n hasLabel,\n hasHint,\n hasDescription,\n hasError,\n onFocus,\n onBlur,\n } = useFieldRoot({ label, hint, description, error, ...props });\n const announcedError = useAnnouncedError(\n Boolean(announceError),\n hasError ? ids.errorId : undefined,\n ids.labelId,\n );\n\n const labelNode = React.useMemo(() => {\n if (!hasLabel || !ids.labelId) {\n return null;\n }\n if (typeof label === 'function') {\n return label({ variant: labelVariant, htmlFor: labelFor, id: ids.labelId });\n }\n return (\n <Label\n variant={labelVariant}\n htmlFor={labelFor}\n id={ids.labelId}\n css={hasHint || labelPosition === 'start' ? COMPACT_LABEL_CSS : undefined}\n >\n {label}\n </Label>\n );\n }, [hasLabel, hasHint, label, labelPosition, labelVariant, labelFor, ids.labelId]);\n\n const hintNode = hasHint && (\n <Text\n as=\"p\"\n id={ids.hintId}\n size={messageSize}\n variant=\"subtle\"\n css={labelPosition === 'top' ? HINT_ABOVE_CONTROL_CSS : MESSAGE_CSS}\n >\n {hint}\n </Text>\n );\n\n const messages = (\n <>\n {hasDescription && (\n <Text as=\"p\" id={ids.descriptionId} size={messageSize} variant=\"subtle\" css={MESSAGE_CSS}>\n {description}\n </Text>\n )}\n {hasError && (\n <Text as=\"p\" id={ids.errorId} size={messageSize} variant=\"invalid\" css={MESSAGE_CSS}>\n {error}\n </Text>\n )}\n </>\n );\n\n return (\n <FieldContext.Provider value={context}>\n <Box\n css={labelPosition === 'start' ? { ...START_ROW_CSS, ...css } : css}\n onFocus={onFocus}\n onBlur={onBlur}\n {...groupProps}\n >\n {labelPosition === 'start' ? (\n <>\n <Box css={START_LABEL_CSS}>\n {labelNode}\n {hintNode}\n </Box>\n <Box css={START_CONTROL_CSS}>\n {children}\n {messages}\n </Box>\n </>\n ) : labelPosition === 'end' ? (\n <>\n <Box\n css={{\n display: 'flex',\n alignItems: 'center',\n gap: '$2',\n '& > [role=\"switch\"]': { m: 0 },\n }}\n >\n {children}\n {labelNode}\n </Box>\n {hintNode}\n {messages}\n </>\n ) : (\n <>\n {labelNode}\n {hintNode}\n {children}\n {messages}\n </>\n )}\n {announceError && <VisuallyHidden aria-live=\"polite\">{announcedError}</VisuallyHidden>}\n </Box>\n </FieldContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;AAWA,IAAM,cAAc;CAAE,SAAS;CAAS,GAAG;CAAG,IAAI;CAAM,YAAY;AAAI;AAExE,IAAM,oBAAoB,EAAE,YAAY,IAAI;AAC5C,IAAM,yBAAyB;CAAE,GAAG;CAAa,IAAI;AAAK;AAE1D,IAAM,gBAAgB;CACpB,SAAS;CACT,UAAU;CACV,YAAY;CACZ,WAAW;CACX,QAAQ;AACV;AACA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+1,114 @@
|
|
|
1
1
|
import { Box } from "../Box/Box.js";
|
|
2
|
-
import { Text } from "../Text/Text.js";
|
|
3
2
|
import { Label } from "../Label/Label.js";
|
|
4
|
-
import {
|
|
3
|
+
import { Text } from "../Text/Text.js";
|
|
5
4
|
import { VisuallyHidden } from "../VisuallyHidden/VisuallyHidden.js";
|
|
5
|
+
import { FieldContext, useAnnouncedError, useFieldRoot } from "./FieldContext.js";
|
|
6
6
|
import React from "react";
|
|
7
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
// components/Field/Field.tsx
|
|
9
9
|
var MESSAGE_CSS = {
|
|
10
10
|
display: "block",
|
|
11
11
|
m: 0,
|
|
12
|
-
mt: "$1"
|
|
12
|
+
mt: "$1",
|
|
13
|
+
lineHeight: 1.4
|
|
14
|
+
};
|
|
15
|
+
var COMPACT_LABEL_CSS = { lineHeight: 1.4 };
|
|
16
|
+
var HINT_ABOVE_CONTROL_CSS = {
|
|
17
|
+
...MESSAGE_CSS,
|
|
18
|
+
mb: "$2"
|
|
19
|
+
};
|
|
20
|
+
var START_ROW_CSS = {
|
|
21
|
+
display: "flex",
|
|
22
|
+
flexWrap: "wrap",
|
|
23
|
+
alignItems: "baseline",
|
|
24
|
+
columnGap: "$5",
|
|
25
|
+
rowGap: "$2"
|
|
26
|
+
};
|
|
27
|
+
var START_LABEL_CSS = {
|
|
28
|
+
flex: "1 1 0",
|
|
29
|
+
minWidth: "10rem"
|
|
30
|
+
};
|
|
31
|
+
var START_CONTROL_CSS = {
|
|
32
|
+
flex: "2 1 0",
|
|
33
|
+
minWidth: "16rem"
|
|
13
34
|
};
|
|
14
35
|
/**
|
|
15
|
-
* Gives a label, a description and an error to the one form control inside it.
|
|
16
|
-
*
|
|
36
|
+
* Gives a label, a hint, a description and an error to the one form control inside it.
|
|
37
|
+
* For more than one control, use `group`.
|
|
17
38
|
*/
|
|
18
|
-
var Field = ({ label, description, error, announceError, labelPosition = "top", children, css, ...props }) => {
|
|
19
|
-
const { context, labelFor, labelVariant, hasLabel, hasDescription, hasError, onFocus, onBlur } = useFieldRoot({
|
|
39
|
+
var Field = ({ label, hint, description, error, announceError, labelPosition = "top", children, css, ...props }) => {
|
|
40
|
+
const { context, ids, groupProps, messageSize, labelFor, labelVariant, hasLabel, hasHint, hasDescription, hasError, onFocus, onBlur } = useFieldRoot({
|
|
20
41
|
label,
|
|
42
|
+
hint,
|
|
21
43
|
description,
|
|
22
44
|
error,
|
|
23
45
|
...props
|
|
24
46
|
});
|
|
25
|
-
const announcedError = useAnnouncedError(Boolean(announceError), hasError ?
|
|
47
|
+
const announcedError = useAnnouncedError(Boolean(announceError), hasError ? ids.errorId : void 0, ids.labelId);
|
|
26
48
|
const labelNode = React.useMemo(() => {
|
|
27
|
-
if (!hasLabel || !
|
|
49
|
+
if (!hasLabel || !ids.labelId) return null;
|
|
28
50
|
if (typeof label === "function") return label({
|
|
29
51
|
variant: labelVariant,
|
|
30
52
|
htmlFor: labelFor,
|
|
31
|
-
id:
|
|
53
|
+
id: ids.labelId
|
|
32
54
|
});
|
|
33
55
|
return /* @__PURE__ */ jsx(Label, {
|
|
34
56
|
variant: labelVariant,
|
|
35
57
|
htmlFor: labelFor,
|
|
36
|
-
id:
|
|
58
|
+
id: ids.labelId,
|
|
59
|
+
css: hasHint || labelPosition === "start" ? COMPACT_LABEL_CSS : void 0,
|
|
37
60
|
children: label
|
|
38
61
|
});
|
|
39
62
|
}, [
|
|
40
63
|
hasLabel,
|
|
64
|
+
hasHint,
|
|
41
65
|
label,
|
|
66
|
+
labelPosition,
|
|
42
67
|
labelVariant,
|
|
43
68
|
labelFor,
|
|
44
|
-
|
|
69
|
+
ids.labelId
|
|
45
70
|
]);
|
|
46
|
-
const
|
|
71
|
+
const hintNode = hasHint && /* @__PURE__ */ jsx(Text, {
|
|
72
|
+
as: "p",
|
|
73
|
+
id: ids.hintId,
|
|
74
|
+
size: messageSize,
|
|
75
|
+
variant: "subtle",
|
|
76
|
+
css: labelPosition === "top" ? HINT_ABOVE_CONTROL_CSS : MESSAGE_CSS,
|
|
77
|
+
children: hint
|
|
78
|
+
});
|
|
79
|
+
const messages = /* @__PURE__ */ jsxs(Fragment, { children: [hasDescription && /* @__PURE__ */ jsx(Text, {
|
|
47
80
|
as: "p",
|
|
48
|
-
id:
|
|
49
|
-
size:
|
|
81
|
+
id: ids.descriptionId,
|
|
82
|
+
size: messageSize,
|
|
83
|
+
variant: "subtle",
|
|
84
|
+
css: MESSAGE_CSS,
|
|
85
|
+
children: description
|
|
86
|
+
}), hasError && /* @__PURE__ */ jsx(Text, {
|
|
87
|
+
as: "p",
|
|
88
|
+
id: ids.errorId,
|
|
89
|
+
size: messageSize,
|
|
50
90
|
variant: "invalid",
|
|
51
91
|
css: MESSAGE_CSS,
|
|
52
92
|
children: error
|
|
53
|
-
});
|
|
93
|
+
})] });
|
|
54
94
|
return /* @__PURE__ */ jsx(FieldContext.Provider, {
|
|
55
95
|
value: context,
|
|
56
96
|
children: /* @__PURE__ */ jsxs(Box, {
|
|
57
|
-
css
|
|
97
|
+
css: labelPosition === "start" ? {
|
|
98
|
+
...START_ROW_CSS,
|
|
99
|
+
...css
|
|
100
|
+
} : css,
|
|
58
101
|
onFocus,
|
|
59
102
|
onBlur,
|
|
60
|
-
|
|
61
|
-
|
|
103
|
+
...groupProps,
|
|
104
|
+
children: [labelPosition === "start" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Box, {
|
|
105
|
+
css: START_LABEL_CSS,
|
|
106
|
+
children: [labelNode, hintNode]
|
|
107
|
+
}), /* @__PURE__ */ jsxs(Box, {
|
|
108
|
+
css: START_CONTROL_CSS,
|
|
109
|
+
children: [children, messages]
|
|
110
|
+
})] }) : labelPosition === "end" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
111
|
+
/* @__PURE__ */ jsxs(Box, {
|
|
62
112
|
css: {
|
|
63
113
|
display: "flex",
|
|
64
114
|
alignItems: "center",
|
|
@@ -66,21 +116,18 @@ var Field = ({ label, description, error, announceError, labelPosition = "top",
|
|
|
66
116
|
"& > [role=\"switch\"]": { m: 0 }
|
|
67
117
|
},
|
|
68
118
|
children: [children, labelNode]
|
|
69
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [labelNode, children] }),
|
|
70
|
-
hasDescription && /* @__PURE__ */ jsx(Text, {
|
|
71
|
-
as: "p",
|
|
72
|
-
id: context.descriptionId,
|
|
73
|
-
size: "0",
|
|
74
|
-
variant: "subtle",
|
|
75
|
-
css: MESSAGE_CSS,
|
|
76
|
-
children: description
|
|
77
119
|
}),
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
120
|
+
hintNode,
|
|
121
|
+
messages
|
|
122
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
123
|
+
labelNode,
|
|
124
|
+
hintNode,
|
|
125
|
+
children,
|
|
126
|
+
messages
|
|
127
|
+
] }), announceError && /* @__PURE__ */ jsx(VisuallyHidden, {
|
|
128
|
+
"aria-live": "polite",
|
|
129
|
+
children: announcedError
|
|
130
|
+
})]
|
|
84
131
|
})
|
|
85
132
|
});
|
|
86
133
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","names":["_Fragment"],"sources":["../../../components/Field/Field.tsx"],"sourcesContent":["import React from 'react';\n\nimport { CSS } from '../../stitches.config';\nimport { Box } from '../Box';\nimport { Label } from '../Label';\nimport { Text } from '../Text';\nimport { VisuallyHidden } from '../VisuallyHidden';\nimport { FieldBaseProps, FieldContext, useAnnouncedError, useFieldRoot } from './FieldContext';\n\nexport type FieldProps = FieldBaseProps & { css?: CSS };\n\nconst MESSAGE_CSS = { display: 'block', m: 0, mt: '$1' };\n\n/**\n * Gives a label, a description and an error to the one form control inside it.\n *
|
|
1
|
+
{"version":3,"file":"Field.js","names":["_Fragment"],"sources":["../../../components/Field/Field.tsx"],"sourcesContent":["import React from 'react';\n\nimport { CSS } from '../../stitches.config';\nimport { Box } from '../Box';\nimport { Label } from '../Label';\nimport { Text } from '../Text';\nimport { VisuallyHidden } from '../VisuallyHidden';\nimport { FieldBaseProps, FieldContext, useAnnouncedError, useFieldRoot } from './FieldContext';\n\nexport type FieldProps = FieldBaseProps & { css?: CSS };\n\nconst MESSAGE_CSS = { display: 'block', m: 0, mt: '$1', lineHeight: 1.4 };\n// The tall line of a label makes room for a control right under it. Before a hint or beside a control, it is a gap.\nconst COMPACT_LABEL_CSS = { lineHeight: 1.4 };\nconst HINT_ABOVE_CONTROL_CSS = { ...MESSAGE_CSS, mb: '$2' };\n\nconst START_ROW_CSS = {\n display: 'flex',\n flexWrap: 'wrap',\n alignItems: 'baseline',\n columnGap: '$5',\n rowGap: '$2',\n};\nconst START_LABEL_CSS = { flex: '1 1 0', minWidth: '10rem' };\nconst START_CONTROL_CSS = { flex: '2 1 0', minWidth: '16rem' };\n\n/**\n * Gives a label, a hint, a description and an error to the one form control inside it.\n * For more than one control, use `group`.\n */\nexport const Field = ({\n label,\n hint,\n description,\n error,\n announceError,\n labelPosition = 'top',\n children,\n css,\n ...props\n}: FieldProps) => {\n const {\n context,\n ids,\n groupProps,\n messageSize,\n labelFor,\n labelVariant,\n hasLabel,\n hasHint,\n hasDescription,\n hasError,\n onFocus,\n onBlur,\n } = useFieldRoot({ label, hint, description, error, ...props });\n const announcedError = useAnnouncedError(\n Boolean(announceError),\n hasError ? ids.errorId : undefined,\n ids.labelId,\n );\n\n const labelNode = React.useMemo(() => {\n if (!hasLabel || !ids.labelId) {\n return null;\n }\n if (typeof label === 'function') {\n return label({ variant: labelVariant, htmlFor: labelFor, id: ids.labelId });\n }\n return (\n <Label\n variant={labelVariant}\n htmlFor={labelFor}\n id={ids.labelId}\n css={hasHint || labelPosition === 'start' ? COMPACT_LABEL_CSS : undefined}\n >\n {label}\n </Label>\n );\n }, [hasLabel, hasHint, label, labelPosition, labelVariant, labelFor, ids.labelId]);\n\n const hintNode = hasHint && (\n <Text\n as=\"p\"\n id={ids.hintId}\n size={messageSize}\n variant=\"subtle\"\n css={labelPosition === 'top' ? HINT_ABOVE_CONTROL_CSS : MESSAGE_CSS}\n >\n {hint}\n </Text>\n );\n\n const messages = (\n <>\n {hasDescription && (\n <Text as=\"p\" id={ids.descriptionId} size={messageSize} variant=\"subtle\" css={MESSAGE_CSS}>\n {description}\n </Text>\n )}\n {hasError && (\n <Text as=\"p\" id={ids.errorId} size={messageSize} variant=\"invalid\" css={MESSAGE_CSS}>\n {error}\n </Text>\n )}\n </>\n );\n\n return (\n <FieldContext.Provider value={context}>\n <Box\n css={labelPosition === 'start' ? { ...START_ROW_CSS, ...css } : css}\n onFocus={onFocus}\n onBlur={onBlur}\n {...groupProps}\n >\n {labelPosition === 'start' ? (\n <>\n <Box css={START_LABEL_CSS}>\n {labelNode}\n {hintNode}\n </Box>\n <Box css={START_CONTROL_CSS}>\n {children}\n {messages}\n </Box>\n </>\n ) : labelPosition === 'end' ? (\n <>\n <Box\n css={{\n display: 'flex',\n alignItems: 'center',\n gap: '$2',\n '& > [role=\"switch\"]': { m: 0 },\n }}\n >\n {children}\n {labelNode}\n </Box>\n {hintNode}\n {messages}\n </>\n ) : (\n <>\n {labelNode}\n {hintNode}\n {children}\n {messages}\n </>\n )}\n {announceError && <VisuallyHidden aria-live=\"polite\">{announcedError}</VisuallyHidden>}\n </Box>\n </FieldContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;AAWA,IAAM,cAAc;CAAE,SAAS;CAAS,GAAG;CAAG,IAAI;CAAM,YAAY;AAAI;AAExE,IAAM,oBAAoB,EAAE,YAAY,IAAI;AAC5C,IAAM,yBAAyB;CAAE,GAAG;CAAa,IAAI;AAAK;AAE1D,IAAM,gBAAgB;CACpB,SAAS;CACT,UAAU;CACV,YAAY;CACZ,WAAW;CACX,QAAQ;AACV;AACA,IAAM,kBAAkB;CAAE,MAAM;CAAS,UAAU;AAAQ;AAC3D,IAAM,oBAAoB;CAAE,MA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kBAAkB,UAAU;IAAE,GAAG;IAAe,GAAG;GAAI,IAAI;GACvD;GACD;GACR,GAAI;GAJN,UAAA,CAMG,kBAAkB,UACjB,qBAAAA,UAAA,EAAA,UAAA,CACE,qBAAC,KAAD;IAAK,KAAK;IAAV,UAAA,CACG,WACA,QACE;GACL,CAAA,GAAA,qBAAC,KAAD;IAAK,KAAK;IAAV,UAAA,CACG,UACA,QACE;GACL,CAAA,CAAA,EAAA,CAAA,IACA,kBAAkB,QACpB,qBAAAA,UAAA,EAAA,UAAA;IACE,qBAAC,KAAD;KACE,KAAK;MACH,SAAS;MACT,YAAY;MACZ,KAAK;MACL,yBAAuB,EAAE,GAAG,EAAE;KAChC;KANF,UAAA,CAQG,UACA,SACE;;IACJ;IACA;GACD,EAAA,CAAA,IAEF,qBAAAA,UAAA,EAAA,UAAA;IACG;IACA;IACA;IACA;GACD,EAAA,CAAA,GAEH,iBAAiB,oBAAC,gBAAD;IAAgB,aAAU;IAAU,UAAA;GAA+B,CAAA,CAClF;;CACgB,CAAA;AAE3B"}
|
|
@@ -2,11 +2,11 @@ const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
|
2
2
|
const require_cssProps = require("../../styles/cssProps.cjs");
|
|
3
3
|
const require_themeContext = require("../../styles/themeContext.cjs");
|
|
4
4
|
const require_Box_vanilla = require("../Box/Box.vanilla.cjs");
|
|
5
|
-
const require_Text_vanilla = require("../Text/Text.vanilla.cjs");
|
|
6
5
|
const require_Label_vanilla = require("../Label/Label.vanilla.cjs");
|
|
7
|
-
const
|
|
6
|
+
const require_Text_vanilla = require("../Text/Text.vanilla.cjs");
|
|
8
7
|
const require_VisuallyHidden = require("../VisuallyHidden/VisuallyHidden.cjs");
|
|
9
8
|
const require_Field_vanilla_css = require("./Field.vanilla.css.cjs");
|
|
9
|
+
const require_FieldContext = require("./FieldContext.cjs");
|
|
10
10
|
let react = require("react");
|
|
11
11
|
react = require_runtime.__toESM(react, 1);
|
|
12
12
|
let _vanilla_extract_dynamic = require("@vanilla-extract/dynamic");
|
|
@@ -15,78 +15,108 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
15
15
|
var MESSAGE_CSS = {
|
|
16
16
|
display: "block",
|
|
17
17
|
m: 0,
|
|
18
|
-
mt: "$1"
|
|
18
|
+
mt: "$1",
|
|
19
|
+
lineHeight: 1.4
|
|
20
|
+
};
|
|
21
|
+
var COMPACT_LABEL_CSS = { lineHeight: 1.4 };
|
|
22
|
+
var HINT_ABOVE_CONTROL_CSS = {
|
|
23
|
+
...MESSAGE_CSS,
|
|
24
|
+
mb: "$2"
|
|
19
25
|
};
|
|
20
26
|
/**
|
|
21
|
-
* Gives a label, a description and an error to the one form control inside it.
|
|
22
|
-
*
|
|
27
|
+
* Gives a label, a hint, a description and an error to the one form control inside it.
|
|
28
|
+
* For more than one control, use `group`.
|
|
23
29
|
*/
|
|
24
|
-
var FieldVanilla = ({ label, description, error, announceError, labelPosition = "top", children, css, ...props }) => {
|
|
25
|
-
const { context, labelFor, labelVariant, hasLabel, hasDescription, hasError, onFocus, onBlur } = require_FieldContext.useFieldRoot({
|
|
30
|
+
var FieldVanilla = ({ label, hint, description, error, announceError, labelPosition = "top", children, css, ...props }) => {
|
|
31
|
+
const { context, ids, groupProps, messageSize, labelFor, labelVariant, hasLabel, hasHint, hasDescription, hasError, onFocus, onBlur } = require_FieldContext.useFieldRoot({
|
|
26
32
|
label,
|
|
33
|
+
hint,
|
|
27
34
|
description,
|
|
28
35
|
error,
|
|
29
36
|
...props
|
|
30
37
|
});
|
|
31
|
-
const announcedError = require_FieldContext.useAnnouncedError(Boolean(announceError), hasError ?
|
|
38
|
+
const announcedError = require_FieldContext.useAnnouncedError(Boolean(announceError), hasError ? ids.errorId : void 0, ids.labelId);
|
|
32
39
|
const { colors } = require_themeContext.useVanillaExtractTheme();
|
|
33
40
|
const { style: rootStyle, vars: rootVars } = require_cssProps.processCSSProp(css, colors);
|
|
34
41
|
const labelNode = react.default.useMemo(() => {
|
|
35
|
-
if (!hasLabel || !
|
|
42
|
+
if (!hasLabel || !ids.labelId) return null;
|
|
36
43
|
if (typeof label === "function") return label({
|
|
37
44
|
variant: labelVariant,
|
|
38
45
|
htmlFor: labelFor,
|
|
39
|
-
id:
|
|
46
|
+
id: ids.labelId
|
|
40
47
|
});
|
|
41
48
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Label_vanilla.LabelVanilla, {
|
|
42
49
|
variant: labelVariant,
|
|
43
50
|
htmlFor: labelFor,
|
|
44
|
-
id:
|
|
51
|
+
id: ids.labelId,
|
|
52
|
+
css: hasHint || labelPosition === "start" ? COMPACT_LABEL_CSS : void 0,
|
|
45
53
|
children: label
|
|
46
54
|
});
|
|
47
55
|
}, [
|
|
48
56
|
hasLabel,
|
|
57
|
+
hasHint,
|
|
49
58
|
label,
|
|
59
|
+
labelPosition,
|
|
50
60
|
labelVariant,
|
|
51
61
|
labelFor,
|
|
52
|
-
|
|
62
|
+
ids.labelId
|
|
53
63
|
]);
|
|
54
|
-
const
|
|
64
|
+
const hintNode = hasHint && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Text_vanilla.TextVanilla, {
|
|
55
65
|
as: "p",
|
|
56
|
-
id:
|
|
57
|
-
size:
|
|
66
|
+
id: ids.hintId,
|
|
67
|
+
size: messageSize,
|
|
68
|
+
variant: "subtle",
|
|
69
|
+
css: labelPosition === "top" ? HINT_ABOVE_CONTROL_CSS : MESSAGE_CSS,
|
|
70
|
+
children: hint
|
|
71
|
+
});
|
|
72
|
+
const messages = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [hasDescription && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Text_vanilla.TextVanilla, {
|
|
73
|
+
as: "p",
|
|
74
|
+
id: ids.descriptionId,
|
|
75
|
+
size: messageSize,
|
|
76
|
+
variant: "subtle",
|
|
77
|
+
css: MESSAGE_CSS,
|
|
78
|
+
children: description
|
|
79
|
+
}), hasError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Text_vanilla.TextVanilla, {
|
|
80
|
+
as: "p",
|
|
81
|
+
id: ids.errorId,
|
|
82
|
+
size: messageSize,
|
|
58
83
|
variant: "invalid",
|
|
59
84
|
css: MESSAGE_CSS,
|
|
60
85
|
children: error
|
|
61
|
-
});
|
|
86
|
+
})] });
|
|
62
87
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_FieldContext.FieldContext.Provider, {
|
|
63
88
|
value: context,
|
|
64
89
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
90
|
+
className: labelPosition === "start" ? require_Field_vanilla_css.startRow : void 0,
|
|
65
91
|
style: {
|
|
66
92
|
...rootStyle,
|
|
67
93
|
...(0, _vanilla_extract_dynamic.assignInlineVars)(rootVars)
|
|
68
94
|
},
|
|
69
95
|
onFocus,
|
|
70
96
|
onBlur,
|
|
71
|
-
|
|
72
|
-
|
|
97
|
+
...groupProps,
|
|
98
|
+
children: [labelPosition === "start" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Box_vanilla.BoxVanilla, {
|
|
99
|
+
className: require_Field_vanilla_css.startLabel,
|
|
100
|
+
children: [labelNode, hintNode]
|
|
101
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Box_vanilla.BoxVanilla, {
|
|
102
|
+
className: require_Field_vanilla_css.startControl,
|
|
103
|
+
children: [children, messages]
|
|
104
|
+
})] }) : labelPosition === "end" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
105
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Box_vanilla.BoxVanilla, {
|
|
73
106
|
className: require_Field_vanilla_css.endLabelRow,
|
|
74
107
|
children: [children, labelNode]
|
|
75
|
-
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [labelNode, children] }),
|
|
76
|
-
hasDescription && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Text_vanilla.TextVanilla, {
|
|
77
|
-
as: "p",
|
|
78
|
-
id: context.descriptionId,
|
|
79
|
-
size: "0",
|
|
80
|
-
variant: "subtle",
|
|
81
|
-
css: MESSAGE_CSS,
|
|
82
|
-
children: description
|
|
83
108
|
}),
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
109
|
+
hintNode,
|
|
110
|
+
messages
|
|
111
|
+
] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
112
|
+
labelNode,
|
|
113
|
+
hintNode,
|
|
114
|
+
children,
|
|
115
|
+
messages
|
|
116
|
+
] }), announceError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_VisuallyHidden.VisuallyHidden, {
|
|
117
|
+
"aria-live": "polite",
|
|
118
|
+
children: announcedError
|
|
119
|
+
})]
|
|
90
120
|
})
|
|
91
121
|
});
|
|
92
122
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.vanilla.cjs","names":["useFieldRoot","useAnnouncedError","useVanillaExtractTheme","processCSSProp","React","LabelVanilla","TextVanilla","FieldContext","assignInlineVars","BoxVanilla","
|
|
1
|
+
{"version":3,"file":"Field.vanilla.cjs","names":["useFieldRoot","useAnnouncedError","useVanillaExtractTheme","processCSSProp","React","LabelVanilla","TextVanilla","_Fragment","FieldContext","startRow","assignInlineVars","BoxVanilla","startLabel","startControl","endLabelRow","VisuallyHidden"],"sources":["../../../components/Field/Field.vanilla.tsx"],"sourcesContent":["import { assignInlineVars } from '@vanilla-extract/dynamic';\nimport React from 'react';\n\nimport { CSSProps, processCSSProp } from '../../styles/cssProps';\nimport { useVanillaExtractTheme } from '../../styles/themeContext';\nimport { BoxVanilla } from '../Box';\nimport { LabelVanilla } from '../Label';\nimport { TextVanilla } from '../Text';\nimport { VisuallyHidden } from '../VisuallyHidden';\nimport { endLabelRow, startControl, startLabel, startRow } from './Field.vanilla.css';\nimport { FieldBaseProps, FieldContext, useAnnouncedError, useFieldRoot } from './FieldContext';\n\nexport type FieldVanillaProps = FieldBaseProps & { css?: CSSProps['css'] };\n\nconst MESSAGE_CSS = { display: 'block', m: 0, mt: '$1', lineHeight: 1.4 };\n// The tall line of a label makes room for a control right under it. Before a hint or beside a control, it is a gap.\nconst COMPACT_LABEL_CSS = { lineHeight: 1.4 };\nconst HINT_ABOVE_CONTROL_CSS = { ...MESSAGE_CSS, mb: '$2' };\n\n/**\n * Gives a label, a hint, a description and an error to the one form control inside it.\n * For more than one control, use `group`.\n */\nexport const FieldVanilla = ({\n label,\n hint,\n description,\n error,\n announceError,\n labelPosition = 'top',\n children,\n css,\n ...props\n}: FieldVanillaProps) => {\n const {\n context,\n ids,\n groupProps,\n messageSize,\n labelFor,\n labelVariant,\n hasLabel,\n hasHint,\n hasDescription,\n hasError,\n onFocus,\n onBlur,\n } = useFieldRoot({ label, hint, description, error, ...props });\n const announcedError = useAnnouncedError(\n Boolean(announceError),\n hasError ? ids.errorId : undefined,\n ids.labelId,\n );\n const { colors } = useVanillaExtractTheme();\n const { style: rootStyle, vars: rootVars } = processCSSProp(css, colors);\n\n const labelNode = React.useMemo(() => {\n if (!hasLabel || !ids.labelId) {\n return null;\n }\n if (typeof label === 'function') {\n return label({ variant: labelVariant, htmlFor: labelFor, id: ids.labelId });\n }\n return (\n <LabelVanilla\n variant={labelVariant}\n htmlFor={labelFor}\n id={ids.labelId}\n css={hasHint || labelPosition === 'start' ? COMPACT_LABEL_CSS : undefined}\n >\n {label}\n </LabelVanilla>\n );\n }, [hasLabel, hasHint, label, labelPosition, labelVariant, labelFor, ids.labelId]);\n\n const hintNode = hasHint && (\n <TextVanilla\n as=\"p\"\n id={ids.hintId}\n size={messageSize}\n variant=\"subtle\"\n css={labelPosition === 'top' ? HINT_ABOVE_CONTROL_CSS : MESSAGE_CSS}\n >\n {hint}\n </TextVanilla>\n );\n\n const messages = (\n <>\n {hasDescription && (\n <TextVanilla\n as=\"p\"\n id={ids.descriptionId}\n size={messageSize}\n variant=\"subtle\"\n css={MESSAGE_CSS}\n >\n {description}\n </TextVanilla>\n )}\n {hasError && (\n <TextVanilla as=\"p\" id={ids.errorId} size={messageSize} variant=\"invalid\" css={MESSAGE_CSS}>\n {error}\n </TextVanilla>\n )}\n </>\n );\n\n return (\n <FieldContext.Provider value={context}>\n <div\n className={labelPosition === 'start' ? startRow : undefined}\n style={{ ...rootStyle, ...assignInlineVars(rootVars) }}\n onFocus={onFocus}\n onBlur={onBlur}\n {...groupProps}\n >\n {labelPosition === 'start' ? (\n <>\n <BoxVanilla className={startLabel}>\n {labelNode}\n {hintNode}\n </BoxVanilla>\n <BoxVanilla className={startControl}>\n {children}\n {messages}\n </BoxVanilla>\n </>\n ) : labelPosition === 'end' ? (\n <>\n <BoxVanilla className={endLabelRow}>\n {children}\n {labelNode}\n </BoxVanilla>\n {hintNode}\n {messages}\n </>\n ) : (\n <>\n {labelNode}\n {hintNode}\n {children}\n {messages}\n </>\n )}\n {announceError && <VisuallyHidden aria-live=\"polite\">{announcedError}</VisuallyHidden>}\n </div>\n </FieldContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAM,cAAc;CAAE,SAAS;CAAS,GAAG;CAAG,IAAI;CAAM,YAAY;AAAI;AAExE,IAAM,oBAAoB,EAAE,YAAY,IAAI;AAC5C,IAAM,yBAAyB;CAAE,GAAG;CAAa,IAAI;AAAK;;;;;AAM1D,IAAa,gBAAgB,EAC3B,OACA,MACA,aACA,OACA,eACA,gBAAgB,OAChB,UACA,KACA,GAAG,YACoB;CACvB,MAAM,EACJ,SACA,KACA,YACA,aACA,UACA,cACA,UACA,SACA,gBACA,UACA,SACA,WACEA,qBAAAA,aAAa;EAAE;EAAO;EAAM;EAAa;EAAO,GAAG;CAAM,C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,kBAAA,IAAA,CAACE,qBAAAA,aAAa,UAAd;EAAuB,OAAO;EAC5B,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;GACE,WAAW,kBAAkB,UAAUC,0BAAAA,WAAW,KAAA;GAClD,OAAO;IAAE,GAAG;IAAW,IAAA,GAAGC,yBAAAA,iBAAAA,CAAiB,QAAQ;GAAE;GAC5C;GACD;GACR,GAAI;GALN,UAAA,CAOG,kBAAkB,UACjB,iBAAA,GAAA,kBAAA,KAAA,CAAAH,kBAAAA,UAAA,EAAA,UAAA,CACE,iBAAA,GAAA,kBAAA,KAAA,CAACI,oBAAAA,YAAD;IAAY,WAAWC,0BAAAA;IAAvB,UAAA,CACG,WACA,QACS;GACZ,CAAA,GAAA,iBAAA,GAAA,kBAAA,KAAA,CAACD,oBAAAA,YAAD;IAAY,WAAWE,0BAAAA;IAAvB,UAAA,CACG,UACA,QACS;GACZ,CAAA,CAAA,EAAA,CAAA,IACA,kBAAkB,QACpB,iBAAA,GAAA,kBAAA,KAAA,CAAAN,kBAAAA,UAAA,EAAA,UAAA;IACE,iBAAA,GAAA,kBAAA,KAAA,CAACI,oBAAAA,YAAD;KAAY,WAAWG,0BAAAA;KAAvB,UAAA,CACG,UACA,SACS;;IACX;IACA;GACD,EAAA,CAAA,IAEF,iBAAA,GAAA,kBAAA,KAAA,CAAAP,kBAAAA,UAAA,EAAA,UAAA;IACG;IACA;IACA;IACA;GACD,EAAA,CAAA,GAEH,iBAAiB,iBAAA,GAAA,kBAAA,IAAA,CAACQ,uBAAAA,gBAAD;IAAgB,aAAU;IAAU,UAAA;GAA+B,CAAA,CAClF;;CACgB,CAAA;AAE3B"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
;/* empty css */
|
|
2
2
|
// components/Field/Field.vanilla.css.ts
|
|
3
3
|
var endLabelRow = "qq7v300";
|
|
4
|
+
var startRow = "qq7v301";
|
|
5
|
+
var startLabel = "qq7v302";
|
|
6
|
+
var startControl = "qq7v303";
|
|
4
7
|
exports.endLabelRow = endLabelRow;
|
|
8
|
+
exports.startControl = startControl;
|
|
9
|
+
exports.startLabel = startLabel;
|
|
10
|
+
exports.startRow = startRow;
|
|
5
11
|
|
|
6
12
|
//# sourceMappingURL=Field.vanilla.css.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.vanilla.css.cjs","names":[],"sources":["../../../components/Field/Field.vanilla.css.ts"],"sourcesContent":["import { globalStyle, style } from '@vanilla-extract/css';\n\nimport { tokens } from '../../styles/tokens.css';\n\nexport const endLabelRow = style({\n display: 'flex',\n alignItems: 'center',\n gap: tokens.space['2'],\n});\n\nglobalStyle(`${endLabelRow} > [role=\"switch\"]`, {\n margin: 0,\n});\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"Field.vanilla.css.cjs","names":[],"sources":["../../../components/Field/Field.vanilla.css.ts"],"sourcesContent":["import { globalStyle, style } from '@vanilla-extract/css';\n\nimport { tokens } from '../../styles/tokens.css';\n\nexport const endLabelRow = style({\n display: 'flex',\n alignItems: 'center',\n gap: tokens.space['2'],\n});\n\nglobalStyle(`${endLabelRow} > [role=\"switch\"]`, {\n margin: 0,\n});\n\nexport const startRow = style({\n display: 'flex',\n flexWrap: 'wrap',\n alignItems: 'baseline',\n columnGap: tokens.space['5'],\n rowGap: tokens.space['2'],\n});\n\nexport const startLabel = style({\n flex: '1 1 0',\n minWidth: '10rem',\n});\n\nexport const startControl = style({\n flex: '2 1 0',\n minWidth: '16rem',\n});\n"],"mappings":""}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/* empty css */
|
|
2
2
|
// components/Field/Field.vanilla.css.ts
|
|
3
3
|
var endLabelRow = "qq7v300";
|
|
4
|
-
|
|
4
|
+
var startRow = "qq7v301";
|
|
5
|
+
var startLabel = "qq7v302";
|
|
6
|
+
var startControl = "qq7v303";
|
|
7
|
+
export { endLabelRow, startControl, startLabel, startRow };
|
|
5
8
|
|
|
6
9
|
//# sourceMappingURL=Field.vanilla.css.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.vanilla.css.js","names":[],"sources":["../../../components/Field/Field.vanilla.css.ts"],"sourcesContent":["import { globalStyle, style } from '@vanilla-extract/css';\n\nimport { tokens } from '../../styles/tokens.css';\n\nexport const endLabelRow = style({\n display: 'flex',\n alignItems: 'center',\n gap: tokens.space['2'],\n});\n\nglobalStyle(`${endLabelRow} > [role=\"switch\"]`, {\n margin: 0,\n});\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"Field.vanilla.css.js","names":[],"sources":["../../../components/Field/Field.vanilla.css.ts"],"sourcesContent":["import { globalStyle, style } from '@vanilla-extract/css';\n\nimport { tokens } from '../../styles/tokens.css';\n\nexport const endLabelRow = style({\n display: 'flex',\n alignItems: 'center',\n gap: tokens.space['2'],\n});\n\nglobalStyle(`${endLabelRow} > [role=\"switch\"]`, {\n margin: 0,\n});\n\nexport const startRow = style({\n display: 'flex',\n flexWrap: 'wrap',\n alignItems: 'baseline',\n columnGap: tokens.space['5'],\n rowGap: tokens.space['2'],\n});\n\nexport const startLabel = style({\n flex: '1 1 0',\n minWidth: '10rem',\n});\n\nexport const startControl = style({\n flex: '2 1 0',\n minWidth: '16rem',\n});\n"],"mappings":""}
|