@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.js","names":[],"sources":["../../../components/TextField/TextField.tsx"],"sourcesContent":["import {\n CrossCircledIcon,\n ExclamationTriangleIcon,\n EyeClosedIcon,\n EyeOpenIcon,\n} from '@radix-ui/react-icons';\nimport React from 'react';\n\nimport { styled } from '../../stitches.config';\nimport {
|
|
1
|
+
{"version":3,"file":"TextField.js","names":[],"sources":["../../../components/TextField/TextField.tsx"],"sourcesContent":["import {\n CrossCircledIcon,\n ExclamationTriangleIcon,\n EyeClosedIcon,\n EyeOpenIcon,\n} from '@radix-ui/react-icons';\nimport React from 'react';\n\nimport { styled } from '../../stitches.config';\nimport { Field } from '../Field/Field';\nimport { FieldLabelProps, useFieldContext } from '../Field/FieldContext';\nimport { Input, InputHandle, InputProps, InputVariants } from '../Input';\nimport { Tooltip } from '../Tooltip';\n\n// TYPES\nexport interface TextFieldLabelProps {\n variant: 'invalid' | 'subtle' | 'contrast' | 'default';\n htmlFor?: string;\n id?: string;\n}\nexport type TextFieldProps = InputProps & {\n type?: string;\n clearable?: boolean;\n label?: string | ((props: TextFieldLabelProps) => JSX.Element);\n description?: React.ReactNode;\n error?: React.ReactNode;\n announceError?: boolean;\n};\n\nexport type TextFieldVariants = InputVariants;\n\n// COMPONENTS\nconst AdornmentGroup = styled('div', {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'center',\n});\n\nconst StyledExclamationTriangleIcon = styled(ExclamationTriangleIcon, {\n '& + *': {\n marginLeft: '$1',\n },\n});\n\nconst AdornmentButton = styled('button', {\n appearance: 'none',\n background: 'none',\n border: 'none',\n padding: 0,\n font: 'inherit',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n borderRadius: '$1',\n color: 'inherit',\n '@hover': {\n '&:hover': {\n cursor: 'pointer',\n },\n },\n '&:focus-visible': {\n outline: '2px solid $inputFocusBorder',\n outlineOffset: '1px',\n },\n});\n\nexport const TextField = React.forwardRef<React.ElementRef<typeof Input>, TextFieldProps>(\n (\n {\n state,\n clearable,\n label: LabelOrComponent,\n description,\n error,\n announceError,\n id,\n type,\n disabled,\n readOnly,\n css,\n ...props\n },\n forwardedRef,\n ) => {\n const inputRef = React.useRef<InputHandle | null>(null);\n React.useImperativeHandle(forwardedRef, () => inputRef.current as InputHandle);\n\n const outerField = useFieldContext();\n const [innerType, setInnerType] = React.useState(type);\n const isPasswordVisible = React.useMemo(() => innerType !== 'password', [innerType]);\n\n const invalid = state === 'invalid' || Boolean(error) || Boolean(outerField?.invalid);\n\n const renderLabel = React.useMemo(() => {\n if (LabelOrComponent === undefined || LabelOrComponent === null) {\n return undefined;\n }\n if (typeof LabelOrComponent === 'string') {\n return LabelOrComponent;\n }\n return (labelProps: FieldLabelProps) => <LabelOrComponent {...labelProps} />;\n }, [LabelOrComponent]);\n\n const isPasswordType = React.useMemo(() => type === 'password', [type]);\n\n const typeOrInnerType = React.useMemo(\n () => (isPasswordType ? innerType : type),\n [isPasswordType, type, innerType],\n );\n\n const hasInnerAdornment = React.useMemo(\n () => clearable || isPasswordType || invalid,\n [clearable, isPasswordType, invalid],\n );\n\n const hasAdornmentGroup = React.useMemo(\n () => (clearable && invalid) || (clearable && isPasswordType) || (invalid && isPasswordType),\n [clearable, invalid, isPasswordType],\n );\n\n const clearDisabled = readOnly || disabled || Boolean(outerField?.disabled);\n\n const handleClear = React.useCallback(() => {\n const { current } = inputRef;\n if (current) {\n const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;\n setValue?.call(current, '');\n current.dispatchEvent(new Event('input', { bubbles: true }));\n current.focus();\n }\n }, [inputRef]);\n\n const togglePasswordVisibility = React.useCallback(() => {\n setInnerType((prevInnerType) => (prevInnerType === 'password' ? undefined : 'password'));\n }, [setInnerType]);\n\n const EndAdornmentWrapper = hasAdornmentGroup ? AdornmentGroup : React.Fragment;\n\n const PasswordVisibilityToggleIcon = isPasswordVisible ? EyeClosedIcon : EyeOpenIcon;\n\n const passwordAction = React.useMemo(\n () => (isPasswordVisible ? 'Hide password' : 'Show password'),\n [isPasswordVisible],\n );\n\n const input = (\n <Input\n id={id}\n ref={inputRef}\n endAdornment={\n hasInnerAdornment && (\n <EndAdornmentWrapper>\n {invalid && <StyledExclamationTriangleIcon aria-hidden />}\n {isPasswordType && (\n <Tooltip content={passwordAction}>\n <AdornmentButton\n type=\"button\"\n aria-label={passwordAction}\n onClick={togglePasswordVisibility}\n >\n <PasswordVisibilityToggleIcon aria-hidden />\n </AdornmentButton>\n </Tooltip>\n )}\n {clearable && !clearDisabled && (\n <Tooltip content=\"Clear\">\n <AdornmentButton type=\"button\" aria-label=\"Clear\" onClick={handleClear}>\n <CrossCircledIcon aria-hidden />\n </AdornmentButton>\n </Tooltip>\n )}\n </EndAdornmentWrapper>\n )\n }\n state={state}\n type={typeOrInnerType}\n disabled={disabled}\n readOnly={readOnly}\n {...props}\n />\n );\n\n return (\n <Field\n id={id}\n label={renderLabel}\n description={description}\n error={error}\n announceError={announceError}\n invalid={state === 'invalid'}\n disabled={disabled}\n css={css}\n >\n {input}\n </Field>\n );\n },\n);\n"],"mappings":";;;;;;;;;AAgCA,IAAM,iBAAiB,OAAO,OAAO;CACnC,SAAS;CACT,eAAe;CACf,YAAY;AACd,CAAC;AAED,IAAM,gCAAgC,OAAO,yBAAyB,EACpE,SAAS,EACP,YAAY,KACd,EACF,CAAC;AAED,IAAM,kBAAkB,OAAO,UAAU;CACvC,YAAY;CACZ,YAAY;CACZ,QAAQ;CACR,SAAS;CACT,MAAM;CACN,SAAS;CACT,YAAY;CACZ,gBAAgB;CAChB,cAAc;CACd,OAAO;CACP,UAAU,EACR,WAAW,EACT,QAAQ,UACV,EACF;CACA,mBAAmB;EACjB,SAAS;EACT,eAAe;CACjB;AACF,CAAC;AAED,IAAa,YAAY,MAAM,YAE3B,EACE,OACA,WACA,OAAO,kBACP,aACA,OACA,eACA,IACA,MACA,UACA,UACA,KACA,GAAG,SAEL,iBACG;CACH,MAAM,WAAW,MAAM,OAA2B,IAAI;CACtD,MAAM,oBAAoB,oBAAoB,SAAS,OAAsB;CAE7E,MAAM,aAAa,gBAAgB;CACnC,MAAM,CAAC,WAAW,gBAAgB,MAAM,SAAS,IAAI;CACrD,MAAM,oBAAoB,MAAM,cAAc,cAAc,YAAY,CAAC,SAAS,CAAC;CAEnF,MAAM,UAAU,UAAU,aAAa,QAAQ,KAAK,KAAK,QAAQ,YAAY,OAAO;CAEpF,MAAM,cAAc,MAAM,cAAc;EACtC,IAAI,qB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C,+BAAD,EAA+B,eAAA,KAAa,CAAA;GACvD,kBACC,oBAAC,SAAD;IAAS,SAAS;IAChB,UAAA,oBAAC,iBAAD;KACE,MAAK;KACL,cAAY;KACZ,SAAS;KAET,UAAA,oBAAC,8BAAD,EAA8B,eAAA,KAAa,CAAA;IAC5B,CAAA;GACV,CAAA;GAEV,aAAa,CAAC,iBACb,oBAAC,SAAD;IAAS,SAAQ;IACf,UAAA,oBAAC,iBAAD;KAAiB,MAAK;KAAS,cAAW;KAAQ,SAAS;KACzD,UAAA,oBAAC,kBAAD,EAAkB,eAAA,KAAa,CAAA;IAChB,CAAA;GACV,CAAA;EAEQ,EAAA,CAAA;EAGlB;EACP,MAAM;EACI;EACA;EACV,GAAI;CACL,CAAA;CAGH,OACE,oBAAC,OAAD;EACM;EACJ,OAAO;EACM;EACN;EACQ;EACf,SAAS,UAAU;EACT;EACL;EAEJ,UAAA;CACI,CAAA;AAEX,CACF"}
|
|
@@ -1,56 +1,26 @@
|
|
|
1
1
|
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const
|
|
3
|
-
const require_Box_vanilla = require("../Box/Box.vanilla.cjs");
|
|
4
|
-
const require_Label_vanilla = require("../Label/Label.vanilla.cjs");
|
|
2
|
+
const require_FieldContext = require("../Field/FieldContext.cjs");
|
|
5
3
|
const require_Input_vanilla = require("../Input/Input.vanilla.cjs");
|
|
4
|
+
const require_Field_vanilla = require("../Field/Field.vanilla.cjs");
|
|
6
5
|
const require_Tooltip = require("../Tooltip/Tooltip.cjs");
|
|
6
|
+
require("./TextField.vanilla.css.cjs");
|
|
7
7
|
let _radix_ui_react_icons = require("@radix-ui/react-icons");
|
|
8
8
|
let react = require("react");
|
|
9
9
|
react = require_runtime.__toESM(react, 1);
|
|
10
10
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
11
11
|
// components/TextField/TextField.vanilla.tsx
|
|
12
|
-
var
|
|
13
|
-
display: "flex",
|
|
14
|
-
flexDirection: "row",
|
|
15
|
-
alignItems: "center"
|
|
16
|
-
});
|
|
17
|
-
var StyledExclamationTriangleIcon = require_stitches_config.styled(_radix_ui_react_icons.ExclamationTriangleIcon, { "& + *": { marginLeft: "$1" } });
|
|
18
|
-
var StyledEyeOpenIcon = require_stitches_config.styled(_radix_ui_react_icons.EyeOpenIcon, { "@hover": { "&:hover": { cursor: "pointer" } } });
|
|
19
|
-
var StyledEyeClosedIcon = require_stitches_config.styled(_radix_ui_react_icons.EyeClosedIcon, { "@hover": { "&:hover": { cursor: "pointer" } } });
|
|
20
|
-
var StyledCrossCircledIcon = require_stitches_config.styled(_radix_ui_react_icons.CrossCircledIcon, { "@hover": { "&:hover": { cursor: "pointer" } } });
|
|
21
|
-
var TextFieldVanilla = react.default.forwardRef(({ state, clearable, label: LabelOrComponent, id, type, disabled, readOnly, onBlur, onFocus, css, ...props }, forwardedRef) => {
|
|
12
|
+
var TextFieldVanilla = react.default.forwardRef(({ state, clearable, label: LabelOrComponent, description, error, announceError, id, type, disabled, readOnly, css, ...props }, forwardedRef) => {
|
|
22
13
|
const inputRef = react.default.useRef(null);
|
|
23
14
|
react.default.useImperativeHandle(forwardedRef, () => inputRef.current);
|
|
24
|
-
const
|
|
15
|
+
const outerField = require_FieldContext.useFieldContext();
|
|
25
16
|
const [innerType, setInnerType] = react.default.useState(type);
|
|
26
17
|
const isPasswordVisible = react.default.useMemo(() => innerType !== "password", [innerType]);
|
|
27
|
-
const invalid =
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}, [
|
|
34
|
-
invalid,
|
|
35
|
-
disabled,
|
|
36
|
-
inputHasFocus
|
|
37
|
-
]);
|
|
38
|
-
const LabelNode = react.default.useMemo(() => {
|
|
39
|
-
if (LabelOrComponent === void 0 || LabelOrComponent === null) return null;
|
|
40
|
-
if (typeof LabelOrComponent === "string") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Label_vanilla.LabelVanilla, {
|
|
41
|
-
variant: labelVariant,
|
|
42
|
-
htmlFor: id,
|
|
43
|
-
children: LabelOrComponent
|
|
44
|
-
});
|
|
45
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LabelOrComponent, {
|
|
46
|
-
variant: labelVariant,
|
|
47
|
-
htmlFor: id
|
|
48
|
-
});
|
|
49
|
-
}, [
|
|
50
|
-
LabelOrComponent,
|
|
51
|
-
labelVariant,
|
|
52
|
-
id
|
|
53
|
-
]);
|
|
18
|
+
const invalid = state === "invalid" || Boolean(error) || Boolean(outerField?.invalid);
|
|
19
|
+
const renderLabel = react.default.useMemo(() => {
|
|
20
|
+
if (LabelOrComponent === void 0 || LabelOrComponent === null) return;
|
|
21
|
+
if (typeof LabelOrComponent === "string") return LabelOrComponent;
|
|
22
|
+
return (labelProps) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LabelOrComponent, { ...labelProps });
|
|
23
|
+
}, [LabelOrComponent]);
|
|
54
24
|
const isPasswordType = react.default.useMemo(() => type === "password", [type]);
|
|
55
25
|
const typeOrInnerType = react.default.useMemo(() => isPasswordType ? innerType : type, [
|
|
56
26
|
isPasswordType,
|
|
@@ -67,58 +37,72 @@ var TextFieldVanilla = react.default.forwardRef(({ state, clearable, label: Labe
|
|
|
67
37
|
invalid,
|
|
68
38
|
isPasswordType
|
|
69
39
|
]);
|
|
70
|
-
const clearDisabled =
|
|
40
|
+
const clearDisabled = readOnly || disabled || Boolean(outerField?.disabled);
|
|
71
41
|
const handleClear = react.default.useCallback(() => {
|
|
72
42
|
const { current } = inputRef;
|
|
73
|
-
if (current)
|
|
43
|
+
if (current) {
|
|
44
|
+
(Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set)?.call(current, "");
|
|
45
|
+
current.dispatchEvent(new Event("input", { bubbles: true }));
|
|
46
|
+
current.focus();
|
|
47
|
+
}
|
|
74
48
|
}, [inputRef]);
|
|
75
|
-
const handleFocus = react.default.useCallback((e) => {
|
|
76
|
-
if (onFocus) onFocus(e);
|
|
77
|
-
setInputHasFocus(true);
|
|
78
|
-
}, [onFocus, setInputHasFocus]);
|
|
79
|
-
const handleBlur = react.default.useCallback((e) => {
|
|
80
|
-
if (onBlur) onBlur(e);
|
|
81
|
-
setInputHasFocus(false);
|
|
82
|
-
}, [onBlur, setInputHasFocus]);
|
|
83
49
|
const togglePasswordVisibility = react.default.useCallback(() => {
|
|
84
50
|
setInnerType((prevInnerType) => prevInnerType === "password" ? void 0 : "password");
|
|
85
51
|
}, [setInnerType]);
|
|
86
|
-
const
|
|
87
|
-
const PasswordVisibilityToggleIcon = isPasswordVisible ? StyledEyeClosedIcon : StyledEyeOpenIcon;
|
|
52
|
+
const PasswordVisibilityToggleIcon = isPasswordVisible ? _radix_ui_react_icons.EyeClosedIcon : _radix_ui_react_icons.EyeOpenIcon;
|
|
88
53
|
const passwordAction = react.default.useMemo(() => isPasswordVisible ? "Hide password" : "Show password", [isPasswordVisible]);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
})
|
|
54
|
+
const adornments = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
55
|
+
invalid && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_icons.ExclamationTriangleIcon, {
|
|
56
|
+
className: "_1q0c5701",
|
|
57
|
+
"aria-hidden": true
|
|
58
|
+
}),
|
|
59
|
+
isPasswordType && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Tooltip.Tooltip, {
|
|
60
|
+
content: passwordAction,
|
|
61
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
62
|
+
type: "button",
|
|
63
|
+
className: "_1q0c5702",
|
|
64
|
+
"aria-label": passwordAction,
|
|
65
|
+
onClick: togglePasswordVisibility,
|
|
66
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PasswordVisibilityToggleIcon, { "aria-hidden": true })
|
|
67
|
+
})
|
|
68
|
+
}),
|
|
69
|
+
clearable && !clearDisabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Tooltip.Tooltip, {
|
|
70
|
+
content: "Clear",
|
|
71
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
72
|
+
type: "button",
|
|
73
|
+
className: "_1q0c5702",
|
|
74
|
+
"aria-label": "Clear",
|
|
75
|
+
onClick: handleClear,
|
|
76
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_icons.CrossCircledIcon, { "aria-hidden": true })
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
] });
|
|
80
|
+
const input = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Input_vanilla.InputVanilla, {
|
|
81
|
+
id,
|
|
82
|
+
ref: inputRef,
|
|
83
|
+
endAdornment: hasInnerAdornment && (hasAdornmentGroup ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
84
|
+
className: "_1q0c5700",
|
|
85
|
+
children: adornments
|
|
86
|
+
}) : adornments),
|
|
87
|
+
state,
|
|
88
|
+
type: typeOrInnerType,
|
|
89
|
+
disabled,
|
|
90
|
+
readOnly,
|
|
91
|
+
...props
|
|
92
|
+
});
|
|
93
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Field_vanilla.FieldVanilla, {
|
|
94
|
+
id,
|
|
95
|
+
label: renderLabel,
|
|
96
|
+
description,
|
|
97
|
+
error,
|
|
98
|
+
announceError,
|
|
99
|
+
invalid: state === "invalid",
|
|
100
|
+
disabled,
|
|
101
|
+
css: {
|
|
102
|
+
boxSizing: "border-box",
|
|
103
|
+
...css
|
|
104
|
+
},
|
|
105
|
+
children: input
|
|
122
106
|
});
|
|
123
107
|
});
|
|
124
108
|
TextFieldVanilla.displayName = "TextFieldVanilla";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.vanilla.cjs","names":["
|
|
1
|
+
{"version":3,"file":"TextField.vanilla.cjs","names":["React","useFieldContext","EyeClosedIcon","EyeOpenIcon","_Fragment","ExclamationTriangleIcon","Tooltip","CrossCircledIcon","InputVanilla","FieldVanilla"],"sources":["../../../components/TextField/TextField.vanilla.tsx"],"sourcesContent":["import {\n CrossCircledIcon,\n ExclamationTriangleIcon,\n EyeClosedIcon,\n EyeOpenIcon,\n} from '@radix-ui/react-icons';\nimport React from 'react';\n\nimport { FieldVanilla } from '../Field/Field.vanilla';\nimport { FieldLabelProps, useFieldContext } from '../Field/FieldContext';\nimport { InputVanilla, InputVanillaHandle, InputVanillaProps } from '../Input';\nimport { Tooltip } from '../Tooltip';\nimport { adornmentButton, adornmentGroup, invalidIcon } from './TextField.vanilla.css';\n\n// TYPES\nexport interface TextFieldLabelProps {\n variant: 'invalid' | 'subtle' | 'contrast' | 'default';\n htmlFor?: string;\n id?: string;\n}\n\nexport type TextFieldVanillaProps = InputVanillaProps & {\n type?: string;\n clearable?: boolean;\n label?: string | ((props: TextFieldLabelProps) => JSX.Element);\n description?: React.ReactNode;\n error?: React.ReactNode;\n announceError?: boolean;\n};\n\nexport const TextFieldVanilla = React.forwardRef<\n React.ElementRef<typeof InputVanilla>,\n TextFieldVanillaProps\n>(\n (\n {\n state,\n clearable,\n label: LabelOrComponent,\n description,\n error,\n announceError,\n id,\n type,\n disabled,\n readOnly,\n css,\n ...props\n },\n forwardedRef,\n ) => {\n const inputRef = React.useRef<InputVanillaHandle | null>(null);\n React.useImperativeHandle(forwardedRef, () => inputRef.current as InputVanillaHandle);\n\n const outerField = useFieldContext();\n const [innerType, setInnerType] = React.useState(type);\n const isPasswordVisible = React.useMemo(() => innerType !== 'password', [innerType]);\n\n const invalid = state === 'invalid' || Boolean(error) || Boolean(outerField?.invalid);\n\n const renderLabel = React.useMemo(() => {\n if (LabelOrComponent === undefined || LabelOrComponent === null) {\n return undefined;\n }\n if (typeof LabelOrComponent === 'string') {\n return LabelOrComponent;\n }\n return (labelProps: FieldLabelProps) => <LabelOrComponent {...labelProps} />;\n }, [LabelOrComponent]);\n\n const isPasswordType = React.useMemo(() => type === 'password', [type]);\n\n const typeOrInnerType = React.useMemo(\n () => (isPasswordType ? innerType : type),\n [isPasswordType, type, innerType],\n );\n\n const hasInnerAdornment = React.useMemo(\n () => clearable || isPasswordType || invalid,\n [clearable, isPasswordType, invalid],\n );\n\n const hasAdornmentGroup = React.useMemo(\n () => (clearable && invalid) || (clearable && isPasswordType) || (invalid && isPasswordType),\n [clearable, invalid, isPasswordType],\n );\n\n const clearDisabled = readOnly || disabled || Boolean(outerField?.disabled);\n\n const handleClear = React.useCallback(() => {\n const { current } = inputRef;\n if (current) {\n const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;\n setValue?.call(current, '');\n current.dispatchEvent(new Event('input', { bubbles: true }));\n current.focus();\n }\n }, [inputRef]);\n\n const togglePasswordVisibility = React.useCallback(() => {\n setInnerType((prevInnerType) => (prevInnerType === 'password' ? undefined : 'password'));\n }, [setInnerType]);\n\n const PasswordVisibilityToggleIcon = isPasswordVisible ? EyeClosedIcon : EyeOpenIcon;\n\n const passwordAction = React.useMemo(\n () => (isPasswordVisible ? 'Hide password' : 'Show password'),\n [isPasswordVisible],\n );\n\n const adornments = (\n <>\n {invalid && <ExclamationTriangleIcon className={invalidIcon} aria-hidden />}\n {isPasswordType && (\n <Tooltip content={passwordAction}>\n <button\n type=\"button\"\n className={adornmentButton}\n aria-label={passwordAction}\n onClick={togglePasswordVisibility}\n >\n <PasswordVisibilityToggleIcon aria-hidden />\n </button>\n </Tooltip>\n )}\n {clearable && !clearDisabled && (\n <Tooltip content=\"Clear\">\n <button\n type=\"button\"\n className={adornmentButton}\n aria-label=\"Clear\"\n onClick={handleClear}\n >\n <CrossCircledIcon aria-hidden />\n </button>\n </Tooltip>\n )}\n </>\n );\n\n const input = (\n <InputVanilla\n id={id}\n ref={inputRef}\n endAdornment={\n hasInnerAdornment &&\n (hasAdornmentGroup ? <div className={adornmentGroup}>{adornments}</div> : adornments)\n }\n state={state}\n type={typeOrInnerType}\n disabled={disabled}\n readOnly={readOnly}\n {...props}\n />\n );\n\n return (\n <FieldVanilla\n id={id}\n label={renderLabel}\n description={description}\n error={error}\n announceError={announceError}\n invalid={state === 'invalid'}\n disabled={disabled}\n css={{ boxSizing: 'border-box', ...css }}\n >\n {input}\n </FieldVanilla>\n );\n },\n);\n\nTextFieldVanilla.displayName = 'TextFieldVanilla';\n"],"mappings":";;;;;;;;;;;AA8BA,IAAa,mBAAmBA,MAAAA,QAAM,YAKlC,EACE,OACA,WACA,OAAO,kBACP,aACA,OACA,eACA,IACA,MACA,UACA,UACA,KACA,GAAG,SAEL,iBACG;CACH,MAAM,WAAWA,MAAAA,QAAM,OAAkC,IAAI;CAC7D,MAAA,QAAM,oBAAoB,oBAAoB,SAAS,OAA6B;CAEpF,MAAM,aAAaC,qBAAAA,gBAAgB;CACnC,MAAM,CAAC,WAAW,gBAAgBD,MAAAA,QAAM,SAAS,IAAI;CACrD,MAAM,oBAAoBA,MAAAA,QAAM,cAAc,cAAc,YAAY,CAAC,SAAS,CAAC;CAEnF,MAAM,UAAU,UAAU,aAAa,QAAQ,KAAK,KAAK,QAAQ,YAAY,OAAO;CAEpF,MAAM,cAAcA,MAAAA,QAAM,cAAc;EACtC,IAAI,qBAAqB,KAAA,KAAa,qBAAqB,MACzD;EAEF,IAAI,OAAO,qBAAqB,UAC9B,OAAO;E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,sBAAAA,yBAAD;GAAyB,WAAA;GAAwB,eAAA;EAAa,CAAA;EACzE,kBACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,gBAAAA,SAAD;GAAS,SAAS;GAChB,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;IACE,MAAK;IACL,WAAA;IACA,cAAY;IACZ,SAAS;IAET,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,8BAAD,EAA8B,eAAA,KAAa,CAAA;GACrC,CAAA;EACD,CAAA;EAEV,aAAa,CAAC,iBACb,iBAAA,GAAA,kBAAA,IAAA,CAACA,gBAAAA,SAAD;GAAS,SAAQ;GACf,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;IACE,MAAK;IACL,WAAA;IACA,cAAW;IACX,SAAS;IAET,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,kBAAD,EAAkB,eAAA,KAAa,CAAA;GACzB,CAAA;EACD,CAAA;CAEX,EAAA,CAAA;CAGJ,MAAM,QACJ,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,cAAD;EACM;EACJ,KAAK;EACL,cACE,sBACC,oBAAoB,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;GAAK,WAAA;GAA4B,UAAA;EAAgB,CAAA,IAAI;EAErE;EACP,MAAM;EACI;EACA;EACV,GAAI;CACL,CAAA;CAGH,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,cAAD;EACM;EACJ,OAAO;EACM;EACN;EACQ;EACf,SAAS,UAAU;EACT;EACV,KAAK;GAAE,WAAW;GAAc,GAAG;EAAI;EAEtC,UAAA;CACW,CAAA;AAElB,CACF;AAEA,iBAAiB,cAAc"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
;/* empty css */
|
|
2
|
+
// components/TextField/TextField.vanilla.css.ts
|
|
3
|
+
var adornmentGroup = "_1q0c5700";
|
|
4
|
+
var invalidIcon = "_1q0c5701";
|
|
5
|
+
var adornmentButton = "_1q0c5702";
|
|
6
|
+
exports.adornmentButton = adornmentButton;
|
|
7
|
+
exports.adornmentGroup = adornmentGroup;
|
|
8
|
+
exports.invalidIcon = invalidIcon;
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=TextField.vanilla.css.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextField.vanilla.css.cjs","names":[],"sources":["../../../components/TextField/TextField.vanilla.css.ts"],"sourcesContent":["import { globalStyle, style } from '@vanilla-extract/css';\n\nimport { tokens } from '../../styles/tokens.css';\n\nexport const adornmentGroup = style({\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'center',\n});\n\nexport const invalidIcon = style({});\n\nglobalStyle(`${invalidIcon} + *`, {\n marginLeft: tokens.space['1'],\n});\n\nexport const adornmentButton = style({\n appearance: 'none',\n background: 'none',\n border: 'none',\n padding: 0,\n font: 'inherit',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n borderRadius: tokens.radii['1'],\n color: 'inherit',\n cursor: 'pointer',\n selectors: {\n '&:focus-visible': {\n outline: `2px solid ${tokens.colors.inputFocusBorder}`,\n outlineOffset: '1px',\n },\n },\n});\n"],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
// components/TextField/TextField.vanilla.css.ts
|
|
3
|
+
var adornmentGroup = "_1q0c5700";
|
|
4
|
+
var invalidIcon = "_1q0c5701";
|
|
5
|
+
var adornmentButton = "_1q0c5702";
|
|
6
|
+
export { adornmentButton, adornmentGroup, invalidIcon };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=TextField.vanilla.css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextField.vanilla.css.js","names":[],"sources":["../../../components/TextField/TextField.vanilla.css.ts"],"sourcesContent":["import { globalStyle, style } from '@vanilla-extract/css';\n\nimport { tokens } from '../../styles/tokens.css';\n\nexport const adornmentGroup = style({\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'center',\n});\n\nexport const invalidIcon = style({});\n\nglobalStyle(`${invalidIcon} + *`, {\n marginLeft: tokens.space['1'],\n});\n\nexport const adornmentButton = style({\n appearance: 'none',\n background: 'none',\n border: 'none',\n padding: 0,\n font: 'inherit',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n borderRadius: tokens.radii['1'],\n color: 'inherit',\n cursor: 'pointer',\n selectors: {\n '&:focus-visible': {\n outline: `2px solid ${tokens.colors.inputFocusBorder}`,\n outlineOffset: '1px',\n },\n },\n});\n"],"mappings":""}
|
|
@@ -1,54 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BoxVanilla } from "../Box/Box.vanilla.js";
|
|
3
|
-
import { LabelVanilla } from "../Label/Label.vanilla.js";
|
|
1
|
+
import { useFieldContext } from "../Field/FieldContext.js";
|
|
4
2
|
import { InputVanilla } from "../Input/Input.vanilla.js";
|
|
3
|
+
import { FieldVanilla } from "../Field/Field.vanilla.js";
|
|
5
4
|
import { Tooltip } from "../Tooltip/Tooltip.js";
|
|
5
|
+
import "./TextField.vanilla.css.js";
|
|
6
6
|
import { CrossCircledIcon, ExclamationTriangleIcon, EyeClosedIcon, EyeOpenIcon } from "@radix-ui/react-icons";
|
|
7
7
|
import React from "react";
|
|
8
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
// components/TextField/TextField.vanilla.tsx
|
|
10
|
-
var
|
|
11
|
-
display: "flex",
|
|
12
|
-
flexDirection: "row",
|
|
13
|
-
alignItems: "center"
|
|
14
|
-
});
|
|
15
|
-
var StyledExclamationTriangleIcon = styled(ExclamationTriangleIcon, { "& + *": { marginLeft: "$1" } });
|
|
16
|
-
var StyledEyeOpenIcon = styled(EyeOpenIcon, { "@hover": { "&:hover": { cursor: "pointer" } } });
|
|
17
|
-
var StyledEyeClosedIcon = styled(EyeClosedIcon, { "@hover": { "&:hover": { cursor: "pointer" } } });
|
|
18
|
-
var StyledCrossCircledIcon = styled(CrossCircledIcon, { "@hover": { "&:hover": { cursor: "pointer" } } });
|
|
19
|
-
var TextFieldVanilla = React.forwardRef(({ state, clearable, label: LabelOrComponent, id, type, disabled, readOnly, onBlur, onFocus, css, ...props }, forwardedRef) => {
|
|
10
|
+
var TextFieldVanilla = React.forwardRef(({ state, clearable, label: LabelOrComponent, description, error, announceError, id, type, disabled, readOnly, css, ...props }, forwardedRef) => {
|
|
20
11
|
const inputRef = React.useRef(null);
|
|
21
12
|
React.useImperativeHandle(forwardedRef, () => inputRef.current);
|
|
22
|
-
const
|
|
13
|
+
const outerField = useFieldContext();
|
|
23
14
|
const [innerType, setInnerType] = React.useState(type);
|
|
24
15
|
const isPasswordVisible = React.useMemo(() => innerType !== "password", [innerType]);
|
|
25
|
-
const invalid =
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}, [
|
|
32
|
-
invalid,
|
|
33
|
-
disabled,
|
|
34
|
-
inputHasFocus
|
|
35
|
-
]);
|
|
36
|
-
const LabelNode = React.useMemo(() => {
|
|
37
|
-
if (LabelOrComponent === void 0 || LabelOrComponent === null) return null;
|
|
38
|
-
if (typeof LabelOrComponent === "string") return /* @__PURE__ */ jsx(LabelVanilla, {
|
|
39
|
-
variant: labelVariant,
|
|
40
|
-
htmlFor: id,
|
|
41
|
-
children: LabelOrComponent
|
|
42
|
-
});
|
|
43
|
-
return /* @__PURE__ */ jsx(LabelOrComponent, {
|
|
44
|
-
variant: labelVariant,
|
|
45
|
-
htmlFor: id
|
|
46
|
-
});
|
|
47
|
-
}, [
|
|
48
|
-
LabelOrComponent,
|
|
49
|
-
labelVariant,
|
|
50
|
-
id
|
|
51
|
-
]);
|
|
16
|
+
const invalid = state === "invalid" || Boolean(error) || Boolean(outerField?.invalid);
|
|
17
|
+
const renderLabel = React.useMemo(() => {
|
|
18
|
+
if (LabelOrComponent === void 0 || LabelOrComponent === null) return;
|
|
19
|
+
if (typeof LabelOrComponent === "string") return LabelOrComponent;
|
|
20
|
+
return (labelProps) => /* @__PURE__ */ jsx(LabelOrComponent, { ...labelProps });
|
|
21
|
+
}, [LabelOrComponent]);
|
|
52
22
|
const isPasswordType = React.useMemo(() => type === "password", [type]);
|
|
53
23
|
const typeOrInnerType = React.useMemo(() => isPasswordType ? innerType : type, [
|
|
54
24
|
isPasswordType,
|
|
@@ -65,58 +35,72 @@ var TextFieldVanilla = React.forwardRef(({ state, clearable, label: LabelOrCompo
|
|
|
65
35
|
invalid,
|
|
66
36
|
isPasswordType
|
|
67
37
|
]);
|
|
68
|
-
const clearDisabled =
|
|
38
|
+
const clearDisabled = readOnly || disabled || Boolean(outerField?.disabled);
|
|
69
39
|
const handleClear = React.useCallback(() => {
|
|
70
40
|
const { current } = inputRef;
|
|
71
|
-
if (current)
|
|
41
|
+
if (current) {
|
|
42
|
+
(Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set)?.call(current, "");
|
|
43
|
+
current.dispatchEvent(new Event("input", { bubbles: true }));
|
|
44
|
+
current.focus();
|
|
45
|
+
}
|
|
72
46
|
}, [inputRef]);
|
|
73
|
-
const handleFocus = React.useCallback((e) => {
|
|
74
|
-
if (onFocus) onFocus(e);
|
|
75
|
-
setInputHasFocus(true);
|
|
76
|
-
}, [onFocus, setInputHasFocus]);
|
|
77
|
-
const handleBlur = React.useCallback((e) => {
|
|
78
|
-
if (onBlur) onBlur(e);
|
|
79
|
-
setInputHasFocus(false);
|
|
80
|
-
}, [onBlur, setInputHasFocus]);
|
|
81
47
|
const togglePasswordVisibility = React.useCallback(() => {
|
|
82
48
|
setInnerType((prevInnerType) => prevInnerType === "password" ? void 0 : "password");
|
|
83
49
|
}, [setInnerType]);
|
|
84
|
-
const
|
|
85
|
-
const PasswordVisibilityToggleIcon = isPasswordVisible ? StyledEyeClosedIcon : StyledEyeOpenIcon;
|
|
50
|
+
const PasswordVisibilityToggleIcon = isPasswordVisible ? EyeClosedIcon : EyeOpenIcon;
|
|
86
51
|
const passwordAction = React.useMemo(() => isPasswordVisible ? "Hide password" : "Show password", [isPasswordVisible]);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
})
|
|
52
|
+
const adornments = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
53
|
+
invalid && /* @__PURE__ */ jsx(ExclamationTriangleIcon, {
|
|
54
|
+
className: "_1q0c5701",
|
|
55
|
+
"aria-hidden": true
|
|
56
|
+
}),
|
|
57
|
+
isPasswordType && /* @__PURE__ */ jsx(Tooltip, {
|
|
58
|
+
content: passwordAction,
|
|
59
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
60
|
+
type: "button",
|
|
61
|
+
className: "_1q0c5702",
|
|
62
|
+
"aria-label": passwordAction,
|
|
63
|
+
onClick: togglePasswordVisibility,
|
|
64
|
+
children: /* @__PURE__ */ jsx(PasswordVisibilityToggleIcon, { "aria-hidden": true })
|
|
65
|
+
})
|
|
66
|
+
}),
|
|
67
|
+
clearable && !clearDisabled && /* @__PURE__ */ jsx(Tooltip, {
|
|
68
|
+
content: "Clear",
|
|
69
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
70
|
+
type: "button",
|
|
71
|
+
className: "_1q0c5702",
|
|
72
|
+
"aria-label": "Clear",
|
|
73
|
+
onClick: handleClear,
|
|
74
|
+
children: /* @__PURE__ */ jsx(CrossCircledIcon, { "aria-hidden": true })
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
] });
|
|
78
|
+
const input = /* @__PURE__ */ jsx(InputVanilla, {
|
|
79
|
+
id,
|
|
80
|
+
ref: inputRef,
|
|
81
|
+
endAdornment: hasInnerAdornment && (hasAdornmentGroup ? /* @__PURE__ */ jsx("div", {
|
|
82
|
+
className: "_1q0c5700",
|
|
83
|
+
children: adornments
|
|
84
|
+
}) : adornments),
|
|
85
|
+
state,
|
|
86
|
+
type: typeOrInnerType,
|
|
87
|
+
disabled,
|
|
88
|
+
readOnly,
|
|
89
|
+
...props
|
|
90
|
+
});
|
|
91
|
+
return /* @__PURE__ */ jsx(FieldVanilla, {
|
|
92
|
+
id,
|
|
93
|
+
label: renderLabel,
|
|
94
|
+
description,
|
|
95
|
+
error,
|
|
96
|
+
announceError,
|
|
97
|
+
invalid: state === "invalid",
|
|
98
|
+
disabled,
|
|
99
|
+
css: {
|
|
100
|
+
boxSizing: "border-box",
|
|
101
|
+
...css
|
|
102
|
+
},
|
|
103
|
+
children: input
|
|
120
104
|
});
|
|
121
105
|
});
|
|
122
106
|
TextFieldVanilla.displayName = "TextFieldVanilla";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.vanilla.js","names":[],"sources":["../../../components/TextField/TextField.vanilla.tsx"],"sourcesContent":["import {\n CrossCircledIcon,\n ExclamationTriangleIcon,\n EyeClosedIcon,\n EyeOpenIcon,\n} from '@radix-ui/react-icons';\nimport React from 'react';\n\nimport {
|
|
1
|
+
{"version":3,"file":"TextField.vanilla.js","names":["_Fragment"],"sources":["../../../components/TextField/TextField.vanilla.tsx"],"sourcesContent":["import {\n CrossCircledIcon,\n ExclamationTriangleIcon,\n EyeClosedIcon,\n EyeOpenIcon,\n} from '@radix-ui/react-icons';\nimport React from 'react';\n\nimport { FieldVanilla } from '../Field/Field.vanilla';\nimport { FieldLabelProps, useFieldContext } from '../Field/FieldContext';\nimport { InputVanilla, InputVanillaHandle, InputVanillaProps } from '../Input';\nimport { Tooltip } from '../Tooltip';\nimport { adornmentButton, adornmentGroup, invalidIcon } from './TextField.vanilla.css';\n\n// TYPES\nexport interface TextFieldLabelProps {\n variant: 'invalid' | 'subtle' | 'contrast' | 'default';\n htmlFor?: string;\n id?: string;\n}\n\nexport type TextFieldVanillaProps = InputVanillaProps & {\n type?: string;\n clearable?: boolean;\n label?: string | ((props: TextFieldLabelProps) => JSX.Element);\n description?: React.ReactNode;\n error?: React.ReactNode;\n announceError?: boolean;\n};\n\nexport const TextFieldVanilla = React.forwardRef<\n React.ElementRef<typeof InputVanilla>,\n TextFieldVanillaProps\n>(\n (\n {\n state,\n clearable,\n label: LabelOrComponent,\n description,\n error,\n announceError,\n id,\n type,\n disabled,\n readOnly,\n css,\n ...props\n },\n forwardedRef,\n ) => {\n const inputRef = React.useRef<InputVanillaHandle | null>(null);\n React.useImperativeHandle(forwardedRef, () => inputRef.current as InputVanillaHandle);\n\n const outerField = useFieldContext();\n const [innerType, setInnerType] = React.useState(type);\n const isPasswordVisible = React.useMemo(() => innerType !== 'password', [innerType]);\n\n const invalid = state === 'invalid' || Boolean(error) || Boolean(outerField?.invalid);\n\n const renderLabel = React.useMemo(() => {\n if (LabelOrComponent === undefined || LabelOrComponent === null) {\n return undefined;\n }\n if (typeof LabelOrComponent === 'string') {\n return LabelOrComponent;\n }\n return (labelProps: FieldLabelProps) => <LabelOrComponent {...labelProps} />;\n }, [LabelOrComponent]);\n\n const isPasswordType = React.useMemo(() => type === 'password', [type]);\n\n const typeOrInnerType = React.useMemo(\n () => (isPasswordType ? innerType : type),\n [isPasswordType, type, innerType],\n );\n\n const hasInnerAdornment = React.useMemo(\n () => clearable || isPasswordType || invalid,\n [clearable, isPasswordType, invalid],\n );\n\n const hasAdornmentGroup = React.useMemo(\n () => (clearable && invalid) || (clearable && isPasswordType) || (invalid && isPasswordType),\n [clearable, invalid, isPasswordType],\n );\n\n const clearDisabled = readOnly || disabled || Boolean(outerField?.disabled);\n\n const handleClear = React.useCallback(() => {\n const { current } = inputRef;\n if (current) {\n const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;\n setValue?.call(current, '');\n current.dispatchEvent(new Event('input', { bubbles: true }));\n current.focus();\n }\n }, [inputRef]);\n\n const togglePasswordVisibility = React.useCallback(() => {\n setInnerType((prevInnerType) => (prevInnerType === 'password' ? undefined : 'password'));\n }, [setInnerType]);\n\n const PasswordVisibilityToggleIcon = isPasswordVisible ? EyeClosedIcon : EyeOpenIcon;\n\n const passwordAction = React.useMemo(\n () => (isPasswordVisible ? 'Hide password' : 'Show password'),\n [isPasswordVisible],\n );\n\n const adornments = (\n <>\n {invalid && <ExclamationTriangleIcon className={invalidIcon} aria-hidden />}\n {isPasswordType && (\n <Tooltip content={passwordAction}>\n <button\n type=\"button\"\n className={adornmentButton}\n aria-label={passwordAction}\n onClick={togglePasswordVisibility}\n >\n <PasswordVisibilityToggleIcon aria-hidden />\n </button>\n </Tooltip>\n )}\n {clearable && !clearDisabled && (\n <Tooltip content=\"Clear\">\n <button\n type=\"button\"\n className={adornmentButton}\n aria-label=\"Clear\"\n onClick={handleClear}\n >\n <CrossCircledIcon aria-hidden />\n </button>\n </Tooltip>\n )}\n </>\n );\n\n const input = (\n <InputVanilla\n id={id}\n ref={inputRef}\n endAdornment={\n hasInnerAdornment &&\n (hasAdornmentGroup ? <div className={adornmentGroup}>{adornments}</div> : adornments)\n }\n state={state}\n type={typeOrInnerType}\n disabled={disabled}\n readOnly={readOnly}\n {...props}\n />\n );\n\n return (\n <FieldVanilla\n id={id}\n label={renderLabel}\n description={description}\n error={error}\n announceError={announceError}\n invalid={state === 'invalid'}\n disabled={disabled}\n css={{ boxSizing: 'border-box', ...css }}\n >\n {input}\n </FieldVanilla>\n );\n },\n);\n\nTextFieldVanilla.displayName = 'TextFieldVanilla';\n"],"mappings":";;;;;;;;;AA8BA,IAAa,mBAAmB,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