@hitachivantara/uikit-react-core 5.82.3 → 5.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseDropdown/BaseDropdown.cjs +1 -1
- package/dist/cjs/BaseInput/BaseInput.cjs +4 -7
- package/dist/cjs/ButtonBase/ButtonBase.styles.cjs +6 -5
- package/dist/cjs/Calendar/Calendar.cjs +2 -2
- package/dist/cjs/Calendar/CalendarHeader/CalendarHeader.cjs +12 -28
- package/dist/cjs/Calendar/SingleCalendar/SingleCalendar.cjs +2 -1
- package/dist/cjs/Calendar/utils.cjs +53 -21
- package/dist/cjs/Card/Card.cjs +1 -1
- package/dist/cjs/ColorPicker/ColorPicker.cjs +11 -9
- package/dist/cjs/ColorPicker/ColorPicker.styles.cjs +14 -7
- package/dist/cjs/ColorPicker/Fields/Fields.cjs +10 -7
- 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 +1 -2
- package/dist/cjs/DatePicker/utils.cjs +2 -2
- package/dist/cjs/DropDownMenu/DropDownMenu.cjs +1 -1
- package/dist/cjs/FormElement/Adornment/Adornment.cjs +1 -1
- package/dist/cjs/FormElement/Suggestions/Suggestions.cjs +1 -1
- package/dist/cjs/Grid/Grid.cjs +1 -1
- package/dist/cjs/Input/Input.cjs +9 -8
- package/dist/cjs/ListContainer/ListContext/ListContext.cjs +1 -3
- package/dist/cjs/Select/Option.cjs +1 -2
- package/dist/cjs/Select/Select.cjs +7 -4
- package/dist/cjs/Slider/Slider.cjs +2 -2
- package/dist/cjs/Snackbar/SnackbarContent/SnackbarContent.cjs +1 -1
- package/dist/cjs/SnackbarProvider/SnackbarProvider.cjs +1 -1
- 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/Table/TableRow/TableRow.styles.cjs +20 -5
- package/dist/cjs/Table/hooks/{useBulkActions.cjs → useHvBulkActions.cjs} +6 -7
- package/dist/cjs/Table/hooks/{useFilters.cjs → useHvFilters.cjs} +2 -2
- package/dist/cjs/Table/hooks/{useGlobalFilter.cjs → useHvGlobalFilter.cjs} +2 -2
- package/dist/cjs/Table/hooks/{useHeaderGroups.cjs → useHvHeaderGroups.cjs} +4 -4
- package/dist/cjs/Table/hooks/{usePagination.cjs → useHvPagination.cjs} +4 -4
- package/dist/cjs/Table/hooks/{useResizeColumns.cjs → useHvResizeColumns.cjs} +4 -4
- package/dist/cjs/Table/hooks/{useRowExpand.cjs → useHvRowExpand.cjs} +6 -5
- package/dist/cjs/Table/hooks/{useRowSelection.cjs → useHvRowSelection.cjs} +4 -8
- package/dist/cjs/Table/hooks/{useRowState.cjs → useHvRowState.cjs} +2 -2
- package/dist/cjs/Table/hooks/{useSortBy.cjs → useHvSortBy.cjs} +4 -4
- package/dist/cjs/Table/hooks/{useSticky.cjs → useHvSticky.cjs} +4 -6
- package/dist/cjs/Table/hooks/{useTable.cjs → useHvTable.cjs} +6 -4
- package/dist/cjs/Table/hooks/{useTableStyles.cjs → useHvTableStyles.cjs} +4 -5
- package/dist/cjs/Table/renderers/{DateColumnCell/DateColumnCell.cjs → DateColumnCell.cjs} +1 -1
- package/dist/cjs/Table/renderers/DefaultCell.cjs +21 -0
- package/dist/cjs/Table/renderers/{DropdownColumnCell/DropdownColumnCell.cjs → DropdownColumnCell.cjs} +1 -1
- package/dist/cjs/Table/renderers/{ProgressColumnCell/ProgressColumnCell.cjs → ProgressColumnCell.cjs} +20 -2
- package/dist/cjs/Table/renderers/{SwitchColumnCell/SwitchColumnCell.cjs → SwitchColumnCell.cjs} +13 -4
- package/dist/cjs/Table/renderers/renderers.cjs +21 -8
- package/dist/cjs/TableSection/TableSection.styles.cjs +6 -2
- package/dist/cjs/Tag/Tag.cjs +67 -49
- package/dist/cjs/Tag/Tag.styles.cjs +50 -64
- package/dist/cjs/TagsInput/TagsInput.cjs +1 -4
- package/dist/cjs/TagsInput/TagsInput.styles.cjs +1 -4
- package/dist/cjs/TextArea/TextArea.cjs +4 -4
- package/dist/cjs/TimeAgo/TimeAgo.cjs +2 -1
- package/dist/cjs/TimePicker/TimePicker.cjs +2 -1
- 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 +40 -50
- package/dist/cjs/utils/keyboardUtils.cjs +4 -0
- package/dist/esm/BaseDropdown/BaseDropdown.js +1 -1
- package/dist/esm/BaseDropdown/BaseDropdown.js.map +1 -1
- package/dist/esm/BaseInput/BaseInput.js +3 -6
- package/dist/esm/BaseInput/BaseInput.js.map +1 -1
- package/dist/esm/ButtonBase/ButtonBase.styles.js +6 -5
- package/dist/esm/ButtonBase/ButtonBase.styles.js.map +1 -1
- package/dist/esm/Calendar/Calendar.js +3 -3
- package/dist/esm/Calendar/Calendar.js.map +1 -1
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.js +13 -24
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.js.map +1 -1
- package/dist/esm/Calendar/SingleCalendar/SingleCalendar.js +3 -2
- package/dist/esm/Calendar/SingleCalendar/SingleCalendar.js.map +1 -1
- package/dist/esm/Calendar/utils.js +54 -20
- package/dist/esm/Calendar/utils.js.map +1 -1
- package/dist/esm/Card/Card.js +1 -1
- package/dist/esm/Card/Card.js.map +1 -1
- package/dist/esm/ColorPicker/ColorPicker.js +12 -10
- package/dist/esm/ColorPicker/ColorPicker.js.map +1 -1
- package/dist/esm/ColorPicker/ColorPicker.styles.js +14 -7
- package/dist/esm/ColorPicker/ColorPicker.styles.js.map +1 -1
- package/dist/esm/ColorPicker/Fields/Fields.js +10 -7
- 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/Controls.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 +2 -3
- package/dist/esm/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/DatePicker/utils.js +2 -2
- package/dist/esm/DatePicker/utils.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/EmptyState/EmptyState.js.map +1 -1
- package/dist/esm/FormElement/Adornment/Adornment.js +1 -1
- package/dist/esm/FormElement/Adornment/Adornment.js.map +1 -1
- package/dist/esm/FormElement/Suggestions/Suggestions.js +1 -1
- package/dist/esm/FormElement/Suggestions/Suggestions.js.map +1 -1
- 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 +10 -9
- package/dist/esm/Input/Input.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/Select/Option.js +1 -2
- package/dist/esm/Select/Option.js.map +1 -1
- package/dist/esm/Select/Select.js +7 -2
- package/dist/esm/Select/Select.js.map +1 -1
- package/dist/esm/Slider/Slider.js +2 -2
- package/dist/esm/Slider/Slider.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/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/Table/TableRow/TableRow.styles.js +16 -1
- package/dist/esm/Table/TableRow/TableRow.styles.js.map +1 -1
- package/dist/esm/Table/hooks/{useBulkActions.js → useHvBulkActions.js} +5 -6
- package/dist/esm/Table/hooks/useHvBulkActions.js.map +1 -0
- package/dist/esm/Table/hooks/{useFilters.js → useHvFilters.js} +1 -1
- package/dist/esm/Table/hooks/useHvFilters.js.map +1 -0
- package/dist/esm/Table/hooks/{useGlobalFilter.js → useHvGlobalFilter.js} +1 -1
- package/dist/esm/Table/hooks/useHvGlobalFilter.js.map +1 -0
- package/dist/esm/Table/hooks/{useHeaderGroups.js → useHvHeaderGroups.js} +3 -3
- package/dist/esm/Table/hooks/useHvHeaderGroups.js.map +1 -0
- package/dist/esm/Table/hooks/{usePagination.js → useHvPagination.js} +4 -4
- package/dist/esm/Table/hooks/useHvPagination.js.map +1 -0
- package/dist/esm/Table/hooks/{useResizeColumns.js → useHvResizeColumns.js} +3 -3
- package/dist/esm/Table/hooks/useHvResizeColumns.js.map +1 -0
- package/dist/esm/Table/hooks/{useRowExpand.js → useHvRowExpand.js} +5 -4
- package/dist/esm/Table/hooks/useHvRowExpand.js.map +1 -0
- package/dist/esm/Table/hooks/{useRowSelection.js → useHvRowSelection.js} +3 -7
- package/dist/esm/Table/hooks/useHvRowSelection.js.map +1 -0
- package/dist/esm/Table/hooks/{useRowState.js → useHvRowState.js} +1 -1
- package/dist/esm/Table/hooks/useHvRowState.js.map +1 -0
- package/dist/esm/Table/hooks/{useSortBy.js → useHvSortBy.js} +3 -3
- package/dist/esm/Table/hooks/useHvSortBy.js.map +1 -0
- package/dist/esm/Table/hooks/{useSticky.js → useHvSticky.js} +3 -5
- package/dist/esm/Table/hooks/useHvSticky.js.map +1 -0
- package/dist/esm/Table/hooks/{useTable.js → useHvTable.js} +5 -3
- package/dist/esm/Table/hooks/useHvTable.js.map +1 -0
- package/dist/esm/Table/hooks/{useTableStyles.js → useHvTableStyles.js} +3 -4
- package/dist/esm/Table/hooks/useHvTableStyles.js.map +1 -0
- package/dist/esm/Table/renderers/{DateColumnCell/DateColumnCell.js → DateColumnCell.js} +1 -1
- package/dist/esm/Table/renderers/DateColumnCell.js.map +1 -0
- package/dist/esm/Table/renderers/DefaultCell.js +21 -0
- package/dist/esm/Table/renderers/DefaultCell.js.map +1 -0
- package/dist/esm/Table/renderers/{DropdownColumnCell/DropdownColumnCell.js → DropdownColumnCell.js} +1 -1
- package/dist/esm/Table/renderers/DropdownColumnCell.js.map +1 -0
- package/dist/esm/Table/renderers/{ProgressColumnCell/ProgressColumnCell.js → ProgressColumnCell.js} +19 -1
- package/dist/esm/Table/renderers/ProgressColumnCell.js.map +1 -0
- package/dist/esm/Table/renderers/{SwitchColumnCell/SwitchColumnCell.js → SwitchColumnCell.js} +12 -3
- package/dist/esm/Table/renderers/SwitchColumnCell.js.map +1 -0
- package/dist/esm/Table/renderers/renderers.js +18 -5
- package/dist/esm/Table/renderers/renderers.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/Tag/Tag.js +71 -51
- package/dist/esm/Tag/Tag.js.map +1 -1
- package/dist/esm/Tag/Tag.styles.js +50 -64
- package/dist/esm/Tag/Tag.styles.js.map +1 -1
- package/dist/esm/TagsInput/TagsInput.js +1 -4
- package/dist/esm/TagsInput/TagsInput.js.map +1 -1
- package/dist/esm/TagsInput/TagsInput.styles.js +1 -4
- package/dist/esm/TagsInput/TagsInput.styles.js.map +1 -1
- package/dist/esm/TextArea/TextArea.js +4 -4
- package/dist/esm/TextArea/TextArea.js.map +1 -1
- package/dist/esm/TimeAgo/TimeAgo.js +2 -1
- package/dist/esm/TimeAgo/TimeAgo.js.map +1 -1
- package/dist/esm/TimePicker/TimePicker.js +2 -1
- 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 +34 -44
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/deepMerge.js.map +1 -1
- package/dist/esm/utils/keyboardUtils.js +4 -0
- package/dist/esm/utils/keyboardUtils.js.map +1 -1
- package/dist/types/index.d.ts +397 -425
- package/package.json +6 -6
- package/dist/cjs/Table/renderers/ProgressColumnCell/ProgressColumnCell.styles.cjs +0 -26
- package/dist/cjs/Table/renderers/SwitchColumnCell/SwitchColumnCell.styles.cjs +0 -21
- package/dist/cjs/Table/utils/fallbacks.cjs +0 -16
- package/dist/cjs/Table/utils/utils.cjs +0 -19
- package/dist/esm/Table/hooks/useBulkActions.js.map +0 -1
- package/dist/esm/Table/hooks/useFilters.js.map +0 -1
- package/dist/esm/Table/hooks/useGlobalFilter.js.map +0 -1
- package/dist/esm/Table/hooks/useHeaderGroups.js.map +0 -1
- package/dist/esm/Table/hooks/usePagination.js.map +0 -1
- package/dist/esm/Table/hooks/useResizeColumns.js.map +0 -1
- package/dist/esm/Table/hooks/useRowExpand.js.map +0 -1
- package/dist/esm/Table/hooks/useRowSelection.js.map +0 -1
- package/dist/esm/Table/hooks/useRowState.js.map +0 -1
- package/dist/esm/Table/hooks/useSortBy.js.map +0 -1
- package/dist/esm/Table/hooks/useSticky.js.map +0 -1
- package/dist/esm/Table/hooks/useTable.js.map +0 -1
- package/dist/esm/Table/hooks/useTableStyles.js.map +0 -1
- package/dist/esm/Table/renderers/DateColumnCell/DateColumnCell.js.map +0 -1
- package/dist/esm/Table/renderers/DropdownColumnCell/DropdownColumnCell.js.map +0 -1
- package/dist/esm/Table/renderers/ProgressColumnCell/ProgressColumnCell.js.map +0 -1
- package/dist/esm/Table/renderers/ProgressColumnCell/ProgressColumnCell.styles.js +0 -26
- package/dist/esm/Table/renderers/ProgressColumnCell/ProgressColumnCell.styles.js.map +0 -1
- package/dist/esm/Table/renderers/SwitchColumnCell/SwitchColumnCell.js.map +0 -1
- package/dist/esm/Table/renderers/SwitchColumnCell/SwitchColumnCell.styles.js +0 -21
- package/dist/esm/Table/renderers/SwitchColumnCell/SwitchColumnCell.styles.js.map +0 -1
- package/dist/esm/Table/utils/fallbacks.js +0 -16
- package/dist/esm/Table/utils/fallbacks.js.map +0 -1
- package/dist/esm/Table/utils/utils.js +0 -19
- package/dist/esm/Table/utils/utils.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Adornment.js","sources":["../../../../src/FormElement/Adornment/Adornment.tsx"],"sourcesContent":["import { forwardRef, useContext } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvButtonBase } from \"../../ButtonBase\";\nimport { HvBaseProps } from \"../../types/generic\";\nimport {\n HvFormElementContext,\n HvFormElementDescriptorsContext,\n} from \"../context\";\nimport { HvFormStatus } from \"../FormElement\";\nimport { staticClasses, useClasses } from \"./Adornment.styles\";\n\nconst noop = () => {};\n\nexport { staticClasses as adornmentClasses };\n\nexport type HvAdornmentClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvAdornmentProps\n extends HvBaseProps<\n HTMLDivElement | HTMLButtonElement,\n \"onMouseDown\" | \"onKeyDown\"\n > {\n /** The icon to be added into the input. */\n icon: React.ReactNode;\n /** When the adornment should be displayed. */\n showWhen?: HvFormStatus;\n /** Function to be executed when this element is clicked. */\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n /** If this property is defined the adornment visibility will be exclusively controlled by this value. */\n isVisible?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvAdornmentClasses;\n}\n\n/**\n * Allows to add a decorative icon or an action to a form element, usually on the right side of an input.\n * E.g., the reveal password button.\n *\n * In addition to the showWhen feature, which uses the form element's context validation state to determine\n * its visibility, this component also ensures that it does not steal focus from the input and that it is\n * not accessible using the keyboard.\n *\n * As such, its functionality, if any, for accessibility purposes must be provided through an alternative mean,\n * or by using a regular icon button or toggle button instead.\n */\nexport const HvAdornment = forwardRef<\n HTMLDivElement | HTMLButtonElement,\n HvAdornmentProps\n>((props, ref)
|
|
1
|
+
{"version":3,"file":"Adornment.js","sources":["../../../../src/FormElement/Adornment/Adornment.tsx"],"sourcesContent":["import { forwardRef, useContext } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvButtonBase } from \"../../ButtonBase\";\nimport { HvBaseProps } from \"../../types/generic\";\nimport {\n HvFormElementContext,\n HvFormElementDescriptorsContext,\n} from \"../context\";\nimport { HvFormStatus } from \"../FormElement\";\nimport { staticClasses, useClasses } from \"./Adornment.styles\";\n\nconst noop = () => {};\n\nexport { staticClasses as adornmentClasses };\n\nexport type HvAdornmentClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvAdornmentProps\n extends HvBaseProps<\n HTMLDivElement | HTMLButtonElement,\n \"onMouseDown\" | \"onKeyDown\"\n > {\n /** The icon to be added into the input. */\n icon: React.ReactNode;\n /** When the adornment should be displayed. */\n showWhen?: HvFormStatus;\n /** Function to be executed when this element is clicked. */\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n /** If this property is defined the adornment visibility will be exclusively controlled by this value. */\n isVisible?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvAdornmentClasses;\n}\n\n/**\n * Allows to add a decorative icon or an action to a form element, usually on the right side of an input.\n * E.g., the reveal password button.\n *\n * In addition to the showWhen feature, which uses the form element's context validation state to determine\n * its visibility, this component also ensures that it does not steal focus from the input and that it is\n * not accessible using the keyboard.\n *\n * As such, its functionality, if any, for accessibility purposes must be provided through an alternative mean,\n * or by using a regular icon button or toggle button instead.\n */\nexport const HvAdornment = forwardRef<\n HTMLDivElement | HTMLButtonElement,\n HvAdornmentProps\n>(function HvAdornment(props, ref) {\n const {\n id,\n classes: classesProp,\n className,\n icon,\n showWhen,\n onClick,\n isVisible,\n ...others\n } = useDefaultProps(\"HvAdornment\", props);\n const { classes, cx } = useClasses(classesProp);\n\n const { status, disabled } = useContext(HvFormElementContext);\n const { input } = useContext(HvFormElementDescriptorsContext);\n\n const displayIcon = isVisible ?? (showWhen == null || status === showWhen);\n\n const isClickable = !!onClick;\n\n return isClickable ? (\n <HvButtonBase\n id={id}\n focusableWhenDisabled\n ref={ref as React.ForwardedRef<HTMLButtonElement>}\n type=\"button\"\n tabIndex={-1}\n aria-controls={input?.[0]?.id}\n className={cx(\n classes.root,\n classes.adornment,\n classes.adornmentButton,\n {\n [classes.hideIcon]: !displayIcon,\n [classes.disabled]: disabled,\n },\n className,\n )}\n onClick={onClick}\n onMouseDown={(event) => event.preventDefault()}\n onKeyDown={noop}\n disabled={disabled}\n {...others}\n >\n <div className={classes.icon}>{icon}</div>\n </HvButtonBase>\n ) : (\n <div\n id={id}\n ref={ref as React.ForwardedRef<HTMLDivElement>}\n className={cx(\n classes.root,\n classes.adornment,\n classes.adornmentIcon,\n {\n [classes.hideIcon]: !displayIcon,\n [classes.disabled]: disabled,\n },\n className,\n )}\n role=\"presentation\"\n {...others}\n >\n <div className={classes.icon}>{icon}</div>\n </div>\n );\n});\n"],"names":["HvAdornment"],"mappings":";;;;;;;AAeA,MAAM,OAAO,MAAM;AAAC;AAkCb,MAAM,cAAc,WAGzB,SAASA,aAAY,OAAO,KAAK;AAC3B,QAAA;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD,gBAAgB,eAAe,KAAK;AACxC,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAE9C,QAAM,EAAE,QAAQ,aAAa,WAAW,oBAAoB;AAC5D,QAAM,EAAE,MAAA,IAAU,WAAW,+BAA+B;AAE5D,QAAM,cAAc,cAAc,YAAY,QAAQ,WAAW;AAE3D,QAAA,cAAc,CAAC,CAAC;AAEtB,SAAO,cACL;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA,uBAAqB;AAAA,MACrB;AAAA,MACA,MAAK;AAAA,MACL,UAAU;AAAA,MACV,iBAAe,QAAQ,CAAC,GAAG;AAAA,MAC3B,WAAW;AAAA,QACT,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR;AAAA,UACE,CAAC,QAAQ,QAAQ,GAAG,CAAC;AAAA,UACrB,CAAC,QAAQ,QAAQ,GAAG;AAAA,QACtB;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,MACA,aAAa,CAAC,UAAU,MAAM,eAAe;AAAA,MAC7C,WAAW;AAAA,MACX;AAAA,MACC,GAAG;AAAA,MAEJ,UAAC,oBAAA,OAAA,EAAI,WAAW,QAAQ,MAAO,UAAK,KAAA,CAAA;AAAA,IAAA;AAAA,EAAA,IAGtC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,WAAW;AAAA,QACT,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR;AAAA,UACE,CAAC,QAAQ,QAAQ,GAAG,CAAC;AAAA,UACrB,CAAC,QAAQ,QAAQ,GAAG;AAAA,QACtB;AAAA,QACA;AAAA,MACF;AAAA,MACA,MAAK;AAAA,MACJ,GAAG;AAAA,MAEJ,UAAC,oBAAA,OAAA,EAAI,WAAW,QAAQ,MAAO,UAAK,KAAA,CAAA;AAAA,IAAA;AAAA,EACtC;AAEJ,CAAC;"}
|
|
@@ -11,7 +11,7 @@ import { useClasses } from "./Suggestions.styles.js";
|
|
|
11
11
|
import { staticClasses } from "./Suggestions.styles.js";
|
|
12
12
|
import { HvSelectionList } from "../../SelectionList/SelectionList.js";
|
|
13
13
|
import { HvListItem } from "../../ListContainer/ListItem/ListItem.js";
|
|
14
|
-
const HvSuggestions = forwardRef((props, extRef)
|
|
14
|
+
const HvSuggestions = forwardRef(function HvSuggestions2(props, extRef) {
|
|
15
15
|
const {
|
|
16
16
|
id: idProp,
|
|
17
17
|
className,
|
|
@@ -1 +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)
|
|
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>(function HvSuggestions(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":["HvSuggestions"],"mappings":";;;;;;;;;;;;;AAwDO,MAAM,gBAAgB,WAI3B,SAASA,eAAc,OAAO,QAAQ;AAChC,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;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalActions.js","sources":["../../../src/GlobalActions/GlobalActions.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"GlobalActions.js","sources":["../../../src/GlobalActions/GlobalActions.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport { useTheme as useMuiTheme } from \"@mui/material/styles\";\nimport useMediaQuery from \"@mui/material/useMediaQuery\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseProps } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport {\n getBreakpointStyles,\n staticClasses,\n useClasses,\n} from \"./GlobalActions.styles\";\n\nexport { staticClasses as globalActionsClasses };\nexport type HvGlobalActionsClasses = ExtractNames<typeof useClasses>;\n\nexport type HvGlobalActionsVariant = \"global\" | \"section\";\nexport type HvGlobalActionsPosition = \"sticky\" | \"fixed\" | \"relative\";\nexport type HvGlobalActionsHeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\nexport interface HvGlobalActionsProps\n extends HvBaseProps<HTMLDivElement, \"title\"> {\n /** Text to display in the component. */\n title?: React.ReactNode;\n /** Denotes if this is a global or section component. */\n variant?: HvGlobalActionsVariant;\n /** User can pass in a fully customized button or false for when the back button should not be rendered. */\n backButton?: React.ReactNode;\n /** Heading Level to apply to Title Area. */\n headingLevel?: HvGlobalActionsHeadingLevel;\n /**\n * Position of the Global Actions.\n * @default variant === \"global\" ? \"sticky\" : \"relative\"\n */\n position?: HvGlobalActionsPosition;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvGlobalActionsClasses;\n}\n\n/**\n * Global Actions are actions that affect the entire page they live in.\n * They should persist while scrolling down the screen.\n */\nexport const HvGlobalActions = forwardRef<\n React.ComponentRef<\"div\">,\n HvGlobalActionsProps\n>(function HvGlobalActions(props, ref) {\n const {\n children,\n classes: classesProp,\n className,\n title,\n variant = \"global\",\n backButton,\n headingLevel,\n position: positionProp,\n ...others\n } = useDefaultProps(\"HvGlobalActions\", props);\n const muiTheme = useMuiTheme();\n const { classes, cx, css } = useClasses(classesProp);\n const isSmDown = useMediaQuery(muiTheme.breakpoints.down(\"sm\"));\n const isUpMd = useMediaQuery(muiTheme.breakpoints.up(\"md\"));\n\n const headingLevelToApply = headingLevel || (variant === \"global\" ? 1 : 2);\n\n const position =\n positionProp || (variant === \"global\" ? \"sticky\" : \"relative\");\n\n return (\n <div\n ref={ref}\n className={cx(\n classes.root,\n {\n [classes.positionSticky]: position === \"sticky\",\n [classes.positionFixed]: position === \"fixed\",\n [classes.global]: variant === \"global\",\n [classes.section]: variant === \"section\",\n },\n position === \"fixed\" && css(getBreakpointStyles(isUpMd, isSmDown)),\n className,\n )}\n {...others}\n >\n <div\n className={cx(classes.wrapper, {\n [classes.globalWrapperComplement]: variant === \"global\",\n [classes.globalSectionArea]: variant === \"section\",\n })}\n >\n {variant === \"global\" && backButton && (\n <div className={classes.backButton}>{backButton}</div>\n )}\n {typeof title !== \"string\" ? (\n title\n ) : (\n <HvTypography\n variant={variant === \"global\" ? \"title3\" : \"title4\"}\n component={`h${headingLevelToApply}`}\n className={cx(classes.name, {\n [classes.sectionName]: variant !== \"global\",\n })}\n >\n {title}\n </HvTypography>\n )}\n {children && <div className={classes.actions}>{children}</div>}\n </div>\n </div>\n );\n});\n"],"names":["HvGlobalActions","useMuiTheme"],"mappings":";;;;;;;;AA8CO,MAAM,kBAAkB,WAG7B,SAASA,iBAAgB,OAAO,KAAK;AAC/B,QAAA;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,GAAG;AAAA,EAAA,IACD,gBAAgB,mBAAmB,KAAK;AAC5C,QAAM,WAAWC,SAAY;AAC7B,QAAM,EAAE,SAAS,IAAI,IAAI,IAAI,WAAW,WAAW;AACnD,QAAM,WAAW,cAAc,SAAS,YAAY,KAAK,IAAI,CAAC;AAC9D,QAAM,SAAS,cAAc,SAAS,YAAY,GAAG,IAAI,CAAC;AAE1D,QAAM,sBAAsB,iBAAiB,YAAY,WAAW,IAAI;AAExE,QAAM,WACJ,iBAAiB,YAAY,WAAW,WAAW;AAGn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70
|
-
const WidthGrid = forwardRef((props, ref)
|
|
70
|
+
const WidthGrid = forwardRef(function WidthGrid2(props, ref) {
|
|
71
71
|
const { container, spacing, rowSpacing, columnSpacing, columns, ...others } = props;
|
|
72
72
|
const width = useWidth();
|
|
73
73
|
const containerProps = container ? getContainerProps(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Grid.js","sources":["../../../src/Grid/Grid.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport MuiGrid, { GridProps as MuiGridProps } from \"@mui/material/Grid\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { useWidth } from \"../hooks/useWidth\";\nimport { staticClasses, useClasses } from \"./Grid.styles\";\n\nexport { staticClasses as gridClasses };\n\nexport type HvGridClasses = ExtractNames<typeof useClasses>;\n\nconst BREAKPOINT_GUTTERS = {\n xs: 2,\n sm: 2,\n md: 4,\n lg: 4,\n xl: 4,\n};\n\nconst BREAKPOINT_COLUMNS = {\n xs: 4,\n sm: 8,\n md: 12,\n lg: 12,\n xl: 12,\n};\n\nexport type HvGridDirection =\n | \"row\"\n | \"row-reverse\"\n | \"column\"\n | \"column-reverse\";\n\nexport type HvGridSpacing =\n | \"xs\"\n | \"sm\"\n | \"md\"\n | \"lg\"\n | \"xl\"\n | \"auto\"\n | 1\n | 2\n | 3\n | 4\n | 5\n | 6\n | 7\n | 8\n | 9\n | 10;\n\nexport interface HvGridProps extends Omit<MuiGridProps, \"classes\" | \"columns\"> {\n /**\n * If `true`, the component will have the flex *container* behavior.\n * You should be wrapping *items* with a *container*.\n */\n container?: boolean;\n /**\n * If `true`, the component will have the flex *item* behavior.\n * You should be wrapping *items* with a *container*.\n */\n item?: boolean;\n /**\n * Defines the space between the type item component. It can only be used on a type container component.\n * Based in the 8x factor defined in the theme, it allows the definition of this factor based on the factor\n * (number between 0 and 10), breakpoint or auto.\n */\n spacing?: HvGridSpacing | number;\n /**\n * Defines the vertical space between the type item component. It can only be used on a type container component.\n * Based in the 8x factor defined in the theme, it allows the definition of this factor based on the factor\n * (number between 0 and 10), breakpoint or auto.\n * It overrides the value of the spacing prop.\n */\n rowSpacing?: HvGridSpacing | number;\n /**\n * Defines the horizontal space between the type item component. It can only be used on a type container component.\n * Based in the 8x factor defined in the theme, it allows the definition of this factor based on the factor\n * (number between 0 and 10), breakpoint or auto.\n * It overrides the value of the spacing prop.\n */\n columnSpacing?: HvGridSpacing | number;\n /**\n * The number of columns.\n * Defaults to a 12-column grid.\n * The value \"auto\" implements the Design System directives in terms of variable number of columns.\n * @default 12\n */\n columns?: \"auto\" | MuiGridProps[\"columns\"];\n /**\n * Defines the `flex-direction` style property.\n * It is applied for all screen sizes.\n */\n direction?: HvGridDirection;\n /**\n * Defines the `justify-content` style property.\n * It is applied for all screen sizes.\n */\n justify?:\n | \"flex-start\"\n | \"center\"\n | \"flex-end\"\n | \"space-between\"\n | \"space-around\"\n | \"space-evenly\";\n /**\n * Defines the number of grids the component is going to use.\n * It's applied for all the screen sizes with the lowest priority.\n */\n xs?: number | boolean;\n /**\n * Defines the number of grids the component is going to use.\n * It's applied for the `sm` breakpoint and wider screens if not overridden.\n */\n sm?: number | boolean;\n /**\n * Defines the number of grids the component is going to use.\n * It's applied for the `md` breakpoint and wider screens if not overridden.\n */\n md?: number | boolean;\n /**\n * Defines the number of grids the component is going to use.\n * It's applied for the `lg` breakpoint and wider screens if not overridden.\n */\n lg?: number | boolean;\n /**\n * Defines the number of grids the component is going to use.\n * It's applied for the `xl` breakpoint and wider screens.\n */\n xl?: number | boolean;\n /**\n * Defines the `flex-wrap` style property.\n * It's applied for all screen sizes.\n */\n wrap?: \"nowrap\" | \"wrap\" | \"wrap-reverse\";\n /**\n * If `true`, it sets `min-width: 0` on the item.\n * Refer to the limitations section of the documentation to better understand the use case.\n */\n zeroMinWidth?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvGridClasses;\n}\n\nfunction getGridSpacing(spacing: HvGridProps[\"spacing\"]) {\n let gridSpacing: MuiGridProps[\"spacing\"];\n\n if (typeof spacing === \"string\") {\n if (spacing === \"auto\") {\n gridSpacing = BREAKPOINT_GUTTERS;\n } else {\n gridSpacing = BREAKPOINT_GUTTERS[spacing];\n }\n } else if (typeof spacing === \"object\") {\n gridSpacing = Object.keys(spacing).reduce<Record<string, number>>(\n (acc, bp) => {\n acc[bp] = BREAKPOINT_GUTTERS[spacing[bp]] ?? spacing[bp];\n return acc;\n },\n {},\n );\n } else if (spacing === 0) {\n gridSpacing = { xs: 0 };\n } else {\n gridSpacing = spacing;\n }\n\n return gridSpacing;\n}\n\nfunction getNumberOfColumns(columns: HvGridProps[\"columns\"]) {\n let numberOfColumns: MuiGridProps[\"columns\"];\n\n if (columns === \"auto\") {\n numberOfColumns = BREAKPOINT_COLUMNS;\n } else {\n numberOfColumns = columns;\n }\n\n return numberOfColumns;\n}\n\nfunction getContainerProps(\n spacing: HvGridProps[\"spacing\"],\n rowSpacing: HvGridProps[\"rowSpacing\"],\n columnSpacing: HvGridProps[\"columnSpacing\"],\n columns: HvGridProps[\"columns\"],\n) {\n const containerProps: Pick<\n MuiGridProps,\n \"container\" | \"spacing\" | \"rowSpacing\" | \"columnSpacing\" | \"columns\"\n > = { container: true };\n\n if (spacing != null) {\n containerProps.spacing = getGridSpacing(spacing);\n }\n if (rowSpacing != null) {\n containerProps.rowSpacing = getGridSpacing(rowSpacing);\n }\n if (columnSpacing != null) {\n containerProps.columnSpacing = getGridSpacing(columnSpacing);\n }\n if (columns != null) {\n containerProps.columns = getNumberOfColumns(columns);\n }\n\n return containerProps;\n}\n\nconst WidthGrid = forwardRef<HTMLDivElement, HvGridProps>((props, ref) => {\n const { container, spacing, rowSpacing, columnSpacing, columns, ...others } =\n props;\n\n const width = useWidth();\n\n const containerProps = container\n ? getContainerProps(\n spacing === \"auto\" ? width : spacing,\n rowSpacing === \"auto\" ? width : rowSpacing,\n columnSpacing === \"auto\" ? width : columnSpacing,\n columns,\n )\n : {};\n\n return <MuiGrid ref={ref} {...containerProps} {...others} />;\n});\n\n/**\n * The grid creates visual consistency between layouts while allowing flexibility\n * across a wide variety of designs. This component is based on a 12-column grid layout.\n *\n * It's based on the [Material UI Grid](https://mui.com/material-ui/react-grid/).\n *\n * The definitions were set following the Design System directives:\n *\n * | Breakpoint | Width (in px) | Gutters (in px) | Number of columns |\n * | ---------- | ------------- | --------------- | ----------------- |\n * | xs | [0-600[ | 16 | 4 |\n * | sm | [600-960[ | 16 | 8 |\n * | md | [960-1270[ | 32 | 12 |\n * | lg | [1270-1920[ | 32 | 12 |\n * | xl | [1920-...[ | 32 | 12 |\n *\n * However, the number of columns is set to 12 for all breakpoints, as it serves most\n * of the use cases and simplifies the implementation.\n * To opt-in to the Design System directives, you can set the `columns` prop to `auto`.\n *\n * Also, the Design System specifications are omissive about the horizontal gutters.\n * The HvGrid sets them to the same value as the vertical gutters, depending on the breakpoint.\n * It can be overridden by setting the `rowSpacing` prop.\n */\nexport const HvGrid = forwardRef<\n // no-indent\n HTMLDivElement,\n HvGridProps\n>(function HvGrid(props, ref) {\n const {\n item,\n container,\n spacing = \"auto\",\n rowSpacing,\n columnSpacing,\n columns,\n classes: classesProp,\n ...others\n } = useDefaultProps(\"HvGrid\", props);\n\n const { classes } = useClasses(classesProp);\n\n // Fixes MUI error when using spacings as objects and the grid is an item and container\n // When set to \"auto\", the spacing changes depending on the screen's breakpoint\n // The condition avoids using useWidth and re-rendering the component unnecessarily\n if (\n container &&\n item &&\n (spacing === \"auto\" || rowSpacing === \"auto\" || columnSpacing === \"auto\")\n ) {\n return (\n <WidthGrid\n ref={ref}\n classes={classes}\n item={item}\n container={container}\n spacing={spacing}\n rowSpacing={rowSpacing}\n columnSpacing={columnSpacing}\n columns={columns}\n {...others}\n />\n );\n }\n\n const containerProps = container\n ? getContainerProps(spacing, rowSpacing, columnSpacing, columns)\n : {};\n\n return (\n <MuiGrid\n ref={ref}\n classes={classes}\n item={item}\n {...containerProps}\n {...others}\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A,UAAU,mBAAmB,OAAO;AAAA,EAAA;AAG9C,SAAA;AACT;AAEA,MAAM,YAAY,WAAwC,CAAC,OAAO,QAAQ;AAClE,QAAA,EAAE,WAAW,SAAS,YAAY,eAAe,SAAS,GAAG,WACjE;AAEF,QAAM,QAAQ,SAAS;AAEvB,QAAM,iBAAiB,YACnB;AAAA,IACE,YAAY,SAAS,QAAQ;AAAA,IAC7B,eAAe,SAAS,QAAQ;AAAA,IAChC,kBAAkB,SAAS,QAAQ;AAAA,IACnC;AAAA,EAAA,IAEF,CAAC;AAEL,6BAAQ,SAAQ,EAAA,KAAW,GAAG,gBAAiB,GAAG,QAAQ;AAC5D,CAAC;AA0BM,MAAM,SAAS,WAIpB,SAASA,QAAO,OAAO,KAAK;AACtB,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,GAAG;AAAA,EAAA,IACD,gBAAgB,UAAU,KAAK;AAEnC,QAAM,EAAE,QAAA,IAAY,WAAW,WAAW;AAK1C,MACE,aACA,SACC,YAAY,UAAU,eAAe,UAAU,kBAAkB,SAClE;AAEE,WAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACC,GAAG;AAAA,MAAA;AAAA,IACN;AAAA,EAAA;AAIE,QAAA,iBAAiB,YACnB,kBAAkB,SAAS,YAAY,eAAe,OAAO,IAC7D,CAAC;AAGH,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACC,GAAG;AAAA,MACH,GAAG;AAAA,IAAA;AAAA,EACN;AAEJ,CAAC;"}
|
|
1
|
+
{"version":3,"file":"Grid.js","sources":["../../../src/Grid/Grid.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport MuiGrid, { GridProps as MuiGridProps } from \"@mui/material/Grid\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { useWidth } from \"../hooks/useWidth\";\nimport { staticClasses, useClasses } from \"./Grid.styles\";\n\nexport { staticClasses as gridClasses };\n\nexport type HvGridClasses = ExtractNames<typeof useClasses>;\n\nconst BREAKPOINT_GUTTERS = {\n xs: 2,\n sm: 2,\n md: 4,\n lg: 4,\n xl: 4,\n};\n\nconst BREAKPOINT_COLUMNS = {\n xs: 4,\n sm: 8,\n md: 12,\n lg: 12,\n xl: 12,\n};\n\nexport type HvGridDirection =\n | \"row\"\n | \"row-reverse\"\n | \"column\"\n | \"column-reverse\";\n\nexport type HvGridSpacing =\n | \"xs\"\n | \"sm\"\n | \"md\"\n | \"lg\"\n | \"xl\"\n | \"auto\"\n | 1\n | 2\n | 3\n | 4\n | 5\n | 6\n | 7\n | 8\n | 9\n | 10;\n\nexport interface HvGridProps extends Omit<MuiGridProps, \"classes\" | \"columns\"> {\n /**\n * If `true`, the component will have the flex *container* behavior.\n * You should be wrapping *items* with a *container*.\n */\n container?: boolean;\n /**\n * If `true`, the component will have the flex *item* behavior.\n * You should be wrapping *items* with a *container*.\n */\n item?: boolean;\n /**\n * Defines the space between the type item component. It can only be used on a type container component.\n * Based in the 8x factor defined in the theme, it allows the definition of this factor based on the factor\n * (number between 0 and 10), breakpoint or auto.\n */\n spacing?: HvGridSpacing | number;\n /**\n * Defines the vertical space between the type item component. It can only be used on a type container component.\n * Based in the 8x factor defined in the theme, it allows the definition of this factor based on the factor\n * (number between 0 and 10), breakpoint or auto.\n * It overrides the value of the spacing prop.\n */\n rowSpacing?: HvGridSpacing | number;\n /**\n * Defines the horizontal space between the type item component. It can only be used on a type container component.\n * Based in the 8x factor defined in the theme, it allows the definition of this factor based on the factor\n * (number between 0 and 10), breakpoint or auto.\n * It overrides the value of the spacing prop.\n */\n columnSpacing?: HvGridSpacing | number;\n /**\n * The number of columns.\n * Defaults to a 12-column grid.\n * The value \"auto\" implements the Design System directives in terms of variable number of columns.\n * @default 12\n */\n columns?: \"auto\" | MuiGridProps[\"columns\"];\n /**\n * Defines the `flex-direction` style property.\n * It is applied for all screen sizes.\n */\n direction?: HvGridDirection;\n /**\n * Defines the `justify-content` style property.\n * It is applied for all screen sizes.\n */\n justify?:\n | \"flex-start\"\n | \"center\"\n | \"flex-end\"\n | \"space-between\"\n | \"space-around\"\n | \"space-evenly\";\n /**\n * Defines the number of grids the component is going to use.\n * It's applied for all the screen sizes with the lowest priority.\n */\n xs?: number | boolean;\n /**\n * Defines the number of grids the component is going to use.\n * It's applied for the `sm` breakpoint and wider screens if not overridden.\n */\n sm?: number | boolean;\n /**\n * Defines the number of grids the component is going to use.\n * It's applied for the `md` breakpoint and wider screens if not overridden.\n */\n md?: number | boolean;\n /**\n * Defines the number of grids the component is going to use.\n * It's applied for the `lg` breakpoint and wider screens if not overridden.\n */\n lg?: number | boolean;\n /**\n * Defines the number of grids the component is going to use.\n * It's applied for the `xl` breakpoint and wider screens.\n */\n xl?: number | boolean;\n /**\n * Defines the `flex-wrap` style property.\n * It's applied for all screen sizes.\n */\n wrap?: \"nowrap\" | \"wrap\" | \"wrap-reverse\";\n /**\n * If `true`, it sets `min-width: 0` on the item.\n * Refer to the limitations section of the documentation to better understand the use case.\n */\n zeroMinWidth?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvGridClasses;\n}\n\nfunction getGridSpacing(spacing: HvGridProps[\"spacing\"]) {\n let gridSpacing: MuiGridProps[\"spacing\"];\n\n if (typeof spacing === \"string\") {\n if (spacing === \"auto\") {\n gridSpacing = BREAKPOINT_GUTTERS;\n } else {\n gridSpacing = BREAKPOINT_GUTTERS[spacing];\n }\n } else if (typeof spacing === \"object\") {\n gridSpacing = Object.keys(spacing).reduce<Record<string, number>>(\n (acc, bp) => {\n acc[bp] = BREAKPOINT_GUTTERS[spacing[bp]] ?? spacing[bp];\n return acc;\n },\n {},\n );\n } else if (spacing === 0) {\n gridSpacing = { xs: 0 };\n } else {\n gridSpacing = spacing;\n }\n\n return gridSpacing;\n}\n\nfunction getNumberOfColumns(columns: HvGridProps[\"columns\"]) {\n let numberOfColumns: MuiGridProps[\"columns\"];\n\n if (columns === \"auto\") {\n numberOfColumns = BREAKPOINT_COLUMNS;\n } else {\n numberOfColumns = columns;\n }\n\n return numberOfColumns;\n}\n\nfunction getContainerProps(\n spacing: HvGridProps[\"spacing\"],\n rowSpacing: HvGridProps[\"rowSpacing\"],\n columnSpacing: HvGridProps[\"columnSpacing\"],\n columns: HvGridProps[\"columns\"],\n) {\n const containerProps: Pick<\n MuiGridProps,\n \"container\" | \"spacing\" | \"rowSpacing\" | \"columnSpacing\" | \"columns\"\n > = { container: true };\n\n if (spacing != null) {\n containerProps.spacing = getGridSpacing(spacing);\n }\n if (rowSpacing != null) {\n containerProps.rowSpacing = getGridSpacing(rowSpacing);\n }\n if (columnSpacing != null) {\n containerProps.columnSpacing = getGridSpacing(columnSpacing);\n }\n if (columns != null) {\n containerProps.columns = getNumberOfColumns(columns);\n }\n\n return containerProps;\n}\n\nconst WidthGrid = forwardRef<\n // no-indent\n HTMLDivElement,\n HvGridProps\n>(function WidthGrid(props, ref) {\n const { container, spacing, rowSpacing, columnSpacing, columns, ...others } =\n props;\n\n const width = useWidth();\n\n const containerProps = container\n ? getContainerProps(\n spacing === \"auto\" ? width : spacing,\n rowSpacing === \"auto\" ? width : rowSpacing,\n columnSpacing === \"auto\" ? width : columnSpacing,\n columns,\n )\n : {};\n\n return <MuiGrid ref={ref} {...containerProps} {...others} />;\n});\n\n/**\n * The grid creates visual consistency between layouts while allowing flexibility\n * across a wide variety of designs. This component is based on a 12-column grid layout.\n *\n * It's based on the [Material UI Grid](https://mui.com/material-ui/react-grid/).\n *\n * The definitions were set following the Design System directives:\n *\n * | Breakpoint | Width (in px) | Gutters (in px) | Number of columns |\n * | ---------- | ------------- | --------------- | ----------------- |\n * | xs | [0-600[ | 16 | 4 |\n * | sm | [600-960[ | 16 | 8 |\n * | md | [960-1270[ | 32 | 12 |\n * | lg | [1270-1920[ | 32 | 12 |\n * | xl | [1920-...[ | 32 | 12 |\n *\n * However, the number of columns is set to 12 for all breakpoints, as it serves most\n * of the use cases and simplifies the implementation.\n * To opt-in to the Design System directives, you can set the `columns` prop to `auto`.\n *\n * Also, the Design System specifications are omissive about the horizontal gutters.\n * The HvGrid sets them to the same value as the vertical gutters, depending on the breakpoint.\n * It can be overridden by setting the `rowSpacing` prop.\n */\nexport const HvGrid = forwardRef<\n // no-indent\n HTMLDivElement,\n HvGridProps\n>(function HvGrid(props, ref) {\n const {\n item,\n container,\n spacing = \"auto\",\n rowSpacing,\n columnSpacing,\n columns,\n classes: classesProp,\n ...others\n } = useDefaultProps(\"HvGrid\", props);\n\n const { classes } = useClasses(classesProp);\n\n // Fixes MUI error when using spacings as objects and the grid is an item and container\n // When set to \"auto\", the spacing changes depending on the screen's breakpoint\n // The condition avoids using useWidth and re-rendering the component unnecessarily\n if (\n container &&\n item &&\n (spacing === \"auto\" || rowSpacing === \"auto\" || columnSpacing === \"auto\")\n ) {\n return (\n <WidthGrid\n ref={ref}\n classes={classes}\n item={item}\n container={container}\n spacing={spacing}\n rowSpacing={rowSpacing}\n columnSpacing={columnSpacing}\n columns={columns}\n {...others}\n />\n );\n }\n\n const containerProps = container\n ? getContainerProps(spacing, rowSpacing, columnSpacing, columns)\n : {};\n\n return (\n <MuiGrid\n ref={ref}\n classes={classes}\n item={item}\n {...containerProps}\n {...others}\n />\n );\n});\n"],"names":["WidthGrid","HvGrid"],"mappings":";;;;;;;AAcA,MAAM,qBAAqB;AAAA,EACzB,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAEA,MAAM,qBAAqB;AAAA,EACzB,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAuHA,SAAS,eAAe,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AAkB,SAAS,QAAQ;AAAA,IACnC;AAAA,EAAA,IAEF,CAAC;AAEL,6BAAQ,SAAQ,EAAA,KAAW,GAAG,gBAAiB,GAAG,QAAQ;AAC5D,CAAC;AA0BM,MAAM,SAAS,WAIpB,SAASC,QAAO,OAAO,KAAK;AACtB,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,GAAG;AAAA,EAAA,IACD,gBAAgB,UAAU,KAAK;AAEnC,QAAM,EAAE,QAAA,IAAY,WAAW,WAAW;AAK1C,MACE,aACA,SACC,YAAY,UAAU,eAAe,UAAU,kBAAkB,SAClE;AAEE,WAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACC,GAAG;AAAA,MAAA;AAAA,IACN;AAAA,EAAA;AAIE,QAAA,iBAAiB,YACnB,kBAAkB,SAAS,YAAY,eAAe,OAAO,IAC7D,CAAC;AAGH,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACC,GAAG;AAAA,MACH,GAAG;AAAA,IAAA;AAAA,EACN;AAEJ,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InlineEditor.js","sources":["../../../src/InlineEditor/InlineEditor.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"InlineEditor.js","sources":["../../../src/InlineEditor/InlineEditor.tsx"],"sourcesContent":["import { useRef, useState } from \"react\";\nimport { Edit } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n useTheme,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvButton, HvButtonProps } from \"../Button\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useEnhancedEffect } from \"../hooks/useEnhancedEffect\";\nimport { HvInput, HvInputProps } from \"../Input\";\nimport { HvTooltip } from \"../Tooltip\";\nimport {\n fixedForwardRef,\n PolymorphicComponentRef,\n PolymorphicRef,\n} from \"../types/generic\";\nimport {\n HvTypography,\n HvTypographyProps,\n HvTypographyVariants,\n} from \"../Typography\";\nimport { isKey } from \"../utils/keyboardUtils\";\nimport { staticClasses, useClasses } from \"./InlineEditor.styles\";\n\nexport { staticClasses as inlineEditorClasses };\n\nexport type HvInlineEditorClasses = ExtractNames<typeof useClasses>;\n\nexport type HvInlineEditorProps<C extends React.ElementType = typeof HvInput> =\n PolymorphicComponentRef<\n C,\n {\n /** The value of the form element. */\n value?: string;\n /** The default value of the form element. */\n defaultValue?: string;\n /** Whether the Edit icon should always be visible */\n showIcon?: boolean;\n /** Variant of the HvTypography to display */\n variant?: HvTypographyVariants;\n /** Called when the input is blurred. */\n onBlur?: (\n event: React.FocusEvent<HTMLTextAreaElement | HTMLInputElement>,\n value: string,\n ) => void;\n /** Called when the input value changes. */\n onChange?: (event: React.SyntheticEvent, value: string) => void;\n /** Called when there's a keydown event on the input. */\n onKeyDown?: (\n event:\n | React.KeyboardEvent<HTMLTextAreaElement | HTMLInputElement>\n | React.MouseEvent,\n value: string,\n ) => void;\n /** Props passed to the HvButton component */\n buttonProps?: HvButtonProps;\n /** Props passed to the HvTypography text component */\n typographyProps?: HvTypographyProps;\n /** Whether the editor is disabled or not. */\n disabled?: boolean;\n /** A Jss Object used to override or extend the styles applied to the empty state component. */\n classes?: HvInlineEditorClasses;\n /** The placeholder value of the input. */\n placeholder?: string;\n }\n >;\n\n/**\n * An Inline Editor allows the user to edit a record without making a major switch\n * between viewing and editing, making it an efficient method of updating a record.\n */\nexport const HvInlineEditor = fixedForwardRef(function HvInlineEditor<\n C extends React.ElementType = typeof HvInput,\n>(props: HvInlineEditorProps<C>, ref: PolymorphicRef<C>) {\n const {\n className,\n classes: classesProp,\n value: valueProp,\n defaultValue = \"\",\n showIcon,\n component: InputComponent = HvInput,\n variant = \"body\",\n placeholder = \"Enter text\",\n onBlur,\n onChange,\n onKeyDown,\n buttonProps,\n typographyProps,\n disabled,\n ...others\n } = useDefaultProps(\"HvInlineEditor\", props);\n\n const { classes, cx } = useClasses(classesProp);\n const [value, setValue] = useControlled(valueProp, defaultValue);\n const [editMode, setEditMode] = useState(false);\n const [cachedValue, setCachedValue] = useState(value);\n const inputRef = useRef<HTMLInputElement>();\n const { activeTheme } = useTheme();\n const [isOverflowing, setIsOverflowing] = useState(false);\n\n const typographyStyles = activeTheme?.typography[variant] || {};\n const { lineHeight } = typographyStyles;\n\n const checkOverflow = () => {\n if (inputRef.current) {\n setIsOverflowing(\n inputRef.current.scrollWidth > inputRef.current.clientWidth,\n );\n }\n };\n\n useEnhancedEffect(() => {\n const input = inputRef.current;\n if (editMode && input) {\n input.focus();\n input.select();\n }\n }, [editMode]);\n\n const handleClick = () => {\n setEditMode(true);\n setCachedValue(value);\n };\n\n const handleBlur: HvInputProps[\"onBlur\"] = (event) => {\n setEditMode(false);\n\n const newValue = value || cachedValue; // empty values should be ignored\n setValue(newValue);\n onBlur?.(event, newValue);\n };\n\n const handleKeyDown: HvInputProps[\"onKeyDown\"] = (event) => {\n let newValue = value;\n if (isKey(event, \"Esc\")) {\n newValue = cachedValue;\n setEditMode(false);\n setValue(newValue);\n checkOverflow();\n }\n onKeyDown?.(event, newValue);\n };\n\n const handleChange: HvInputProps[\"onChange\"] = (event, val) => {\n setValue(val);\n checkOverflow();\n onChange?.(event, val);\n };\n\n return (\n <div className={cx(classes.root, className)}>\n {editMode && !disabled ? (\n <InputComponent\n ref={ref}\n inputRef={inputRef}\n classes={{\n root: classes.inputRoot,\n input: classes.input,\n inputBorderContainer: classes.inputBorderContainer,\n }}\n inputProps={{\n style: {\n ...typographyStyles,\n height: InputComponent === HvInput ? lineHeight : undefined,\n },\n }}\n value={value}\n onBlur={handleBlur}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n {...others}\n />\n ) : (\n <HvTooltip title={isOverflowing && value}>\n <HvButton\n variant=\"secondaryGhost\"\n overrideIconColors={false}\n endIcon={\n <Edit\n color=\"secondary_60\"\n className={cx(classes.icon, {\n [classes.iconVisible]: showIcon,\n })}\n />\n }\n className={cx(classes.button, {\n [classes.largeText]: parseInt(lineHeight as string, 10) >= 28,\n })}\n onClick={handleClick}\n disabled={disabled}\n {...buttonProps}\n >\n <HvTypography\n variant={variant}\n noWrap\n className={cx(classes.text, { [classes.textEmpty]: !value })}\n {...typographyProps}\n >\n {value || placeholder}\n </HvTypography>\n </HvButton>\n </HvTooltip>\n )}\n </div>\n );\n});\n"],"names":["HvInlineEditor"],"mappings":";;;;;;;;;;;;;;AAyEO,MAAM,iBAAiB,gBAAgB,SAASA,gBAErD,OAA+B,KAAwB;AACjD,QAAA;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT,OAAO;AAAA,IACP,eAAe;AAAA,IACf;AAAA,IACA,WAAW,iBAAiB;AAAA,IAC5B,UAAU;AAAA,IACV,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD,gBAAgB,kBAAkB,KAAK;AAE3C,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAC9C,QAAM,CAAC,OAAO,QAAQ,IAAI,cAAc,WAAW,YAAY;AAC/D,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AAC9C,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AACpD,QAAM,WAAW,OAAyB;AACpC,QAAA,EAAE,YAAY,IAAI,SAAS;AACjC,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAS,KAAK;AAExD,QAAM,mBAAmB,aAAa,WAAW,OAAO,KAAK,CAAC;AACxD,QAAA,EAAE,eAAe;AAEvB,QAAM,gBAAgB,MAAM;AAC1B,QAAI,SAAS,SAAS;AACpB;AAAA,QACE,SAAS,QAAQ,cAAc,SAAS,QAAQ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AAA,IAAA;AAAA,MACC,SAAQ;AAAA,MACR,oBAAoB;AAAA,MACpB,SACE;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,OAAM;AAAA,UACN,WAAW,GAAG,QAAQ,MAAM;AAAA,YAC1B,CAAC,QAAQ,WAAW,GAAG;AAAA,UACxB,CAAA;AAAA,QAAA;AAAA,MACH;AAAA,MAEF,WAAW,GAAG,QAAQ,QAAQ;AAAA,QAC5B,CAAC,QAAQ,SAAS,GAAG,SAAS,YAAsB,EAAE,KAAK;AAAA,MAAA,CAC5D;AAAA,MACD,SAAS;AAAA,MACT;AAAA,MACC,GAAG;AAAA,MAEJ,UAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC;AAAA,UACA,QAAM;AAAA,UACN,WAAW,GAAG,QAAQ,MAAM,EAAE,CAAC,QAAQ,SAAS,GAAG,CAAC,OAAO;AAAA,UAC1D,GAAG;AAAA,UAEH,UAAS,SAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IACZ;AAAA,KAEJ,EAEJ,CAAA;AAEJ,CAAC;"}
|
package/dist/esm/Input/Input.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useRef, useState, useMemo, useCallback, isValidElement, cloneElement, useEffect } from "react";
|
|
3
3
|
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";
|
|
@@ -9,6 +9,7 @@ import { useControlled } from "../hooks/useControlled.js";
|
|
|
9
9
|
import { useIsMounted } from "../hooks/useIsMounted.js";
|
|
10
10
|
import { useLabels } from "../hooks/useLabels.js";
|
|
11
11
|
import { useUniqueId } from "../hooks/useUniqueId.js";
|
|
12
|
+
import { fixedForwardRef } from "../types/generic.js";
|
|
12
13
|
import { isKey } from "../utils/keyboardUtils.js";
|
|
13
14
|
import { setId } from "../utils/setId.js";
|
|
14
15
|
import { useClasses } from "./Input.styles.js";
|
|
@@ -45,7 +46,7 @@ const changeInputValue = (input, value = "") => {
|
|
|
45
46
|
setInputValue?.call(input, value);
|
|
46
47
|
input?.dispatchEvent(event);
|
|
47
48
|
};
|
|
48
|
-
const HvInput =
|
|
49
|
+
const HvInput = fixedForwardRef(function HvInput2(props, ref) {
|
|
49
50
|
const {
|
|
50
51
|
classes: classesProp,
|
|
51
52
|
className,
|
|
@@ -122,7 +123,7 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
122
123
|
const performValidation = useCallback(() => {
|
|
123
124
|
const inputValidity = validateInput(
|
|
124
125
|
inputRef.current,
|
|
125
|
-
value,
|
|
126
|
+
String(value),
|
|
126
127
|
required,
|
|
127
128
|
minCharQuantity,
|
|
128
129
|
maxCharQuantity,
|
|
@@ -208,12 +209,12 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
208
209
|
if (eventTargetIsInsideContainer(suggestionsRef.current, event)) return;
|
|
209
210
|
setFocused(false);
|
|
210
211
|
const inputValidity = performValidation();
|
|
211
|
-
onBlur?.(event, value, inputValidity);
|
|
212
|
+
onBlur?.(event, String(value), inputValidity);
|
|
212
213
|
};
|
|
213
214
|
const onFocusHandler = (event) => {
|
|
214
215
|
setFocused(true);
|
|
215
216
|
setValidationState(validationStates.standBy);
|
|
216
|
-
onFocus?.(event, value);
|
|
217
|
+
onFocus?.(event, String(value));
|
|
217
218
|
};
|
|
218
219
|
const getSuggestions = (li) => {
|
|
219
220
|
const listEl = document.getElementById(
|
|
@@ -234,9 +235,9 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
234
235
|
const li = getSuggestions(0);
|
|
235
236
|
li?.focus();
|
|
236
237
|
} else if (isKey(event, "Enter")) {
|
|
237
|
-
onEnter?.(event, value);
|
|
238
|
+
onEnter?.(event, String(value));
|
|
238
239
|
}
|
|
239
|
-
onKeyDown?.(event, value);
|
|
240
|
+
onKeyDown?.(event, String(value));
|
|
240
241
|
};
|
|
241
242
|
const onContainerBlurHandler = (event) => {
|
|
242
243
|
if (event.relatedTarget) {
|
|
@@ -289,7 +290,7 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
289
290
|
]);
|
|
290
291
|
const handleSearch = useCallback(
|
|
291
292
|
(event) => {
|
|
292
|
-
onEnter?.(event, value);
|
|
293
|
+
onEnter?.(event, String(value));
|
|
293
294
|
},
|
|
294
295
|
[onEnter, value]
|
|
295
296
|
);
|
|
@@ -465,7 +466,7 @@ const HvInput = forwardRef(function HvInput2(props, ref) {
|
|
|
465
466
|
onFocus: (event) => {
|
|
466
467
|
inputProps.onFocus?.(event);
|
|
467
468
|
if (canShowSuggestions && suggestOnFocus) {
|
|
468
|
-
suggestionHandler(value);
|
|
469
|
+
suggestionHandler(String(value));
|
|
469
470
|
}
|
|
470
471
|
},
|
|
471
472
|
onClick: (event) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","sources":["../../../src/Input/Input.tsx"],"sourcesContent":["import {\n cloneElement,\n forwardRef,\n isValidElement,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { InputBaseComponentProps as MuiInputBaseComponentProps } from \"@mui/material/InputBase\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport {\n CloseXS,\n Preview,\n PreviewOff,\n Search,\n Success,\n} from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseInput, HvBaseInputProps } from \"../BaseInput\";\nimport {\n computeValidationMessage,\n computeValidationState,\n computeValidationType,\n DEFAULT_ERROR_MESSAGES,\n hasBuiltInValidations,\n HvInputValidity,\n validateInput,\n} from \"../BaseInput/validations\";\nimport {\n HvAdornment,\n HvAdornmentProps,\n HvFormElement,\n HvFormElementProps,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvWarningText,\n isInvalid,\n isValid,\n validationStates,\n} from \"../FormElement\";\nimport {\n HvSuggestion,\n HvSuggestions,\n HvSuggestionsProps,\n} from \"../FormElement/Suggestions/Suggestions\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useIsMounted } from \"../hooks/useIsMounted\";\nimport { useLabels } from \"../hooks/useLabels\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvTooltip } from \"../Tooltip\";\nimport { isKey } from \"../utils/keyboardUtils\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./Input.styles\";\n\nexport { staticClasses as inputClasses };\n\nexport type HvInputClasses = ExtractNames<typeof useClasses>;\n\ntype InputElement = HTMLInputElement | HTMLTextAreaElement;\n\nexport interface HvValidationMessages {\n /** The value when a validation fails. */\n error?: string;\n /** The message that appears when there are too many characters. */\n maxCharError?: string;\n /** The message that appears when there are too few characters. */\n minCharError?: string;\n /** The message that appears when the input is empty and required. */\n requiredError?: string;\n /** The message that appears when the input is value is incompatible with the expected type. */\n typeMismatchError?: string;\n}\n\nexport interface HvInputSuggestion {\n id: string;\n label: string;\n value?: string;\n}\n\nexport interface HvInputProps\n extends Omit<HvBaseInputProps, \"onBlur\" | \"onFocus\" | \"onKeyDown\"> {\n /** The form element name. */\n name?: string;\n /** The value of the form element. */\n value?: string;\n /** When uncontrolled, defines the initial input value. */\n defaultValue?: string;\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 inputted via inputProps.\n */\n label?: React.ReactNode;\n /** Provide additional descriptive text for the form element. */\n description?: React.ReactNode;\n /** Indicates that the form element is disabled. */\n disabled?: boolean;\n /** Indicates that the form element is not editable. */\n readOnly?: boolean;\n /** Indicates that user input is required on the form element. */\n required?: boolean;\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 `checked`, depending of the values of both `required` and `checked`.\n */\n status?: HvFormStatus;\n /** The error message to show when `status` is \"invalid\". */\n statusMessage?: string;\n /**\n * Callback called when the user submits the value by pressing Enter/Return.\n *\n * Also called when the search button is clicked (when type is \"search\").\n */\n onEnter?: (\n event: React.KeyboardEvent<InputElement> | React.MouseEvent,\n value: string,\n ) => void;\n /**\n * The function that will be executed onBlur, allows checking the validation state,\n * it receives the value and the validation state.\n */\n onBlur?: (\n event: React.FocusEvent<InputElement>,\n value: string,\n validationState: HvInputValidity,\n ) => void;\n /**\n * The function that will be executed onBlur, allows checking the value state,\n * it receives the value.\n */\n onFocus?: (event: React.FocusEvent<InputElement>, value: string) => void;\n /**\n * The function that will be executed onKeyDown, allows checking the value state,\n * it receives the event and value.\n */\n onKeyDown?: (\n event: React.KeyboardEvent<InputElement> | React.MouseEvent,\n value: string,\n ) => void;\n /** The input type. */\n type?: React.HTMLInputTypeAttribute;\n /** The placeholder value of the input. */\n placeholder?: string;\n /** Internal labels?. */\n labels?: HvInputLabels & Record<string, any>;\n /** An Object containing the various texts associated with the input. */\n validationMessages?: HvValidationMessages;\n /** Attributes applied to the input element. */\n inputProps?: MuiInputBaseComponentProps;\n /**\n * Allows passing a ref to the underlying input\n * @deprecated Use `ref` directly instead\n * */\n inputRef?: HvBaseInputProps[\"inputRef\"];\n /** The function that will be executed to received an array of objects that has a label and id to create list of suggestion */\n suggestionListCallback?: (value: string) => HvInputSuggestion[] | null;\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 /**\n * Whether the suggestions should be triggered once the input is focused and not only when typing.\n * @default false\n * */\n suggestOnFocus?: boolean;\n /**\n * The custom validation function, it receives the value and must return\n * either `true` for valid or `false` for invalid, default validations would only\n * occur if this function is null or undefined\n */\n validation?: (value: string) => boolean;\n /** If `true` it should autofocus. */\n autoFocus?: boolean;\n /** If `true` the clear button is disabled. */\n disableClear?: boolean; // TODO - rename in v6 since it doesn't disable but hides the button\n /** If `true` the reveal password button is disabled. Valid only when type is \"password\". */\n disableRevealPassword?: boolean; // TODO - rename in v6 since it doesn't disable but hides the button\n /** If `true` the search button is disabled. Valid only when type is \"search\". */\n disableSearchButton?: boolean; // TODO - rename in v6 since it doesn't disable but hides the button\n /**\n * If `true` the validation icon adornment is visible. Defaults to `false`.\n *\n * Currently, DS specifications define only a positive feedback icon;\n * errors are signaled through the border style and by displaying the error message.\n */\n showValidationIcon?: boolean;\n /** A custom icon to be added into the input. */\n endAdornment?: React.ReactNode;\n /** The maximum allowed length of the characters, if this value is null no check will be performed. */\n maxCharQuantity?: number;\n /** The minimum allowed length of the characters, if this value is null no check will be perform. */\n minCharQuantity?: number;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvInputClasses;\n}\n\nconst DEFAULT_LABELS = {\n /** The label of the clear button. */\n clearButtonLabel: \"Clear the text\",\n /** The label of the reveal password button. */\n revealPasswordButtonLabel: \"Reveal password\",\n /** The tooltip of the reveal password button when the password is hidden. */\n revealPasswordButtonClickToShowTooltip: \"Click to show password.\",\n /** The tooltip of the reveal password button when the password is revealed. */\n revealPasswordButtonClickToHideTooltip: \"Click to hide password.\",\n /** The label of the search button. */\n searchButtonLabel: \"Search\",\n};\n\nexport type HvInputLabels = Partial<typeof DEFAULT_LABELS>;\n\nfunction eventTargetIsInsideContainer(\n container: HTMLElement | null,\n event: React.FocusEvent<any>,\n) {\n return !!container?.contains(event.relatedTarget);\n}\n\n/** Changes a given `input`'s `value`, triggering its `onChange` */\nconst changeInputValue = (input: HTMLInputElement | null, value = \"\") => {\n const event = new Event(\"input\", { bubbles: true });\n\n /** Original `input.value` setter (React overrides it). */\n const setInputValue = Object.getOwnPropertyDescriptor(\n window.HTMLInputElement.prototype,\n \"value\",\n )?.set;\n\n setInputValue?.call(input, value);\n input?.dispatchEvent(event);\n};\n\n/**\n * A text input box is a graphical control element intended to enable the user to input text information to be used by the software.\n */\nexport const HvInput = forwardRef<\n // no-indent\n InputElement,\n HvInputProps\n>(function HvInput(props, ref) {\n const {\n classes: classesProp,\n className,\n id,\n name,\n value: valueProp,\n defaultValue = \"\",\n required,\n readOnly,\n disabled,\n enablePortal = false,\n suggestOnFocus = false,\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n onChange,\n onEnter,\n status,\n statusMessage,\n \"aria-errormessage\": ariaErrorMessage,\n type = \"text\",\n placeholder,\n autoFocus = false,\n labels: labelsProp,\n validationMessages,\n disableClear = false,\n disableRevealPassword = false,\n disableSearchButton = false,\n endAdornment,\n maxCharQuantity,\n minCharQuantity,\n validation,\n showValidationIcon = false,\n suggestionListCallback,\n inputRef: inputRefProp,\n onBlur,\n onFocus,\n onKeyDown,\n inputProps = {},\n ...others\n } = useDefaultProps(\"HvInput\", props);\n const { classes, cx } = useClasses(classesProp);\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n const elementId = useUniqueId(id);\n\n const inputRef = useRef<HTMLInputElement>(null);\n const forkedRef = useForkRef(ref, inputRef, inputRefProp);\n const suggestionsRef = useRef<HTMLDivElement>(null);\n\n const [focused, setFocused] = useState(false);\n\n // Signals that the user has manually edited the input value\n const isDirty = useRef(false);\n\n // Value related state\n const [value, setValue] = useControlled(valueProp, defaultValue);\n\n const isEmptyValue = value == null || value === \"\";\n\n // Validation related state\n const [validationState, setValidationState] = useControlled(\n status,\n validationStates.standBy,\n );\n\n const [validationMessage, setValidationMessage] = useControlled(\n statusMessage,\n \"\",\n );\n\n // validationMessages reference tends to change, as users will not memoize/useState for it;\n // dependencies must be more explicit so we set\n const errorMessages = useMemo(\n () => ({ ...DEFAULT_ERROR_MESSAGES, ...validationMessages }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n validationMessages?.error,\n validationMessages?.requiredError,\n validationMessages?.minCharError,\n validationMessages?.maxCharError,\n validationMessages?.typeMismatchError,\n ],\n );\n\n const validationType = useMemo(() => computeValidationType(type), [type]);\n\n // Validates the input, sets the status and the statusMessage accordingly (if uncontrolled)\n // and returns the validity state of the input.\n const performValidation = useCallback(() => {\n const inputValidity = validateInput(\n inputRef.current,\n value,\n required,\n minCharQuantity,\n maxCharQuantity,\n validationType,\n validation,\n );\n\n // This will only run if status is uncontrolled\n setValidationState(computeValidationState(inputValidity, isEmptyValue));\n\n // This will only run if statusMessage is uncontrolled\n setValidationMessage(\n computeValidationMessage(inputValidity, errorMessages),\n );\n\n return inputValidity;\n }, [\n errorMessages,\n isEmptyValue,\n maxCharQuantity,\n minCharQuantity,\n required,\n setValidationMessage,\n setValidationState,\n validation,\n validationType,\n value,\n ]);\n\n // The error message area will only be created if:\n // - an external element that provides an error message isn't identified via aria-errormessage AND\n // - both status and statusMessage properties are being controlled OR\n // - status is uncontrolled and any of the built-in validations are active\n const canShowError =\n ariaErrorMessage == null &&\n ((status !== undefined && statusMessage !== undefined) ||\n (status === undefined &&\n hasBuiltInValidations(\n required,\n validationType,\n minCharQuantity,\n maxCharQuantity,\n validation,\n inputProps,\n )));\n\n const isStateInvalid = isInvalid(validationState);\n\n // Input type related state\n const [revealPassword, setRevealPassword] = useState(false);\n\n const realType = useMemo(() => {\n if (type === \"password\") {\n return revealPassword ? \"text\" : \"password\";\n }\n\n if (type === \"search\") {\n return \"search\";\n }\n\n return \"text\";\n }, [revealPassword, type]);\n\n // Suggestions related state\n const [suggestionValues, setSuggestionValues] = useState<\n HvSuggestion[] | null\n >(null);\n\n const canShowSuggestions = suggestionListCallback != null;\n const hasSuggestions = !!suggestionValues;\n\n // Miscellaneous state\n const hasLabel = label != null;\n const hasDescription = description != null;\n\n /**\n * Looks for the node that represent the input inside the material tree and focus it.\n */\n const focusInput = () => {\n inputRef.current?.focus();\n };\n\n const isMounted = useIsMounted();\n\n /**\n * Clears the suggestion array.\n */\n const suggestionClearHandler = () => {\n if (isMounted.current) {\n setSuggestionValues(null);\n }\n };\n\n /**\n * Fills of the suggestion array.\n */\n const suggestionHandler = (val: string) => {\n const suggestionsArray = suggestionListCallback?.(val);\n if (suggestionsArray?.[0]?.label) {\n setSuggestionValues(suggestionsArray);\n } else {\n suggestionClearHandler();\n }\n };\n\n /**\n * Executes the user callback adds the selection to the state and clears the suggestions.\n */\n const suggestionSelectedHandler: HvSuggestionsProps[\"onSuggestionSelected\"] =\n (event, item) => {\n const newValue = item.value || (item.label as any);\n\n changeInputValue(inputRef.current, newValue);\n\n focusInput();\n suggestionClearHandler();\n\n if (type === \"search\") {\n // trigger the onEnter callback when the user selects an option in a search box\n onEnter?.(event, newValue);\n }\n };\n\n const onChangeHandler: HvBaseInputProps[\"onChange\"] = (event, newValue) => {\n isDirty.current = true;\n\n // set the input value (only when value is uncontrolled)\n setValue(newValue);\n\n onChange?.(event, newValue);\n\n if (canShowSuggestions) {\n // an edge case might be a controlled input whose onChange callback\n // doesn't change the value (or sets another): the suggestionListCallback\n // callback will still receive the original rejected value.\n // a refactor is needed so the suggestionListCallback might be called only\n // when the input is uncontrolled, providing a way to externally control\n // the suggestion values.\n suggestionHandler(newValue);\n }\n };\n\n /**\n * Validates the input updating the state and modifying the info text, also executes\n * the user provided onBlur passing the current validation status and value.\n */\n const onInputBlurHandler: HvBaseInputProps[\"onBlur\"] = (event) => {\n // If the blur is executed when choosing an suggestion it should be ignored.\n if (eventTargetIsInsideContainer(suggestionsRef.current, event)) return;\n\n setFocused(false);\n\n const inputValidity = performValidation();\n\n onBlur?.(event, value, inputValidity);\n };\n\n /**\n * Updates the state putting again the value from the state because the input value is\n * not automatically manage, it also executes the onFocus function from the user passing the value\n */\n const onFocusHandler: HvBaseInputProps[\"onFocus\"] = (event) => {\n setFocused(true);\n\n // reset validation status to standBy (only when status is uncontrolled)\n setValidationState(validationStates.standBy);\n\n onFocus?.(event, value);\n };\n\n const getSuggestions = (li: number | null) => {\n // TODO Replace with ref\n const listEl = document.getElementById(\n setId(elementId, \"suggestions-list\") || \"\",\n );\n return li != null ? listEl?.getElementsByTagName(\"li\")?.[li] : listEl;\n };\n\n const onSuggestionKeyDown: HvSuggestionsProps[\"onKeyDown\"] = (event) => {\n if (isKey(event, \"Esc\")) {\n suggestionClearHandler();\n focusInput();\n } else if (isKey(event, \"Tab\")) {\n suggestionClearHandler();\n }\n };\n\n /** Focus the suggestion list when the arrow down is pressed. */\n const onKeyDownHandler: HvBaseInputProps[\"onKeyDown\"] = (event) => {\n if (isKey(event, \"ArrowDown\") && hasSuggestions) {\n const li = getSuggestions(0);\n li?.focus();\n } else if (isKey(event, \"Enter\")) {\n onEnter?.(event, value);\n }\n\n onKeyDown?.(event, value);\n };\n\n /** Clears the suggestion list on blur. */\n const onContainerBlurHandler: HvFormElementProps[\"onBlur\"] = (event) => {\n if (event.relatedTarget) {\n setTimeout(() => {\n const list = getSuggestions(null);\n if (!list?.contains(document.activeElement)) suggestionClearHandler();\n }, 10);\n }\n };\n\n const hasOnEnter = onEnter != null;\n\n // show the clear button only if the input is enabled, not read-only, disableClear is false and the input is not empty\n // also, don't show it when the input type is \"search\" and the input is active (standBy)\n const showClear =\n !disabled &&\n !readOnly &&\n !disableClear &&\n !isEmptyValue &&\n (!hasOnEnter ||\n type !== \"search\" ||\n disableSearchButton ||\n validationState !== validationStates.standBy);\n\n const showSearchIcon = type === \"search\" && !disableSearchButton;\n\n const showRevealPasswordButton =\n type === \"password\" && !disableRevealPassword;\n\n /**\n * Clears the input value from the state and refocus the input.\n */\n const handleClear = useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n // reset validation status to standBy (only when status is uncontrolled)\n setValidationState(validationStates.standBy);\n\n changeInputValue(inputRef.current, \"\");\n\n // prevent triggering the suggestions when clicking on the clear button when suggestOnFocus is true\n if (canShowSuggestions && suggestOnFocus) event.stopPropagation();\n else {\n // we want to focus the input when clicked and not active\n setTimeout(focusInput);\n }\n },\n [canShowSuggestions, setValidationState, suggestOnFocus],\n );\n\n const clearButton = useMemo(() => {\n if (!showClear) {\n return null;\n }\n\n return (\n <HvAdornment\n // Don't control visibility when the search icon is enabled\n className={cx(classes.adornmentButton, {\n [classes.iconClear]: !showSearchIcon,\n })}\n onClick={handleClear}\n aria-label={labels?.clearButtonLabel}\n aria-controls={setId(elementId, \"input\")}\n icon={<CloseXS />}\n />\n );\n }, [\n showClear,\n classes.adornmentButton,\n classes.iconClear,\n showSearchIcon,\n handleClear,\n labels?.clearButtonLabel,\n elementId,\n cx,\n ]);\n\n /**\n * Calls the onEnter callback and refocus the input.\n */\n const handleSearch = useCallback<NonNullable<HvAdornmentProps[\"onClick\"]>>(\n (event) => {\n onEnter?.(event, value);\n },\n [onEnter, value],\n );\n\n const searchButton = useMemo(() => {\n // If the search icon is not actionable, only show it when the input is empty or active\n const reallyShowIt =\n showSearchIcon &&\n (isEmptyValue ||\n (hasOnEnter && validationState === validationStates.standBy));\n\n if (!reallyShowIt) {\n return null;\n }\n\n return (\n <HvAdornment\n className={classes.adornmentButton}\n onClick={hasOnEnter ? handleSearch : undefined}\n aria-label={labels?.searchButtonLabel}\n icon={<Search />}\n />\n );\n }, [\n showSearchIcon,\n isEmptyValue,\n hasOnEnter,\n validationState,\n classes.adornmentButton,\n handleSearch,\n labels?.searchButtonLabel,\n ]);\n\n /**\n * Changes input type and refocus the input.\n */\n const handleRevealPassword = useCallback(() => {\n setRevealPassword(!revealPassword);\n }, [revealPassword]);\n\n const revealPasswordButton = useMemo(() => {\n if (!showRevealPasswordButton) {\n return null;\n }\n\n return (\n <HvTooltip\n disableFocusListener\n disableTouchListener\n title={\n revealPassword\n ? labels?.revealPasswordButtonClickToHideTooltip\n : labels?.revealPasswordButtonClickToShowTooltip\n }\n >\n <HvAdornment\n className={classes.adornmentButton}\n onClick={handleRevealPassword}\n aria-label={labels?.revealPasswordButtonLabel}\n aria-controls={setId(elementId, \"input\")}\n icon={revealPassword ? <PreviewOff /> : <Preview />}\n />\n </HvTooltip>\n );\n }, [\n showRevealPasswordButton,\n revealPassword,\n labels?.revealPasswordButtonClickToHideTooltip,\n labels?.revealPasswordButtonClickToShowTooltip,\n labels?.revealPasswordButtonLabel,\n classes.adornmentButton,\n handleRevealPassword,\n elementId,\n ]);\n\n const validationIcon = useMemo(() => {\n if (!showValidationIcon) {\n return null;\n }\n\n if (!isValid(validationState)) {\n return null;\n }\n\n return <Success color=\"positive\" className={classes.icon} />;\n }, [showValidationIcon, validationState, classes.icon]);\n\n // useMemo to avoid repetitive cloning of the custom icon\n const customIconEl = useMemo(\n () =>\n isValidElement(endAdornment) &&\n cloneElement(endAdornment as React.ReactElement, {\n className: cx(endAdornment.props.className, classes.icon),\n }),\n [classes.icon, endAdornment, cx],\n );\n\n const adornments = useMemo(() => {\n if (\n !clearButton &&\n !revealPasswordButton &&\n !searchButton &&\n !validationIcon &&\n !customIconEl\n )\n return null;\n\n // note: specification implies that the custom icon should be hidden when\n // a validation feedback icon is being shown.\n return (\n <div className={classes.adornmentsBox} aria-hidden=\"true\">\n {clearButton}\n {revealPasswordButton}\n {searchButton}\n {validationIcon || customIconEl}\n </div>\n );\n }, [\n classes.adornmentsBox,\n clearButton,\n customIconEl,\n revealPasswordButton,\n searchButton,\n validationIcon,\n ]);\n\n // run initial validation after first render\n // and also when any validation condition changes\n useEffect(() => {\n if (focused || (!isDirty.current && isEmptyValue)) {\n // skip validation if currently focused or if empty and\n // the user never manually edited the input value\n return;\n }\n\n performValidation();\n }, [focused, isEmptyValue, performValidation]);\n\n const errorMessageId = isStateInvalid\n ? canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage\n : undefined;\n\n return (\n <HvFormElement\n id={id}\n name={name}\n status={validationState}\n disabled={disabled}\n required={required}\n readOnly={readOnly}\n className={cx(\n classes.root,\n {\n [classes.hasSuggestions]: hasSuggestions,\n },\n className,\n )}\n onBlur={onContainerBlurHandler}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n id={setId(elementId, \"label\")}\n className={classes.label}\n htmlFor={setId(elementId, \"input\")}\n label={label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvBaseInput\n id={\n hasLabel || showClear || showRevealPasswordButton\n ? setId(elementId, \"input\")\n : setId(id, \"input\")\n }\n name={name}\n value={value}\n required={required}\n readOnly={readOnly}\n disabled={disabled}\n onChange={onChangeHandler}\n autoFocus={autoFocus}\n onKeyDown={onKeyDownHandler}\n onBlur={onInputBlurHandler}\n onFocus={onFocusHandler}\n placeholder={placeholder}\n type={realType}\n classes={{\n input: classes.input,\n inputRoot: classes.inputRoot,\n inputRootFocused: classes.inputRootFocused,\n inputRootDisabled: classes.inputRootDisabled,\n inputRootMultiline: classes.inputRootMultiline,\n inputBorderContainer: classes.inputBorderContainer,\n }}\n invalid={isStateInvalid}\n inputProps={{\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-invalid\": isStateInvalid ? true : undefined,\n \"aria-errormessage\": errorMessageId,\n \"aria-describedby\":\n ariaDescribedBy != null\n ? ariaDescribedBy\n : description\n ? setId(elementId, \"description\")\n : undefined,\n \"aria-controls\": canShowSuggestions\n ? setId(elementId, \"suggestions\")\n : undefined,\n\n ref: inputRef,\n\n // prevent browsers auto-fill/suggestions when we have our own\n autoComplete: canShowSuggestions ? \"off\" : undefined,\n\n onFocus: (event) => {\n inputProps.onFocus?.(event);\n\n // trigger suggestions when focusing the input\n if (canShowSuggestions && suggestOnFocus) {\n suggestionHandler(value);\n }\n },\n\n onClick: (event) => {\n inputProps.onClick?.(event);\n\n // prevent closing the suggestions when clicking on the input when suggestOnFocus is true\n if (canShowSuggestions && suggestOnFocus) event.stopPropagation();\n },\n\n ...inputProps,\n }}\n inputRef={forkedRef}\n endAdornment={adornments}\n {...others}\n />\n {canShowSuggestions && (\n <>\n {hasSuggestions && (\n <div role=\"presentation\" className={classes.inputExtension} />\n )}\n <HvSuggestions\n id={setId(elementId, \"suggestions\")}\n classes={{\n root: classes.suggestionsContainer,\n list: classes.suggestionList,\n }}\n expanded={hasSuggestions}\n anchorEl={inputRef.current?.parentElement}\n onClose={suggestionClearHandler}\n onKeyDown={onSuggestionKeyDown}\n onSuggestionSelected={suggestionSelectedHandler}\n suggestionValues={suggestionValues}\n enablePortal={enablePortal}\n popperProps={{ ref: suggestionsRef }}\n />\n </>\n )}\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n});\n"],"names":["HvInput"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkNA,MAAM,iBAAiB;AAAA;AAAA,EAErB,kBAAkB;AAAA;AAAA,EAElB,2BAA2B;AAAA;AAAA,EAE3B,wCAAwC;AAAA;AAAA,EAExC,wCAAwC;AAAA;AAAA,EAExC,mBAAmB;AACrB;AAIA,SAAS,6BACP,WACA,OACA;AACA,SAAO,CAAC,CAAC,WAAW,SAAS,MAAM,aAAa;AAClD;AAGA,MAAM,mBAAmB,CAAC,OAAgC,QAAQ,OAAO;AACvE,QAAM,QAAQ,IAAI,MAAM,SAAS,EAAE,SAAS,MAAM;AAGlD,QAAM,gBAAgB,OAAO;AAAA,IAC3B,OAAO,iBAAiB;AAAA,IACxB;AAAA,EAAA,GACC;AAEY,iBAAA,KAAK,OAAO,KAAK;AAChC,SAAO,cAAc,KAAK;AAC5B;AAKO,MAAM,UAAU,WAIrB,SAASA,SAAQ,OAAO,KAAK;AACvB,QAAA;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf,iBAAiB;AAAA,IACjB;AAAA,IACA,cAAc;AAAA,IACd,mBAAmB;AAAA,IACnB;AAAA,IACA,oBAAoB;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,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BAAiB,qBACb,MAAM,WAAW,aAAa,IAC9B;AAAA,cAEJ,KAAK;AAAA;AAAA,cAGL,cAAc,qBAAqB,QAAQ;AAAA,cAE3C,SAAS,CAAC,UAAU;AAClB,2BAAW,UAAU,KAAK;AAG1B,oBAAI,sBAAsB,gBAAgB;AACxC,oCAAkB,KAAK;AAAA,gBAAA;AAAA,cAE3B;AAAA,cAEA,SAAS,CAAC,UAAU;AAClB,2BAAW,UAAU,KAAK;AAGtB,oBAAA,sBAAsB,eAAgB,OAAM,gBAAgB;AAAA,cAClE;AAAA,cAEA,GAAG;AAAA,YACL;AAAA,YACA,UAAU;AAAA,YACV,cAAc;AAAA,YACb,GAAG;AAAA,UAAA;AAAA,QACN;AAAA,QACC,sBAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,UAAA,sCACE,OAAI,EAAA,MAAK,gBAAe,WAAW,QAAQ,gBAAgB;AAAA,UAE9D;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,IAAI,MAAM,WAAW,aAAa;AAAA,cAClC,SAAS;AAAA,gBACP,MAAM,QAAQ;AAAA,gBACd,MAAM,QAAQ;AAAA,cAChB;AAAA,cACA,UAAU;AAAA,cACV,UAAU,SAAS,SAAS;AAAA,cAC5B,SAAS;AAAA,cACT,WAAW;AAAA,cACX,sBAAsB;AAAA,cACtB;AAAA,cACA;AAAA,cACA,aAAa,EAAE,KAAK,eAAe;AAAA,YAAA;AAAA,UAAA;AAAA,QACrC,GACF;AAAA,QAED,gBACC;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,IAAI,MAAM,WAAW,OAAO;AAAA,YAC5B,eAAa;AAAA,YACb,WAAW,QAAQ;AAAA,YAElB,UAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAEJ;AAEJ,CAAC;"}
|
|
1
|
+
{"version":3,"file":"Input.js","sources":["../../../src/Input/Input.tsx"],"sourcesContent":["import {\n cloneElement,\n isValidElement,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport {\n CloseXS,\n Preview,\n PreviewOff,\n Search,\n Success,\n} from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseInput, HvBaseInputProps } from \"../BaseInput\";\nimport {\n computeValidationMessage,\n computeValidationState,\n computeValidationType,\n DEFAULT_ERROR_MESSAGES,\n hasBuiltInValidations,\n HvInputValidity,\n validateInput,\n} from \"../BaseInput/validations\";\nimport {\n HvAdornment,\n HvAdornmentProps,\n HvFormElement,\n HvFormElementProps,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvWarningText,\n isInvalid,\n isValid,\n validationStates,\n} from \"../FormElement\";\nimport {\n HvSuggestion,\n HvSuggestions,\n HvSuggestionsProps,\n} from \"../FormElement/Suggestions/Suggestions\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useIsMounted } from \"../hooks/useIsMounted\";\nimport { useLabels } from \"../hooks/useLabels\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvTooltip } from \"../Tooltip\";\nimport { fixedForwardRef } from \"../types/generic\";\nimport { isKey } from \"../utils/keyboardUtils\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./Input.styles\";\n\nexport { staticClasses as inputClasses };\n\nexport type HvInputClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvValidationMessages {\n /** The value when a validation fails. */\n error?: string;\n /** The message that appears when there are too many characters. */\n maxCharError?: string;\n /** The message that appears when there are too few characters. */\n minCharError?: string;\n /** The message that appears when the input is empty and required. */\n requiredError?: string;\n /** The message that appears when the input is value is incompatible with the expected type. */\n typeMismatchError?: string;\n}\n\nexport interface HvInputSuggestion {\n id: string;\n label: string;\n value?: string;\n}\n\nexport interface HvInputProps<\n InputElement extends HTMLElement = HTMLInputElement | HTMLTextAreaElement,\n> extends Omit<\n HvBaseInputProps,\n \"onChange\" | \"onBlur\" | \"onFocus\" | \"onKeyDown\"\n > {\n /** The form element name. */\n name?: string;\n /** The value of the form element. */\n value?: React.InputHTMLAttributes<InputElement>[\"value\"];\n /** When uncontrolled, defines the initial input value. */\n defaultValue?: React.InputHTMLAttributes<InputElement>[\"value\"];\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 inputted via inputProps.\n */\n label?: React.ReactNode;\n /** Provide additional descriptive text for the form element. */\n description?: React.ReactNode;\n /** Indicates that the form element is disabled. */\n disabled?: boolean;\n /** Indicates that the form element is not editable. */\n readOnly?: boolean;\n /** Indicates that user input is required on the form element. */\n required?: boolean;\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 `checked`, depending of the values of both `required` and `checked`.\n */\n status?: HvFormStatus;\n /** The error message to show when `status` is \"invalid\". */\n statusMessage?: string;\n /**\n * Callback called when the user submits the value by pressing Enter/Return.\n *\n * Also called when the search button is clicked (when type is \"search\").\n */\n /**\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 */\n onChange?: (event: React.ChangeEvent<InputElement>, value: string) => void;\n onEnter?: (\n event: React.KeyboardEvent<InputElement> | React.MouseEvent,\n value: string,\n ) => void;\n /**\n * The function that will be executed onBlur, allows checking the validation state,\n * it receives the value and the validation state.\n */\n onBlur?: (\n event: React.FocusEvent<InputElement>,\n value: string,\n validationState: HvInputValidity,\n ) => void;\n /**\n * The function that will be executed onBlur, allows checking the value state,\n * it receives the value.\n */\n onFocus?: (event: React.FocusEvent<InputElement>, value: string) => void;\n /**\n * The function that will be executed onKeyDown, allows checking the value state,\n * it receives the event and value.\n */\n onKeyDown?: (event: React.KeyboardEvent<InputElement>, value: string) => void;\n /** The input type. */\n type?: React.HTMLInputTypeAttribute;\n /** The placeholder value of the input. */\n placeholder?: string;\n /** Internal labels?. */\n labels?: HvInputLabels & Record<string, any>;\n /** An Object containing the various texts associated with the input. */\n validationMessages?: HvValidationMessages;\n /** The function that will be executed to received an array of objects that has a label and id to create list of suggestion */\n suggestionListCallback?: (value: string) => HvInputSuggestion[] | null;\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 /**\n * Whether the suggestions should be triggered once the input is focused and not only when typing.\n * @default false\n * */\n suggestOnFocus?: boolean;\n /**\n * The custom validation function, it receives the value and must return\n * either `true` for valid or `false` for invalid, default validations would only\n * occur if this function is null or undefined\n */\n validation?: (value: string) => boolean;\n /** If `true` it should autofocus. */\n autoFocus?: boolean;\n /** If `true` the clear button is disabled. */\n disableClear?: boolean; // TODO - rename in v6 since it doesn't disable but hides the button\n /** If `true` the reveal password button is disabled. Valid only when type is \"password\". */\n disableRevealPassword?: boolean; // TODO - rename in v6 since it doesn't disable but hides the button\n /** If `true` the search button is disabled. Valid only when type is \"search\". */\n disableSearchButton?: boolean; // TODO - rename in v6 since it doesn't disable but hides the button\n /**\n * If `true` the validation icon adornment is visible. Defaults to `false`.\n *\n * Currently, DS specifications define only a positive feedback icon;\n * errors are signaled through the border style and by displaying the error message.\n */\n showValidationIcon?: boolean;\n /** A custom icon to be added into the input. */\n endAdornment?: React.ReactNode;\n /** The maximum allowed length of the characters, if this value is null no check will be performed. */\n maxCharQuantity?: number;\n /** The minimum allowed length of the characters, if this value is null no check will be perform. */\n minCharQuantity?: number;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvInputClasses;\n}\n\nconst DEFAULT_LABELS = {\n /** The label of the clear button. */\n clearButtonLabel: \"Clear the text\",\n /** The label of the reveal password button. */\n revealPasswordButtonLabel: \"Reveal password\",\n /** The tooltip of the reveal password button when the password is hidden. */\n revealPasswordButtonClickToShowTooltip: \"Click to show password.\",\n /** The tooltip of the reveal password button when the password is revealed. */\n revealPasswordButtonClickToHideTooltip: \"Click to hide password.\",\n /** The label of the search button. */\n searchButtonLabel: \"Search\",\n};\n\nexport type HvInputLabels = Partial<typeof DEFAULT_LABELS>;\n\nfunction eventTargetIsInsideContainer(\n container: HTMLElement | null,\n event: React.FocusEvent<any>,\n) {\n return !!container?.contains(event.relatedTarget);\n}\n\n/** Changes a given `input`'s `value`, triggering its `onChange` */\nconst changeInputValue = (input: HTMLInputElement | null, value = \"\") => {\n const event = new Event(\"input\", { bubbles: true });\n\n /** Original `input.value` setter (React overrides it). */\n const setInputValue = Object.getOwnPropertyDescriptor(\n window.HTMLInputElement.prototype,\n \"value\",\n )?.set;\n\n setInputValue?.call(input, value);\n input?.dispatchEvent(event);\n};\n\n/**\n * A text input box is a graphical control element intended to enable the user to input text information to be used by the software.\n */\nexport const HvInput = fixedForwardRef(function HvInput<\n InputElement extends HTMLElement = HTMLInputElement | HTMLTextAreaElement,\n>(props: HvInputProps<InputElement>, ref: React.Ref<InputElement>) {\n const {\n classes: classesProp,\n className,\n id,\n name,\n value: valueProp,\n defaultValue = \"\",\n required,\n readOnly,\n disabled,\n enablePortal = false,\n suggestOnFocus = false,\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n onChange,\n onEnter,\n status,\n statusMessage,\n \"aria-errormessage\": ariaErrorMessage,\n type = \"text\",\n placeholder,\n autoFocus = false,\n labels: labelsProp,\n validationMessages,\n disableClear = false,\n disableRevealPassword = false,\n disableSearchButton = false,\n endAdornment,\n maxCharQuantity,\n minCharQuantity,\n validation,\n showValidationIcon = false,\n suggestionListCallback,\n inputRef: inputRefProp,\n onBlur,\n onFocus,\n onKeyDown,\n inputProps = {},\n ...others\n } = useDefaultProps(\"HvInput\", props);\n const { classes, cx } = useClasses(classesProp);\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n const elementId = useUniqueId(id);\n\n const inputRef = useRef<HTMLInputElement>(null);\n const forkedRef = useForkRef(ref, inputRef, inputRefProp);\n const suggestionsRef = useRef<HTMLDivElement>(null);\n\n const [focused, setFocused] = useState(false);\n\n // Signals that the user has manually edited the input value\n const isDirty = useRef(false);\n\n // Value related state\n const [value, setValue] = useControlled(valueProp, defaultValue);\n\n const isEmptyValue = value == null || value === \"\";\n\n // Validation related state\n const [validationState, setValidationState] = useControlled(\n status,\n validationStates.standBy,\n );\n\n const [validationMessage, setValidationMessage] = useControlled(\n statusMessage,\n \"\",\n );\n\n // validationMessages reference tends to change, as users will not memoize/useState for it;\n // dependencies must be more explicit so we set\n const errorMessages = useMemo(\n () => ({ ...DEFAULT_ERROR_MESSAGES, ...validationMessages }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n validationMessages?.error,\n validationMessages?.requiredError,\n validationMessages?.minCharError,\n validationMessages?.maxCharError,\n validationMessages?.typeMismatchError,\n ],\n );\n\n const validationType = useMemo(() => computeValidationType(type), [type]);\n\n // Validates the input, sets the status and the statusMessage accordingly (if uncontrolled)\n // and returns the validity state of the input.\n const performValidation = useCallback(() => {\n const inputValidity = validateInput(\n inputRef.current,\n String(value),\n required,\n minCharQuantity,\n maxCharQuantity,\n validationType,\n validation,\n );\n\n // This will only run if status is uncontrolled\n setValidationState(computeValidationState(inputValidity, isEmptyValue));\n\n // This will only run if statusMessage is uncontrolled\n setValidationMessage(\n computeValidationMessage(inputValidity, errorMessages),\n );\n\n return inputValidity;\n }, [\n errorMessages,\n isEmptyValue,\n maxCharQuantity,\n minCharQuantity,\n required,\n setValidationMessage,\n setValidationState,\n validation,\n validationType,\n value,\n ]);\n\n // The error message area will only be created if:\n // - an external element that provides an error message isn't identified via aria-errormessage AND\n // - both status and statusMessage properties are being controlled OR\n // - status is uncontrolled and any of the built-in validations are active\n const canShowError =\n ariaErrorMessage == null &&\n ((status !== undefined && statusMessage !== undefined) ||\n (status === undefined &&\n hasBuiltInValidations(\n required,\n validationType,\n minCharQuantity,\n maxCharQuantity,\n validation,\n inputProps,\n )));\n\n const isStateInvalid = isInvalid(validationState);\n\n // Input type related state\n const [revealPassword, setRevealPassword] = useState(false);\n\n const realType = useMemo(() => {\n if (type === \"password\") {\n return revealPassword ? \"text\" : \"password\";\n }\n\n if (type === \"search\") {\n return \"search\";\n }\n\n return \"text\";\n }, [revealPassword, type]);\n\n // Suggestions related state\n const [suggestionValues, setSuggestionValues] = useState<\n HvSuggestion[] | null\n >(null);\n\n const canShowSuggestions = suggestionListCallback != null;\n const hasSuggestions = !!suggestionValues;\n\n // Miscellaneous state\n const hasLabel = label != null;\n const hasDescription = description != null;\n\n /**\n * Looks for the node that represent the input inside the material tree and focus it.\n */\n const focusInput = () => {\n inputRef.current?.focus();\n };\n\n const isMounted = useIsMounted();\n\n /**\n * Clears the suggestion array.\n */\n const suggestionClearHandler = () => {\n if (isMounted.current) {\n setSuggestionValues(null);\n }\n };\n\n /**\n * Fills of the suggestion array.\n */\n const suggestionHandler = (val: string) => {\n const suggestionsArray = suggestionListCallback?.(val);\n if (suggestionsArray?.[0]?.label) {\n setSuggestionValues(suggestionsArray);\n } else {\n suggestionClearHandler();\n }\n };\n\n /**\n * Executes the user callback adds the selection to the state and clears the suggestions.\n */\n const suggestionSelectedHandler: HvSuggestionsProps[\"onSuggestionSelected\"] =\n (event, item) => {\n const newValue = item.value || (item.label as any);\n\n changeInputValue(inputRef.current, newValue);\n\n focusInput();\n suggestionClearHandler();\n\n if (type === \"search\") {\n // trigger the onEnter callback when the user selects an option in a search box\n onEnter?.(event, newValue);\n }\n };\n\n const onChangeHandler: HvBaseInputProps[\"onChange\"] = (event, newValue) => {\n isDirty.current = true;\n\n // set the input value (only when value is uncontrolled)\n setValue(newValue);\n\n onChange?.(event as any, newValue);\n\n if (canShowSuggestions) {\n // an edge case might be a controlled input whose onChange callback\n // doesn't change the value (or sets another): the suggestionListCallback\n // callback will still receive the original rejected value.\n // a refactor is needed so the suggestionListCallback might be called only\n // when the input is uncontrolled, providing a way to externally control\n // the suggestion values.\n suggestionHandler(newValue);\n }\n };\n\n /**\n * Validates the input updating the state and modifying the info text, also executes\n * the user provided onBlur passing the current validation status and value.\n */\n const onInputBlurHandler: HvBaseInputProps[\"onBlur\"] = (event) => {\n // If the blur is executed when choosing an suggestion it should be ignored.\n if (eventTargetIsInsideContainer(suggestionsRef.current, event)) return;\n\n setFocused(false);\n\n const inputValidity = performValidation();\n\n onBlur?.(event as any, String(value), inputValidity);\n };\n\n /**\n * Updates the state putting again the value from the state because the input value is\n * not automatically manage, it also executes the onFocus function from the user passing the value\n */\n const onFocusHandler: HvBaseInputProps[\"onFocus\"] = (event) => {\n setFocused(true);\n\n // reset validation status to standBy (only when status is uncontrolled)\n setValidationState(validationStates.standBy);\n\n onFocus?.(event as any, String(value));\n };\n\n const getSuggestions = (li: number | null) => {\n // TODO Replace with ref\n const listEl = document.getElementById(\n setId(elementId, \"suggestions-list\") || \"\",\n );\n return li != null ? listEl?.getElementsByTagName(\"li\")?.[li] : listEl;\n };\n\n const onSuggestionKeyDown: HvSuggestionsProps[\"onKeyDown\"] = (event) => {\n if (isKey(event, \"Esc\")) {\n suggestionClearHandler();\n focusInput();\n } else if (isKey(event, \"Tab\")) {\n suggestionClearHandler();\n }\n };\n\n /** Focus the suggestion list when the arrow down is pressed. */\n const onKeyDownHandler: HvBaseInputProps[\"onKeyDown\"] = (event) => {\n if (isKey(event, \"ArrowDown\") && hasSuggestions) {\n const li = getSuggestions(0);\n li?.focus();\n } else if (isKey(event, \"Enter\")) {\n onEnter?.(event as any, String(value));\n }\n\n onKeyDown?.(event as any, String(value));\n };\n\n /** Clears the suggestion list on blur. */\n const onContainerBlurHandler: HvFormElementProps[\"onBlur\"] = (event) => {\n if (event.relatedTarget) {\n setTimeout(() => {\n const list = getSuggestions(null);\n if (!list?.contains(document.activeElement)) suggestionClearHandler();\n }, 10);\n }\n };\n\n const hasOnEnter = onEnter != null;\n\n // show the clear button only if the input is enabled, not read-only, disableClear is false and the input is not empty\n // also, don't show it when the input type is \"search\" and the input is active (standBy)\n const showClear =\n !disabled &&\n !readOnly &&\n !disableClear &&\n !isEmptyValue &&\n (!hasOnEnter ||\n type !== \"search\" ||\n disableSearchButton ||\n validationState !== validationStates.standBy);\n\n const showSearchIcon = type === \"search\" && !disableSearchButton;\n\n const showRevealPasswordButton =\n type === \"password\" && !disableRevealPassword;\n\n /**\n * Clears the input value from the state and refocus the input.\n */\n const handleClear = useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n // reset validation status to standBy (only when status is uncontrolled)\n setValidationState(validationStates.standBy);\n\n changeInputValue(inputRef.current, \"\");\n\n // prevent triggering the suggestions when clicking on the clear button when suggestOnFocus is true\n if (canShowSuggestions && suggestOnFocus) event.stopPropagation();\n else {\n // we want to focus the input when clicked and not active\n setTimeout(focusInput);\n }\n },\n [canShowSuggestions, setValidationState, suggestOnFocus],\n );\n\n const clearButton = useMemo(() => {\n if (!showClear) {\n return null;\n }\n\n return (\n <HvAdornment\n // Don't control visibility when the search icon is enabled\n className={cx(classes.adornmentButton, {\n [classes.iconClear]: !showSearchIcon,\n })}\n onClick={handleClear}\n aria-label={labels?.clearButtonLabel}\n aria-controls={setId(elementId, \"input\")}\n icon={<CloseXS />}\n />\n );\n }, [\n showClear,\n classes.adornmentButton,\n classes.iconClear,\n showSearchIcon,\n handleClear,\n labels?.clearButtonLabel,\n elementId,\n cx,\n ]);\n\n /**\n * Calls the onEnter callback and refocus the input.\n */\n const handleSearch = useCallback<NonNullable<HvAdornmentProps[\"onClick\"]>>(\n (event) => {\n onEnter?.(event, String(value));\n },\n [onEnter, value],\n );\n\n const searchButton = useMemo(() => {\n // If the search icon is not actionable, only show it when the input is empty or active\n const reallyShowIt =\n showSearchIcon &&\n (isEmptyValue ||\n (hasOnEnter && validationState === validationStates.standBy));\n\n if (!reallyShowIt) {\n return null;\n }\n\n return (\n <HvAdornment\n className={classes.adornmentButton}\n onClick={hasOnEnter ? handleSearch : undefined}\n aria-label={labels?.searchButtonLabel}\n icon={<Search />}\n />\n );\n }, [\n showSearchIcon,\n isEmptyValue,\n hasOnEnter,\n validationState,\n classes.adornmentButton,\n handleSearch,\n labels?.searchButtonLabel,\n ]);\n\n /**\n * Changes input type and refocus the input.\n */\n const handleRevealPassword = useCallback(() => {\n setRevealPassword(!revealPassword);\n }, [revealPassword]);\n\n const revealPasswordButton = useMemo(() => {\n if (!showRevealPasswordButton) {\n return null;\n }\n\n return (\n <HvTooltip\n disableFocusListener\n disableTouchListener\n title={\n revealPassword\n ? labels?.revealPasswordButtonClickToHideTooltip\n : labels?.revealPasswordButtonClickToShowTooltip\n }\n >\n <HvAdornment\n className={classes.adornmentButton}\n onClick={handleRevealPassword}\n aria-label={labels?.revealPasswordButtonLabel}\n aria-controls={setId(elementId, \"input\")}\n icon={revealPassword ? <PreviewOff /> : <Preview />}\n />\n </HvTooltip>\n );\n }, [\n showRevealPasswordButton,\n revealPassword,\n labels?.revealPasswordButtonClickToHideTooltip,\n labels?.revealPasswordButtonClickToShowTooltip,\n labels?.revealPasswordButtonLabel,\n classes.adornmentButton,\n handleRevealPassword,\n elementId,\n ]);\n\n const validationIcon = useMemo(() => {\n if (!showValidationIcon) {\n return null;\n }\n\n if (!isValid(validationState)) {\n return null;\n }\n\n return <Success color=\"positive\" className={classes.icon} />;\n }, [showValidationIcon, validationState, classes.icon]);\n\n // useMemo to avoid repetitive cloning of the custom icon\n const customIconEl = useMemo(\n () =>\n isValidElement(endAdornment) &&\n cloneElement(endAdornment as React.ReactElement, {\n className: cx(endAdornment.props.className, classes.icon),\n }),\n [classes.icon, endAdornment, cx],\n );\n\n const adornments = useMemo(() => {\n if (\n !clearButton &&\n !revealPasswordButton &&\n !searchButton &&\n !validationIcon &&\n !customIconEl\n )\n return null;\n\n // note: specification implies that the custom icon should be hidden when\n // a validation feedback icon is being shown.\n return (\n <div className={classes.adornmentsBox} aria-hidden=\"true\">\n {clearButton}\n {revealPasswordButton}\n {searchButton}\n {validationIcon || customIconEl}\n </div>\n );\n }, [\n classes.adornmentsBox,\n clearButton,\n customIconEl,\n revealPasswordButton,\n searchButton,\n validationIcon,\n ]);\n\n // run initial validation after first render\n // and also when any validation condition changes\n useEffect(() => {\n if (focused || (!isDirty.current && isEmptyValue)) {\n // skip validation if currently focused or if empty and\n // the user never manually edited the input value\n return;\n }\n\n performValidation();\n }, [focused, isEmptyValue, performValidation]);\n\n const errorMessageId = isStateInvalid\n ? canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage\n : undefined;\n\n return (\n <HvFormElement\n id={id}\n name={name}\n status={validationState}\n disabled={disabled}\n required={required}\n readOnly={readOnly}\n className={cx(\n classes.root,\n {\n [classes.hasSuggestions]: hasSuggestions,\n },\n className,\n )}\n onBlur={onContainerBlurHandler}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n id={setId(elementId, \"label\")}\n className={classes.label}\n htmlFor={setId(elementId, \"input\")}\n label={label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvBaseInput\n id={\n hasLabel || showClear || showRevealPasswordButton\n ? setId(elementId, \"input\")\n : setId(id, \"input\")\n }\n name={name}\n value={value}\n required={required}\n readOnly={readOnly}\n disabled={disabled}\n onChange={onChangeHandler}\n autoFocus={autoFocus}\n onKeyDown={onKeyDownHandler}\n onBlur={onInputBlurHandler}\n onFocus={onFocusHandler}\n placeholder={placeholder}\n type={realType}\n classes={{\n input: classes.input,\n inputRoot: classes.inputRoot,\n inputRootFocused: classes.inputRootFocused,\n inputRootDisabled: classes.inputRootDisabled,\n inputRootMultiline: classes.inputRootMultiline,\n inputBorderContainer: classes.inputBorderContainer,\n }}\n invalid={isStateInvalid}\n inputProps={{\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-invalid\": isStateInvalid ? true : undefined,\n \"aria-errormessage\": errorMessageId,\n \"aria-describedby\":\n ariaDescribedBy != null\n ? ariaDescribedBy\n : description\n ? setId(elementId, \"description\")\n : undefined,\n \"aria-controls\": canShowSuggestions\n ? setId(elementId, \"suggestions\")\n : undefined,\n\n ref: inputRef,\n\n // prevent browsers auto-fill/suggestions when we have our own\n autoComplete: canShowSuggestions ? \"off\" : undefined,\n\n onFocus: (event) => {\n inputProps.onFocus?.(event);\n\n // trigger suggestions when focusing the input\n if (canShowSuggestions && suggestOnFocus) {\n suggestionHandler(String(value));\n }\n },\n\n onClick: (event) => {\n inputProps.onClick?.(event);\n\n // prevent closing the suggestions when clicking on the input when suggestOnFocus is true\n if (canShowSuggestions && suggestOnFocus) event.stopPropagation();\n },\n\n ...inputProps,\n }}\n inputRef={forkedRef}\n endAdornment={adornments}\n {...others}\n />\n {canShowSuggestions && (\n <>\n {hasSuggestions && (\n <div role=\"presentation\" className={classes.inputExtension} />\n )}\n <HvSuggestions\n id={setId(elementId, \"suggestions\")}\n classes={{\n root: classes.suggestionsContainer,\n list: classes.suggestionList,\n }}\n expanded={hasSuggestions}\n anchorEl={inputRef.current?.parentElement}\n onClose={suggestionClearHandler}\n onKeyDown={onSuggestionKeyDown}\n onSuggestionSelected={suggestionSelectedHandler}\n suggestionValues={suggestionValues}\n enablePortal={enablePortal}\n popperProps={{ ref: suggestionsRef }}\n />\n </>\n )}\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n});\n"],"names":["HvInput"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8MA,MAAM,iBAAiB;AAAA;AAAA,EAErB,kBAAkB;AAAA;AAAA,EAElB,2BAA2B;AAAA;AAAA,EAE3B,wCAAwC;AAAA;AAAA,EAExC,wCAAwC;AAAA;AAAA,EAExC,mBAAmB;AACrB;AAIA,SAAS,6BACP,WACA,OACA;AACA,SAAO,CAAC,CAAC,WAAW,SAAS,MAAM,aAAa;AAClD;AAGA,MAAM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,YAAC;AAAA,YAAA;AAAA,cACC,IAAI,MAAM,WAAW,aAAa;AAAA,cAClC,SAAS;AAAA,gBACP,MAAM,QAAQ;AAAA,gBACd,MAAM,QAAQ;AAAA,cAChB;AAAA,cACA,UAAU;AAAA,cACV,UAAU,SAAS,SAAS;AAAA,cAC5B,SAAS;AAAA,cACT,WAAW;AAAA,cACX,sBAAsB;AAAA,cACtB;AAAA,cACA;AAAA,cACA,aAAa,EAAE,KAAK,eAAe;AAAA,YAAA;AAAA,UAAA;AAAA,QACrC,GACF;AAAA,QAED,gBACC;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,IAAI,MAAM,WAAW,OAAO;AAAA,YAC5B,eAAa;AAAA,YACb,WAAW,QAAQ;AAAA,YAElB,UAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAEJ;AAEJ,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.js","sources":["../../../src/List/List.tsx"],"sourcesContent":["import {\n AriaRole,\n forwardRef,\n isValidElement,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { FixedSizeList } from \"react-window\";\nimport { DropRightXS } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvCheckBox } from \"../CheckBox\";\nimport { HvLink } from \"../Link\";\nimport {\n HvListContainer,\n HvListContainerProps,\n HvListItem,\n} from \"../ListContainer\";\nimport { HvOverflowTooltip } from \"../OverflowTooltip\";\nimport { HvRadio } from \"../Radio\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./List.styles\";\nimport { HvListLabels, HvListValue } from \"./types\";\nimport { useSelectableList } from \"./useSelectableList\";\nimport { parseList } from \"./utils\";\n\nexport { staticClasses as listClasses };\n\nexport type HvListClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvListProps\n extends HvBaseProps<HTMLUListElement, \"onChange\" | \"onClick\"> {\n /**\n * A list containing the elements to be rendered.\n *\n * - id: The id of the item.\n * - label: The label of the element to be rendered.\n * - selected: The selection state of the element.\n * - disabled: The disabled state of the element.\n * - isHidden: Is item visible.\n * - icon: The icon.\n * - showNavIcon: If true renders the navigation icon on the right.\n * - path: The path to navigate to.\n */\n values: HvListValue[];\n /** If true renders a multi select list. */\n multiSelect?: boolean;\n /**\n * If true renders select all option for multi selection lists with selectors.\n * note: It will only be rendered if multiSelect and useSelector props are set to true.\n */\n showSelectAll?: boolean;\n /** An object containing all the labels for the dropdown. */\n labels?: HvListLabels;\n /** If true renders list items with radio or checkbox selectors. */\n useSelector?: boolean;\n /** Call back fired when list item is selected. Returns selection state. */\n onChange?: (value: HvListValue[]) => void;\n /** Call back fired when list item is selected. Returns selected item. */\n onClick?: (\n event:\n | React.ChangeEvent<HTMLInputElement>\n | React.MouseEvent<HTMLLIElement>,\n value: HvListValue,\n ) => void;\n /** If `true` the list items will show the selection state. */\n selectable?: boolean;\n /** If `true`, selection can be toggled when single selection. */\n singleSelectionToggle?: boolean;\n /** If `true` the list will be rendered without vertical spacing. */\n condensed?: boolean;\n /** If `true` the dropdown will show tooltips when user mouseenter text in list. @deprecated this is always enabled */\n hasTooltips?: boolean;\n /** Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used */\n height?: number;\n /** Experimental. Uses dropdown in a virtualized form, where not all options are rendered initially. Good for use cases with a lot of options. */\n virtualized?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvListClasses;\n}\n\nconst DEFAULT_LABELS = {\n selectAll: \"Select All\",\n selectionConjunction: \"/\",\n};\n\n/**\n * Component used to show a set of related data to the user.\n */\nexport const HvList = (props: HvListProps) => {\n const {\n id,\n classes: classesProp,\n className,\n multiSelect = false,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n hasTooltips = false,\n showSelectAll = false,\n labels = DEFAULT_LABELS,\n useSelector = false,\n selectable = true,\n singleSelectionToggle = true,\n condensed = false,\n onChange,\n onClick,\n values: valuesProp = [],\n height,\n virtualized = false,\n ...others\n } = useDefaultProps(\"HvList\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const [list, setList, selection] = useSelectableList(valuesProp);\n const listRef = useRef<any>(null);\n\n useEffect(() => {\n const passedProps = { multiSelect, selectable, singleSelectionToggle };\n const parsedList: HvListValue[] = parseList(\n undefined,\n passedProps,\n undefined,\n valuesProp,\n );\n\n setList(parsedList);\n }, [valuesProp, multiSelect, selectable, singleSelectionToggle, setList]);\n\n const [role, itemRole] = useMemo<[AriaRole, AriaRole]>(() => {\n // selectors are responsible for the role & selection state\n if (selectable && useSelector) return [\"list\", \"listitem\"];\n\n if (selectable) return [\"listbox\", \"option\"];\n return [\"menu\", \"menuitem\"];\n }, [selectable, useSelector]);\n\n const handleSelect = (\n evt: React.ChangeEvent<HTMLInputElement> | React.MouseEvent<HTMLLIElement>,\n item: HvListValue,\n ) => {\n if (!item.path) evt.preventDefault();\n if (item.disabled) return;\n\n const passedProps = { multiSelect, selectable, singleSelectionToggle };\n const parsedList = parseList(item, passedProps, undefined, list);\n setList(parsedList);\n\n onClick?.(evt, item);\n onChange?.(parsedList);\n };\n\n const handleSelectAll = () => {\n const passedProps = { multiSelect, selectable, singleSelectionToggle };\n const anySelectableSelected = list.some(\n (elem) => elem.selected || elem.disabled,\n );\n const parsedList = parseList(\n undefined,\n passedProps,\n !anySelectableSelected,\n list,\n );\n setList(parsedList);\n\n onChange?.(parsedList);\n };\n\n const renderLeftIcon = (item: HvListValue) => {\n return isValidElement(item.icon)\n ? item.icon\n : typeof item.icon === \"function\"\n ? item.icon?.({\n isSelected: item.selected,\n isDisabled: item.disabled,\n })\n : null;\n };\n\n const renderSelectAll = () => {\n const { selectAll, selectionConjunction } = labels;\n\n const anySelected = !!selection?.length;\n const allSelected = selection.length === list.length;\n\n const selectionLabel = (\n <HvTypography component=\"span\">\n {!anySelected ? (\n <>\n <b>{selectAll}</b>\n {` (${list.length})`}\n </>\n ) : (\n <>\n <b>{selection.length}</b>\n {`\\xa0${selectionConjunction}\\xa0`}\n {list.length}\n </>\n )}\n </HvTypography>\n );\n\n return (\n <HvCheckBox\n id={setId(id, \"select-all\")}\n label={selectionLabel}\n onChange={handleSelectAll}\n className={classes.selectAllSelector}\n indeterminate={anySelected && !allSelected}\n checked={allSelected}\n />\n );\n };\n\n const renderItemText = (item: HvListValue) => {\n return !multiSelect && item.path ? (\n <HvLink route={item.path} classes={{ a: classes.link }}>\n <HvOverflowTooltip data={item.label} />\n </HvLink>\n ) : (\n <HvOverflowTooltip data={item.label} />\n );\n };\n\n const renderSelectItem = (item: HvListValue, itemId?: string) => {\n if (!useSelector) return renderItemText(item);\n\n const Component = multiSelect ? HvCheckBox : HvRadio;\n\n return (\n <Component\n id={setId(itemId, \"selector\")}\n label={<HvOverflowTooltip data={item.label} />}\n checked={item.selected || false}\n disabled={item.disabled}\n onChange={multiSelect ? (evt) => handleSelect(evt, item) : undefined}\n classes={{\n root: classes.selectorRoot,\n container: classes.selectorContainer,\n label: classes.truncate,\n }}\n />\n );\n };\n\n const renderListItem = (item: HvListValue, i: number, otherProps = {}) => {\n const itemId = setId(id, \"item\", i);\n const selected = item.selected || false;\n\n const startAdornment =\n !useSelector && item.icon ? renderLeftIcon(item) : null;\n\n return (\n <HvListItem\n key={i}\n id={itemId}\n role={itemRole}\n disabled={item.disabled || undefined}\n className={classes.item}\n classes={{\n selected: cx({\n [classes.itemSelector]: useSelector || multiSelect,\n }),\n }}\n selected={multiSelect || selected ? selected : undefined}\n onClick={(evt) => handleSelect(evt, item)}\n startAdornment={startAdornment}\n endAdornment={\n item.showNavIcon && (\n <DropRightXS className={classes.box} iconSize=\"XS\" />\n )\n }\n {...otherProps}\n >\n {renderSelectItem(item, itemId)}\n </HvListItem>\n );\n };\n\n const filteredList = list.filter((it) => !it.isHidden);\n const anySelected = list\n .map((item) => item.selected && !item.disabled)\n .reduce((result, selected) => result || selected, false);\n\n const selectedItemIndex = list.findIndex((item) => item.selected);\n useEffect(() => {\n if (selectedItemIndex >= 0 && listRef.current !== null) {\n listRef.current.scrollToItem(selectedItemIndex);\n }\n }, [listRef, selectedItemIndex]);\n\n const renderVirtualizedListItem = ({\n index,\n style,\n }: {\n index: number;\n style: Record<string, any>;\n }) => {\n const item = filteredList[index];\n const tabIndex =\n item.tabIndex ||\n (!anySelected && index === 0) ||\n (item.selected && !item.disabled)\n ? 0\n : -1;\n\n return renderListItem(item, index, {\n style: {\n ...style,\n top: `${parseFloat(style.top) + 5}px`,\n left: `${parseFloat(style.left) + 5}px`,\n width: `calc(${parseFloat(style.width)}% - 10px)`,\n },\n tabIndex,\n interactive: true,\n condensed,\n disableGutters: useSelector,\n });\n };\n\n const ariaMultiSelectable = (role === \"listbox\" && multiSelect) || undefined;\n\n const ListContainer = useMemo(() => {\n return forwardRef<HTMLUListElement, HvListContainerProps>(\n ({ ...rest }, ref) => (\n <HvListContainer\n id={id}\n className={cx(classes.root, className)}\n role={role}\n interactive\n condensed={condensed}\n disableGutters={useSelector}\n aria-multiselectable={ariaMultiSelectable}\n ref={ref}\n {...rest}\n />\n ),\n );\n }, [\n cx,\n id,\n useSelector,\n className,\n classes.root,\n role,\n condensed,\n ariaMultiSelectable,\n ]);\n\n // Render nothing if there are no items\n if (filteredList.length === 0) return null;\n\n return (\n <>\n {multiSelect && useSelector && showSelectAll && renderSelectAll()}\n\n {!virtualized ? (\n <HvListContainer\n id={id}\n className={cx(classes.root, className)}\n role={role}\n interactive\n condensed={condensed}\n disableGutters={useSelector}\n aria-multiselectable={ariaMultiSelectable}\n {...others}\n >\n {filteredList.map((item, i) => renderListItem(item, i))}\n </HvListContainer>\n ) : (\n <FixedSizeList\n ref={listRef}\n className={classes.virtualizedRoot}\n height={(height || 0) + 5}\n width=\"100%\"\n itemCount={filteredList.length}\n itemSize={condensed ? 32 : 40}\n innerElementType={ListContainer}\n {...(others as any)}\n >\n {renderVirtualizedListItem}\n </FixedSizeList>\n )}\n </>\n );\n};\n"],"names":["anySelected"],"mappings":";;;;;;;;;;;;;;;;;AAuFA,MAAM,iBAAiB;AAAA,EACrB,WAAW;AAAA,EACX,sBAAsB;AACxB;AAKa,MAAA,SAAS,CAAC,UAAuB;AACtC,QAAA;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA,cAAc;AAAA;AAAA,IAEd,cAAc;AAAA,IACd,gBAAgB;AAAA,IAChB,SAAS;AAAA,IACT,cAAc;AAAA,IACd,aAAa;AAAA,IACb,wBAAwB;AAAA,IACxB,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,QAAQ,aAAa,CAAC;AAAA,IACtB;AAAA,IACA,cAAc;AAAA,IACd,GAAG;AAAA,EAAA,IACD,gBAAgB,UAAU,KAAK;AAEnC,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAE9C,QAAM,CAAC,MAAM,SAAS,SAAS,IAAI,kBAAkB,UAAU;AACzD,QAAA,UAAU,OAAY,IAAI;AAEhC,YAAU,MAAM;AACd,UAAM,cAAc,EAAE,aAAa,YAAY,sBAAsB;AACrE,UAAM,aAA4B;AAAA,MAChC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,YAAQ,UAAU;AAAA,EAAA,GACjB,CAAC,YAAY,aAAa,YAAY,uBAAuB,OAAO,CAAC;AAExE,QAAM,CAAC,MAAM,QAAQ,IAAI,QAA8B,MAAM;AAE3D,QAAI,cAAc,YAAoB,QAAA,CAAC,QAAQ,UAAU;AAEzD,QAAI,WAAY,QAAO,CAAC,WAAW,QAAQ;AACpC,WAAA,CAAC,QAAQ,UAAU;AAAA,EAAA,GACzB,CAAC,YAAY,WAAW,CAAC;AAEtB,QAAA,eAAe,CACnB,KACA,SACG;AACH,QAAI,CAAC,KAAK,KAAM,KAAI,eAAe;AACnC,QAAI,KAAK,SAAU;AAEnB,UAA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1
|
+
{"version":3,"file":"List.js","sources":["../../../src/List/List.tsx"],"sourcesContent":["import {\n AriaRole,\n forwardRef,\n isValidElement,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { FixedSizeList } from \"react-window\";\nimport { DropRightXS } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvCheckBox } from \"../CheckBox\";\nimport { HvLink } from \"../Link\";\nimport {\n HvListContainer,\n HvListContainerProps,\n HvListItem,\n} from \"../ListContainer\";\nimport { HvOverflowTooltip } from \"../OverflowTooltip\";\nimport { HvRadio } from \"../Radio\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./List.styles\";\nimport { HvListLabels, HvListValue } from \"./types\";\nimport { useSelectableList } from \"./useSelectableList\";\nimport { parseList } from \"./utils\";\n\nexport { staticClasses as listClasses };\n\nexport type HvListClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvListProps\n extends HvBaseProps<HTMLUListElement, \"onChange\" | \"onClick\"> {\n /**\n * A list containing the elements to be rendered.\n *\n * - id: The id of the item.\n * - label: The label of the element to be rendered.\n * - selected: The selection state of the element.\n * - disabled: The disabled state of the element.\n * - isHidden: Is item visible.\n * - icon: The icon.\n * - showNavIcon: If true renders the navigation icon on the right.\n * - path: The path to navigate to.\n */\n values: HvListValue[];\n /** If true renders a multi select list. */\n multiSelect?: boolean;\n /**\n * If true renders select all option for multi selection lists with selectors.\n * note: It will only be rendered if multiSelect and useSelector props are set to true.\n */\n showSelectAll?: boolean;\n /** An object containing all the labels for the dropdown. */\n labels?: HvListLabels;\n /** If true renders list items with radio or checkbox selectors. */\n useSelector?: boolean;\n /** Call back fired when list item is selected. Returns selection state. */\n onChange?: (value: HvListValue[]) => void;\n /** Call back fired when list item is selected. Returns selected item. */\n onClick?: (\n event:\n | React.ChangeEvent<HTMLInputElement>\n | React.MouseEvent<HTMLLIElement>,\n value: HvListValue,\n ) => void;\n /** If `true` the list items will show the selection state. */\n selectable?: boolean;\n /** If `true`, selection can be toggled when single selection. */\n singleSelectionToggle?: boolean;\n /** If `true` the list will be rendered without vertical spacing. */\n condensed?: boolean;\n /** If `true` the dropdown will show tooltips when user mouseenter text in list. @deprecated this is always enabled */\n hasTooltips?: boolean;\n /** Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used */\n height?: number;\n /** Experimental. Uses dropdown in a virtualized form, where not all options are rendered initially. Good for use cases with a lot of options. */\n virtualized?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvListClasses;\n}\n\nconst DEFAULT_LABELS = {\n selectAll: \"Select All\",\n selectionConjunction: \"/\",\n};\n\n/**\n * Component used to show a set of related data to the user.\n */\nexport const HvList = (props: HvListProps) => {\n const {\n id,\n classes: classesProp,\n className,\n multiSelect = false,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n hasTooltips = false,\n showSelectAll = false,\n labels = DEFAULT_LABELS,\n useSelector = false,\n selectable = true,\n singleSelectionToggle = true,\n condensed = false,\n onChange,\n onClick,\n values: valuesProp = [],\n height,\n virtualized = false,\n ...others\n } = useDefaultProps(\"HvList\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const [list, setList, selection] = useSelectableList(valuesProp);\n const listRef = useRef<any>(null);\n\n useEffect(() => {\n const passedProps = { multiSelect, selectable, singleSelectionToggle };\n const parsedList: HvListValue[] = parseList(\n undefined,\n passedProps,\n undefined,\n valuesProp,\n );\n\n setList(parsedList);\n }, [valuesProp, multiSelect, selectable, singleSelectionToggle, setList]);\n\n const [role, itemRole] = useMemo<[AriaRole, AriaRole]>(() => {\n // selectors are responsible for the role & selection state\n if (selectable && useSelector) return [\"list\", \"listitem\"];\n\n if (selectable) return [\"listbox\", \"option\"];\n return [\"menu\", \"menuitem\"];\n }, [selectable, useSelector]);\n\n const handleSelect = (\n evt: React.ChangeEvent<HTMLInputElement> | React.MouseEvent<HTMLLIElement>,\n item: HvListValue,\n ) => {\n if (!item.path) evt.preventDefault();\n if (item.disabled) return;\n\n const passedProps = { multiSelect, selectable, singleSelectionToggle };\n const parsedList = parseList(item, passedProps, undefined, list);\n setList(parsedList);\n\n onClick?.(evt, item);\n onChange?.(parsedList);\n };\n\n const handleSelectAll = () => {\n const passedProps = { multiSelect, selectable, singleSelectionToggle };\n const anySelectableSelected = list.some(\n (elem) => elem.selected || elem.disabled,\n );\n const parsedList = parseList(\n undefined,\n passedProps,\n !anySelectableSelected,\n list,\n );\n setList(parsedList);\n\n onChange?.(parsedList);\n };\n\n const renderLeftIcon = (item: HvListValue) => {\n return isValidElement(item.icon)\n ? item.icon\n : typeof item.icon === \"function\"\n ? item.icon?.({\n isSelected: item.selected,\n isDisabled: item.disabled,\n })\n : null;\n };\n\n const renderSelectAll = () => {\n const { selectAll, selectionConjunction } = labels;\n\n const anySelected = !!selection?.length;\n const allSelected = selection.length === list.length;\n\n const selectionLabel = (\n <HvTypography component=\"span\">\n {!anySelected ? (\n <>\n <b>{selectAll}</b>\n {` (${list.length})`}\n </>\n ) : (\n <>\n <b>{selection.length}</b>\n {`\\xa0${selectionConjunction}\\xa0`}\n {list.length}\n </>\n )}\n </HvTypography>\n );\n\n return (\n <HvCheckBox\n id={setId(id, \"select-all\")}\n label={selectionLabel}\n onChange={handleSelectAll}\n className={classes.selectAllSelector}\n indeterminate={anySelected && !allSelected}\n checked={allSelected}\n />\n );\n };\n\n const renderItemText = (item: HvListValue) => {\n return !multiSelect && item.path ? (\n <HvLink route={item.path} classes={{ a: classes.link }}>\n <HvOverflowTooltip data={item.label} />\n </HvLink>\n ) : (\n <HvOverflowTooltip data={item.label} />\n );\n };\n\n const renderSelectItem = (item: HvListValue, itemId?: string) => {\n if (!useSelector) return renderItemText(item);\n\n const Component = multiSelect ? HvCheckBox : HvRadio;\n\n return (\n <Component\n id={setId(itemId, \"selector\")}\n label={<HvOverflowTooltip data={item.label} />}\n checked={item.selected || false}\n disabled={item.disabled}\n onChange={multiSelect ? (evt) => handleSelect(evt, item) : undefined}\n classes={{\n root: classes.selectorRoot,\n container: classes.selectorContainer,\n label: classes.truncate,\n }}\n />\n );\n };\n\n const renderListItem = (item: HvListValue, i: number, otherProps = {}) => {\n const itemId = setId(id, \"item\", i);\n const selected = item.selected || false;\n\n const startAdornment =\n !useSelector && item.icon ? renderLeftIcon(item) : null;\n\n return (\n <HvListItem\n key={i}\n id={itemId}\n role={itemRole}\n disabled={item.disabled || undefined}\n className={classes.item}\n classes={{\n selected: cx({\n [classes.itemSelector]: useSelector || multiSelect,\n }),\n }}\n selected={multiSelect || selected ? selected : undefined}\n onClick={(evt) => handleSelect(evt, item)}\n startAdornment={startAdornment}\n endAdornment={\n item.showNavIcon && (\n <DropRightXS className={classes.box} iconSize=\"XS\" />\n )\n }\n {...otherProps}\n >\n {renderSelectItem(item, itemId)}\n </HvListItem>\n );\n };\n\n const filteredList = list.filter((it) => !it.isHidden);\n const anySelected = list\n .map((item) => item.selected && !item.disabled)\n .reduce((result, selected) => result || selected, false);\n\n const selectedItemIndex = list.findIndex((item) => item.selected);\n useEffect(() => {\n if (selectedItemIndex >= 0 && listRef.current !== null) {\n listRef.current.scrollToItem(selectedItemIndex);\n }\n }, [listRef, selectedItemIndex]);\n\n const renderVirtualizedListItem = ({\n index,\n style,\n }: {\n index: number;\n style: Record<string, any>;\n }) => {\n const item = filteredList[index];\n const tabIndex =\n item.tabIndex ||\n (!anySelected && index === 0) ||\n (item.selected && !item.disabled)\n ? 0\n : -1;\n\n return renderListItem(item, index, {\n style: {\n ...style,\n top: `${parseFloat(style.top) + 5}px`,\n left: `${parseFloat(style.left) + 5}px`,\n width: `calc(${parseFloat(style.width)}% - 10px)`,\n },\n tabIndex,\n interactive: true,\n condensed,\n disableGutters: useSelector,\n });\n };\n\n const ariaMultiSelectable = (role === \"listbox\" && multiSelect) || undefined;\n\n const ListContainer = useMemo(() => {\n // eslint-disable-next-line react/display-name\n return forwardRef<HTMLUListElement, HvListContainerProps>(\n ({ ...rest }, ref) => (\n <HvListContainer\n id={id}\n className={cx(classes.root, className)}\n role={role}\n interactive\n condensed={condensed}\n disableGutters={useSelector}\n aria-multiselectable={ariaMultiSelectable}\n ref={ref}\n {...rest}\n />\n ),\n );\n }, [\n cx,\n id,\n useSelector,\n className,\n classes.root,\n role,\n condensed,\n ariaMultiSelectable,\n ]);\n\n // Render nothing if there are no items\n if (filteredList.length === 0) return null;\n\n return (\n <>\n {multiSelect && useSelector && showSelectAll && renderSelectAll()}\n\n {!virtualized ? (\n <HvListContainer\n id={id}\n className={cx(classes.root, className)}\n role={role}\n interactive\n condensed={condensed}\n disableGutters={useSelector}\n aria-multiselectable={ariaMultiSelectable}\n {...others}\n >\n {filteredList.map((item, i) => renderListItem(item, i))}\n </HvListContainer>\n ) : (\n <FixedSizeList\n ref={listRef}\n className={classes.virtualizedRoot}\n height={(height || 0) + 5}\n width=\"100%\"\n itemCount={filteredList.length}\n itemSize={condensed ? 32 : 40}\n innerElementType={ListContainer}\n {...(others as any)}\n >\n {renderVirtualizedListItem}\n </FixedSizeList>\n )}\n </>\n );\n};\n"],"names":["anySelected"],"mappings":";;;;;;;;;;;;;;;;;AAuFA,MAAM,iBAAiB;AAAA,EACrB,WAAW;AAAA,EACX,sBAAsB;AACxB;AAKa,MAAA,SAAS,CAAC,UAAuB;AACtC,QAAA;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA,cAAc;AAAA;AAAA,IAEd,cAAc;AAAA,IACd,gBAAgB;AAAA,IAChB,SAAS;AAAA,IACT,cAAc;AAAA,IACd,aAAa;AAAA,IACb,wBAAwB;AAAA,IACxB,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,QAAQ,aAAa,CAAC;AAAA,IACtB;AAAA,IACA,cAAc;AAAA,IACd,GAAG;AAAA,EAAA,IACD,gBAAgB,UAAU,KAAK;AA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W,EAAU,QAAA;AAEtC,SAEK,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAe,eAAA,eAAe,iBAAiB,gBAAgB;AAAA,IAE/D,CAAC,cACA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAW,GAAG,QAAQ,MAAM,SAAS;AAAA,QACrC;AAAA,QACA,aAAW;AAAA,QACX;AAAA,QACA,gBAAgB;AAAA,QAChB,wBAAsB;AAAA,QACrB,GAAG;AAAA,QAEH,UAAA,aAAa,IAAI,CAAC,MAAM,MAAM,eAAe,MAAM,CAAC,CAAC;AAAA,MAAA;AAAA,IAAA,IAGxD;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,KAAK;AAAA,QACL,WAAW,QAAQ;AAAA,QACnB,SAAS,UAAU,KAAK;AAAA,QACxB,OAAM;AAAA,QACN,WAAW,aAAa;AAAA,QACxB,UAAU,YAAY,KAAK;AAAA,QAC3B,kBAAkB;AAAA,QACjB,GAAI;AAAA,QAEJ,UAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACH,GAEJ;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListContext.js","sources":["../../../../src/ListContainer/ListContext/ListContext.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"ListContext.js","sources":["../../../../src/ListContainer/ListContext/ListContext.ts"],"sourcesContent":["import { createContext } from \"react\";\n\nconst ListContext = createContext<{\n interactive?: boolean;\n nesting?: number;\n condensed?: boolean;\n selectable?: boolean;\n disableGutters?: boolean;\n topContainerRef?: React.MutableRefObject<HTMLUListElement | null>;\n}>({});\n\nListContext.displayName = \"ListContext\";\n\nexport default ListContext;\n"],"names":[],"mappings":";AAEM,MAAA,cAAc,cAOjB,CAAE,CAAA;AAEL,YAAY,cAAc;"}
|