@simplybusiness/mobius 5.5.0 → 5.6.1
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/CHANGELOG.md +18 -0
- package/dist/cjs/components/Combobox/Combobox.js +56 -33
- package/dist/cjs/components/Combobox/Combobox.js.map +1 -1
- package/dist/cjs/components/Combobox/Listbox.js +58 -0
- package/dist/cjs/components/Combobox/Listbox.js.map +1 -0
- package/dist/cjs/components/Combobox/Option.js +44 -0
- package/dist/cjs/components/Combobox/Option.js.map +1 -0
- package/dist/cjs/components/Combobox/fixtures.js +115 -0
- package/dist/cjs/components/Combobox/fixtures.js.map +1 -1
- package/dist/cjs/components/Combobox/useComboboxHighlight.js +86 -0
- package/dist/cjs/components/Combobox/useComboboxHighlight.js.map +1 -0
- package/dist/cjs/components/Combobox/utils.js +46 -0
- package/dist/cjs/components/Combobox/utils.js.map +1 -0
- package/dist/cjs/components/TextArea/TextArea.js +4 -4
- package/dist/cjs/components/TextArea/TextArea.js.map +1 -1
- package/dist/cjs/components/TextAreaInput/TextAreaInput.js +6 -3
- package/dist/cjs/components/TextAreaInput/TextAreaInput.js.map +1 -1
- package/dist/cjs/components/TextField/TextField.js +4 -3
- package/dist/cjs/components/TextField/TextField.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/components/Combobox/Combobox.js +55 -32
- package/dist/esm/components/Combobox/Combobox.js.map +1 -1
- package/dist/esm/components/Combobox/Listbox.js +43 -0
- package/dist/esm/components/Combobox/Listbox.js.map +1 -0
- package/dist/esm/components/Combobox/Option.js +29 -0
- package/dist/esm/components/Combobox/Option.js.map +1 -0
- package/dist/esm/components/Combobox/fixtures.js +109 -0
- package/dist/esm/components/Combobox/fixtures.js.map +1 -1
- package/dist/esm/components/Combobox/types.js.map +1 -1
- package/dist/esm/components/Combobox/useComboboxHighlight.js +76 -0
- package/dist/esm/components/Combobox/useComboboxHighlight.js.map +1 -0
- package/dist/esm/components/Combobox/utils.js +20 -0
- package/dist/esm/components/Combobox/utils.js.map +1 -0
- package/dist/esm/components/TextArea/TextArea.js +4 -4
- package/dist/esm/components/TextArea/TextArea.js.map +1 -1
- package/dist/esm/components/TextAreaInput/TextAreaInput.js +6 -3
- package/dist/esm/components/TextAreaInput/TextAreaInput.js.map +1 -1
- package/dist/esm/components/TextField/TextField.js +4 -3
- package/dist/esm/components/TextField/TextField.js.map +1 -1
- package/dist/types/components/Combobox/Combobox.d.ts +1 -1
- package/dist/types/components/Combobox/Combobox.stories.d.ts +4 -1
- package/dist/types/components/Combobox/Listbox.d.ts +10 -0
- package/dist/types/components/Combobox/Option.d.ts +2 -0
- package/dist/types/components/Combobox/fixtures.d.ts +5 -0
- package/dist/types/components/Combobox/types.d.ts +17 -2
- package/dist/types/components/Combobox/useComboboxHighlight.d.ts +10 -0
- package/dist/types/components/Combobox/useComboboxHighlight.test.d.ts +1 -0
- package/dist/types/components/Combobox/utils.d.ts +6 -0
- package/dist/types/components/Combobox/utils.test.d.ts +1 -0
- package/dist/types/components/TextArea/TextArea.d.ts +2 -2
- package/dist/types/components/TextAreaInput/TextAreaInput.d.ts +3 -1
- package/package.json +1 -1
- package/src/components/Combobox/Combobox.css +51 -4
- package/src/components/Combobox/Combobox.mdx +147 -0
- package/src/components/Combobox/Combobox.stories.tsx +47 -2
- package/src/components/Combobox/Combobox.test.tsx +535 -316
- package/src/components/Combobox/Combobox.tsx +78 -58
- package/src/components/Combobox/Listbox.tsx +74 -0
- package/src/components/Combobox/Option.tsx +41 -0
- package/src/components/Combobox/fixtures.tsx +111 -0
- package/src/components/Combobox/types.tsx +22 -4
- package/src/components/Combobox/useComboboxHighlight.test.tsx +242 -0
- package/src/components/Combobox/useComboboxHighlight.tsx +88 -0
- package/src/components/Combobox/utils.test.tsx +120 -0
- package/src/components/Combobox/utils.tsx +50 -0
- package/src/components/TextArea/TextArea.tsx +6 -6
- package/src/components/TextAreaInput/TextAreaInput.tsx +16 -4
- package/src/components/TextField/TextField.test.tsx +8 -0
- package/src/components/TextField/TextField.tsx +3 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
clamp: function() {
|
|
13
|
+
return clamp;
|
|
14
|
+
},
|
|
15
|
+
filterOptions: function() {
|
|
16
|
+
return filterOptions;
|
|
17
|
+
},
|
|
18
|
+
getOptionLabel: function() {
|
|
19
|
+
return getOptionLabel;
|
|
20
|
+
},
|
|
21
|
+
getOptionValue: function() {
|
|
22
|
+
return getOptionValue;
|
|
23
|
+
},
|
|
24
|
+
isOptionGroup: function() {
|
|
25
|
+
return isOptionGroup;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
function isOptionGroup(options) {
|
|
29
|
+
return typeof options[0] === "object" && "options" in options[0] && options[0].options !== undefined && "heading" in options[0] && options[0].heading !== undefined;
|
|
30
|
+
}
|
|
31
|
+
const getOptionValue = (option)=>typeof option === "string" ? option : option === null || option === void 0 ? void 0 : option.value;
|
|
32
|
+
const getOptionLabel = (option)=>typeof option === "string" ? option : option === null || option === void 0 ? void 0 : option.label;
|
|
33
|
+
function filterOptions(options, inputValue) {
|
|
34
|
+
if (isOptionGroup(options)) {
|
|
35
|
+
return options.map((optionGroup)=>({
|
|
36
|
+
...optionGroup,
|
|
37
|
+
options: optionGroup.options.filter((option)=>getOptionLabel(option).toLowerCase().includes(inputValue.toLowerCase()))
|
|
38
|
+
})).filter((optionGroup)=>optionGroup.options.length > 0);
|
|
39
|
+
}
|
|
40
|
+
return options.filter((option)=>getOptionLabel(option).toLowerCase().includes(inputValue.toLowerCase()));
|
|
41
|
+
}
|
|
42
|
+
function clamp(value, min, max) {
|
|
43
|
+
return Math.min(Math.max(value, min), max);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Combobox/utils.tsx"],"sourcesContent":["import type {\n ComboboxOption,\n ComboboxOptionGroup,\n ComboboxOptions,\n} from \"./types\";\n\n// FIXME: This might be better handled with Zod\nexport function isOptionGroup(\n options: ComboboxOptions,\n): options is ComboboxOptionGroup[] {\n return (\n typeof options[0] === \"object\" &&\n \"options\" in options[0] &&\n options[0].options !== undefined &&\n \"heading\" in options[0] &&\n options[0].heading !== undefined\n );\n}\n\nexport const getOptionValue = (option: ComboboxOption | undefined) =>\n typeof option === \"string\" ? option : option?.value;\n\nexport const getOptionLabel = (option: ComboboxOption | undefined) =>\n typeof option === \"string\" ? option : option?.label;\n\nexport function filterOptions(\n options: ComboboxOptions,\n inputValue: string,\n): ComboboxOptions {\n if (isOptionGroup(options)) {\n return options\n .map(optionGroup => ({\n ...optionGroup,\n options: optionGroup.options.filter(option =>\n getOptionLabel(option)!\n .toLowerCase()\n .includes(inputValue.toLowerCase()),\n ),\n }))\n .filter(optionGroup => optionGroup.options.length > 0);\n }\n\n return options.filter(option =>\n getOptionLabel(option)!.toLowerCase().includes(inputValue.toLowerCase()),\n );\n}\n\nexport function clamp(value: number, min: number, max: number) {\n return Math.min(Math.max(value, min), max);\n}\n"],"names":["clamp","filterOptions","getOptionLabel","getOptionValue","isOptionGroup","options","undefined","heading","option","value","label","inputValue","map","optionGroup","filter","toLowerCase","includes","length","min","max","Math"],"mappings":";;;;;;;;;;;IA+CgBA,KAAK;eAALA;;IAtBAC,aAAa;eAAbA;;IAHHC,cAAc;eAAdA;;IAHAC,cAAc;eAAdA;;IAZGC,aAAa;eAAbA;;;AAAT,SAASA,cACdC,OAAwB;IAExB,OACE,OAAOA,OAAO,CAAC,EAAE,KAAK,YACtB,aAAaA,OAAO,CAAC,EAAE,IACvBA,OAAO,CAAC,EAAE,CAACA,OAAO,KAAKC,aACvB,aAAaD,OAAO,CAAC,EAAE,IACvBA,OAAO,CAAC,EAAE,CAACE,OAAO,KAAKD;AAE3B;AAEO,MAAMH,iBAAiB,CAACK,SAC7B,OAAOA,WAAW,WAAWA,SAASA,mBAAAA,6BAAAA,OAAQC,KAAK;AAE9C,MAAMP,iBAAiB,CAACM,SAC7B,OAAOA,WAAW,WAAWA,SAASA,mBAAAA,6BAAAA,OAAQE,KAAK;AAE9C,SAAST,cACdI,OAAwB,EACxBM,UAAkB;IAElB,IAAIP,cAAcC,UAAU;QAC1B,OAAOA,QACJO,GAAG,CAACC,CAAAA,cAAgB,CAAA;gBACnB,GAAGA,WAAW;gBACdR,SAASQ,YAAYR,OAAO,CAACS,MAAM,CAACN,CAAAA,SAClCN,eAAeM,QACZO,WAAW,GACXC,QAAQ,CAACL,WAAWI,WAAW;YAEtC,CAAA,GACCD,MAAM,CAACD,CAAAA,cAAeA,YAAYR,OAAO,CAACY,MAAM,GAAG;IACxD;IAEA,OAAOZ,QAAQS,MAAM,CAACN,CAAAA,SACpBN,eAAeM,QAASO,WAAW,GAAGC,QAAQ,CAACL,WAAWI,WAAW;AAEzE;AAEO,SAASf,MAAMS,KAAa,EAAES,GAAW,EAAEC,GAAW;IAC3D,OAAOC,KAAKF,GAAG,CAACE,KAAKD,GAAG,CAACV,OAAOS,MAAMC;AACxC"}
|
|
@@ -10,13 +10,13 @@ Object.defineProperty(exports, "TextArea", {
|
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
const _jsxruntime = require("react/jsx-runtime");
|
|
13
|
-
const _react = require("react");
|
|
14
13
|
const _dedupe = /*#__PURE__*/ _interop_require_default(require("classnames/dedupe"));
|
|
15
|
-
const
|
|
16
|
-
const _Label = require("../Label");
|
|
17
|
-
const _ErrorMessage = require("../ErrorMessage");
|
|
14
|
+
const _react = require("react");
|
|
18
15
|
const _hooks = require("../../hooks");
|
|
16
|
+
const _ErrorMessage = require("../ErrorMessage");
|
|
17
|
+
const _Label = require("../Label");
|
|
19
18
|
const _Stack = require("../Stack");
|
|
19
|
+
const _TextAreaInput = require("../TextAreaInput");
|
|
20
20
|
function _interop_require_default(obj) {
|
|
21
21
|
return obj && obj.__esModule ? obj : {
|
|
22
22
|
default: obj
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/TextArea/TextArea.tsx"],"sourcesContent":["\"use client\";\n\nimport { Ref,
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/TextArea/TextArea.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport { Ref, RefAttributes, forwardRef } from \"react\";\nimport {\n UseTextFieldProps,\n useTextField,\n useValidationClasses,\n} from \"../../hooks\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { DOMProps } from \"../../types/dom\";\nimport { ErrorMessage } from \"../ErrorMessage\";\nimport { Label } from \"../Label\";\nimport { Stack } from \"../Stack\";\nimport { TextAreaInput } from \"../TextAreaInput\";\n\nexport type TextAreaElementType = HTMLTextAreaElement;\n\nexport interface TextAreaProps\n extends UseTextFieldProps,\n DOMProps,\n RefAttributes<TextAreaElementType> {\n className?: string;\n errorMessage?: string;\n}\n\nexport type TextAreaRef = Ref<TextAreaElementType>;\n\nconst TextArea: ForwardedRefComponent<TextAreaProps, TextAreaElementType> =\n forwardRef((props: TextAreaProps, ref: TextAreaRef) => {\n const {\n isDisabled,\n className,\n errorMessage,\n label,\n validationState,\n isInvalid,\n ...otherProps\n } = props;\n\n const { inputProps, labelProps, errorMessageProps } = useTextField(props);\n\n // Set class name for atom, including interaction state\n const classes = classNames(\"mobius\", \"mobius-text-area\", className);\n const validationClasses = useValidationClasses({\n validationState,\n isInvalid,\n });\n const inputClasses = classNames(\n \"mobius-text-area__input\",\n validationClasses,\n );\n const labelClasses = classNames(\n {\n \"--is-disabled\": isDisabled,\n },\n validationClasses,\n );\n\n return (\n <Stack className={classes} gap=\"xs\">\n {label && (\n <Label {...labelProps} className={labelClasses}>\n {props.label}\n </Label>\n )}\n <TextAreaInput\n {...otherProps}\n {...inputProps}\n ref={ref}\n className={inputClasses}\n isDisabled={isDisabled}\n aria-invalid={errorMessage != null}\n />\n <ErrorMessage {...errorMessageProps} errorMessage={errorMessage} />\n </Stack>\n );\n });\n\nTextArea.displayName = \"TextArea\";\nexport { TextArea };\n"],"names":["TextArea","forwardRef","props","ref","isDisabled","className","errorMessage","label","validationState","isInvalid","otherProps","inputProps","labelProps","errorMessageProps","useTextField","classes","classNames","validationClasses","useValidationClasses","inputClasses","labelClasses","Stack","gap","Label","TextAreaInput","aria-invalid","ErrorMessage","displayName"],"mappings":"AAAA;;;;;+BAgFSA;;;eAAAA;;;;+DA9Ec;uBACwB;uBAKxC;8BAGsB;uBACP;uBACA;+BACQ;;;;;;AAc9B,MAAMA,yBACJC,IAAAA,iBAAU,EAAC,CAACC,OAAsBC;IAChC,MAAM,EACJC,UAAU,EACVC,SAAS,EACTC,YAAY,EACZC,KAAK,EACLC,eAAe,EACfC,SAAS,EACT,GAAGC,YACJ,GAAGR;IAEJ,MAAM,EAAES,UAAU,EAAEC,UAAU,EAAEC,iBAAiB,EAAE,GAAGC,IAAAA,mBAAY,EAACZ;IAEnE,uDAAuD;IACvD,MAAMa,UAAUC,IAAAA,eAAU,EAAC,UAAU,oBAAoBX;IACzD,MAAMY,oBAAoBC,IAAAA,2BAAoB,EAAC;QAC7CV;QACAC;IACF;IACA,MAAMU,eAAeH,IAAAA,eAAU,EAC7B,2BACAC;IAEF,MAAMG,eAAeJ,IAAAA,eAAU,EAC7B;QACE,iBAAiBZ;IACnB,GACAa;IAGF,qBACE,sBAACI,YAAK;QAAChB,WAAWU;QAASO,KAAI;;YAC5Bf,uBACC,qBAACgB,YAAK;gBAAE,GAAGX,UAAU;gBAAEP,WAAWe;0BAC/BlB,MAAMK,KAAK;;0BAGhB,qBAACiB,4BAAa;gBACX,GAAGd,UAAU;gBACb,GAAGC,UAAU;gBACdR,KAAKA;gBACLE,WAAWc;gBACXf,YAAYA;gBACZqB,gBAAcnB,gBAAgB;;0BAEhC,qBAACoB,0BAAY;gBAAE,GAAGb,iBAAiB;gBAAEP,cAAcA;;;;AAGzD;AAEFN,SAAS2B,WAAW,GAAG"}
|
|
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "TextAreaInput", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _jsxruntime = require("react/jsx-runtime");
|
|
12
|
-
const _react = require("react");
|
|
13
12
|
const _dedupe = /*#__PURE__*/ _interop_require_default(require("classnames/dedupe"));
|
|
13
|
+
const _react = require("react");
|
|
14
14
|
function _interop_require_default(obj) {
|
|
15
15
|
return obj && obj.__esModule ? obj : {
|
|
16
16
|
default: obj
|
|
@@ -18,14 +18,17 @@ function _interop_require_default(obj) {
|
|
|
18
18
|
}
|
|
19
19
|
const TextAreaInput = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
20
20
|
// Extract interaction props:
|
|
21
|
-
const { isSelected, isDisabled, ...otherProps } = props;
|
|
21
|
+
const { isSelected, isDisabled, isReadOnly, isRequired, ...otherProps } = props;
|
|
22
22
|
const classes = (0, _dedupe.default)("mobius", "mobius-text-area__input", {
|
|
23
23
|
"--is-disabled": isDisabled,
|
|
24
|
-
"--is-selected": isSelected
|
|
24
|
+
"--is-selected": isSelected,
|
|
25
|
+
"--is-required": isRequired
|
|
25
26
|
}, otherProps.className);
|
|
26
27
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)("textarea", {
|
|
27
28
|
ref: ref,
|
|
28
29
|
...otherProps,
|
|
30
|
+
required: isRequired,
|
|
31
|
+
readOnly: isReadOnly,
|
|
29
32
|
className: classes
|
|
30
33
|
});
|
|
31
34
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/TextAreaInput/TextAreaInput.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/TextAreaInput/TextAreaInput.tsx"],"sourcesContent":["import classNames from \"classnames/dedupe\";\nimport { forwardRef, Ref, RefAttributes } from \"react\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { DOMProps } from \"../../types/dom\";\n\nexport type TextAreaInputElementType = HTMLTextAreaElement;\n\nexport interface InteractionStateProps {\n isSelected?: boolean;\n isDisabled?: boolean;\n}\n\nexport interface TextAreaInputProps\n extends DOMProps,\n InteractionStateProps,\n RefAttributes<TextAreaInputElementType> {\n className?: string;\n isReadOnly?: boolean;\n isRequired?: boolean;\n}\n\nexport type TextAreaInputRef = Ref<TextAreaInputElementType>;\n\nconst TextAreaInput: ForwardedRefComponent<\n TextAreaInputProps,\n TextAreaInputElementType\n> = forwardRef((props: TextAreaInputProps, ref: TextAreaInputRef) => {\n // Extract interaction props:\n const { isSelected, isDisabled, isReadOnly, isRequired, ...otherProps } =\n props;\n\n const classes = classNames(\n \"mobius\",\n \"mobius-text-area__input\",\n {\n \"--is-disabled\": isDisabled,\n \"--is-selected\": isSelected,\n \"--is-required\": isRequired,\n },\n otherProps.className,\n );\n\n return (\n <textarea\n ref={ref}\n {...otherProps}\n required={isRequired}\n readOnly={isReadOnly}\n className={classes}\n />\n );\n});\n\nTextAreaInput.displayName = \"TextAreaInput\";\nexport { TextAreaInput };\n"],"names":["TextAreaInput","forwardRef","props","ref","isSelected","isDisabled","isReadOnly","isRequired","otherProps","classes","classNames","className","textarea","required","readOnly","displayName"],"mappings":";;;;+BAsDSA;;;eAAAA;;;;+DAtDc;uBACwB;;;;;;AAsB/C,MAAMA,8BAGFC,IAAAA,iBAAU,EAAC,CAACC,OAA2BC;IACzC,6BAA6B;IAC7B,MAAM,EAAEC,UAAU,EAAEC,UAAU,EAAEC,UAAU,EAAEC,UAAU,EAAE,GAAGC,YAAY,GACrEN;IAEF,MAAMO,UAAUC,IAAAA,eAAU,EACxB,UACA,2BACA;QACE,iBAAiBL;QACjB,iBAAiBD;QACjB,iBAAiBG;IACnB,GACAC,WAAWG,SAAS;IAGtB,qBACE,qBAACC;QACCT,KAAKA;QACJ,GAAGK,UAAU;QACdK,UAAUN;QACVO,UAAUR;QACVK,WAAWF;;AAGjB;AAEAT,cAAce,WAAW,GAAG"}
|
|
@@ -15,15 +15,15 @@ const _react = require("react");
|
|
|
15
15
|
const _hooks = require("../../hooks");
|
|
16
16
|
const _ErrorMessage = require("../ErrorMessage");
|
|
17
17
|
const _Label = require("../Label");
|
|
18
|
-
const _adornmentWithClassName = require("./adornmentWithClassName");
|
|
19
18
|
const _Stack = require("../Stack");
|
|
19
|
+
const _adornmentWithClassName = require("./adornmentWithClassName");
|
|
20
20
|
function _interop_require_default(obj) {
|
|
21
21
|
return obj && obj.__esModule ? obj : {
|
|
22
22
|
default: obj
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
const TextField = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
26
|
-
const { isDisabled, type = "text", validationState, isInvalid, className, label, errorMessage, children, isRequired, prefixInside, prefixOutside, suffixInside, suffixOutside, ...otherProps } = props;
|
|
26
|
+
const { isDisabled, isReadOnly, type = "text", validationState, isInvalid, className, label, errorMessage, children, isRequired, prefixInside, prefixOutside, suffixInside, suffixOutside, ...otherProps } = props;
|
|
27
27
|
const { inputProps, labelProps, errorMessageProps } = (0, _hooks.useTextField)({
|
|
28
28
|
...props,
|
|
29
29
|
"aria-errormessage": errorMessage
|
|
@@ -69,7 +69,8 @@ const TextField = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
69
69
|
...inputProps,
|
|
70
70
|
ref: ref,
|
|
71
71
|
type: type,
|
|
72
|
-
className: inputClasses
|
|
72
|
+
className: inputClasses,
|
|
73
|
+
readOnly: isReadOnly
|
|
73
74
|
}),
|
|
74
75
|
(0, _adornmentWithClassName.adornmentWithClassName)(suffixInside, "mobius-text-field__suffix-inside")
|
|
75
76
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/TextField/TextField.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport {\n HTMLInputTypeAttribute,\n ReactElement,\n ReactNode,\n Ref,\n RefAttributes,\n forwardRef,\n} from \"react\";\nimport {\n UseTextFieldProps,\n useTextField,\n useValidationClasses,\n} from \"../../hooks\";\nimport { DOMProps, FocusEvents } from \"../../types\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { ErrorMessage } from \"../ErrorMessage\";\nimport { Label } from \"../Label\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/TextField/TextField.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport {\n HTMLInputTypeAttribute,\n ReactElement,\n ReactNode,\n Ref,\n RefAttributes,\n forwardRef,\n} from \"react\";\nimport {\n UseTextFieldProps,\n useTextField,\n useValidationClasses,\n} from \"../../hooks\";\nimport { DOMProps, FocusEvents } from \"../../types\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { ErrorMessage } from \"../ErrorMessage\";\nimport { Label } from \"../Label\";\nimport { Stack } from \"../Stack\";\nimport { adornmentWithClassName } from \"./adornmentWithClassName\";\n\nexport type TextFieldElementType = HTMLInputElement;\nexport interface TextFieldProps\n extends DOMProps,\n FocusEvents,\n UseTextFieldProps,\n RefAttributes<TextFieldElementType> {\n className?: string;\n errorMessage?: string;\n children?: ReactNode;\n label?: string;\n type?: Exclude<\n HTMLInputTypeAttribute,\n | \"button\"\n | \"checkbox\"\n | \"color\"\n | \"date\"\n | \"datetime-local\"\n | \"file\"\n | \"image\"\n | \"month\"\n | \"radio\"\n | \"range\"\n | \"reset\"\n | \"submit\"\n | \"week\"\n >;\n prefixInside?: ReactElement;\n prefixOutside?: ReactElement;\n suffixInside?: ReactElement;\n suffixOutside?: ReactElement;\n}\n\nexport type TextFieldRef = Ref<TextFieldElementType>;\n\nconst TextField: ForwardedRefComponent<TextFieldProps, TextFieldElementType> =\n forwardRef((props: TextFieldProps, ref: TextFieldRef) => {\n const {\n isDisabled,\n isReadOnly,\n type = \"text\",\n validationState,\n isInvalid,\n className,\n label,\n errorMessage,\n children,\n isRequired,\n prefixInside,\n prefixOutside,\n suffixInside,\n suffixOutside,\n ...otherProps\n } = props;\n\n const { inputProps, labelProps, errorMessageProps } = useTextField({\n ...props,\n \"aria-errormessage\": errorMessage,\n });\n\n const hidden = type === \"hidden\";\n\n const validationClasses = useValidationClasses({\n validationState,\n isInvalid,\n });\n\n const textfieldClasses = {\n \"--is-disabled\": isDisabled,\n \"--is-required\": typeof isRequired === \"boolean\" && isRequired,\n \"--is-optional\": typeof isRequired === \"boolean\" && !isRequired,\n \"--is-hidden\": hidden,\n [className || \"\"]: true,\n };\n\n const sharedClasses = classNames(validationClasses, textfieldClasses);\n\n const labelClasses = classNames(\n {\n \"--is-disabled\": isDisabled,\n },\n validationClasses,\n );\n\n const containerClasses = classNames(\n \"mobius\",\n \"mobius-text-field\",\n sharedClasses,\n );\n\n const inputClasses = classNames(\n \"mobius\",\n \"mobius-text-field__input\",\n sharedClasses,\n );\n\n const inputWrapperClasses = classNames(\n \"mobius-text-field__input-wrapper\",\n sharedClasses,\n );\n\n return (\n <Stack gap=\"xs\" className={containerClasses}>\n {label && !hidden && (\n <Label {...labelProps} className={labelClasses}>\n {label}\n </Label>\n )}\n <div className=\"mobius-text-field__inner-container\">\n {adornmentWithClassName(\n prefixOutside,\n \"mobius-text-field__prefix-outside\",\n )}\n <div className={inputWrapperClasses}>\n {adornmentWithClassName(\n prefixInside,\n \"mobius-text-field__prefix-inside\",\n )}\n <input\n {...otherProps}\n {...inputProps}\n ref={ref}\n type={type}\n className={inputClasses}\n readOnly={isReadOnly}\n />\n {adornmentWithClassName(\n suffixInside,\n \"mobius-text-field__suffix-inside\",\n )}\n </div>\n {adornmentWithClassName(\n suffixOutside,\n \"mobius-text-field__suffix-outside\",\n )}\n </div>\n {children && (\n <div className=\"mobius-text-field__children\">{children}</div>\n )}\n\n <ErrorMessage {...errorMessageProps} errorMessage={errorMessage} />\n </Stack>\n );\n });\n\nTextField.displayName = \"TextField\";\nexport { TextField };\n"],"names":["TextField","forwardRef","props","ref","isDisabled","isReadOnly","type","validationState","isInvalid","className","label","errorMessage","children","isRequired","prefixInside","prefixOutside","suffixInside","suffixOutside","otherProps","inputProps","labelProps","errorMessageProps","useTextField","hidden","validationClasses","useValidationClasses","textfieldClasses","sharedClasses","classNames","labelClasses","containerClasses","inputClasses","inputWrapperClasses","Stack","gap","Label","div","adornmentWithClassName","input","readOnly","ErrorMessage","displayName"],"mappings":"AAAA;;;;;+BAwKSA;;;eAAAA;;;;+DAtKc;uBAQhB;uBAKA;8BAGsB;uBACP;uBACA;wCACiB;;;;;;AAoCvC,MAAMA,0BACJC,IAAAA,iBAAU,EAAC,CAACC,OAAuBC;IACjC,MAAM,EACJC,UAAU,EACVC,UAAU,EACVC,OAAO,MAAM,EACbC,eAAe,EACfC,SAAS,EACTC,SAAS,EACTC,KAAK,EACLC,YAAY,EACZC,QAAQ,EACRC,UAAU,EACVC,YAAY,EACZC,aAAa,EACbC,YAAY,EACZC,aAAa,EACb,GAAGC,YACJ,GAAGhB;IAEJ,MAAM,EAAEiB,UAAU,EAAEC,UAAU,EAAEC,iBAAiB,EAAE,GAAGC,IAAAA,mBAAY,EAAC;QACjE,GAAGpB,KAAK;QACR,qBAAqBS;IACvB;IAEA,MAAMY,SAASjB,SAAS;IAExB,MAAMkB,oBAAoBC,IAAAA,2BAAoB,EAAC;QAC7ClB;QACAC;IACF;IAEA,MAAMkB,mBAAmB;QACvB,iBAAiBtB;QACjB,iBAAiB,OAAOS,eAAe,aAAaA;QACpD,iBAAiB,OAAOA,eAAe,aAAa,CAACA;QACrD,eAAeU;QACf,CAACd,aAAa,GAAG,EAAE;IACrB;IAEA,MAAMkB,gBAAgBC,IAAAA,eAAU,EAACJ,mBAAmBE;IAEpD,MAAMG,eAAeD,IAAAA,eAAU,EAC7B;QACE,iBAAiBxB;IACnB,GACAoB;IAGF,MAAMM,mBAAmBF,IAAAA,eAAU,EACjC,UACA,qBACAD;IAGF,MAAMI,eAAeH,IAAAA,eAAU,EAC7B,UACA,4BACAD;IAGF,MAAMK,sBAAsBJ,IAAAA,eAAU,EACpC,oCACAD;IAGF,qBACE,sBAACM,YAAK;QAACC,KAAI;QAAKzB,WAAWqB;;YACxBpB,SAAS,CAACa,wBACT,qBAACY,YAAK;gBAAE,GAAGf,UAAU;gBAAEX,WAAWoB;0BAC/BnB;;0BAGL,sBAAC0B;gBAAI3B,WAAU;;oBACZ4B,IAAAA,8CAAsB,EACrBtB,eACA;kCAEF,sBAACqB;wBAAI3B,WAAWuB;;4BACbK,IAAAA,8CAAsB,EACrBvB,cACA;0CAEF,qBAACwB;gCACE,GAAGpB,UAAU;gCACb,GAAGC,UAAU;gCACdhB,KAAKA;gCACLG,MAAMA;gCACNG,WAAWsB;gCACXQ,UAAUlC;;4BAEXgC,IAAAA,8CAAsB,EACrBrB,cACA;;;oBAGHqB,IAAAA,8CAAsB,EACrBpB,eACA;;;YAGHL,0BACC,qBAACwB;gBAAI3B,WAAU;0BAA+BG;;0BAGhD,qBAAC4B,0BAAY;gBAAE,GAAGnB,iBAAiB;gBAAEV,cAAcA;;;;AAGzD;AAEFX,UAAUyC,WAAW,GAAG"}
|