@hitachivantara/uikit-react-core 5.82.2 → 5.82.4
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/BaseDropdown/BaseDropdown.cjs +1 -1
- 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/Card/Card.cjs +1 -1
- 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/ColorPicker/Fields/Fields.cjs +4 -4
- package/dist/cjs/ColorPicker/Picker/Picker.cjs +11 -3
- package/dist/cjs/ColorPicker/Picker/Picker.styles.cjs +6 -1
- package/dist/cjs/Controls/context/ControlsContext.cjs +1 -3
- package/dist/cjs/DatePicker/DatePicker.cjs +15 -15
- package/dist/cjs/DropDownMenu/DropDownMenu.cjs +1 -1
- 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 +10 -11
- 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 +7 -7
- 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/Grid/Grid.cjs +1 -1
- package/dist/cjs/Input/Input.cjs +17 -17
- package/dist/cjs/Input/Input.styles.cjs +2 -2
- package/dist/cjs/ListContainer/ListContext/ListContext.cjs +1 -3
- 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 +5 -7
- package/dist/cjs/SelectionList/SelectionList.cjs +7 -7
- package/dist/cjs/Slider/Slider.cjs +12 -12
- package/dist/cjs/Slider/utils.cjs +7 -7
- package/dist/cjs/Snackbar/SnackbarContent/SnackbarContent.cjs +1 -1
- package/dist/cjs/SnackbarProvider/SnackbarProvider.cjs +1 -1
- package/dist/cjs/Switch/Switch.cjs +9 -12
- package/dist/cjs/Table/TableBody/TableBody.cjs +10 -8
- package/dist/cjs/Table/TableCell/TableCell.cjs +2 -2
- package/dist/cjs/Table/TableContainer/TableContainer.cjs +9 -2
- package/dist/cjs/Table/TableHead/TableHead.cjs +10 -2
- package/dist/cjs/Table/TableHeader/TableHeader.cjs +2 -2
- package/dist/cjs/Table/TableRow/TableRow.cjs +2 -2
- package/dist/cjs/TableSection/TableSection.styles.cjs +6 -2
- 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/VerticalNavigation/TreeView/TreeViewItem.cjs +1 -1
- package/dist/cjs/hocs/withTooltip.cjs +40 -37
- package/dist/cjs/hooks/useIsMounted.cjs +2 -4
- package/dist/cjs/index.cjs +15 -36
- package/dist/esm/BaseDropdown/BaseDropdown.js +1 -1
- package/dist/esm/BaseDropdown/BaseDropdown.js.map +1 -1
- 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/Card/Card.js +1 -1
- package/dist/esm/Card/Card.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/ColorPicker/Fields/Fields.js +4 -4
- package/dist/esm/ColorPicker/Fields/Fields.js.map +1 -1
- package/dist/esm/ColorPicker/Picker/Picker.js +11 -3
- package/dist/esm/ColorPicker/Picker/Picker.js.map +1 -1
- package/dist/esm/ColorPicker/Picker/Picker.styles.js +6 -1
- package/dist/esm/ColorPicker/Picker/Picker.styles.js.map +1 -1
- package/dist/esm/Controls/context/ControlsContext.js +2 -2
- package/dist/esm/Controls/context/ControlsContext.js.map +1 -1
- package/dist/esm/DatePicker/DatePicker.js +9 -9
- package/dist/esm/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/Dialog/Dialog.js.map +1 -1
- package/dist/esm/DropDownMenu/DropDownMenu.js +1 -1
- package/dist/esm/DropDownMenu/DropDownMenu.js.map +1 -1
- package/dist/esm/Dropdown/Dropdown.js +8 -8
- package/dist/esm/Dropdown/Dropdown.js.map +1 -1
- package/dist/esm/EmptyState/EmptyState.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 +9 -10
- 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 +7 -7
- 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/GlobalActions/GlobalActions.js.map +1 -1
- package/dist/esm/Grid/Grid.js +1 -1
- package/dist/esm/Grid/Grid.js.map +1 -1
- package/dist/esm/InlineEditor/InlineEditor.js.map +1 -1
- 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/List/List.js.map +1 -1
- package/dist/esm/ListContainer/ListContext/ListContext.js +2 -2
- package/dist/esm/ListContainer/ListContext/ListContext.js.map +1 -1
- package/dist/esm/Pagination/Pagination.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 +5 -5
- 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 +12 -12
- 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/Snackbar/SnackbarContent/SnackbarContent.js +1 -1
- package/dist/esm/Snackbar/SnackbarContent/SnackbarContent.js.map +1 -1
- package/dist/esm/SnackbarProvider/SnackbarProvider.js +1 -1
- package/dist/esm/SnackbarProvider/SnackbarProvider.js.map +1 -1
- package/dist/esm/Switch/Switch.js +8 -11
- package/dist/esm/Switch/Switch.js.map +1 -1
- package/dist/esm/Table/TableBody/TableBody.js +10 -8
- package/dist/esm/Table/TableBody/TableBody.js.map +1 -1
- package/dist/esm/Table/TableCell/TableCell.js +2 -2
- package/dist/esm/Table/TableCell/TableCell.js.map +1 -1
- package/dist/esm/Table/TableContainer/TableContainer.js +9 -2
- package/dist/esm/Table/TableContainer/TableContainer.js.map +1 -1
- package/dist/esm/Table/TableHead/TableHead.js +10 -2
- package/dist/esm/Table/TableHead/TableHead.js.map +1 -1
- package/dist/esm/Table/TableHeader/TableHeader.js +2 -2
- package/dist/esm/Table/TableHeader/TableHeader.js.map +1 -1
- package/dist/esm/Table/TableRow/TableRow.js +2 -2
- package/dist/esm/Table/TableRow/TableRow.js.map +1 -1
- package/dist/esm/TableSection/TableSection.styles.js +6 -2
- package/dist/esm/TableSection/TableSection.styles.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/TreeView/internals/utils/EventManager.js.map +1 -1
- package/dist/esm/VerticalNavigation/TreeView/TreeViewItem.js +1 -1
- package/dist/esm/VerticalNavigation/TreeView/TreeViewItem.js.map +1 -1
- package/dist/esm/hocs/withTooltip.js +40 -37
- package/dist/esm/hocs/withTooltip.js.map +1 -1
- package/dist/esm/hooks/useIsMounted.js +3 -3
- package/dist/esm/hooks/useIsMounted.js.map +1 -1
- package/dist/esm/index.js +14 -35
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/deepMerge.js.map +1 -1
- package/dist/types/index.d.ts +66 -143
- package/package.json +6 -6
- 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
|
@@ -10,41 +10,44 @@ const styles = {
|
|
|
10
10
|
whiteSpace: "nowrap"
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
const withTooltip = (Component, label = "", placement, hideTooltip, tooltipProps, tooltipContainerProps) => (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
13
|
+
const withTooltip = (Component, label = "", placement, hideTooltip, tooltipProps, tooltipContainerProps) => (
|
|
14
|
+
// eslint-disable-next-line react/display-name
|
|
15
|
+
(props) => {
|
|
16
|
+
const [isHoverDisabled, setIsHoverDisabled] = React.useState(
|
|
17
|
+
false
|
|
18
|
+
);
|
|
19
|
+
const [open, setOpen] = React.useState(false);
|
|
20
|
+
const handleMouseEnter = (event) => {
|
|
21
|
+
const isHidden = hideTooltip?.(event);
|
|
22
|
+
setIsHoverDisabled(isHidden);
|
|
23
|
+
setOpen(!isHidden);
|
|
24
|
+
};
|
|
25
|
+
const handleMouseLeave = () => {
|
|
26
|
+
setIsHoverDisabled(false);
|
|
27
|
+
setOpen(false);
|
|
28
|
+
};
|
|
29
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
30
|
+
Tooltip.HvTooltip,
|
|
31
|
+
{
|
|
32
|
+
style: { ...styles.truncate },
|
|
33
|
+
disableHoverListener: isHoverDisabled,
|
|
34
|
+
disableFocusListener: true,
|
|
35
|
+
disableTouchListener: true,
|
|
36
|
+
title: label,
|
|
37
|
+
open,
|
|
38
|
+
placement,
|
|
39
|
+
...tooltipProps,
|
|
40
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
41
|
+
"div",
|
|
42
|
+
{
|
|
43
|
+
...tooltipContainerProps,
|
|
44
|
+
onMouseEnter: handleMouseEnter,
|
|
45
|
+
onMouseLeave: handleMouseLeave,
|
|
46
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props })
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
50
53
|
exports.withTooltip = withTooltip;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
|
-
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
5
|
-
const React__default = /* @__PURE__ */ _interopDefault(React);
|
|
6
4
|
const useIsMounted = () => {
|
|
7
|
-
const isMounted =
|
|
8
|
-
|
|
5
|
+
const isMounted = React.useRef(false);
|
|
6
|
+
React.useEffect(() => {
|
|
9
7
|
isMounted.current = true;
|
|
10
8
|
return () => {
|
|
11
9
|
isMounted.current = false;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const uikitStyles = require("@hitachivantara/uikit-styles");
|
|
4
4
|
const uikitReactUtils = require("@hitachivantara/uikit-react-utils");
|
|
5
|
+
const FormElement = require("./FormElement/FormElement.cjs");
|
|
5
6
|
const useClickOutside = require("./hooks/useClickOutside.cjs");
|
|
6
7
|
const useComputation = require("./hooks/useComputation.cjs");
|
|
7
8
|
const useControlled = require("./hooks/useControlled.cjs");
|
|
@@ -57,31 +58,25 @@ const ListContainer_styles = require("./ListContainer/ListContainer.styles.cjs")
|
|
|
57
58
|
const ListContainer = require("./ListContainer/ListContainer.cjs");
|
|
58
59
|
const ListItem_styles = require("./ListContainer/ListItem/ListItem.styles.cjs");
|
|
59
60
|
const ListItem = require("./ListContainer/ListItem/ListItem.cjs");
|
|
60
|
-
const CharCounter_styles = require("./
|
|
61
|
-
const CharCounter = require("./
|
|
62
|
-
const Adornment_styles = require("./
|
|
63
|
-
const Adornment = require("./
|
|
64
|
-
const FormElement_styles = require("./
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const Label_styles = require("./Forms/Label/Label.styles.cjs");
|
|
72
|
-
const Label = require("./Forms/Label/Label.cjs");
|
|
73
|
-
const InfoMessage_styles = require("./Forms/InfoMessage/InfoMessage.styles.cjs");
|
|
74
|
-
const InfoMessage = require("./Forms/InfoMessage/InfoMessage.cjs");
|
|
75
|
-
const WarningText_styles = require("./Forms/WarningText/WarningText.styles.cjs");
|
|
76
|
-
const WarningText = require("./Forms/WarningText/WarningText.cjs");
|
|
61
|
+
const CharCounter_styles = require("./FormElement/CharCounter/CharCounter.styles.cjs");
|
|
62
|
+
const CharCounter = require("./FormElement/CharCounter/CharCounter.cjs");
|
|
63
|
+
const Adornment_styles = require("./FormElement/Adornment/Adornment.styles.cjs");
|
|
64
|
+
const Adornment = require("./FormElement/Adornment/Adornment.cjs");
|
|
65
|
+
const FormElement_styles = require("./FormElement/FormElement.styles.cjs");
|
|
66
|
+
const Label_styles = require("./FormElement/Label/Label.styles.cjs");
|
|
67
|
+
const Label = require("./FormElement/Label/Label.cjs");
|
|
68
|
+
const InfoMessage_styles = require("./FormElement/InfoMessage/InfoMessage.styles.cjs");
|
|
69
|
+
const InfoMessage = require("./FormElement/InfoMessage/InfoMessage.cjs");
|
|
70
|
+
const WarningText_styles = require("./FormElement/WarningText/WarningText.styles.cjs");
|
|
71
|
+
const WarningText = require("./FormElement/WarningText/WarningText.cjs");
|
|
77
72
|
const Select_styles = require("./Select/Select.styles.cjs");
|
|
78
73
|
const Select = require("./Select/Select.cjs");
|
|
79
74
|
const Option = require("./Select/Option.cjs");
|
|
80
75
|
const OptionGroup = require("./Select/OptionGroup.cjs");
|
|
81
76
|
const SelectionList_styles = require("./SelectionList/SelectionList.styles.cjs");
|
|
82
77
|
const SelectionList = require("./SelectionList/SelectionList.cjs");
|
|
83
|
-
const Suggestions_styles = require("./
|
|
84
|
-
const Suggestions = require("./
|
|
78
|
+
const Suggestions_styles = require("./FormElement/Suggestions/Suggestions.styles.cjs");
|
|
79
|
+
const Suggestions = require("./FormElement/Suggestions/Suggestions.cjs");
|
|
85
80
|
const BaseInput_styles = require("./BaseInput/BaseInput.styles.cjs");
|
|
86
81
|
const BaseInput = require("./BaseInput/BaseInput.cjs");
|
|
87
82
|
const BaseDropdown_styles = require("./BaseDropdown/BaseDropdown.styles.cjs");
|
|
@@ -350,6 +345,7 @@ Object.defineProperty(exports, "useTheme", {
|
|
|
350
345
|
enumerable: true,
|
|
351
346
|
get: () => uikitReactUtils.useTheme
|
|
352
347
|
});
|
|
348
|
+
exports.HvFormElement = FormElement.HvFormElement;
|
|
353
349
|
exports.useClickOutside = useClickOutside.useClickOutside;
|
|
354
350
|
exports.useComputation = useComputation.useComputation;
|
|
355
351
|
exports.useControlled = useControlled.useControlled;
|
|
@@ -432,23 +428,6 @@ exports.HvCharCounter = CharCounter.HvCharCounter;
|
|
|
432
428
|
exports.adornmentClasses = Adornment_styles.staticClasses;
|
|
433
429
|
exports.HvAdornment = Adornment.HvAdornment;
|
|
434
430
|
exports.formElementClasses = FormElement_styles.staticClasses;
|
|
435
|
-
exports.HvFormElement = FormElement.HvFormElement;
|
|
436
|
-
exports.HvFormElementContext = FormElementContext.HvFormElementContext;
|
|
437
|
-
exports.HvFormElementContextConsumer = FormElementContext.HvFormElementContextConsumer;
|
|
438
|
-
exports.HvFormElementContextProvider = FormElementContext.HvFormElementContextProvider;
|
|
439
|
-
exports.HvFormElementValueContext = FormElementValueContext.HvFormElementValueContext;
|
|
440
|
-
exports.HvFormElementValueContextConsumer = FormElementValueContext.HvFormElementValueContextConsumer;
|
|
441
|
-
exports.HvFormElementValueContextProvider = FormElementValueContext.HvFormElementValueContextProvider;
|
|
442
|
-
exports.HvFormElementDescriptorsContext = FormElementDescriptorsContext.HvFormElementDescriptorsContext;
|
|
443
|
-
exports.HvFormElementDescriptorsContextConsumer = FormElementDescriptorsContext.HvFormElementDescriptorsContextConsumer;
|
|
444
|
-
exports.HvFormElementDescriptorsContextProvider = FormElementDescriptorsContext.HvFormElementDescriptorsContextProvider;
|
|
445
|
-
exports.buildAriaPropsFromContext = FormUtils.buildAriaPropsFromContext;
|
|
446
|
-
exports.buildFormElementPropsFromContext = FormUtils.buildFormElementPropsFromContext;
|
|
447
|
-
exports.findDescriptors = FormUtils.findDescriptors;
|
|
448
|
-
exports.getIdReferenceFor = FormUtils.getIdReferenceFor;
|
|
449
|
-
exports.getIdReferenceListFor = FormUtils.getIdReferenceListFor;
|
|
450
|
-
exports.isInvalid = validationStates.isInvalid;
|
|
451
|
-
exports.isValid = validationStates.isValid;
|
|
452
431
|
exports.labelClasses = Label_styles.staticClasses;
|
|
453
432
|
exports.HvLabel = Label.HvLabel;
|
|
454
433
|
exports.infoMessageClasses = InfoMessage_styles.staticClasses;
|
|
@@ -15,7 +15,7 @@ import { staticClasses } from "./BaseDropdown.styles.js";
|
|
|
15
15
|
import { BaseDropdownPanel } from "./BaseDropdownPanel.js";
|
|
16
16
|
import { useBaseDropdownContext, BaseDropdownContext } from "./context.js";
|
|
17
17
|
import { HvTypography } from "../Typography/Typography.js";
|
|
18
|
-
const BaseDropdown = forwardRef((props, ref)
|
|
18
|
+
const BaseDropdown = forwardRef(function BaseDropdown2(props, ref) {
|
|
19
19
|
const {
|
|
20
20
|
id: idProp,
|
|
21
21
|
className,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseDropdown.js","sources":["../../../src/BaseDropdown/BaseDropdown.tsx"],"sourcesContent":["import {\n cloneElement,\n forwardRef,\n Fragment,\n isValidElement,\n useCallback,\n useMemo,\n useState,\n} from \"react\";\nimport { PopperProps, usePopper } from \"react-popper\";\nimport type { ClickAwayListenerProps } from \"@mui/material/ClickAwayListener\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport { detectOverflow, Options, Placement } from \"@popperjs/core\";\nimport { DropDownXS, DropUpXS } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { getFirstAndLastFocus } from \"../utils/focusableElementFinder\";\nimport { isKey, isOneOfKeys } from \"../utils/keyboardUtils\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./BaseDropdown.styles\";\nimport { BaseDropdownPanel } from \"./BaseDropdownPanel\";\nimport { BaseDropdownContext, useBaseDropdownContext } from \"./context\";\n\nexport { staticClasses as baseDropdownClasses };\n\nexport type HvBaseDropdownClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvBaseDropdownProps\n extends HvBaseProps<HTMLDivElement, \"onToggle\"> {\n /**\n * The role of the element that triggers the popup.\n *\n * Defaults to \"combobox\" if `component` and the default\n * \"textbox\" header is used, undefined otherwise.\n */\n role?: string;\n /**\n * Header placeholder.\n */\n placeholder?: React.ReactNode;\n /**\n * If `true` the dropdown is disabled unable to be interacted, if `false` it is enabled.\n */\n disabled?: boolean;\n /**\n * If `true` the dropdown will be in read only mode, unable to be interacted.\n */\n readOnly?: boolean;\n /**\n * Indicates that user input is required on the form element.\n */\n required?: boolean;\n /**\n * Disable the portal behavior.\n * The children stay within it's parent DOM hierarchy.\n */\n disablePortal?: boolean;\n /**\n * If `true` the dropdown width depends size of content if `false` the width depends on the header size.\n * Defaults to `false`.\n */\n variableWidth?: boolean;\n /**\n * If `true` the dropdown starts opened if `false` it starts closed.\n */\n expanded?: boolean;\n /**\n * When uncontrolled, defines the initial expanded state.\n */\n defaultExpanded?: boolean;\n /**\n * An object containing props to be wired to the popper component.\n */\n popperProps?: Partial<PopperProps<any>>;\n /**\n * Placement of the dropdown.\n */\n placement?: \"left\" | \"right\";\n /**\n * Replacement for the header component.\n * @deprecated use `Component` instead\n */\n component?: React.ReactNode;\n /** Replacement for the header component */\n headerComponent?: React.ElementType;\n /**\n * Adornment to replace the default arrows.\n */\n adornment?: React.ReactNode;\n /**\n * When dropdown changes the expanded state.\n */\n onToggle?: (event: Event, open: boolean) => void;\n /**\n * When user click outside the open container.\n */\n onClickOutside?: (event: Event) => void;\n /**\n * Callback called when the dropdown is opened and ready,\n * commonly used to set focus to the content.\n */\n onContainerCreation?: (container: HTMLElement | null) => void;\n /**\n * Attributes applied to the dropdown header element.\n */\n dropdownHeaderProps?: React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLDivElement>,\n HTMLDivElement\n >;\n /**\n * Pass a ref to the dropdown header element.\n */\n dropdownHeaderRef?: React.Ref<HTMLDivElement>;\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvBaseDropdownClasses;\n /** @ignore */\n ref?: React.Ref<HTMLDivElement>;\n}\n\nconst BaseDropdown = forwardRef<\n HTMLDivElement,\n Omit<\n HvBaseDropdownProps,\n \"popperProps\" | \"variableWidth\" | \"placement\" | \"onContainerCreation\"\n >\n>((props, ref) => {\n const {\n id: idProp,\n className,\n classes: classesProp,\n children,\n role,\n placeholder,\n component,\n headerComponent: HeaderComponentProp,\n adornment,\n expanded,\n dropdownHeaderProps,\n defaultExpanded,\n disabled,\n readOnly,\n required,\n disablePortal,\n \"aria-expanded\": ariaExpandedProp,\n \"aria-label\": ariaLabelProp,\n \"aria-labelledby\": ariaLabelledByProp,\n dropdownHeaderRef: dropdownHeaderRefProp,\n onToggle,\n onClickOutside,\n ...others\n } = props;\n\n const { classes, cx } = useClasses(classesProp);\n\n const {\n popperPlacement,\n popperElement,\n referenceElement,\n setReferenceElement,\n } = useBaseDropdownContext();\n\n const [isOpen, setIsOpen] = useControlled(expanded, Boolean(defaultExpanded));\n\n const headerRef = useForkRef(\n setReferenceElement,\n dropdownHeaderRefProp,\n dropdownHeaderProps?.ref as any,\n );\n\n const customHeaderRef = useForkRef(ref, headerRef);\n\n const ariaRole = role || (component == null ? \"combobox\" : undefined);\n\n const ariaExpanded = ariaExpandedProp ?? (ariaRole ? !!isOpen : undefined);\n\n const id = useUniqueId(idProp);\n const containerId = setId(id, \"children-container\");\n\n const headerControlArias = {\n \"aria-required\": required ?? undefined,\n \"aria-readonly\": readOnly ?? undefined,\n \"aria-disabled\": disabled ?? undefined,\n\n \"aria-expanded\": ariaExpanded,\n \"aria-owns\": isOpen ? containerId : undefined,\n \"aria-controls\": isOpen ? containerId : undefined,\n } satisfies React.AriaAttributes;\n\n const headerAriaLabels = {\n \"aria-label\": ariaLabelProp,\n \"aria-labelledby\": ariaLabelledByProp,\n } satisfies React.AriaAttributes;\n\n const handleToggle = useCallback(\n (event: any) => {\n if (event && !isKey(event, \"Tab\")) {\n event.preventDefault();\n }\n\n const notControlKey =\n !!event?.code &&\n !isOneOfKeys(event, [\"Tab\", \"Enter\", \"Esc\", \"ArrowDown\", \"Space\"]);\n\n const ignoredCombinations =\n (isKey(event, \"Esc\") && !isOpen) ||\n (isKey(event, \"ArrowDown\") && isOpen) ||\n (isKey(event, \"Tab\") && !isOpen);\n\n if (disabled || notControlKey || ignoredCombinations) return;\n\n const newOpen = !isOpen;\n\n /* If about to close focus on the header component. */\n setIsOpen(() => {\n if (!newOpen) {\n // Focus-ring won't be visible even if using the keyboard:\n // https://github.com/WICG/focus-visible/issues/88\n referenceElement?.focus({ preventScroll: true });\n }\n\n return newOpen;\n });\n\n onToggle?.(event, newOpen);\n },\n [isOpen, disabled, setIsOpen, onToggle, referenceElement],\n );\n\n const ExpanderComponent = isOpen ? DropUpXS : DropDownXS;\n\n const defaultHeaderElement = (\n <div\n id={setId(id, \"header\")}\n className={cx(classes.header, {\n [classes.headerDisabled]: disabled,\n [classes.headerReadOnly]: readOnly,\n [classes.headerOpen]: isOpen,\n [classes.headerOpenUp]: isOpen && popperPlacement?.includes(\"top\"),\n [classes.headerOpenDown]: isOpen && popperPlacement?.includes(\"bottom\"),\n })}\n // TODO: review \"textbox\" role\n role={ariaRole === \"combobox\" ? \"textbox\" : undefined}\n {...headerAriaLabels}\n style={disabled || readOnly ? { pointerEvents: \"none\" } : undefined}\n // Removes the element from the navigation sequence for keyboard focus if disabled\n tabIndex={disabled ? -1 : 0}\n ref={headerRef}\n {...dropdownHeaderProps}\n >\n <div\n className={cx(classes.selection, {\n [classes.selectionDisabled]: disabled,\n })}\n >\n {placeholder && typeof placeholder === \"string\" ? (\n <HvTypography noWrap className={classes.placeholder}>\n {placeholder}\n </HvTypography>\n ) : (\n placeholder\n )}\n </div>\n <div className={classes.arrowContainer}>\n {adornment || (\n <ExpanderComponent\n iconSize=\"XS\"\n color={disabled ? \"secondary_60\" : undefined}\n className={classes.arrow}\n />\n )}\n </div>\n </div>\n );\n\n const headerElement =\n component && isValidElement(component)\n ? cloneElement(component as React.ReactElement, {\n ref: headerRef,\n ...headerControlArias,\n })\n : defaultHeaderElement;\n\n /** Handle keyboard inside children container. */\n const handleContainerKeyDown: React.KeyboardEventHandler = (event) => {\n if (isKey(event, \"Esc\")) {\n handleToggle(event);\n }\n if (isKey(event, \"Tab\") && !event.shiftKey) {\n const focusList = getFirstAndLastFocus(popperElement);\n if (document.activeElement === focusList?.last) {\n event.preventDefault();\n focusList?.first?.focus();\n }\n }\n };\n\n const handleOutside: ClickAwayListenerProps[\"onClickAway\"] = (event) => {\n const isButtonClick = referenceElement?.contains(event.target as any);\n if (!isButtonClick) {\n onClickOutside?.(event);\n setIsOpen(false);\n onToggle?.(event, false);\n }\n };\n\n const hasCustomHeader = !!HeaderComponentProp;\n const HeaderComponent = HeaderComponentProp || \"div\";\n const RootComponent = HeaderComponentProp ? Fragment : \"div\";\n\n return (\n <RootComponent {...(!hasCustomHeader && { className: classes.root })}>\n <HeaderComponent\n ref={hasCustomHeader ? customHeaderRef : ref}\n id={id}\n disabled={hasCustomHeader && disabled}\n className={cx(className, {\n [classes.anchor]: !hasCustomHeader,\n [classes.rootDisabled]: disabled,\n })}\n {...(!readOnly && {\n onKeyDown: handleToggle,\n onClick: handleToggle,\n })}\n {...((ariaRole || hasCustomHeader) && {\n role: hasCustomHeader ? undefined : ariaRole,\n ...headerAriaLabels,\n ...headerControlArias,\n })}\n // Removes the element from the navigation sequence for keyboard focus\n tabIndex={hasCustomHeader ? undefined : -1}\n {...others}\n >\n {headerElement}\n </HeaderComponent>\n {isOpen && (\n <BaseDropdownPanel\n classes={classes}\n containerId={containerId}\n onClickAway={handleOutside}\n onContainerKeyDown={handleContainerKeyDown}\n >\n {children}\n </BaseDropdownPanel>\n )}\n </RootComponent>\n );\n});\n\nexport const HvBaseDropdown = forwardRef<HTMLDivElement, HvBaseDropdownProps>(\n function HvBaseDropdown(props, ref) {\n const {\n popperProps = {},\n variableWidth,\n placement: placementProp = \"right\",\n onContainerCreation,\n ...others\n } = useDefaultProps(\"HvBaseDropdown\", props);\n\n const placement: Placement = `bottom-${\n placementProp === \"right\" ? \"start\" : \"end\"\n }`;\n\n const { modifiers: popperPropsModifiers, ...otherPopperProps } =\n popperProps;\n\n const [referenceElement, setReferenceElement] =\n useState<HTMLElement | null>(null);\n const [popperElement, setPopperElement] = useState<HTMLElement | null>(\n null,\n );\n\n const onFirstUpdate = useCallback(() => {\n onContainerCreation?.(popperElement);\n }, [onContainerCreation, popperElement]);\n\n const modifiers = useMemo<Options[\"modifiers\"]>(\n () => [\n {\n name: \"variableWidth\",\n enabled: !variableWidth,\n phase: \"beforeWrite\",\n requires: [\"computeStyles\"],\n fn: ({ state }) => {\n state.styles.popper.width = `${state.rects.reference.width}px`;\n },\n effect: ({ state }) => {\n state.elements.popper.style.width = `${\n (state.elements.reference as any).offsetWidth\n }px`;\n },\n },\n {\n name: \"maxSize\",\n enabled: true,\n phase: \"main\",\n requiresIfExists: [\"offset\", \"preventOverflow\", \"flip\"],\n fn: ({ state, name, options }) => {\n const overflow = detectOverflow(state, options);\n\n const x = state.modifiersData.preventOverflow?.x || 0;\n const y = state.modifiersData.preventOverflow?.y || 0;\n\n const popperWidth = state.rects.popper.width;\n const popperHeight = state.rects.popper.height;\n\n const basePlacement = state.placement.split(\"-\")[0];\n\n const widthProp = basePlacement === \"left\" ? \"left\" : \"right\";\n const heightProp = basePlacement === \"top\" ? \"top\" : \"bottom\";\n\n state.modifiersData[name] = {\n width: popperWidth - overflow[widthProp] - x,\n height: popperHeight - overflow[heightProp] - y,\n };\n },\n },\n {\n name: \"applyMaxSize\",\n enabled: true,\n phase: \"beforeWrite\",\n requires: [\"maxSize\"],\n fn: ({ state }) => {\n // The `maxSize` modifier provides this data\n const { width, height } = state.modifiersData.maxSize;\n state.styles.popper.maxWidth = `${width}px`;\n state.styles.popper.maxHeight = `${height}px`;\n },\n },\n ...(popperPropsModifiers || []),\n ],\n [popperPropsModifiers, variableWidth],\n );\n\n const popper = usePopper(referenceElement, popperElement, {\n placement,\n modifiers,\n onFirstUpdate,\n ...otherPopperProps,\n });\n\n const value = useMemo(\n () => ({\n popperPlacement:\n (popper?.attributes.popper?.[\"data-popper-placement\"] as Placement) ??\n \"bottom\",\n popper,\n popperElement,\n setPopperElement,\n referenceElement,\n setReferenceElement,\n }),\n [popper, popperElement, referenceElement],\n );\n\n return (\n <BaseDropdownContext.Provider value={value}>\n <BaseDropdown ref={ref} {...others} />\n </BaseDropdownContext.Provider>\n );\n },\n);\n"],"names":["HvBaseDropdown"],"mappings":";;;;;;;;;;;;;;;;;AAgIA,MAAM,eAAe,WAMnB,CAAC,OAAO,QAAQ;AACV,QAAA;AAAA,IACJ,IAAI;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,IACjB,cAAc;AAAA,IACd,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,IACnB;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AAEJ,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAExC,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE,uBAAuB;AAErB,QAAA,CAAC,QAAQ,SAAS,IAAI,cAAc,UAAU,QAAQ,eAAe,CAAC;AAE5E,QAAM,YAAY;AAAA,IAChB;AAAA,IACA;AAAA,IACA,qBAAqB;AAAA,EACvB;AAEM,QAAA,kBAAkB,WAAW,KAAK,SAAS;AAEjD,QAAM,WAAW,SAAS,aAAa,OAAO,aAAa;AAE3D,QAAM,eAAe,qBAAqB,WAAW,CAAC,CAAC,SAAS;AAE1D,QAAA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AAA,aAAa,kBAAkB,QAAQ,QAAQ;AAE/C,kBAAA,cAAc,IAAI,IAAI;AAAA,cAC1B,OAAO,cAAc,SAAS,SAAS,IAAI;AAAA,cAC3C,QAAQ,eAAe,SAAS,UAAU,IAAI;AAAA,YAChD;AAAA,UAAA;AAAA,QAEJ;AAAA,QACA;AAAA,UACE,MAAM;AAAA,UACN,SAAS;AAAA,UACT,OAAO;AAAA,UACP,UAAU,CAAC,SAAS;AAAA,UACpB,IAAI,CAAC,EAAE,YAAY;AAEjB,kBAAM,EAAE,OAAO,OAAO,IAAI,MAAM,cAAc;AAC9C,kBAAM,OAAO,OAAO,WAAW,GAAG,KAAK;AACvC,kBAAM,OAAO,OAAO,YAAY,GAAG,MAAM;AAAA,UAAA;AAAA,QAE7C;AAAA,QACA,GAAI,wBAAwB,CAAA;AAAA,MAC9B;AAAA,MACA,CAAC,sBAAsB,aAAa;AAAA,IACtC;AAEM,UAAA,SAAS,UAAU,kBAAkB,eAAe;AAAA,MACxD;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA,CACJ;AAED,UAAM,QAAQ;AAAA,MACZ,OAAO;AAAA,QACL,iBACG,QAAQ,WAAW,SAAS,uBAAuB,KACpD;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,MAEF,CAAC,QAAQ,eAAe,gBAAgB;AAAA,IAC1C;AAGE,WAAA,oBAAC,oBAAoB,UAApB,EAA6B,OAC5B,8BAAC,cAAa,EAAA,KAAW,GAAG,OAAA,CAAQ,EACtC,CAAA;AAAA,EAAA;AAGN;"}
|
|
1
|
+
{"version":3,"file":"BaseDropdown.js","sources":["../../../src/BaseDropdown/BaseDropdown.tsx"],"sourcesContent":["import {\n cloneElement,\n forwardRef,\n Fragment,\n isValidElement,\n useCallback,\n useMemo,\n useState,\n} from \"react\";\nimport { PopperProps, usePopper } from \"react-popper\";\nimport type { ClickAwayListenerProps } from \"@mui/material/ClickAwayListener\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport { detectOverflow, Options, Placement } from \"@popperjs/core\";\nimport { DropDownXS, DropUpXS } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { getFirstAndLastFocus } from \"../utils/focusableElementFinder\";\nimport { isKey, isOneOfKeys } from \"../utils/keyboardUtils\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./BaseDropdown.styles\";\nimport { BaseDropdownPanel } from \"./BaseDropdownPanel\";\nimport { BaseDropdownContext, useBaseDropdownContext } from \"./context\";\n\nexport { staticClasses as baseDropdownClasses };\n\nexport type HvBaseDropdownClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvBaseDropdownProps\n extends HvBaseProps<HTMLDivElement, \"onToggle\"> {\n /**\n * The role of the element that triggers the popup.\n *\n * Defaults to \"combobox\" if `component` and the default\n * \"textbox\" header is used, undefined otherwise.\n */\n role?: string;\n /**\n * Header placeholder.\n */\n placeholder?: React.ReactNode;\n /**\n * If `true` the dropdown is disabled unable to be interacted, if `false` it is enabled.\n */\n disabled?: boolean;\n /**\n * If `true` the dropdown will be in read only mode, unable to be interacted.\n */\n readOnly?: boolean;\n /**\n * Indicates that user input is required on the form element.\n */\n required?: boolean;\n /**\n * Disable the portal behavior.\n * The children stay within it's parent DOM hierarchy.\n */\n disablePortal?: boolean;\n /**\n * If `true` the dropdown width depends size of content if `false` the width depends on the header size.\n * Defaults to `false`.\n */\n variableWidth?: boolean;\n /**\n * If `true` the dropdown starts opened if `false` it starts closed.\n */\n expanded?: boolean;\n /**\n * When uncontrolled, defines the initial expanded state.\n */\n defaultExpanded?: boolean;\n /**\n * An object containing props to be wired to the popper component.\n */\n popperProps?: Partial<PopperProps<any>>;\n /**\n * Placement of the dropdown.\n */\n placement?: \"left\" | \"right\";\n /**\n * Replacement for the header component.\n * @deprecated use `Component` instead\n */\n component?: React.ReactNode;\n /** Replacement for the header component */\n headerComponent?: React.ElementType;\n /**\n * Adornment to replace the default arrows.\n */\n adornment?: React.ReactNode;\n /**\n * When dropdown changes the expanded state.\n */\n onToggle?: (event: Event, open: boolean) => void;\n /**\n * When user click outside the open container.\n */\n onClickOutside?: (event: Event) => void;\n /**\n * Callback called when the dropdown is opened and ready,\n * commonly used to set focus to the content.\n */\n onContainerCreation?: (container: HTMLElement | null) => void;\n /**\n * Attributes applied to the dropdown header element.\n */\n dropdownHeaderProps?: React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLDivElement>,\n HTMLDivElement\n >;\n /**\n * Pass a ref to the dropdown header element.\n */\n dropdownHeaderRef?: React.Ref<HTMLDivElement>;\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvBaseDropdownClasses;\n /** @ignore */\n ref?: React.Ref<HTMLDivElement>;\n}\n\nconst BaseDropdown = forwardRef<\n HTMLDivElement,\n Omit<\n HvBaseDropdownProps,\n \"popperProps\" | \"variableWidth\" | \"placement\" | \"onContainerCreation\"\n >\n>(function BaseDropdown(props, ref) {\n const {\n id: idProp,\n className,\n classes: classesProp,\n children,\n role,\n placeholder,\n component,\n headerComponent: HeaderComponentProp,\n adornment,\n expanded,\n dropdownHeaderProps,\n defaultExpanded,\n disabled,\n readOnly,\n required,\n disablePortal,\n \"aria-expanded\": ariaExpandedProp,\n \"aria-label\": ariaLabelProp,\n \"aria-labelledby\": ariaLabelledByProp,\n dropdownHeaderRef: dropdownHeaderRefProp,\n onToggle,\n onClickOutside,\n ...others\n } = props;\n\n const { classes, cx } = useClasses(classesProp);\n\n const {\n popperPlacement,\n popperElement,\n referenceElement,\n setReferenceElement,\n } = useBaseDropdownContext();\n\n const [isOpen, setIsOpen] = useControlled(expanded, Boolean(defaultExpanded));\n\n const headerRef = useForkRef(\n setReferenceElement,\n dropdownHeaderRefProp,\n dropdownHeaderProps?.ref as any,\n );\n\n const customHeaderRef = useForkRef(ref, headerRef);\n\n const ariaRole = role || (component == null ? \"combobox\" : undefined);\n\n const ariaExpanded = ariaExpandedProp ?? (ariaRole ? !!isOpen : undefined);\n\n const id = useUniqueId(idProp);\n const containerId = setId(id, \"children-container\");\n\n const headerControlArias = {\n \"aria-required\": required ?? undefined,\n \"aria-readonly\": readOnly ?? undefined,\n \"aria-disabled\": disabled ?? undefined,\n\n \"aria-expanded\": ariaExpanded,\n \"aria-owns\": isOpen ? containerId : undefined,\n \"aria-controls\": isOpen ? containerId : undefined,\n } satisfies React.AriaAttributes;\n\n const headerAriaLabels = {\n \"aria-label\": ariaLabelProp,\n \"aria-labelledby\": ariaLabelledByProp,\n } satisfies React.AriaAttributes;\n\n const handleToggle = useCallback(\n (event: any) => {\n if (event && !isKey(event, \"Tab\")) {\n event.preventDefault();\n }\n\n const notControlKey =\n !!event?.code &&\n !isOneOfKeys(event, [\"Tab\", \"Enter\", \"Esc\", \"ArrowDown\", \"Space\"]);\n\n const ignoredCombinations =\n (isKey(event, \"Esc\") && !isOpen) ||\n (isKey(event, \"ArrowDown\") && isOpen) ||\n (isKey(event, \"Tab\") && !isOpen);\n\n if (disabled || notControlKey || ignoredCombinations) return;\n\n const newOpen = !isOpen;\n\n /* If about to close focus on the header component. */\n setIsOpen(() => {\n if (!newOpen) {\n // Focus-ring won't be visible even if using the keyboard:\n // https://github.com/WICG/focus-visible/issues/88\n referenceElement?.focus({ preventScroll: true });\n }\n\n return newOpen;\n });\n\n onToggle?.(event, newOpen);\n },\n [isOpen, disabled, setIsOpen, onToggle, referenceElement],\n );\n\n const ExpanderComponent = isOpen ? DropUpXS : DropDownXS;\n\n const defaultHeaderElement = (\n <div\n id={setId(id, \"header\")}\n className={cx(classes.header, {\n [classes.headerDisabled]: disabled,\n [classes.headerReadOnly]: readOnly,\n [classes.headerOpen]: isOpen,\n [classes.headerOpenUp]: isOpen && popperPlacement?.includes(\"top\"),\n [classes.headerOpenDown]: isOpen && popperPlacement?.includes(\"bottom\"),\n })}\n // TODO: review \"textbox\" role\n role={ariaRole === \"combobox\" ? \"textbox\" : undefined}\n {...headerAriaLabels}\n style={disabled || readOnly ? { pointerEvents: \"none\" } : undefined}\n // Removes the element from the navigation sequence for keyboard focus if disabled\n tabIndex={disabled ? -1 : 0}\n ref={headerRef}\n {...dropdownHeaderProps}\n >\n <div\n className={cx(classes.selection, {\n [classes.selectionDisabled]: disabled,\n })}\n >\n {placeholder && typeof placeholder === \"string\" ? (\n <HvTypography noWrap className={classes.placeholder}>\n {placeholder}\n </HvTypography>\n ) : (\n placeholder\n )}\n </div>\n <div className={classes.arrowContainer}>\n {adornment || (\n <ExpanderComponent\n iconSize=\"XS\"\n color={disabled ? \"secondary_60\" : undefined}\n className={classes.arrow}\n />\n )}\n </div>\n </div>\n );\n\n const headerElement =\n component && isValidElement(component)\n ? cloneElement(component as React.ReactElement, {\n ref: headerRef,\n ...headerControlArias,\n })\n : defaultHeaderElement;\n\n /** Handle keyboard inside children container. */\n const handleContainerKeyDown: React.KeyboardEventHandler = (event) => {\n if (isKey(event, \"Esc\")) {\n handleToggle(event);\n }\n if (isKey(event, \"Tab\") && !event.shiftKey) {\n const focusList = getFirstAndLastFocus(popperElement);\n if (document.activeElement === focusList?.last) {\n event.preventDefault();\n focusList?.first?.focus();\n }\n }\n };\n\n const handleOutside: ClickAwayListenerProps[\"onClickAway\"] = (event) => {\n const isButtonClick = referenceElement?.contains(event.target as any);\n if (!isButtonClick) {\n onClickOutside?.(event);\n setIsOpen(false);\n onToggle?.(event, false);\n }\n };\n\n const hasCustomHeader = !!HeaderComponentProp;\n const HeaderComponent = HeaderComponentProp || \"div\";\n const RootComponent = HeaderComponentProp ? Fragment : \"div\";\n\n return (\n <RootComponent {...(!hasCustomHeader && { className: classes.root })}>\n <HeaderComponent\n ref={hasCustomHeader ? customHeaderRef : ref}\n id={id}\n disabled={hasCustomHeader && disabled}\n className={cx(className, {\n [classes.anchor]: !hasCustomHeader,\n [classes.rootDisabled]: disabled,\n })}\n {...(!readOnly && {\n onKeyDown: handleToggle,\n onClick: handleToggle,\n })}\n {...((ariaRole || hasCustomHeader) && {\n role: hasCustomHeader ? undefined : ariaRole,\n ...headerAriaLabels,\n ...headerControlArias,\n })}\n // Removes the element from the navigation sequence for keyboard focus\n tabIndex={hasCustomHeader ? undefined : -1}\n {...others}\n >\n {headerElement}\n </HeaderComponent>\n {isOpen && (\n <BaseDropdownPanel\n classes={classes}\n containerId={containerId}\n onClickAway={handleOutside}\n onContainerKeyDown={handleContainerKeyDown}\n >\n {children}\n </BaseDropdownPanel>\n )}\n </RootComponent>\n );\n});\n\nexport const HvBaseDropdown = forwardRef<HTMLDivElement, HvBaseDropdownProps>(\n function HvBaseDropdown(props, ref) {\n const {\n popperProps = {},\n variableWidth,\n placement: placementProp = \"right\",\n onContainerCreation,\n ...others\n } = useDefaultProps(\"HvBaseDropdown\", props);\n\n const placement: Placement = `bottom-${\n placementProp === \"right\" ? \"start\" : \"end\"\n }`;\n\n const { modifiers: popperPropsModifiers, ...otherPopperProps } =\n popperProps;\n\n const [referenceElement, setReferenceElement] =\n useState<HTMLElement | null>(null);\n const [popperElement, setPopperElement] = useState<HTMLElement | null>(\n null,\n );\n\n const onFirstUpdate = useCallback(() => {\n onContainerCreation?.(popperElement);\n }, [onContainerCreation, popperElement]);\n\n const modifiers = useMemo<Options[\"modifiers\"]>(\n () => [\n {\n name: \"variableWidth\",\n enabled: !variableWidth,\n phase: \"beforeWrite\",\n requires: [\"computeStyles\"],\n fn: ({ state }) => {\n state.styles.popper.width = `${state.rects.reference.width}px`;\n },\n effect: ({ state }) => {\n state.elements.popper.style.width = `${\n (state.elements.reference as any).offsetWidth\n }px`;\n },\n },\n {\n name: \"maxSize\",\n enabled: true,\n phase: \"main\",\n requiresIfExists: [\"offset\", \"preventOverflow\", \"flip\"],\n fn: ({ state, name, options }) => {\n const overflow = detectOverflow(state, options);\n\n const x = state.modifiersData.preventOverflow?.x || 0;\n const y = state.modifiersData.preventOverflow?.y || 0;\n\n const popperWidth = state.rects.popper.width;\n const popperHeight = state.rects.popper.height;\n\n const basePlacement = state.placement.split(\"-\")[0];\n\n const widthProp = basePlacement === \"left\" ? \"left\" : \"right\";\n const heightProp = basePlacement === \"top\" ? \"top\" : \"bottom\";\n\n state.modifiersData[name] = {\n width: popperWidth - overflow[widthProp] - x,\n height: popperHeight - overflow[heightProp] - y,\n };\n },\n },\n {\n name: \"applyMaxSize\",\n enabled: true,\n phase: \"beforeWrite\",\n requires: [\"maxSize\"],\n fn: ({ state }) => {\n // The `maxSize` modifier provides this data\n const { width, height } = state.modifiersData.maxSize;\n state.styles.popper.maxWidth = `${width}px`;\n state.styles.popper.maxHeight = `${height}px`;\n },\n },\n ...(popperPropsModifiers || []),\n ],\n [popperPropsModifiers, variableWidth],\n );\n\n const popper = usePopper(referenceElement, popperElement, {\n placement,\n modifiers,\n onFirstUpdate,\n ...otherPopperProps,\n });\n\n const value = useMemo(\n () => ({\n popperPlacement:\n (popper?.attributes.popper?.[\"data-popper-placement\"] as Placement) ??\n \"bottom\",\n popper,\n popperElement,\n setPopperElement,\n referenceElement,\n setReferenceElement,\n }),\n [popper, popperElement, referenceElement],\n );\n\n return (\n <BaseDropdownContext.Provider value={value}>\n <BaseDropdown ref={ref} {...others} />\n </BaseDropdownContext.Provider>\n );\n },\n);\n"],"names":["BaseDropdown","HvBaseDropdown"],"mappings":";;;;;;;;;;;;;;;;;AAgIA,MAAM,eAAe,WAMnB,SAASA,cAAa,OAAO,KAAK;AAC5B,QAAA;AAAA,IACJ,IAAI;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB;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;AAAA,QACL,iBACG,QAAQ,WAAW,SAAS,uBAAuB,KACpD;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,MAEF,CAAC,QAAQ,eAAe,gBAAgB;AAAA,IAC1C;AAGE,WAAA,oBAAC,oBAAoB,UAApB,EAA6B,OAC5B,8BAAC,cAAa,EAAA,KAAW,GAAG,OAAA,CAAQ,EACtC,CAAA;AAAA,EAAA;AAGN;"}
|
|
@@ -7,9 +7,8 @@ import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
|
7
7
|
import { theme } from "@hitachivantara/uikit-styles";
|
|
8
8
|
import { useClasses } from "./BaseInput.styles.js";
|
|
9
9
|
import { staticClasses } from "./BaseInput.styles.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { HvFormElementDescriptorsContext } from "../Forms/FormElement/context/FormElementDescriptorsContext.js";
|
|
10
|
+
import { HvFormElementContext, HvFormElementDescriptorsContext } from "../FormElement/context.js";
|
|
11
|
+
import { buildFormElementPropsFromContext, buildAriaPropsFromContext } from "../FormElement/utils.js";
|
|
13
12
|
const baseInputStyles = css({
|
|
14
13
|
"input:-webkit-autofill": {
|
|
15
14
|
WebkitBoxShadow: `0 0 0px 1000px ${theme.colors.atmo1} inset`,
|
|
@@ -46,9 +45,9 @@ const HvBaseInput = forwardRef(function HvBaseInput2(props, ref) {
|
|
|
46
45
|
onChange,
|
|
47
46
|
type = "text",
|
|
48
47
|
placeholder,
|
|
49
|
-
multiline
|
|
50
|
-
resizable
|
|
51
|
-
invalid
|
|
48
|
+
multiline,
|
|
49
|
+
resizable,
|
|
50
|
+
invalid,
|
|
52
51
|
inputRef,
|
|
53
52
|
inputProps = {},
|
|
54
53
|
...others
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseInput.js","sources":["../../../src/BaseInput/BaseInput.tsx"],"sourcesContent":["import { forwardRef, useContext } from \"react\";\nimport { css as emotionCss, Global } from \"@emotion/react\";\nimport MuiInput, { InputProps as MuiInputProps } from \"@mui/material/Input\";\nimport {\n InputBaseProps,\n InputBaseComponentProps as MuiInputBaseComponentProps,\n} from \"@mui/material/InputBase\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nimport {\n buildAriaPropsFromContext,\n buildFormElementPropsFromContext,\n HvFormElementContext,\n HvFormElementDescriptorsContext,\n} from \"../
|
|
1
|
+
{"version":3,"file":"BaseInput.js","sources":["../../../src/BaseInput/BaseInput.tsx"],"sourcesContent":["import { forwardRef, useContext } from \"react\";\nimport { css as emotionCss, Global } from \"@emotion/react\";\nimport MuiInput, { InputProps as MuiInputProps } from \"@mui/material/Input\";\nimport {\n InputBaseProps,\n InputBaseComponentProps as MuiInputBaseComponentProps,\n} from \"@mui/material/InputBase\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nimport {\n buildAriaPropsFromContext,\n buildFormElementPropsFromContext,\n HvFormElementContext,\n HvFormElementDescriptorsContext,\n} from \"../FormElement\";\nimport { staticClasses, useClasses } from \"./BaseInput.styles\";\n\nexport { staticClasses as baseInputClasses };\n\nexport type HvBaseInputClasses = ExtractNames<typeof useClasses>;\n\n// Global styles for the base input.\nconst baseInputStyles = emotionCss({\n \"input:-webkit-autofill\": {\n WebkitBoxShadow: `0 0 0px 1000px ${theme.colors.atmo1} inset`,\n WebkitTextFillColor: theme.colors.secondary,\n },\n\n // Clears number input up/down arrows in Chrome and Firefox\n \"input::-webkit-outer-spin-button,input::-webkit-inner-spin-button\": {\n WebkitAppearance: \"none\",\n margin: 0,\n },\n \"input[type=number]\": {\n MozAppearance: \"textfield\",\n },\n\n // Clears time input clock in Chrome\n \"input::-webkit-calendar-picker-indicator\": {\n display: \"none\",\n },\n\n // Clears search input clear button in Chrome\n \"input::-webkit-search-decoration,input::-webkit-search-cancel-button,input::-webkit-search-results-button,input::-webkit-search-results-decoration\":\n {\n display: \"none\",\n },\n});\n\nexport interface HvBaseInputProps\n extends Omit<MuiInputProps, \"onChange\" | \"classes\" | \"ref\"> {\n /** The input name. */\n name?: string;\n /** The value of the input, when controlled. */\n value?: string;\n /** The initial value of the input, when uncontrolled. */\n defaultValue?: string;\n /** If `true` the input is disabled. */\n disabled?: boolean;\n /** Indicates that the input is not editable. */\n readOnly?: boolean;\n /** If true, the input element will be required. */\n required?: boolean;\n /** The function that will be executed onChange, allows modification of the input,\n * it receives the value. If a new value should be presented it must returned it. */\n onChange?: (\n event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,\n value: string,\n ) => void;\n /** The input type. */\n type?: string;\n /** Label inside the input used to help user. */\n placeholder?: string;\n /** If true, a textarea element will be rendered. */\n multiline?: boolean;\n /** If true and multiline is also true the textarea element will be resizable. */\n resizable?: boolean;\n /** Denotes if the input is in an invalid state. */\n invalid?: boolean;\n /** Attributes applied to the input element. */\n inputProps?: MuiInputBaseComponentProps;\n /** Allows passing a ref to the underlying input */\n inputRef?: InputBaseProps[\"inputRef\"];\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvBaseInputClasses;\n}\n\n/**\n * An Input component that only posses the most basic functionalities.\n * It should be used alongside the other form elements to construct a proper accessible form.\n */\nexport const HvBaseInput = forwardRef<\n // no-indent\n unknown,\n HvBaseInputProps\n>(function HvBaseInput(props, ref) {\n const {\n classes: classesProp,\n className = \"\",\n id,\n name,\n value,\n defaultValue,\n required,\n readOnly,\n disabled,\n onChange,\n type = \"text\",\n placeholder,\n multiline,\n resizable,\n invalid,\n inputRef,\n inputProps = {},\n ...others\n } = useDefaultProps(\"HvBaseInput\", props);\n const { classes, cx } = useClasses(classesProp);\n const formElementContext = useContext(HvFormElementContext);\n const formElementProps = buildFormElementPropsFromContext(\n name,\n disabled,\n readOnly,\n required,\n formElementContext,\n );\n\n const forkedRef = useForkRef(ref, inputRef);\n\n const localInvalid = invalid || formElementProps.status === \"invalid\";\n\n const formElementDescriptorsContext = useContext(\n HvFormElementDescriptorsContext,\n );\n const ariaProps = buildAriaPropsFromContext(\n inputProps,\n formElementDescriptorsContext,\n localInvalid,\n id,\n );\n\n const onChangeHandler: MuiInputProps[\"onChange\"] = (event) => {\n onChange?.(event, event.target.value);\n };\n\n return (\n <>\n <Global styles={baseInputStyles} />\n <div\n className={cx(classes.root, className, {\n [classes.disabled]: formElementProps.disabled,\n [classes.invalid]: localInvalid,\n [classes.resizable]: multiline && resizable,\n [classes.readOnly]: formElementProps.readOnly,\n })}\n >\n <MuiInput\n id={id}\n name={formElementProps.name}\n value={value}\n defaultValue={defaultValue}\n type={type}\n placeholder={placeholder}\n readOnly={!!formElementProps.readOnly}\n disabled={formElementProps.disabled}\n onChange={onChangeHandler}\n className={cx({\n [classes.inputRootInvalid]: localInvalid,\n [classes.inputRootReadOnly]: formElementProps.readOnly,\n })}\n classes={{\n root: classes.inputRoot,\n focused: classes.inputRootFocused,\n disabled: classes.inputRootDisabled,\n multiline: classes.inputRootMultiline,\n input: cx(classes.input, {\n [classes.inputResizable]: !formElementProps.disabled && resizable,\n [classes.inputDisabled]: formElementProps.disabled,\n [classes.inputReadOnly]: formElementProps.readOnly,\n }),\n }}\n inputProps={{\n // Avoid the required attribute at the root node\n required: formElementProps.required,\n ...inputProps,\n ...ariaProps,\n }}\n inputRef={forkedRef}\n multiline={multiline}\n rows={10}\n {...others}\n />\n {!multiline && (\n <div role=\"presentation\" className={classes.inputBorderContainer} />\n )}\n </div>\n </>\n );\n});\n"],"names":["emotionCss","HvBaseInput"],"mappings":";;;;;;;;;;;AA2BA,MAAM,kBAAkBA,IAAW;AAAA,EACjC,0BAA0B;AAAA,IACxB,iBAAiB,kBAAkB,MAAM,OAAO,KAAK;AAAA,IACrD,qBAAqB,MAAM,OAAO;AAAA,E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
1
|
+
import { validationStates } from "../FormElement/utils.js";
|
|
2
2
|
const isNumeric = (num) => (
|
|
3
3
|
// to prevent Number( <spaces> ) = 0
|
|
4
4
|
num.trim().length > 0 && !Number.isNaN(Number(num))
|
|
@@ -25,9 +25,9 @@ const computeValidationType = (type) => {
|
|
|
25
25
|
const hasBuiltInValidations = (required, validationType, minCharQuantity, maxCharQuantity, validation, inputProps) => required || validationType !== validationTypes.none || minCharQuantity != null || maxCharQuantity != null || validation != null || inputProps?.required != null || inputProps?.minLength != null || inputProps?.maxLength != null || inputProps?.min != null || inputProps?.max != null || inputProps?.type != null && inputProps?.type !== "text" && inputProps?.type !== "password" || inputProps?.pattern != null;
|
|
26
26
|
const computeValidationState = (inputValidity, isEmptyValue) => {
|
|
27
27
|
if (inputValidity.valid && isEmptyValue) {
|
|
28
|
-
return
|
|
28
|
+
return validationStates.standBy;
|
|
29
29
|
}
|
|
30
|
-
return inputValidity.valid ?
|
|
30
|
+
return inputValidity.valid ? validationStates.valid : validationStates.invalid;
|
|
31
31
|
};
|
|
32
32
|
const computeValidationMessage = (inputValidity, errorMessages) => {
|
|
33
33
|
if (inputValidity.valid) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validations.js","sources":["../../../src/BaseInput/validations.ts"],"sourcesContent":["import { InputBaseComponentProps } from \"@mui/material/InputBase\";\n\nimport validationStates from \"../
|
|
1
|
+
{"version":3,"file":"validations.js","sources":["../../../src/BaseInput/validations.ts"],"sourcesContent":["import { InputBaseComponentProps } from \"@mui/material/InputBase\";\n\nimport { validationStates } from \"../FormElement\";\n\n/** Checks if the value is a number. */\nconst isNumeric = (num: string) =>\n // to prevent Number( <spaces> ) = 0\n num.trim().length > 0 && !Number.isNaN(Number(num));\n\n/** Checks if the value is an email */\nconst isEmail = (email: string) => {\n const regexp =\n /^[^\\\\s]+[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?[.])+[a-z0-9](?:[a-z0-9-]*[a-z0-9])$/i;\n return regexp.test(email);\n};\n\nexport const validationTypes = Object.freeze({\n none: \"none\",\n number: \"number\",\n email: \"email\",\n});\n\n/** Returns the input's validation type based in the type of the input. */\nexport const computeValidationType = (type: React.HTMLInputTypeAttribute) => {\n switch (type) {\n case \"number\":\n return validationTypes.number;\n case \"email\":\n return validationTypes.email;\n\n default:\n return validationTypes.none;\n }\n};\n\n/**\n * Checks whether any integrated validation, native or not, is active.\n */\nexport const hasBuiltInValidations = (\n required: boolean | undefined,\n validationType: React.HTMLInputTypeAttribute,\n minCharQuantity: number | null | undefined,\n maxCharQuantity: number | null | undefined,\n validation?: (value: string) => boolean,\n inputProps?: InputBaseComponentProps,\n) =>\n required ||\n validationType !== validationTypes.none ||\n minCharQuantity != null ||\n maxCharQuantity != null ||\n validation != null ||\n inputProps?.required != null ||\n inputProps?.minLength != null ||\n inputProps?.maxLength != null ||\n inputProps?.min != null ||\n inputProps?.max != null ||\n (inputProps?.type != null &&\n inputProps?.type !== \"text\" &&\n inputProps?.type !== \"password\") ||\n inputProps?.pattern != null;\n\n/** Returns the form element's validation state based in the validity state of the input. */\nexport const computeValidationState = (\n inputValidity: HvInputValidity,\n isEmptyValue: boolean,\n) => {\n // to keep 2.x behaviour,\n // consider that if the value is empty (and not required) we're returning to the standBy state.\n // might not make sense, as it makes impossible to say if the user explicitly cleared the input.\n if (inputValidity.valid && isEmptyValue) {\n return validationStates.standBy;\n }\n\n return inputValidity.valid\n ? validationStates.valid\n : validationStates.invalid;\n};\n\n/**\n * Returns a error message based in the validity state of the input.\n *\n * Only one error message is returned even if multiple validations fail.\n * Also, only required, minCharQuantity, maxCharQuantity and validationType have specific error messages.\n *\n * For further customization both status and statusMessage should be controlled and\n * set using the onBlur callback that receives both the value and the input validity object.\n */\nexport const computeValidationMessage = (\n inputValidity: HvInputValidity,\n /** The available localized error messages. */\n errorMessages: Record<string, string>,\n) => {\n if (inputValidity.valid) {\n return \"\";\n }\n\n if (inputValidity.valueMissing) {\n return errorMessages.requiredError;\n }\n if (inputValidity.tooLong) {\n return errorMessages.maxCharError;\n }\n if (inputValidity.tooShort) {\n return errorMessages.minCharError;\n }\n if (inputValidity.typeMismatch) {\n return errorMessages.typeMismatchError;\n }\n\n return errorMessages.error;\n};\n\n/**\n * Returns a object describing the validity state of the input.\n *\n * It implements the native browser's ValidityState interface:\n * https://developer.mozilla.org/en-US/docs/Web/API/ValidityState\n */\nexport const validateInput = (\n input: HTMLInputElement | HTMLTextAreaElement | null,\n value: string,\n required: boolean | undefined,\n minCharQuantity: any,\n maxCharQuantity: any,\n validationType: string,\n validation?: (value: string) => boolean,\n): HvInputValidity => {\n // bootstrap validity object using browser's built-in validation\n const inputValidity: HvInputValidity = {\n valid: input?.validity?.valid ?? true,\n badInput: input?.validity?.badInput,\n customError: input?.validity?.customError,\n patternMismatch: input?.validity?.patternMismatch,\n rangeOverflow: input?.validity?.rangeOverflow,\n rangeUnderflow: input?.validity?.rangeUnderflow,\n stepMismatch: input?.validity?.stepMismatch,\n tooLong: input?.validity?.tooLong,\n tooShort: input?.validity?.tooShort,\n typeMismatch: input?.validity?.typeMismatch,\n valueMissing: input?.validity?.valueMissing,\n };\n\n if (!value) {\n if (required) {\n // this is redundant because we're setting the required property in the native input\n inputValidity.valueMissing = true;\n inputValidity.valid = false;\n }\n } else {\n // we're not setting minlength and maxlength in the native input\n // to avoid different browser's behaviours and keep the user experience consistent\n if (minCharQuantity !== null && value.length < minCharQuantity) {\n inputValidity.tooShort = true;\n inputValidity.valid = false;\n }\n\n if (maxCharQuantity !== null && value.length > maxCharQuantity) {\n inputValidity.tooLong = true;\n inputValidity.valid = false;\n }\n\n // the validationType is used instead of type\n // for the same reason stated above\n switch (validationType) {\n case validationTypes.number:\n if (!isNumeric(value)) {\n inputValidity.typeMismatch = true;\n inputValidity.valid = false;\n }\n break;\n\n case validationTypes.email:\n if (!isEmail(value)) {\n inputValidity.typeMismatch = true;\n inputValidity.valid = false;\n }\n break;\n\n default:\n }\n\n if (validation != null && !validation(value)) {\n inputValidity.customError = true;\n inputValidity.valid = false;\n }\n }\n\n return inputValidity;\n};\n\ntype Mutable<T> = { -readonly [P in keyof T]: T[P] };\n\nexport interface HvInputValidity extends Partial<Mutable<ValidityState>> {}\n\nexport const DEFAULT_ERROR_MESSAGES = {\n error: \"Invalid value\",\n requiredError: \"The value is required\",\n minCharError: \"The value is too short\",\n maxCharError: \"The value is too long\",\n typeMismatchError: \"Invalid value\",\n};\n"],"names":[],"mappings":";AAKA,MAAM,YAAY,CAAC;AAAA;AAAA,EAEjB,IAAI,KAAK,EAAE,SAAS,KAAK,CAAC,OAAO,MAAM,OAAO,GAAG,CAAC;AAAA;AAGpD,MAAM,UAAU,CAAC,UAAkB;AACjC,QAAM,SACJ;AACK,SAAA,OAAO,KAAK,KAAK;AAC1B;AAEa,MAAA,kBAAkB,OAAO,OAAO;AAAA,EAC3C,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AACT,CAAC;AAGY,MAAA,wBAAwB,CAAC,SAAuC;AAC3E,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO,gBAAgB;AAAA,IACzB,KAAK;AACH,aAAO,gBAAgB;AAAA,IAEzB;AACE,aAAO,gBAAgB;AAAA,EAAA;AAE7B;AAKO,MAAM,wBAAwB,CACnC,UACA,gBACA,iBACA,iBACA,YACA,eAEA,YACA,mBAAmB,gBAAgB,QACnC,mBAAmB,QACnB,mBAAmB,QACnB,cAAc,QACd,YAAY,YAAY,QACxB,YAAY,aAAa,QACzB,YAAY,aAAa,QACzB,YAAY,OAAO,QACnB,YAAY,OAAO,QAClB,YAAY,QAAQ,QACnB,YAAY,SAAS,UACrB,YAAY,SAAS,cACvB,YAAY,WAAW;AAGZ,MAAA,yBAAyB,CACpC,eACA,iBACG;AAIC,MAAA,cAAc,SAAS,cAAc;AACvC,WAAO,iBAAiB;AAAA,EAAA;AAG1B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ACrB,wBAAc,eAAe;AAC7B,wBAAc,QAAQ;AAAA,QAAA;AAExB;AAAA,MAEF,KAAK,gBAAgB;AACf,YAAA,CAAC,QAAQ,KAAK,GAAG;AACnB,wBAAc,eAAe;AAC7B,wBAAc,QAAQ;AAAA,QAAA;AAExB;AAAA,IAEF;AAGF,QAAI,cAAc,QAAQ,CAAC,WAAW,KAAK,GAAG;AAC5C,oBAAc,cAAc;AAC5B,oBAAc,QAAQ;AAAA,IAAA;AAAA,EACxB;AAGK,SAAA;AACT;AAMO,MAAM,yBAAyB;AAAA,EACpC,OAAO;AAAA,EACP,eAAe;AAAA,EACf,cAAc;AAAA,EACd,cAAc;AAAA,EACd,mBAAmB;AACrB;"}
|
|
@@ -6,14 +6,13 @@ import { useClasses } from "./Calendar.styles.js";
|
|
|
6
6
|
import { staticClasses } from "./Calendar.styles.js";
|
|
7
7
|
import { isRange } from "./utils.js";
|
|
8
8
|
import { HvSingleCalendar } from "./SingleCalendar/SingleCalendar.js";
|
|
9
|
-
import { HvFormElementContext } from "../
|
|
10
|
-
import { HvFormElementValueContext } from "../Forms/FormElement/context/FormElementValueContext.js";
|
|
9
|
+
import { HvFormElementContext, HvFormElementValueContext } from "../FormElement/context.js";
|
|
11
10
|
const HvCalendar = (props) => {
|
|
12
11
|
const {
|
|
13
12
|
classes: classesProp,
|
|
14
|
-
id,
|
|
13
|
+
id: idProp,
|
|
15
14
|
locale = "en-US",
|
|
16
|
-
value,
|
|
15
|
+
value: valueProp,
|
|
17
16
|
visibleMonth,
|
|
18
17
|
visibleYear,
|
|
19
18
|
rightVisibleMonth,
|
|
@@ -28,19 +27,19 @@ const HvCalendar = (props) => {
|
|
|
28
27
|
...others
|
|
29
28
|
} = useDefaultProps("HvCalendar", props);
|
|
30
29
|
const { classes } = useClasses(classesProp);
|
|
31
|
-
const
|
|
30
|
+
const context = useContext(HvFormElementContext);
|
|
32
31
|
const elementValue = useContext(HvFormElementValueContext);
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const rangeMode = isRange(
|
|
36
|
-
const rightCalendarId = setId(
|
|
32
|
+
const value = valueProp ?? elementValue;
|
|
33
|
+
const id = idProp ?? setId(context.id, "single-calendar");
|
|
34
|
+
const rangeMode = isRange(value);
|
|
35
|
+
const rightCalendarId = setId(id, "single-calendar-right");
|
|
37
36
|
const clampedMonth = visibleMonth && visibleMonth % 13 > 0 ? visibleMonth % 13 : 1;
|
|
38
37
|
const singleCalendar = /* @__PURE__ */ jsx(
|
|
39
38
|
HvSingleCalendar,
|
|
40
39
|
{
|
|
41
|
-
id
|
|
40
|
+
id,
|
|
42
41
|
locale,
|
|
43
|
-
value
|
|
42
|
+
value,
|
|
44
43
|
visibleMonth: clampedMonth,
|
|
45
44
|
visibleYear,
|
|
46
45
|
minimumDate,
|
|
@@ -59,9 +58,9 @@ const HvCalendar = (props) => {
|
|
|
59
58
|
HvSingleCalendar,
|
|
60
59
|
{
|
|
61
60
|
className: classes.singleCalendar,
|
|
62
|
-
id
|
|
61
|
+
id,
|
|
63
62
|
locale,
|
|
64
|
-
value
|
|
63
|
+
value,
|
|
65
64
|
visibleMonth: clampedMonth,
|
|
66
65
|
visibleYear,
|
|
67
66
|
minimumDate,
|
|
@@ -81,7 +80,7 @@ const HvCalendar = (props) => {
|
|
|
81
80
|
className: classes.singleCalendar,
|
|
82
81
|
id: rightCalendarId,
|
|
83
82
|
locale,
|
|
84
|
-
value
|
|
83
|
+
value,
|
|
85
84
|
visibleMonth: rightVisibleMonth,
|
|
86
85
|
visibleYear: rightVisibleYear,
|
|
87
86
|
minimumDate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Calendar.js","sources":["../../../src/Calendar/Calendar.tsx"],"sourcesContent":["import { useContext } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"Calendar.js","sources":["../../../src/Calendar/Calendar.tsx"],"sourcesContent":["import { useContext } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport {\n HvFormElementContext,\n HvFormElementValueContext,\n} from \"../FormElement\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./Calendar.styles\";\nimport { HvSingleCalendar } from \"./SingleCalendar\";\nimport { DateRangeProp, VisibilitySelectorActions } from \"./types\";\nimport { isRange } from \"./utils\";\n\nexport { staticClasses as calendarClasses };\n\nexport type HvCalendarClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvCalendarProps {\n /**\n * Styles applied from the theme.\n */\n classes?: HvCalendarClasses;\n /**\n * Identifier.\n */\n id?: string;\n /**\n * The calendar locale. If undefined, it defaults to en-US\n *\n */\n locale?: string;\n /**\n * Date that the calendar would show.\n * if using the object format the calendar enter in range mode showing two calendars\n */\n value?: DateRangeProp | Date;\n /**\n * Controls the visible month of the Calendar\n */\n visibleMonth?: number;\n /**\n * Controls the visible year of the Calendar\n */\n visibleYear?: number;\n /**\n * Controls the visible month of the Calendar on the right side of the datepicker\n */\n rightVisibleMonth?: number;\n /**\n * Controls the visible year of the Calendar on the right side of the datepicker\n */\n rightVisibleYear?: number;\n /**\n * Callback function to be triggered when the selected date has changed.\n */\n onChange?: (\n event:\n | React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>\n | undefined,\n value: Date | DateRangeProp,\n ) => void;\n /**\n * Callback function to be triggered when the selected date input has changed.\n */\n onInputChange?: (\n event:\n | React.ChangeEvent<\n HTMLTextAreaElement | HTMLInputElement | HTMLButtonElement\n >\n | undefined,\n value: Date | DateRangeProp,\n position: \"left\" | \"right\",\n ) => void;\n /**\n * Callback function to be triggered when the user clicks on the month or year selector.\n * it receives the action that was pressed:\n * previous_month, next_month, previous_year, next_year,month\n */\n onVisibleDateChange?: (\n event:\n | React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>\n | undefined,\n action: VisibilitySelectorActions,\n value?: Date | DateRangeProp | number,\n position?: \"left\" | \"right\",\n ) => void;\n /**\n * The maximum selectable date after this all values are disabled.\n */\n maximumDate?: Date;\n /**\n * The minimum selectable date before this all values are disabled.\n */\n minimumDate?: Date;\n /**\n * An element placed before the Calendar\n */\n startAdornment?: React.ReactNode;\n /**\n * Indicates if header should display the day of week.\n */\n showDayOfWeek?: boolean;\n /**\n * Label shown when date is invalid.\n */\n invalidDateLabel?: string;\n}\n\nexport const HvCalendar = (props: HvCalendarProps) => {\n const {\n classes: classesProp,\n id: idProp,\n locale = \"en-US\",\n value: valueProp,\n visibleMonth,\n visibleYear,\n rightVisibleMonth,\n rightVisibleYear,\n minimumDate,\n maximumDate,\n startAdornment,\n onChange,\n onInputChange,\n onVisibleDateChange,\n invalidDateLabel,\n ...others\n } = useDefaultProps(\"HvCalendar\", props);\n const { classes } = useClasses(classesProp);\n\n const context = useContext(HvFormElementContext);\n const elementValue = useContext(HvFormElementValueContext);\n const value = valueProp ?? elementValue;\n const id = idProp ?? setId(context.id, \"single-calendar\");\n const rangeMode = isRange(value);\n const rightCalendarId = setId(id, \"single-calendar-right\");\n const clampedMonth =\n visibleMonth && visibleMonth % 13 > 0 ? visibleMonth % 13 : 1;\n\n const singleCalendar = (\n <HvSingleCalendar\n id={id}\n locale={locale}\n value={value}\n visibleMonth={clampedMonth}\n visibleYear={visibleYear}\n minimumDate={minimumDate}\n maximumDate={maximumDate}\n onChange={onChange}\n onInputChange={(evt, date) => {\n onInputChange?.(evt, date, \"left\");\n }}\n onVisibleDateChange={onVisibleDateChange}\n invalidDateLabel={invalidDateLabel}\n {...others}\n />\n );\n\n const rangeCalendar = (\n <div className={classes.rangeCalendarContainer}>\n <HvSingleCalendar\n className={classes.singleCalendar}\n id={id}\n locale={locale}\n value={value}\n visibleMonth={clampedMonth}\n visibleYear={visibleYear}\n minimumDate={minimumDate}\n maximumDate={maximumDate}\n onChange={onChange}\n onInputChange={(evt, date) => {\n onInputChange?.(evt, date, \"left\");\n }}\n onVisibleDateChange={(event, action, index) =>\n onVisibleDateChange?.(event, action, index, \"left\")\n }\n invalidDateLabel={invalidDateLabel}\n {...others}\n />\n\n <HvSingleCalendar\n className={classes.singleCalendar}\n id={rightCalendarId}\n locale={locale}\n value={value}\n visibleMonth={rightVisibleMonth}\n visibleYear={rightVisibleYear}\n minimumDate={minimumDate}\n maximumDate={maximumDate}\n onChange={onChange}\n onInputChange={(evt, date) => {\n onInputChange?.(evt, date, \"right\");\n }}\n onVisibleDateChange={(event, action, index) => {\n onVisibleDateChange?.(event, action, index, \"right\");\n }}\n showEndDate\n invalidDateLabel={invalidDateLabel}\n {...others}\n />\n </div>\n );\n\n return (\n <div className={classes.root}>\n {startAdornment}\n {rangeMode ? rangeCalendar : singleCalendar}\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;AA+Ga,MAAA,aAAa,CAAC,UAA2B;AAC9C,QAAA;AAAA,IACJ,SAAS;AAAA,IACT,IAAI;AAAA,IACJ,SAAS;AAAA,IACT,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD,gBAAgB,cAAc,KAAK;AACvC,QAAM,EAAE,QAAA,IAAY,WAAW,WAAW;AAEpC,QAAA,UAAU,WAAW,oBAAoB;AACzC,QAAA,eAAe,WAAW,yBAAyB;AACzD,QAAM,QAAQ,aAAa;AAC3B,QAAM,KAAK,UAAU,MAAM,QAAQ,IAAI,iBAAiB;AAClD,QAAA,YAAY,QAAQ,KAAK;AACzB,QAAA,kBAAkB,MAAM,IAAI,uBAAuB;AACzD,QAAM,eACJ,gBAAgB,eAAe,KAAK,IAAI,eAAe,KAAK;AAE9D,QAAM,iBACJ;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,eAAe,CAAC,KAAK,SAAS;AACZ,wBAAA,KAAK,MAAM,MAAM;AAAA,MACnC;AAAA,MACA;AAAA,MACA;AAAA,MACC,GAAG;AAAA,IAAA;AAAA,EACN;AAGF,QAAM,gBACJ,qBAAC,OAAI,EAAA,WAAW,QAAQ,wBACtB,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAW,QAAQ;AAAA,QACnB;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAc;AAAA,QACd;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,eAAe,CAAC,KAAK,SAAS;AACZ,0BAAA,KAAK,MAAM,MAAM;AAAA,QACnC;AAAA,QACA,qBAAqB,CAAC,OAAO,QAAQ,UACnC,sBAAsB,OAAO,QAAQ,OAAO,MAAM;AAAA,QAEpD;AAAA,QACC,GAAG;AAAA,MAAA;AAAA,IACN;AAAA,IAEA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAW,QAAQ;AAAA,QACnB,IAAI;AAAA,QACJ;AAAA,QACA;AAAA,QACA,cAAc;AAAA,QACd,aAAa;AAAA,QACb;AAAA,QACA;AAAA,QACA;AAAA,QACA,eAAe,CAAC,KAAK,SAAS;AACZ,0BAAA,KAAK,MAAM,OAAO;AAAA,QACpC;AAAA,QACA,qBAAqB,CAAC,OAAO,QAAQ,UAAU;AACvB,gCAAA,OAAO,QAAQ,OAAO,OAAO;AAAA,QACrD;AAAA,QACA,aAAW;AAAA,QACX;AAAA,QACC,GAAG;AAAA,MAAA;AAAA,IAAA;AAAA,EACN,GACF;AAGF,SACG,qBAAA,OAAA,EAAI,WAAW,QAAQ,MACrB,UAAA;AAAA,IAAA;AAAA,IACA,YAAY,gBAAgB;AAAA,EAAA,GAC/B;AAEJ;"}
|
|
@@ -10,17 +10,15 @@ import { setId } from "../../utils/setId.js";
|
|
|
10
10
|
import { isRange, isDate, formatToLocale, isSameDay } from "../utils.js";
|
|
11
11
|
import { useClasses } from "./CalendarHeader.styles.js";
|
|
12
12
|
import { staticClasses } from "./CalendarHeader.styles.js";
|
|
13
|
-
import { HvFormElementValueContext } from "../../
|
|
13
|
+
import { HvFormElementContext, HvFormElementValueContext, HvFormElementDescriptorsContext } from "../../FormElement/context.js";
|
|
14
14
|
import { HvInput } from "../../Input/Input.js";
|
|
15
|
-
import { HvFormElementContext } from "../../Forms/FormElement/context/FormElementContext.js";
|
|
16
|
-
import { HvFormElementDescriptorsContext } from "../../Forms/FormElement/context/FormElementDescriptorsContext.js";
|
|
17
15
|
import { HvTypography } from "../../Typography/Typography.js";
|
|
18
16
|
dayjs.extend(localeData);
|
|
19
17
|
dayjs.extend(localizedFormat);
|
|
20
18
|
dayjs.extend(customParseFormat);
|
|
21
19
|
const HvCalendarHeader = (props) => {
|
|
22
20
|
const {
|
|
23
|
-
id,
|
|
21
|
+
id: idProp,
|
|
24
22
|
value,
|
|
25
23
|
locale = "en-US",
|
|
26
24
|
classes: classesProp,
|
|
@@ -31,7 +29,7 @@ const HvCalendarHeader = (props) => {
|
|
|
31
29
|
invalidDateLabel = "Invalid Date"
|
|
32
30
|
} = useDefaultProps("HvCalendarHeader", props);
|
|
33
31
|
const { classes, cx } = useClasses(classesProp);
|
|
34
|
-
const
|
|
32
|
+
const context = useContext(HvFormElementContext);
|
|
35
33
|
const elementValue = useContext(HvFormElementValueContext);
|
|
36
34
|
const { label } = useContext(HvFormElementDescriptorsContext);
|
|
37
35
|
let localValue = value ?? elementValue ?? "";
|
|
@@ -42,7 +40,7 @@ const HvCalendarHeader = (props) => {
|
|
|
42
40
|
const [editedValue, setEditedValue] = useState(null);
|
|
43
41
|
const [displayValue, setDisplayValue] = useState("");
|
|
44
42
|
const [weekdayDisplay, setWeekdayDisplay] = useState("");
|
|
45
|
-
const
|
|
43
|
+
const id = idProp ?? setId(context.id, "calendarHeader");
|
|
46
44
|
const inputValue = editedValue ?? displayValue;
|
|
47
45
|
const localeFormat = dayjs().locale(locale).localeData().longDateFormat("L");
|
|
48
46
|
const [isValidValue, setIsValidValue] = useState(
|
|
@@ -108,7 +106,7 @@ const HvCalendarHeader = (props) => {
|
|
|
108
106
|
return /* @__PURE__ */ jsxs(
|
|
109
107
|
"div",
|
|
110
108
|
{
|
|
111
|
-
id
|
|
109
|
+
id,
|
|
112
110
|
className: cx(classes.root, {
|
|
113
111
|
[classes.invalid]: isInvalid
|
|
114
112
|
}),
|
|
@@ -118,7 +116,7 @@ const HvCalendarHeader = (props) => {
|
|
|
118
116
|
HvInput,
|
|
119
117
|
{
|
|
120
118
|
type: "text",
|
|
121
|
-
id: setId(
|
|
119
|
+
id: setId(id, "header-input"),
|
|
122
120
|
className: classes.headerDate,
|
|
123
121
|
classes: {
|
|
124
122
|
input: classes.input,
|