@hitachivantara/uikit-react-core 5.66.6 → 5.66.7

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.
Files changed (70) hide show
  1. package/dist/cjs/BaseDropdown/BaseDropdown.cjs +259 -241
  2. package/dist/cjs/BaseDropdown/BaseDropdownContext/BaseDropdownContext.cjs +6 -3
  3. package/dist/cjs/Button/Button.cjs +10 -2
  4. package/dist/cjs/Button/Button.styles.cjs +1 -1
  5. package/dist/cjs/Calendar/SingleCalendar/SingleCalendar.styles.cjs +0 -1
  6. package/dist/cjs/ColorPicker/ColorPicker.styles.cjs +2 -1
  7. package/dist/cjs/DropDownMenu/DropDownMenu.cjs +22 -5
  8. package/dist/cjs/DropDownMenu/DropDownMenu.styles.cjs +3 -1
  9. package/dist/cjs/Dropdown/List/List.cjs +2 -2
  10. package/dist/cjs/InlineEditor/InlineEditor.cjs +1 -1
  11. package/dist/cjs/MultiButton/MultiButton.styles.cjs +1 -6
  12. package/dist/cjs/TagsInput/TagsInput.cjs +1 -1
  13. package/dist/cjs/TimePicker/TimePicker.styles.cjs +0 -1
  14. package/dist/cjs/TreeView/TreeItem/TreeItem.cjs +2 -2
  15. package/dist/cjs/TreeView/TreeItem/TreeItem.styles.cjs +5 -3
  16. package/dist/cjs/TreeView/TreeItem/useHvTreeItem.cjs +23 -0
  17. package/dist/cjs/TreeView/internals/DescendantProvider.cjs +12 -16
  18. package/dist/cjs/VerticalNavigation/TreeView/TreeView.cjs +17 -24
  19. package/dist/cjs/VerticalNavigation/TreeView/TreeViewItem.cjs +4 -4
  20. package/dist/esm/BaseDropdown/BaseDropdown.js +261 -243
  21. package/dist/esm/BaseDropdown/BaseDropdown.js.map +1 -1
  22. package/dist/esm/BaseDropdown/BaseDropdownContext/BaseDropdownContext.js +8 -3
  23. package/dist/esm/BaseDropdown/BaseDropdownContext/BaseDropdownContext.js.map +1 -1
  24. package/dist/esm/Button/Button.js +11 -3
  25. package/dist/esm/Button/Button.js.map +1 -1
  26. package/dist/esm/Button/Button.styles.js +1 -1
  27. package/dist/esm/Button/Button.styles.js.map +1 -1
  28. package/dist/esm/Calendar/SingleCalendar/SingleCalendar.styles.js +0 -1
  29. package/dist/esm/Calendar/SingleCalendar/SingleCalendar.styles.js.map +1 -1
  30. package/dist/esm/CheckBox/CheckBox.js.map +1 -1
  31. package/dist/esm/CheckBoxGroup/CheckBoxGroup.js.map +1 -1
  32. package/dist/esm/ColorPicker/ColorPicker.styles.js +2 -1
  33. package/dist/esm/ColorPicker/ColorPicker.styles.js.map +1 -1
  34. package/dist/esm/DatePicker/DatePicker.js.map +1 -1
  35. package/dist/esm/DropDownMenu/DropDownMenu.js +23 -6
  36. package/dist/esm/DropDownMenu/DropDownMenu.js.map +1 -1
  37. package/dist/esm/DropDownMenu/DropDownMenu.styles.js +3 -1
  38. package/dist/esm/DropDownMenu/DropDownMenu.styles.js.map +1 -1
  39. package/dist/esm/Dropdown/Dropdown.js.map +1 -1
  40. package/dist/esm/Dropdown/List/List.js +3 -3
  41. package/dist/esm/Dropdown/List/List.js.map +1 -1
  42. package/dist/esm/InlineEditor/InlineEditor.js +1 -1
  43. package/dist/esm/InlineEditor/InlineEditor.js.map +1 -1
  44. package/dist/esm/MultiButton/MultiButton.styles.js +1 -6
  45. package/dist/esm/MultiButton/MultiButton.styles.js.map +1 -1
  46. package/dist/esm/SelectionList/SelectionList.js.map +1 -1
  47. package/dist/esm/Switch/Switch.js.map +1 -1
  48. package/dist/esm/TagsInput/TagsInput.js +1 -1
  49. package/dist/esm/TagsInput/TagsInput.js.map +1 -1
  50. package/dist/esm/TimePicker/TimePicker.js.map +1 -1
  51. package/dist/esm/TimePicker/TimePicker.styles.js +0 -1
  52. package/dist/esm/TimePicker/TimePicker.styles.js.map +1 -1
  53. package/dist/esm/TreeView/TreeItem/TreeItem.js +2 -2
  54. package/dist/esm/TreeView/TreeItem/TreeItem.js.map +1 -1
  55. package/dist/esm/TreeView/TreeItem/TreeItem.styles.js +5 -3
  56. package/dist/esm/TreeView/TreeItem/TreeItem.styles.js.map +1 -1
  57. package/dist/esm/TreeView/TreeItem/useHvTreeItem.js +4 -0
  58. package/dist/esm/TreeView/TreeItem/useHvTreeItem.js.map +1 -1
  59. package/dist/esm/TreeView/internals/DescendantProvider.js +12 -16
  60. package/dist/esm/TreeView/internals/DescendantProvider.js.map +1 -1
  61. package/dist/esm/VerticalNavigation/TreeView/TreeView.js +16 -23
  62. package/dist/esm/VerticalNavigation/TreeView/TreeView.js.map +1 -1
  63. package/dist/esm/VerticalNavigation/TreeView/TreeViewItem.js +2 -2
  64. package/dist/esm/VerticalNavigation/TreeView/TreeViewItem.js.map +1 -1
  65. package/dist/esm/hooks/useControlled.js.map +1 -1
  66. package/dist/types/index.d.ts +15 -11
  67. package/package.json +5 -5
  68. package/dist/cjs/VerticalNavigation/TreeView/descendants.cjs +0 -125
  69. package/dist/esm/VerticalNavigation/TreeView/descendants.js +0 -125
  70. package/dist/esm/VerticalNavigation/TreeView/descendants.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"TagsInput.js","sources":["../../../src/TagsInput/TagsInput.tsx"],"sourcesContent":["import {\n forwardRef,\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 { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { baseInputClasses } from \"../BaseInput\";\nimport { DEFAULT_ERROR_MESSAGES } from \"../BaseInput/validations\";\nimport {\n HvCharCounter,\n HvCharCounterProps,\n HvFormElement,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvSuggestions,\n HvWarningText,\n} from \"../Forms\";\nimport validationStates from \"../Forms/FormElement/validationStates\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useDefaultProps } from \"../hooks/useDefaultProps\";\nimport { useIsMounted } from \"../hooks/useIsMounted\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvInput } from \"../Input\";\nimport { HvListContainer, HvListItem } from \"../ListContainer\";\nimport { HvTag, HvTagProps } from \"../Tag\";\nimport { HvTagSuggestion, HvValidationMessages } from \"../types/forms\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { ExtractNames } from \"../utils/classes\";\nimport { isKey } from \"../utils/keyboardUtils\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./TagsInput.styles\";\n\nexport { staticClasses as tagsInputClasses };\n\nexport type HvTagsInputClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvTagsInputProps\n extends HvBaseProps<\n HTMLElement,\n \"onChange\" | \"onBlur\" | \"onFocus\" | \"onKeyDown\" | \"color\" | \"defaultValue\"\n > {\n /** The form element name. */\n name?: string;\n /** The value of the form element. */\n value?: string[] | HvTagProps[];\n /** When uncontrolled, defines the initial input value. */\n defaultValue?: string[] | HvTagProps[];\n /**\n * The label of the form element.\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 the form element is required. */\n required?: boolean;\n /** The function that will be executed onChange. */\n onChange?: (\n event:\n | React.ChangeEvent<HTMLInputElement>\n | React.KeyboardEvent<HTMLInputElement>\n | React.MouseEvent<HTMLButtonElement>\n | React.MouseEvent<HTMLElement, MouseEvent>\n | React.KeyboardEventHandler<HTMLElement>,\n value: HvTagProps[],\n ) => void;\n /** The function that will be executed when the element is focused. */\n onFocus?: (event: React.FocusEvent<HTMLInputElement>, value: string) => void;\n /** The function that will be executed when the element is blurred. */\n onBlur?: (event: React.FocusEvent<HTMLInputElement>, value: string) => void;\n /** The function that will be executed when a tag is deleted. */\n onDelete?: (\n event:\n | React.ChangeEvent<HTMLInputElement>\n | React.KeyboardEvent<HTMLInputElement>\n | React.MouseEvent<HTMLButtonElement>\n | React.MouseEvent<HTMLElement, MouseEvent>\n | React.KeyboardEventHandler<HTMLElement>,\n value: HvTagProps,\n index: number,\n ) => void;\n /** The function that will be executed when a tag is added. */\n onAdd?: (\n event:\n | React.ChangeEvent<HTMLInputElement>\n | React.KeyboardEvent<HTMLInputElement>\n | React.MouseEvent<HTMLButtonElement>\n | React.MouseEvent<HTMLElement, MouseEvent>\n | React.KeyboardEventHandler<HTMLElement>,\n value: HvTagProps,\n index: number,\n ) => void;\n /** The placeholder value of the input. */\n placeholder?: string;\n /** If `true` the character counter isn't shown even if maxTagsQuantity is set. */\n hideCounter?: boolean;\n /** Text between the current char counter and max value. */\n middleCountLabel?: string;\n /** The maximum allowed length of the characters, if this value is null no check will be performed. */\n maxTagsQuantity?: number;\n /** Attributes applied to the input element. */\n inputProps?: MuiInputBaseComponentProps;\n /** If `true` it should autofocus. */\n autoFocus?: boolean;\n /** If `true` the component is resizable. */\n resizable?: boolean;\n /** Props passed to the HvCharCount component. */\n countCharProps?: Partial<HvCharCounterProps>;\n /** If `true` the component is in multiline mode. */\n multiline?: boolean;\n /** The status of the form element. */\n status?: HvFormStatus;\n /** The error message to show when `status` is \"invalid\". */\n statusMessage?: React.ReactNode;\n /** An Object containing the various texts associated with the input. */\n validationMessages?: HvValidationMessages;\n /** An array of strings that represent the character used to input a tag. This character is the string representation of the event.code from the input event. */\n commitTagOn?: string[];\n /** If `true` the tag will be committed when the blur event occurs. */\n commitOnBlur?: boolean;\n /** The function that will be executed to received an array of objects that has a label and id to create list of suggestions. */\n suggestionListCallback?: (value: string) => HvTagSuggestion[] | null;\n /** The validation function that will be executed when adding tags in the suggestions mode. */\n suggestionValidation?: (value: string) => boolean;\n /** When in suggestions mode, this property indicates that tags that are not present on the suggestions list can also be added. */\n suggestionsLoose?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvTagsInputClasses;\n}\n\n/**\n * A tags input is a single or multiline control that allows the input of tags.\n */\nexport const HvTagsInput = forwardRef<HTMLUListElement, HvTagsInputProps>(\n (props, ref) => {\n const {\n classes: classesProp,\n className,\n id,\n name,\n value: valueProp,\n defaultValue = [],\n readOnly = false,\n disabled = false,\n required = false,\n label: textAreaLabel,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n onChange,\n onAdd,\n onDelete,\n onBlur,\n onFocus,\n placeholder,\n hideCounter = false,\n middleCountLabel = \"/\",\n maxTagsQuantity,\n autoFocus = false,\n resizable = true,\n inputProps = {},\n countCharProps = {},\n multiline = false,\n status,\n statusMessage,\n validationMessages,\n commitTagOn = [\"Enter\"],\n commitOnBlur = false,\n suggestionListCallback,\n suggestionValidation,\n suggestionsLoose = false,\n ...others\n } = useDefaultProps(\"HvTagsInput\", props);\n\n const { classes, cx, css } = useClasses(classesProp);\n\n const elementId = useUniqueId(id);\n\n const hasLabel = textAreaLabel != null;\n const hasDescription = description != null;\n\n const [value, setValue] = useControlled(valueProp, defaultValue);\n\n const [validationState, setValidationState] = useControlled(\n status,\n validationStates.standBy,\n );\n const [validationMessage, setValidationMessage] = useControlled(\n statusMessage,\n \"\",\n );\n\n const [tagInput, setTagInput] = useState(\"\");\n const [tagCursorPos, setTagCursorPos] = useState(value.length);\n const [stateValid, setStateValid] = useState(true);\n\n const inputRef = useRef<any>();\n const containerRef = useRef<any>();\n const skipReset = useRef(false);\n const blurTimeout = useRef<any>();\n const materialInputRef = useRef<any>(null);\n\n const forkedContainerRef = useForkRef(ref, containerRef);\n\n const isTagSelected = tagCursorPos >= 0 && tagCursorPos < value.length;\n const hasCounter = maxTagsQuantity != null && !hideCounter;\n\n // suggestions related state\n const [suggestionValues, setSuggestionValues] = useState<\n HvTagSuggestion[] | null\n >(null);\n\n const isStateInvalid = useMemo(() => {\n return hasCounter && value.length > maxTagsQuantity;\n }, [hasCounter, maxTagsQuantity, value.length]);\n\n const canShowSuggestions = suggestionListCallback != null;\n const hasSuggestions = !!suggestionValues;\n\n const errorMessages = useMemo(\n () => ({ ...DEFAULT_ERROR_MESSAGES, ...validationMessages }),\n [validationMessages],\n );\n\n const performValidation = useCallback(\n (currValue) => {\n if (\n maxTagsQuantity !== null &&\n maxTagsQuantity !== undefined &&\n currValue.length > maxTagsQuantity\n ) {\n setValidationState(validationStates.invalid);\n setValidationMessage(errorMessages.maxCharError);\n setStateValid(false);\n } else {\n setValidationState(validationStates.valid);\n setValidationMessage(\"\");\n setStateValid(true);\n }\n },\n [\n errorMessages.maxCharError,\n maxTagsQuantity,\n setValidationMessage,\n setValidationState,\n ],\n );\n\n /**\n * Deletes a Tag from the array of tags and sets the new position for the tag cursor.\n * Also executes the user provided onDelete and onChange events.\n *\n * @param {number} tagPos - the position at which to remove the tag\n * @param {Event} event - the event associated with the delete\n * @param {boolean} end - whether or not to set the cursor at the end of the array\n */\n const deleteTag = useCallback(\n (tagPos, event, end) => {\n const newTagsArr = [\n ...value.slice(0, tagPos),\n ...value.slice(tagPos + 1),\n ];\n setValue(newTagsArr);\n setTagCursorPos(\n end ? newTagsArr.length : tagCursorPos > 0 ? tagCursorPos - 1 : 0,\n );\n inputRef.current?.focus();\n performValidation(newTagsArr);\n onDelete?.(event, value[tagPos], tagPos);\n onChange?.(event, newTagsArr);\n skipReset.current = true;\n },\n [onChange, onDelete, performValidation, setValue, tagCursorPos, value],\n );\n\n /**\n * Adds a Tag to the array of tags.\n * Also executes the user provided onAdd and onDelete events.\n *\n * @param {Event} event - whatever event triggered adding a tag\n * @param {string} tag - the string for the tag\n */\n const addTag = useCallback(\n (event, tag) => {\n event.preventDefault();\n if (tag !== \"\") {\n const newTag: HvTagProps = { label: tag, type: \"semantic\" };\n const newTagsArr = [...value, newTag];\n setValue(newTagsArr);\n performValidation(newTagsArr);\n onAdd?.(event, newTag, newTagsArr.length - 1);\n onChange?.(event, newTagsArr);\n }\n },\n [onAdd, onChange, performValidation, setValue, value],\n );\n\n const canShowError =\n (status !== undefined &&\n status === \"invalid\" &&\n statusMessage !== undefined) ||\n !stateValid;\n\n useEffect(() => {\n if (!multiline) {\n const element = containerRef?.current?.children[tagCursorPos];\n // this setTimeout is a workaround for Firefox not properly dealing\n // with setting the scrollLeft value.\n setTimeout(() => {\n const container = containerRef.current;\n if (container == null) return;\n container.scrollLeft = element\n ? element.offsetLeft -\n container.getBoundingClientRect().width / 2 +\n element.getBoundingClientRect().width / 2\n : 0;\n }, 50);\n\n element?.focus();\n }\n }, [multiline, tagCursorPos]);\n\n useEffect(() => {\n if (!skipReset.current) {\n setTagInput(\"\");\n setTagCursorPos(value.length);\n }\n skipReset.current = false;\n }, [value]);\n\n const isMounted = useIsMounted();\n\n /**\n * Looks for the node that represent the input inside the material tree and focus it.\n */\n const focusInput = () => {\n materialInputRef.current.focus();\n };\n\n const getSuggestions = useCallback(\n (li) => {\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 [elementId],\n );\n\n /**\n * Clears the suggestion array.\n */\n const suggestionClearHandler = useCallback(() => {\n if (isMounted.current) {\n setSuggestionValues(null);\n }\n }, [isMounted]);\n\n /**\n * Fills of the suggestion array.\n */\n const suggestionHandler = useCallback(\n (val) => {\n const suggestionsArray = suggestionListCallback?.(val);\n if (suggestionsArray?.[0]?.label) {\n setSuggestionValues(suggestionsArray);\n } else {\n suggestionClearHandler();\n }\n },\n [suggestionClearHandler, suggestionListCallback],\n );\n\n /**\n * Executes the user callback adds the selection to the state and clears the suggestions.\n */\n const suggestionSelectedHandler = (event, item) => {\n addTag(event, item.value || item.label);\n\n // set the input value (only when value is uncontrolled)\n setTagInput(item.value || item.label);\n\n focusInput();\n suggestionClearHandler();\n };\n\n /**\n * Handler for the `onKeyDown` event on the suggestions component\n */\n const onSuggestionKeyDown = (event) => {\n if (isKey(event, \"Esc\")) {\n suggestionClearHandler();\n focusInput();\n } else if (isKey(event, \"Tab\")) {\n suggestionClearHandler();\n }\n };\n\n /**\n * Handler for the `onChange` event on the tag input\n */\n const onChangeHandler = useCallback(\n (_, input) => {\n setTagInput(input);\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(input);\n }\n },\n [canShowSuggestions, suggestionHandler],\n );\n\n /**\n * Handler for the `onKeyDown` event on the form element\n */\n const onInputKeyDownHandler = useCallback(\n (event) => {\n if (!canShowSuggestions && commitTagOn.includes(event.code)) {\n addTag(event, tagInput);\n }\n },\n [addTag, canShowSuggestions, commitTagOn, tagInput],\n );\n\n /**\n * Handler for the `onKeyDown` event on the list container.\n */\n const onKeyDownHandler = useCallback(\n (event) => {\n if (tagInput === \"\") {\n switch (event.code) {\n case \"ArrowLeft\":\n setTagCursorPos(tagCursorPos > 0 ? tagCursorPos - 1 : 0);\n break;\n case \"ArrowRight\":\n setTagCursorPos(\n tagCursorPos < value.length ? tagCursorPos + 1 : value.length,\n );\n break;\n case \"Backspace\":\n if (isTagSelected) {\n deleteTag(tagCursorPos, event, false);\n } else {\n setTagCursorPos(value.length - 1);\n }\n break;\n case \"Delete\":\n if (isTagSelected) {\n deleteTag(tagCursorPos, event, false);\n }\n break;\n default:\n break;\n }\n } else {\n switch (event.code) {\n case \"ArrowDown\":\n getSuggestions(0)?.focus();\n break;\n case \"Enter\":\n if (\n canShowSuggestions &&\n suggestionsLoose &&\n (suggestionValidation?.(tagInput) || !suggestionValidation)\n ) {\n addTag(event, tagInput);\n\n // set the input value (only when value is uncontrolled)\n setTagInput(tagInput);\n\n focusInput();\n suggestionClearHandler();\n }\n break;\n default:\n break;\n }\n }\n },\n [\n addTag,\n canShowSuggestions,\n deleteTag,\n getSuggestions,\n isTagSelected,\n suggestionClearHandler,\n suggestionValidation,\n suggestionsLoose,\n tagCursorPos,\n tagInput,\n value.length,\n ],\n );\n\n /**\n * Handler for the `onDelete` event on the tag component\n */\n const onDeleteTagHandler = useCallback(\n (event, i) => {\n deleteTag(i, event, true);\n setValidationState(validationStates.standBy);\n },\n [deleteTag, setValidationState],\n );\n\n /**\n * Handler for the `onClick` event on the list container\n */\n const onContainerClickHandler = useCallback(() => {\n inputRef.current?.focus();\n clearTimeout(blurTimeout.current);\n setTagCursorPos(value.length);\n }, [value.length]);\n\n const onBlurHandler = (evt) => {\n blurTimeout.current = setTimeout(() => {\n if (commitOnBlur) {\n addTag(evt, tagInput);\n }\n onBlur?.(evt, tagInput);\n }, 250);\n };\n\n const onFocusHandler = (evt) => {\n clearTimeout(blurTimeout.current);\n onFocus?.(evt, tagInput);\n };\n\n return (\n <HvFormElement\n id={id}\n name={name}\n disabled={disabled}\n readOnly={readOnly}\n status={validationState}\n required={required}\n onBlur={onBlurHandler}\n onFocus={onFocusHandler}\n className={cx(\n classes.root,\n { [classes.disabled]: disabled, [classes.readOnly]: readOnly },\n className,\n )}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n className={classes.label}\n id={setId(id, \"label\")}\n htmlFor={setId(elementId, \"input\")}\n label={textAreaLabel}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n className={classes.description}\n id={setId(elementId, \"description\")}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n\n {hasCounter && (\n <HvCharCounter\n id={setId(elementId, \"charCounter\")}\n className={classes.characterCounter}\n separator={middleCountLabel}\n currentCharQuantity={value.length}\n maxCharQuantity={maxTagsQuantity}\n {...countCharProps}\n />\n )}\n\n <HvListContainer\n className={cx(classes.tagsList, {\n [classes.error]: canShowError,\n [classes.resizable]: resizable && multiline,\n [classes.invalid]: isStateInvalid,\n [classes.singleLine]: !multiline,\n })}\n onKeyDown={onKeyDownHandler}\n onClick={onContainerClickHandler}\n ref={forkedContainerRef}\n >\n {value &&\n value.map((t, i) => {\n const tag =\n typeof t === \"string\"\n ? {\n label: t,\n type: \"semantic\",\n }\n : t;\n const { label, type, ...otherProps } = tag;\n return (\n <HvListItem\n key={`${tag.label}-${i}`}\n tabIndex={-1}\n className={cx({ [classes.singleLine]: !multiline })}\n classes={{\n gutters: classes.listItemGutters,\n root: classes.listItemRoot,\n }}\n id={setId(elementId, `tag-${i}`)}\n >\n <HvTag\n label={label}\n className={cx({\n [classes.tagSelected]: i === tagCursorPos,\n })}\n classes={{\n chipRoot: classes.chipRoot,\n }}\n type={type}\n {...(!(readOnly || disabled || type === \"categorical\") && {\n onDelete: (event) => onDeleteTagHandler(event, i),\n })}\n deleteButtonProps={{\n tabIndex: -1,\n }}\n {...otherProps}\n />\n </HvListItem>\n );\n })}\n {!(disabled || readOnly) && (\n <HvListItem\n className={cx(\n {\n [classes.singleLine]: !multiline,\n [classes.tagInputRootEmpty]: value.length === 0,\n },\n !!isTagSelected &&\n css({\n [`& .${baseInputClasses.inputRoot}`]: {\n backgroundColor: theme.colors.atmo1,\n },\n }),\n )}\n classes={{\n root: classes.tagInputContainerRoot,\n gutters: classes.listItemGutters,\n }}\n id={setId(elementId, `tag-${value.length}`)}\n >\n <HvInput\n value={tagInput}\n disableClear\n onChange={onChangeHandler}\n onKeyDown={onInputKeyDownHandler}\n placeholder={value.length === 0 ? placeholder : \"\"}\n autoFocus={autoFocus}\n className={cx({\n [classes.singleLine]: !multiline,\n })}\n classes={{\n root: classes.tagInputRoot,\n input: classes.input,\n inputBorderContainer: classes.tagInputBorderContainer,\n inputRootFocused: classes.tagInputRootFocused,\n }}\n disabled={disabled}\n readOnly={readOnly || isTagSelected}\n inputProps={{\n ref: materialInputRef,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\":\n ariaDescribedBy != null\n ? ariaDescribedBy\n : (description && setId(elementId, \"description\")) ||\n undefined,\n\n ...inputProps,\n }}\n inputRef={inputRef}\n {...others}\n />\n </HvListItem>\n )}\n </HvListContainer>\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={containerRef?.current?.parentElement}\n onClose={suggestionClearHandler}\n onKeyDown={onSuggestionKeyDown}\n onSuggestionSelected={suggestionSelectedHandler}\n suggestionValues={suggestionValues}\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);\n"],"names":["validationState","validationStates","baseInputClasses"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiJO,MAAM,cAAc;AAAA,EACzB,CAAC,OAAO,QAAQ;AACR,UAAA;AAAA,MACJ,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP,eAAe,CAAC;AAAA,MAChB,WAAW;AAAA,MACX,WAAW;AAAA,MACX,WAAW;AAAA,MACX,OAAO;AAAA,MACP,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB;AAAA,MACA,oBAAoB;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB;AAAA,MACA,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,aAAa,CAAC;AAAA,MACd,iBAAiB,CAAC;AAAA,MAClB,YAAY;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc,CAAC,OAAO;AAAA,MACtB,eAAe;AAAA,MACf;AAAA,MACA;AAAA,MACA,mBAAmB;AAAA,MACnB,GAAG;AAAA,IAAA,IACD,gBAAgB,eAAe,KAAK;AAExC,UAAM,EAAE,SAAS,IAAI,IAAI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AAC;AAAA,wBAAA,CACxB;AAAA,wBACD,SAAS;AAAA,0BACP,MAAM,QAAQ;AAAA,0BACd,OAAO,QAAQ;AAAA,0BACf,sBAAsB,QAAQ;AAAA,0BAC9B,kBAAkB,QAAQ;AAAA,wBAC5B;AAAA,wBACA;AAAA,wBACA,UAAU,YAAY;AAAA,wBACtB,YAAY;AAAA,0BACV,KAAK;AAAA,0BACL,cAAc;AAAA,0BACd,mBAAmB;AAAA,0BACnB,oBACE,mBAAmB,OACf,kBACC,eAAe,MAAM,WAAW,aAAa,KAC9C;AAAA,0BAEN,GAAG;AAAA,wBACL;AAAA,wBACA;AAAA,wBACC,GAAG;AAAA,sBAAA;AAAA,oBACN;AAAA,kBAAA;AAAA,gBACF;AAAA,cAAA;AAAA,YAAA;AAAA,UAEJ;AAAA,UACC,sBAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,YAAA,sCACE,OAAI,EAAA,MAAK,gBAAe,WAAW,QAAQ,gBAAgB;AAAA,YAE9D;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,IAAI,MAAM,WAAW,aAAa;AAAA,gBAClC,SAAS;AAAA,kBACP,MAAM,QAAQ;AAAA,kBACd,MAAM,QAAQ;AAAA,gBAChB;AAAA,gBACA,UAAU;AAAA,gBACV,UAAU,cAAc,SAAS;AAAA,gBACjC,SAAS;AAAA,gBACT,WAAW;AAAA,gBACX,sBAAsB;AAAA,gBACtB;AAAA,cAAA;AAAA,YACF;AAAA,UAAA,GACF;AAAA,UAED,gBACC;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,IAAI,MAAM,WAAW,OAAO;AAAA,cAC5B,eAAa;AAAA,cACb,WAAW,QAAQ;AAAA,cAElB,UAAA;AAAA,YAAA;AAAA,UACH;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;"}
1
+ {"version":3,"file":"TagsInput.js","sources":["../../../src/TagsInput/TagsInput.tsx"],"sourcesContent":["import {\n forwardRef,\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 { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { baseInputClasses } from \"../BaseInput\";\nimport { DEFAULT_ERROR_MESSAGES } from \"../BaseInput/validations\";\nimport {\n HvCharCounter,\n HvCharCounterProps,\n HvFormElement,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvSuggestions,\n HvWarningText,\n} from \"../Forms\";\nimport validationStates from \"../Forms/FormElement/validationStates\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useDefaultProps } from \"../hooks/useDefaultProps\";\nimport { useIsMounted } from \"../hooks/useIsMounted\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvInput } from \"../Input\";\nimport { HvListContainer, HvListItem } from \"../ListContainer\";\nimport { HvTag, HvTagProps } from \"../Tag\";\nimport { HvTagSuggestion, HvValidationMessages } from \"../types/forms\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { ExtractNames } from \"../utils/classes\";\nimport { isKey } from \"../utils/keyboardUtils\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./TagsInput.styles\";\n\nexport { staticClasses as tagsInputClasses };\n\nexport type HvTagsInputClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvTagsInputProps\n extends HvBaseProps<\n HTMLElement,\n \"onChange\" | \"onBlur\" | \"onFocus\" | \"onKeyDown\" | \"color\" | \"defaultValue\"\n > {\n /** The form element name. */\n name?: string;\n /** The value of the form element. */\n value?: string[] | HvTagProps[];\n /** When uncontrolled, defines the initial input value. */\n defaultValue?: string[] | HvTagProps[];\n /**\n * The label of the form element.\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 the form element is required. */\n required?: boolean;\n /** The function that will be executed onChange. */\n onChange?: (\n event:\n | React.ChangeEvent<HTMLInputElement>\n | React.KeyboardEvent<HTMLInputElement>\n | React.MouseEvent<HTMLButtonElement>\n | React.MouseEvent<HTMLElement, MouseEvent>\n | React.KeyboardEventHandler<HTMLElement>,\n value: HvTagProps[],\n ) => void;\n /** The function that will be executed when the element is focused. */\n onFocus?: (event: React.FocusEvent<HTMLInputElement>, value: string) => void;\n /** The function that will be executed when the element is blurred. */\n onBlur?: (event: React.FocusEvent<HTMLInputElement>, value: string) => void;\n /** The function that will be executed when a tag is deleted. */\n onDelete?: (\n event:\n | React.ChangeEvent<HTMLInputElement>\n | React.KeyboardEvent<HTMLInputElement>\n | React.MouseEvent<HTMLButtonElement>\n | React.MouseEvent<HTMLElement, MouseEvent>\n | React.KeyboardEventHandler<HTMLElement>,\n value: HvTagProps,\n index: number,\n ) => void;\n /** The function that will be executed when a tag is added. */\n onAdd?: (\n event:\n | React.ChangeEvent<HTMLInputElement>\n | React.KeyboardEvent<HTMLInputElement>\n | React.MouseEvent<HTMLButtonElement>\n | React.MouseEvent<HTMLElement, MouseEvent>\n | React.KeyboardEventHandler<HTMLElement>,\n value: HvTagProps,\n index: number,\n ) => void;\n /** The placeholder value of the input. */\n placeholder?: string;\n /** If `true` the character counter isn't shown even if maxTagsQuantity is set. */\n hideCounter?: boolean;\n /** Text between the current char counter and max value. */\n middleCountLabel?: string;\n /** The maximum allowed length of the characters, if this value is null no check will be performed. */\n maxTagsQuantity?: number;\n /** Attributes applied to the input element. */\n inputProps?: MuiInputBaseComponentProps;\n /** If `true` it should autofocus. */\n autoFocus?: boolean;\n /** If `true` the component is resizable. */\n resizable?: boolean;\n /** Props passed to the HvCharCount component. */\n countCharProps?: Partial<HvCharCounterProps>;\n /** If `true` the component is in multiline mode. */\n multiline?: boolean;\n /** The status of the form element. */\n status?: HvFormStatus;\n /** The error message to show when `status` is \"invalid\". */\n statusMessage?: React.ReactNode;\n /** An Object containing the various texts associated with the input. */\n validationMessages?: HvValidationMessages;\n /** An array of strings that represent the character used to input a tag. This character is the string representation of the event.code from the input event. */\n commitTagOn?: string[];\n /** If `true` the tag will be committed when the blur event occurs. */\n commitOnBlur?: boolean;\n /** The function that will be executed to received an array of objects that has a label and id to create list of suggestions. */\n suggestionListCallback?: (value: string) => HvTagSuggestion[] | null;\n /** The validation function that will be executed when adding tags in the suggestions mode. */\n suggestionValidation?: (value: string) => boolean;\n /** When in suggestions mode, this property indicates that tags that are not present on the suggestions list can also be added. */\n suggestionsLoose?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvTagsInputClasses;\n}\n\n/**\n * A tags input is a single or multiline control that allows the input of tags.\n */\nexport const HvTagsInput = forwardRef<HTMLUListElement, HvTagsInputProps>(\n (props, ref) => {\n const {\n classes: classesProp,\n className,\n id,\n name,\n value: valueProp,\n defaultValue = [],\n readOnly = false,\n disabled = false,\n required = false,\n label: textAreaLabel,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n onChange,\n onAdd,\n onDelete,\n onBlur,\n onFocus,\n placeholder,\n hideCounter = false,\n middleCountLabel = \"/\",\n maxTagsQuantity,\n autoFocus = false,\n resizable = true,\n inputProps = {},\n countCharProps = {},\n multiline = false,\n status,\n statusMessage,\n validationMessages,\n commitTagOn = [\"Enter\"],\n commitOnBlur = false,\n suggestionListCallback,\n suggestionValidation,\n suggestionsLoose = false,\n ...others\n } = useDefaultProps(\"HvTagsInput\", props);\n\n const { classes, cx, css } = useClasses(classesProp);\n\n const elementId = useUniqueId(id);\n\n const hasLabel = textAreaLabel != null;\n const hasDescription = description != null;\n\n const [value, setValue] = useControlled(valueProp, defaultValue);\n\n const [validationState, setValidationState] = useControlled<HvFormStatus>(\n status,\n \"standBy\",\n );\n const [validationMessage, setValidationMessage] = useControlled(\n statusMessage,\n \"\",\n );\n\n const [tagInput, setTagInput] = useState(\"\");\n const [tagCursorPos, setTagCursorPos] = useState(value.length);\n const [stateValid, setStateValid] = useState(true);\n\n const inputRef = useRef<any>();\n const containerRef = useRef<any>();\n const skipReset = useRef(false);\n const blurTimeout = useRef<any>();\n const materialInputRef = useRef<any>(null);\n\n const forkedContainerRef = useForkRef(ref, containerRef);\n\n const isTagSelected = tagCursorPos >= 0 && tagCursorPos < value.length;\n const hasCounter = maxTagsQuantity != null && !hideCounter;\n\n // suggestions related state\n const [suggestionValues, setSuggestionValues] = useState<\n HvTagSuggestion[] | null\n >(null);\n\n const isStateInvalid = useMemo(() => {\n return hasCounter && value.length > maxTagsQuantity;\n }, [hasCounter, maxTagsQuantity, value.length]);\n\n const canShowSuggestions = suggestionListCallback != null;\n const hasSuggestions = !!suggestionValues;\n\n const errorMessages = useMemo(\n () => ({ ...DEFAULT_ERROR_MESSAGES, ...validationMessages }),\n [validationMessages],\n );\n\n const performValidation = useCallback(\n (currValue) => {\n if (\n maxTagsQuantity !== null &&\n maxTagsQuantity !== undefined &&\n currValue.length > maxTagsQuantity\n ) {\n setValidationState(validationStates.invalid);\n setValidationMessage(errorMessages.maxCharError);\n setStateValid(false);\n } else {\n setValidationState(validationStates.valid);\n setValidationMessage(\"\");\n setStateValid(true);\n }\n },\n [\n errorMessages.maxCharError,\n maxTagsQuantity,\n setValidationMessage,\n setValidationState,\n ],\n );\n\n /**\n * Deletes a Tag from the array of tags and sets the new position for the tag cursor.\n * Also executes the user provided onDelete and onChange events.\n *\n * @param {number} tagPos - the position at which to remove the tag\n * @param {Event} event - the event associated with the delete\n * @param {boolean} end - whether or not to set the cursor at the end of the array\n */\n const deleteTag = useCallback(\n (tagPos: number, event: any, end: boolean) => {\n const newTagsArr = [\n ...value.slice(0, tagPos),\n ...value.slice(tagPos + 1),\n ] as HvTagProps[];\n setValue(newTagsArr);\n setTagCursorPos(\n end ? newTagsArr.length : tagCursorPos > 0 ? tagCursorPos - 1 : 0,\n );\n inputRef.current?.focus();\n performValidation(newTagsArr);\n onDelete?.(event, value[tagPos] as HvTagProps, tagPos);\n onChange?.(event, newTagsArr);\n skipReset.current = true;\n },\n [onChange, onDelete, performValidation, setValue, tagCursorPos, value],\n );\n\n /**\n * Adds a Tag to the array of tags.\n * Also executes the user provided onAdd and onDelete events.\n *\n * @param {Event} event - whatever event triggered adding a tag\n * @param {string} tag - the string for the tag\n */\n const addTag = useCallback(\n (event, tag) => {\n event.preventDefault();\n if (tag !== \"\") {\n const newTag: HvTagProps = { label: tag, type: \"semantic\" };\n const newTagsArr = [...value, newTag] as HvTagProps[];\n setValue(newTagsArr);\n performValidation(newTagsArr);\n onAdd?.(event, newTag, newTagsArr.length - 1);\n onChange?.(event, newTagsArr);\n }\n },\n [onAdd, onChange, performValidation, setValue, value],\n );\n\n const canShowError =\n (status !== undefined &&\n status === \"invalid\" &&\n statusMessage !== undefined) ||\n !stateValid;\n\n useEffect(() => {\n if (!multiline) {\n const element = containerRef?.current?.children[tagCursorPos];\n // this setTimeout is a workaround for Firefox not properly dealing\n // with setting the scrollLeft value.\n setTimeout(() => {\n const container = containerRef.current;\n if (container == null) return;\n container.scrollLeft = element\n ? element.offsetLeft -\n container.getBoundingClientRect().width / 2 +\n element.getBoundingClientRect().width / 2\n : 0;\n }, 50);\n\n element?.focus();\n }\n }, [multiline, tagCursorPos]);\n\n useEffect(() => {\n if (!skipReset.current) {\n setTagInput(\"\");\n setTagCursorPos(value.length);\n }\n skipReset.current = false;\n }, [value]);\n\n const isMounted = useIsMounted();\n\n /**\n * Looks for the node that represent the input inside the material tree and focus it.\n */\n const focusInput = () => {\n materialInputRef.current.focus();\n };\n\n const getSuggestions = useCallback(\n (li) => {\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 [elementId],\n );\n\n /**\n * Clears the suggestion array.\n */\n const suggestionClearHandler = useCallback(() => {\n if (isMounted.current) {\n setSuggestionValues(null);\n }\n }, [isMounted]);\n\n /**\n * Fills of the suggestion array.\n */\n const suggestionHandler = useCallback(\n (val) => {\n const suggestionsArray = suggestionListCallback?.(val);\n if (suggestionsArray?.[0]?.label) {\n setSuggestionValues(suggestionsArray);\n } else {\n suggestionClearHandler();\n }\n },\n [suggestionClearHandler, suggestionListCallback],\n );\n\n /**\n * Executes the user callback adds the selection to the state and clears the suggestions.\n */\n const suggestionSelectedHandler = (event, item) => {\n addTag(event, item.value || item.label);\n\n // set the input value (only when value is uncontrolled)\n setTagInput(item.value || item.label);\n\n focusInput();\n suggestionClearHandler();\n };\n\n /**\n * Handler for the `onKeyDown` event on the suggestions component\n */\n const onSuggestionKeyDown = (event) => {\n if (isKey(event, \"Esc\")) {\n suggestionClearHandler();\n focusInput();\n } else if (isKey(event, \"Tab\")) {\n suggestionClearHandler();\n }\n };\n\n /**\n * Handler for the `onChange` event on the tag input\n */\n const onChangeHandler = useCallback(\n (_, input) => {\n setTagInput(input);\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(input);\n }\n },\n [canShowSuggestions, suggestionHandler],\n );\n\n /**\n * Handler for the `onKeyDown` event on the form element\n */\n const onInputKeyDownHandler = useCallback(\n (event) => {\n if (!canShowSuggestions && commitTagOn.includes(event.code)) {\n addTag(event, tagInput);\n }\n },\n [addTag, canShowSuggestions, commitTagOn, tagInput],\n );\n\n /**\n * Handler for the `onKeyDown` event on the list container.\n */\n const onKeyDownHandler = useCallback(\n (event) => {\n if (tagInput === \"\") {\n switch (event.code) {\n case \"ArrowLeft\":\n setTagCursorPos(tagCursorPos > 0 ? tagCursorPos - 1 : 0);\n break;\n case \"ArrowRight\":\n setTagCursorPos(\n tagCursorPos < value.length ? tagCursorPos + 1 : value.length,\n );\n break;\n case \"Backspace\":\n if (isTagSelected) {\n deleteTag(tagCursorPos, event, false);\n } else {\n setTagCursorPos(value.length - 1);\n }\n break;\n case \"Delete\":\n if (isTagSelected) {\n deleteTag(tagCursorPos, event, false);\n }\n break;\n default:\n break;\n }\n } else {\n switch (event.code) {\n case \"ArrowDown\":\n getSuggestions(0)?.focus();\n break;\n case \"Enter\":\n if (\n canShowSuggestions &&\n suggestionsLoose &&\n (suggestionValidation?.(tagInput) || !suggestionValidation)\n ) {\n addTag(event, tagInput);\n\n // set the input value (only when value is uncontrolled)\n setTagInput(tagInput);\n\n focusInput();\n suggestionClearHandler();\n }\n break;\n default:\n break;\n }\n }\n },\n [\n addTag,\n canShowSuggestions,\n deleteTag,\n getSuggestions,\n isTagSelected,\n suggestionClearHandler,\n suggestionValidation,\n suggestionsLoose,\n tagCursorPos,\n tagInput,\n value.length,\n ],\n );\n\n /**\n * Handler for the `onDelete` event on the tag component\n */\n const onDeleteTagHandler = useCallback(\n (event, i) => {\n deleteTag(i, event, true);\n setValidationState(validationStates.standBy);\n },\n [deleteTag, setValidationState],\n );\n\n /**\n * Handler for the `onClick` event on the list container\n */\n const onContainerClickHandler = useCallback(() => {\n inputRef.current?.focus();\n clearTimeout(blurTimeout.current);\n setTagCursorPos(value.length);\n }, [value.length]);\n\n const onBlurHandler = (evt) => {\n blurTimeout.current = setTimeout(() => {\n if (commitOnBlur) {\n addTag(evt, tagInput);\n }\n onBlur?.(evt, tagInput);\n }, 250);\n };\n\n const onFocusHandler = (evt) => {\n clearTimeout(blurTimeout.current);\n onFocus?.(evt, tagInput);\n };\n\n return (\n <HvFormElement\n id={id}\n name={name}\n disabled={disabled}\n readOnly={readOnly}\n status={validationState}\n required={required}\n onBlur={onBlurHandler}\n onFocus={onFocusHandler}\n className={cx(\n classes.root,\n { [classes.disabled]: disabled, [classes.readOnly]: readOnly },\n className,\n )}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n className={classes.label}\n id={setId(id, \"label\")}\n htmlFor={setId(elementId, \"input\")}\n label={textAreaLabel}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n className={classes.description}\n id={setId(elementId, \"description\")}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n\n {hasCounter && (\n <HvCharCounter\n id={setId(elementId, \"charCounter\")}\n className={classes.characterCounter}\n separator={middleCountLabel}\n currentCharQuantity={value.length}\n maxCharQuantity={maxTagsQuantity}\n {...countCharProps}\n />\n )}\n\n <HvListContainer\n className={cx(classes.tagsList, {\n [classes.error]: canShowError,\n [classes.resizable]: resizable && multiline,\n [classes.invalid]: isStateInvalid,\n [classes.singleLine]: !multiline,\n })}\n onKeyDown={onKeyDownHandler}\n onClick={onContainerClickHandler}\n ref={forkedContainerRef}\n >\n {value &&\n value.map((t, i) => {\n const tag =\n typeof t === \"string\"\n ? {\n label: t,\n type: \"semantic\",\n }\n : t;\n const { label, type, ...otherProps } = tag;\n return (\n <HvListItem\n key={`${tag.label}-${i}`}\n tabIndex={-1}\n className={cx({ [classes.singleLine]: !multiline })}\n classes={{\n gutters: classes.listItemGutters,\n root: classes.listItemRoot,\n }}\n id={setId(elementId, `tag-${i}`)}\n >\n <HvTag\n label={label}\n className={cx({\n [classes.tagSelected]: i === tagCursorPos,\n })}\n classes={{\n chipRoot: classes.chipRoot,\n }}\n type={type}\n {...(!(readOnly || disabled || type === \"categorical\") && {\n onDelete: (event) => onDeleteTagHandler(event, i),\n })}\n deleteButtonProps={{\n tabIndex: -1,\n }}\n {...otherProps}\n />\n </HvListItem>\n );\n })}\n {!(disabled || readOnly) && (\n <HvListItem\n className={cx(\n {\n [classes.singleLine]: !multiline,\n [classes.tagInputRootEmpty]: value.length === 0,\n },\n !!isTagSelected &&\n css({\n [`& .${baseInputClasses.inputRoot}`]: {\n backgroundColor: theme.colors.atmo1,\n },\n }),\n )}\n classes={{\n root: classes.tagInputContainerRoot,\n gutters: classes.listItemGutters,\n }}\n id={setId(elementId, `tag-${value.length}`)}\n >\n <HvInput\n value={tagInput}\n disableClear\n onChange={onChangeHandler}\n onKeyDown={onInputKeyDownHandler}\n placeholder={value.length === 0 ? placeholder : \"\"}\n autoFocus={autoFocus}\n className={cx({\n [classes.singleLine]: !multiline,\n })}\n classes={{\n root: classes.tagInputRoot,\n input: classes.input,\n inputBorderContainer: classes.tagInputBorderContainer,\n inputRootFocused: classes.tagInputRootFocused,\n }}\n disabled={disabled}\n readOnly={readOnly || isTagSelected}\n inputProps={{\n ref: materialInputRef,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\":\n ariaDescribedBy != null\n ? ariaDescribedBy\n : (description && setId(elementId, \"description\")) ||\n undefined,\n\n ...inputProps,\n }}\n inputRef={inputRef}\n {...others}\n />\n </HvListItem>\n )}\n </HvListContainer>\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={containerRef?.current?.parentElement}\n onClose={suggestionClearHandler}\n onKeyDown={onSuggestionKeyDown}\n onSuggestionSelected={suggestionSelectedHandler}\n suggestionValues={suggestionValues}\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);\n"],"names":["validationState","validationStates","baseInputClasses"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiJO,MAAM,cAAc;AAAA,EACzB,CAAC,OAAO,QAAQ;AACR,UAAA;AAAA,MACJ,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP,eAAe,CAAC;AAAA,MAChB,WAAW;AAAA,MACX,WAAW;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AAM,QAAQ;AAAA,kBACd,MAAM,QAAQ;AAAA,gBAChB;AAAA,gBACA,UAAU;AAAA,gBACV,UAAU,cAAc,SAAS;AAAA,gBACjC,SAAS;AAAA,gBACT,WAAW;AAAA,gBACX,sBAAsB;AAAA,gBACtB;AAAA,cAAA;AAAA,YACF;AAAA,UAAA,GACF;AAAA,UAED,gBACC;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,IAAI,MAAM,WAAW,OAAO;AAAA,cAC5B,eAAa;AAAA,cACb,WAAW,QAAQ;AAAA,cAElB,UAAA;AAAA,YAAA;AAAA,UACH;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"TimePicker.js","sources":["../../../src/TimePicker/TimePicker.tsx"],"sourcesContent":["import { forwardRef, useMemo, useRef, useState } from \"react\";\nimport { Time } from \"@internationalized/date\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport { useTimeField } from \"@react-aria/datepicker\";\nimport {\n TimeFieldStateOptions,\n useTimeFieldState,\n} from \"@react-stately/datepicker\";\nimport { Time as TimeIcon } from \"@hitachivantara/uikit-react-icons\";\n\nimport { HvBaseDropdown, HvBaseDropdownProps } from \"../BaseDropdown\";\nimport {\n HvFormElement,\n HvFormElementProps,\n HvInfoMessage,\n HvLabel,\n HvWarningText,\n} from \"../Forms\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useDefaultProps } from \"../hooks/useDefaultProps\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { ExtractNames } from \"../utils/classes\";\nimport { setId } from \"../utils/setId\";\nimport { Placeholder } from \"./Placeholder\";\nimport { staticClasses, useClasses } from \"./TimePicker.styles\";\nimport { Unit } from \"./Unit\";\n\nconst toTime = (value?: HvTimePickerValue | null) => {\n if (!value) return value;\n const { hours, minutes, seconds } = value;\n return new Time(hours, minutes, seconds);\n};\n\nconst getFormat = (timeFormat?: TimeFormat) => {\n if (timeFormat == null) return 24;\n return timeFormat === \"12\" ? 12 : 24;\n};\n\nexport { staticClasses as timePickerClasses };\n\nexport type TimeFormat = \"12\" | \"24\";\n\nexport type HvTimePickerClasses = ExtractNames<typeof useClasses>;\n\nexport type HvTimePickerClassKey =\n | \"root\"\n | \"input\"\n | \"label\"\n | \"placeholder\"\n | \"timePopperContainer\"\n | \"separator\"\n | \"periodContainer\"\n | \"formElementRoot\"\n | \"dropdownPlaceholder\"\n | \"iconBaseRoot\"\n | \"error\"\n | \"labelContainer\"\n | \"description\"\n | \"dropdownHeaderInvalid\"\n | \"dropdownPlaceholderDisabled\"\n | \"dropdownHeaderOpen\";\n\nexport type HvTimePickerValue = {\n hours: number;\n minutes: number;\n seconds: number;\n};\n\nexport interface HvTimePickerProps\n extends Omit<\n HvFormElementProps,\n \"classes\" | \"value\" | \"defaultValue\" | \"onChange\"\n > {\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvTimePickerClasses;\n /** Current value of the element when _controlled_. Follows the 24-hour format. */\n value?: HvTimePickerValue | null;\n /** Initial value of the element when _uncontrolled_. Follows the 24-hour format. */\n defaultValue?: HvTimePickerValue | null;\n /** The placeholder value when no time is selected. */\n placeholder?: string;\n /** The placeholder of the hours input. */\n hoursPlaceholder?: string;\n /** The placeholder of the minutes input. */\n minutesPlaceholder?: string;\n /** The placeholder of the seconds input. */\n secondsPlaceholder?: string;\n /**\n * Whether the time picker should show the AM/PM 12-hour clock or the 24-hour one.\n * If undefined, the component will use a format according to the passed locale.\n */\n timeFormat?: TimeFormat;\n /** Whether to show the seconds when using the native time picker */\n showSeconds?: boolean;\n /** Locale that will provide the time format(12 or 24 hour format). It is \"overwritten\" by `showAmPm` */\n locale?: string;\n /** Whether the dropdown is expandable. */\n disableExpand?: boolean;\n /**\n * Callback function to be triggered when the input value is changed.\n * It is invoked with a `{hours, minutes, seconds}` object, always in the 24h format\n */\n onChange?: (value: HvTimePickerValue) => void;\n /** Callback called when dropdown changes the expanded state. */\n onToggle?: (event: Event, isOpen: boolean) => void;\n /** Disable the portal behavior. The children stay within it's parent DOM hierarchy. */\n disablePortal?: boolean;\n /** Sets if the calendar container should follow the date picker input out of the screen or stay visible. */\n escapeWithReference?: boolean;\n /** Extra properties to be passed to the TimePicker's dropdown. */\n dropdownProps?: Partial<HvBaseDropdownProps>;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /**\n * Provide additional descriptive text for the form element.\n */\n description?: React.ReactNode;\n}\n\n/**\n * A Time Picker allows the user to choose a specific time or a time range.\n */\nexport const HvTimePicker = forwardRef<HTMLDivElement, HvTimePickerProps>(\n (props, ref) => {\n const {\n classes: classesProp,\n className,\n\n id: idProp,\n name,\n required = false,\n disabled = false,\n readOnly = false,\n label,\n\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n status,\n statusMessage,\n \"aria-errormessage\": ariaErrorMessage,\n\n placeholder,\n hoursPlaceholder = \"hh\",\n minutesPlaceholder = \"mm\",\n secondsPlaceholder = \"ss\",\n\n value: valueProp,\n defaultValue: defaultValueProp,\n\n timeFormat,\n showSeconds,\n disableExpand,\n locale = \"en\",\n\n onToggle,\n onChange,\n\n // misc properties:\n disablePortal = true,\n escapeWithReference = true,\n dropdownProps = {},\n ...others\n } = useDefaultProps(\"HvTimePicker\", props);\n\n const id = useUniqueId(idProp);\n\n const { classes, cx } = useClasses(classesProp);\n\n const timeFieldRef = useRef<HTMLDivElement>(null);\n\n const { ref: refProp, ...otherDropdownProps } = dropdownProps;\n const dropdownForkedRef = useForkRef(ref, refProp);\n\n const stateProps: TimeFieldStateOptions = {\n value: toTime(valueProp),\n defaultValue: toTime(defaultValueProp),\n label,\n locale,\n isRequired: required,\n isReadOnly: readOnly,\n isDisabled: disabled,\n granularity: \"second\",\n hourCycle: getFormat(timeFormat),\n onChange: (value) => {\n const { hour: hours, minute: minutes, second: seconds } = value;\n onChange?.({ hours, minutes, seconds });\n },\n };\n const state = useTimeFieldState(stateProps);\n const { labelProps, fieldProps, descriptionProps } = useTimeField(\n {\n ...stateProps,\n id,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n },\n state,\n timeFieldRef,\n );\n\n const [open, setOpen] = useState(false);\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n const [validationState] = useControlled(status, \"standBy\");\n\n const placeholders = useMemo(\n () => ({\n hour: hoursPlaceholder,\n minute: minutesPlaceholder,\n second: secondsPlaceholder,\n }),\n [hoursPlaceholder, minutesPlaceholder, secondsPlaceholder],\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 required is true\n const canShowError =\n ariaErrorMessage == null &&\n ((status !== undefined && statusMessage !== undefined) ||\n (status === undefined && required));\n\n const isStateInvalid = validationState === \"invalid\";\n const errorMessageId = isStateInvalid\n ? canShowError\n ? setId(id, \"error\")\n : ariaErrorMessage\n : undefined;\n\n return (\n <HvFormElement\n name={name}\n required={required}\n disabled={disabled}\n status={validationState}\n className={cx(classes.root, className)}\n {...others}\n >\n {(label || description) && (\n <div className={classes.labelContainer}>\n {label && (\n <HvLabel\n label={label}\n className={classes.label}\n {...labelProps}\n />\n )}\n {description && (\n <HvInfoMessage\n className={classes.description}\n {...descriptionProps}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n\n <HvBaseDropdown\n ref={dropdownForkedRef}\n role=\"combobox\"\n variableWidth\n disabled={disabled}\n readOnly={readOnly}\n placeholder={\n placeholder && !state.value ? (\n placeholder\n ) : (\n <Placeholder\n ref={timeFieldRef}\n name={name}\n state={state}\n placeholders={placeholders}\n className={cx(classes.placeholder, {\n [classes.placeholderDisabled]: disabled,\n })}\n {...fieldProps}\n />\n )\n }\n classes={{\n header: cx(classes.dropdownHeader, {\n [classes.dropdownHeaderInvalid]: isStateInvalid,\n }),\n panel: classes.dropdownPanel,\n headerOpen: classes.dropdownHeaderOpen,\n }}\n placement=\"right\"\n adornment={\n <TimeIcon\n color={disabled ? \"secondary_60\" : undefined}\n className={classes.icon}\n />\n }\n expanded={open}\n onToggle={(evt, newOpen) => {\n if (disableExpand) return;\n setOpen(newOpen);\n onToggle?.(evt, newOpen);\n }}\n onContainerCreation={(containerRef) => {\n containerRef?.getElementsByTagName(\"input\")[0]?.focus();\n }}\n aria-haspopup=\"dialog\"\n aria-label={ariaLabel}\n aria-labelledby={fieldProps[\"aria-labelledby\"]}\n aria-describedby={fieldProps[\"aria-describedby\"]}\n aria-invalid={isStateInvalid ? true : undefined}\n aria-errormessage={errorMessageId}\n disablePortal={disablePortal}\n popperProps={{\n modifiers: [\n { name: \"preventOverflow\", enabled: escapeWithReference },\n ],\n }}\n {...otherDropdownProps}\n >\n <div ref={timeFieldRef} className={classes.timePopperContainer}>\n {state.segments.map((segment, i) => (\n <Unit\n key={i}\n state={state}\n segment={segment}\n placeholder={placeholders[segment.type]}\n onAdd={() => state.increment(segment.type)}\n onSub={() => state.decrement(segment.type)}\n onChange={(evt, val) => {\n state.setSegment(segment.type, Number(val));\n }}\n />\n ))}\n </div>\n </HvBaseDropdown>\n\n {canShowError && (\n <HvWarningText\n id={setId(id, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n },\n);\n"],"names":["Time","TimeIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,SAAS,CAAC,UAAqC;AACnD,MAAI,CAAC;AAAc,WAAA;AACnB,QAAM,EAAE,OAAO,SAAS,QAAA,IAAY;AACpC,SAAO,IAAIA,OAAK,OAAO,SAAS,OAAO;AACzC;AAEA,MAAM,YAAY,CAAC,eAA4B;AAC7C,MAAI,cAAc;AAAa,WAAA;AACxB,SAAA,eAAe,OAAO,KAAK;AACpC;AA2FO,MAAM,eA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AAC;AAAA,gBAAA;AAAA,kBAEC;AAAA,kBACA;AAAA,kBACA,aAAa,aAAa,QAAQ,IAAI;AAAA,kBACtC,OAAO,MAAM,MAAM,UAAU,QAAQ,IAAI;AAAA,kBACzC,OAAO,MAAM,MAAM,UAAU,QAAQ,IAAI;AAAA,kBACzC,UAAU,CAAC,KAAK,QAAQ;AACtB,0BAAM,WAAW,QAAQ,MAAM,OAAO,GAAG,CAAC;AAAA,kBAC5C;AAAA,gBAAA;AAAA,gBARK;AAAA,cAUR,CAAA,GACH;AAAA,YAAA;AAAA,UACF;AAAA,UAEC,gBACC;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,IAAI,MAAM,IAAI,OAAO;AAAA,cACrB,eAAa;AAAA,cACb,WAAW,QAAQ;AAAA,cAElB,UAAA;AAAA,YAAA;AAAA,UACH;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;"}
1
+ {"version":3,"file":"TimePicker.js","sources":["../../../src/TimePicker/TimePicker.tsx"],"sourcesContent":["import { forwardRef, useMemo, useRef, useState } from \"react\";\nimport { Time } from \"@internationalized/date\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport { useTimeField } from \"@react-aria/datepicker\";\nimport {\n TimeFieldStateOptions,\n useTimeFieldState,\n} from \"@react-stately/datepicker\";\nimport { Time as TimeIcon } from \"@hitachivantara/uikit-react-icons\";\n\nimport { HvBaseDropdown, HvBaseDropdownProps } from \"../BaseDropdown\";\nimport {\n HvFormElement,\n HvFormElementProps,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvWarningText,\n} from \"../Forms\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useDefaultProps } from \"../hooks/useDefaultProps\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { ExtractNames } from \"../utils/classes\";\nimport { setId } from \"../utils/setId\";\nimport { Placeholder } from \"./Placeholder\";\nimport { staticClasses, useClasses } from \"./TimePicker.styles\";\nimport { Unit } from \"./Unit\";\n\nconst toTime = (value?: HvTimePickerValue | null) => {\n if (!value) return value;\n const { hours, minutes, seconds } = value;\n return new Time(hours, minutes, seconds);\n};\n\nconst getFormat = (timeFormat?: TimeFormat) => {\n if (timeFormat == null) return 24;\n return timeFormat === \"12\" ? 12 : 24;\n};\n\nexport { staticClasses as timePickerClasses };\n\nexport type TimeFormat = \"12\" | \"24\";\n\nexport type HvTimePickerClasses = ExtractNames<typeof useClasses>;\n\nexport type HvTimePickerClassKey =\n | \"root\"\n | \"input\"\n | \"label\"\n | \"placeholder\"\n | \"timePopperContainer\"\n | \"separator\"\n | \"periodContainer\"\n | \"formElementRoot\"\n | \"dropdownPlaceholder\"\n | \"iconBaseRoot\"\n | \"error\"\n | \"labelContainer\"\n | \"description\"\n | \"dropdownHeaderInvalid\"\n | \"dropdownPlaceholderDisabled\"\n | \"dropdownHeaderOpen\";\n\nexport type HvTimePickerValue = {\n hours: number;\n minutes: number;\n seconds: number;\n};\n\nexport interface HvTimePickerProps\n extends Omit<\n HvFormElementProps,\n \"classes\" | \"value\" | \"defaultValue\" | \"onChange\"\n > {\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvTimePickerClasses;\n /** Current value of the element when _controlled_. Follows the 24-hour format. */\n value?: HvTimePickerValue | null;\n /** Initial value of the element when _uncontrolled_. Follows the 24-hour format. */\n defaultValue?: HvTimePickerValue | null;\n /** The placeholder value when no time is selected. */\n placeholder?: string;\n /** The placeholder of the hours input. */\n hoursPlaceholder?: string;\n /** The placeholder of the minutes input. */\n minutesPlaceholder?: string;\n /** The placeholder of the seconds input. */\n secondsPlaceholder?: string;\n /**\n * Whether the time picker should show the AM/PM 12-hour clock or the 24-hour one.\n * If undefined, the component will use a format according to the passed locale.\n */\n timeFormat?: TimeFormat;\n /** Whether to show the seconds when using the native time picker */\n showSeconds?: boolean;\n /** Locale that will provide the time format(12 or 24 hour format). It is \"overwritten\" by `showAmPm` */\n locale?: string;\n /** Whether the dropdown is expandable. */\n disableExpand?: boolean;\n /**\n * Callback function to be triggered when the input value is changed.\n * It is invoked with a `{hours, minutes, seconds}` object, always in the 24h format\n */\n onChange?: (value: HvTimePickerValue) => void;\n /** Callback called when dropdown changes the expanded state. */\n onToggle?: (event: Event, isOpen: boolean) => void;\n /** Disable the portal behavior. The children stay within it's parent DOM hierarchy. */\n disablePortal?: boolean;\n /** Sets if the calendar container should follow the date picker input out of the screen or stay visible. */\n escapeWithReference?: boolean;\n /** Extra properties to be passed to the TimePicker's dropdown. */\n dropdownProps?: Partial<HvBaseDropdownProps>;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /**\n * Provide additional descriptive text for the form element.\n */\n description?: React.ReactNode;\n}\n\n/**\n * A Time Picker allows the user to choose a specific time or a time range.\n */\nexport const HvTimePicker = forwardRef<HTMLDivElement, HvTimePickerProps>(\n (props, ref) => {\n const {\n classes: classesProp,\n className,\n\n id: idProp,\n name,\n required = false,\n disabled = false,\n readOnly = false,\n label,\n\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n status,\n statusMessage,\n \"aria-errormessage\": ariaErrorMessage,\n\n placeholder,\n hoursPlaceholder = \"hh\",\n minutesPlaceholder = \"mm\",\n secondsPlaceholder = \"ss\",\n\n value: valueProp,\n defaultValue: defaultValueProp,\n\n timeFormat,\n showSeconds,\n disableExpand,\n locale = \"en\",\n\n onToggle,\n onChange,\n\n // misc properties:\n disablePortal = true,\n escapeWithReference = true,\n dropdownProps = {},\n ...others\n } = useDefaultProps(\"HvTimePicker\", props);\n\n const id = useUniqueId(idProp);\n\n const { classes, cx } = useClasses(classesProp);\n\n const timeFieldRef = useRef<HTMLDivElement>(null);\n\n const { ref: refProp, ...otherDropdownProps } = dropdownProps;\n const dropdownForkedRef = useForkRef(ref, refProp);\n\n const stateProps: TimeFieldStateOptions = {\n value: toTime(valueProp),\n defaultValue: toTime(defaultValueProp),\n label,\n locale,\n isRequired: required,\n isReadOnly: readOnly,\n isDisabled: disabled,\n granularity: \"second\",\n hourCycle: getFormat(timeFormat),\n onChange: (value) => {\n const { hour: hours, minute: minutes, second: seconds } = value;\n onChange?.({ hours, minutes, seconds });\n },\n };\n const state = useTimeFieldState(stateProps);\n const { labelProps, fieldProps, descriptionProps } = useTimeField(\n {\n ...stateProps,\n id,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n },\n state,\n timeFieldRef,\n );\n\n const [open, setOpen] = useState(false);\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n const [validationState] = useControlled<HvFormStatus>(status, \"standBy\");\n\n const placeholders = useMemo(\n () => ({\n hour: hoursPlaceholder,\n minute: minutesPlaceholder,\n second: secondsPlaceholder,\n }),\n [hoursPlaceholder, minutesPlaceholder, secondsPlaceholder],\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 required is true\n const canShowError =\n ariaErrorMessage == null &&\n ((status !== undefined && statusMessage !== undefined) ||\n (status === undefined && required));\n\n const isStateInvalid = validationState === \"invalid\";\n const errorMessageId = isStateInvalid\n ? canShowError\n ? setId(id, \"error\")\n : ariaErrorMessage\n : undefined;\n\n return (\n <HvFormElement\n name={name}\n required={required}\n disabled={disabled}\n status={validationState}\n className={cx(classes.root, className)}\n {...others}\n >\n {(label || description) && (\n <div className={classes.labelContainer}>\n {label && (\n <HvLabel\n label={label}\n className={classes.label}\n {...labelProps}\n />\n )}\n {description && (\n <HvInfoMessage\n className={classes.description}\n {...descriptionProps}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n\n <HvBaseDropdown\n ref={dropdownForkedRef}\n role=\"combobox\"\n variableWidth\n disabled={disabled}\n readOnly={readOnly}\n placeholder={\n placeholder && !state.value ? (\n placeholder\n ) : (\n <Placeholder\n ref={timeFieldRef}\n name={name}\n state={state}\n placeholders={placeholders}\n className={cx(classes.placeholder, {\n [classes.placeholderDisabled]: disabled,\n })}\n {...fieldProps}\n />\n )\n }\n classes={{\n header: cx(classes.dropdownHeader, {\n [classes.dropdownHeaderInvalid]: isStateInvalid,\n }),\n panel: classes.dropdownPanel,\n headerOpen: classes.dropdownHeaderOpen,\n }}\n placement=\"right\"\n adornment={\n <TimeIcon\n color={disabled ? \"secondary_60\" : undefined}\n className={classes.icon}\n />\n }\n expanded={open}\n onToggle={(evt, newOpen) => {\n if (disableExpand) return;\n setOpen(newOpen);\n onToggle?.(evt, newOpen);\n }}\n onContainerCreation={(containerRef) => {\n containerRef?.getElementsByTagName(\"input\")[0]?.focus();\n }}\n aria-haspopup=\"dialog\"\n aria-label={ariaLabel}\n aria-labelledby={fieldProps[\"aria-labelledby\"]}\n aria-describedby={fieldProps[\"aria-describedby\"]}\n aria-invalid={isStateInvalid ? true : undefined}\n aria-errormessage={errorMessageId}\n disablePortal={disablePortal}\n popperProps={{\n modifiers: [\n { name: \"preventOverflow\", enabled: escapeWithReference },\n ],\n }}\n {...otherDropdownProps}\n >\n <div ref={timeFieldRef} className={classes.timePopperContainer}>\n {state.segments.map((segment, i) => (\n <Unit\n key={i}\n state={state}\n segment={segment}\n placeholder={placeholders[segment.type]}\n onAdd={() => state.increment(segment.type)}\n onSub={() => state.decrement(segment.type)}\n onChange={(evt, val) => {\n state.setSegment(segment.type, Number(val));\n }}\n />\n ))}\n </div>\n </HvBaseDropdown>\n\n {canShowError && (\n <HvWarningText\n id={setId(id, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n },\n);\n"],"names":["Time","TimeIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,SAAS,CAAC,UAAqC;AACnD,MAAI,CAAC;AAAc,WAAA;AACnB,QAAM,EAAE,OAAO,SAAS,QAAA,IAAY;AACpC,S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BAC1D;AAAA,cACF;AAAA,cACC,GAAG;AAAA,cAEJ,UAAC,oBAAA,OAAA,EAAI,KAAK,cAAc,WAAW,QAAQ,qBACxC,UAAA,MAAM,SAAS,IAAI,CAAC,SAAS,MAC5B;AAAA,gBAAC;AAAA,gBAAA;AAAA,kBAEC;AAAA,kBACA;AAAA,kBACA,aAAa,aAAa,QAAQ,IAAI;AAAA,kBACtC,OAAO,MAAM,MAAM,UAAU,QAAQ,IAAI;AAAA,kBACzC,OAAO,MAAM,MAAM,UAAU,QAAQ,IAAI;AAAA,kBACzC,UAAU,CAAC,KAAK,QAAQ;AACtB,0BAAM,WAAW,QAAQ,MAAM,OAAO,GAAG,CAAC;AAAA,kBAC5C;AAAA,gBAAA;AAAA,gBARK;AAAA,cAUR,CAAA,GACH;AAAA,YAAA;AAAA,UACF;AAAA,UAEC,gBACC;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,IAAI,MAAM,IAAI,OAAO;AAAA,cACrB,eAAa;AAAA,cACb,WAAW,QAAQ;AAAA,cAElB,UAAA;AAAA,YAAA;AAAA,UACH;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;"}
@@ -31,7 +31,6 @@ const { useClasses, staticClasses } = createClasses("HvTimePicker", {
31
31
  dropdownPanel: {},
32
32
  icon: {},
33
33
  timePopperContainer: {
34
- backgroundColor: theme.colors.atmo1,
35
34
  zIndex: 10,
36
35
  display: "flex",
37
36
  flexDirection: "row",
@@ -1 +1 @@
1
- {"version":3,"file":"TimePicker.styles.js","sources":["../../../src/TimePicker/TimePicker.styles.ts"],"sourcesContent":["import { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { createClasses } from \"../utils/classes\";\n\nexport const { useClasses, staticClasses } = createClasses(\"HvTimePicker\", {\n root: {\n position: \"relative\",\n },\n\n labelContainer: {\n display: \"flex\",\n alignItems: \"flex-start\",\n },\n label: {\n marginBottom: 6,\n display: \"block\",\n },\n description: {},\n\n placeholder: {\n display: \"flex\",\n gap: 1,\n },\n placeholderDisabled: {\n color: theme.colors.secondary_60,\n },\n\n dropdownHeader: {},\n dropdownHeaderOpen: {},\n dropdownHeaderInvalid: {\n border: `1px solid ${theme.colors.negative}`,\n \"&:hover\": {\n border: `1px solid ${theme.colors.negative}`,\n },\n },\n dropdownPanel: {},\n\n icon: {},\n\n timePopperContainer: {\n backgroundColor: theme.colors.atmo1,\n zIndex: 10,\n display: \"flex\",\n flexDirection: \"row\",\n justifyContent: \"center\",\n alignItems: \"center\",\n padding: theme.spacing(\"xs\", 0),\n userSelect: \"none\",\n minWidth: \"175px\",\n },\n\n error: {},\n});\n"],"names":[],"mappings":";;AAIO,MAAM,EAAE,YAAY,kBAAkB,cAAc,gBAAgB;AAAA,EACzE,MAAM;AAAA,IACJ,UAAU;AAAA,EACZ;AAAA,EAEA,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,YAAY;AAAA,EACd;AAAA,EACA,OAAO;AAAA,IACL,cAAc;AAAA,IACd,SAAS;AAAA,EACX;AAAA,EACA,aAAa,CAAC;AAAA,EAEd,aAAa;AAAA,IACX,SAAS;AAAA,IACT,KAAK;AAAA,EACP;AAAA,EACA,qBAAqB;AAAA,IACnB,OAAO,MAAM,OAAO;AAAA,EACtB;AAAA,EAEA,gBAAgB,CAAC;AAAA,EACjB,oBAAoB,CAAC;AAAA,EACrB,uBAAuB;AAAA,IACrB,QAAQ,aAAa,MAAM,OAAO,QAAQ;AAAA,IAC1C,WAAW;AAAA,MACT,QAAQ,aAAa,MAAM,OAAO,QAAQ;AAAA,IAC5C;AAAA,EACF;AAAA,EACA,eAAe,CAAC;AAAA,EAEhB,MAAM,CAAC;AAAA,EAEP,qBAAqB;AAAA,IACnB,iBAAiB,MAAM,OAAO;AAAA,IAC9B,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,eAAe;AAAA,IACf,gBAAgB;AAAA,IAChB,YAAY;AAAA,IACZ,SAAS,MAAM,QAAQ,MAAM,CAAC;AAAA,IAC9B,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AAAA,EAEA,OAAO,CAAC;AACV,CAAC;"}
1
+ {"version":3,"file":"TimePicker.styles.js","sources":["../../../src/TimePicker/TimePicker.styles.ts"],"sourcesContent":["import { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { createClasses } from \"../utils/classes\";\n\nexport const { useClasses, staticClasses } = createClasses(\"HvTimePicker\", {\n root: {\n position: \"relative\",\n },\n\n labelContainer: {\n display: \"flex\",\n alignItems: \"flex-start\",\n },\n label: {\n marginBottom: 6,\n display: \"block\",\n },\n description: {},\n\n placeholder: {\n display: \"flex\",\n gap: 1,\n },\n placeholderDisabled: {\n color: theme.colors.secondary_60,\n },\n\n dropdownHeader: {},\n dropdownHeaderOpen: {},\n dropdownHeaderInvalid: {\n border: `1px solid ${theme.colors.negative}`,\n \"&:hover\": {\n border: `1px solid ${theme.colors.negative}`,\n },\n },\n dropdownPanel: {},\n\n icon: {},\n\n timePopperContainer: {\n zIndex: 10,\n display: \"flex\",\n flexDirection: \"row\",\n justifyContent: \"center\",\n alignItems: \"center\",\n padding: theme.spacing(\"xs\", 0),\n userSelect: \"none\",\n minWidth: \"175px\",\n },\n\n error: {},\n});\n"],"names":[],"mappings":";;AAIO,MAAM,EAAE,YAAY,kBAAkB,cAAc,gBAAgB;AAAA,EACzE,MAAM;AAAA,IACJ,UAAU;AAAA,EACZ;AAAA,EAEA,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,YAAY;AAAA,EACd;AAAA,EACA,OAAO;AAAA,IACL,cAAc;AAAA,IACd,SAAS;AAAA,EACX;AAAA,EACA,aAAa,CAAC;AAAA,EAEd,aAAa;AAAA,IACX,SAAS;AAAA,IACT,KAAK;AAAA,EACP;AAAA,EACA,qBAAqB;AAAA,IACnB,OAAO,MAAM,OAAO;AAAA,EACtB;AAAA,EAEA,gBAAgB,CAAC;AAAA,EACjB,oBAAoB,CAAC;AAAA,EACrB,uBAAuB;AAAA,IACrB,QAAQ,aAAa,MAAM,OAAO,QAAQ;AAAA,IAC1C,WAAW;AAAA,MACT,QAAQ,aAAa,MAAM,OAAO,QAAQ;AAAA,IAC5C;AAAA,EACF;AAAA,EACA,eAAe,CAAC;AAAA,EAEhB,MAAM,CAAC;AAAA,EAEP,qBAAqB;AAAA,IACnB,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,eAAe;AAAA,IACf,gBAAgB;AAAA,IAChB,YAAY;AAAA,IACZ,SAAS,MAAM,QAAQ,MAAM,CAAC;AAAA,IAC9B,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AAAA,EAEA,OAAO,CAAC;AACV,CAAC;"}
@@ -43,7 +43,7 @@ const HvTreeItem = forwardRef(
43
43
  () => ({ element: treeItemElement, id: nodeId }),
44
44
  [nodeId, treeItemElement]
45
45
  );
46
- const { index, parentId } = useDescendant(descendant);
46
+ const { index, parentId, level } = useDescendant(descendant);
47
47
  const expandable = !!(Array.isArray(children) ? children.length : children);
48
48
  const expanded = instance ? instance.isNodeExpanded(nodeId) : false;
49
49
  const focused = instance ? instance.isNodeFocused(nodeId) : false;
@@ -120,7 +120,7 @@ const HvTreeItem = forwardRef(
120
120
  ...contentProps
121
121
  }
122
122
  ),
123
- children && /* @__PURE__ */ jsx(DescendantProvider, { id: nodeId, children: /* @__PURE__ */ jsx(
123
+ children && /* @__PURE__ */ jsx(DescendantProvider, { id: nodeId, level: level + 1, children: /* @__PURE__ */ jsx(
124
124
  Collapse,
125
125
  {
126
126
  component: "ul",
@@ -1 +1 @@
1
- {"version":3,"file":"TreeItem.js","sources":["../../../../src/TreeView/TreeItem/TreeItem.tsx"],"sourcesContent":["import { forwardRef, useEffect, useMemo, useRef, useState } from \"react\";\nimport Collapse from \"@mui/material/Collapse\";\nimport { TransitionProps } from \"@mui/material/transitions\";\n\nimport { useDefaultProps } from \"../../hooks/useDefaultProps\";\nimport { useForkRef } from \"../../hooks/useForkRef\";\nimport { ExtractNames } from \"../../utils/classes\";\nimport {\n DescendantProvider,\n TreeItemDescendant,\n useDescendant,\n} from \"../internals/DescendantProvider\";\nimport { DefaultTreeViewPlugins } from \"../internals/hooks/plugins\";\nimport { useTreeViewContext } from \"../internals/TreeViewProvider\";\nimport { DefaultContent, HvTreeContentClasses } from \"./DefaultContent\";\nimport { staticClasses, useClasses } from \"./TreeItem.styles\";\n\nexport { staticClasses as treeItemClasses };\n\nexport type HvTreeItemClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvTreeContentProps extends React.HTMLAttributes<HTMLElement> {\n /** className applied to the root element. */\n className?: string;\n /** Override or extend the styles applied to the component. */\n classes?: HvTreeContentClasses;\n /** The tree node label. */\n label?: React.ReactNode;\n /** The id of the node. */\n nodeId: string;\n /** The icon to display next to the tree node's label. */\n icon?: React.ReactNode;\n /** The icon to display next to the tree node's label. Either an expansion or collapse icon. */\n expansionIcon?: React.ReactNode;\n /** The icon to display next to the tree node's label. Either a parent or end icon. */\n displayIcon?: React.ReactNode;\n}\n\nexport interface HvTreeItemProps extends React.HTMLAttributes<HTMLElement> {\n /** The element id */\n id?: string;\n /** The id of the node. */\n nodeId: string;\n /** The tree node label. */\n label?: React.ReactNode;\n /** Override or extend the styles applied to the component. */\n classes?: HvTreeItemClasses;\n /** If `true`, the node is disabled. */\n disabled?: boolean;\n /** The icon to display next to the tree node's label. */\n icon?: React.ReactNode;\n /** The component used for the content node. */\n ContentComponent?: React.JSXElementConstructor<HvTreeContentProps>;\n /** Props applied to the content component */\n ContentProps?: HvTreeContentProps;\n /** The content of the component. */\n children?: React.ReactNode;\n /** className applied to the root element. */\n className?: string;\n /** The icon used to collapse the node. */\n collapseIcon?: React.ReactNode;\n /** The icon displayed next to an end node. */\n endIcon?: React.ReactNode;\n /** The icon used to expand the node. */\n expandIcon?: React.ReactNode;\n /** The component used for the transition. */\n TransitionComponent?: React.JSXElementConstructor<TransitionProps>;\n /** Props applied to the transition component */\n TransitionProps?: TransitionProps;\n}\n\nexport const HvTreeItem = forwardRef<HTMLLIElement, HvTreeItemProps>(\n (props, ref) => {\n const {\n id: idProp,\n nodeId,\n children,\n classes: classesProp,\n className,\n label,\n disabled: disabledProp,\n icon,\n endIcon,\n expandIcon,\n collapseIcon,\n ContentComponent: Component = DefaultContent,\n TransitionProps: transitionProps,\n ContentProps: contentProps,\n ...others\n } = useDefaultProps(\"HvTreeItem\", props);\n const { classes, cx } = useClasses(classesProp);\n\n const {\n instance,\n multiSelect,\n disabledItemsFocusable,\n treeId,\n icons: contextIcons,\n } = useTreeViewContext<DefaultTreeViewPlugins>();\n\n const id =\n idProp || (treeId && nodeId && `${treeId}-${nodeId}`) || undefined;\n\n const [treeItemElement, setTreeItemElement] =\n useState<HTMLLIElement | null>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const handleRef = useForkRef(setTreeItemElement, ref);\n\n const descendant = useMemo<TreeItemDescendant>(\n () => ({ element: treeItemElement!, id: nodeId }),\n [nodeId, treeItemElement],\n );\n\n const { index, parentId } = useDescendant(descendant);\n\n const expandable = !!(Array.isArray(children) ? children.length : children);\n const expanded = instance ? instance.isNodeExpanded(nodeId) : false;\n const focused = instance ? instance.isNodeFocused(nodeId) : false;\n const selected = instance ? instance.isNodeSelected(nodeId) : false;\n const disabled = instance ? instance.isNodeDisabled(nodeId) : false;\n\n const expansionIcon = !expanded\n ? expandIcon || contextIcons.defaultExpandIcon\n : collapseIcon || contextIcons.defaultCollapseIcon;\n\n const displayIcon = expandable\n ? contextIcons.defaultParentIcon\n : endIcon || contextIcons.defaultEndIcon;\n\n useEffect(() => {\n // On the first render a node's index will be -1. We want to wait for the real index.\n if (instance && index !== -1) {\n instance.updateNode({\n id: nodeId,\n idAttribute: id,\n index,\n parentId,\n expandable,\n disabled: disabledProp,\n });\n\n return () => instance.removeNode(nodeId);\n }\n\n return undefined;\n }, [instance, parentId, index, nodeId, expandable, disabledProp, id]);\n\n useEffect(() => {\n if (instance && label) {\n return instance.mapFirstChar(\n nodeId,\n (contentRef.current?.textContent ?? \"\").substring(0, 1).toLowerCase(),\n );\n }\n return undefined;\n }, [instance, nodeId, label]);\n\n const handleFocus = (event: React.FocusEvent<HTMLLIElement>) => {\n // DOM focus stays on the tree which manages focus with aria-activedescendant\n if (event.target === event.currentTarget) {\n const rootElement: any =\n typeof event.target.getRootNode === \"function\"\n ? event.target.getRootNode()\n : event.target.ownerDocument || document;\n\n rootElement.getElementById(treeId).focus({ preventScroll: true });\n }\n\n const unfocusable = !disabledItemsFocusable && disabled;\n const canFocus =\n instance &&\n !focused &&\n !disabled &&\n !unfocusable &&\n event.currentTarget === event.target;\n\n if (canFocus) {\n instance.focusNode(event, nodeId);\n }\n };\n\n return (\n <li\n id={id}\n ref={handleRef}\n role=\"treeitem\"\n aria-expanded={expandable ? expanded : undefined}\n aria-selected={(multiSelect && selected) || selected || undefined}\n aria-disabled={disabled || undefined}\n className={cx(classes.root, className)}\n // @ts-ignore\n onFocus={handleFocus}\n tabIndex={-1}\n {...others}\n >\n <Component\n ref={contentRef}\n nodeId={nodeId}\n classes={{\n root: classes.content,\n expanded: classes.expanded,\n selected: classes.selected,\n focused: classes.focused,\n disabled: classes.disabled,\n label: classes.label,\n iconContainer: classes.iconContainer,\n }}\n label={label}\n icon={icon}\n expansionIcon={expandable && expansionIcon}\n displayIcon={displayIcon}\n {...contentProps}\n />\n {children && (\n <DescendantProvider id={nodeId}>\n <Collapse\n component=\"ul\"\n role=\"group\"\n unmountOnExit\n className={classes.group}\n in={expanded}\n {...transitionProps}\n >\n {children}\n </Collapse>\n </DescendantProvider>\n )}\n </li>\n );\n },\n);\n"],"names":[],"mappings":";;;;;;;;;;AAuEO,MAAM,aAAa;AAAA,EACxB,CAAC,OAAO,QAAQ;AACR,UAAA;AAAA,MACJ,IAAI;AAAA,MACJ;AAAA,MACA;AAAA,MACA,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,kBAAkB,YAAY;AAAA,MAC9B,iBAAiB;AAAA,MACjB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ACA;AAAA,cACA,eAAe,cAAc;AAAA,cAC7B;AAAA,cACC,GAAG;AAAA,YAAA;AAAA,UACN;AAAA,UACC,YACC,oBAAC,oBAAmB,EAAA,IAAI,QACtB,UAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,WAAU;AAAA,cACV,MAAK;AAAA,cACL,eAAa;AAAA,cACb,WAAW,QAAQ;AAAA,cACnB,IAAI;AAAA,cACH,GAAG;AAAA,cAEH;AAAA,YAAA;AAAA,UAAA,GAEL;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;"}
1
+ {"version":3,"file":"TreeItem.js","sources":["../../../../src/TreeView/TreeItem/TreeItem.tsx"],"sourcesContent":["import { forwardRef, useEffect, useMemo, useRef, useState } from \"react\";\nimport Collapse from \"@mui/material/Collapse\";\nimport { TransitionProps } from \"@mui/material/transitions\";\n\nimport { useDefaultProps } from \"../../hooks/useDefaultProps\";\nimport { useForkRef } from \"../../hooks/useForkRef\";\nimport { ExtractNames } from \"../../utils/classes\";\nimport {\n DescendantProvider,\n TreeItemDescendant,\n useDescendant,\n} from \"../internals/DescendantProvider\";\nimport { DefaultTreeViewPlugins } from \"../internals/hooks/plugins\";\nimport { useTreeViewContext } from \"../internals/TreeViewProvider\";\nimport { DefaultContent, HvTreeContentClasses } from \"./DefaultContent\";\nimport { staticClasses, useClasses } from \"./TreeItem.styles\";\n\nexport { staticClasses as treeItemClasses };\n\nexport type HvTreeItemClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvTreeContentProps extends React.HTMLAttributes<HTMLElement> {\n /** className applied to the root element. */\n className?: string;\n /** Override or extend the styles applied to the component. */\n classes?: HvTreeContentClasses;\n /** The tree node label. */\n label?: React.ReactNode;\n /** The id of the node. */\n nodeId: string;\n /** The icon to display next to the tree node's label. */\n icon?: React.ReactNode;\n /** The icon to display next to the tree node's label. Either an expansion or collapse icon. */\n expansionIcon?: React.ReactNode;\n /** The icon to display next to the tree node's label. Either a parent or end icon. */\n displayIcon?: React.ReactNode;\n}\n\nexport interface HvTreeItemProps extends React.HTMLAttributes<HTMLElement> {\n /** The element id */\n id?: string;\n /** The id of the node. */\n nodeId: string;\n /** The tree node label. */\n label?: React.ReactNode;\n /** Override or extend the styles applied to the component. */\n classes?: HvTreeItemClasses;\n /** If `true`, the node is disabled. */\n disabled?: boolean;\n /** The icon to display next to the tree node's label. */\n icon?: React.ReactNode;\n /** The component used for the content node. */\n ContentComponent?: React.JSXElementConstructor<HvTreeContentProps>;\n /** Props applied to the content component */\n ContentProps?: HvTreeContentProps;\n /** The content of the component. */\n children?: React.ReactNode;\n /** className applied to the root element. */\n className?: string;\n /** The icon used to collapse the node. */\n collapseIcon?: React.ReactNode;\n /** The icon displayed next to an end node. */\n endIcon?: React.ReactNode;\n /** The icon used to expand the node. */\n expandIcon?: React.ReactNode;\n /** The component used for the transition. */\n TransitionComponent?: React.JSXElementConstructor<TransitionProps>;\n /** Props applied to the transition component */\n TransitionProps?: TransitionProps;\n}\n\nexport const HvTreeItem = forwardRef<HTMLLIElement, HvTreeItemProps>(\n (props, ref) => {\n const {\n id: idProp,\n nodeId,\n children,\n classes: classesProp,\n className,\n label,\n disabled: disabledProp,\n icon,\n endIcon,\n expandIcon,\n collapseIcon,\n ContentComponent: Component = DefaultContent,\n TransitionProps: transitionProps,\n ContentProps: contentProps,\n ...others\n } = useDefaultProps(\"HvTreeItem\", props);\n const { classes, cx } = useClasses(classesProp);\n\n const {\n instance,\n multiSelect,\n disabledItemsFocusable,\n treeId,\n icons: contextIcons,\n } = useTreeViewContext<DefaultTreeViewPlugins>();\n\n const id =\n idProp || (treeId && nodeId && `${treeId}-${nodeId}`) || undefined;\n\n const [treeItemElement, setTreeItemElement] =\n useState<HTMLLIElement | null>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const handleRef = useForkRef(setTreeItemElement, ref);\n\n const descendant = useMemo<TreeItemDescendant>(\n () => ({ element: treeItemElement!, id: nodeId }),\n [nodeId, treeItemElement],\n );\n\n const { index, parentId, level } = useDescendant(descendant);\n\n const expandable = !!(Array.isArray(children) ? children.length : children);\n const expanded = instance ? instance.isNodeExpanded(nodeId) : false;\n const focused = instance ? instance.isNodeFocused(nodeId) : false;\n const selected = instance ? instance.isNodeSelected(nodeId) : false;\n const disabled = instance ? instance.isNodeDisabled(nodeId) : false;\n\n const expansionIcon = !expanded\n ? expandIcon || contextIcons.defaultExpandIcon\n : collapseIcon || contextIcons.defaultCollapseIcon;\n\n const displayIcon = expandable\n ? contextIcons.defaultParentIcon\n : endIcon || contextIcons.defaultEndIcon;\n\n useEffect(() => {\n // On the first render a node's index will be -1. We want to wait for the real index.\n if (instance && index !== -1) {\n instance.updateNode({\n id: nodeId,\n idAttribute: id,\n index,\n parentId,\n expandable,\n disabled: disabledProp,\n });\n\n return () => instance.removeNode(nodeId);\n }\n\n return undefined;\n }, [instance, parentId, index, nodeId, expandable, disabledProp, id]);\n\n useEffect(() => {\n if (instance && label) {\n return instance.mapFirstChar(\n nodeId,\n (contentRef.current?.textContent ?? \"\").substring(0, 1).toLowerCase(),\n );\n }\n return undefined;\n }, [instance, nodeId, label]);\n\n const handleFocus = (event: React.FocusEvent<HTMLLIElement>) => {\n // DOM focus stays on the tree which manages focus with aria-activedescendant\n if (event.target === event.currentTarget) {\n const rootElement: any =\n typeof event.target.getRootNode === \"function\"\n ? event.target.getRootNode()\n : event.target.ownerDocument || document;\n\n rootElement.getElementById(treeId).focus({ preventScroll: true });\n }\n\n const unfocusable = !disabledItemsFocusable && disabled;\n const canFocus =\n instance &&\n !focused &&\n !disabled &&\n !unfocusable &&\n event.currentTarget === event.target;\n\n if (canFocus) {\n instance.focusNode(event, nodeId);\n }\n };\n\n return (\n <li\n id={id}\n ref={handleRef}\n role=\"treeitem\"\n aria-expanded={expandable ? expanded : undefined}\n aria-selected={(multiSelect && selected) || selected || undefined}\n aria-disabled={disabled || undefined}\n className={cx(classes.root, className)}\n // @ts-ignore\n onFocus={handleFocus}\n tabIndex={-1}\n {...others}\n >\n <Component\n ref={contentRef}\n nodeId={nodeId}\n classes={{\n root: classes.content,\n expanded: classes.expanded,\n selected: classes.selected,\n focused: classes.focused,\n disabled: classes.disabled,\n label: classes.label,\n iconContainer: classes.iconContainer,\n }}\n label={label}\n icon={icon}\n expansionIcon={expandable && expansionIcon}\n displayIcon={displayIcon}\n {...contentProps}\n />\n {children && (\n <DescendantProvider id={nodeId} level={level + 1}>\n <Collapse\n component=\"ul\"\n role=\"group\"\n unmountOnExit\n className={classes.group}\n in={expanded}\n {...transitionProps}\n >\n {children}\n </Collapse>\n </DescendantProvider>\n )}\n </li>\n );\n },\n);\n"],"names":[],"mappings":";;;;;;;;;;AAuEO,MAAM,aAAa;AAAA,EACxB,CAAC,OAAO,QAAQ;AACR,UAAA;AAAA,MACJ,IAAI;AAAA,MACJ;AAAA,MACA;AAAA,MACA,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,kBAAkB,YAAY;AAAA,MAC9B,iBAAiB;AAAA,MACjB,cAAc;AAAA,MACd,GAAG;AAAA,IAAA,IACD,gBAAgB,cAAc,KAAK;AACvC,UAAM,EAAE,SAAS,GAAG,IAAI,WAAW,WAAW;AAExC,UAAA;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO;AAAA,QACL,mBAA2C;AAEzC,UAAA,KACJ,UAAW,UAAU,UAAU,GAAG,MAAM,IAAI,MAAM,MAAO;AAE3D,UAAM,CAAC,iBAAiB,kBAAkB,IACxC,SAA+B,IAAI;AAC/B,UAAA,aAAa,OAAuB,IAAI;AACxC,UAAA,YAAY,WAAW,oBAAoB,GAAG;AAEpD,UAAM,aAAa;AAAA,MACjB,OAAO,EAAE,SAAS,iBAAkB,IAAI,OAAO;AAAA,MAC/C,CAAC,QAAQ,eAAe;AAAA,IAAA;AAG1B,UAAM,EAAE,OAAO,UAAU,MAAM,IAAI,cA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eACD,MAAM,kBAAkB,MAAM;AAEhC,UAAI,UAAU;AACH,iBAAA,UAAU,OAAO,MAAM;AAAA,MAClC;AAAA,IAAA;AAIA,WAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,KAAK;AAAA,QACL,MAAK;AAAA,QACL,iBAAe,aAAa,WAAW;AAAA,QACvC,iBAAgB,eAAe,YAAa,YAAY;AAAA,QACxD,iBAAe,YAAY;AAAA,QAC3B,WAAW,GAAG,QAAQ,MAAM,SAAS;AAAA,QAErC,SAAS;AAAA,QACT,UAAU;AAAA,QACT,GAAG;AAAA,QAEJ,UAAA;AAAA,UAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,KAAK;AAAA,cACL;AAAA,cACA,SAAS;AAAA,gBACP,MAAM,QAAQ;AAAA,gBACd,UAAU,QAAQ;AAAA,gBAClB,UAAU,QAAQ;AAAA,gBAClB,SAAS,QAAQ;AAAA,gBACjB,UAAU,QAAQ;AAAA,gBAClB,OAAO,QAAQ;AAAA,gBACf,eAAe,QAAQ;AAAA,cACzB;AAAA,cACA;AAAA,cACA;AAAA,cACA,eAAe,cAAc;AAAA,cAC7B;AAAA,cACC,GAAG;AAAA,YAAA;AAAA,UACN;AAAA,UACC,YACE,oBAAA,oBAAA,EAAmB,IAAI,QAAQ,OAAO,QAAQ,GAC7C,UAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,WAAU;AAAA,cACV,MAAK;AAAA,cACL,eAAa;AAAA,cACb,WAAW,QAAQ;AAAA,cACnB,IAAI;AAAA,cACH,GAAG;AAAA,cAEH;AAAA,YAAA;AAAA,UAAA,GAEL;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;"}
@@ -59,9 +59,11 @@ const { staticClasses, useClasses } = createClasses("HvTreeItem", {
59
59
  display: "flex",
60
60
  flexShrink: 0,
61
61
  justifyContent: "center",
62
- width: 16,
63
- // TODO: review
64
- marginRight: 4
62
+ marginRight: 4,
63
+ width: theme.space.sm,
64
+ ":empty": {
65
+ width: theme.space.xs
66
+ }
65
67
  }
66
68
  });
67
69
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"TreeItem.styles.js","sources":["../../../../src/TreeView/TreeItem/TreeItem.styles.ts"],"sourcesContent":["import { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { createClasses } from \"../../utils/classes\";\nimport { outlineStyles } from \"../../utils/focusUtils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvTreeItem\", {\n /** Applied to the root element */\n root: {\n listStyle: \"none\",\n margin: 0,\n padding: 0,\n outline: 0,\n },\n group: {\n margin: 0,\n padding: 0,\n marginLeft: theme.space.sm,\n },\n\n content: {\n padding: theme.spacing(0, 1),\n minHeight: 32, // TODO: review\n\n width: \"100%\",\n boxSizing: \"border-box\", // prevent width + padding to overflow\n display: \"flex\",\n alignItems: \"center\",\n cursor: \"pointer\",\n WebkitTapHighlightColor: \"transparent\",\n \"&:hover:not($disabled)\": {\n backgroundColor: theme.colors.containerBackgroundHover,\n },\n },\n expanded: {},\n selected: {\n backgroundColor: theme.colors.atmo3,\n },\n focused: {\n backgroundColor: theme.colors.containerBackgroundHover,\n \"&:focus-visible\": {\n ...outlineStyles,\n },\n },\n disabled: {\n cursor: \"not-allowed\",\n color: theme.colors.secondary_60,\n \"& $label\": {\n color: theme.colors.secondary_60,\n },\n },\n label: {\n paddingLeft: 4,\n width: \"100%\",\n boxSizing: \"border-box\",\n\n // fixes overflow\n minWidth: 0,\n position: \"relative\",\n ...theme.typography.body,\n },\n iconContainer: {\n display: \"flex\",\n flexShrink: 0,\n justifyContent: \"center\",\n\n width: 16, // TODO: review\n marginRight: 4,\n },\n});\n"],"names":[],"mappings":";;;AAKO,MAAM,EAAE,eAAe,eAAe,cAAc,cAAc;AAAA;AAAA,EAEvE,MAAM;AAAA,IACJ,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,EACX;AAAA,EACA,OAAO;AAAA,IACL,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,YAAY,MAAM,MAAM;AAAA,EAC1B;AAAA,EAEA,SAAS;AAAA,IACP,SAAS,MAAM,QAAQ,GAAG,CAAC;AAAA,IAC3B,WAAW;AAAA;AAAA,IAEX,OAAO;AAAA,IACP,WAAW;AAAA;AAAA,IACX,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,yBAAyB;AAAA,IACzB,0BAA0B;AAAA,MACxB,iBAAiB,MAAM,OAAO;AAAA,IAChC;AAAA,EACF;AAAA,EACA,UAAU,CAAC;AAAA,EACX,UAAU;AAAA,IACR,iBAAiB,MAAM,OAAO;AAAA,EAChC;AAAA,EACA,SAAS;AAAA,IACP,iBAAiB,MAAM,OAAO;AAAA,IAC9B,mBAAmB;AAAA,MACjB,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EACA,UAAU;AAAA,IACR,QAAQ;AAAA,IACR,OAAO,MAAM,OAAO;AAAA,IACpB,YAAY;AAAA,MACV,OAAO,MAAM,OAAO;AAAA,IACtB;AAAA,EACF;AAAA,EACA,OAAO;AAAA,IACL,aAAa;AAAA,IACb,OAAO;AAAA,IACP,WAAW;AAAA;AAAA,IAGX,UAAU;AAAA,IACV,UAAU;AAAA,IACV,GAAG,MAAM,WAAW;AAAA,EACtB;AAAA,EACA,eAAe;AAAA,IACb,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAEhB,OAAO;AAAA;AAAA,IACP,aAAa;AAAA,EACf;AACF,CAAC;"}
1
+ {"version":3,"file":"TreeItem.styles.js","sources":["../../../../src/TreeView/TreeItem/TreeItem.styles.ts"],"sourcesContent":["import { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { createClasses } from \"../../utils/classes\";\nimport { outlineStyles } from \"../../utils/focusUtils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvTreeItem\", {\n /** Applied to the root element */\n root: {\n listStyle: \"none\",\n margin: 0,\n padding: 0,\n outline: 0,\n },\n group: {\n margin: 0,\n padding: 0,\n marginLeft: theme.space.sm,\n },\n\n content: {\n padding: theme.spacing(0, 1),\n minHeight: 32, // TODO: review\n\n width: \"100%\",\n boxSizing: \"border-box\", // prevent width + padding to overflow\n display: \"flex\",\n alignItems: \"center\",\n cursor: \"pointer\",\n WebkitTapHighlightColor: \"transparent\",\n \"&:hover:not($disabled)\": {\n backgroundColor: theme.colors.containerBackgroundHover,\n },\n },\n expanded: {},\n selected: {\n backgroundColor: theme.colors.atmo3,\n },\n focused: {\n backgroundColor: theme.colors.containerBackgroundHover,\n \"&:focus-visible\": {\n ...outlineStyles,\n },\n },\n disabled: {\n cursor: \"not-allowed\",\n color: theme.colors.secondary_60,\n \"& $label\": {\n color: theme.colors.secondary_60,\n },\n },\n label: {\n paddingLeft: 4,\n width: \"100%\",\n boxSizing: \"border-box\",\n\n // fixes overflow\n minWidth: 0,\n position: \"relative\",\n ...theme.typography.body,\n },\n iconContainer: {\n display: \"flex\",\n flexShrink: 0,\n justifyContent: \"center\",\n\n marginRight: 4,\n width: theme.space.sm,\n \":empty\": {\n width: theme.space.xs,\n },\n },\n});\n"],"names":[],"mappings":";;;AAKO,MAAM,EAAE,eAAe,eAAe,cAAc,cAAc;AAAA;AAAA,EAEvE,MAAM;AAAA,IACJ,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,EACX;AAAA,EACA,OAAO;AAAA,IACL,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,YAAY,MAAM,MAAM;AAAA,EAC1B;AAAA,EAEA,SAAS;AAAA,IACP,SAAS,MAAM,QAAQ,GAAG,CAAC;AAAA,IAC3B,WAAW;AAAA;AAAA,IAEX,OAAO;AAAA,IACP,WAAW;AAAA;AAAA,IACX,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,yBAAyB;AAAA,IACzB,0BAA0B;AAAA,MACxB,iBAAiB,MAAM,OAAO;AAAA,IAChC;AAAA,EACF;AAAA,EACA,UAAU,CAAC;AAAA,EACX,UAAU;AAAA,IACR,iBAAiB,MAAM,OAAO;AAAA,EAChC;AAAA,EACA,SAAS;AAAA,IACP,iBAAiB,MAAM,OAAO;AAAA,IAC9B,mBAAmB;AAAA,MACjB,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EACA,UAAU;AAAA,IACR,QAAQ;AAAA,IACR,OAAO,MAAM,OAAO;AAAA,IACpB,YAAY;AAAA,MACV,OAAO,MAAM,OAAO;AAAA,IACtB;AAAA,EACF;AAAA,EACA,OAAO;AAAA,IACL,aAAa;AAAA,IACb,OAAO;AAAA,IACP,WAAW;AAAA;AAAA,IAGX,UAAU;AAAA,IACV,UAAU;AAAA,IACV,GAAG,MAAM,WAAW;AAAA,EACtB;AAAA,EACA,eAAe;AAAA,IACb,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAEhB,aAAa;AAAA,IACb,OAAO,MAAM,MAAM;AAAA,IACnB,UAAU;AAAA,MACR,OAAO,MAAM,MAAM;AAAA,IACrB;AAAA,EACF;AACF,CAAC;"}
@@ -1,6 +1,9 @@
1
+ import * as React from "react";
2
+ import { DescendantContext } from "../internals/DescendantProvider.js";
1
3
  import { useTreeViewContext } from "../internals/TreeViewProvider.js";
2
4
  function useHvTreeItem(nodeId) {
3
5
  const { instance, multiSelect } = useTreeViewContext();
6
+ const { level = 0 } = React.useContext(DescendantContext);
4
7
  const expandable = instance ? instance.isNodeExpandable(nodeId) : false;
5
8
  const expanded = instance ? instance.isNodeExpanded(nodeId) : false;
6
9
  const focused = instance ? instance.isNodeFocused(nodeId) : false;
@@ -41,6 +44,7 @@ function useHvTreeItem(nodeId) {
41
44
  };
42
45
  return {
43
46
  instance,
47
+ level,
44
48
  disabled,
45
49
  expanded,
46
50
  selected,
@@ -1 +1 @@
1
- {"version":3,"file":"useHvTreeItem.js","sources":["../../../../src/TreeView/TreeItem/useHvTreeItem.ts"],"sourcesContent":["import * as React from \"react\";\n\nimport { DefaultTreeViewPlugins } from \"../internals/hooks/plugins\";\nimport { useTreeViewContext } from \"../internals/TreeViewProvider\";\n\nexport function useHvTreeItem(nodeId: string) {\n const { instance, multiSelect } =\n useTreeViewContext<DefaultTreeViewPlugins>();\n\n const expandable = instance ? instance.isNodeExpandable(nodeId) : false;\n const expanded = instance ? instance.isNodeExpanded(nodeId) : false;\n const focused = instance ? instance.isNodeFocused(nodeId) : false;\n const selected = instance ? instance.isNodeSelected(nodeId) : false;\n const disabled = instance ? instance.isNodeDisabled(nodeId) : false;\n\n const handleExpansion = (event: React.MouseEvent<HTMLDivElement>) => {\n if (!instance || disabled) return;\n\n if (!focused) {\n instance.focusNode(event, nodeId);\n }\n\n const multiple =\n multiSelect && (event.shiftKey || event.ctrlKey || event.metaKey);\n\n // If already expanded and trying to toggle selection don't close\n if (expandable && !(multiple && instance.isNodeExpanded(nodeId))) {\n instance.toggleNodeExpansion(event, nodeId);\n }\n };\n\n const handleSelection = (event: React.MouseEvent<HTMLDivElement>) => {\n if (!instance || disabled) return;\n\n if (!focused) {\n instance.focusNode(event, nodeId);\n }\n\n const multiple =\n multiSelect && (event.shiftKey || event.ctrlKey || event.metaKey);\n\n if (multiple) {\n if (event.shiftKey) {\n instance.selectRange(event, { end: nodeId });\n } else {\n instance.selectNode(event, nodeId, true);\n }\n } else {\n instance.selectNode(event, nodeId);\n }\n };\n\n const preventSelection = (event: React.MouseEvent<HTMLDivElement>) => {\n if (event.shiftKey || event.ctrlKey || event.metaKey || disabled) {\n // Prevent text selection\n event.preventDefault();\n }\n };\n\n return {\n instance,\n disabled,\n expanded,\n selected,\n focused,\n handleExpansion,\n handleSelection,\n preventSelection,\n };\n}\n"],"names":[],"mappings":";AAKO,SAAS,cAAc,QAAgB;AAC5C,QAAM,EAAE,UAAU,YAAY,IAC5B,mBAA2C;AAE7C,QAAM,aAAa,WAAW,SAAS,iBAAiB,MAAM,IAAI;AAClE,QAAM,WAAW,WAAW,SAAS,eAAe,MAAM,IAAI;AAC9D,QAAM,UAAU,WAAW,SAAS,cAAc,MAAM,IAAI;AAC5D,QAAM,WAAW,WAAW,SAAS,eAAe,MAAM,IAAI;AAC9D,QAAM,WAAW,WAAW,SAAS,eAAe,MAAM,IAAI;AAExD,QAAA,kBAAkB,CAAC,UAA4C;AACnE,QAAI,CAAC,YAAY;AAAU;AAE3B,QAAI,CAAC,SAAS;AACH,eAAA,UAAU,OAAO,MAAM;AAAA,IAClC;AAEA,UAAM,WACJ,gBAAgB,MAAM,YAAY,MAAM,WAAW,MAAM;AAG3D,QAAI,cAAc,EAAE,YAAY,SAAS,eAAe,MAAM,IAAI;AACvD,eAAA,oBAAoB,OAAO,MAAM;AAAA,IAC5C;AAAA,EAAA;AAGI,QAAA,kBAAkB,CAAC,UAA4C;AACnE,QAAI,CAAC,YAAY;AAAU;AAE3B,QAAI,CAAC,SAAS;AACH,eAAA,UAAU,OAAO,MAAM;AAAA,IAClC;AAEA,UAAM,WACJ,gBAAgB,MAAM,YAAY,MAAM,WAAW,MAAM;AAE3D,QAAI,UAAU;AACZ,UAAI,MAAM,UAAU;AAClB,iBAAS,YAAY,OAAO,EAAE,KAAK,OAAQ,CAAA;AAAA,MAAA,OACtC;AACI,iBAAA,WAAW,OAAO,QAAQ,IAAI;AAAA,MACzC;AAAA,IAAA,OACK;AACI,eAAA,WAAW,OAAO,MAAM;AAAA,IACnC;AAAA,EAAA;AAGI,QAAA,mBAAmB,CAAC,UAA4C;AACpE,QAAI,MAAM,YAAY,MAAM,WAAW,MAAM,WAAW,UAAU;AAEhE,YAAM,eAAe;AAAA,IACvB;AAAA,EAAA;AAGK,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useHvTreeItem.js","sources":["../../../../src/TreeView/TreeItem/useHvTreeItem.ts"],"sourcesContent":["import * as React from \"react\";\n\nimport { DescendantContext } from \"../internals/DescendantProvider\";\nimport { DefaultTreeViewPlugins } from \"../internals/hooks/plugins\";\nimport { useTreeViewContext } from \"../internals/TreeViewProvider\";\n\nexport function useHvTreeItem(nodeId: string) {\n const { instance, multiSelect } =\n useTreeViewContext<DefaultTreeViewPlugins>();\n const { level = 0 } = React.useContext(DescendantContext);\n\n const expandable = instance ? instance.isNodeExpandable(nodeId) : false;\n const expanded = instance ? instance.isNodeExpanded(nodeId) : false;\n const focused = instance ? instance.isNodeFocused(nodeId) : false;\n const selected = instance ? instance.isNodeSelected(nodeId) : false;\n const disabled = instance ? instance.isNodeDisabled(nodeId) : false;\n\n const handleExpansion = (event: React.MouseEvent<HTMLDivElement>) => {\n if (!instance || disabled) return;\n\n if (!focused) {\n instance.focusNode(event, nodeId);\n }\n\n const multiple =\n multiSelect && (event.shiftKey || event.ctrlKey || event.metaKey);\n\n // If already expanded and trying to toggle selection don't close\n if (expandable && !(multiple && instance.isNodeExpanded(nodeId))) {\n instance.toggleNodeExpansion(event, nodeId);\n }\n };\n\n const handleSelection = (event: React.MouseEvent<HTMLDivElement>) => {\n if (!instance || disabled) return;\n\n if (!focused) {\n instance.focusNode(event, nodeId);\n }\n\n const multiple =\n multiSelect && (event.shiftKey || event.ctrlKey || event.metaKey);\n\n if (multiple) {\n if (event.shiftKey) {\n instance.selectRange(event, { end: nodeId });\n } else {\n instance.selectNode(event, nodeId, true);\n }\n } else {\n instance.selectNode(event, nodeId);\n }\n };\n\n const preventSelection = (event: React.MouseEvent<HTMLDivElement>) => {\n if (event.shiftKey || event.ctrlKey || event.metaKey || disabled) {\n // Prevent text selection\n event.preventDefault();\n }\n };\n\n return {\n instance,\n level,\n disabled,\n expanded,\n selected,\n focused,\n handleExpansion,\n handleSelection,\n preventSelection,\n };\n}\n"],"names":[],"mappings":";;;AAMO,SAAS,cAAc,QAAgB;AAC5C,QAAM,EAAE,UAAU,YAAY,IAC5B,mBAA2C;AAC7C,QAAM,EAAE,QAAQ,EAAA,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AAA,EAAA;AAEJ;"}
@@ -1,14 +1,6 @@
1
1
  import { jsx } from "@emotion/react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import { unstable_useEnhancedEffect } from "@mui/material/utils";
4
- function findIndex(array, comp) {
5
- for (let i = 0; i < array.length; i += 1) {
6
- if (comp(array[i])) {
7
- return i;
8
- }
9
- }
10
- return -1;
11
- }
12
4
  function binaryFindElement(array, element) {
13
5
  let start = 0;
14
6
  let end = array.length - 1;
@@ -28,7 +20,9 @@ function binaryFindElement(array, element) {
28
20
  }
29
21
  return start;
30
22
  }
31
- const DescendantContext = React.createContext({});
23
+ const DescendantContext = React.createContext({
24
+ level: 0
25
+ });
32
26
  function usePrevious(value) {
33
27
  const ref = React.useRef(null);
34
28
  React.useEffect(() => {
@@ -44,10 +38,10 @@ function useDescendant(descendant) {
44
38
  registerDescendant = noop,
45
39
  unregisterDescendant = noop,
46
40
  descendants = [],
47
- parentId = null
41
+ parentId = null,
42
+ level = 0
48
43
  } = React.useContext(DescendantContext);
49
- const index = findIndex(
50
- descendants,
44
+ const index = descendants.findIndex(
51
45
  (item) => item.element === descendant.element
52
46
  );
53
47
  const previousDescendants = usePrevious(descendants);
@@ -75,10 +69,10 @@ function useDescendant(descendant) {
75
69
  someDescendantsHaveChanged,
76
70
  descendant
77
71
  ]);
78
- return { parentId, index };
72
+ return { parentId, index, level };
79
73
  }
80
74
  const DescendantProvider = (props) => {
81
- const { children, id } = props;
75
+ const { children, id, level } = props;
82
76
  const [items, set] = React.useState([]);
83
77
  const registerDescendant = React.useCallback(
84
78
  ({ element, ...other }) => {
@@ -121,13 +115,15 @@ const DescendantProvider = (props) => {
121
115
  descendants: items,
122
116
  registerDescendant,
123
117
  unregisterDescendant,
124
- parentId: id
118
+ parentId: id,
119
+ level
125
120
  }),
126
- [items, registerDescendant, unregisterDescendant, id]
121
+ [items, registerDescendant, unregisterDescendant, id, level]
127
122
  );
128
123
  return /* @__PURE__ */ jsx(DescendantContext.Provider, { value, children });
129
124
  };
130
125
  export {
126
+ DescendantContext,
131
127
  DescendantProvider,
132
128
  useDescendant
133
129
  };
@@ -1 +1 @@
1
- {"version":3,"file":"DescendantProvider.js","sources":["../../../../src/TreeView/internals/DescendantProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { unstable_useEnhancedEffect as useEnhancedEffect } from \"@mui/material/utils\";\n\n/** Credit: https://github.com/reach/reach-ui/blob/86a046f54d53b6420e392b3fa56dd991d9d4e458/packages/descendants/README.md\n * Modified slightly to suit our purposes.\n */\n\n// To replace with .findIndex() once we stop IE11 support.\nfunction findIndex<T>(array: T[], comp: (item: T) => boolean) {\n for (let i = 0; i < array.length; i += 1) {\n if (comp(array[i])) {\n return i;\n }\n }\n\n return -1;\n}\n\nfunction binaryFindElement(\n array: TreeItemDescendant[],\n element: HTMLLIElement,\n) {\n let start = 0;\n let end = array.length - 1;\n\n while (start <= end) {\n const middle = Math.floor((start + end) / 2);\n\n if (array[middle].element === element) {\n return middle;\n }\n\n if (\n // eslint-disable-next-line no-bitwise\n array[middle].element.compareDocumentPosition(element) &\n Node.DOCUMENT_POSITION_PRECEDING\n ) {\n end = middle - 1;\n } else {\n start = middle + 1;\n }\n }\n\n return start;\n}\n\nexport interface TreeItemDescendant {\n element: HTMLLIElement;\n id: string;\n}\n\ninterface DescendantContextValue {\n registerDescendant?: (params: TreeItemDescendant & { index: number }) => void;\n unregisterDescendant?: (params: HTMLLIElement) => void;\n descendants?: TreeItemDescendant[];\n parentId?: string | null;\n}\n\nconst DescendantContext = React.createContext<DescendantContextValue>({});\n\nfunction usePrevious<T>(value: T) {\n const ref = React.useRef<T | null>(null);\n React.useEffect(() => {\n ref.current = value;\n }, [value]);\n return ref.current;\n}\n\nconst noop = () => {};\n\n/**\n * This hook registers our descendant by passing it into an array. We can then\n * search that array by to find its index when registering it in the component.\n * We use this for focus management, keyboard navigation, and typeahead\n * functionality for some components.\n *\n * The hook accepts the element node\n *\n * Our main goals with this are:\n * 1) maximum composability,\n * 2) minimal API friction\n * 3) SSR compatibility*\n * 4) concurrent safe\n * 5) index always up-to-date with the tree despite changes\n * 6) works with memoization of any component in the tree (hopefully)\n *\n * * As for SSR, the good news is that we don't actually need the index on the\n * server for most use-cases, as we are only using it to determine the order of\n * composed descendants for keyboard navigation.\n */\nexport function useDescendant(descendant: TreeItemDescendant) {\n const [, forceUpdate] = React.useState<{}>();\n const {\n registerDescendant = noop,\n unregisterDescendant = noop,\n descendants = [],\n parentId = null,\n } = React.useContext(DescendantContext);\n\n // This will initially return -1 because we haven't registered the descendant\n // on the first render. After we register, this will then return the correct\n // index on the following render, and we will re-register descendants\n // so that everything is up-to-date before the user interacts with a\n // collection.\n const index = findIndex(\n descendants,\n (item) => item.element === descendant.element,\n );\n\n const previousDescendants = usePrevious(descendants);\n\n // We also need to re-register descendants any time ANY of the other\n // descendants have changed. My brain was melting when I wrote this and it\n // feels a little off, but checking in render and using the result in the\n // effect's dependency array works well enough.\n const someDescendantsHaveChanged = descendants.some(\n (newDescendant, position) => {\n return (\n previousDescendants &&\n previousDescendants[position] &&\n previousDescendants[position].element !== newDescendant.element\n );\n },\n );\n\n // Prevent any flashing\n useEnhancedEffect(() => {\n if (descendant.element) {\n registerDescendant({\n ...descendant,\n index,\n });\n return () => {\n unregisterDescendant(descendant.element!);\n };\n }\n forceUpdate({});\n\n return undefined;\n }, [\n registerDescendant,\n unregisterDescendant,\n index,\n someDescendantsHaveChanged,\n descendant,\n ]);\n\n return { parentId, index };\n}\n\ninterface DescendantProviderProps {\n id?: string;\n children: React.ReactNode;\n}\n\nexport const DescendantProvider = (props: DescendantProviderProps) => {\n const { children, id } = props;\n\n const [items, set] = React.useState<\n (TreeItemDescendant & { index: number })[]\n >([]);\n\n const registerDescendant = React.useCallback(\n ({ element, ...other }: TreeItemDescendant) => {\n set((oldItems) => {\n if (oldItems.length === 0) {\n // If there are no items, register at index 0 and bail.\n return [\n {\n ...other,\n element,\n index: 0,\n },\n ];\n }\n\n const index = binaryFindElement(oldItems, element);\n let newItems: typeof oldItems;\n\n if (oldItems[index] && oldItems[index].element === element) {\n // If the element is already registered, just use the same array\n newItems = oldItems;\n } else {\n // When registering a descendant, we need to make sure we insert in\n // into the array in the same order that it appears in the DOM. So as\n // new descendants are added or maybe some are removed, we always know\n // that the array is up-to-date and correct.\n //\n // So here we look at our registered descendants and see if the new\n // element we are adding appears earlier than an existing descendant's\n // DOM node via `node.compareDocumentPosition`. If it does, we insert\n // the new element at this index. Because `registerDescendant` will be\n // called in an effect every time the descendants state value changes,\n // we should be sure that this index is accurate when descendent\n // elements come or go from our component.\n\n const newItem = {\n ...other,\n element,\n index,\n };\n\n // If an index is not found we will push the element to the end.\n newItems = oldItems.slice();\n newItems.splice(index, 0, newItem);\n }\n newItems.forEach((item, position) => {\n item.index = position;\n });\n return newItems;\n });\n },\n [],\n );\n\n const unregisterDescendant = React.useCallback((element: HTMLLIElement) => {\n set((oldItems) => oldItems.filter((item) => element !== item.element));\n }, []);\n\n const value = React.useMemo(\n () => ({\n descendants: items,\n registerDescendant,\n unregisterDescendant,\n parentId: id,\n }),\n [items, registerDescendant, unregisterDescendant, id],\n );\n\n return (\n <DescendantContext.Provider value={value}>\n {children}\n </DescendantContext.Provider>\n );\n};\n"],"names":["useEnhancedEffect"],"mappings":";;;AAQA,SAAS,UAAa,OAAY,MAA4B;AAC5D,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,GAAG;AACxC,QAAI,KAAK,MAAM,CAAC,CAAC,GAAG;AACX,aAAA;AAAA,IACT;AAAA,EACF;AAEO,SAAA;AACT;AAEA,SAAS,kBACP,OACA,SACA;AACA,MAAI,QAAQ;AACR,MAAA,MAAM,MAAM,SAAS;AAEzB,SAAO,SAAS,KAAK;AACnB,UAAM,SAAS,KAAK,OAAO,QAAQ,OAAO,CAAC;AAE3C,QAAI,MAAM,MAAM,EAAE,YAAY,SAAS;AAC9B,aAAA;AAAA,IACT;AAEA;AAAA;AAAA,MAEE,MAAM,MAAM,EAAE,Q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AAU,GAAO,IAAA;AAEzB,QAAM,CAAC,OAAO,GAAG,IAAI,MAAM,SAEzB,CAAA,CAAE;AAEJ,QAAM,qBAAqB,MAAM;AAAA,IAC/B,CAAC,EAAE,SAAS,GAAG,YAAgC;AAC7C,UAAI,CAAC,aAAa;AACZ,YAAA,SAAS,WAAW,GAAG;AAElB,iBAAA;AAAA,YACL;AAAA,cACE,GAAG;AAAA,cACH;AAAA,cACA,OAAO;AAAA,YACT;AAAA,UAAA;AAAA,QAEJ;AAEM,cAAA,QAAQ,kBAAkB,UAAU,OAAO;AAC7C,YAAA;AAEJ,YAAI,SAAS,KAAK,KAAK,SAAS,KAAK,EAAE,YAAY,SAAS;AAE/C,qBAAA;AAAA,QAAA,OACN;AAcL,gBAAM,UAAU;AAAA,YACd,GAAG;AAAA,YACH;AAAA,YACA;AAAA,UAAA;AAIF,qBAAW,SAAS;AACX,mBAAA,OAAO,OAAO,GAAG,OAAO;AAAA,QACnC;AACS,iBAAA,QAAQ,CAAC,MAAM,aAAa;AACnC,eAAK,QAAQ;AAAA,QAAA,CACd;AACM,eAAA;AAAA,MAAA,CACR;AAAA,IACH;AAAA,IACA,CAAC;AAAA,EAAA;AAGH,QAAM,uBAAuB,MAAM,YAAY,CAAC,YAA2B;AACrE,QAAA,CAAC,aAAa,SAAS,OAAO,CAAC,SAAS,YAAY,KAAK,OAAO,CAAC;AAAA,EACvE,GAAG,CAAE,CAAA;AAEL,QAAM,QAAQ,MAAM;AAAA,IAClB,OAAO;AAAA,MACL,aAAa;AAAA,MACb;AAAA,MACA;AAAA,MACA,UAAU;AAAA,IAAA;AAAA,IAEZ,CAAC,OAAO,oBAAoB,sBAAsB,EAAE;AAAA,EAAA;AAGtD,SACG,oBAAA,kBAAkB,UAAlB,EAA2B,OACzB,SACH,CAAA;AAEJ;"}
1
+ {"version":3,"file":"DescendantProvider.js","sources":["../../../../src/TreeView/internals/DescendantProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { unstable_useEnhancedEffect as useEnhancedEffect } from \"@mui/material/utils\";\n\n/** Credit: https://github.com/reach/reach-ui/blob/86a046f54d53b6420e392b3fa56dd991d9d4e458/packages/descendants/README.md\n * Modified slightly to suit our purposes.\n */\n\nfunction binaryFindElement(\n array: TreeItemDescendant[],\n element: HTMLLIElement,\n) {\n let start = 0;\n let end = array.length - 1;\n\n while (start <= end) {\n const middle = Math.floor((start + end) / 2);\n\n if (array[middle].element === element) {\n return middle;\n }\n\n if (\n // eslint-disable-next-line no-bitwise\n array[middle].element.compareDocumentPosition(element) &\n Node.DOCUMENT_POSITION_PRECEDING\n ) {\n end = middle - 1;\n } else {\n start = middle + 1;\n }\n }\n\n return start;\n}\n\nexport interface TreeItemDescendant {\n element: HTMLLIElement;\n id: string;\n}\n\ninterface DescendantContextValue {\n registerDescendant?: (params: TreeItemDescendant & { index: number }) => void;\n unregisterDescendant?: (params: HTMLLIElement) => void;\n descendants?: TreeItemDescendant[];\n parentId?: string | null;\n level?: number;\n}\n\nexport const DescendantContext = React.createContext<DescendantContextValue>({\n level: 0,\n});\n\nfunction usePrevious<T>(value: T) {\n const ref = React.useRef<T | null>(null);\n React.useEffect(() => {\n ref.current = value;\n }, [value]);\n return ref.current;\n}\n\nconst noop = () => {};\n\n/**\n * This hook registers our descendant by passing it into an array. We can then\n * search that array by to find its index when registering it in the component.\n * We use this for focus management, keyboard navigation, and typeahead\n * functionality for some components.\n *\n * The hook accepts the element node\n *\n * Our main goals with this are:\n * 1) maximum composability,\n * 2) minimal API friction\n * 3) SSR compatibility*\n * 4) concurrent safe\n * 5) index always up-to-date with the tree despite changes\n * 6) works with memoization of any component in the tree (hopefully)\n *\n * * As for SSR, the good news is that we don't actually need the index on the\n * server for most use-cases, as we are only using it to determine the order of\n * composed descendants for keyboard navigation.\n */\nexport function useDescendant(descendant: TreeItemDescendant) {\n const [, forceUpdate] = React.useState<{}>();\n const {\n registerDescendant = noop,\n unregisterDescendant = noop,\n descendants = [],\n parentId = null,\n level = 0,\n } = React.useContext(DescendantContext);\n\n // This will initially return -1 because we haven't registered the descendant\n // on the first render. After we register, this will then return the correct\n // index on the following render, and we will re-register descendants\n // so that everything is up-to-date before the user interacts with a\n // collection.\n const index = descendants.findIndex(\n (item) => item.element === descendant.element,\n );\n\n const previousDescendants = usePrevious(descendants);\n\n // We also need to re-register descendants any time ANY of the other\n // descendants have changed. My brain was melting when I wrote this and it\n // feels a little off, but checking in render and using the result in the\n // effect's dependency array works well enough.\n const someDescendantsHaveChanged = descendants.some(\n (newDescendant, position) => {\n return (\n previousDescendants &&\n previousDescendants[position] &&\n previousDescendants[position].element !== newDescendant.element\n );\n },\n );\n\n // Prevent any flashing\n useEnhancedEffect(() => {\n if (descendant.element) {\n registerDescendant({\n ...descendant,\n index,\n });\n return () => {\n unregisterDescendant(descendant.element!);\n };\n }\n forceUpdate({});\n\n return undefined;\n }, [\n registerDescendant,\n unregisterDescendant,\n index,\n someDescendantsHaveChanged,\n descendant,\n ]);\n\n return { parentId, index, level };\n}\n\ninterface DescendantProviderProps {\n id?: string;\n level?: number;\n children: React.ReactNode;\n}\n\nexport const DescendantProvider = (props: DescendantProviderProps) => {\n const { children, id, level } = props;\n\n const [items, set] = React.useState<\n (TreeItemDescendant & { index: number })[]\n >([]);\n\n const registerDescendant = React.useCallback(\n ({ element, ...other }: TreeItemDescendant) => {\n set((oldItems) => {\n if (oldItems.length === 0) {\n // If there are no items, register at index 0 and bail.\n return [\n {\n ...other,\n element,\n index: 0,\n },\n ];\n }\n\n const index = binaryFindElement(oldItems, element);\n let newItems: typeof oldItems;\n\n if (oldItems[index] && oldItems[index].element === element) {\n // If the element is already registered, just use the same array\n newItems = oldItems;\n } else {\n // When registering a descendant, we need to make sure we insert in\n // into the array in the same order that it appears in the DOM. So as\n // new descendants are added or maybe some are removed, we always know\n // that the array is up-to-date and correct.\n //\n // So here we look at our registered descendants and see if the new\n // element we are adding appears earlier than an existing descendant's\n // DOM node via `node.compareDocumentPosition`. If it does, we insert\n // the new element at this index. Because `registerDescendant` will be\n // called in an effect every time the descendants state value changes,\n // we should be sure that this index is accurate when descendent\n // elements come or go from our component.\n\n const newItem = {\n ...other,\n element,\n index,\n };\n\n // If an index is not found we will push the element to the end.\n newItems = oldItems.slice();\n newItems.splice(index, 0, newItem);\n }\n newItems.forEach((item, position) => {\n item.index = position;\n });\n return newItems;\n });\n },\n [],\n );\n\n const unregisterDescendant = React.useCallback((element: HTMLLIElement) => {\n set((oldItems) => oldItems.filter((item) => element !== item.element));\n }, []);\n\n const value = React.useMemo(\n () => ({\n descendants: items,\n registerDescendant,\n unregisterDescendant,\n parentId: id,\n level,\n }),\n [items, registerDescendant, unregisterDescendant, id, level],\n );\n\n return (\n <DescendantContext.Provider value={value}>\n {children}\n </DescendantContext.Provider>\n );\n};\n"],"names":["useEnhancedEffect"],"mappings":";;;AAOA,SAAS,kBACP,OACA,SACA;AACA,MAAI,QAAQ;AACR,MAAA,MAAM,MAAM,SAAS;AAEzB,SAAO,SAAS,KAAK;AACnB,UAAM,SAAS,KAAK,OAAO,QAAQ,OAAO,CAAC;AAE3C,QAAI,MAAM,MAAM,EAAE,YAAY,SAAS;AAC9B,aAAA;AAAA,IACT;AAEA;AAAA;AAAA,MAEE,MAAM,MAAM,EAAE,QAAQ,wBAAwB,OAAO,IACrD,KAAK;AAAA,MACL;AACA,YAAM,SAAS;AAAA,IAAA,OACV;AACL,cAAQ,SAAS;AAAA,IACnB;AAAA,EACF;AAEO,SAAA;AACT;AAea,MAAA,oBAAoB,MAAM,cAAsC;AAAA,EAC3E,OAAO;AACT,CAAC;AAED,SAAS,YAAe,OAAU;AAC1B,QAAA,MAAM,MAAM,OAAiB,IAAI;AACvC,QAAM,UAAU,MAAM;AACpB,QAAI,UAAU;AAAA,EAAA,GACb,CAAC,KAAK,CAAC;AACV,SAAO,IAAI;AACb;AAEA,MAAM,OAAO,MAAM;AAAC;AAsBb,SAAS,cAAc,YAAgC;AAC5D,QAAM,GAAG,WAAW,IAAI,MAAM,SAAa;AACr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