@hitachivantara/uikit-react-core 5.82.1 → 5.82.3
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/cjs/BaseInput/BaseInput.cjs +11 -12
- package/dist/cjs/BaseInput/validations.cjs +3 -3
- package/dist/cjs/Calendar/Calendar.cjs +14 -15
- package/dist/cjs/Calendar/CalendarHeader/CalendarHeader.cjs +8 -10
- package/dist/cjs/CheckBox/CheckBox.cjs +10 -10
- package/dist/cjs/CheckBoxGroup/CheckBoxGroup.cjs +8 -8
- package/dist/cjs/ColorPicker/ColorPicker.cjs +6 -9
- package/dist/cjs/DatePicker/DatePicker.cjs +15 -15
- package/dist/cjs/Dropdown/Dropdown.cjs +9 -9
- package/dist/cjs/FileUploader/DropZone/DropZone.cjs +2 -2
- package/dist/cjs/FilterGroup/FilterGroup.cjs +6 -6
- package/dist/cjs/{Forms → FormElement}/Adornment/Adornment.cjs +9 -10
- package/dist/cjs/{Forms → FormElement}/CharCounter/CharCounter.cjs +15 -15
- package/dist/cjs/FormElement/FormElement.cjs +35 -0
- package/dist/cjs/{Forms → FormElement}/InfoMessage/InfoMessage.cjs +8 -8
- package/dist/cjs/{Forms → FormElement}/Label/Label.cjs +13 -13
- package/dist/cjs/{Forms → FormElement}/Suggestions/Suggestions.cjs +6 -6
- package/dist/cjs/{Forms → FormElement}/WarningText/WarningText.cjs +5 -5
- package/dist/cjs/FormElement/context.cjs +11 -0
- package/dist/cjs/{Forms/FormElement/utils/FormUtils.cjs → FormElement/utils.cjs} +19 -11
- package/dist/cjs/Input/Input.cjs +17 -17
- package/dist/cjs/Input/Input.styles.cjs +2 -2
- package/dist/cjs/QueryBuilder/Rule/Value/DateTimeValue/DateTimeValue.cjs +1 -1
- package/dist/cjs/Radio/Radio.cjs +10 -13
- package/dist/cjs/RadioGroup/RadioGroup.cjs +7 -7
- package/dist/cjs/Select/Select.cjs +4 -4
- package/dist/cjs/SelectionList/SelectionList.cjs +7 -7
- package/dist/cjs/Slider/Slider.cjs +10 -10
- package/dist/cjs/Slider/utils.cjs +7 -7
- package/dist/cjs/Switch/Switch.cjs +9 -12
- package/dist/cjs/TagsInput/TagsInput.cjs +17 -17
- package/dist/cjs/TagsInput/TagsInput.styles.cjs +1 -1
- package/dist/cjs/TextArea/TextArea.cjs +17 -17
- package/dist/cjs/TimePicker/TimePicker.cjs +7 -7
- package/dist/cjs/index.cjs +15 -36
- package/dist/esm/BaseInput/BaseInput.js +5 -6
- package/dist/esm/BaseInput/BaseInput.js.map +1 -1
- package/dist/esm/BaseInput/validations.js +3 -3
- package/dist/esm/BaseInput/validations.js.map +1 -1
- package/dist/esm/Calendar/Calendar.js +13 -14
- package/dist/esm/Calendar/Calendar.js.map +1 -1
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.js +6 -8
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.js.map +1 -1
- package/dist/esm/Calendar/CalendarNavigation/MonthSelector/MonthSelector.js.map +1 -1
- package/dist/esm/CheckBox/CheckBox.js +9 -9
- package/dist/esm/CheckBox/CheckBox.js.map +1 -1
- package/dist/esm/CheckBoxGroup/CheckBoxGroup.js +8 -8
- package/dist/esm/CheckBoxGroup/CheckBoxGroup.js.map +1 -1
- package/dist/esm/ColorPicker/ColorPicker.js +6 -9
- package/dist/esm/ColorPicker/ColorPicker.js.map +1 -1
- package/dist/esm/DatePicker/DatePicker.js +9 -9
- package/dist/esm/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/Dropdown/Dropdown.js +8 -8
- package/dist/esm/Dropdown/Dropdown.js.map +1 -1
- package/dist/esm/FileUploader/DropZone/DropZone.js +2 -2
- package/dist/esm/FileUploader/DropZone/DropZone.js.map +1 -1
- package/dist/esm/FilterGroup/FilterContent/FilterContent.js.map +1 -1
- package/dist/esm/FilterGroup/FilterGroup.js +6 -6
- package/dist/esm/FilterGroup/FilterGroup.js.map +1 -1
- package/dist/esm/{Forms → FormElement}/Adornment/Adornment.js +8 -9
- package/dist/esm/FormElement/Adornment/Adornment.js.map +1 -0
- package/dist/esm/FormElement/Adornment/Adornment.styles.js.map +1 -0
- package/dist/esm/{Forms → FormElement}/CharCounter/CharCounter.js +15 -15
- package/dist/esm/FormElement/CharCounter/CharCounter.js.map +1 -0
- package/dist/esm/FormElement/CharCounter/CharCounter.styles.js.map +1 -0
- package/dist/esm/FormElement/FormElement.js +36 -0
- package/dist/esm/FormElement/FormElement.js.map +1 -0
- package/dist/esm/FormElement/FormElement.styles.js.map +1 -0
- package/dist/esm/{Forms → FormElement}/InfoMessage/InfoMessage.js +8 -8
- package/dist/esm/FormElement/InfoMessage/InfoMessage.js.map +1 -0
- package/dist/esm/FormElement/InfoMessage/InfoMessage.styles.js.map +1 -0
- package/dist/esm/{Forms → FormElement}/Label/Label.js +12 -12
- package/dist/esm/FormElement/Label/Label.js.map +1 -0
- package/dist/esm/FormElement/Label/Label.styles.js.map +1 -0
- package/dist/esm/{Forms → FormElement}/Suggestions/Suggestions.js +6 -6
- package/dist/esm/FormElement/Suggestions/Suggestions.js.map +1 -0
- package/dist/esm/FormElement/Suggestions/Suggestions.styles.js.map +1 -0
- package/dist/esm/{Forms → FormElement}/WarningText/WarningText.js +5 -5
- package/dist/esm/FormElement/WarningText/WarningText.js.map +1 -0
- package/dist/esm/FormElement/WarningText/WarningText.styles.js.map +1 -0
- package/dist/esm/FormElement/context.js +11 -0
- package/dist/esm/FormElement/context.js.map +1 -0
- package/dist/esm/{Forms/FormElement/utils/FormUtils.js → FormElement/utils.js} +21 -11
- package/dist/esm/FormElement/utils.js.map +1 -0
- package/dist/esm/Input/Input.js +21 -21
- package/dist/esm/Input/Input.js.map +1 -1
- package/dist/esm/Input/Input.styles.js +2 -2
- package/dist/esm/Input/Input.styles.js.map +1 -1
- package/dist/esm/QueryBuilder/Rule/Value/DateTimeValue/DateTimeValue.js +1 -1
- package/dist/esm/QueryBuilder/Rule/Value/DateTimeValue/DateTimeValue.js.map +1 -1
- package/dist/esm/QueryBuilder/Rule/Value/TextValue/TextValue.js.map +1 -1
- package/dist/esm/Radio/Radio.js +9 -12
- package/dist/esm/Radio/Radio.js.map +1 -1
- package/dist/esm/RadioGroup/RadioGroup.js +7 -7
- package/dist/esm/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/esm/Select/Select.js +4 -4
- package/dist/esm/Select/Select.js.map +1 -1
- package/dist/esm/SelectionList/SelectionList.js +7 -7
- package/dist/esm/SelectionList/SelectionList.js.map +1 -1
- package/dist/esm/Slider/Slider.js +10 -10
- package/dist/esm/Slider/Slider.js.map +1 -1
- package/dist/esm/Slider/SliderInput/SliderInput.js.map +1 -1
- package/dist/esm/Slider/utils.js +7 -7
- package/dist/esm/Slider/utils.js.map +1 -1
- package/dist/esm/Switch/Switch.js +8 -11
- package/dist/esm/Switch/Switch.js.map +1 -1
- package/dist/esm/TagsInput/TagsInput.js +19 -19
- package/dist/esm/TagsInput/TagsInput.js.map +1 -1
- package/dist/esm/TagsInput/TagsInput.styles.js +1 -1
- package/dist/esm/TagsInput/TagsInput.styles.js.map +1 -1
- package/dist/esm/TextArea/TextArea.js +19 -19
- package/dist/esm/TextArea/TextArea.js.map +1 -1
- package/dist/esm/TimePicker/TimePicker.js +7 -7
- package/dist/esm/TimePicker/TimePicker.js.map +1 -1
- package/dist/esm/index.js +14 -35
- package/dist/esm/index.js.map +1 -1
- package/dist/types/index.d.ts +66 -143
- package/package.json +2 -2
- package/dist/cjs/Forms/FormElement/FormElement.cjs +0 -44
- package/dist/cjs/Forms/FormElement/context/FormElementContext.cjs +0 -12
- package/dist/cjs/Forms/FormElement/context/FormElementDescriptorsContext.cjs +0 -12
- package/dist/cjs/Forms/FormElement/context/FormElementValueContext.cjs +0 -12
- package/dist/cjs/Forms/FormElement/validationStates.cjs +0 -12
- package/dist/esm/Forms/Adornment/Adornment.js.map +0 -1
- package/dist/esm/Forms/Adornment/Adornment.styles.js.map +0 -1
- package/dist/esm/Forms/CharCounter/CharCounter.js.map +0 -1
- package/dist/esm/Forms/CharCounter/CharCounter.styles.js.map +0 -1
- package/dist/esm/Forms/FormElement/FormElement.js +0 -45
- package/dist/esm/Forms/FormElement/FormElement.js.map +0 -1
- package/dist/esm/Forms/FormElement/FormElement.styles.js.map +0 -1
- package/dist/esm/Forms/FormElement/context/FormElementContext.js +0 -10
- package/dist/esm/Forms/FormElement/context/FormElementContext.js.map +0 -1
- package/dist/esm/Forms/FormElement/context/FormElementDescriptorsContext.js +0 -10
- package/dist/esm/Forms/FormElement/context/FormElementDescriptorsContext.js.map +0 -1
- package/dist/esm/Forms/FormElement/context/FormElementValueContext.js +0 -10
- package/dist/esm/Forms/FormElement/context/FormElementValueContext.js.map +0 -1
- package/dist/esm/Forms/FormElement/utils/FormUtils.js.map +0 -1
- package/dist/esm/Forms/FormElement/validationStates.js +0 -12
- package/dist/esm/Forms/FormElement/validationStates.js.map +0 -1
- package/dist/esm/Forms/InfoMessage/InfoMessage.js.map +0 -1
- package/dist/esm/Forms/InfoMessage/InfoMessage.styles.js.map +0 -1
- package/dist/esm/Forms/Label/Label.js.map +0 -1
- package/dist/esm/Forms/Label/Label.styles.js.map +0 -1
- package/dist/esm/Forms/Suggestions/Suggestions.js.map +0 -1
- package/dist/esm/Forms/Suggestions/Suggestions.styles.js.map +0 -1
- package/dist/esm/Forms/WarningText/WarningText.js.map +0 -1
- package/dist/esm/Forms/WarningText/WarningText.styles.js.map +0 -1
- /package/dist/cjs/{Forms → FormElement}/Adornment/Adornment.styles.cjs +0 -0
- /package/dist/cjs/{Forms → FormElement}/CharCounter/CharCounter.styles.cjs +0 -0
- /package/dist/cjs/{Forms/FormElement → FormElement}/FormElement.styles.cjs +0 -0
- /package/dist/cjs/{Forms → FormElement}/InfoMessage/InfoMessage.styles.cjs +0 -0
- /package/dist/cjs/{Forms → FormElement}/Label/Label.styles.cjs +0 -0
- /package/dist/cjs/{Forms → FormElement}/Suggestions/Suggestions.styles.cjs +0 -0
- /package/dist/cjs/{Forms → FormElement}/WarningText/WarningText.styles.cjs +0 -0
- /package/dist/esm/{Forms → FormElement}/Adornment/Adornment.styles.js +0 -0
- /package/dist/esm/{Forms → FormElement}/CharCounter/CharCounter.styles.js +0 -0
- /package/dist/esm/{Forms/FormElement → FormElement}/FormElement.styles.js +0 -0
- /package/dist/esm/{Forms → FormElement}/InfoMessage/InfoMessage.styles.js +0 -0
- /package/dist/esm/{Forms → FormElement}/Label/Label.styles.js +0 -0
- /package/dist/esm/{Forms → FormElement}/Suggestions/Suggestions.styles.js +0 -0
- /package/dist/esm/{Forms → FormElement}/WarningText/WarningText.styles.js +0 -0
|
@@ -2,9 +2,9 @@ import { jsxs, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
4
4
|
import { setId } from "../../utils/setId.js";
|
|
5
|
+
import { HvFormElementContext } from "../context.js";
|
|
5
6
|
import { useClasses } from "./CharCounter.styles.js";
|
|
6
7
|
import { staticClasses } from "./CharCounter.styles.js";
|
|
7
|
-
import { HvFormElementContext } from "../FormElement/context/FormElementContext.js";
|
|
8
8
|
import { HvTypography } from "../../Typography/Typography.js";
|
|
9
9
|
const HvCharCounter = (props) => {
|
|
10
10
|
const {
|
|
@@ -13,32 +13,32 @@ const HvCharCounter = (props) => {
|
|
|
13
13
|
currentCharQuantity = 0,
|
|
14
14
|
classes: classesProp,
|
|
15
15
|
className,
|
|
16
|
-
id,
|
|
17
|
-
disabled,
|
|
16
|
+
id: idProp,
|
|
17
|
+
disabled: disabledProp,
|
|
18
18
|
disableGutter = false,
|
|
19
19
|
...others
|
|
20
20
|
} = useDefaultProps("HvCharCounter", props);
|
|
21
21
|
const { classes, cx } = useClasses(classesProp);
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const currentId = setId(
|
|
26
|
-
const maxQuantityId = setId(
|
|
22
|
+
const context = useContext(HvFormElementContext);
|
|
23
|
+
const disabled = disabledProp ?? context.disabled;
|
|
24
|
+
const id = idProp ?? setId(context.id, "counter");
|
|
25
|
+
const currentId = setId(id, "currentQuantity");
|
|
26
|
+
const maxQuantityId = setId(id, "maxQuantity");
|
|
27
27
|
const isOverloaded = currentCharQuantity > maxCharQuantity;
|
|
28
28
|
return /* @__PURE__ */ jsxs(
|
|
29
29
|
"div",
|
|
30
30
|
{
|
|
31
|
-
id
|
|
31
|
+
id,
|
|
32
32
|
className: cx(
|
|
33
33
|
classes.root,
|
|
34
34
|
{
|
|
35
|
-
[classes.counterDisabled]:
|
|
35
|
+
[classes.counterDisabled]: disabled,
|
|
36
36
|
[classes.gutter]: !disableGutter
|
|
37
37
|
},
|
|
38
38
|
className
|
|
39
39
|
),
|
|
40
40
|
"aria-live": "polite",
|
|
41
|
-
"aria-disabled":
|
|
41
|
+
"aria-disabled": disabled,
|
|
42
42
|
...others,
|
|
43
43
|
children: [
|
|
44
44
|
/* @__PURE__ */ jsx(
|
|
@@ -46,8 +46,8 @@ const HvCharCounter = (props) => {
|
|
|
46
46
|
{
|
|
47
47
|
id: currentId,
|
|
48
48
|
className: cx({
|
|
49
|
-
[classes.overloaded]: isOverloaded && !
|
|
50
|
-
[classes.counterDisabled]:
|
|
49
|
+
[classes.overloaded]: isOverloaded && !disabled,
|
|
50
|
+
[classes.counterDisabled]: disabled
|
|
51
51
|
}),
|
|
52
52
|
variant: "label",
|
|
53
53
|
component: "label",
|
|
@@ -59,8 +59,8 @@ const HvCharCounter = (props) => {
|
|
|
59
59
|
{
|
|
60
60
|
id: maxQuantityId,
|
|
61
61
|
className: cx({
|
|
62
|
-
[classes.overloaded]: isOverloaded && !
|
|
63
|
-
[classes.counterDisabled]:
|
|
62
|
+
[classes.overloaded]: isOverloaded && !disabled,
|
|
63
|
+
[classes.counterDisabled]: disabled
|
|
64
64
|
}),
|
|
65
65
|
variant: "body",
|
|
66
66
|
component: "label",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CharCounter.js","sources":["../../../../src/FormElement/CharCounter/CharCounter.tsx"],"sourcesContent":["import { useContext } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseProps } from \"../../types/generic\";\nimport { HvTypography } from \"../../Typography\";\nimport { setId } from \"../../utils/setId\";\nimport { HvFormElementContext } from \"../context\";\nimport { staticClasses, useClasses } from \"./CharCounter.styles\";\n\nexport { staticClasses as charCounterClasses };\n\nexport type HvCharCounterClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvCharCounterProps extends HvBaseProps {\n /** The string that separates the current char quantity from the max quantity. */\n separator?: string;\n /** The maximum allowed length of the characters. */\n maxCharQuantity: number;\n /** The current char quantity to be rendered. */\n currentCharQuantity?: number;\n /** If `true` the counter is disabled. */\n disabled?: boolean;\n /** If `true` the info message won't have margins. */\n disableGutter?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvCharCounterClasses;\n}\n\n/**\n * Displays the capacity and current usage of a text input box (character count by default).\n *\n * Use the character counter when there is a character or word limit.\n * By itself it doesn't block the user from going above the limit.\n */\nexport const HvCharCounter = (props: HvCharCounterProps) => {\n const {\n separator = \"/\",\n maxCharQuantity,\n currentCharQuantity = 0,\n classes: classesProp,\n className,\n id: idProp,\n disabled: disabledProp,\n disableGutter = false,\n ...others\n } = useDefaultProps(\"HvCharCounter\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const context = useContext(HvFormElementContext);\n const disabled = disabledProp ?? context.disabled;\n const id = idProp ?? setId(context.id, \"counter\");\n const currentId = setId(id, \"currentQuantity\");\n const maxQuantityId = setId(id, \"maxQuantity\");\n const isOverloaded = currentCharQuantity > maxCharQuantity;\n\n return (\n <div\n id={id}\n className={cx(\n classes.root,\n {\n [classes.counterDisabled]: disabled,\n [classes.gutter]: !disableGutter,\n },\n className,\n )}\n aria-live=\"polite\"\n aria-disabled={disabled}\n {...others}\n >\n <HvTypography\n id={currentId}\n className={cx({\n [classes.overloaded]: isOverloaded && !disabled,\n [classes.counterDisabled]: disabled,\n })}\n variant=\"label\"\n component=\"label\"\n >\n {currentCharQuantity}\n </HvTypography>\n <HvTypography\n id={maxQuantityId}\n className={cx({\n [classes.overloaded]: isOverloaded && !disabled,\n [classes.counterDisabled]: disabled,\n })}\n variant=\"body\"\n component=\"label\"\n >\n {` ${separator} ${maxCharQuantity}`}\n </HvTypography>\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;AAqCa,MAAA,gBAAgB,CAAC,UAA8B;AACpD,QAAA;AAAA,IACJ,YAAY;AAAA,IACZ;AAAA,IACA,sBAAsB;AAAA,IACtB,SAAS;AAAA,IACT;AAAA,IACA,IAAI;AAAA,IACJ,UAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,GAAG;AAAA,EAAA,IACD,gBAAgB,iBAAiB,KAAK;AAE1C,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAExC,QAAA,UAAU,WAAW,oBAAoB;AACzC,QAAA,WAAW,gBAAgB,QAAQ;AACzC,QAAM,KAAK,UAAU,MAAM,QAAQ,IAAI,SAAS;AAC1C,QAAA,YAAY,MAAM,IAAI,iBAAiB;AACvC,QAAA,gBAAgB,MAAM,IAAI,aAAa;AAC7C,QAAM,eAAe,sBAAsB;AAGzC,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA,WAAW;AAAA,QACT,QAAQ;AAAA,QACR;AAAA,UACE,CAAC,QAAQ,eAAe,GAAG;AAAA,UAC3B,CAAC,QAAQ,MAAM,GAAG,CAAC;AAAA,QACrB;AAAA,QACA;AAAA,MACF;AAAA,MACA,aAAU;AAAA,MACV,iBAAe;AAAA,MACd,GAAG;AAAA,MAEJ,UAAA;AAAA,QAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,IAAI;AAAA,YACJ,WAAW,GAAG;AAAA,cACZ,CAAC,QAAQ,UAAU,GAAG,gBAAgB,CAAC;AAAA,cACvC,CAAC,QAAQ,eAAe,GAAG;AAAA,YAAA,CAC5B;AAAA,YACD,SAAQ;AAAA,YACR,WAAU;AAAA,YAET,UAAA;AAAA,UAAA;AAAA,QACH;AAAA,QACA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,IAAI;AAAA,YACJ,WAAW,GAAG;AAAA,cACZ,CAAC,QAAQ,UAAU,GAAG,gBAAgB,CAAC;AAAA,cACvC,CAAC,QAAQ,eAAe,GAAG;AAAA,YAAA,CAC5B;AAAA,YACD,SAAQ;AAAA,YACR,WAAU;AAAA,YAET,UAAA,IAAI,SAAS,IAAI,eAAe;AAAA,UAAA;AAAA,QAAA;AAAA,MACnC;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CharCounter.styles.js","sources":["../../../../src/FormElement/CharCounter/CharCounter.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvCharCounter\", {\n root: { display: \"inline-block\", float: \"right\" },\n counterDisabled: { color: theme.colors.secondary_60 },\n gutter: { paddingLeft: \"6px\" },\n overloaded: { color: theme.colors.negative },\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,iBAAiB;AAAA,EAC1E,MAAM,EAAE,SAAS,gBAAgB,OAAO,QAAQ;AAAA,EAChD,iBAAiB,EAAE,OAAO,MAAM,OAAO,aAAa;AAAA,EACpD,QAAQ,EAAE,aAAa,MAAM;AAAA,EAC7B,YAAY,EAAE,OAAO,MAAM,OAAO,SAAS;AAC7C,CAAC;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
4
|
+
import { useUniqueId } from "../hooks/useUniqueId.js";
|
|
5
|
+
import { HvFormElementContext, HvFormElementValueContext, HvFormElementDescriptorsContext } from "./context.js";
|
|
6
|
+
import { useClasses } from "./FormElement.styles.js";
|
|
7
|
+
import { staticClasses } from "./FormElement.styles.js";
|
|
8
|
+
import { findDescriptors } from "./utils.js";
|
|
9
|
+
const HvFormElement = (props) => {
|
|
10
|
+
const {
|
|
11
|
+
classes: classesProp,
|
|
12
|
+
className,
|
|
13
|
+
children,
|
|
14
|
+
id: idProp,
|
|
15
|
+
name,
|
|
16
|
+
value,
|
|
17
|
+
disabled,
|
|
18
|
+
required,
|
|
19
|
+
readOnly,
|
|
20
|
+
status = "standBy",
|
|
21
|
+
...others
|
|
22
|
+
} = useDefaultProps("HvFormElement", props);
|
|
23
|
+
const { classes, cx } = useClasses(classesProp);
|
|
24
|
+
const id = useUniqueId(idProp);
|
|
25
|
+
const contextValue = useMemo(
|
|
26
|
+
() => ({ id, name, status, disabled, required, readOnly }),
|
|
27
|
+
[id, name, status, disabled, required, readOnly]
|
|
28
|
+
);
|
|
29
|
+
const descriptors = useMemo(() => findDescriptors(children), [children]);
|
|
30
|
+
return /* @__PURE__ */ jsx("div", { id, className: cx(classes.root, className), ...others, children: /* @__PURE__ */ jsx(HvFormElementContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(HvFormElementValueContext.Provider, { value, children: /* @__PURE__ */ jsx(HvFormElementDescriptorsContext.Provider, { value: descriptors, children }) }) }) });
|
|
31
|
+
};
|
|
32
|
+
HvFormElement.formElementType = "formelement";
|
|
33
|
+
export {
|
|
34
|
+
HvFormElement,
|
|
35
|
+
staticClasses as formElementClasses
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormElement.js","sources":["../../../src/FormElement/FormElement.tsx"],"sourcesContent":["import { useMemo } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvBaseProps } from \"../types/generic\";\nimport {\n HvFormElementContext,\n HvFormElementDescriptorsContext,\n HvFormElementValueContext,\n type HvFormElementContextValue,\n} from \"./context\";\nimport { staticClasses, useClasses } from \"./FormElement.styles\";\nimport { findDescriptors } from \"./utils\";\n\nexport { staticClasses as formElementClasses };\n\nexport type HvFormElementClasses = ExtractNames<typeof useClasses>;\n\nexport type HvFormStatus = \"standBy\" | \"valid\" | \"invalid\" | \"empty\";\n\nexport interface HvFormElementProps\n extends HvFormElementContextValue,\n HvBaseProps<HTMLDivElement, \"onChange\" | \"onToggle\"> {\n /**\n * Current value of the form element.\n *\n * Part of a name/value pair, should be the value property of the underling native input.\n */\n value?: any;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /** Provide additional descriptive text for the form element. */\n description?: React.ReactNode;\n /** The error message to show when `status` is \"invalid\". */\n statusMessage?: string;\n /** The callback fired when the value changes. */\n onChange?: (event: React.FormEvent<HTMLDivElement>) => void;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFormElementClasses;\n}\n\n/**\n * Provides form-related context (ie. required/disabled/readOnly) for building form components,\n * analogous to MUI's [`FormControl`](https://mui.com/material-ui/api/form-control/) component.\n *\n * It is used internally to build UI Kit's form components (eg. `HvInput`, `HvDatePicker`), and can be used to build custom form components.\n */\nexport const HvFormElement = (props: HvFormElementProps) => {\n const {\n classes: classesProp,\n className,\n children,\n id: idProp,\n name,\n value,\n disabled,\n required,\n readOnly,\n status = \"standBy\",\n ...others\n } = useDefaultProps(\"HvFormElement\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const id = useUniqueId(idProp);\n\n const contextValue = useMemo<HvFormElementContextValue>(\n () => ({ id, name, status, disabled, required, readOnly }),\n [id, name, status, disabled, required, readOnly],\n );\n\n const descriptors = useMemo(() => findDescriptors(children), [children]);\n\n return (\n <div id={id} className={cx(classes.root, className)} {...others}>\n <HvFormElementContext.Provider value={contextValue}>\n <HvFormElementValueContext.Provider value={value}>\n <HvFormElementDescriptorsContext.Provider value={descriptors}>\n {children}\n </HvFormElementDescriptorsContext.Provider>\n </HvFormElementValueContext.Provider>\n </HvFormElementContext.Provider>\n </div>\n );\n};\n\nHvFormElement.formElementType = \"formelement\";\n"],"names":[],"mappings":";;;;;;;;AAuDa,MAAA,gBAAgB,CAAC,UAA8B;AACpD,QAAA;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,IAAI;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,GAAG;AAAA,EAAA,IACD,gBAAgB,iBAAiB,KAAK;AAE1C,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAExC,QAAA,KAAK,YAAY,MAAM;AAE7B,QAAM,eAAe;AAAA,IACnB,OAAO,EAAE,IAAI,MAAM,QAAQ,UAAU,UAAU;IAC/C,CAAC,IAAI,MAAM,QAAQ,UAAU,UAAU,QAAQ;AAAA,EACjD;AAEM,QAAA,cAAc,QAAQ,MAAM,gBAAgB,QAAQ,GAAG,CAAC,QAAQ,CAAC;AAEvE,SACG,oBAAA,OAAA,EAAI,IAAQ,WAAW,GAAG,QAAQ,MAAM,SAAS,GAAI,GAAG,QACvD,UAAA,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,cACpC,UAAC,oBAAA,0BAA0B,UAA1B,EAAmC,OAClC,UAAC,oBAAA,gCAAgC,UAAhC,EAAyC,OAAO,aAC9C,SACH,CAAA,EACF,CAAA,EACF,CAAA,GACF;AAEJ;AAEA,cAAc,kBAAkB;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormElement.styles.js","sources":["../../../src/FormElement/FormElement.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFormElement\", {\n root: {},\n});\n"],"names":[],"mappings":";AAEO,MAAM,EAAE,eAAe,eAAe,cAAc,iBAAiB;AAAA,EAC1E,MAAM,CAAA;AACR,CAAC;"}
|
|
@@ -2,32 +2,32 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
4
4
|
import { setId } from "../../utils/setId.js";
|
|
5
|
+
import { HvFormElementContext } from "../context.js";
|
|
5
6
|
import { useClasses } from "./InfoMessage.styles.js";
|
|
6
7
|
import { staticClasses } from "./InfoMessage.styles.js";
|
|
7
|
-
import { HvFormElementContext } from "../FormElement/context/FormElementContext.js";
|
|
8
8
|
import { HvTypography } from "../../Typography/Typography.js";
|
|
9
9
|
const HvInfoMessage = (props) => {
|
|
10
10
|
const {
|
|
11
|
-
id,
|
|
11
|
+
id: idProp,
|
|
12
12
|
classes: classesProp,
|
|
13
13
|
className,
|
|
14
14
|
children,
|
|
15
|
-
disabled,
|
|
15
|
+
disabled: disabledProp,
|
|
16
16
|
disableGutter = false,
|
|
17
17
|
...others
|
|
18
18
|
} = useDefaultProps("HvInfoMessage", props);
|
|
19
19
|
const { classes, cx } = useClasses(classesProp);
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
20
|
+
const context = useContext(HvFormElementContext);
|
|
21
|
+
const disabled = disabledProp ?? context.disabled;
|
|
22
|
+
const id = idProp ?? setId(context.id, "description");
|
|
23
23
|
return /* @__PURE__ */ jsx(
|
|
24
24
|
HvTypography,
|
|
25
25
|
{
|
|
26
|
-
id
|
|
26
|
+
id,
|
|
27
27
|
className: cx(
|
|
28
28
|
classes.root,
|
|
29
29
|
{
|
|
30
|
-
[classes.infoDisabled]: !!
|
|
30
|
+
[classes.infoDisabled]: !!disabled,
|
|
31
31
|
[classes.gutter]: !disableGutter
|
|
32
32
|
},
|
|
33
33
|
className
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InfoMessage.js","sources":["../../../../src/FormElement/InfoMessage/InfoMessage.tsx"],"sourcesContent":["import { useContext } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvTypography, HvTypographyProps } from \"../../Typography\";\nimport { setId } from \"../../utils/setId\";\nimport { HvFormElementContext } from \"../context\";\nimport { staticClasses, useClasses } from \"./InfoMessage.styles\";\n\nexport { staticClasses as infoMessageClasses };\n\nexport type HvInfoMessageClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvInfoMessageProps extends HvTypographyProps<\"label\"> {\n /** If `true` the label is disabled. */\n disabled?: boolean;\n /** If `true` the info message won't have margins. */\n disableGutter?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvInfoMessageClasses;\n}\n\n/**\n * Provides the user with additional descriptive text for the form element.\n */\nexport const HvInfoMessage = (props: HvInfoMessageProps) => {\n const {\n id: idProp,\n classes: classesProp,\n className,\n children,\n disabled: disabledProp,\n disableGutter = false,\n ...others\n } = useDefaultProps(\"HvInfoMessage\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const context = useContext(HvFormElementContext);\n const disabled = disabledProp ?? context.disabled;\n const id = idProp ?? setId(context.id, \"description\");\n\n return (\n <HvTypography\n id={id}\n className={cx(\n classes.root,\n {\n [classes.infoDisabled]: !!disabled,\n [classes.gutter]: !disableGutter,\n },\n className,\n )}\n variant=\"body\"\n component=\"label\"\n {...others}\n >\n {children}\n </HvTypography>\n );\n};\n"],"names":[],"mappings":";;;;;;;;AA2Ba,MAAA,gBAAgB,CAAC,UAA8B;AACpD,QAAA;AAAA,IACJ,IAAI;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,GAAG;AAAA,EAAA,IACD,gBAAgB,iBAAiB,KAAK;AAE1C,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAExC,QAAA,UAAU,WAAW,oBAAoB;AACzC,QAAA,WAAW,gBAAgB,QAAQ;AACzC,QAAM,KAAK,UAAU,MAAM,QAAQ,IAAI,aAAa;AAGlD,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA,WAAW;AAAA,QACT,QAAQ;AAAA,QACR;AAAA,UACE,CAAC,QAAQ,YAAY,GAAG,CAAC,CAAC;AAAA,UAC1B,CAAC,QAAQ,MAAM,GAAG,CAAC;AAAA,QACrB;AAAA,QACA;AAAA,MACF;AAAA,MACA,SAAQ;AAAA,MACR,WAAU;AAAA,MACT,GAAG;AAAA,MAEH;AAAA,IAAA;AAAA,EACH;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InfoMessage.styles.js","sources":["../../../../src/FormElement/InfoMessage/InfoMessage.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvInfoMessage\", {\n root: { color: theme.colors.secondary_80, display: \"inline-block\" },\n infoDisabled: { color: theme.colors.secondary_60 },\n gutter: { padding: `0 0 6px ${theme.space.xs}` },\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,iBAAiB;AAAA,EAC1E,MAAM,EAAE,OAAO,MAAM,OAAO,cAAc,SAAS,eAAe;AAAA,EAClE,cAAc,EAAE,OAAO,MAAM,OAAO,aAAa;AAAA,EACjD,QAAQ,EAAE,SAAS,WAAW,MAAM,MAAM,EAAE,GAAG;AACjD,CAAC;"}
|
|
@@ -2,38 +2,38 @@ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
4
4
|
import { setId } from "../../utils/setId.js";
|
|
5
|
-
import {
|
|
5
|
+
import { HvFormElementContext } from "../context.js";
|
|
6
|
+
import { findDescriptors } from "../utils.js";
|
|
6
7
|
import { useClasses } from "./Label.styles.js";
|
|
7
8
|
import { staticClasses } from "./Label.styles.js";
|
|
8
|
-
import { HvFormElementContext } from "../FormElement/context/FormElementContext.js";
|
|
9
9
|
import { HvTypography } from "../../Typography/Typography.js";
|
|
10
10
|
const HvLabel = (props) => {
|
|
11
11
|
const {
|
|
12
|
-
id,
|
|
12
|
+
id: idProp,
|
|
13
13
|
classes: classesProp,
|
|
14
14
|
className,
|
|
15
15
|
children,
|
|
16
16
|
label,
|
|
17
|
-
disabled,
|
|
18
|
-
required,
|
|
17
|
+
disabled: disabledProp,
|
|
18
|
+
required: requiredProp,
|
|
19
19
|
htmlFor: htmlForProp,
|
|
20
20
|
...others
|
|
21
21
|
} = useDefaultProps("HvLabel", props);
|
|
22
22
|
const { classes, cx } = useClasses(classesProp);
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
23
|
+
const context = useContext(HvFormElementContext);
|
|
24
|
+
const disabled = disabledProp ?? context.disabled;
|
|
25
|
+
const required = requiredProp ?? context.required;
|
|
26
|
+
const id = idProp ?? setId(context.id, "label");
|
|
27
27
|
const forId = htmlForProp || findDescriptors(children)?.input?.[0]?.id;
|
|
28
28
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
29
29
|
/* @__PURE__ */ jsxs(
|
|
30
30
|
HvTypography,
|
|
31
31
|
{
|
|
32
|
-
id
|
|
32
|
+
id,
|
|
33
33
|
className: cx(
|
|
34
34
|
classes.root,
|
|
35
35
|
{
|
|
36
|
-
[classes.labelDisabled]: !!
|
|
36
|
+
[classes.labelDisabled]: !!disabled,
|
|
37
37
|
[classes.childGutter]: !!(children && label)
|
|
38
38
|
},
|
|
39
39
|
className
|
|
@@ -44,7 +44,7 @@ const HvLabel = (props) => {
|
|
|
44
44
|
...others,
|
|
45
45
|
children: [
|
|
46
46
|
label,
|
|
47
|
-
|
|
47
|
+
required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "*" })
|
|
48
48
|
]
|
|
49
49
|
}
|
|
50
50
|
),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Label.js","sources":["../../../../src/FormElement/Label/Label.tsx"],"sourcesContent":["import { useContext } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvTypography, HvTypographyProps } from \"../../Typography\";\nimport { setId } from \"../../utils/setId\";\nimport { HvFormElementContext } from \"../context\";\nimport { findDescriptors } from \"../utils\";\nimport { staticClasses, useClasses } from \"./Label.styles\";\n\nexport { staticClasses as labelClasses };\n\nexport type HvLabelClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvLabelProps extends HvTypographyProps<\"label\"> {\n /** Id to be applied to the root node */\n id?: string;\n /** The text to be shown by the label. */\n label?: React.ReactNode;\n /** The id of the form element the label is bound to. */\n htmlFor?: string;\n /** If `true` the label is displayed with a disabled style. */\n disabled?: boolean;\n /** If `true`, the label will indicate that the form element is required (an `*` after the label text). */\n required?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvLabelClasses;\n}\n\n/**\n * Provides the user with a recognizable name for a given form element.\n */\nexport const HvLabel = (props: HvLabelProps) => {\n const {\n id: idProp,\n classes: classesProp,\n className,\n children,\n label,\n disabled: disabledProp,\n required: requiredProp,\n htmlFor: htmlForProp,\n ...others\n } = useDefaultProps(\"HvLabel\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const context = useContext(HvFormElementContext);\n\n const disabled = disabledProp ?? context.disabled;\n const required = requiredProp ?? context.required;\n const id = idProp ?? setId(context.id, \"label\");\n\n const forId = htmlForProp || findDescriptors(children)?.input?.[0]?.id;\n\n return (\n <>\n <HvTypography\n id={id}\n className={cx(\n classes.root,\n {\n [classes.labelDisabled]: !!disabled,\n [classes.childGutter]: !!(children && label),\n },\n className,\n )}\n variant=\"label\"\n component=\"label\"\n htmlFor={forId}\n {...others}\n >\n {label}\n {required && <span aria-hidden=\"true\">*</span>}\n </HvTypography>\n {children}\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;AAkCa,MAAA,UAAU,CAAC,UAAwB;AACxC,QAAA;AAAA,IACJ,IAAI;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,UAAU;AAAA,IACV,SAAS;AAAA,IACT,GAAG;AAAA,EAAA,IACD,gBAAgB,WAAW,KAAK;AAEpC,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAExC,QAAA,UAAU,WAAW,oBAAoB;AAEzC,QAAA,WAAW,gBAAgB,QAAQ;AACnC,QAAA,WAAW,gBAAgB,QAAQ;AACzC,QAAM,KAAK,UAAU,MAAM,QAAQ,IAAI,OAAO;AAE9C,QAAM,QAAQ,eAAe,gBAAgB,QAAQ,GAAG,QAAQ,CAAC,GAAG;AAEpE,SAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAW;AAAA,UACT,QAAQ;AAAA,UACR;AAAA,YACE,CAAC,QAAQ,aAAa,GAAG,CAAC,CAAC;AAAA,YAC3B,CAAC,QAAQ,WAAW,GAAG,CAAC,EAAE,YAAY;AAAA,UACxC;AAAA,UACA;AAAA,QACF;AAAA,QACA,SAAQ;AAAA,QACR,WAAU;AAAA,QACV,SAAS;AAAA,QACR,GAAG;AAAA,QAEH,UAAA;AAAA,UAAA;AAAA,UACA,YAAY,oBAAC,QAAK,EAAA,eAAY,QAAO,UAAC,IAAA,CAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IACzC;AAAA,IACC;AAAA,EAAA,GACH;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Label.styles.js","sources":["../../../../src/FormElement/Label/Label.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvLabel\", {\n root: { fontWeight: theme.fontWeights.normal, display: \"inline-block\" },\n labelDisabled: { color: theme.colors.secondary_60 },\n childGutter: { paddingBottom: \"6px\" },\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,WAAW;AAAA,EACpE,MAAM,EAAE,YAAY,MAAM,YAAY,QAAQ,SAAS,eAAe;AAAA,EACtE,eAAe,EAAE,OAAO,MAAM,OAAO,aAAa;AAAA,EAClD,aAAa,EAAE,eAAe,MAAM;AACtC,CAAC;"}
|
|
@@ -6,14 +6,14 @@ import { useForkRef } from "@mui/material/utils";
|
|
|
6
6
|
import { useTheme } from "@hitachivantara/uikit-react-utils";
|
|
7
7
|
import { getContainerElement } from "../../utils/document.js";
|
|
8
8
|
import { setId } from "../../utils/setId.js";
|
|
9
|
+
import { HvFormElementContext } from "../context.js";
|
|
9
10
|
import { useClasses } from "./Suggestions.styles.js";
|
|
10
11
|
import { staticClasses } from "./Suggestions.styles.js";
|
|
11
12
|
import { HvSelectionList } from "../../SelectionList/SelectionList.js";
|
|
12
13
|
import { HvListItem } from "../../ListContainer/ListItem/ListItem.js";
|
|
13
|
-
import { HvFormElementContext } from "../FormElement/context/FormElementContext.js";
|
|
14
14
|
const HvSuggestions = forwardRef((props, extRef) => {
|
|
15
15
|
const {
|
|
16
|
-
id,
|
|
16
|
+
id: idProp,
|
|
17
17
|
className,
|
|
18
18
|
classes: classesProp,
|
|
19
19
|
expanded = false,
|
|
@@ -28,8 +28,8 @@ const HvSuggestions = forwardRef((props, extRef) => {
|
|
|
28
28
|
} = props;
|
|
29
29
|
const { classes, cx } = useClasses(classesProp);
|
|
30
30
|
const { rootId } = useTheme();
|
|
31
|
-
const
|
|
32
|
-
const
|
|
31
|
+
const context = useContext(HvFormElementContext);
|
|
32
|
+
const id = idProp ?? setId(context.id, "suggestions");
|
|
33
33
|
const ref = useRef(null);
|
|
34
34
|
const forkedRef = useForkRef(ref, extRef);
|
|
35
35
|
const [isOpen, setIsOpen] = useState(expanded);
|
|
@@ -39,7 +39,7 @@ const HvSuggestions = forwardRef((props, extRef) => {
|
|
|
39
39
|
return /* @__PURE__ */ jsx(
|
|
40
40
|
"div",
|
|
41
41
|
{
|
|
42
|
-
id
|
|
42
|
+
id,
|
|
43
43
|
ref: forkedRef,
|
|
44
44
|
className: cx(classes.root, className),
|
|
45
45
|
...others,
|
|
@@ -69,7 +69,7 @@ const HvSuggestions = forwardRef((props, extRef) => {
|
|
|
69
69
|
HvSelectionList,
|
|
70
70
|
{
|
|
71
71
|
className: classes.list,
|
|
72
|
-
id: setId(
|
|
72
|
+
id: setId(id, "list"),
|
|
73
73
|
onChange: onSuggestionSelected,
|
|
74
74
|
children: suggestionValues?.map((item) => /* @__PURE__ */ jsx(HvListItem, { value: item, disabled: item.disabled, children: item.label }, item.id))
|
|
75
75
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Suggestions.js","sources":["../../../../src/FormElement/Suggestions/Suggestions.tsx"],"sourcesContent":["import { forwardRef, useContext, useEffect, useRef, useState } from \"react\";\nimport {\n ClickAwayListener,\n ClickAwayListenerProps,\n} from \"@mui/base/ClickAwayListener\";\nimport { Popper, PopperProps } from \"@mui/base/Popper\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport { useTheme, type ExtractNames } from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvListItem } from \"../../ListContainer\";\nimport { HvSelectionList } from \"../../SelectionList\";\nimport { HvBaseProps } from \"../../types/generic\";\nimport { getContainerElement } from \"../../utils/document\";\nimport { setId } from \"../../utils/setId\";\nimport { HvFormElementContext } from \"../context\";\nimport { staticClasses, useClasses } from \"./Suggestions.styles\";\n\nexport { staticClasses as suggestionsClasses };\n\nexport type HvSuggestionsClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvSuggestion {\n id?: string;\n label: React.ReactNode;\n value?: string;\n disabled?: boolean;\n}\n\nexport interface HvSuggestionsProps extends HvBaseProps {\n /** Whether suggestions is visible */\n open?: boolean;\n /**\n * Whether suggestions is visible.\n * @deprecated use `open` instead.\n * */\n expanded?: boolean;\n /** The HTML element Suggestions attaches to. */\n anchorEl?: HTMLElement | null;\n /** Array of { id, label, ...others } values to display in the suggestion list */\n suggestionValues?: HvSuggestion[] | null;\n /** Function called when a suggestion is selected */\n onSuggestionSelected?: (event: React.MouseEvent, value: HvSuggestion) => void;\n /** Function called when suggestion list is closed */\n onClose?: ClickAwayListenerProps[\"onClickAway\"];\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvSuggestionsClasses;\n /**\n * If enabled, the suggestions list will be rendered using a portal.\n * If disabled, it will be under the DOM hierarchy of the parent component.\n * @default false\n * */\n enablePortal?: boolean;\n /** Props passed to the underlying MUI Popper component */\n popperProps?: Partial<PopperProps>;\n}\n\nexport const HvSuggestions = forwardRef<\n // no-indent\n unknown,\n HvSuggestionsProps\n>((props, extRef) => {\n const {\n id: idProp,\n className,\n classes: classesProp,\n expanded = false,\n enablePortal = false,\n open: openProp,\n anchorEl,\n suggestionValues = [],\n onClose,\n onSuggestionSelected,\n popperProps,\n ...others\n } = props;\n\n const { classes, cx } = useClasses(classesProp);\n\n const { rootId } = useTheme();\n\n const context = useContext(HvFormElementContext);\n const id = idProp ?? setId(context.id, \"suggestions\");\n\n const ref = useRef<HTMLDivElement>(null);\n const forkedRef = useForkRef(ref, extRef);\n\n // TODO: remove controlled+uncontrolled `expanded` prop in v6\n const [isOpen, setIsOpen] = useState(expanded);\n useEffect(() => {\n setIsOpen(expanded);\n }, [expanded]);\n\n return (\n <div\n id={id}\n ref={forkedRef}\n className={cx(classes.root, className)}\n {...others}\n >\n <ClickAwayListener\n onClickAway={(event) => {\n setIsOpen(false);\n onClose?.(event);\n }}\n >\n <Popper\n style={{\n // @ts-ignore\n \"--popper-width\": enablePortal\n ? `${anchorEl?.clientWidth}px`\n : \"100%\",\n }}\n open={openProp ?? isOpen}\n disablePortal={!enablePortal}\n container={enablePortal ? getContainerElement(rootId) : undefined}\n anchorEl={anchorEl}\n className={cx(classes.popper, {\n [classes.portal]: enablePortal,\n })}\n {...popperProps}\n >\n <HvSelectionList\n className={classes.list}\n id={setId(id, \"list\")}\n onChange={onSuggestionSelected}\n >\n {suggestionValues?.map((item) => (\n <HvListItem key={item.id} value={item} disabled={item.disabled}>\n {item.label}\n </HvListItem>\n ))}\n </HvSelectionList>\n </Popper>\n </ClickAwayListener>\n </div>\n );\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;AAwDO,MAAM,gBAAgB,WAI3B,CAAC,OAAO,WAAW;AACb,QAAA;AAAA,IACJ,IAAI;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT,WAAW;AAAA,IACX,eAAe;AAAA,IACf,MAAM;AAAA,IACN;AAAA,IACA,mBAAmB,CAAC;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AAEJ,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAExC,QAAA,EAAE,OAAO,IAAI,SAAS;AAEtB,QAAA,UAAU,WAAW,oBAAoB;AAC/C,QAAM,KAAK,UAAU,MAAM,QAAQ,IAAI,aAAa;AAE9C,QAAA,MAAM,OAAuB,IAAI;AACjC,QAAA,YAAY,WAAW,KAAK,MAAM;AAGxC,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,QAAQ;AAC7C,YAAU,MAAM;AACd,cAAU,QAAQ;AAAA,EAAA,GACjB,CAAC,QAAQ,CAAC;AAGX,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA,KAAK;AAAA,MACL,WAAW,GAAG,QAAQ,MAAM,SAAS;AAAA,MACpC,GAAG;AAAA,MAEJ,UAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,aAAa,CAAC,UAAU;AACtB,sBAAU,KAAK;AACf,sBAAU,KAAK;AAAA,UACjB;AAAA,UAEA,UAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,OAAO;AAAA;AAAA,gBAEL,kBAAkB,eACd,GAAG,UAAU,WAAW,OACxB;AAAA,cACN;AAAA,cACA,MAAM,YAAY;AAAA,cAClB,eAAe,CAAC;AAAA,cAChB,WAAW,eAAe,oBAAoB,MAAM,IAAI;AAAA,cACxD;AAAA,cACA,WAAW,GAAG,QAAQ,QAAQ;AAAA,gBAC5B,CAAC,QAAQ,MAAM,GAAG;AAAA,cAAA,CACnB;AAAA,cACA,GAAG;AAAA,cAEJ,UAAA;AAAA,gBAAC;AAAA,gBAAA;AAAA,kBACC,WAAW,QAAQ;AAAA,kBACnB,IAAI,MAAM,IAAI,MAAM;AAAA,kBACpB,UAAU;AAAA,kBAET,UAAkB,kBAAA,IAAI,CAAC,6BACrB,YAAyB,EAAA,OAAO,MAAM,UAAU,KAAK,UACnD,UAAA,KAAK,MADS,GAAA,KAAK,EAEtB,CACD;AAAA,gBAAA;AAAA,cAAA;AAAA,YACH;AAAA,UAAA;AAAA,QACF;AAAA,MAAA;AAAA,IACF;AAAA,EACF;AAEJ,CAAC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Suggestions.styles.js","sources":["../../../../src/FormElement/Suggestions/Suggestions.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvSuggestions\", {\n root: { position: \"relative\" },\n list: {\n backgroundColor: theme.colors.atmo1,\n boxShadow: theme.colors.shadow,\n padding: theme.space.xs,\n width: \"100%\",\n },\n popper: {\n width: \"var(--popper-width)\",\n position: \"absolute\",\n zIndex: theme.zIndices.tooltip,\n \":not($portal)\": {\n transform: \"translate3d(0, -1px, 0) !important\",\n },\n },\n portal: {},\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,iBAAiB;AAAA,EAC1E,MAAM,EAAE,UAAU,WAAW;AAAA,EAC7B,MAAM;AAAA,IACJ,iBAAiB,MAAM,OAAO;AAAA,IAC9B,WAAW,MAAM,OAAO;AAAA,IACxB,SAAS,MAAM,MAAM;AAAA,IACrB,OAAO;AAAA,EACT;AAAA,EACA,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,UAAU;AAAA,IACV,QAAQ,MAAM,SAAS;AAAA,IACvB,iBAAiB;AAAA,MACf,WAAW;AAAA,IAAA;AAAA,EAEf;AAAA,EACA,QAAQ,CAAA;AACV,CAAC;"}
|
|
@@ -3,9 +3,9 @@ import { useContext } from "react";
|
|
|
3
3
|
import { Fail } from "@hitachivantara/uikit-react-icons";
|
|
4
4
|
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
5
5
|
import { setId } from "../../utils/setId.js";
|
|
6
|
+
import { HvFormElementContext } from "../context.js";
|
|
6
7
|
import { useClasses } from "./WarningText.styles.js";
|
|
7
8
|
import { staticClasses } from "./WarningText.styles.js";
|
|
8
|
-
import { HvFormElementContext } from "../FormElement/context/FormElementContext.js";
|
|
9
9
|
const HvWarningText = (props) => {
|
|
10
10
|
const {
|
|
11
11
|
children,
|
|
@@ -22,10 +22,10 @@ const HvWarningText = (props) => {
|
|
|
22
22
|
...others
|
|
23
23
|
} = useDefaultProps("HvWarningText", props);
|
|
24
24
|
const { classes, cx } = useClasses(classesProp);
|
|
25
|
-
const
|
|
26
|
-
const disabled = disabledProp
|
|
27
|
-
const visible = isVisibleProp ??
|
|
28
|
-
const id = idProp ?? setId(
|
|
25
|
+
const context = useContext(HvFormElementContext);
|
|
26
|
+
const disabled = disabledProp ?? context.disabled;
|
|
27
|
+
const visible = isVisibleProp ?? context.status === "invalid";
|
|
28
|
+
const id = idProp ?? setId(context.id, "error");
|
|
29
29
|
const showWarning = visible && !disabled;
|
|
30
30
|
const adornment = adornmentProp || /* @__PURE__ */ jsx(Fail, { size: "xs", className: classes.defaultIcon });
|
|
31
31
|
return /* @__PURE__ */ jsxs(
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WarningText.js","sources":["../../../../src/FormElement/WarningText/WarningText.tsx"],"sourcesContent":["import { useContext } from \"react\";\nimport { Fail } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseProps } from \"../../types/generic\";\nimport { setId } from \"../../utils/setId\";\nimport { HvFormElementContext } from \"../context\";\nimport { staticClasses, useClasses } from \"./WarningText.styles\";\n\nexport { staticClasses as warningTextClasses };\n\nexport type HvWarningTextClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvWarningTextProps extends HvBaseProps {\n /** Icon to be rendered alongside the warning text. */\n adornment?: React.ReactNode;\n /** If `true` the text is not rendered. */\n isVisible?: boolean;\n /** If `true` the text is disabled. */\n disabled?: boolean;\n /** If `true` the text won't include a gutter. */\n disableGutter?: boolean;\n /** If `true` the text won't include the top border. */\n disableBorder?: boolean;\n /** If `true` the adornment icon isn't shown. */\n disableAdornment?: boolean;\n /** If `true` the text isn't shown. */\n hideText?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvWarningTextClasses;\n}\n\n/**\n * Provides the user with a descriptive text, signaling an error, for when the form element is in an invalid state.\n */\nexport const HvWarningText = (props: HvWarningTextProps) => {\n const {\n children,\n adornment: adornmentProp,\n isVisible: isVisibleProp,\n classes: classesProp,\n className,\n id: idProp,\n disabled: disabledProp,\n disableGutter = false,\n disableBorder = false,\n disableAdornment = false,\n hideText = false,\n ...others\n } = useDefaultProps(\"HvWarningText\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const context = useContext(HvFormElementContext);\n const disabled = disabledProp ?? context.disabled;\n const visible = isVisibleProp ?? context.status === \"invalid\";\n const id = idProp ?? setId(context.id, \"error\");\n const showWarning = visible && !disabled;\n const adornment = adornmentProp || (\n <Fail size=\"xs\" className={classes.defaultIcon} />\n );\n\n return (\n <div\n className={cx(\n classes.root,\n {\n [classes.show]: showWarning,\n [classes.topBorder]: !disableBorder,\n },\n className,\n )}\n >\n {!disableAdornment && adornment}\n <span\n id={id}\n className={cx(classes.warningText, {\n [classes.topGutter]: !disableGutter,\n [classes.hideText]: hideText,\n })}\n role=\"status\"\n aria-live=\"polite\"\n aria-relevant=\"additions text\"\n {...others}\n >\n {showWarning && children}\n </span>\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;AAsCa,MAAA,gBAAgB,CAAC,UAA8B;AACpD,QAAA;AAAA,IACJ;AAAA,IACA,WAAW;AAAA,IACX,WAAW;AAAA,IACX,SAAS;AAAA,IACT;AAAA,IACA,IAAI;AAAA,IACJ,UAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,mBAAmB;AAAA,IACnB,WAAW;AAAA,IACX,GAAG;AAAA,EAAA,IACD,gBAAgB,iBAAiB,KAAK;AAE1C,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAExC,QAAA,UAAU,WAAW,oBAAoB;AACzC,QAAA,WAAW,gBAAgB,QAAQ;AACnC,QAAA,UAAU,iBAAiB,QAAQ,WAAW;AACpD,QAAM,KAAK,UAAU,MAAM,QAAQ,IAAI,OAAO;AACxC,QAAA,cAAc,WAAW,CAAC;AAC1B,QAAA,YAAY,iBACf,oBAAA,MAAA,EAAK,MAAK,MAAK,WAAW,QAAQ,aAAa;AAIhD,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAW;AAAA,QACT,QAAQ;AAAA,QACR;AAAA,UACE,CAAC,QAAQ,IAAI,GAAG;AAAA,UAChB,CAAC,QAAQ,SAAS,GAAG,CAAC;AAAA,QACxB;AAAA,QACA;AAAA,MACF;AAAA,MAEC,UAAA;AAAA,QAAA,CAAC,oBAAoB;AAAA,QACtB;AAAA,UAAC;AAAA,UAAA;AAAA,YACC;AAAA,YACA,WAAW,GAAG,QAAQ,aAAa;AAAA,cACjC,CAAC,QAAQ,SAAS,GAAG,CAAC;AAAA,cACtB,CAAC,QAAQ,QAAQ,GAAG;AAAA,YAAA,CACrB;AAAA,YACD,MAAK;AAAA,YACL,aAAU;AAAA,YACV,iBAAc;AAAA,YACb,GAAG;AAAA,YAEH,UAAe,eAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MAClB;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WarningText.styles.js","sources":["../../../../src/FormElement/WarningText/WarningText.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvWarningText\", {\n root: {\n display: \"none\",\n color: theme.colors.negative_120,\n },\n defaultIcon: { minWidth: \"24px\", width: \"24px\", height: \"24px\" },\n warningText: {\n ...theme.typography.caption1,\n color: \"inherit\",\n paddingRight: theme.space.xs,\n },\n show: { display: \"flex\" },\n topGutter: { paddingTop: \"3px\" },\n hideText: {\n // display none or visibility hidden prevents\n // browser to trigger the aria-alert\n width: 0,\n height: 0,\n padding: 0,\n margin: 0,\n overflow: \"hidden\",\n },\n topBorder: { borderTop: \"1px solid currentcolor\" },\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,iBAAiB;AAAA,EAC1E,MAAM;AAAA,IACJ,SAAS;AAAA,IACT,OAAO,MAAM,OAAO;AAAA,EACtB;AAAA,EACA,aAAa,EAAE,UAAU,QAAQ,OAAO,QAAQ,QAAQ,OAAO;AAAA,EAC/D,aAAa;AAAA,IACX,GAAG,MAAM,WAAW;AAAA,IACpB,OAAO;AAAA,IACP,cAAc,MAAM,MAAM;AAAA,EAC5B;AAAA,EACA,MAAM,EAAE,SAAS,OAAO;AAAA,EACxB,WAAW,EAAE,YAAY,MAAM;AAAA,EAC/B,UAAU;AAAA;AAAA;AAAA,IAGR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,UAAU;AAAA,EACZ;AAAA,EACA,WAAW,EAAE,WAAW,yBAAyB;AACnD,CAAC;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
const HvFormElementContext = createContext(
|
|
3
|
+
{}
|
|
4
|
+
);
|
|
5
|
+
const HvFormElementDescriptorsContext = createContext({});
|
|
6
|
+
const HvFormElementValueContext = createContext(void 0);
|
|
7
|
+
export {
|
|
8
|
+
HvFormElementContext,
|
|
9
|
+
HvFormElementDescriptorsContext,
|
|
10
|
+
HvFormElementValueContext
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../../../src/FormElement/context.ts"],"sourcesContent":["import { createContext } from \"react\";\n\nimport type { HvFormStatus } from \"./FormElement\";\n\nexport interface HvFormElementContextValue {\n /** id to be applied to the form element root node. */\n id?: string;\n /**\n * Name of the form element.\n *\n * Part of a name/value pair, should be the name property of the underling native input.\n */\n name?: string;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvFormStatus;\n /** Whether the form element is disabled. */\n disabled?: boolean;\n /** Indicates that user input is required on the form element. */\n required?: boolean;\n /** Indicates that the form element is not editable. */\n readOnly?: boolean;\n}\n\nexport const HvFormElementContext = createContext<HvFormElementContextValue>(\n {},\n);\n\nexport interface HvFormElementDescriptorsContextValue {\n input?: any;\n label?: any;\n descriptors?: any;\n}\n\nexport const HvFormElementDescriptorsContext =\n createContext<HvFormElementDescriptorsContextValue>({});\n\nexport const HvFormElementValueContext = createContext<any>(undefined);\n"],"names":[],"mappings":";AA8BO,MAAM,uBAAuB;AAAA,EAClC,CAAA;AACF;AAQa,MAAA,kCACX,cAAoD,CAAE,CAAA;AAE3C,MAAA,4BAA4B,cAAmB,MAAS;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Children } from "react";
|
|
2
2
|
const findDescriptors = (children, descriptors = {
|
|
3
3
|
input: [],
|
|
4
4
|
label: [],
|
|
@@ -8,7 +8,7 @@ const findDescriptors = (children, descriptors = {
|
|
|
8
8
|
// TODO: refactor this out
|
|
9
9
|
HvCalendarHeader: []
|
|
10
10
|
}) => {
|
|
11
|
-
|
|
11
|
+
Children.forEach(children, (child) => {
|
|
12
12
|
if (child?.type?.formElementType && child.props?.id) {
|
|
13
13
|
descriptors[child.type.formElementType]?.push(
|
|
14
14
|
{
|
|
@@ -33,29 +33,39 @@ const getIdReferenceFor = (formElementType, descriptors, filterFor = null) => {
|
|
|
33
33
|
};
|
|
34
34
|
const buildFormElementPropsFromContext = (name, disabled, readOnly, required, context) => {
|
|
35
35
|
return {
|
|
36
|
-
name: name || context?.
|
|
37
|
-
disabled: disabled
|
|
38
|
-
readOnly: readOnly
|
|
39
|
-
required: required
|
|
40
|
-
status: context?.
|
|
36
|
+
name: name || context?.name,
|
|
37
|
+
disabled: disabled ?? context?.disabled,
|
|
38
|
+
readOnly: readOnly ?? context?.readOnly,
|
|
39
|
+
required: required ?? context?.required,
|
|
40
|
+
status: context?.status
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
|
-
const buildAriaPropsFromContext = (props, context,
|
|
43
|
+
const buildAriaPropsFromContext = (props, context, isInvalid2, inputId) => {
|
|
44
44
|
const arias = {
|
|
45
45
|
"aria-labelledby": props?.["aria-labelledby"] !== void 0 ? props?.["aria-labelledby"] : getIdReferenceListFor("label", context?.descriptors, inputId),
|
|
46
46
|
"aria-describedby": props?.["aria-describedby"] !== void 0 ? props?.["aria-describedby"] : getIdReferenceListFor("description", context?.descriptors),
|
|
47
47
|
"aria-controls": props?.["aria-controls"] !== void 0 ? props?.["aria-controls"] : getIdReferenceListFor("controlled", context?.descriptors)
|
|
48
48
|
};
|
|
49
|
-
if (
|
|
50
|
-
arias["aria-invalid"] =
|
|
49
|
+
if (isInvalid2) {
|
|
50
|
+
arias["aria-invalid"] = isInvalid2;
|
|
51
51
|
arias["aria-errormessage"] = props?.["aria-errormessage"] !== void 0 ? props?.["aria-errormessage"] : getIdReferenceFor("errormessage", context?.descriptors);
|
|
52
52
|
}
|
|
53
53
|
return arias;
|
|
54
54
|
};
|
|
55
|
+
const validationStates = Object.freeze({
|
|
56
|
+
standBy: "standBy",
|
|
57
|
+
valid: "valid",
|
|
58
|
+
invalid: "invalid"
|
|
59
|
+
});
|
|
60
|
+
const isValid = (state) => state === validationStates.valid;
|
|
61
|
+
const isInvalid = (state) => state === validationStates.invalid;
|
|
55
62
|
export {
|
|
56
63
|
buildAriaPropsFromContext,
|
|
57
64
|
buildFormElementPropsFromContext,
|
|
58
65
|
findDescriptors,
|
|
59
66
|
getIdReferenceFor,
|
|
60
|
-
getIdReferenceListFor
|
|
67
|
+
getIdReferenceListFor,
|
|
68
|
+
isInvalid,
|
|
69
|
+
isValid,
|
|
70
|
+
validationStates
|
|
61
71
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/FormElement/utils.ts"],"sourcesContent":["import { Children } from \"react\";\nimport type { InputBaseComponentProps } from \"@mui/material/InputBase\";\n\nimport type {\n HvFormElementContextValue,\n HvFormElementDescriptorsContextValue,\n} from \"./context\";\nimport type { HvFormStatus } from \"./FormElement\";\n\ninterface Descriptor {\n id?: string;\n htmlFor?: string;\n}\n/**\n * Scans the element's children looking for the children IDs that match the different form element types.\n * This function will produce an object that has a key for each provided name\n * Inside each key there will be an array with each id of the found descriptor.\n *\n * @param {Array} children - The children inside the form element to scan.\n * @param {Object} descriptors - Initial descriptors map (used for recursion).\n *\n */\nexport const findDescriptors = (\n children: React.ReactNode,\n descriptors: {\n input: Descriptor[];\n label: Descriptor[];\n description: Descriptor[];\n controlled: Descriptor[];\n errormessage: Descriptor[];\n HvCalendarHeader?: Descriptor[];\n } = {\n input: [],\n label: [],\n description: [],\n controlled: [],\n errormessage: [],\n\n // TODO: refactor this out\n HvCalendarHeader: [],\n },\n) => {\n Children.forEach(children, (child: any) => {\n if (child?.type?.formElementType && child.props?.id) {\n descriptors[child.type.formElementType as keyof typeof descriptors]?.push(\n {\n id: child.props?.id,\n htmlFor: child.props?.htmlFor,\n },\n );\n }\n\n if (child?.type?.formElementType !== \"formelement\") {\n findDescriptors(child?.props?.children, descriptors);\n }\n });\n\n return descriptors;\n};\n\nexport const getIdReferenceListFor = (\n formElementType: string,\n descriptors: any,\n filterFor: string | null = null,\n) => {\n const referenceList = descriptors?.[formElementType]\n ?.filter((d: any) => d.htmlFor !== filterFor)\n ?.map((d: any) => d.id)\n .join(\" \")\n .trim();\n\n return referenceList !== \"\" ? referenceList : undefined;\n};\n\nexport const getIdReferenceFor = (\n formElementType: string,\n descriptors: any,\n filterFor = null,\n) => {\n const referenceList = descriptors?.[formElementType]\n ?.filter((d: any) => d.htmlFor !== filterFor)\n ?.map((d: any) => d.id)?.[0];\n\n return referenceList !== \"\" ? referenceList : undefined;\n};\n\nexport const buildFormElementPropsFromContext = (\n name?: string,\n disabled?: boolean,\n readOnly?: boolean,\n required?: boolean,\n context?: HvFormElementContextValue,\n) => {\n return {\n name: name || context?.name,\n disabled: disabled ?? context?.disabled,\n readOnly: readOnly ?? context?.readOnly,\n required: required ?? context?.required,\n status: context?.status,\n };\n};\n\nexport const buildAriaPropsFromContext = (\n props: InputBaseComponentProps,\n context: HvFormElementDescriptorsContextValue,\n isInvalid: boolean,\n inputId?: string,\n) => {\n const arias: React.AriaAttributes = {\n \"aria-labelledby\":\n props?.[\"aria-labelledby\"] !== undefined\n ? props?.[\"aria-labelledby\"]\n : getIdReferenceListFor(\"label\", context?.descriptors, inputId),\n \"aria-describedby\":\n props?.[\"aria-describedby\"] !== undefined\n ? props?.[\"aria-describedby\"]\n : getIdReferenceListFor(\"description\", context?.descriptors),\n \"aria-controls\":\n props?.[\"aria-controls\"] !== undefined\n ? props?.[\"aria-controls\"]\n : getIdReferenceListFor(\"controlled\", context?.descriptors),\n };\n\n if (isInvalid) {\n arias[\"aria-invalid\"] = isInvalid;\n arias[\"aria-errormessage\"] =\n props?.[\"aria-errormessage\"] !== undefined\n ? props?.[\"aria-errormessage\"]\n : getIdReferenceFor(\"errormessage\", context?.descriptors);\n }\n\n return arias;\n};\n\nexport const validationStates = Object.freeze({\n standBy: \"standBy\",\n valid: \"valid\",\n invalid: \"invalid\",\n});\n\nexport const isValid = (state: HvFormStatus) =>\n state === validationStates.valid;\nexport const isInvalid = (state: HvFormStatus) =>\n state === validationStates.invalid;\n"],"names":["isInvalid"],"mappings":";AAsBa,MAAA,kBAAkB,CAC7B,UACA,cAOI;AAAA,EACF,OAAO,CAAC;AAAA,EACR,OAAO,CAAC;AAAA,EACR,aAAa,CAAC;AAAA,EACd,YAAY,CAAC;AAAA,EACb,cAAc,CAAC;AAAA;AAAA,EAGf,kBAAkB,CAAA;AACpB,MACG;AACM,WAAA,QAAQ,UAAU,CAAC,UAAe;AACzC,QAAI,OAAO,MAAM,mBAAmB,MAAM,OAAO,IAAI;AACvC,kBAAA,MAAM,KAAK,eAA2C,GAAG;AAAA,QACnE;AAAA,UACE,IAAI,MAAM,OAAO;AAAA,UACjB,SAAS,MAAM,OAAO;AAAA,QAAA;AAAA,MAE1B;AAAA,IAAA;AAGE,QAAA,OAAO,MAAM,oBAAoB,eAAe;AAClC,sBAAA,OAAO,OAAO,UAAU,WAAW;AAAA,IAAA;AAAA,EACrD,CACD;AAEM,SAAA;AACT;AAEO,MAAM,wBAAwB,CACnC,iBACA,aACA,YAA2B,SACxB;AACG,QAAA,gBAAgB,cAAc,eAAe,GAC/C,OAAO,CAAC,MAAW,EAAE,YAAY,SAAS,GAC1C,IAAI,CAAC,MAAW,EAAE,EAAE,EACrB,KAAK,GAAG,EACR,KAAK;AAED,SAAA,kBAAkB,KAAK,gBAAgB;AAChD;AAEO,MAAM,oBAAoB,CAC/B,iBACA,aACA,YAAY,SACT;AACH,QAAM,gBAAgB,cAAc,eAAe,GAC/C,OAAO,CAAC,MAAW,EAAE,YAAY,SAAS,GAC1C,IAAI,CAAC,MAAW,EAAE,EAAE,IAAI,CAAC;AAEtB,SAAA,kBAAkB,KAAK,gBAAgB;AAChD;AAEO,MAAM,mCAAmC,CAC9C,MACA,UACA,UACA,UACA,YACG;AACI,SAAA;AAAA,IACL,MAAM,QAAQ,SAAS;AAAA,IACvB,UAAU,YAAY,SAAS;AAAA,IAC/B,UAAU,YAAY,SAAS;AAAA,IAC/B,UAAU,YAAY,SAAS;AAAA,IAC/B,QAAQ,SAAS;AAAA,EACnB;AACF;AAEO,MAAM,4BAA4B,CACvC,OACA,SACAA,YACA,YACG;AACH,QAAM,QAA8B;AAAA,IAClC,mBACE,QAAQ,iBAAiB,MAAM,SAC3B,QAAQ,iBAAiB,IACzB,sBAAsB,SAAS,SAAS,aAAa,OAAO;AAAA,IAClE,oBACE,QAAQ,kBAAkB,MAAM,SAC5B,QAAQ,kBAAkB,IAC1B,sBAAsB,eAAe,SAAS,WAAW;AAAA,IAC/D,iBACE,QAAQ,eAAe,MAAM,SACzB,QAAQ,eAAe,IACvB,sBAAsB,cAAc,SAAS,WAAW;AAAA,EAChE;AAEA,MAAIA,YAAW;AACb,UAAM,cAAc,IAAIA;AACxB,UAAM,mBAAmB,IACvB,QAAQ,mBAAmB,MAAM,SAC7B,QAAQ,mBAAmB,IAC3B,kBAAkB,gBAAgB,SAAS,WAAW;AAAA,EAAA;AAGvD,SAAA;AACT;AAEa,MAAA,mBAAmB,OAAO,OAAO;AAAA,EAC5C,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AACX,CAAC;AAEM,MAAM,UAAU,CAAC,UACtB,UAAU,iBAAiB;AACtB,MAAM,YAAY,CAAC,UACxB,UAAU,iBAAiB;"}
|
package/dist/esm/Input/Input.js
CHANGED
|
@@ -4,7 +4,7 @@ import { useForkRef } from "@mui/material/utils";
|
|
|
4
4
|
import { CloseXS, Search, PreviewOff, Preview, Success } from "@hitachivantara/uikit-react-icons";
|
|
5
5
|
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
6
6
|
import { DEFAULT_ERROR_MESSAGES, computeValidationType, validateInput, computeValidationState, computeValidationMessage, hasBuiltInValidations } from "../BaseInput/validations.js";
|
|
7
|
-
import
|
|
7
|
+
import { HvSuggestions } from "../FormElement/Suggestions/Suggestions.js";
|
|
8
8
|
import { useControlled } from "../hooks/useControlled.js";
|
|
9
9
|
import { useIsMounted } from "../hooks/useIsMounted.js";
|
|
10
10
|
import { useLabels } from "../hooks/useLabels.js";
|
|
@@ -13,14 +13,14 @@ import { isKey } from "../utils/keyboardUtils.js";
|
|
|
13
13
|
import { setId } from "../utils/setId.js";
|
|
14
14
|
import { useClasses } from "./Input.styles.js";
|
|
15
15
|
import { staticClasses } from "./Input.styles.js";
|
|
16
|
-
import { HvAdornment } from "../
|
|
16
|
+
import { HvAdornment } from "../FormElement/Adornment/Adornment.js";
|
|
17
|
+
import { validationStates, isInvalid, isValid } from "../FormElement/utils.js";
|
|
17
18
|
import { HvBaseInput } from "../BaseInput/BaseInput.js";
|
|
18
|
-
import { HvSuggestions } from "../Forms/Suggestions/Suggestions.js";
|
|
19
19
|
import { HvTooltip } from "../Tooltip/Tooltip.js";
|
|
20
|
-
import { HvFormElement } from "../
|
|
21
|
-
import { HvLabel } from "../
|
|
22
|
-
import { HvInfoMessage } from "../
|
|
23
|
-
import { HvWarningText } from "../
|
|
20
|
+
import { HvFormElement } from "../FormElement/FormElement.js";
|
|
21
|
+
import { HvLabel } from "../FormElement/Label/Label.js";
|
|
22
|
+
import { HvInfoMessage } from "../FormElement/InfoMessage/InfoMessage.js";
|
|
23
|
+
import { HvWarningText } from "../FormElement/WarningText/WarningText.js";
|
|
24
24
|
const DEFAULT_LABELS = {
|
|
25
25
|
/** The label of the clear button. */
|
|
26
26
|
clearButtonLabel: "Clear the text",
|
|
@@ -53,9 +53,9 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
53
53
|
name,
|
|
54
54
|
value: valueProp,
|
|
55
55
|
defaultValue = "",
|
|
56
|
-
required
|
|
57
|
-
readOnly
|
|
58
|
-
disabled
|
|
56
|
+
required,
|
|
57
|
+
readOnly,
|
|
58
|
+
disabled,
|
|
59
59
|
enablePortal = false,
|
|
60
60
|
suggestOnFocus = false,
|
|
61
61
|
label,
|
|
@@ -99,9 +99,9 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
99
99
|
const isDirty = useRef(false);
|
|
100
100
|
const [value, setValue] = useControlled(valueProp, defaultValue);
|
|
101
101
|
const isEmptyValue = value == null || value === "";
|
|
102
|
-
const [validationState
|
|
102
|
+
const [validationState, setValidationState] = useControlled(
|
|
103
103
|
status,
|
|
104
|
-
|
|
104
|
+
validationStates.standBy
|
|
105
105
|
);
|
|
106
106
|
const [validationMessage, setValidationMessage] = useControlled(
|
|
107
107
|
statusMessage,
|
|
@@ -154,7 +154,7 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
154
154
|
validation,
|
|
155
155
|
inputProps
|
|
156
156
|
));
|
|
157
|
-
const isStateInvalid = isInvalid(validationState
|
|
157
|
+
const isStateInvalid = isInvalid(validationState);
|
|
158
158
|
const [revealPassword, setRevealPassword] = useState(false);
|
|
159
159
|
const realType = useMemo(() => {
|
|
160
160
|
if (type === "password") {
|
|
@@ -212,7 +212,7 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
212
212
|
};
|
|
213
213
|
const onFocusHandler = (event) => {
|
|
214
214
|
setFocused(true);
|
|
215
|
-
setValidationState(
|
|
215
|
+
setValidationState(validationStates.standBy);
|
|
216
216
|
onFocus?.(event, value);
|
|
217
217
|
};
|
|
218
218
|
const getSuggestions = (li) => {
|
|
@@ -247,12 +247,12 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
247
247
|
}
|
|
248
248
|
};
|
|
249
249
|
const hasOnEnter = onEnter != null;
|
|
250
|
-
const showClear = !disabled && !readOnly && !disableClear && !isEmptyValue && (!hasOnEnter || type !== "search" || disableSearchButton || validationState
|
|
250
|
+
const showClear = !disabled && !readOnly && !disableClear && !isEmptyValue && (!hasOnEnter || type !== "search" || disableSearchButton || validationState !== validationStates.standBy);
|
|
251
251
|
const showSearchIcon = type === "search" && !disableSearchButton;
|
|
252
252
|
const showRevealPasswordButton = type === "password" && !disableRevealPassword;
|
|
253
253
|
const handleClear = useCallback(
|
|
254
254
|
(event) => {
|
|
255
|
-
setValidationState(
|
|
255
|
+
setValidationState(validationStates.standBy);
|
|
256
256
|
changeInputValue(inputRef.current, "");
|
|
257
257
|
if (canShowSuggestions && suggestOnFocus) event.stopPropagation();
|
|
258
258
|
else {
|
|
@@ -294,7 +294,7 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
294
294
|
[onEnter, value]
|
|
295
295
|
);
|
|
296
296
|
const searchButton = useMemo(() => {
|
|
297
|
-
const reallyShowIt = showSearchIcon && (isEmptyValue || hasOnEnter && validationState
|
|
297
|
+
const reallyShowIt = showSearchIcon && (isEmptyValue || hasOnEnter && validationState === validationStates.standBy);
|
|
298
298
|
if (!reallyShowIt) {
|
|
299
299
|
return null;
|
|
300
300
|
}
|
|
@@ -311,7 +311,7 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
311
311
|
showSearchIcon,
|
|
312
312
|
isEmptyValue,
|
|
313
313
|
hasOnEnter,
|
|
314
|
-
validationState
|
|
314
|
+
validationState,
|
|
315
315
|
classes.adornmentButton,
|
|
316
316
|
handleSearch,
|
|
317
317
|
labels?.searchButtonLabel
|
|
@@ -355,11 +355,11 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
355
355
|
if (!showValidationIcon) {
|
|
356
356
|
return null;
|
|
357
357
|
}
|
|
358
|
-
if (!isValid(validationState
|
|
358
|
+
if (!isValid(validationState)) {
|
|
359
359
|
return null;
|
|
360
360
|
}
|
|
361
361
|
return /* @__PURE__ */ jsx(Success, { color: "positive", className: classes.icon });
|
|
362
|
-
}, [showValidationIcon, validationState
|
|
362
|
+
}, [showValidationIcon, validationState, classes.icon]);
|
|
363
363
|
const customIconEl = useMemo(
|
|
364
364
|
() => isValidElement(endAdornment) && cloneElement(endAdornment, {
|
|
365
365
|
className: cx(endAdornment.props.className, classes.icon)
|
|
@@ -395,7 +395,7 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
395
395
|
{
|
|
396
396
|
id,
|
|
397
397
|
name,
|
|
398
|
-
status: validationState
|
|
398
|
+
status: validationState,
|
|
399
399
|
disabled,
|
|
400
400
|
required,
|
|
401
401
|
readOnly,
|