@traefik-labs/faency 13.1.1 → 13.2.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/Checkbox/Checkbox.cjs +15 -2
- package/dist/components/Checkbox/Checkbox.cjs.map +1 -1
- package/dist/components/Checkbox/Checkbox.js +15 -2
- package/dist/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/components/Checkbox/Checkbox.themes.cjs +4 -2
- package/dist/components/Checkbox/Checkbox.themes.cjs.map +1 -1
- package/dist/components/Checkbox/Checkbox.themes.js +4 -2
- package/dist/components/Checkbox/Checkbox.themes.js.map +1 -1
- package/dist/components/DateTimePickerInput/DateTimePickerInput.cjs +1 -1
- package/dist/components/DateTimePickerInput/DateTimePickerInput.cjs.map +1 -1
- package/dist/components/DateTimePickerInput/DateTimePickerInput.js +1 -1
- package/dist/components/DateTimePickerInput/DateTimePickerInput.js.map +1 -1
- package/dist/components/Field/Field.cjs +91 -0
- package/dist/components/Field/Field.cjs.map +1 -0
- package/dist/components/Field/Field.js +89 -0
- package/dist/components/Field/Field.js.map +1 -0
- package/dist/components/Field/Field.vanilla.cjs +95 -0
- package/dist/components/Field/Field.vanilla.cjs.map +1 -0
- package/dist/components/Field/Field.vanilla.css.cjs +6 -0
- package/dist/components/Field/Field.vanilla.css.cjs.map +1 -0
- package/dist/components/Field/Field.vanilla.css.js +6 -0
- package/dist/components/Field/Field.vanilla.css.js.map +1 -0
- package/dist/components/Field/Field.vanilla.js +93 -0
- package/dist/components/Field/Field.vanilla.js.map +1 -0
- package/dist/components/Field/FieldContext.cjs +136 -0
- package/dist/components/Field/FieldContext.cjs.map +1 -0
- package/dist/components/Field/FieldContext.js +130 -0
- package/dist/components/Field/FieldContext.js.map +1 -0
- package/dist/components/Input/Input.cjs +31 -6
- package/dist/components/Input/Input.cjs.map +1 -1
- package/dist/components/Input/Input.js +31 -6
- package/dist/components/Input/Input.js.map +1 -1
- package/dist/components/Input/Input.vanilla.cjs +17 -4
- package/dist/components/Input/Input.vanilla.cjs.map +1 -1
- package/dist/components/Input/Input.vanilla.css.cjs.map +1 -1
- package/dist/components/Input/Input.vanilla.css.js.map +1 -1
- package/dist/components/Input/Input.vanilla.js +17 -4
- package/dist/components/Input/Input.vanilla.js.map +1 -1
- package/dist/components/Radio/Radio.cjs +21 -1
- package/dist/components/Radio/Radio.cjs.map +1 -1
- package/dist/components/Radio/Radio.js +21 -1
- package/dist/components/Radio/Radio.js.map +1 -1
- package/dist/components/Radio/Radio.themes.cjs +4 -2
- package/dist/components/Radio/Radio.themes.cjs.map +1 -1
- package/dist/components/Radio/Radio.themes.js +4 -2
- package/dist/components/Radio/Radio.themes.js.map +1 -1
- package/dist/components/Select/Select.cjs +33 -4
- package/dist/components/Select/Select.cjs.map +1 -1
- package/dist/components/Select/Select.js +33 -4
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Switch/Switch.cjs +19 -5
- package/dist/components/Switch/Switch.cjs.map +1 -1
- package/dist/components/Switch/Switch.js +19 -5
- package/dist/components/Switch/Switch.js.map +1 -1
- package/dist/components/Switch/Switch.themes.cjs +4 -2
- package/dist/components/Switch/Switch.themes.cjs.map +1 -1
- package/dist/components/Switch/Switch.themes.js +4 -2
- package/dist/components/Switch/Switch.themes.js.map +1 -1
- package/dist/components/Text/Text.themes.cjs +2 -2
- package/dist/components/Text/Text.themes.cjs.map +1 -1
- package/dist/components/Text/Text.themes.js +2 -2
- package/dist/components/Text/Text.themes.js.map +1 -1
- package/dist/components/Text/Text.vanilla.cjs +36 -0
- package/dist/components/Text/Text.vanilla.cjs.map +1 -0
- package/dist/components/Text/Text.vanilla.css.cjs +55 -0
- package/dist/components/Text/Text.vanilla.css.cjs.map +1 -0
- package/dist/components/Text/Text.vanilla.css.js +56 -0
- package/dist/components/Text/Text.vanilla.css.js.map +1 -0
- package/dist/components/Text/Text.vanilla.js +36 -0
- package/dist/components/Text/Text.vanilla.js.map +1 -0
- package/dist/components/TextField/TextField.cjs +73 -77
- package/dist/components/TextField/TextField.cjs.map +1 -1
- package/dist/components/TextField/TextField.js +73 -77
- package/dist/components/TextField/TextField.js.map +1 -1
- package/dist/components/TextField/TextField.vanilla.cjs +70 -86
- package/dist/components/TextField/TextField.vanilla.cjs.map +1 -1
- package/dist/components/TextField/TextField.vanilla.css.cjs +10 -0
- package/dist/components/TextField/TextField.vanilla.css.cjs.map +1 -0
- package/dist/components/TextField/TextField.vanilla.css.js +8 -0
- package/dist/components/TextField/TextField.vanilla.css.js.map +1 -0
- package/dist/components/TextField/TextField.vanilla.js +71 -87
- package/dist/components/TextField/TextField.vanilla.js.map +1 -1
- package/dist/components/Textarea/Textarea.cjs +51 -41
- package/dist/components/Textarea/Textarea.cjs.map +1 -1
- package/dist/components/Textarea/Textarea.js +51 -41
- package/dist/components/Textarea/Textarea.js.map +1 -1
- package/dist/components/Textarea/Textarea.vanilla.cjs +49 -49
- package/dist/components/Textarea/Textarea.vanilla.cjs.map +1 -1
- package/dist/components/Textarea/Textarea.vanilla.css.cjs.map +1 -1
- package/dist/components/Textarea/Textarea.vanilla.css.js.map +1 -1
- package/dist/components/Textarea/Textarea.vanilla.js +49 -49
- package/dist/components/Textarea/Textarea.vanilla.js.map +1 -1
- package/dist/faency.css +170 -14
- package/dist/index.cjs +7 -1
- package/dist/index.d.ts +375 -0
- package/dist/index.js +5 -2
- package/dist/styles/themes.css.cjs.map +1 -1
- package/dist/styles/themes.css.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Field.vanilla.cjs","names":["useFieldRoot","useAnnouncedError","useVanillaExtractTheme","processCSSProp","React","LabelVanilla","TextVanilla","FieldContext","assignInlineVars","BoxVanilla","endLabelRow","_Fragment","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 } 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' };\n\n/**\n * Gives a label, a description and an error to the one form control inside it.\n * Its label connects to one control, so do not put two controls in one Field.\n */\nexport const FieldVanilla = ({\n label,\n description,\n error,\n announceError,\n labelPosition = 'top',\n children,\n css,\n ...props\n}: FieldVanillaProps) => {\n const { context, labelFor, labelVariant, hasLabel, hasDescription, hasError, onFocus, onBlur } =\n useFieldRoot({ label, description, error, ...props });\n const announcedError = useAnnouncedError(\n Boolean(announceError),\n hasError ? context.errorId : undefined,\n context.labelId,\n );\n const { colors } = useVanillaExtractTheme();\n const { style: rootStyle, vars: rootVars } = processCSSProp(css, colors);\n\n const labelNode = React.useMemo(() => {\n if (!hasLabel || !context.labelId) {\n return null;\n }\n if (typeof label === 'function') {\n return label({ variant: labelVariant, htmlFor: labelFor, id: context.labelId });\n }\n return (\n <LabelVanilla variant={labelVariant} htmlFor={labelFor} id={context.labelId}>\n {label}\n </LabelVanilla>\n );\n }, [hasLabel, label, labelVariant, labelFor, context.labelId]);\n\n const errorNode = hasError && (\n <TextVanilla as=\"p\" id={context.errorId} size=\"0\" variant=\"invalid\" css={MESSAGE_CSS}>\n {error}\n </TextVanilla>\n );\n\n return (\n <FieldContext.Provider value={context}>\n <div\n style={{ ...rootStyle, ...assignInlineVars(rootVars) }}\n onFocus={onFocus}\n onBlur={onBlur}\n >\n {labelPosition === 'end' ? (\n <BoxVanilla className={endLabelRow}>\n {children}\n {labelNode}\n </BoxVanilla>\n ) : (\n <>\n {labelNode}\n {children}\n </>\n )}\n {hasDescription && (\n <TextVanilla\n as=\"p\"\n id={context.descriptionId}\n size=\"0\"\n variant=\"subtle\"\n css={MESSAGE_CSS}\n >\n {description}\n </TextVanilla>\n )}\n {errorNode}\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;AAAK;;;;;AAMvD,IAAa,gBAAgB,EAC3B,OACA,aACA,OACA,eACA,gBAAgB,OAChB,UACA,KACA,GAAG,YACoB;CACvB,MAAM,EAAE,SAAS,UAAU,cAAc,UAAU,gBAAgB,UAAU,SAAS,WACpFA,qBAAAA,aAAa;EAAE;EAAO;EAAa;EAAO,GAAG;CAAM,CAAC;CACtD,MAAM,iBAAiBC,qBAAAA,kBACrB,QAAQ,aAAa,GACrB,WAAW,QAAQ,UAAU,KAAA,GAC7B,QAAQ,OACV;CACA,MAAM,EAAE,WAAWC,qBAAAA,uBAAuB;CAC1C,MAAM,EAAE,OAAO,WAAW,MAAM,aAAaC,iBAAAA,eAAe,KAAK,MAAM;CAEvE,MAAM,YAAYC,MAAAA,QAAM,cAAc;EACpC,IAAI,CAAC,YAAY,CAAC,QAAQ,SACxB,OAAO;EAET,IAAI,OAAO,UAAU,YACnB,OAAO,MAAM;GAAE,SAAS;GAAc,SAAS;GAAU,IAAI,QAAQ;EAAQ,CAAC;EAEhF,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,cAAD;GAAc,SAAS;GAAc,SAAS;GAAU,IAAI,QAAQ;GACjE,UAAA;EACW,CAAA;CAElB,GAAG;EAAC;EAAU;EAAO;EAAc;EAAU,QAAQ;CAAO,CAAC;CAE7D,MAAM,YAAY,YAChB,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,aAAD;EAAa,IAAG;EAAI,IAAI,QAAQ;EAAS,MAAK;EAAI,SAAQ;EAAU,KAAK;EACtE,UAAA;CACU,CAAA;CAGf,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,aAAa,UAAd;EAAuB,OAAO;EAC5B,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;GACE,OAAO;IAAE,GAAG;IAAW,IAAA,GAAGC,yBAAAA,iBAAAA,CAAiB,QAAQ;GAAE;GAC5C;GACD;GAHV,UAAA;IAKG,kBAAkB,QACjB,iBAAA,GAAA,kBAAA,KAAA,CAACC,oBAAAA,YAAD;KAAY,WAAWC,0BAAAA;KAAvB,UAAA,CACG,UACA,SACS;IAEZ,CAAA,IAAA,iBAAA,GAAA,kBAAA,KAAA,CAAAC,kBAAAA,UAAA,EAAA,UAAA,CACG,WACA,QACD,EAAA,CAAA;IAEH,kBACC,iBAAA,GAAA,kBAAA,IAAA,CAACL,qBAAAA,aAAD;KACE,IAAG;KACH,IAAI,QAAQ;KACZ,MAAK;KACL,SAAQ;KACR,KAAK;KAEJ,UAAA;IACU,CAAA;IAEd;IACA,iBAAiB,iBAAA,GAAA,kBAAA,IAAA,CAACM,uBAAAA,gBAAD;KAAgB,aAAU;KAAU,UAAA;IAA+B,CAAA;GAClF;;CACgB,CAAA;AAE3B"}
|
|
@@ -0,0 +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":""}
|
|
@@ -0,0 +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":""}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { processCSSProp } from "../../styles/cssProps.js";
|
|
2
|
+
import { useVanillaExtractTheme } from "../../styles/themeContext.js";
|
|
3
|
+
import { BoxVanilla } from "../Box/Box.vanilla.js";
|
|
4
|
+
import { TextVanilla } from "../Text/Text.vanilla.js";
|
|
5
|
+
import { LabelVanilla } from "../Label/Label.vanilla.js";
|
|
6
|
+
import { FieldContext, useAnnouncedError, useFieldRoot } from "./FieldContext.js";
|
|
7
|
+
import { VisuallyHidden } from "../VisuallyHidden/VisuallyHidden.js";
|
|
8
|
+
import { endLabelRow } from "./Field.vanilla.css.js";
|
|
9
|
+
import React from "react";
|
|
10
|
+
import { assignInlineVars } from "@vanilla-extract/dynamic";
|
|
11
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
// components/Field/Field.vanilla.tsx
|
|
13
|
+
var MESSAGE_CSS = {
|
|
14
|
+
display: "block",
|
|
15
|
+
m: 0,
|
|
16
|
+
mt: "$1"
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Gives a label, a description and an error to the one form control inside it.
|
|
20
|
+
* Its label connects to one control, so do not put two controls in one Field.
|
|
21
|
+
*/
|
|
22
|
+
var FieldVanilla = ({ label, description, error, announceError, labelPosition = "top", children, css, ...props }) => {
|
|
23
|
+
const { context, labelFor, labelVariant, hasLabel, hasDescription, hasError, onFocus, onBlur } = useFieldRoot({
|
|
24
|
+
label,
|
|
25
|
+
description,
|
|
26
|
+
error,
|
|
27
|
+
...props
|
|
28
|
+
});
|
|
29
|
+
const announcedError = useAnnouncedError(Boolean(announceError), hasError ? context.errorId : void 0, context.labelId);
|
|
30
|
+
const { colors } = useVanillaExtractTheme();
|
|
31
|
+
const { style: rootStyle, vars: rootVars } = processCSSProp(css, colors);
|
|
32
|
+
const labelNode = React.useMemo(() => {
|
|
33
|
+
if (!hasLabel || !context.labelId) return null;
|
|
34
|
+
if (typeof label === "function") return label({
|
|
35
|
+
variant: labelVariant,
|
|
36
|
+
htmlFor: labelFor,
|
|
37
|
+
id: context.labelId
|
|
38
|
+
});
|
|
39
|
+
return /* @__PURE__ */ jsx(LabelVanilla, {
|
|
40
|
+
variant: labelVariant,
|
|
41
|
+
htmlFor: labelFor,
|
|
42
|
+
id: context.labelId,
|
|
43
|
+
children: label
|
|
44
|
+
});
|
|
45
|
+
}, [
|
|
46
|
+
hasLabel,
|
|
47
|
+
label,
|
|
48
|
+
labelVariant,
|
|
49
|
+
labelFor,
|
|
50
|
+
context.labelId
|
|
51
|
+
]);
|
|
52
|
+
const errorNode = hasError && /* @__PURE__ */ jsx(TextVanilla, {
|
|
53
|
+
as: "p",
|
|
54
|
+
id: context.errorId,
|
|
55
|
+
size: "0",
|
|
56
|
+
variant: "invalid",
|
|
57
|
+
css: MESSAGE_CSS,
|
|
58
|
+
children: error
|
|
59
|
+
});
|
|
60
|
+
return /* @__PURE__ */ jsx(FieldContext.Provider, {
|
|
61
|
+
value: context,
|
|
62
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
63
|
+
style: {
|
|
64
|
+
...rootStyle,
|
|
65
|
+
...assignInlineVars(rootVars)
|
|
66
|
+
},
|
|
67
|
+
onFocus,
|
|
68
|
+
onBlur,
|
|
69
|
+
children: [
|
|
70
|
+
labelPosition === "end" ? /* @__PURE__ */ jsxs(BoxVanilla, {
|
|
71
|
+
className: endLabelRow,
|
|
72
|
+
children: [children, labelNode]
|
|
73
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [labelNode, children] }),
|
|
74
|
+
hasDescription && /* @__PURE__ */ jsx(TextVanilla, {
|
|
75
|
+
as: "p",
|
|
76
|
+
id: context.descriptionId,
|
|
77
|
+
size: "0",
|
|
78
|
+
variant: "subtle",
|
|
79
|
+
css: MESSAGE_CSS,
|
|
80
|
+
children: description
|
|
81
|
+
}),
|
|
82
|
+
errorNode,
|
|
83
|
+
announceError && /* @__PURE__ */ jsx(VisuallyHidden, {
|
|
84
|
+
"aria-live": "polite",
|
|
85
|
+
children: announcedError
|
|
86
|
+
})
|
|
87
|
+
]
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
export { FieldVanilla };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=Field.vanilla.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Field.vanilla.js","names":["_Fragment"],"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 } 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' };\n\n/**\n * Gives a label, a description and an error to the one form control inside it.\n * Its label connects to one control, so do not put two controls in one Field.\n */\nexport const FieldVanilla = ({\n label,\n description,\n error,\n announceError,\n labelPosition = 'top',\n children,\n css,\n ...props\n}: FieldVanillaProps) => {\n const { context, labelFor, labelVariant, hasLabel, hasDescription, hasError, onFocus, onBlur } =\n useFieldRoot({ label, description, error, ...props });\n const announcedError = useAnnouncedError(\n Boolean(announceError),\n hasError ? context.errorId : undefined,\n context.labelId,\n );\n const { colors } = useVanillaExtractTheme();\n const { style: rootStyle, vars: rootVars } = processCSSProp(css, colors);\n\n const labelNode = React.useMemo(() => {\n if (!hasLabel || !context.labelId) {\n return null;\n }\n if (typeof label === 'function') {\n return label({ variant: labelVariant, htmlFor: labelFor, id: context.labelId });\n }\n return (\n <LabelVanilla variant={labelVariant} htmlFor={labelFor} id={context.labelId}>\n {label}\n </LabelVanilla>\n );\n }, [hasLabel, label, labelVariant, labelFor, context.labelId]);\n\n const errorNode = hasError && (\n <TextVanilla as=\"p\" id={context.errorId} size=\"0\" variant=\"invalid\" css={MESSAGE_CSS}>\n {error}\n </TextVanilla>\n );\n\n return (\n <FieldContext.Provider value={context}>\n <div\n style={{ ...rootStyle, ...assignInlineVars(rootVars) }}\n onFocus={onFocus}\n onBlur={onBlur}\n >\n {labelPosition === 'end' ? (\n <BoxVanilla className={endLabelRow}>\n {children}\n {labelNode}\n </BoxVanilla>\n ) : (\n <>\n {labelNode}\n {children}\n </>\n )}\n {hasDescription && (\n <TextVanilla\n as=\"p\"\n id={context.descriptionId}\n size=\"0\"\n variant=\"subtle\"\n css={MESSAGE_CSS}\n >\n {description}\n </TextVanilla>\n )}\n {errorNode}\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;AAAK;;;;;AAMvD,IAAa,gBAAgB,EAC3B,OACA,aACA,OACA,eACA,gBAAgB,OAChB,UACA,KACA,GAAG,YACoB;CACvB,MAAM,EAAE,SAAS,UAAU,cAAc,UAAU,gBAAgB,UAAU,SAAS,WACpF,aAAa;EAAE;EAAO;EAAa;EAAO,GAAG;CAAM,CAAC;CACtD,MAAM,iBAAiB,kBACrB,QAAQ,aAAa,GACrB,WAAW,QAAQ,UAAU,KAAA,GAC7B,QAAQ,OACV;CACA,MAAM,EAAE,WAAW,uBAAuB;CAC1C,MAAM,EAAE,OAAO,WAAW,MAAM,aAAa,eAAe,KAAK,MAAM;CAEvE,MAAM,YAAY,MAAM,cAAc;EACpC,IAAI,CAAC,YAAY,CAAC,QAAQ,SACxB,OAAO;EAET,IAAI,OAAO,UAAU,YACnB,OAAO,MAAM;GAAE,SAAS;GAAc,SAAS;GAAU,IAAI,QAAQ;EAAQ,CAAC;EAEhF,OACE,oBAAC,cAAD;GAAc,SAAS;GAAc,SAAS;GAAU,IAAI,QAAQ;GACjE,UAAA;EACW,CAAA;CAElB,GAAG;EAAC;EAAU;EAAO;EAAc;EAAU,QAAQ;CAAO,CAAC;CAE7D,MAAM,YAAY,YAChB,oBAAC,aAAD;EAAa,IAAG;EAAI,IAAI,QAAQ;EAAS,MAAK;EAAI,SAAQ;EAAU,KAAK;EACtE,UAAA;CACU,CAAA;CAGf,OACE,oBAAC,aAAa,UAAd;EAAuB,OAAO;EAC5B,UAAA,qBAAC,OAAD;GACE,OAAO;IAAE,GAAG;IAAW,GAAG,iBAAiB,QAAQ;GAAE;GAC5C;GACD;GAHV,UAAA;IAKG,kBAAkB,QACjB,qBAAC,YAAD;KAAY,WAAW;KAAvB,UAAA,CACG,UACA,SACS;IAEZ,CAAA,IAAA,qBAAAA,UAAA,EAAA,UAAA,CACG,WACA,QACD,EAAA,CAAA;IAEH,kBACC,oBAAC,aAAD;KACE,IAAG;KACH,IAAI,QAAQ;KACZ,MAAK;KACL,SAAQ;KACR,KAAK;KAEJ,UAAA;IACU,CAAA;IAEd;IACA,iBAAiB,oBAAC,gBAAD;KAAgB,aAAU;KAAU,UAAA;IAA+B,CAAA;GAClF;;CACgB,CAAA;AAE3B"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let react = require("react");
|
|
3
|
+
react = require_runtime.__toESM(react, 1);
|
|
4
|
+
// components/Field/FieldContext.ts
|
|
5
|
+
var FieldContext = react.default.createContext(null);
|
|
6
|
+
var useFieldContext = () => react.default.useContext(FieldContext);
|
|
7
|
+
var hasContent = (node) => node !== void 0 && node !== null && node !== false && node !== "";
|
|
8
|
+
var useFieldRoot = ({ id, label, description, error, invalid, disabled }) => {
|
|
9
|
+
const outerContext = useFieldContext();
|
|
10
|
+
const generatedId = react.default.useId();
|
|
11
|
+
const hasLabel = typeof label === "function" || hasContent(label);
|
|
12
|
+
const hasDescription = hasContent(description);
|
|
13
|
+
const hasError = hasContent(error);
|
|
14
|
+
const isInvalid = Boolean(invalid) || hasError;
|
|
15
|
+
const [control, setControl] = react.default.useState(null);
|
|
16
|
+
const registerControl = react.default.useCallback((next) => {
|
|
17
|
+
setControl((prev) => prev?.id === next?.id && prev?.disabled === next?.disabled && prev?.invalid === next?.invalid && prev?.labelable === next?.labelable ? prev : next);
|
|
18
|
+
}, []);
|
|
19
|
+
const controlId = control?.id ?? id ?? (hasLabel ? `${generatedId}-control` : void 0);
|
|
20
|
+
const labelFor = control?.labelable === false ? void 0 : controlId;
|
|
21
|
+
const [hasFocus, setHasFocus] = react.default.useState(false);
|
|
22
|
+
const onFocus = react.default.useCallback(() => setHasFocus(true), []);
|
|
23
|
+
const onBlur = react.default.useCallback(() => setHasFocus(false), []);
|
|
24
|
+
const labelVariant = react.default.useMemo(() => {
|
|
25
|
+
if (disabled || control?.disabled) return "subtle";
|
|
26
|
+
if (isInvalid || control?.invalid) return "invalid";
|
|
27
|
+
if (hasFocus) return "contrast";
|
|
28
|
+
return "default";
|
|
29
|
+
}, [
|
|
30
|
+
disabled,
|
|
31
|
+
isInvalid,
|
|
32
|
+
hasFocus,
|
|
33
|
+
control?.disabled,
|
|
34
|
+
control?.invalid
|
|
35
|
+
]);
|
|
36
|
+
const ownContext = react.default.useMemo(() => ({
|
|
37
|
+
controlId,
|
|
38
|
+
labelId: hasLabel ? `${generatedId}-label` : void 0,
|
|
39
|
+
descriptionId: hasDescription ? `${generatedId}-description` : void 0,
|
|
40
|
+
errorId: hasError ? `${generatedId}-error` : void 0,
|
|
41
|
+
invalid: isInvalid,
|
|
42
|
+
disabled: Boolean(disabled),
|
|
43
|
+
registerControl
|
|
44
|
+
}), [
|
|
45
|
+
controlId,
|
|
46
|
+
generatedId,
|
|
47
|
+
hasLabel,
|
|
48
|
+
hasDescription,
|
|
49
|
+
hasError,
|
|
50
|
+
isInvalid,
|
|
51
|
+
disabled,
|
|
52
|
+
registerControl
|
|
53
|
+
]);
|
|
54
|
+
return {
|
|
55
|
+
context: outerContext && !hasLabel && !hasDescription && !hasError ? outerContext : ownContext,
|
|
56
|
+
labelFor,
|
|
57
|
+
labelVariant,
|
|
58
|
+
hasLabel,
|
|
59
|
+
hasDescription,
|
|
60
|
+
hasError,
|
|
61
|
+
onFocus,
|
|
62
|
+
onBlur
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Gives a form control the id, `aria-describedby`, `aria-invalid` and `disabled` of the `Field` around it,
|
|
67
|
+
* and gives its own id, `disabled` and invalid state to that `Field`.
|
|
68
|
+
* Outside a `Field`, it only sets `aria-invalid` from `invalid`.
|
|
69
|
+
*/
|
|
70
|
+
var useFieldControl = ({ id, invalid, disabled, "aria-describedby": describedBy, "aria-invalid": ariaInvalid, labelable = true }) => {
|
|
71
|
+
const field = useFieldContext();
|
|
72
|
+
const ownInvalid = Boolean(invalid || ariaInvalid === true || ariaInvalid === "true");
|
|
73
|
+
const isInvalid = ownInvalid || Boolean(field?.invalid);
|
|
74
|
+
const registerControl = field?.registerControl;
|
|
75
|
+
react.default.useEffect(() => {
|
|
76
|
+
if (!registerControl) return;
|
|
77
|
+
registerControl({
|
|
78
|
+
id,
|
|
79
|
+
disabled: Boolean(disabled),
|
|
80
|
+
invalid: ownInvalid,
|
|
81
|
+
labelable
|
|
82
|
+
});
|
|
83
|
+
return () => registerControl(null);
|
|
84
|
+
}, [
|
|
85
|
+
registerControl,
|
|
86
|
+
id,
|
|
87
|
+
disabled,
|
|
88
|
+
ownInvalid,
|
|
89
|
+
labelable
|
|
90
|
+
]);
|
|
91
|
+
const describedByIds = [
|
|
92
|
+
field?.errorId,
|
|
93
|
+
field?.descriptionId,
|
|
94
|
+
describedBy
|
|
95
|
+
].filter(Boolean).join(" ") || void 0;
|
|
96
|
+
return {
|
|
97
|
+
id: id ?? field?.controlId,
|
|
98
|
+
labelId: field?.labelId,
|
|
99
|
+
invalid: isInvalid,
|
|
100
|
+
disabled: disabled || field?.disabled || void 0,
|
|
101
|
+
"aria-describedby": describedByIds,
|
|
102
|
+
"aria-invalid": isInvalid ? true : ariaInvalid
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
var ANNOUNCE_DELAY = 1e3;
|
|
106
|
+
/**
|
|
107
|
+
* Returns the text of the error, after the text of the label when there is one, once it has not
|
|
108
|
+
* changed for a short time, so that a screen reader reads it after the echo of the typed text.
|
|
109
|
+
*/
|
|
110
|
+
var useAnnouncedError = (enabled, errorId, labelId) => {
|
|
111
|
+
const [announcedError, setAnnouncedError] = react.default.useState(null);
|
|
112
|
+
const lastTextRef = react.default.useRef(void 0);
|
|
113
|
+
const timeoutRef = react.default.useRef();
|
|
114
|
+
react.default.useEffect(() => {
|
|
115
|
+
const text = enabled && errorId && document.getElementById(errorId)?.textContent?.trim() || null;
|
|
116
|
+
if (text === lastTextRef.current) return;
|
|
117
|
+
lastTextRef.current = text;
|
|
118
|
+
clearTimeout(timeoutRef.current);
|
|
119
|
+
timeoutRef.current = setTimeout(() => {
|
|
120
|
+
const fieldName = labelId ? document.getElementById(labelId)?.textContent?.trim() : void 0;
|
|
121
|
+
setAnnouncedError(text !== null && fieldName ? `${fieldName}: ${text}` : text);
|
|
122
|
+
}, text === null ? 0 : ANNOUNCE_DELAY);
|
|
123
|
+
});
|
|
124
|
+
react.default.useEffect(() => () => {
|
|
125
|
+
clearTimeout(timeoutRef.current);
|
|
126
|
+
lastTextRef.current = void 0;
|
|
127
|
+
}, []);
|
|
128
|
+
return announcedError;
|
|
129
|
+
};
|
|
130
|
+
exports.FieldContext = FieldContext;
|
|
131
|
+
exports.useAnnouncedError = useAnnouncedError;
|
|
132
|
+
exports.useFieldContext = useFieldContext;
|
|
133
|
+
exports.useFieldControl = useFieldControl;
|
|
134
|
+
exports.useFieldRoot = useFieldRoot;
|
|
135
|
+
|
|
136
|
+
//# sourceMappingURL=FieldContext.cjs.map
|
|
@@ -0,0 +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,QAAM,cAAwC,IAAI;AAE9E,IAAa,wBAAwBA,MAAAA,QAAM,WAAW,YAAY;AAgClE,IAAM,cAAc,SAClB,SAAS,KAAA,KAAa,SAAS,QAAQ,SAAS,SAA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AM,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"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
// components/Field/FieldContext.ts
|
|
3
|
+
var FieldContext = React.createContext(null);
|
|
4
|
+
var useFieldContext = () => React.useContext(FieldContext);
|
|
5
|
+
var hasContent = (node) => node !== void 0 && node !== null && node !== false && node !== "";
|
|
6
|
+
var useFieldRoot = ({ id, label, description, error, invalid, disabled }) => {
|
|
7
|
+
const outerContext = useFieldContext();
|
|
8
|
+
const generatedId = React.useId();
|
|
9
|
+
const hasLabel = typeof label === "function" || hasContent(label);
|
|
10
|
+
const hasDescription = hasContent(description);
|
|
11
|
+
const hasError = hasContent(error);
|
|
12
|
+
const isInvalid = Boolean(invalid) || hasError;
|
|
13
|
+
const [control, setControl] = React.useState(null);
|
|
14
|
+
const registerControl = React.useCallback((next) => {
|
|
15
|
+
setControl((prev) => prev?.id === next?.id && prev?.disabled === next?.disabled && prev?.invalid === next?.invalid && prev?.labelable === next?.labelable ? prev : next);
|
|
16
|
+
}, []);
|
|
17
|
+
const controlId = control?.id ?? id ?? (hasLabel ? `${generatedId}-control` : void 0);
|
|
18
|
+
const labelFor = control?.labelable === false ? void 0 : controlId;
|
|
19
|
+
const [hasFocus, setHasFocus] = React.useState(false);
|
|
20
|
+
const onFocus = React.useCallback(() => setHasFocus(true), []);
|
|
21
|
+
const onBlur = React.useCallback(() => setHasFocus(false), []);
|
|
22
|
+
const labelVariant = React.useMemo(() => {
|
|
23
|
+
if (disabled || control?.disabled) return "subtle";
|
|
24
|
+
if (isInvalid || control?.invalid) return "invalid";
|
|
25
|
+
if (hasFocus) return "contrast";
|
|
26
|
+
return "default";
|
|
27
|
+
}, [
|
|
28
|
+
disabled,
|
|
29
|
+
isInvalid,
|
|
30
|
+
hasFocus,
|
|
31
|
+
control?.disabled,
|
|
32
|
+
control?.invalid
|
|
33
|
+
]);
|
|
34
|
+
const ownContext = React.useMemo(() => ({
|
|
35
|
+
controlId,
|
|
36
|
+
labelId: hasLabel ? `${generatedId}-label` : void 0,
|
|
37
|
+
descriptionId: hasDescription ? `${generatedId}-description` : void 0,
|
|
38
|
+
errorId: hasError ? `${generatedId}-error` : void 0,
|
|
39
|
+
invalid: isInvalid,
|
|
40
|
+
disabled: Boolean(disabled),
|
|
41
|
+
registerControl
|
|
42
|
+
}), [
|
|
43
|
+
controlId,
|
|
44
|
+
generatedId,
|
|
45
|
+
hasLabel,
|
|
46
|
+
hasDescription,
|
|
47
|
+
hasError,
|
|
48
|
+
isInvalid,
|
|
49
|
+
disabled,
|
|
50
|
+
registerControl
|
|
51
|
+
]);
|
|
52
|
+
return {
|
|
53
|
+
context: outerContext && !hasLabel && !hasDescription && !hasError ? outerContext : ownContext,
|
|
54
|
+
labelFor,
|
|
55
|
+
labelVariant,
|
|
56
|
+
hasLabel,
|
|
57
|
+
hasDescription,
|
|
58
|
+
hasError,
|
|
59
|
+
onFocus,
|
|
60
|
+
onBlur
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Gives a form control the id, `aria-describedby`, `aria-invalid` and `disabled` of the `Field` around it,
|
|
65
|
+
* and gives its own id, `disabled` and invalid state to that `Field`.
|
|
66
|
+
* Outside a `Field`, it only sets `aria-invalid` from `invalid`.
|
|
67
|
+
*/
|
|
68
|
+
var useFieldControl = ({ id, invalid, disabled, "aria-describedby": describedBy, "aria-invalid": ariaInvalid, labelable = true }) => {
|
|
69
|
+
const field = useFieldContext();
|
|
70
|
+
const ownInvalid = Boolean(invalid || ariaInvalid === true || ariaInvalid === "true");
|
|
71
|
+
const isInvalid = ownInvalid || Boolean(field?.invalid);
|
|
72
|
+
const registerControl = field?.registerControl;
|
|
73
|
+
React.useEffect(() => {
|
|
74
|
+
if (!registerControl) return;
|
|
75
|
+
registerControl({
|
|
76
|
+
id,
|
|
77
|
+
disabled: Boolean(disabled),
|
|
78
|
+
invalid: ownInvalid,
|
|
79
|
+
labelable
|
|
80
|
+
});
|
|
81
|
+
return () => registerControl(null);
|
|
82
|
+
}, [
|
|
83
|
+
registerControl,
|
|
84
|
+
id,
|
|
85
|
+
disabled,
|
|
86
|
+
ownInvalid,
|
|
87
|
+
labelable
|
|
88
|
+
]);
|
|
89
|
+
const describedByIds = [
|
|
90
|
+
field?.errorId,
|
|
91
|
+
field?.descriptionId,
|
|
92
|
+
describedBy
|
|
93
|
+
].filter(Boolean).join(" ") || void 0;
|
|
94
|
+
return {
|
|
95
|
+
id: id ?? field?.controlId,
|
|
96
|
+
labelId: field?.labelId,
|
|
97
|
+
invalid: isInvalid,
|
|
98
|
+
disabled: disabled || field?.disabled || void 0,
|
|
99
|
+
"aria-describedby": describedByIds,
|
|
100
|
+
"aria-invalid": isInvalid ? true : ariaInvalid
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
var ANNOUNCE_DELAY = 1e3;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the text of the error, after the text of the label when there is one, once it has not
|
|
106
|
+
* changed for a short time, so that a screen reader reads it after the echo of the typed text.
|
|
107
|
+
*/
|
|
108
|
+
var useAnnouncedError = (enabled, errorId, labelId) => {
|
|
109
|
+
const [announcedError, setAnnouncedError] = React.useState(null);
|
|
110
|
+
const lastTextRef = React.useRef(void 0);
|
|
111
|
+
const timeoutRef = React.useRef();
|
|
112
|
+
React.useEffect(() => {
|
|
113
|
+
const text = enabled && errorId && document.getElementById(errorId)?.textContent?.trim() || null;
|
|
114
|
+
if (text === lastTextRef.current) return;
|
|
115
|
+
lastTextRef.current = text;
|
|
116
|
+
clearTimeout(timeoutRef.current);
|
|
117
|
+
timeoutRef.current = setTimeout(() => {
|
|
118
|
+
const fieldName = labelId ? document.getElementById(labelId)?.textContent?.trim() : void 0;
|
|
119
|
+
setAnnouncedError(text !== null && fieldName ? `${fieldName}: ${text}` : text);
|
|
120
|
+
}, text === null ? 0 : ANNOUNCE_DELAY);
|
|
121
|
+
});
|
|
122
|
+
React.useEffect(() => () => {
|
|
123
|
+
clearTimeout(timeoutRef.current);
|
|
124
|
+
lastTextRef.current = void 0;
|
|
125
|
+
}, []);
|
|
126
|
+
return announcedError;
|
|
127
|
+
};
|
|
128
|
+
export { FieldContext, useAnnouncedError, useFieldContext, useFieldControl, useFieldRoot };
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=FieldContext.js.map
|
|
@@ -0,0 +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,WAAW;CAC7C,MAAM,WAAW,WAAW,KAAK;CACjC,MAAM,YAAY,QAAQ,OAAO,KAAK;CAEtC,MAAM,CAAC,SAAS,cAAc,MAAM,SAAmC,IAAI;CAC3E,MAAM,kBAAkB,MAAM,aAAa,SAAmC;EAC5E,YAAY,SACV,MAAM,OAAO,MAAM,MACnB,MAAM,aAAa,MAAM,YACzB,MAAM,YAAY,MAAM,WACxB,MAAM,cAAc,MAAM,YACtB,OACA,IACN;CACF,GAAG,CAAC,CAAC;CACL,MAAM,YAAY,SAAS,MAAM,OAAO,WAAW,GAAG,YAAY,YAAY,KAAA;CAC9E,MAAM,WAAW,SAAS,cAAc,QAAQ,KAAA,IAAY;CAE5D,MAAM,CAAC,UAAU,eAAe,MAAM,SAAS,KAAK;CACpD,MAAM,UAAU,MAAM,kBAAk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AAO,CAAC,CAAC,KAAK,GAAG,KAAK,KAAA;CAEnF,OAAO;EACL,IAAI,MAAM,OAAO;EACjB,SAAS,OAAO;EAChB,SAAS;EACT,UAAU,YAAY,OAAO,YAAY,KAAA;EACzC,oBAAoB;EACpB,gBAAgB,YAAY,OAAO;CACrC;AACF;AAEA,IAAM,iBAAiB;;;;;AAMvB,IAAa,qBAAqB,SAAkB,SAAkB,YAAqB;CACzF,MAAM,CAAC,gBAAgB,qBAAqB,MAAM,SAAwB,IAAI;CAC9E,MAAM,cAAc,MAAM,OAAkC,KAAA,CAAS;CACrE,MAAM,aAAa,MAAM,OAAsC;CAG/D,MAAM,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,MAAM,sBACQ;EACV,aAAa,WAAW,OAAO;EAC/B,YAAY,UAAU,KAAA;CACxB,GACA,CAAC,CACH;CAEA,OAAO;AACT"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_stitches_config = require("../../stitches.config.cjs");
|
|
3
3
|
const require_Elevation = require("../Elevation/Elevation.cjs");
|
|
4
|
+
const require_FieldContext = require("../Field/FieldContext.cjs");
|
|
4
5
|
let react = require("react");
|
|
5
6
|
react = require_runtime.__toESM(react, 1);
|
|
6
7
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -24,12 +25,16 @@ var StyledInput = require_stitches_config.styled("input", {
|
|
|
24
25
|
fontVariantNumeric: "tabular-nums",
|
|
25
26
|
transition: "box-shadow .1s ease-in-out",
|
|
26
27
|
"&[type=\"number\"]": { pr: "0" },
|
|
27
|
-
"&:-webkit-autofill,&:autofill": {
|
|
28
|
+
"&:-webkit-autofill,&:autofill": {
|
|
29
|
+
boxShadow: "inset 0 0 0 1px $colors$inputBorder, inset 0 0 0 100px $colors$inputBg",
|
|
30
|
+
WebkitTextFillColor: "$colors$hiContrast"
|
|
31
|
+
},
|
|
28
32
|
"&:-webkit-autofill::first-line,&:autofill::first-line": {
|
|
29
33
|
fontFamily: "$rubik",
|
|
30
34
|
color: "$hiContrast"
|
|
31
35
|
},
|
|
32
36
|
"&:focus-visible": { boxShadow: `inset 0 0 0 2px $colors$inputFocusBorder, ${FOCUS_SHADOW}` },
|
|
37
|
+
"&:-webkit-autofill:focus-visible,&:autofill:focus-visible": { boxShadow: `inset 0 0 0 2px $colors$inputFocusBorder, inset 0 0 0 100px $colors$inputBg, ${FOCUS_SHADOW}` },
|
|
33
38
|
"&::placeholder": { color: "$inputPlaceholder" },
|
|
34
39
|
"&:read-only:not(:disabled)": { boxShadow: "none" },
|
|
35
40
|
"&:disabled": {
|
|
@@ -70,7 +75,9 @@ var StyledInput = require_stitches_config.styled("input", {
|
|
|
70
75
|
} },
|
|
71
76
|
state: { invalid: {
|
|
72
77
|
boxShadow: "inset 0 0 0 1px $colors$inputInvalidBorder",
|
|
73
|
-
"
|
|
78
|
+
"&:-webkit-autofill,&:autofill": { boxShadow: "inset 0 0 0 1px $colors$inputInvalidBorder, inset 0 0 0 100px $colors$inputBg" },
|
|
79
|
+
"&:focus-visible": { boxShadow: `inset 0 0 0 2px $colors$inputInvalidBorder, ${FOCUS_SHADOW}` },
|
|
80
|
+
"&:-webkit-autofill:focus-visible,&:autofill:focus-visible": { boxShadow: `inset 0 0 0 2px $colors$inputInvalidBorder, inset 0 0 0 100px $colors$inputBg, ${FOCUS_SHADOW}` }
|
|
74
81
|
} },
|
|
75
82
|
cursor: {
|
|
76
83
|
default: {
|
|
@@ -145,6 +152,7 @@ var InputWrapper = require_stitches_config.styled("div", {
|
|
|
145
152
|
outline: "none",
|
|
146
153
|
lineHeight: 0,
|
|
147
154
|
position: "relative",
|
|
155
|
+
isolation: "isolate",
|
|
148
156
|
backgroundColor: "$inputBg",
|
|
149
157
|
color: "$inputPlaceholder",
|
|
150
158
|
"&::before": {
|
|
@@ -225,10 +233,22 @@ var AdornmentWrapper = require_stitches_config.styled("div", {
|
|
|
225
233
|
},
|
|
226
234
|
defaultVariants: { size: "medium" }
|
|
227
235
|
});
|
|
228
|
-
var AdornmentWrapperStart = require_stitches_config.styled(AdornmentWrapper, {
|
|
236
|
+
var AdornmentWrapperStart = require_stitches_config.styled(AdornmentWrapper, {
|
|
237
|
+
left: 0,
|
|
238
|
+
zIndex: 1,
|
|
239
|
+
pointerEvents: "none"
|
|
240
|
+
});
|
|
229
241
|
var AdornmentWrapperEnd = require_stitches_config.styled(AdornmentWrapper, { right: 0 });
|
|
230
|
-
var Input = react.default.forwardRef(({ size, startAdornment, endAdornment, css, ...props }, forwardedRef) => {
|
|
242
|
+
var Input = react.default.forwardRef(({ size, startAdornment, endAdornment, css, state, id, disabled, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }, forwardedRef) => {
|
|
231
243
|
const inputRef = react.default.useRef(null);
|
|
244
|
+
const control = require_FieldContext.useFieldControl({
|
|
245
|
+
id,
|
|
246
|
+
disabled,
|
|
247
|
+
invalid: state === "invalid",
|
|
248
|
+
"aria-describedby": ariaDescribedBy,
|
|
249
|
+
"aria-invalid": ariaInvalid
|
|
250
|
+
});
|
|
251
|
+
const resolvedState = control.invalid ? "invalid" : state;
|
|
232
252
|
react.default.useImperativeHandle(forwardedRef, () => {
|
|
233
253
|
const { current } = inputRef;
|
|
234
254
|
if (current) current.clear = () => {
|
|
@@ -240,8 +260,8 @@ var Input = react.default.forwardRef(({ size, startAdornment, endAdornment, css,
|
|
|
240
260
|
const hasEndAdornment = react.default.useMemo(() => Boolean(endAdornment), [endAdornment]);
|
|
241
261
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(InputWrapper, {
|
|
242
262
|
css,
|
|
243
|
-
disabled:
|
|
244
|
-
state:
|
|
263
|
+
disabled: control.disabled,
|
|
264
|
+
state: resolvedState,
|
|
245
265
|
children: [
|
|
246
266
|
hasStartAdornment && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AdornmentWrapperStart, {
|
|
247
267
|
size,
|
|
@@ -252,6 +272,11 @@ var Input = react.default.forwardRef(({ size, startAdornment, endAdornment, css,
|
|
|
252
272
|
startAdornment: hasStartAdornment,
|
|
253
273
|
endAdornment: hasEndAdornment,
|
|
254
274
|
size,
|
|
275
|
+
state: resolvedState,
|
|
276
|
+
id: control.id,
|
|
277
|
+
disabled: control.disabled,
|
|
278
|
+
"aria-describedby": control["aria-describedby"],
|
|
279
|
+
"aria-invalid": control["aria-invalid"],
|
|
255
280
|
...props
|
|
256
281
|
}),
|
|
257
282
|
hasEndAdornment && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AdornmentWrapperEnd, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.cjs","names":["elevationVariants","styled","React"],"sources":["../../../components/Input/Input.tsx"],"sourcesContent":["import React from 'react';\n\nimport { CSS, styled, VariantProps } from '../../stitches.config';\nimport { elevationVariants } from '../Elevation';\n\n// CONSTANTS\nconst FOCUS_SHADOW = elevationVariants[1].boxShadow; // apply elevation $1 when focus\n\nconst SMALL_HEIGHT = '$5';\nconst MEDIUM_HEIGHT = '$6';\nconst LARGE_HEIGHT = '$7';\n\nconst StyledInput = styled('input', {\n // Reset\n appearance: 'none',\n borderWidth: '0',\n boxSizing: 'border-box',\n fontFamily: '$rubik',\n margin: '0',\n outline: 'none',\n padding: '0',\n width: '100%',\n WebkitTapHighlightColor: 'rgba(0,0,0,0)',\n\n // Custom\n position: 'relative',\n backgroundColor: 'transparent',\n borderRadius: 'inherit', // inherit border radius from InputWrapper\n boxShadow: 'inset 0 0 0 1px $colors$inputBorder',\n color: '$inputText',\n fontVariantNumeric: 'tabular-nums',\n transition: 'box-shadow .1s ease-in-out',\n\n '&[type=\"number\"]': {\n pr: '0', // remove padding for number native controls\n },\n\n '&:-webkit-autofill,&:autofill': {\n boxShadow: 'inset 0 0 0 1px $colors$inputBorder, inset 0 0 0 100px $colors$inputBg',\n },\n\n '&:-webkit-autofill::first-line,&:autofill::first-line': {\n fontFamily: '$rubik',\n color: '$hiContrast',\n },\n\n '&:focus-visible': {\n boxShadow: `inset 0 0 0 2px $colors$inputFocusBorder, ${FOCUS_SHADOW}`,\n },\n\n '&::placeholder': {\n color: '$inputPlaceholder',\n },\n\n '&:read-only:not(:disabled)': {\n boxShadow: 'none',\n },\n\n '&:disabled': {\n pointerEvents: 'none',\n color: '$inputDisabledText',\n },\n\n variants: {\n size: {\n small: {\n height: SMALL_HEIGHT,\n fontSize: '$1',\n px: '$2',\n lineHeight: '$sizes$5',\n '&:-webkit-autofill::first-line,&:autofill::first-line': {\n fontSize: '$1',\n },\n },\n medium: {\n height: MEDIUM_HEIGHT,\n fontSize: '$3',\n px: '$3',\n lineHeight: '$sizes$6',\n '&:-webkit-autofill::first-line,&:autofill::first-line': {\n fontSize: '$3',\n },\n },\n large: {\n height: LARGE_HEIGHT,\n fontSize: '$3',\n px: '$3',\n lineHeight: '$sizes$7',\n '&:-webkit-autofill::first-line,&:autofill::first-line': {\n fontSize: '$3',\n },\n },\n },\n startAdornment: {\n true: {},\n },\n endAdornment: {\n true: {},\n },\n variant: {\n ghost: {\n boxShadow: 'none',\n '&:disabled': {\n boxShadow: 'none',\n },\n backgroundColor: 'transparent',\n '&:focus-visible': {\n backgroundColor: '$loContrast',\n },\n },\n },\n state: {\n invalid: {\n boxShadow: 'inset 0 0 0 1px $colors$inputInvalidBorder',\n '&:focus-visible': {\n boxShadow: `inset 0 0 0 2px $colors$inputInvalidBorder, ${FOCUS_SHADOW}`,\n },\n },\n },\n cursor: {\n default: {\n cursor: 'default',\n '@hover': {\n '&:hover:not(:read-only)': {\n cursor: 'text',\n },\n },\n '&:focus-visible:not(:read-only)': {\n cursor: 'text',\n },\n },\n text: {\n cursor: 'text',\n },\n },\n },\n defaultVariants: {\n size: 'medium',\n cursor: 'default',\n },\n compoundVariants: [\n {\n variant: 'ghost',\n state: 'invalid',\n css: {\n boxShadow: 'inset 0 0 0 1px $colors$inputInvalidBorder',\n },\n },\n {\n startAdornment: true,\n size: 'small',\n css: {\n paddingInlineStart: 'calc($2 + 15px)',\n },\n },\n {\n startAdornment: true,\n size: 'medium',\n css: {\n paddingInlineStart: 'calc($3 + 15px)',\n },\n },\n {\n startAdornment: true,\n size: 'large',\n css: {\n paddingInlineStart: 'calc($3 + 15px)',\n },\n },\n {\n endAdornment: true,\n size: 'small',\n css: {\n paddingInlineEnd: 'calc($2 + 15px)',\n },\n },\n {\n endAdornment: true,\n size: 'medium',\n css: {\n paddingInlineEnd: 'calc($3 + 15px)',\n },\n },\n {\n endAdornment: true,\n size: 'large',\n css: {\n paddingInlineEnd: 'calc($3 + 15px)',\n },\n },\n {\n endAdornment: true,\n size: 'small',\n state: 'invalid',\n css: {\n paddingInlineEnd: 'calc($4 + 30px)', // size padding + adornment margins + icon size + icon size\n },\n },\n {\n endAdornment: true,\n size: 'medium',\n state: 'invalid',\n css: {\n paddingInlineEnd: 'calc($6 + 30px)', // size padding + adornment margins + icon size + icon size\n },\n },\n {\n endAdornment: true,\n size: 'large',\n state: 'invalid',\n css: {\n paddingInlineEnd: 'calc($6 + 30px)', // size padding + adornment margins + icon size + icon size\n },\n },\n ],\n});\n\nconst InputWrapper = styled('div', {\n // Reset\n outline: 'none',\n lineHeight: 0,\n\n position: 'relative',\n backgroundColor: '$inputBg',\n color: '$inputPlaceholder',\n\n '&::before': {\n boxSizing: 'border-box',\n content: '\"\"',\n position: 'absolute',\n inset: 0,\n pointerEvents: 'none',\n },\n '&::after': {\n boxSizing: 'border-box',\n content: '\"\"',\n position: 'absolute',\n inset: 0,\n pointerEvents: 'none',\n },\n\n '&:focus-visible': {\n '&::before': {\n backgroundColor: '$inputFocusBg',\n },\n '&::after': {\n backgroundColor: '$primary',\n opacity: 0.15,\n },\n },\n\n '@hover': {\n '&:hover': {\n '&::before': {\n backgroundColor: '$inputHoverBg',\n },\n '&::after': {\n backgroundColor: '$primary',\n opacity: 0.05,\n },\n },\n },\n\n variants: {\n disabled: {\n true: {\n opacity: 0.7,\n color: '$inputDisabledText',\n '@hover': {\n '&:hover': {\n '&::before': {\n backgroundColor: 'inherit',\n },\n '&::after': {\n backgroundColor: 'inherit',\n },\n },\n },\n },\n },\n state: {\n invalid: {\n '@hover': {\n '&:hover': {\n '&::after': {\n backgroundColor: '$inputInvalidBorder',\n },\n },\n },\n },\n },\n size: {\n small: {\n borderRadius: '$2',\n '&::before, &::after': {\n borderRadius: '$2',\n },\n },\n medium: {\n borderRadius: '$3',\n '&::before, &::after': {\n borderRadius: '$3',\n },\n },\n large: {\n borderRadius: '$3',\n '&::before, &::after': {\n borderRadius: '$3',\n },\n },\n },\n },\n defaultVariants: {\n size: 'medium',\n disabled: false,\n },\n});\n\nconst AdornmentWrapper = styled('div', {\n position: 'absolute',\n top: 0,\n height: '100%',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n variants: {\n size: {\n small: {\n mx: 'calc($2 / 2)',\n },\n medium: {\n mx: 'calc($3 / 2)',\n },\n large: {\n mx: 'calc($3 / 2)',\n },\n },\n variant: {\n start: {\n left: 0,\n },\n end: {\n right: 0,\n },\n },\n },\n defaultVariants: {\n size: 'medium',\n },\n});\n\nconst AdornmentWrapperStart = styled(AdornmentWrapper, {\n left: 0,\n});\n\nconst AdornmentWrapperEnd = styled(AdornmentWrapper, {\n right: 0,\n});\n\ntype DefaultInputVariants = VariantProps<typeof StyledInput>;\nexport type InputVariants = Omit<DefaultInputVariants, 'startAdornment' | 'endAdornment'>;\nexport interface HTMLInputProps extends React.InputHTMLAttributes<any> {\n startAdornment?: React.ReactNode;\n endAdornment?: React.ReactNode;\n type?: string;\n}\n\nexport type InputProps = Omit<HTMLInputProps, 'size'> & InputVariants & { css?: CSS };\n\nexport interface InputHandle extends HTMLInputElement {\n clear: () => void;\n}\n\nexport const Input = React.forwardRef<InputHandle, InputProps>(\n ({ size, startAdornment, endAdornment, css, ...props }, forwardedRef) => {\n const inputRef = React.useRef<InputHandle>(null);\n\n React.useImperativeHandle(\n forwardedRef,\n () => {\n const { current } = inputRef;\n if (current) {\n current.clear = () => {\n current.value = '';\n };\n }\n return current as InputHandle;\n },\n [inputRef]\n );\n\n const hasStartAdornment = React.useMemo(() => Boolean(startAdornment), [startAdornment]);\n\n const hasEndAdornment = React.useMemo(() => Boolean(endAdornment), [endAdornment]);\n\n return (\n <InputWrapper css={css} disabled={props.disabled} state={props.state}>\n {hasStartAdornment && (\n <AdornmentWrapperStart size={size}>{startAdornment}</AdornmentWrapperStart>\n )}\n\n <StyledInput\n ref={inputRef}\n startAdornment={hasStartAdornment}\n endAdornment={hasEndAdornment}\n size={size}\n {...props}\n />\n {hasEndAdornment && <AdornmentWrapperEnd size={size}>{endAdornment}</AdornmentWrapperEnd>}\n </InputWrapper>\n );\n }\n);\n"],"mappings":";;;;;;;AAMA,IAAM,eAAeA,kBAAAA,kBAAkB,EAAE,CAAC;AAM1C,IAAM,cAAcC,wBAAAA,OAAO,SAAS;CAElC,YAAY;CACZ,aAAa;CACb,WAAW;CACX,YAAY;CACZ,QAAQ;CACR,SAAS;CACT,SAAS;CACT,OAAO;CACP,yBAAyB;CAGzB,UAAU;CACV,iBAAiB;CACjB,cAAc;CACd,WAAW;CACX,OAAO;CACP,oBAAoB;CACpB,YAAY;CAEZ,sBAAoB,EAClB,IAAI,IACN;CAEA,iCAAiC,EAC/B,WAAW,yEACb;CAEA,yDAAyD;EACvD,YAAY;EACZ,OAAO;CACT;CAEA,mBAAmB,EACjB,WAAW,6CAA6C,eAC1D;CA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ACd,MAAM;GACN,KAAK,EACH,kBAAkB,kBACpB;EACF;EACA;GACE,cAAc;GACd,MAAM;GACN,KAAK,EACH,kBAAkB,kBACpB;EACF;EACA;GACE,cAAc;GACd,MAAM;GACN,OAAO;GACP,KAAK,EACH,kBAAkB,kBACpB;EACF;EACA;GACE,cAAc;GACd,MAAM;GACN,OAAO;GACP,KAAK,EACH,kBAAkB,kBACpB;EACF;EACA;GACE,cAAc;GACd,MAAM;GACN,OAAO;GACP,KAAK,EACH,kBAAkB,kBACpB;EACF;CACF;AACF,CAAC;AAED,IAAM,eAAeA,wBAAAA,OAAO,OAAO;CAEjC,SAAS;CACT,YAAY;CAEZ,UAAU;CACV,iBAAiB;CACjB,OAAO;CAEP,aAAa;EACX,WAAW;EACX,SAAS;EACT,UAAU;EACV,OAAO;EACP,eAAe;CACjB;CACA,YAAY;EACV,WAAW;EACX,SAAS;EACT,UAAU;EACV,OAAO;EACP,eAAe;CACjB;CAEA,mBAAmB;EACjB,aAAa,EACX,iBAAiB,gBACnB;EACA,YAAY;GACV,iBAAiB;GACjB,SAAS;EACX;CACF;CAEA,UAAU,EACR,WAAW;EACT,aAAa,EACX,iBAAiB,gBACnB;EACA,YAAY;GACV,iBAAiB;GACjB,SAAS;EACX;CACF,EACF;CAEA,UAAU;EACR,UAAU,EACR,MAAM;GACJ,SAAS;GACT,OAAO;GACP,UAAU,EACR,WAAW;IACT,aAAa,EACX,iBAAiB,UACnB;IACA,YAAY,EACV,iBAAiB,UACnB;GACF,EACF;EACF,EACF;EACA,OAAO,EACL,SAAS,EACP,UAAU,EACR,WAAW,EACT,YAAY,EACV,iBAAiB,sBACnB,EACF,EACF,EACF,EACF;EACA,MAAM;GACJ,OAAO;IACL,cAAc;IACd,uBAAuB,EACrB,cAAc,KAChB;GACF;GACA,QAAQ;IACN,cAAc;IACd,uBAAuB,EACrB,cAAc,KAChB;GACF;GACA,OAAO;IACL,cAAc;IACd,uBAAuB,EACrB,cAAc,KAChB;GACF;EACF;CACF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B,cAAc;IACR;IACN,GAAI;GACL,CAAA;GACA,mBAAmB,iBAAA,GAAA,kBAAA,IAAA,CAAC,qBAAD;IAA2B;IAAO,UAAA;GAAkC,CAAA;EAC5E;;AAElB,CACF"}
|
|
1
|
+
{"version":3,"file":"Input.cjs","names":["elevationVariants","styled","React","useFieldControl"],"sources":["../../../components/Input/Input.tsx"],"sourcesContent":["import React from 'react';\n\nimport { CSS, styled, VariantProps } from '../../stitches.config';\nimport { elevationVariants } from '../Elevation';\nimport { useFieldControl } from '../Field/FieldContext';\n\n// CONSTANTS\nconst FOCUS_SHADOW = elevationVariants[1].boxShadow; // apply elevation $1 when focus\n\nconst SMALL_HEIGHT = '$5';\nconst MEDIUM_HEIGHT = '$6';\nconst LARGE_HEIGHT = '$7';\n\nconst StyledInput = styled('input', {\n // Reset\n appearance: 'none',\n borderWidth: '0',\n boxSizing: 'border-box',\n fontFamily: '$rubik',\n margin: '0',\n outline: 'none',\n padding: '0',\n width: '100%',\n WebkitTapHighlightColor: 'rgba(0,0,0,0)',\n\n // Custom\n position: 'relative',\n backgroundColor: 'transparent',\n borderRadius: 'inherit', // inherit border radius from InputWrapper\n boxShadow: 'inset 0 0 0 1px $colors$inputBorder',\n color: '$inputText',\n fontVariantNumeric: 'tabular-nums',\n transition: 'box-shadow .1s ease-in-out',\n\n '&[type=\"number\"]': {\n pr: '0', // remove padding for number native controls\n },\n\n '&:-webkit-autofill,&:autofill': {\n boxShadow: 'inset 0 0 0 1px $colors$inputBorder, inset 0 0 0 100px $colors$inputBg',\n WebkitTextFillColor: '$colors$hiContrast',\n },\n\n '&:-webkit-autofill::first-line,&:autofill::first-line': {\n fontFamily: '$rubik',\n color: '$hiContrast',\n },\n\n '&:focus-visible': {\n boxShadow: `inset 0 0 0 2px $colors$inputFocusBorder, ${FOCUS_SHADOW}`,\n },\n\n '&:-webkit-autofill:focus-visible,&:autofill:focus-visible': {\n boxShadow: `inset 0 0 0 2px $colors$inputFocusBorder, inset 0 0 0 100px $colors$inputBg, ${FOCUS_SHADOW}`,\n },\n\n '&::placeholder': {\n color: '$inputPlaceholder',\n },\n\n '&:read-only:not(:disabled)': {\n boxShadow: 'none',\n },\n\n '&:disabled': {\n pointerEvents: 'none',\n color: '$inputDisabledText',\n },\n\n variants: {\n size: {\n small: {\n height: SMALL_HEIGHT,\n fontSize: '$1',\n px: '$2',\n lineHeight: '$sizes$5',\n '&:-webkit-autofill::first-line,&:autofill::first-line': {\n fontSize: '$1',\n },\n },\n medium: {\n height: MEDIUM_HEIGHT,\n fontSize: '$3',\n px: '$3',\n lineHeight: '$sizes$6',\n '&:-webkit-autofill::first-line,&:autofill::first-line': {\n fontSize: '$3',\n },\n },\n large: {\n height: LARGE_HEIGHT,\n fontSize: '$3',\n px: '$3',\n lineHeight: '$sizes$7',\n '&:-webkit-autofill::first-line,&:autofill::first-line': {\n fontSize: '$3',\n },\n },\n },\n startAdornment: {\n true: {},\n },\n endAdornment: {\n true: {},\n },\n variant: {\n ghost: {\n boxShadow: 'none',\n '&:disabled': {\n boxShadow: 'none',\n },\n backgroundColor: 'transparent',\n '&:focus-visible': {\n backgroundColor: '$loContrast',\n },\n },\n },\n state: {\n invalid: {\n boxShadow: 'inset 0 0 0 1px $colors$inputInvalidBorder',\n '&:-webkit-autofill,&:autofill': {\n boxShadow:\n 'inset 0 0 0 1px $colors$inputInvalidBorder, inset 0 0 0 100px $colors$inputBg',\n },\n '&:focus-visible': {\n boxShadow: `inset 0 0 0 2px $colors$inputInvalidBorder, ${FOCUS_SHADOW}`,\n },\n '&:-webkit-autofill:focus-visible,&:autofill:focus-visible': {\n boxShadow: `inset 0 0 0 2px $colors$inputInvalidBorder, inset 0 0 0 100px $colors$inputBg, ${FOCUS_SHADOW}`,\n },\n },\n },\n cursor: {\n default: {\n cursor: 'default',\n '@hover': {\n '&:hover:not(:read-only)': {\n cursor: 'text',\n },\n },\n '&:focus-visible:not(:read-only)': {\n cursor: 'text',\n },\n },\n text: {\n cursor: 'text',\n },\n },\n },\n defaultVariants: {\n size: 'medium',\n cursor: 'default',\n },\n compoundVariants: [\n {\n variant: 'ghost',\n state: 'invalid',\n css: {\n boxShadow: 'inset 0 0 0 1px $colors$inputInvalidBorder',\n },\n },\n {\n startAdornment: true,\n size: 'small',\n css: {\n paddingInlineStart: 'calc($2 + 15px)',\n },\n },\n {\n startAdornment: true,\n size: 'medium',\n css: {\n paddingInlineStart: 'calc($3 + 15px)',\n },\n },\n {\n startAdornment: true,\n size: 'large',\n css: {\n paddingInlineStart: 'calc($3 + 15px)',\n },\n },\n {\n endAdornment: true,\n size: 'small',\n css: {\n paddingInlineEnd: 'calc($2 + 15px)',\n },\n },\n {\n endAdornment: true,\n size: 'medium',\n css: {\n paddingInlineEnd: 'calc($3 + 15px)',\n },\n },\n {\n endAdornment: true,\n size: 'large',\n css: {\n paddingInlineEnd: 'calc($3 + 15px)',\n },\n },\n {\n endAdornment: true,\n size: 'small',\n state: 'invalid',\n css: {\n paddingInlineEnd: 'calc($4 + 30px)', // size padding + adornment margins + icon size + icon size\n },\n },\n {\n endAdornment: true,\n size: 'medium',\n state: 'invalid',\n css: {\n paddingInlineEnd: 'calc($6 + 30px)', // size padding + adornment margins + icon size + icon size\n },\n },\n {\n endAdornment: true,\n size: 'large',\n state: 'invalid',\n css: {\n paddingInlineEnd: 'calc($6 + 30px)', // size padding + adornment margins + icon size + icon size\n },\n },\n ],\n});\n\nconst InputWrapper = styled('div', {\n // Reset\n outline: 'none',\n lineHeight: 0,\n\n position: 'relative',\n isolation: 'isolate',\n backgroundColor: '$inputBg',\n color: '$inputPlaceholder',\n\n '&::before': {\n boxSizing: 'border-box',\n content: '\"\"',\n position: 'absolute',\n inset: 0,\n pointerEvents: 'none',\n },\n '&::after': {\n boxSizing: 'border-box',\n content: '\"\"',\n position: 'absolute',\n inset: 0,\n pointerEvents: 'none',\n },\n\n '&:focus-visible': {\n '&::before': {\n backgroundColor: '$inputFocusBg',\n },\n '&::after': {\n backgroundColor: '$primary',\n opacity: 0.15,\n },\n },\n\n '@hover': {\n '&:hover': {\n '&::before': {\n backgroundColor: '$inputHoverBg',\n },\n '&::after': {\n backgroundColor: '$primary',\n opacity: 0.05,\n },\n },\n },\n\n variants: {\n disabled: {\n true: {\n opacity: 0.7,\n color: '$inputDisabledText',\n '@hover': {\n '&:hover': {\n '&::before': {\n backgroundColor: 'inherit',\n },\n '&::after': {\n backgroundColor: 'inherit',\n },\n },\n },\n },\n },\n state: {\n invalid: {\n '@hover': {\n '&:hover': {\n '&::after': {\n backgroundColor: '$inputInvalidBorder',\n },\n },\n },\n },\n },\n size: {\n small: {\n borderRadius: '$2',\n '&::before, &::after': {\n borderRadius: '$2',\n },\n },\n medium: {\n borderRadius: '$3',\n '&::before, &::after': {\n borderRadius: '$3',\n },\n },\n large: {\n borderRadius: '$3',\n '&::before, &::after': {\n borderRadius: '$3',\n },\n },\n },\n },\n defaultVariants: {\n size: 'medium',\n disabled: false,\n },\n});\n\nconst AdornmentWrapper = styled('div', {\n position: 'absolute',\n top: 0,\n height: '100%',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n variants: {\n size: {\n small: {\n mx: 'calc($2 / 2)',\n },\n medium: {\n mx: 'calc($3 / 2)',\n },\n large: {\n mx: 'calc($3 / 2)',\n },\n },\n variant: {\n start: {\n left: 0,\n },\n end: {\n right: 0,\n },\n },\n },\n defaultVariants: {\n size: 'medium',\n },\n});\n\nconst AdornmentWrapperStart = styled(AdornmentWrapper, {\n left: 0,\n zIndex: 1,\n pointerEvents: 'none',\n});\n\nconst AdornmentWrapperEnd = styled(AdornmentWrapper, {\n right: 0,\n});\n\ntype DefaultInputVariants = VariantProps<typeof StyledInput>;\nexport type InputVariants = Omit<DefaultInputVariants, 'startAdornment' | 'endAdornment'>;\nexport interface HTMLInputProps extends React.InputHTMLAttributes<any> {\n startAdornment?: React.ReactNode;\n endAdornment?: React.ReactNode;\n type?: string;\n}\n\nexport type InputProps = Omit<HTMLInputProps, 'size'> & InputVariants & { css?: CSS };\n\nexport interface InputHandle extends HTMLInputElement {\n clear: () => void;\n}\n\nexport const Input = React.forwardRef<InputHandle, InputProps>(\n (\n {\n size,\n startAdornment,\n endAdornment,\n css,\n state,\n id,\n disabled,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n ...props\n },\n forwardedRef,\n ) => {\n const inputRef = React.useRef<InputHandle>(null);\n const control = useFieldControl({\n id,\n disabled,\n invalid: state === 'invalid',\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n });\n const resolvedState = control.invalid ? 'invalid' : state;\n\n React.useImperativeHandle(forwardedRef, () => {\n const { current } = inputRef;\n if (current) {\n current.clear = () => {\n current.value = '';\n };\n }\n return current as InputHandle;\n }, [inputRef]);\n\n const hasStartAdornment = React.useMemo(() => Boolean(startAdornment), [startAdornment]);\n\n const hasEndAdornment = React.useMemo(() => Boolean(endAdornment), [endAdornment]);\n\n return (\n <InputWrapper css={css} disabled={control.disabled} state={resolvedState}>\n {hasStartAdornment && (\n <AdornmentWrapperStart size={size}>{startAdornment}</AdornmentWrapperStart>\n )}\n\n <StyledInput\n ref={inputRef}\n startAdornment={hasStartAdornment}\n endAdornment={hasEndAdornment}\n size={size}\n state={resolvedState}\n id={control.id}\n disabled={control.disabled}\n aria-describedby={control['aria-describedby']}\n aria-invalid={control['aria-invalid']}\n {...props}\n />\n {hasEndAdornment && <AdornmentWrapperEnd size={size}>{endAdornment}</AdornmentWrapperEnd>}\n </InputWrapper>\n );\n },\n);\n"],"mappings":";;;;;;;;AAOA,IAAM,eAAeA,kBAAAA,kBAAkB,EAAE,CAAC;AAM1C,IAAM,cAAcC,wBAAAA,OAAO,SAAS;CAElC,YAAY;CACZ,aAAa;CACb,WAAW;CACX,YAAY;CACZ,QAAQ;CACR,SAAS;CACT,SAAS;CACT,OAAO;CACP,yBAAyB;CAGzB,UAAU;CACV,iBAAiB;CACjB,cAAc;CACd,WAAW;CACX,OAAO;CACP,oBAAoB;CACpB,YA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6CACb;EACF;EACA;GACE,gBAAgB;GAChB,MAAM;GACN,KAAK,EACH,oBAAoB,kBACtB;EACF;EACA;GACE,gBAAgB;GAChB,MAAM;GACN,KAAK,EACH,oBAAoB,kBACtB;EACF;EACA;GACE,gBAAgB;GAChB,MAAM;GACN,KAAK,EACH,oBAAoB,kBACtB;EACF;EACA;GACE,cAAc;GACd,MAAM;GACN,KAAK,EACH,kBAAkB,kBACpB;EACF;EACA;GACE,cAAc;GACd,MAAM;GACN,KAAK,EACH,kBAAkB,kBACpB;EACF;EACA;GACE,cAAc;GACd,MAAM;GACN,KAAK,EACH,kBAAkB,kBACpB;EACF;EACA;GACE,cAAc;GACd,MAAM;GACN,OAAO;GACP,KAAK,EACH,kBAAkB,kBACpB;EACF;EACA;GACE,cAAc;GACd,MAAM;GACN,OAAO;GACP,KAAK,EACH,kBAAkB,kBACpB;EACF;EACA;GACE,cAAc;GACd,MAAM;GACN,OAAO;GACP,KAAK,EACH,kBAAkB,kBACpB;EACF;CACF;AACF,CAAC;AAED,IAAM,eAAeA,wBAAAA,OAAO,OAAO;CAEjC,SAAS;CACT,YAAY;CAEZ,UAAU;CACV,WAAW;CACX,iBAAiB;CACjB,OAAO;CAEP,aAAa;EACX,WAAW;EACX,SAAS;EACT,UAAU;EACV,OAAO;EACP,eAAe;CACjB;CACA,YAAY;EACV,WAAW;EACX,SAAS;EACT,UAAU;EACV,OAAO;EACP,eAAe;CACjB;CAEA,mBAAmB;EACjB,aAAa,EACX,iBAAiB,gBACnB;EACA,YAAY;GACV,iBAAiB;GACjB,SAAS;EACX;CACF;CAEA,UAAU,EACR,WAAW;EACT,aAAa,EACX,iBAAiB,gBACnB;EACA,YAAY;GACV,iBAAiB;GACjB,SAAS;EACX;CACF,EACF;CAEA,UAAU;EACR,UAAU,EACR,MAAM;GACJ,SAAS;GACT,OAAO;GACP,UAAU,EACR,WAAW;IACT,aAAa,EACX,iBAAiB,UACnB;IACA,YAAY,EACV,iBAAiB,UACnB;GACF,EACF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