@hitachivantara/uikit-react-core 5.30.1 → 5.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/cjs/components/ActionBar/ActionBar.styles.cjs +1 -1
  2. package/dist/cjs/components/ActionBar/ActionBar.styles.cjs.map +1 -1
  3. package/dist/cjs/components/BaseCheckBox/BaseCheckBox.cjs +4 -4
  4. package/dist/cjs/components/BaseCheckBox/BaseCheckBox.cjs.map +1 -1
  5. package/dist/cjs/components/BaseDropdown/BaseDropdown.cjs +3 -2
  6. package/dist/cjs/components/BaseDropdown/BaseDropdown.cjs.map +1 -1
  7. package/dist/cjs/components/BaseRadio/BaseRadio.cjs +3 -3
  8. package/dist/cjs/components/BaseRadio/BaseRadio.cjs.map +1 -1
  9. package/dist/cjs/components/BaseSwitch/BaseSwitch.cjs +3 -3
  10. package/dist/cjs/components/BaseSwitch/BaseSwitch.cjs.map +1 -1
  11. package/dist/cjs/components/BreadCrumb/BreadCrumb.cjs +1 -1
  12. package/dist/cjs/components/BreadCrumb/BreadCrumb.cjs.map +1 -1
  13. package/dist/cjs/components/BreadCrumb/Page/Page.cjs +10 -8
  14. package/dist/cjs/components/BreadCrumb/Page/Page.cjs.map +1 -1
  15. package/dist/cjs/components/BreadCrumb/Page/Page.styles.cjs +3 -3
  16. package/dist/cjs/components/BreadCrumb/Page/Page.styles.cjs.map +1 -1
  17. package/dist/cjs/components/CheckBox/CheckBox.cjs +3 -3
  18. package/dist/cjs/components/CheckBox/CheckBox.cjs.map +1 -1
  19. package/dist/cjs/components/CheckBoxGroup/CheckBoxGroup.cjs +3 -3
  20. package/dist/cjs/components/CheckBoxGroup/CheckBoxGroup.cjs.map +1 -1
  21. package/dist/cjs/components/ColorPicker/ColorPicker.cjs +4 -3
  22. package/dist/cjs/components/ColorPicker/ColorPicker.cjs.map +1 -1
  23. package/dist/cjs/components/DatePicker/DatePicker.cjs +12 -6
  24. package/dist/cjs/components/DatePicker/DatePicker.cjs.map +1 -1
  25. package/dist/cjs/components/Dropdown/Dropdown.cjs +12 -4
  26. package/dist/cjs/components/Dropdown/Dropdown.cjs.map +1 -1
  27. package/dist/cjs/components/FilterGroup/FilterContent/FilterContent.cjs +3 -3
  28. package/dist/cjs/components/FilterGroup/FilterContent/FilterContent.cjs.map +1 -1
  29. package/dist/cjs/components/FilterGroup/FilterGroup.cjs +4 -3
  30. package/dist/cjs/components/FilterGroup/FilterGroup.cjs.map +1 -1
  31. package/dist/cjs/components/Header/Navigation/MenuItem/MenuItem.cjs +12 -1
  32. package/dist/cjs/components/Header/Navigation/MenuItem/MenuItem.cjs.map +1 -1
  33. package/dist/cjs/components/InlineEditor/InlineEditor.cjs +3 -2
  34. package/dist/cjs/components/InlineEditor/InlineEditor.cjs.map +1 -1
  35. package/dist/cjs/components/InlineEditor/InlineEditor.styles.cjs +2 -2
  36. package/dist/cjs/components/InlineEditor/InlineEditor.styles.cjs.map +1 -1
  37. package/dist/cjs/components/List/List.cjs.map +1 -1
  38. package/dist/cjs/components/ListContainer/ListContainer.cjs +2 -2
  39. package/dist/cjs/components/ListContainer/ListContainer.cjs.map +1 -1
  40. package/dist/cjs/components/QueryBuilder/Context.cjs.map +1 -1
  41. package/dist/cjs/components/QueryBuilder/QueryBuilder.cjs.map +1 -1
  42. package/dist/cjs/components/Radio/Radio.cjs +3 -3
  43. package/dist/cjs/components/Radio/Radio.cjs.map +1 -1
  44. package/dist/cjs/components/RadioGroup/RadioGroup.cjs +3 -3
  45. package/dist/cjs/components/RadioGroup/RadioGroup.cjs.map +1 -1
  46. package/dist/cjs/components/Section/Section.cjs +50 -0
  47. package/dist/cjs/components/Section/Section.cjs.map +1 -0
  48. package/dist/cjs/components/Section/Section.styles.cjs +40 -0
  49. package/dist/cjs/components/Section/Section.styles.cjs.map +1 -0
  50. package/dist/cjs/components/SelectionList/SelectionList.cjs +7 -5
  51. package/dist/cjs/components/SelectionList/SelectionList.cjs.map +1 -1
  52. package/dist/cjs/components/Slider/Slider.cjs +5 -5
  53. package/dist/cjs/components/Slider/Slider.cjs.map +1 -1
  54. package/dist/cjs/components/Switch/Switch.cjs +3 -3
  55. package/dist/cjs/components/Switch/Switch.cjs.map +1 -1
  56. package/dist/cjs/components/TagsInput/TagsInput.cjs +5 -3
  57. package/dist/cjs/components/TagsInput/TagsInput.cjs.map +1 -1
  58. package/dist/cjs/components/TimePicker/TimePicker.cjs +14 -8
  59. package/dist/cjs/components/TimePicker/TimePicker.cjs.map +1 -1
  60. package/dist/cjs/index.cjs +8 -0
  61. package/dist/cjs/index.cjs.map +1 -1
  62. package/dist/esm/components/ActionBar/ActionBar.styles.js +1 -1
  63. package/dist/esm/components/ActionBar/ActionBar.styles.js.map +1 -1
  64. package/dist/esm/components/BaseCheckBox/BaseCheckBox.js +5 -5
  65. package/dist/esm/components/BaseCheckBox/BaseCheckBox.js.map +1 -1
  66. package/dist/esm/components/BaseDropdown/BaseDropdown.js +4 -3
  67. package/dist/esm/components/BaseDropdown/BaseDropdown.js.map +1 -1
  68. package/dist/esm/components/BaseRadio/BaseRadio.js +4 -4
  69. package/dist/esm/components/BaseRadio/BaseRadio.js.map +1 -1
  70. package/dist/esm/components/BaseSwitch/BaseSwitch.js +4 -4
  71. package/dist/esm/components/BaseSwitch/BaseSwitch.js.map +1 -1
  72. package/dist/esm/components/BreadCrumb/BreadCrumb.js +2 -2
  73. package/dist/esm/components/BreadCrumb/BreadCrumb.js.map +1 -1
  74. package/dist/esm/components/BreadCrumb/Page/Page.js +10 -8
  75. package/dist/esm/components/BreadCrumb/Page/Page.js.map +1 -1
  76. package/dist/esm/components/BreadCrumb/Page/Page.styles.js +3 -3
  77. package/dist/esm/components/BreadCrumb/Page/Page.styles.js.map +1 -1
  78. package/dist/esm/components/CheckBox/CheckBox.js +4 -4
  79. package/dist/esm/components/CheckBox/CheckBox.js.map +1 -1
  80. package/dist/esm/components/CheckBoxGroup/CheckBoxGroup.js +4 -4
  81. package/dist/esm/components/CheckBoxGroup/CheckBoxGroup.js.map +1 -1
  82. package/dist/esm/components/ColorPicker/ColorPicker.js +4 -3
  83. package/dist/esm/components/ColorPicker/ColorPicker.js.map +1 -1
  84. package/dist/esm/components/DatePicker/DatePicker.js +13 -7
  85. package/dist/esm/components/DatePicker/DatePicker.js.map +1 -1
  86. package/dist/esm/components/Dropdown/Dropdown.js +13 -5
  87. package/dist/esm/components/Dropdown/Dropdown.js.map +1 -1
  88. package/dist/esm/components/FilterGroup/FilterContent/FilterContent.js +4 -4
  89. package/dist/esm/components/FilterGroup/FilterContent/FilterContent.js.map +1 -1
  90. package/dist/esm/components/FilterGroup/FilterGroup.js +4 -3
  91. package/dist/esm/components/FilterGroup/FilterGroup.js.map +1 -1
  92. package/dist/esm/components/Header/Navigation/MenuItem/MenuItem.js +12 -1
  93. package/dist/esm/components/Header/Navigation/MenuItem/MenuItem.js.map +1 -1
  94. package/dist/esm/components/InlineEditor/InlineEditor.js +3 -2
  95. package/dist/esm/components/InlineEditor/InlineEditor.js.map +1 -1
  96. package/dist/esm/components/InlineEditor/InlineEditor.styles.js +2 -2
  97. package/dist/esm/components/InlineEditor/InlineEditor.styles.js.map +1 -1
  98. package/dist/esm/components/List/List.js.map +1 -1
  99. package/dist/esm/components/ListContainer/ListContainer.js +2 -2
  100. package/dist/esm/components/ListContainer/ListContainer.js.map +1 -1
  101. package/dist/esm/components/QueryBuilder/Context.js.map +1 -1
  102. package/dist/esm/components/QueryBuilder/QueryBuilder.js.map +1 -1
  103. package/dist/esm/components/Radio/Radio.js +4 -4
  104. package/dist/esm/components/Radio/Radio.js.map +1 -1
  105. package/dist/esm/components/RadioGroup/RadioGroup.js +4 -4
  106. package/dist/esm/components/RadioGroup/RadioGroup.js.map +1 -1
  107. package/dist/esm/components/Section/Section.js +51 -0
  108. package/dist/esm/components/Section/Section.js.map +1 -0
  109. package/dist/esm/components/Section/Section.styles.js +40 -0
  110. package/dist/esm/components/Section/Section.styles.js.map +1 -0
  111. package/dist/esm/components/SelectionList/SelectionList.js +8 -6
  112. package/dist/esm/components/SelectionList/SelectionList.js.map +1 -1
  113. package/dist/esm/components/Slider/Slider.js +5 -5
  114. package/dist/esm/components/Slider/Slider.js.map +1 -1
  115. package/dist/esm/components/Switch/Switch.js +4 -4
  116. package/dist/esm/components/Switch/Switch.js.map +1 -1
  117. package/dist/esm/components/TagsInput/TagsInput.js +6 -4
  118. package/dist/esm/components/TagsInput/TagsInput.js.map +1 -1
  119. package/dist/esm/components/TimePicker/TimePicker.js +15 -9
  120. package/dist/esm/components/TimePicker/TimePicker.js.map +1 -1
  121. package/dist/esm/index.js +8 -0
  122. package/dist/esm/index.js.map +1 -1
  123. package/dist/types/index.d.ts +398 -187
  124. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"CheckBox.cjs","sources":["../../../../src/components/CheckBox/CheckBox.tsx"],"sourcesContent":["import { useCallback, useState } from \"react\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { useUniqueId } from \"@core/hooks/useUniqueId\";\nimport { useControlled } from \"@core/hooks/useControlled\";\nimport { setId } from \"@core/utils/setId\";\nimport {\n HvBaseCheckBox,\n HvBaseCheckBoxProps,\n} from \"@core/components/BaseCheckBox\";\nimport {\n HvLabelProps,\n HvFormStatus,\n HvWarningText,\n isInvalid,\n HvFormElement,\n HvLabel,\n} from \"@core/components/Forms\";\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { staticClasses, useClasses } from \"./CheckBox.styles\";\n\nexport { staticClasses as checkBoxClasses };\n\nexport type HvCheckBoxClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvCheckBoxProps extends Omit<HvBaseCheckBoxProps, \"classes\"> {\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be inputted via inputProps.\n */\n label?: React.ReactNode;\n /**\n * Properties passed on to the label element.\n */\n labelProps?: HvLabelProps;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvFormStatus;\n /**\n * The error message to show when the validation status is \"invalid\".\n *\n * Defaults to \"Required\" when the status is uncontrolled and no `aria-errormessage` is provided.\n */\n statusMessage?: React.ReactNode;\n /**\n * A Jss Object used to override or extend the styles applied to the checkbox.\n */\n classes?: HvCheckBoxClasses;\n}\n\n/**\n * A Checkbox is a mechanism that allows the user to select one or more options.\n *\n * Usually used in a Checkbox Group to present the user with a range of options from\n * which the user <b>may select any number of options</b> to complete their task.\n *\n * It can also be used individually to represent the toggle of a single option, when\n * the Toggle Switch and Toggle Button aren't more appropriate.\n */\nexport const HvCheckBox = (props: HvCheckBoxProps) => {\n const {\n id,\n classes: classesProp,\n className,\n name,\n checked,\n status,\n indeterminate,\n statusMessage,\n label,\n labelProps,\n inputProps,\n value = \"on\",\n required = false,\n readOnly = false,\n disabled = false,\n semantic = false,\n defaultChecked = false,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-errormessage\": ariaErrorMessage,\n onChange,\n onFocusVisible,\n onBlur,\n ...others\n } = useDefaultProps(\"HvCheckBox\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const elementId = useUniqueId(id, \"hvcheckbox\");\n\n const [focusVisible, setFocusVisible] = useState<boolean>(false);\n\n const [validationState, setValidationState] = useControlled(\n status,\n \"standBy\"\n );\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const [isChecked, setIsChecked] = useControlled(\n checked,\n Boolean(defaultChecked)\n );\n\n const [isIndeterminate, setIsIndeterminate] = useControlled(\n checked !== undefined ? indeterminate : undefined,\n Boolean(indeterminate)\n );\n\n const isStateInvalid = isInvalid(validationState);\n\n const onChangeCallback = useCallback<\n NonNullable<HvBaseCheckBoxProps[\"onChange\"]>\n >(\n (event, newChecked) => {\n setIsChecked(() => {\n // This will only run if uncontrolled\n setIsIndeterminate(false);\n\n if (required && !newChecked) {\n setValidationState(\"invalid\");\n } else {\n setValidationState(\"valid\");\n }\n\n return newChecked;\n });\n\n onChange?.(event, newChecked, value);\n },\n [\n onChange,\n required,\n setIsChecked,\n setIsIndeterminate,\n setValidationState,\n value,\n ]\n );\n\n const onFocusVisibleCallback: HvBaseCheckBoxProps[\"onBlur\"] = (event) => {\n setFocusVisible(true);\n onFocusVisible?.(event);\n };\n\n const onBlurCallback: HvBaseCheckBoxProps[\"onBlur\"] = (event) => {\n setFocusVisible(false);\n onBlur?.(event);\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 hasLabel = label != null;\n\n let errorMessageId;\n if (isStateInvalid) {\n errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n }\n\n const checkbox = (\n <HvBaseCheckBox\n id={hasLabel ? setId(elementId, \"input\") : setId(id, \"input\")}\n name={name}\n className={cx(classes.checkbox, {\n [classes.invalidCheckbox]: isStateInvalid,\n })}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n onChange={onChangeCallback}\n value={value}\n checked={isChecked}\n indeterminate={isIndeterminate}\n semantic={semantic}\n inputProps={{\n \"aria-invalid\": isStateInvalid ? true : undefined,\n \"aria-errormessage\": errorMessageId,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n ...inputProps,\n }}\n onFocusVisible={onFocusVisibleCallback}\n onBlur={onBlurCallback}\n {...others}\n />\n );\n\n return (\n <HvFormElement\n id={id}\n name={name}\n status={validationState}\n disabled={disabled}\n required={required}\n readOnly={readOnly}\n className={cx(\n classes.root,\n { [classes.focusVisible]: !!(focusVisible && label) },\n className\n )}\n >\n {hasLabel ? (\n <div\n className={cx(classes.container, {\n [classes.disabled]: disabled,\n [classes.invalidContainer]: isStateInvalid,\n })}\n >\n {checkbox}\n <HvLabel\n id={setId(elementId, \"label\")}\n htmlFor={setId(elementId, \"input\")}\n label={label}\n className={classes.label}\n {...labelProps}\n />\n </div>\n ) : (\n checkbox\n )}\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableAdornment={!hasLabel}\n hideText={!hasLabel}\n disableBorder\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n};\n"],"names":["HvCheckBox","props","id","classes","classesProp","className","name","checked","status","indeterminate","statusMessage","label","labelProps","inputProps","value","required","readOnly","disabled","semantic","defaultChecked","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaErrorMessage","onChange","onFocusVisible","onBlur","others","useDefaultProps","cx","useClasses","elementId","useUniqueId","focusVisible","setFocusVisible","useState","validationState","setValidationState","useControlled","validationMessage","isChecked","setIsChecked","Boolean","isIndeterminate","setIsIndeterminate","undefined","isStateInvalid","isInvalid","onChangeCallback","useCallback","event","newChecked","onFocusVisibleCallback","onBlurCallback","canShowError","hasLabel","errorMessageId","setId","checkbox","jsx","HvBaseCheckBox","invalidCheckbox","jsxs","HvFormElement","root","container","invalidContainer","HvLabel","HvWarningText"],"mappings":";;;;;;;;;;;;;;AAoEaA,MAAAA,aAAaA,CAACC,UAA2B;AAC9C,QAAA;AAAA,IACJC;AAAAA,IACAC,SAASC;AAAAA,IACTC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,QAAQ;AAAA,IACRC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,iBAAiB;AAAA,IACjB,cAAcC;AAAAA,IACd,mBAAmBC;AAAAA,IACnB,oBAAoBC;AAAAA,IACpB,qBAAqBC;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S0B,MAAAA,MAAM1B,WAAW,OAAO,GACjC,OACA,WAAW5B,QAAQQ,OACnB,GAAIC,YAAW;AAAA,IAAA,EAAA,CAEnB,IAEA8C;AAAAA,IAEDJ,gBACEK,2BAAA,IAAAS,2BAAA,EACC,IAAIX,YAAM1B,WAAW,OAAO,GAC5B,kBAAkB,CAACwB,UACnB,UAAU,CAACA,UACX,eAAa,MAEZhB,UACH,mBAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ;;;"}
1
+ {"version":3,"file":"CheckBox.cjs","sources":["../../../../src/components/CheckBox/CheckBox.tsx"],"sourcesContent":["import { forwardRef, useCallback, useState } from \"react\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { useUniqueId } from \"@core/hooks/useUniqueId\";\nimport { useControlled } from \"@core/hooks/useControlled\";\nimport { setId } from \"@core/utils/setId\";\nimport {\n HvBaseCheckBox,\n HvBaseCheckBoxProps,\n} from \"@core/components/BaseCheckBox\";\nimport {\n HvLabelProps,\n HvFormStatus,\n HvWarningText,\n isInvalid,\n HvFormElement,\n HvLabel,\n} from \"@core/components/Forms\";\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { staticClasses, useClasses } from \"./CheckBox.styles\";\n\nexport { staticClasses as checkBoxClasses };\n\nexport type HvCheckBoxClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvCheckBoxProps extends Omit<HvBaseCheckBoxProps, \"classes\"> {\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be inputted via inputProps.\n */\n label?: React.ReactNode;\n /**\n * Properties passed on to the label element.\n */\n labelProps?: HvLabelProps;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvFormStatus;\n /**\n * The error message to show when the validation status is \"invalid\".\n *\n * Defaults to \"Required\" when the status is uncontrolled and no `aria-errormessage` is provided.\n */\n statusMessage?: React.ReactNode;\n /**\n * A Jss Object used to override or extend the styles applied to the checkbox.\n */\n classes?: HvCheckBoxClasses;\n}\n\n/**\n * A Checkbox is a mechanism that allows the user to select one or more options.\n *\n * Usually used in a Checkbox Group to present the user with a range of options from\n * which the user <b>may select any number of options</b> to complete their task.\n *\n * It can also be used individually to represent the toggle of a single option, when\n * the Toggle Switch and Toggle Button aren't more appropriate.\n */\nexport const HvCheckBox = forwardRef<HTMLButtonElement, HvCheckBoxProps>(\n (props, ref) => {\n const {\n id,\n classes: classesProp,\n className,\n name,\n checked,\n status,\n indeterminate,\n statusMessage,\n label,\n labelProps,\n inputProps,\n value = \"on\",\n required = false,\n readOnly = false,\n disabled = false,\n semantic = false,\n defaultChecked = false,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-errormessage\": ariaErrorMessage,\n onChange,\n onFocusVisible,\n onBlur,\n ...others\n } = useDefaultProps(\"HvCheckBox\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const elementId = useUniqueId(id, \"hvcheckbox\");\n\n const [focusVisible, setFocusVisible] = useState<boolean>(false);\n\n const [validationState, setValidationState] = useControlled(\n status,\n \"standBy\"\n );\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const [isChecked, setIsChecked] = useControlled(\n checked,\n Boolean(defaultChecked)\n );\n\n const [isIndeterminate, setIsIndeterminate] = useControlled(\n checked !== undefined ? indeterminate : undefined,\n Boolean(indeterminate)\n );\n\n const isStateInvalid = isInvalid(validationState);\n\n const onChangeCallback = useCallback<\n NonNullable<HvBaseCheckBoxProps[\"onChange\"]>\n >(\n (event, newChecked) => {\n setIsChecked(() => {\n // This will only run if uncontrolled\n setIsIndeterminate(false);\n\n if (required && !newChecked) {\n setValidationState(\"invalid\");\n } else {\n setValidationState(\"valid\");\n }\n\n return newChecked;\n });\n\n onChange?.(event, newChecked, value);\n },\n [\n onChange,\n required,\n setIsChecked,\n setIsIndeterminate,\n setValidationState,\n value,\n ]\n );\n\n const onFocusVisibleCallback: HvBaseCheckBoxProps[\"onBlur\"] = (event) => {\n setFocusVisible(true);\n onFocusVisible?.(event);\n };\n\n const onBlurCallback: HvBaseCheckBoxProps[\"onBlur\"] = (event) => {\n setFocusVisible(false);\n onBlur?.(event);\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 hasLabel = label != null;\n\n let errorMessageId;\n if (isStateInvalid) {\n errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n }\n\n const checkbox = (\n <HvBaseCheckBox\n ref={ref}\n id={hasLabel ? setId(elementId, \"input\") : setId(id, \"input\")}\n name={name}\n className={cx(classes.checkbox, {\n [classes.invalidCheckbox]: isStateInvalid,\n })}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n onChange={onChangeCallback}\n value={value}\n checked={isChecked}\n indeterminate={isIndeterminate}\n semantic={semantic}\n inputProps={{\n \"aria-invalid\": isStateInvalid ? true : undefined,\n \"aria-errormessage\": errorMessageId,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n ...inputProps,\n }}\n onFocusVisible={onFocusVisibleCallback}\n onBlur={onBlurCallback}\n {...others}\n />\n );\n\n return (\n <HvFormElement\n id={id}\n name={name}\n status={validationState}\n disabled={disabled}\n required={required}\n readOnly={readOnly}\n className={cx(\n classes.root,\n { [classes.focusVisible]: !!(focusVisible && label) },\n className\n )}\n >\n {hasLabel ? (\n <div\n className={cx(classes.container, {\n [classes.disabled]: disabled,\n [classes.invalidContainer]: isStateInvalid,\n })}\n >\n {checkbox}\n <HvLabel\n id={setId(elementId, \"label\")}\n htmlFor={setId(elementId, \"input\")}\n label={label}\n className={classes.label}\n {...labelProps}\n />\n </div>\n ) : (\n checkbox\n )}\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableAdornment={!hasLabel}\n hideText={!hasLabel}\n disableBorder\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n }\n);\n"],"names":["HvCheckBox","forwardRef","props","ref","id","classes","classesProp","className","name","checked","status","indeterminate","statusMessage","label","labelProps","inputProps","value","required","readOnly","disabled","semantic","defaultChecked","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaErrorMessage","onChange","onFocusVisible","onBlur","others","useDefaultProps","cx","useClasses","elementId","useUniqueId","focusVisible","setFocusVisible","useState","validationState","setValidationState","useControlled","validationMessage","isChecked","setIsChecked","Boolean","isIndeterminate","setIsIndeterminate","undefined","isStateInvalid","isInvalid","onChangeCallback","useCallback","event","newChecked","onFocusVisibleCallback","onBlurCallback","canShowError","hasLabel","errorMessageId","setId","checkbox","jsx","HvBaseCheckBox","invalidCheckbox","jsxs","HvFormElement","root","container","invalidContainer","HvLabel","HvWarningText"],"mappings":";;;;;;;;;;;;;;AAoEO,MAAMA,aAAaC,MAAAA,WACxB,CAACC,OAAOC,QAAQ;AACR,QAAA;AAAA,IACJC;AAAAA,IACAC,SAASC;AAAAA,IACTC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,QAAQ;AAAA,IACRC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,iBAAiB;AAAA,IACjB,cAAcC;AAAAA,IACd,mBAAmBC;AAAAA,IACnB,oBAAoBC;AAAAA,IACpB,qBAAqBC;AAAAA,IACrBC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACA,GAAGC;AAAAA,EAAAA,IACDC,gBAAgB,gBAAA,cAAc5B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EAAA,CAEnB,IAEA8C;AAAAA,IAEDJ,gBACEK,2BAAA,IAAAS,2BAAA,EACC,IAAIX,YAAM1B,WAAW,OAAO,GAC5B,kBAAkB,CAACwB,UACnB,UAAU,CAACA,UACX,eAAa,MAEZhB,UACH,mBAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ,CACF;;;"}
@@ -31,7 +31,7 @@ const getValueFromSelectedChildren = (children) => {
31
31
  }).filter((v) => v !== void 0);
32
32
  return selectedValues;
33
33
  };
34
- const HvCheckBoxGroup = (props) => {
34
+ const HvCheckBoxGroup = React.forwardRef((props, ref) => {
35
35
  const {
36
36
  id,
37
37
  classes: classesProp,
@@ -146,7 +146,7 @@ const HvCheckBoxGroup = (props) => {
146
146
  return /* @__PURE__ */ jsxRuntime.jsxs(FormElement.HvFormElement, { id, name, status: validationState, disabled, required, readOnly, className: cx(classes.root, className), children: [
147
147
  label && /* @__PURE__ */ jsxRuntime.jsx(Label.HvLabel, { id: setId.setId(elementId, "label"), label, className: classes.label }),
148
148
  description && /* @__PURE__ */ jsxRuntime.jsx(InfoMessage.HvInfoMessage, { id: setId.setId(elementId, "description"), children: description }),
149
- /* @__PURE__ */ jsxRuntime.jsxs("div", { role: "group", "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy || label && setId.setId(elementId, "label") || void 0, "aria-disabled": disabled ? true : void 0, "aria-invalid": validationState === "invalid" ? true : void 0, "aria-errormessage": validationState === "invalid" ? errorMessageId : void 0, "aria-describedby": [description && setId.setId(elementId, "description"), ariaDescribedBy].join(" ").trim() || void 0, className: cx(classes.group, {
149
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { ref, role: "group", "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy || label && setId.setId(elementId, "label") || void 0, "aria-disabled": disabled ? true : void 0, "aria-invalid": validationState === "invalid" ? true : void 0, "aria-errormessage": validationState === "invalid" ? errorMessageId : void 0, "aria-describedby": [description && setId.setId(elementId, "description"), ariaDescribedBy].join(" ").trim() || void 0, className: cx(classes.group, {
150
150
  [classes.vertical]: orientation === "vertical",
151
151
  [classes.horizontal]: orientation === "horizontal",
152
152
  [classes.invalid]: validationState === "invalid"
@@ -156,7 +156,7 @@ const HvCheckBoxGroup = (props) => {
156
156
  ] }),
157
157
  canShowError && /* @__PURE__ */ jsxRuntime.jsx(WarningText.HvWarningText, { id: setId.setId(elementId, "error"), disableBorder: true, className: classes.error, children: validationMessage })
158
158
  ] });
159
- };
159
+ });
160
160
  exports.checkBoxGroupClasses = CheckBoxGroup_styles.staticClasses;
161
161
  exports.HvCheckBoxGroup = HvCheckBoxGroup;
162
162
  //# sourceMappingURL=CheckBoxGroup.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"CheckBoxGroup.cjs","sources":["../../../../src/components/CheckBoxGroup/CheckBoxGroup.tsx"],"sourcesContent":["import { Children, cloneElement, useCallback, useMemo, useRef } from \"react\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { HvBaseProps } from \"@core/types/generic\";\nimport { useUniqueId } from \"@core/hooks/useUniqueId\";\nimport { useControlled } from \"@core/hooks/useControlled\";\nimport { setId } from \"@core/utils/setId\";\nimport { multiSelectionEventHandler } from \"@core/utils/multiSelectionEventHandler\";\nimport { HvCheckBox } from \"@core/components/CheckBox\";\nimport {\n HvFormElement,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvWarningText,\n} from \"@core/components/Forms\";\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { staticClasses, useClasses } from \"./CheckBoxGroup.styles\";\n\nconst computeSelectAllState = (selected: number, total: number) => {\n if (selected === 0) {\n return \"none\";\n }\n\n if (selected === total) {\n return \"all\";\n }\n\n return \"some\";\n};\n\nconst getValueFromSelectedChildren = (children: React.ReactNode) => {\n const selectedValues = Children.toArray(children)\n .map((child: any) => {\n const childIsControlled = child?.props?.checked !== undefined;\n const childIsSelected = childIsControlled\n ? child?.props?.checked\n : child?.props?.defaultChecked;\n\n return childIsSelected ? child?.props?.value : undefined;\n })\n .filter((v) => v !== undefined);\n\n return selectedValues;\n};\n\nexport { staticClasses as checkBoxGroupClasses };\n\nexport type HvCheckBoxGroupClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvCheckBoxGroupProps\n extends HvBaseProps<HTMLDivElement, \"onChange\"> {\n /**\n * The form element name.\n *\n * It is propagated to the children checkboxes, unless they already have one.\n */\n name?: string;\n /**\n * The value of the form element. An array of values represented in the child checkboxes.\n *\n * When defined the checkbox group state becomes controlled.\n */\n value?: any[];\n /**\n * When uncontrolled, defines the initial value.\n */\n defaultValue?: any[];\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /**\n * Provide additional descriptive text for the form element.\n */\n description?: React.ReactNode;\n /**\n * Indicates that the form element is disabled.\n * If `true` the state is propagated to the children checkboxes.\n */\n disabled?: boolean;\n /**\n * Indicates that the form element is not editable.\n * If `true` the state is propagated to the children checkboxes.\n */\n readOnly?: boolean;\n /**\n * Indicates that user input is required on the form element.\n */\n required?: boolean;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvFormStatus;\n /**\n * The error message to show when the validation status is \"invalid\".\n *\n * Defaults to \"Required\" when the status is uncontrolled and no `aria-errormessage` is provided.\n */\n statusMessage?: React.ReactNode;\n /**\n * The callback fired when the value changes.\n */\n onChange?: (event: React.ChangeEvent<HTMLInputElement>, value: any[]) => void;\n /**\n * Indicates whether the checkbox group's orientation is horizontal or vertical.\n *\n * Defaults to vertical.\n */\n orientation?: \"vertical\" | \"horizontal\";\n /**\n * Indicates if an additional select all checkbox should be shown.\n */\n showSelectAll?: boolean;\n /**\n * The label of the select all checkbox. Defaults to \"All\".\n */\n selectAllLabel?: string;\n /**\n * Custom label for select all checkbox conjunction\n */\n selectAllConjunctionLabel?: string;\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvCheckBoxGroupClasses;\n}\n\n/**\n * A checkbox group is a type of selection list that allows the user to select multiple options through the use of checkboxes.\n */\nexport const HvCheckBoxGroup = (props: HvCheckBoxGroupProps) => {\n const {\n id,\n classes: classesProp,\n className,\n children,\n name,\n label,\n description,\n status,\n statusMessage,\n defaultValue,\n value: valueProp,\n required = false,\n readOnly = false,\n disabled = false,\n showSelectAll = false,\n orientation = \"vertical\",\n selectAllLabel = \"All\",\n selectAllConjunctionLabel = \"/\",\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-errormessage\": ariaErrorMessage,\n onChange,\n ...others\n } = useDefaultProps(\"HvCheckBoxGroup\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const [value, setValue] = useControlled(\n valueProp,\n defaultValue !== undefined\n ? defaultValue\n : // When uncontrolled and no default value is given,\n // extract the initial selected values from the children own state\n () => getValueFromSelectedChildren(children)\n );\n\n const [validationState, setValidationState] = useControlled(\n status,\n \"standBy\"\n );\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const elementId = useUniqueId(id, \"hvcheckboxgroup\");\n\n const selectionAnchor = useRef(undefined);\n\n const [allValues, selectedState, selectedCount] = useMemo(() => {\n const childValues: any[] = [];\n const childSelectedState: boolean[] = [];\n let childSelectedCounter = 0;\n\n Children.toArray(children).forEach((child: any, i: number) => {\n const childValue = child?.props?.value;\n const childIsSelected = value.indexOf(childValue) !== -1;\n\n childValues[i] = childValue;\n childSelectedState[i] = childIsSelected;\n\n if (childIsSelected) {\n childSelectedCounter += 1;\n }\n });\n\n return [childValues, childSelectedState, childSelectedCounter];\n }, [children, value]);\n\n const selectAllState = computeSelectAllState(\n value.length,\n selectedState.length\n );\n\n const onChildChangeInterceptor = useCallback(\n (\n index: number,\n childOnChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean\n ) => void,\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean\n ) => {\n const newValue = multiSelectionEventHandler(\n event,\n index,\n selectionAnchor,\n allValues,\n selectedState,\n isChecked\n );\n\n childOnChange?.(event, isChecked);\n\n onChange?.(event, newValue);\n\n setValue(() => {\n // This will only run if uncontrolled\n\n if (required && newValue.length === 0) {\n setValidationState(\"invalid\");\n } else {\n setValidationState(\"valid\");\n }\n\n return newValue;\n });\n },\n [allValues, onChange, required, selectedState, setValidationState, setValue]\n );\n\n const modifiedChildren = useMemo(() => {\n return Children.map(children, (child: any, i: number) => {\n const childIsSelected = selectedState[i];\n\n return cloneElement(child, {\n checked: childIsSelected,\n name: child?.props?.name || name,\n onChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean\n ) =>\n onChildChangeInterceptor(i, child?.props?.onChange, event, isChecked),\n disabled: disabled || child?.props?.disabled,\n readOnly: readOnly || child?.props?.readOnly,\n });\n });\n }, [\n children,\n disabled,\n name,\n onChildChangeInterceptor,\n readOnly,\n selectedState,\n ]);\n\n const handleSelectAll = (\n event: React.ChangeEvent<HTMLInputElement>,\n selectAllChecked: boolean\n ) => {\n let newValue: any[];\n if (selectAllChecked) {\n newValue = [...allValues];\n } else {\n newValue = [];\n }\n\n onChange?.(event, newValue);\n\n setValue(() => {\n // This will only run if uncontrolled\n if (required && newValue.length === 0) {\n setValidationState(\"invalid\");\n } else {\n setValidationState(\"valid\");\n }\n\n return newValue;\n });\n };\n\n const selectAllLabelComponent =\n selectedCount === 0 ? (\n <>\n <b>{selectAllLabel}</b>\n {` (${Children.toArray(children).length})`}\n </>\n ) : (\n <>\n <b>{selectedCount}</b>\n {` ${selectAllConjunctionLabel} ${Children.toArray(children).length}`}\n </>\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 errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n\n return (\n <HvFormElement\n id={id}\n name={name}\n status={validationState}\n disabled={disabled}\n required={required}\n readOnly={readOnly}\n className={cx(classes.root, className)}\n >\n {label && (\n <HvLabel\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {description && (\n <HvInfoMessage id={setId(elementId, \"description\")}>\n {description}\n </HvInfoMessage>\n )}\n\n <div\n role=\"group\"\n aria-label={ariaLabel}\n aria-labelledby={\n ariaLabelledBy || (label && setId(elementId, \"label\")) || undefined\n }\n aria-disabled={disabled ? true : undefined}\n aria-invalid={validationState === \"invalid\" ? true : undefined}\n aria-errormessage={\n validationState === \"invalid\" ? errorMessageId : undefined\n }\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n className={cx(classes.group, {\n [classes.vertical]: orientation === \"vertical\",\n [classes.horizontal]: orientation === \"horizontal\",\n [classes.invalid]: validationState === \"invalid\",\n })}\n {...others}\n >\n {showSelectAll && (\n <HvCheckBox\n checked={selectAllState === \"all\"}\n indeterminate={selectAllState === \"some\"}\n label={selectAllLabelComponent}\n disabled={disabled}\n readOnly={readOnly}\n className={classes.selectAll}\n onChange={handleSelectAll}\n />\n )}\n {modifiedChildren}\n </div>\n\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n};\n"],"names":["computeSelectAllState","selected","total","getValueFromSelectedChildren","children","selectedValues","Children","toArray","map","child","childIsControlled","props","checked","undefined","childIsSelected","defaultChecked","value","filter","v","HvCheckBoxGroup","id","classes","classesProp","className","name","label","description","status","statusMessage","defaultValue","valueProp","required","readOnly","disabled","showSelectAll","orientation","selectAllLabel","selectAllConjunctionLabel","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaErrorMessage","onChange","others","useDefaultProps","cx","useClasses","setValue","useControlled","validationState","setValidationState","validationMessage","elementId","useUniqueId","selectionAnchor","useRef","allValues","selectedState","selectedCount","useMemo","childValues","childSelectedState","childSelectedCounter","forEach","i","childValue","indexOf","selectAllState","length","onChildChangeInterceptor","useCallback","index","childOnChange","event","isChecked","newValue","multiSelectionEventHandler","modifiedChildren","cloneElement","handleSelectAll","selectAllChecked","selectAllLabelComponent","jsxs","Fragment","jsx","canShowError","errorMessageId","setId","HvFormElement","root","HvLabel","HvInfoMessage","join","trim","group","vertical","horizontal","invalid","HvCheckBox","selectAll","HvWarningText","error"],"mappings":";;;;;;;;;;;;;;;AAoBA,MAAMA,wBAAwBA,CAACC,UAAkBC,UAAkB;AACjE,MAAID,aAAa,GAAG;AACX,WAAA;AAAA,EACT;AAEA,MAAIA,aAAaC,OAAO;AACf,WAAA;AAAA,EACT;AAEO,SAAA;AACT;AAEA,MAAMC,+BAA+BA,CAACC,aAA8B;AAClE,QAAMC,iBAAiBC,MAAAA,SAASC,QAAQH,QAAQ,EAC7CI,IAAI,CAACC,UAAe;;AACbC,UAAAA,sBAAoBD,oCAAOE,UAAPF,mBAAcG,aAAYC;AACpD,UAAMC,kBAAkBJ,qBACpBD,oCAAOE,UAAPF,mBAAcG,WACdH,oCAAOE,UAAPF,mBAAcM;AAEXD,WAAAA,mBAAkBL,oCAAOE,UAAPF,mBAAcO,QAAQH;AAAAA,EAAAA,CAChD,EACAI,OAAQC,CAAAA,MAAMA,MAAML,MAAS;AAEzBR,SAAAA;AACT;AA+Fac,MAAAA,kBAAkBA,CAACR,UAAgC;AACxD,QAAA;AAAA,IACJS;AAAAA,IACAC,SAASC;AAAAA,IACTC;AAAAA,IACAnB;AAAAA,IACAoB;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAb,OAAOc;AAAAA,IACPC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,WAAW;AAAA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A,KAAC,SACC,MAAK,SACL,cAAY5C,WACZ,mBACEC,kBAAmBd,SAAS8D,YAAMnC,WAAW,OAAO,KAAMvC,QAE5D,iBAAeoB,WAAW,OAAOpB,QACjC,gBAAcoC,oBAAoB,YAAY,OAAOpC,QACrD,qBACEoC,oBAAoB,YAAYqC,iBAAiBzE,QAEnD,oBACE,CAACa,eAAe6D,MAAAA,MAAMnC,WAAW,aAAa,GAAGZ,eAAe,EAC7DoD,KAAK,GAAG,EACRC,KAAAA,KAAUhF,QAEf,WAAWgC,GAAGxB,QAAQyE,OAAO;AAAA,MAC3B,CAACzE,QAAQ0E,QAAQ,GAAG5D,gBAAgB;AAAA,MACpC,CAACd,QAAQ2E,UAAU,GAAG7D,gBAAgB;AAAA,MACtC,CAACd,QAAQ4E,OAAO,GAAGhD,oBAAoB;AAAA,IAAA,CACxC,GACD,GAAIN,QAEHT,UAAAA;AAAAA,MAAAA,gDACEgE,SAAAA,YACC,EAAA,SAAS/B,mBAAmB,OAC5B,eAAeA,mBAAmB,QAClC,OAAOc,yBACP,UACA,UACA,WAAW5D,QAAQ8E,WACnB,UAAUpB,iBAEb;AAAA,MACAF;AAAAA,IAAAA,GACH;AAAA,IAECQ,gBACCD,2BAAA,IAACgB,YACC,eAAA,EAAA,IAAIb,MAAAA,MAAMnC,WAAW,OAAO,GAC5B,eAAa,MACb,WAAW/B,QAAQgF,OAElBlD,UACH,mBAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ;;;"}
1
+ {"version":3,"file":"CheckBoxGroup.cjs","sources":["../../../../src/components/CheckBoxGroup/CheckBoxGroup.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n forwardRef,\n useCallback,\n useMemo,\n useRef,\n} from \"react\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { HvBaseProps } from \"@core/types/generic\";\nimport { useUniqueId } from \"@core/hooks/useUniqueId\";\nimport { useControlled } from \"@core/hooks/useControlled\";\nimport { setId } from \"@core/utils/setId\";\nimport { multiSelectionEventHandler } from \"@core/utils/multiSelectionEventHandler\";\nimport { HvCheckBox } from \"@core/components/CheckBox\";\nimport {\n HvFormElement,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvWarningText,\n} from \"@core/components/Forms\";\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { staticClasses, useClasses } from \"./CheckBoxGroup.styles\";\n\nconst computeSelectAllState = (selected: number, total: number) => {\n if (selected === 0) {\n return \"none\";\n }\n\n if (selected === total) {\n return \"all\";\n }\n\n return \"some\";\n};\n\nconst getValueFromSelectedChildren = (children: React.ReactNode) => {\n const selectedValues = Children.toArray(children)\n .map((child: any) => {\n const childIsControlled = child?.props?.checked !== undefined;\n const childIsSelected = childIsControlled\n ? child?.props?.checked\n : child?.props?.defaultChecked;\n\n return childIsSelected ? child?.props?.value : undefined;\n })\n .filter((v) => v !== undefined);\n\n return selectedValues;\n};\n\nexport { staticClasses as checkBoxGroupClasses };\n\nexport type HvCheckBoxGroupClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvCheckBoxGroupProps\n extends HvBaseProps<HTMLDivElement, \"onChange\"> {\n /**\n * The form element name.\n *\n * It is propagated to the children checkboxes, unless they already have one.\n */\n name?: string;\n /**\n * The value of the form element. An array of values represented in the child checkboxes.\n *\n * When defined the checkbox group state becomes controlled.\n */\n value?: any[];\n /**\n * When uncontrolled, defines the initial value.\n */\n defaultValue?: any[];\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /**\n * Provide additional descriptive text for the form element.\n */\n description?: React.ReactNode;\n /**\n * Indicates that the form element is disabled.\n * If `true` the state is propagated to the children checkboxes.\n */\n disabled?: boolean;\n /**\n * Indicates that the form element is not editable.\n * If `true` the state is propagated to the children checkboxes.\n */\n readOnly?: boolean;\n /**\n * Indicates that user input is required on the form element.\n */\n required?: boolean;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvFormStatus;\n /**\n * The error message to show when the validation status is \"invalid\".\n *\n * Defaults to \"Required\" when the status is uncontrolled and no `aria-errormessage` is provided.\n */\n statusMessage?: React.ReactNode;\n /**\n * The callback fired when the value changes.\n */\n onChange?: (event: React.ChangeEvent<HTMLInputElement>, value: any[]) => void;\n /**\n * Indicates whether the checkbox group's orientation is horizontal or vertical.\n *\n * Defaults to vertical.\n */\n orientation?: \"vertical\" | \"horizontal\";\n /**\n * Indicates if an additional select all checkbox should be shown.\n */\n showSelectAll?: boolean;\n /**\n * The label of the select all checkbox. Defaults to \"All\".\n */\n selectAllLabel?: string;\n /**\n * Custom label for select all checkbox conjunction\n */\n selectAllConjunctionLabel?: string;\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvCheckBoxGroupClasses;\n}\n\n/**\n * A checkbox group is a type of selection list that allows the user to select multiple options through the use of checkboxes.\n */\nexport const HvCheckBoxGroup = forwardRef<HTMLDivElement, HvCheckBoxGroupProps>(\n (props, ref) => {\n const {\n id,\n classes: classesProp,\n className,\n children,\n name,\n label,\n description,\n status,\n statusMessage,\n defaultValue,\n value: valueProp,\n required = false,\n readOnly = false,\n disabled = false,\n showSelectAll = false,\n orientation = \"vertical\",\n selectAllLabel = \"All\",\n selectAllConjunctionLabel = \"/\",\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-errormessage\": ariaErrorMessage,\n onChange,\n ...others\n } = useDefaultProps(\"HvCheckBoxGroup\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const [value, setValue] = useControlled(\n valueProp,\n defaultValue !== undefined\n ? defaultValue\n : // When uncontrolled and no default value is given,\n // extract the initial selected values from the children own state\n () => getValueFromSelectedChildren(children)\n );\n\n const [validationState, setValidationState] = useControlled(\n status,\n \"standBy\"\n );\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const elementId = useUniqueId(id, \"hvcheckboxgroup\");\n\n const selectionAnchor = useRef(undefined);\n\n const [allValues, selectedState, selectedCount] = useMemo(() => {\n const childValues: any[] = [];\n const childSelectedState: boolean[] = [];\n let childSelectedCounter = 0;\n\n Children.toArray(children).forEach((child: any, i: number) => {\n const childValue = child?.props?.value;\n const childIsSelected = value.indexOf(childValue) !== -1;\n\n childValues[i] = childValue;\n childSelectedState[i] = childIsSelected;\n\n if (childIsSelected) {\n childSelectedCounter += 1;\n }\n });\n\n return [childValues, childSelectedState, childSelectedCounter];\n }, [children, value]);\n\n const selectAllState = computeSelectAllState(\n value.length,\n selectedState.length\n );\n\n const onChildChangeInterceptor = useCallback(\n (\n index: number,\n childOnChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean\n ) => void,\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean\n ) => {\n const newValue = multiSelectionEventHandler(\n event,\n index,\n selectionAnchor,\n allValues,\n selectedState,\n isChecked\n );\n\n childOnChange?.(event, isChecked);\n\n onChange?.(event, newValue);\n\n setValue(() => {\n // This will only run if uncontrolled\n\n if (required && newValue.length === 0) {\n setValidationState(\"invalid\");\n } else {\n setValidationState(\"valid\");\n }\n\n return newValue;\n });\n },\n [\n allValues,\n onChange,\n required,\n selectedState,\n setValidationState,\n setValue,\n ]\n );\n\n const modifiedChildren = useMemo(() => {\n return Children.map(children, (child: any, i: number) => {\n const childIsSelected = selectedState[i];\n\n return cloneElement(child, {\n checked: childIsSelected,\n name: child?.props?.name || name,\n onChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean\n ) =>\n onChildChangeInterceptor(\n i,\n child?.props?.onChange,\n event,\n isChecked\n ),\n disabled: disabled || child?.props?.disabled,\n readOnly: readOnly || child?.props?.readOnly,\n });\n });\n }, [\n children,\n disabled,\n name,\n onChildChangeInterceptor,\n readOnly,\n selectedState,\n ]);\n\n const handleSelectAll = (\n event: React.ChangeEvent<HTMLInputElement>,\n selectAllChecked: boolean\n ) => {\n let newValue: any[];\n if (selectAllChecked) {\n newValue = [...allValues];\n } else {\n newValue = [];\n }\n\n onChange?.(event, newValue);\n\n setValue(() => {\n // This will only run if uncontrolled\n if (required && newValue.length === 0) {\n setValidationState(\"invalid\");\n } else {\n setValidationState(\"valid\");\n }\n\n return newValue;\n });\n };\n\n const selectAllLabelComponent =\n selectedCount === 0 ? (\n <>\n <b>{selectAllLabel}</b>\n {` (${Children.toArray(children).length})`}\n </>\n ) : (\n <>\n <b>{selectedCount}</b>\n {` ${selectAllConjunctionLabel} ${Children.toArray(children).length}`}\n </>\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 errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n\n return (\n <HvFormElement\n id={id}\n name={name}\n status={validationState}\n disabled={disabled}\n required={required}\n readOnly={readOnly}\n className={cx(classes.root, className)}\n >\n {label && (\n <HvLabel\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {description && (\n <HvInfoMessage id={setId(elementId, \"description\")}>\n {description}\n </HvInfoMessage>\n )}\n\n <div\n ref={ref}\n role=\"group\"\n aria-label={ariaLabel}\n aria-labelledby={\n ariaLabelledBy || (label && setId(elementId, \"label\")) || undefined\n }\n aria-disabled={disabled ? true : undefined}\n aria-invalid={validationState === \"invalid\" ? true : undefined}\n aria-errormessage={\n validationState === \"invalid\" ? errorMessageId : undefined\n }\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n className={cx(classes.group, {\n [classes.vertical]: orientation === \"vertical\",\n [classes.horizontal]: orientation === \"horizontal\",\n [classes.invalid]: validationState === \"invalid\",\n })}\n {...others}\n >\n {showSelectAll && (\n <HvCheckBox\n checked={selectAllState === \"all\"}\n indeterminate={selectAllState === \"some\"}\n label={selectAllLabelComponent}\n disabled={disabled}\n readOnly={readOnly}\n className={classes.selectAll}\n onChange={handleSelectAll}\n />\n )}\n {modifiedChildren}\n </div>\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":["computeSelectAllState","selected","total","getValueFromSelectedChildren","children","selectedValues","Children","toArray","map","child","childIsControlled","props","checked","undefined","childIsSelected","defaultChecked","value","filter","v","HvCheckBoxGroup","forwardRef","ref","id","classes","classesProp","className","name","label","description","status","statusMessage","defaultValue","valueProp","required","readOnly","disabled","showSelectAll","orientation","selectAllLabel","selectAllConjunctionLabel","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaErrorMessage","onChange","others","useDefaultProps","cx","useClasses","setValue","useControlled","validationState","setValidationState","validationMessage","elementId","useUniqueId","selectionAnchor","useRef","allValues","selectedState","selectedCount","useMemo","childValues","childSelectedState","childSelectedCounter","forEach","i","childValue","indexOf","selectAllState","length","onChildChangeInterceptor","useCallback","index","childOnChange","event","isChecked","newValue","multiSelectionEventHandler","modifiedChildren","cloneElement","handleSelectAll","selectAllChecked","selectAllLabelComponent","jsxs","Fragment","jsx","canShowError","errorMessageId","setId","HvFormElement","root","HvLabel","HvInfoMessage","join","trim","group","vertical","horizontal","invalid","HvCheckBox","selectAll","HvWarningText","error"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAMA,wBAAwBA,CAACC,UAAkBC,UAAkB;AACjE,MAAID,aAAa,GAAG;AACX,WAAA;AAAA,EACT;AAEA,MAAIA,aAAaC,OAAO;AACf,WAAA;AAAA,EACT;AAEO,SAAA;AACT;AAEA,MAAMC,+BAA+BA,CAACC,aAA8B;AAClE,QAAMC,iBAAiBC,MAAAA,S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OAC5B,eAAeA,mBAAmB,QAClC,OAAOc,yBACP,UACA,UACA,WAAW5D,QAAQ8E,WACnB,UAAUpB,iBAEb;AAAA,MACAF;AAAAA,IAAAA,GACH;AAAA,IAECQ,gBACCD,2BAAA,IAACgB,YACC,eAAA,EAAA,IAAIb,MAAAA,MAAMnC,WAAW,OAAO,GAC5B,eAAa,MACb,WAAW/B,QAAQgF,OAElBlD,UACH,mBAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ,CACF;;;"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("@emotion/react/jsx-runtime");
4
+ const React = require("react");
4
5
  const uikitReactIcons = require("@hitachivantara/uikit-react-icons");
5
6
  const useDefaultProps = require("../../hooks/useDefaultProps.cjs");
6
7
  const useControlled = require("../../hooks/useControlled.cjs");
@@ -21,7 +22,7 @@ const DEFAULT_LABELS = {
21
22
  recommendedColorsLabel: "Recommended colors:",
22
23
  customColorsLabel: "Custom colors:"
23
24
  };
24
- const HvColorPicker = (props) => {
25
+ const HvColorPicker = React.forwardRef((props, ref) => {
25
26
  const {
26
27
  id,
27
28
  name,
@@ -108,7 +109,7 @@ const HvColorPicker = (props) => {
108
109
  hasLabel && /* @__PURE__ */ jsxRuntime.jsx(Label.HvLabel, { id: setId.setId(elementId, "label"), label, className: classes.label }),
109
110
  hasDescription && /* @__PURE__ */ jsxRuntime.jsx(InfoMessage.HvInfoMessage, { id: setId.setId(elementId, "description"), className: classes.description, children: description })
110
111
  ] }),
111
- /* @__PURE__ */ jsxRuntime.jsx(BaseDropdown.HvBaseDropdown, { variableWidth: true, className, expanded: isOpen, onToggle: handleToggle, onContainerCreation: setFocusToContent, classes: {
112
+ /* @__PURE__ */ jsxRuntime.jsx(BaseDropdown.HvBaseDropdown, { ref, variableWidth: true, className, expanded: isOpen, onToggle: handleToggle, onContainerCreation: setFocusToContent, classes: {
112
113
  root: cx({
113
114
  [classes.dropdownRootIconOnly]: iconOnly
114
115
  }),
@@ -129,7 +130,7 @@ const HvColorPicker = (props) => {
129
130
  recommendedColorsPosition === "bottom" && /* @__PURE__ */ jsxRuntime.jsx(PresetColors.PresetColors, { colors: recommendedColors, onClick: handleSelect, title: showLabels ? labels == null ? void 0 : labels.recommendedColorsLabel : void 0 })
130
131
  ] }) }) })
131
132
  ] });
132
- };
133
+ });
133
134
  exports.colorPickerClasses = ColorPicker_styles.staticClasses;
134
135
  exports.HvColorPicker = HvColorPicker;
135
136
  //# sourceMappingURL=ColorPicker.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ColorPicker.cjs","sources":["../../../../src/components/ColorPicker/ColorPicker.tsx"],"sourcesContent":["import { Checkbox, ColorPicker } from \"@hitachivantara/uikit-react-icons\";\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\n\nimport { ColorState } from \"react-color\";\n\nimport { useControlled } from \"@core/hooks/useControlled\";\nimport { useUniqueId } from \"@core/hooks/useUniqueId\";\nimport { useLabels } from \"@core/hooks/useLabels\";\nimport { ExtractNames } from \"@core/utils/classes\";\nimport { setId } from \"@core/utils/setId\";\nimport { HvTypography } from \"@core/components/Typography\";\nimport { HvPanel } from \"@core/components/Panel\";\nimport { HvFormElement, HvInfoMessage, HvLabel } from \"@core/components/Forms\";\nimport { HvBaseDropdown } from \"@core/components/BaseDropdown\";\nimport { HvDropdownProps } from \"@core/components/Dropdown\";\n\nimport { Picker } from \"./Picker\";\nimport { staticClasses, useClasses } from \"./ColorPicker.styles\";\nimport { PresetColors } from \"./PresetColors\";\nimport { SavedColors } from \"./SavedColors\";\n\nexport { staticClasses as colorPickerClasses };\n\nexport type HvColorPickerClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvColorPickerProps {\n \"aria-label\"?: string;\n \"aria-labelledby\"?: string;\n \"aria-describedby\"?: string;\n /** Class names to be applied. */\n className?: string;\n /** Id to be applied to the form element root node. */\n id?: string;\n /** The form element name. */\n name?: string;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /** Provide additional descriptive text for the form element. */\n description?: React.ReactNode;\n /** Indicates that user input is required on the form element. */\n required?: boolean;\n /** The value color, in HEX format. */\n value?: string;\n /** The default value color, in HEX format. */\n defaultValue?: string;\n /** If `true` the dropdown is disabled unable to be interacted, if `false` it is enabled. */\n disabled?: boolean;\n /** If `true` the dropdown starts opened if `false` it starts closed. */\n expanded?: boolean;\n /** When uncontrolled, defines the initial expanded state. */\n defaultExpanded?: boolean;\n /** A function to be executed whenever the color changes. */\n onChange?: (color: string) => void;\n /** A function to be executed whenever the color change is complete. */\n onChangeComplete?: (color: string) => void;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvColorPickerClasses;\n /** The placeholder value when nothing is selected. */\n placeholder?: string;\n /** Recommended colors. The colors are HEX values. */\n recommendedColors?: string[];\n /** Recommended colors position. */\n recommendedColorsPosition?: \"top\" | \"bottom\";\n /** If `true`, the labels are shown. If `false`, they are not shown. */\n showLabels?: boolean;\n /** An object containing all the labels. */\n labels?: {\n recommendedColorsLabel?: string;\n customColorsLabel?: string;\n };\n /** Icon type for the input's end adornment. */\n dropdownIcon?: \"arrow\" | \"colorPicker\";\n /** If `true`, the input only shows an icon. If `false`, the input shows text and icons. */\n iconOnly?: boolean;\n /** If `true`, the saved colors area is shown. If `false`, it is not shown. */\n showSavedColors?: boolean;\n /** If `true`, the custom colors area is shown. If `false`, it is not shown. */\n showCustomColors?: boolean;\n /** The saved colors. The colors are HEX values. */\n savedColorsValue?: string[];\n /** The default saved colors. The colors are HEX values. */\n defaultSavedColorsValue?: string[];\n /** Callback fired when a new saved color is added. */\n onSavedColorAdded?: (color?: string) => void;\n /** Callback fired when a new saved color is removed. */\n onSavedColorRemoved?: (color?: string) => void;\n /** Aria label to apply to delete saved color button. */\n deleteSavedColorButtonArialLabel?: string; // TODO: fix typo \"ArialLabel\" in next version\n /** Aria label to apply to add saved color button. */\n addSavedColorButtonAriaLabel?: string;\n}\n\nconst DEFAULT_LABELS: HvColorPickerProps[\"labels\"] = {\n recommendedColorsLabel: \"Recommended colors:\",\n customColorsLabel: \"Custom colors:\",\n};\n\n/**\n * A color picker component which allows the user to select a color from a list of pre-defined colors or freely select one color via the Hue and Saturation.\n * It receives a color string in HEX format and outputs an HEX formatted color.\n */\nexport const HvColorPicker = (props: HvColorPickerProps) => {\n const {\n id,\n name,\n required = false,\n disabled = false,\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n className,\n classes: classesProp,\n value,\n onChange,\n onChangeComplete,\n defaultValue = \"\",\n expanded,\n defaultExpanded = false,\n recommendedColorsPosition = \"top\",\n recommendedColors = [\n \"#95AFE8\",\n \"#E89E5D\",\n \"#83B8A6\",\n \"#70759C\",\n \"#C57E7E\",\n \"#FADA95\",\n \"#ADBFE8\",\n \"#E3B386\",\n \"#9AC6B7\",\n \"#8B90AF\",\n \"#CF9797\",\n \"#FAE1AA\",\n ],\n showLabels = true,\n labels: labelsProp,\n dropdownIcon = \"colorPicker\",\n placeholder = \"Select color...\",\n iconOnly = false,\n showSavedColors = true,\n showCustomColors = true,\n savedColorsValue,\n defaultSavedColorsValue = [],\n onSavedColorAdded,\n onSavedColorRemoved,\n deleteSavedColorButtonArialLabel = \"Delete saved color\",\n addSavedColorButtonAriaLabel = \"Add current color to saved colors\",\n } = useDefaultProps(\"HvColorPicker\", props);\n\n const { classes, css, cx } = useClasses(classesProp);\n\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const [isOpen, setIsOpen] = useControlled(expanded, Boolean(defaultExpanded));\n const [color, setColor] = useControlled(value, defaultValue);\n const [savedColors, setSavedColors] = useControlled(\n savedColorsValue,\n defaultSavedColorsValue\n );\n const elementId = useUniqueId(id, \"hvdropdown\");\n const hasLabel = label != null;\n const hasDescription = description != null;\n\n const handleToggle: HvDropdownProps[\"onToggle\"] = (_, open) => {\n setIsOpen(open);\n };\n\n const handleSelect = (val: ColorState | { hex: string; source: string }) => {\n onChange?.(val.hex);\n onChangeComplete?.(val.hex);\n setColor(val.hex);\n };\n\n const handleOnChange = (\n val: ColorState | { hex: string; source: string }\n ) => {\n onChange?.(val.hex);\n setColor(val.hex);\n };\n\n const handleOnChangeComplete = (\n val: ColorState | { hex: string; source: string }\n ) => {\n onChangeComplete?.(val.hex);\n setColor(val.hex);\n };\n\n const handleAddColor = () => {\n // When no color is provided, react-color sets the picker to #000000.\n // This is the color that should be added in this case.\n const colorToAdd = color || \"#000000\";\n\n onSavedColorAdded?.(colorToAdd);\n setSavedColors([...savedColors, colorToAdd]);\n };\n\n const handleRemoveColor = (val: string, position: number) => {\n if (savedColors[position] === val) {\n const sColors = [...savedColors];\n sColors.splice(position, 1);\n onSavedColorRemoved?.(val);\n setSavedColors(sColors);\n }\n };\n\n const setFocusToContent = (containerRef: HTMLElement | null) => {\n const inputs = containerRef?.getElementsByTagName(\"input\");\n if (inputs && inputs.length > 0) {\n inputs[0].focus();\n }\n };\n\n return (\n <HvFormElement\n id={id}\n name={name}\n disabled={disabled}\n required={required}\n className={cx(classes.root, className)}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvBaseDropdown\n variableWidth\n className={className}\n expanded={isOpen}\n onToggle={handleToggle}\n onContainerCreation={setFocusToContent}\n classes={{\n root: cx({ [classes.dropdownRootIconOnly]: iconOnly }),\n selection: cx(iconOnly && css({ padding: 0 })),\n }}\n adornment={\n iconOnly && color ? (\n <Checkbox\n className={classes.headerColorIconOnly}\n color={[color, \"transparent\"]}\n />\n ) : dropdownIcon === \"colorPicker\" ? (\n <ColorPicker className={classes.colorPickerIcon} />\n ) : undefined\n }\n placeholder={\n iconOnly ? undefined : color ? (\n <>\n <Checkbox\n className={classes.headerColorIcon}\n color={[color, \"transparent\"]}\n />\n <HvTypography\n className={classes.headerColorValue}\n variant=\"label\"\n >\n {color}\n </HvTypography>\n </>\n ) : (\n placeholder\n )\n }\n aria-label={ariaLabel}\n aria-labelledby={\n [label && setId(elementId, \"label\"), ariaLabelledBy]\n .join(\" \")\n .trim() || undefined\n }\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n >\n <HvPanel className={classes.panel}>\n <div className={classes.colorPicker}>\n {recommendedColorsPosition === \"top\" && (\n <PresetColors\n className={classes.recommendedColorsRoot}\n colors={recommendedColors}\n onClick={handleSelect}\n title={showLabels ? labels?.recommendedColorsLabel : undefined}\n />\n )}\n {showCustomColors && (\n <Picker\n classes={{\n fields: cx({\n [classes.pickerFields]:\n recommendedColorsPosition === \"bottom\" || showSavedColors,\n }),\n }}\n title={showLabels ? labels?.customColorsLabel : undefined}\n color={color}\n onChange={handleOnChange}\n onChangeComplete={handleOnChangeComplete}\n />\n )}\n {showSavedColors && (\n <SavedColors\n colors={savedColors}\n onAddColor={handleAddColor}\n onClickColor={handleSelect}\n onRemoveColor={handleRemoveColor}\n deleteButtonAriaLabel={deleteSavedColorButtonArialLabel}\n addButtonAriaLabel={addSavedColorButtonAriaLabel}\n />\n )}\n {recommendedColorsPosition === \"bottom\" && (\n <PresetColors\n colors={recommendedColors}\n onClick={handleSelect}\n title={showLabels ? labels?.recommendedColorsLabel : undefined}\n />\n )}\n </div>\n </HvPanel>\n </HvBaseDropdown>\n </HvFormElement>\n );\n};\n"],"names":["DEFAULT_LABELS","recommendedColorsLabel","customColorsLabel","HvColorPicker","props","id","name","required","disabled","label","ariaLabel","ariaLabelledBy","description","ariaDescribedBy","className","classes","classesProp","value","onChange","onChangeComplete","defaultValue","expanded","defaultExpanded","recommendedColorsPosition","recommendedColors","showLabels","labels","labelsProp","dropdownIcon","placeholder","iconOnly","showSavedColors","showCustomColors","savedColorsValue","defaultSavedColorsValue","onSavedColorAdded","onSavedColorRemoved","deleteSavedColorButtonArialLabel","addSavedColorButtonAriaLabel","useDefaultProps","css","cx","useClasses","useLabels","isOpen","setIsOpen","useControlled","Boolean","color","setColor","savedColors","setSavedColors","elementId","useUniqueId","hasLabel","hasDescription","handleToggle","_","open","handleSelect","val","hex","handleOnChange","handleOnChangeComplete","handleAddColor","colorToAdd","handleRemoveColor","position","sColors","splice","setFocusToContent","containerRef","inputs","getElementsByTagName","length","focus","jsxs","HvFormElement","root","labelContainer","jsx","HvLabel","setId","HvInfoMessage","HvBaseDropdown","dropdownRootIconOnly","selection","padding","Checkbox","headerColorIconOnly","ColorPicker","colorPickerIcon","undefined","Fragment","headerColorIcon","HvTypography","headerColorValue","join","trim","HvPanel","panel","colorPicker","PresetColors","recommendedColorsRoot","Picker","fields","pickerFields","SavedColors"],"mappings":";;;;;;;;;;;;;;;;;;;AAiGA,MAAMA,iBAA+C;AAAA,EACnDC,wBAAwB;AAAA,EACxBC,mBAAmB;AACrB;AAMaC,MAAAA,gBAAgBA,CAACC,UAA8B;AACpD,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC;AAAAA,IACA,cAAcC;AAAAA,IACd,mBAAmBC;AAAAA,IACnBC;AAAAA,IACA,oBAAoBC;AAAAA,IACpBC;AAAAA,IACAC,SAASC;AAAAA,IACTC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,eAAe;AAAA,IACfC;AAAAA,IACAC,kBAAkB;AAAA,IAClBC,4BAA4B;AAAA,IAC5BC,oBAAoB,CAClB,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,SAAS;AAAA,IAEXC,aAAa;AAAA,IACbC,QAAQC;AAAAA,IACRC,eAAe;AAAA,IACfC,cAAc;A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,UAAU9B,gBACV,kBAAkBC,uBAErB,CAAA;AAAA,MACAhC,mBACCiD,2BAAA,IAAC2B,YACC,aAAA,EAAA,QAAQzD,aACR,YAAYc,gBACZ,cAAcL,cACd,eAAeO,mBACf,uBAAuB7B,kCACvB,oBAAoBC,8BAEvB;AAAA,MACAf,8BAA8B,YAC5ByD,2BAAA,IAAAsB,aAAA,cAAA,EACC,QAAQ9E,mBACR,SAASmC,cACT,OAAOlC,aAAaC,iCAAQzB,yBAAyB2F,OAExD,CAAA;AAAA,IAAA,EACH,CAAA,EACF,CAAA,GACF;AAAA,EACF,EAAA,CAAA;AAEJ;;;"}
1
+ {"version":3,"file":"ColorPicker.cjs","sources":["../../../../src/components/ColorPicker/ColorPicker.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\n\nimport { ColorState } from \"react-color\";\n\nimport { Checkbox, ColorPicker } from \"@hitachivantara/uikit-react-icons\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { useControlled } from \"@core/hooks/useControlled\";\nimport { useUniqueId } from \"@core/hooks/useUniqueId\";\nimport { useLabels } from \"@core/hooks/useLabels\";\nimport { ExtractNames } from \"@core/utils/classes\";\nimport { setId } from \"@core/utils/setId\";\nimport { HvTypography } from \"@core/components/Typography\";\nimport { HvPanel } from \"@core/components/Panel\";\nimport { HvFormElement, HvInfoMessage, HvLabel } from \"@core/components/Forms\";\nimport { HvBaseDropdown } from \"@core/components/BaseDropdown\";\nimport { HvDropdownProps } from \"@core/components/Dropdown\";\n\nimport { Picker } from \"./Picker\";\nimport { staticClasses, useClasses } from \"./ColorPicker.styles\";\nimport { PresetColors } from \"./PresetColors\";\nimport { SavedColors } from \"./SavedColors\";\n\nexport { staticClasses as colorPickerClasses };\n\nexport type HvColorPickerClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvColorPickerProps {\n \"aria-label\"?: string;\n \"aria-labelledby\"?: string;\n \"aria-describedby\"?: string;\n /** Class names to be applied. */\n className?: string;\n /** Id to be applied to the form element root node. */\n id?: string;\n /** The form element name. */\n name?: string;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /** Provide additional descriptive text for the form element. */\n description?: React.ReactNode;\n /** Indicates that user input is required on the form element. */\n required?: boolean;\n /** The value color, in HEX format. */\n value?: string;\n /** The default value color, in HEX format. */\n defaultValue?: string;\n /** If `true` the dropdown is disabled unable to be interacted, if `false` it is enabled. */\n disabled?: boolean;\n /** If `true` the dropdown starts opened if `false` it starts closed. */\n expanded?: boolean;\n /** When uncontrolled, defines the initial expanded state. */\n defaultExpanded?: boolean;\n /** A function to be executed whenever the color changes. */\n onChange?: (color: string) => void;\n /** A function to be executed whenever the color change is complete. */\n onChangeComplete?: (color: string) => void;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvColorPickerClasses;\n /** The placeholder value when nothing is selected. */\n placeholder?: string;\n /** Recommended colors. The colors are HEX values. */\n recommendedColors?: string[];\n /** Recommended colors position. */\n recommendedColorsPosition?: \"top\" | \"bottom\";\n /** If `true`, the labels are shown. If `false`, they are not shown. */\n showLabels?: boolean;\n /** An object containing all the labels. */\n labels?: {\n recommendedColorsLabel?: string;\n customColorsLabel?: string;\n };\n /** Icon type for the input's end adornment. */\n dropdownIcon?: \"arrow\" | \"colorPicker\";\n /** If `true`, the input only shows an icon. If `false`, the input shows text and icons. */\n iconOnly?: boolean;\n /** If `true`, the saved colors area is shown. If `false`, it is not shown. */\n showSavedColors?: boolean;\n /** If `true`, the custom colors area is shown. If `false`, it is not shown. */\n showCustomColors?: boolean;\n /** The saved colors. The colors are HEX values. */\n savedColorsValue?: string[];\n /** The default saved colors. The colors are HEX values. */\n defaultSavedColorsValue?: string[];\n /** Callback fired when a new saved color is added. */\n onSavedColorAdded?: (color?: string) => void;\n /** Callback fired when a new saved color is removed. */\n onSavedColorRemoved?: (color?: string) => void;\n /** Aria label to apply to delete saved color button. */\n deleteSavedColorButtonArialLabel?: string; // TODO: fix typo \"ArialLabel\" in next version\n /** Aria label to apply to add saved color button. */\n addSavedColorButtonAriaLabel?: string;\n}\n\nconst DEFAULT_LABELS: HvColorPickerProps[\"labels\"] = {\n recommendedColorsLabel: \"Recommended colors:\",\n customColorsLabel: \"Custom colors:\",\n};\n\n/**\n * A color picker component which allows the user to select a color from a list of pre-defined colors or freely select one color via the Hue and Saturation.\n * It receives a color string in HEX format and outputs an HEX formatted color.\n */\nexport const HvColorPicker = forwardRef<HTMLDivElement, HvColorPickerProps>(\n (props, ref) => {\n const {\n id,\n name,\n required = false,\n disabled = false,\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n className,\n classes: classesProp,\n value,\n onChange,\n onChangeComplete,\n defaultValue = \"\",\n expanded,\n defaultExpanded = false,\n recommendedColorsPosition = \"top\",\n recommendedColors = [\n \"#95AFE8\",\n \"#E89E5D\",\n \"#83B8A6\",\n \"#70759C\",\n \"#C57E7E\",\n \"#FADA95\",\n \"#ADBFE8\",\n \"#E3B386\",\n \"#9AC6B7\",\n \"#8B90AF\",\n \"#CF9797\",\n \"#FAE1AA\",\n ],\n showLabels = true,\n labels: labelsProp,\n dropdownIcon = \"colorPicker\",\n placeholder = \"Select color...\",\n iconOnly = false,\n showSavedColors = true,\n showCustomColors = true,\n savedColorsValue,\n defaultSavedColorsValue = [],\n onSavedColorAdded,\n onSavedColorRemoved,\n deleteSavedColorButtonArialLabel = \"Delete saved color\",\n addSavedColorButtonAriaLabel = \"Add current color to saved colors\",\n } = useDefaultProps(\"HvColorPicker\", props);\n\n const { classes, css, cx } = useClasses(classesProp);\n\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const [isOpen, setIsOpen] = useControlled(\n expanded,\n Boolean(defaultExpanded)\n );\n const [color, setColor] = useControlled(value, defaultValue);\n const [savedColors, setSavedColors] = useControlled(\n savedColorsValue,\n defaultSavedColorsValue\n );\n const elementId = useUniqueId(id, \"hvdropdown\");\n const hasLabel = label != null;\n const hasDescription = description != null;\n\n const handleToggle: HvDropdownProps[\"onToggle\"] = (_, open) => {\n setIsOpen(open);\n };\n\n const handleSelect = (\n val: ColorState | { hex: string; source: string }\n ) => {\n onChange?.(val.hex);\n onChangeComplete?.(val.hex);\n setColor(val.hex);\n };\n\n const handleOnChange = (\n val: ColorState | { hex: string; source: string }\n ) => {\n onChange?.(val.hex);\n setColor(val.hex);\n };\n\n const handleOnChangeComplete = (\n val: ColorState | { hex: string; source: string }\n ) => {\n onChangeComplete?.(val.hex);\n setColor(val.hex);\n };\n\n const handleAddColor = () => {\n // When no color is provided, react-color sets the picker to #000000.\n // This is the color that should be added in this case.\n const colorToAdd = color || \"#000000\";\n\n onSavedColorAdded?.(colorToAdd);\n setSavedColors([...savedColors, colorToAdd]);\n };\n\n const handleRemoveColor = (val: string, position: number) => {\n if (savedColors[position] === val) {\n const sColors = [...savedColors];\n sColors.splice(position, 1);\n onSavedColorRemoved?.(val);\n setSavedColors(sColors);\n }\n };\n\n const setFocusToContent = (containerRef: HTMLElement | null) => {\n const inputs = containerRef?.getElementsByTagName(\"input\");\n if (inputs && inputs.length > 0) {\n inputs[0].focus();\n }\n };\n\n return (\n <HvFormElement\n id={id}\n name={name}\n disabled={disabled}\n required={required}\n className={cx(classes.root, className)}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvBaseDropdown\n ref={ref}\n variableWidth\n className={className}\n expanded={isOpen}\n onToggle={handleToggle}\n onContainerCreation={setFocusToContent}\n classes={{\n root: cx({ [classes.dropdownRootIconOnly]: iconOnly }),\n selection: cx(iconOnly && css({ padding: 0 })),\n }}\n adornment={\n iconOnly && color ? (\n <Checkbox\n className={classes.headerColorIconOnly}\n color={[color, \"transparent\"]}\n />\n ) : dropdownIcon === \"colorPicker\" ? (\n <ColorPicker className={classes.colorPickerIcon} />\n ) : undefined\n }\n placeholder={\n iconOnly ? undefined : color ? (\n <>\n <Checkbox\n className={classes.headerColorIcon}\n color={[color, \"transparent\"]}\n />\n <HvTypography\n className={classes.headerColorValue}\n variant=\"label\"\n >\n {color}\n </HvTypography>\n </>\n ) : (\n placeholder\n )\n }\n aria-label={ariaLabel}\n aria-labelledby={\n [label && setId(elementId, \"label\"), ariaLabelledBy]\n .join(\" \")\n .trim() || undefined\n }\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n >\n <HvPanel className={classes.panel}>\n <div className={classes.colorPicker}>\n {recommendedColorsPosition === \"top\" && (\n <PresetColors\n className={classes.recommendedColorsRoot}\n colors={recommendedColors}\n onClick={handleSelect}\n title={\n showLabels ? labels?.recommendedColorsLabel : undefined\n }\n />\n )}\n {showCustomColors && (\n <Picker\n classes={{\n fields: cx({\n [classes.pickerFields]:\n recommendedColorsPosition === \"bottom\" ||\n showSavedColors,\n }),\n }}\n title={showLabels ? labels?.customColorsLabel : undefined}\n color={color}\n onChange={handleOnChange}\n onChangeComplete={handleOnChangeComplete}\n />\n )}\n {showSavedColors && (\n <SavedColors\n colors={savedColors}\n onAddColor={handleAddColor}\n onClickColor={handleSelect}\n onRemoveColor={handleRemoveColor}\n deleteButtonAriaLabel={deleteSavedColorButtonArialLabel}\n addButtonAriaLabel={addSavedColorButtonAriaLabel}\n />\n )}\n {recommendedColorsPosition === \"bottom\" && (\n <PresetColors\n colors={recommendedColors}\n onClick={handleSelect}\n title={\n showLabels ? labels?.recommendedColorsLabel : undefined\n }\n />\n )}\n </div>\n </HvPanel>\n </HvBaseDropdown>\n </HvFormElement>\n );\n }\n);\n"],"names":["DEFAULT_LABELS","recommendedColorsLabel","customColorsLabel","HvColorPicker","forwardRef","props","ref","id","name","required","disabled","label","ariaLabel","ariaLabelledBy","description","ariaDescribedBy","className","classes","classesProp","value","onChange","onChangeComplete","defaultValue","expanded","defaultExpanded","recommendedColorsPosition","recommendedColors","showLabels","labels","labelsProp","dropdownIcon","placeholder","iconOnly","showSavedColors","showCustomColors","savedColorsValue","defaultSavedColorsValue","onSavedColorAdded","onSavedColorRemoved","deleteSavedColorButtonArialLabel","addSavedColorButtonAriaLabel","useDefaultProps","css","cx","useClasses","useLabels","isOpen","setIsOpen","useControlled","Boolean","color","setColor","savedColors","setSavedColors","elementId","useUniqueId","hasLabel","hasDescription","handleToggle","_","open","handleSelect","val","hex","handleOnChange","handleOnChangeComplete","handleAddColor","colorToAdd","handleRemoveColor","position","sColors","splice","setFocusToContent","containerRef","inputs","getElementsByTagName","length","focus","jsxs","HvFormElement","root","labelContainer","jsx","HvLabel","setId","HvInfoMessage","HvBaseDropdown","dropdownRootIconOnly","selection","padding","Checkbox","headerColorIconOnly","ColorPicker","colorPickerIcon","undefined","Fragment","headerColorIcon","HvTypography","headerColorValue","join","trim","HvPanel","panel","colorPicker","PresetColors","recommendedColorsRoot","Picker","fields","pickerFields","SavedColors"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmGA,MAAMA,iBAA+C;AAAA,EACnDC,wBAAwB;AAAA,EACxBC,mBAAmB;AACrB;AAMO,MAAMC,gBAAgBC,MAAAA,WAC3B,CAACC,OAAOC,QAAQ;AACR,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC;AAAAA,IACA,cAAcC;AAAAA,IACd,mBAAmBC;AAAAA,IACnBC;AAAAA,IACA,oBAAoBC;AAAAA,IACpBC;AAAAA,IACAC,SAASC;AAAAA,IACTC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,eAAe;AAAA,IACfC;AAAAA,IACAC,kBAAkB;AAAA,IAClBC,4BAA4B;AAAA,IAC5BC,oBAAoB,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G;AAAA,UACT,CAAC1B,QAAQ2F,YAAY,GACnBnF,8BAA8B,YAC9BQ;AAAAA,QAAAA,CACH;AAAA,MACH,GACA,OAAON,aAAaC,iCAAQ1B,oBAAoB4F,QAChD,OACA,UAAU9B,gBACV,kBAAkBC,uBAErB,CAAA;AAAA,MACAhC,mBACCiD,2BAAA,IAAC2B,YACC,aAAA,EAAA,QAAQzD,aACR,YAAYc,gBACZ,cAAcL,cACd,eAAeO,mBACf,uBAAuB7B,kCACvB,oBAAoBC,8BAEvB;AAAA,MACAf,8BAA8B,YAC5ByD,2BAAA,IAAAsB,aAAA,cAAA,EACC,QAAQ9E,mBACR,SAASmC,cACT,OACElC,aAAaC,iCAAQ3B,yBAAyB6F,OAGnD,CAAA;AAAA,IAAA,EACH,CAAA,EACF,CAAA,GACF;AAAA,EACF,EAAA,CAAA;AAEJ,CACF;;;"}
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("@emotion/react/jsx-runtime");
4
4
  const React = require("react");
5
- const useDefaultProps = require("../../hooks/useDefaultProps.cjs");
5
+ const material = require("@mui/material");
6
6
  const uikitReactIcons = require("@hitachivantara/uikit-react-icons");
7
+ const useDefaultProps = require("../../hooks/useDefaultProps.cjs");
7
8
  const useControlled = require("../../hooks/useControlled.cjs");
8
9
  const useUniqueId = require("../../hooks/useUniqueId.cjs");
9
10
  const useLabels = require("../../hooks/useLabels.cjs");
@@ -29,7 +30,7 @@ const DEFAULT_LABELS = {
29
30
  clearLabel: "Clear",
30
31
  invalidLabel: "Invalid date"
31
32
  };
32
- const HvDatePicker = (props) => {
33
+ const HvDatePicker = React.forwardRef((props, ref) => {
33
34
  const {
34
35
  classes: classesProp,
35
36
  className,
@@ -65,7 +66,7 @@ const HvDatePicker = (props) => {
65
66
  showClear = false,
66
67
  disablePortal = true,
67
68
  escapeWithReference = true,
68
- dropdownProps,
69
+ dropdownProps = {},
69
70
  calendarProps,
70
71
  ...others
71
72
  } = useDefaultProps.useDefaultProps("HvDatePicker", props);
@@ -83,6 +84,11 @@ const HvDatePicker = (props) => {
83
84
  const [endDate, setEndDate, rollbackEndDate] = useSavedState.useSavedState(endValue);
84
85
  const [visibleDate, dispatchAction] = useVisibleDate.default(startDate, endDate);
85
86
  const focusTarget = React.useRef(null);
87
+ const {
88
+ ref: refProp,
89
+ ...otherDropdownProps
90
+ } = dropdownProps;
91
+ const dropdownForkedRef = material.useForkRef(ref, refProp);
86
92
  React.useEffect(() => {
87
93
  setStartDate(rangeMode ? startValue : value, true);
88
94
  setEndDate(endValue, true);
@@ -227,7 +233,7 @@ const HvDatePicker = (props) => {
227
233
  hasLabel && /* @__PURE__ */ jsxRuntime.jsx(Label.HvLabel, { id: setId.setId(elementId, "label"), label, className: classes.label }),
228
234
  hasDescription && /* @__PURE__ */ jsxRuntime.jsx(InfoMessage.HvInfoMessage, { id: setId.setId(elementId, "description"), className: classes.description, children: description })
229
235
  ] }),
230
- /* @__PURE__ */ jsxRuntime.jsxs(BaseDropdown.HvBaseDropdown, { role: "combobox", classes: {
236
+ /* @__PURE__ */ jsxRuntime.jsxs(BaseDropdown.HvBaseDropdown, { ref: dropdownForkedRef, role: "combobox", classes: {
231
237
  root: classes.dropdown,
232
238
  panel: classes.panel,
233
239
  header: cx({
@@ -239,7 +245,7 @@ const HvDatePicker = (props) => {
239
245
  name: "preventOverflow",
240
246
  enabled: escapeWithReference
241
247
  }]
242
- }, "aria-haspopup": "dialog", "aria-label": ariaLabel, "aria-labelledby": [label && setId.setId(elementId, "label"), ariaLabelledBy].join(" ").trim() || void 0, "aria-invalid": isStateInvalid ? true : void 0, "aria-errormessage": errorMessageId, "aria-describedby": [description && setId.setId(elementId, "description"), ariaDescribedBy].join(" ").trim() || void 0, ...dropdownProps, children: [
248
+ }, "aria-haspopup": "dialog", "aria-label": ariaLabel, "aria-labelledby": [label && setId.setId(elementId, "label"), ariaLabelledBy].join(" ").trim() || void 0, "aria-invalid": isStateInvalid ? true : void 0, "aria-errormessage": errorMessageId, "aria-describedby": [description && setId.setId(elementId, "description"), ariaDescribedBy].join(" ").trim() || void 0, ...otherDropdownProps, children: [
243
249
  /* @__PURE__ */ jsxRuntime.jsx("div", { ref: focusTarget, tabIndex: -1 }),
244
250
  /* @__PURE__ */ jsxRuntime.jsx(Calendar.HvCalendar, { id: setId.setId(id, "calendar"), startAdornment, onChange: handleDateChange, onInputChange: handleInputDateChange, onVisibleDateChange: (_event, type, month, target) => {
245
251
  dispatchAction({
@@ -252,7 +258,7 @@ const HvDatePicker = (props) => {
252
258
  ] }),
253
259
  canShowError && /* @__PURE__ */ jsxRuntime.jsx(WarningText.HvWarningText, { id: setId.setId(elementId, "error"), disableBorder: true, className: cx(classes.error), children: validationMessage })
254
260
  ] });
255
- };
261
+ });
256
262
  exports.datePickerClasses = DatePicker_styles.staticClasses;
257
263
  exports.HvDatePicker = HvDatePicker;
258
264
  //# sourceMappingURL=DatePicker.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"DatePicker.cjs","sources":["../../../../src/components/DatePicker/DatePicker.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\n\nimport { Calendar } from \"@hitachivantara/uikit-react-icons\";\n\nimport { useControlled } from \"@core/hooks/useControlled\";\nimport { useUniqueId } from \"@core/hooks/useUniqueId\";\nimport { useLabels } from \"@core/hooks/useLabels\";\nimport { ExtractNames } from \"@core/utils/classes\";\nimport { setId } from \"@core/utils/setId\";\nimport { useSavedState } from \"@core/utils/useSavedState\";\nimport {\n isInvalid,\n HvLabel,\n HvFormStatus,\n HvWarningText,\n HvFormElement,\n HvInfoMessage,\n HvFormElementProps,\n} from \"@core/components/Forms\";\nimport { isDate } from \"@core/components/Calendar/utils\";\nimport { HvCalendar, HvCalendarProps } from \"@core/components/Calendar\";\nimport {\n HvBaseDropdown,\n HvBaseDropdownProps,\n} from \"@core/components/BaseDropdown\";\nimport { HvTypography } from \"@core/components/Typography\";\nimport { HvActionBar } from \"@core/components/ActionBar\";\nimport { HvButton } from \"@core/components/Button\";\n\nimport { getDateLabel } from \"./utils\";\nimport useVisibleDate from \"./useVisibleDate\";\nimport { staticClasses, useClasses } from \"./DatePicker.styles\";\n\nexport { staticClasses as datePickerClasses };\n\nexport type HvDatePickerClasses = ExtractNames<typeof useClasses>;\n\nconst DEFAULT_LABELS = {\n applyLabel: \"Apply\",\n cancelLabel: \"Cancel\",\n clearLabel: \"Clear\",\n invalidLabel: \"Invalid date\",\n};\n\n/** @deprecated use `HvFormStatus` instead */\nexport type HvDatePickerStatus = HvFormStatus;\n\nexport interface HvDatePickerProps\n extends Omit<HvFormElementProps, \"onChange\">,\n Pick<\n HvBaseDropdownProps,\n \"disablePortal\" | \"expanded\" | \"defaultExpanded\" | \"onToggle\"\n > {\n /**\n * Identifies the element that provides an error message for the date picker.\n *\n * Will only be used when the validation status is invalid.\n */\n \"aria-errormessage\"?: string;\n /**\n * The callback fired when the value changes.\n */\n onChange?: (date?: Date, endDate?: Date) => void;\n /**\n * The callback fired when user clicks on cancel.\n */\n onCancel?: () => void;\n /**\n * The callback fired when user clicks on clear.\n */\n onClear?: () => void;\n /**\n * An object containing all the labels for the datepicker.\n */\n labels?: {\n /**\n * Apply button label.\n */\n applyLabel?: string;\n /**\n * Cancel button label.\n */\n cancelLabel?: string;\n /**\n * Clear button label.\n */\n clearLabel?: string;\n /**\n * Invalid Date label.\n */\n invalidDateLabel?: string;\n };\n /**\n * The initial value of the input when in single calendar mode.\n */\n value?: Date;\n /**\n * The initial value for the start date when in range mode.\n */\n startValue?: Date;\n /**\n * The initial value for the end date when in range mode.\n */\n endValue?: Date;\n /**\n * Flag informing if the the component should be in range mode or in single mode.\n */\n // TODO: remove this in favour of discriminated union\n rangeMode?: boolean;\n /**\n * The placement where the calendar should be placed according to the input. Options are `left` or `right`.\n * Note this prop only affects the calendar when in `rangeMode`.\n */\n horizontalPlacement?: \"left\" | \"right\";\n /**\n * The calendar locale. If undefined, it uses calendar default\n */\n locale?: string;\n /**\n * Controls if actions buttons are visible at the calendar.\n */\n showActions?: boolean;\n /**\n * Controls if clear button is visible at the calendar,\n * only works if showing actions or in range mode.\n */\n showClear?: boolean;\n /**\n * Sets if the calendar container should follow the date picker input out of the screen or stay visible.\n */\n escapeWithReference?: boolean;\n /**\n * An element placed before the Calendar\n */\n startAdornment?: React.ReactNode;\n /**\n * An object containing props to be passed onto the baseDropdown.\n */\n dropdownProps?: Partial<HvBaseDropdownProps>;\n /**\n * Additional props passed to the HvCalendar component.\n */\n calendarProps?: Partial<HvCalendarProps>;\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvDatePickerClasses;\n}\n\n/**\n * A date picker, popup calendar or date range picker is a graphical user\n * interface widget which allows the user to select a date from a calendar.\n */\nexport const HvDatePicker = (props: HvDatePickerProps) => {\n const {\n classes: classesProp,\n className,\n\n id,\n name,\n\n required = false,\n disabled = false,\n readOnly,\n\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n\n onChange,\n onCancel,\n onClear,\n status,\n statusMessage,\n \"aria-errormessage\": ariaErrorMessage,\n\n placeholder,\n\n labels: labelsProp,\n\n value,\n startValue,\n endValue,\n\n expanded,\n defaultExpanded,\n onToggle,\n rangeMode = false,\n startAdornment,\n horizontalPlacement = \"right\",\n locale: localeProp,\n showActions = false,\n showClear = false,\n disablePortal = true,\n escapeWithReference = true,\n dropdownProps,\n calendarProps,\n ...others\n } = useDefaultProps(\"HvDatePicker\", props);\n\n const { classes, cx } = useClasses(classesProp);\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const elementId = useUniqueId(id, \"hvdatepicker\");\n\n const [validationState, setValidationState] = useControlled(\n status,\n \"standBy\"\n );\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const locale = localeProp || \"en-US\";\n\n const [calendarOpen, setCalendarOpen] = useControlled(\n expanded,\n Boolean(defaultExpanded)\n );\n\n const [startDate, setStartDate, rollbackStartDate] = useSavedState(\n rangeMode ? startValue : value\n );\n const [endDate, setEndDate, rollbackEndDate] = useSavedState(endValue);\n\n const [visibleDate, dispatchAction] = useVisibleDate(startDate, endDate);\n\n const focusTarget = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n setStartDate(rangeMode ? startValue : value, true);\n setEndDate(endValue, true);\n }, [value, startValue, endValue, rangeMode, setStartDate, setEndDate]);\n\n const endDateIsSet = useRef(false);\n endDateIsSet.current = endDate != null;\n\n useEffect(() => {\n if (startDate != null) {\n dispatchAction({\n type: \"month_year\",\n target: endDateIsSet.current ? \"left\" : \"best\",\n year: startDate.getFullYear(),\n month: startDate.getMonth() + 1,\n });\n }\n }, [dispatchAction, startDate]);\n\n useEffect(() => {\n if (endDate != null) {\n dispatchAction({\n type: \"month_year\",\n target: \"right\",\n year: endDate.getFullYear(),\n month: endDate.getMonth() + 1,\n });\n }\n }, [dispatchAction, endDate]);\n\n /**\n * Handles the `Apply` action. Both single and ranged modes are handled here.\n */\n const handleApply = () => {\n setStartDate(startDate, true);\n setEndDate(endDate ?? startDate, true);\n\n onChange?.(startDate, endDate);\n\n setValidationState(() => {\n // this will only run if status is uncontrolled\n if (required && (!isDate(startDate) || (rangeMode && !isDate(endDate)))) {\n return \"invalid\";\n }\n\n return \"valid\";\n });\n\n setCalendarOpen(false);\n };\n\n /**\n * Handles the `Cancel` action. Both single and ranged modes are handled here.\n */\n const handleCancel = () => {\n rollbackStartDate();\n rollbackEndDate();\n\n onCancel?.();\n\n setCalendarOpen(false);\n };\n\n /**\n * Handles the `Cancel` action. Both single and ranged modes are handled here.\n */\n const handleClear = () => {\n setStartDate(undefined, false);\n setEndDate(undefined, false);\n onClear?.();\n };\n\n const handleCalendarClose = () => {\n const shouldSave = !(rangeMode || showActions);\n if (shouldSave) {\n handleApply();\n } else {\n handleCancel();\n }\n };\n\n const handleToggle: HvBaseDropdownProps[\"onToggle\"] = (evt, open) => {\n /* \n If evt is null this toggle wasn't triggered by the user.\n instead it was triggered by the baseDropdown useEffect after\n the datepicker changed the expanded value this baseDropdown behavior needs a review\n */\n if (evt === null) return;\n onToggle?.(evt, open);\n setCalendarOpen(open);\n if (!open) handleCalendarClose();\n };\n\n const focusOnContainer = () => {\n focusTarget.current?.focus();\n };\n\n const handleDateChange: HvCalendarProps[\"onChange\"] = (event, newDate) => {\n if (!isDate(newDate)) return;\n\n const autoSave = !showActions && !rangeMode;\n\n if (rangeMode) {\n if (!startDate || (startDate && endDate) || newDate < startDate) {\n setStartDate(newDate);\n setEndDate(undefined);\n } else {\n setEndDate(newDate);\n }\n } else {\n setStartDate(newDate, autoSave);\n }\n\n if (autoSave) {\n onChange?.(newDate);\n\n setValidationState(() => {\n // this will only run if status is uncontrolled\n if (required && !isDate(newDate)) {\n return \"invalid\";\n }\n\n return \"valid\";\n });\n\n setCalendarOpen(false);\n }\n };\n\n const handleInputDateChange: HvCalendarProps[\"onInputChange\"] = (\n event,\n newDate,\n position\n ) => {\n if (!isDate(newDate)) return;\n\n if (!rangeMode) {\n handleDateChange(event as any, newDate);\n return;\n }\n\n if (position === \"left\") {\n if (endDate) setStartDate(newDate > endDate ? endDate : newDate);\n } else if (position === \"right\") {\n if (!startDate) {\n if (endDate) setStartDate(newDate > endDate ? endDate : newDate);\n return;\n }\n setEndDate(newDate < startDate ? startDate : newDate);\n }\n };\n\n /**\n * Renders the container for the action elements.\n */\n const renderActions = () => (\n <HvActionBar className={cx({ [classes.actionContainer]: showClear })}>\n {showClear && (\n <div className={classes.leftContainer}>\n <HvButton\n id={setId(id, \"action\", \"clear\")}\n className={classes.action}\n variant=\"primaryGhost\"\n onClick={handleClear}\n >\n {labels?.clearLabel}\n </HvButton>\n </div>\n )}\n <div className={classes.rightContainer}>\n <HvButton\n id={setId(id, \"action\", \"apply\")}\n className={classes.action}\n variant=\"primaryGhost\"\n onClick={handleApply}\n >\n {labels?.applyLabel}\n </HvButton>\n <HvButton\n id={setId(id, \"action\", \"cancel\")}\n className={classes.action}\n variant=\"primaryGhost\"\n onClick={handleCancel}\n >\n {labels?.cancelLabel}\n </HvButton>\n </div>\n </HvActionBar>\n );\n\n const renderInput = (dateString: string) => {\n return (\n <HvTypography\n className={cx(classes.inputText, { [classes.dateText]: dateString })}\n variant=\"label\"\n >\n {dateString || placeholder || \"\"}\n </HvTypography>\n );\n };\n const dateValue = rangeMode ? { startDate, endDate } : startDate;\n\n const hasLabel = label != null;\n const hasDescription = description != null;\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 = isInvalid(validationState);\n\n let errorMessageId;\n if (isStateInvalid) {\n errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n }\n\n return (\n <HvFormElement\n id={id}\n name={name}\n value={dateValue}\n status={validationState}\n disabled={disabled}\n required={required}\n className={cx(classes.root, className)}\n readOnly={readOnly}\n {...others}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvBaseDropdown\n role=\"combobox\"\n classes={{\n root: classes.dropdown,\n panel: classes.panel,\n header: cx({ [classes.dropdownHeaderInvalid]: isStateInvalid }),\n headerOpen: classes.dropdownHeaderOpen,\n }}\n readOnly={readOnly}\n disabled={disabled}\n disablePortal={disablePortal}\n variableWidth\n placement={horizontalPlacement}\n expanded={calendarOpen}\n onToggle={handleToggle}\n onClickOutside={handleCalendarClose}\n onContainerCreation={focusOnContainer}\n placeholder={renderInput(getDateLabel(dateValue, rangeMode, locale))}\n adornment={\n <Calendar\n className={classes.icon}\n color={disabled ? \"secondary_80\" : undefined}\n />\n }\n popperProps={{\n modifiers: [\n { name: \"preventOverflow\", enabled: escapeWithReference },\n ],\n }}\n aria-haspopup=\"dialog\"\n aria-label={ariaLabel}\n aria-labelledby={\n [label && setId(elementId, \"label\"), ariaLabelledBy]\n .join(\" \")\n .trim() || undefined\n }\n aria-invalid={isStateInvalid ? true : undefined}\n aria-errormessage={errorMessageId}\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n {...dropdownProps}\n >\n <div ref={focusTarget} tabIndex={-1} />\n <HvCalendar\n id={setId(id, \"calendar\")}\n startAdornment={startAdornment}\n onChange={handleDateChange}\n onInputChange={handleInputDateChange}\n onVisibleDateChange={(_event, type, month, target) => {\n dispatchAction({ type, target, month });\n }}\n locale={locale}\n {...visibleDate}\n {...calendarProps}\n invalidDateLabel={labels?.invalidDateLabel}\n />\n {(rangeMode || showActions) && renderActions()}\n </HvBaseDropdown>\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={cx(classes.error)}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n};\n"],"names":["DEFAULT_LABELS","applyLabel","cancelLabel","clearLabel","invalidLabel","HvDatePicker","props","classes","classesProp","className","id","name","required","disabled","readOnly","label","ariaLabel","ariaLabelledBy","description","ariaDescribedBy","onChange","onCancel","onClear","status","statusMessage","ariaErrorMessage","placeholder","labels","labelsProp","value","startValue","endValue","expanded","defaultExpanded","onToggle","rangeMode","startAdornment","horizontalPlacement","locale","localeProp","showActions","showClear","disablePortal","escapeWithReference","dropdownProps","calendarProps","others","useDefaultProps","cx","useClasses","useLabels","elementId","useUniqueId","validationState","setValidationState","useControlled","validationMessage","calendarOpen","setCalendarOpen","Boolean","startDate","setStartDate","rollbackStartDate","useSavedState","endDate","setEndDate","rollbackEndDate","visibleDate","dispatchAction","useVisibleDate","focusTarget","useRef","useEffect","endDateIsSet","current","type","target","year","getFullYear","month","getMonth","handleApply","isDate","handleCancel","handleClear","undefined","handleCalendarClose","shouldSave","handleToggle","evt","open","focusOnContainer","focus","handleDateChange","event","newDate","autoSave","handleInputDateChange","position","renderActions","jsxs","HvActionBar","actionContainer","jsx","leftContainer","HvButton","setId","action","rightContainer","renderInput","dateString","HvTypography","inputText","dateText","dateValue","hasLabel","hasDescription","canShowError","isStateInvalid","isInvalid","errorMessageId","HvFormElement","root","labelContainer","HvLabel","HvInfoMessage","HvBaseDropdown","dropdown","panel","header","dropdownHeaderInvalid","headerOpen","dropdownHeaderOpen","getDateLabel","Calendar","icon","modifiers","enabled","join","trim","HvCalendar","_event","invalidDateLabel","HvWarningText","error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAMA,iBAAiB;AAAA,EACrBC,YAAY;AAAA,EACZC,aAAa;AAAA,EACbC,YAAY;AAAA,EACZC,cAAc;AAChB;AA+GaC,MAAAA,eAAeA,CAACC,UAA6B;AAClD,QAAA;AAAA,IACJC,SAASC;AAAAA,IACTC;AAAAA,IAEAC;AAAAA,IACAC;AAAAA,IAEAC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC;AAAAA,IAEAC;AAAAA,IACA,cAAcC;AAAAA,IACd,mBAAmBC;AAAAA,IACnBC;AAAAA,IACA,oBAAoBC;AAAAA,IAEpBC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACA,qBAAqBC;AAAAA,IAErBC;AAAAA,IAEAC,QAAQC;AAAAA,IAERC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IAEAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,YAAY;AAAA,IACZC;AAAAA,IACAC,sBAAsB;AAAA,IACtBC,QAAQC;AAAAA,IACRC,cAAc;AAAA,IACdC,YAAY;AAAA,IACZC,gBAAgB;AAAA,IAChBC,sBAAsB;AAAA,IACtBC;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AK,GAAG,EACRC,UAAUtD,QAEf,gBAAciC,iBAAiB,OAAOjC,QACtC,qBAAmBmC,gBACnB,oBACE,CAACtG,eAAewF,MAAAA,MAAMvD,WAAW,aAAa,GAAGhC,eAAe,EAC7DuH,KAAK,GAAG,EACRC,KAAUtD,KAAAA,QAEf,GAAIzC,eAEJ,UAAA;AAAA,MAAA2D,2BAAA,IAAC,OAAI,EAAA,KAAKjC,aAAa,UAAU,IAAG;AAAA,qCACnCsE,SACC,YAAA,EAAA,IAAIlC,MAAMhG,MAAAA,IAAI,UAAU,GACxB,gBACA,UAAUmF,kBACV,eAAeI,uBACf,qBAAqB,CAAC4C,QAAQlE,MAAMI,OAAOH,WAAW;AACrC,uBAAA;AAAA,UAAED;AAAAA,UAAMC;AAAAA,UAAQG;AAAAA,QAAAA,CAAO;AAAA,MAAA,GAExC,QACA,GAAIZ,aACAtB,GAAAA,eACJ,kBAAkBlB,iCAAQmH,kBAAiB;AAAA,OAE3C3G,aAAaK,gBAAgB2D,cAAc;AAAA,IAAA,GAC/C;AAAA,IACCkB,gBACCd,2BAAA,IAACwC,2BACC,EAAA,IAAIrC,YAAMvD,WAAW,OAAO,GAC5B,eAAa,MACb,WAAWH,GAAGzC,QAAQyI,KAAK,GAE1BxF,UACH,mBAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ;;;"}
1
+ {"version":3,"file":"DatePicker.cjs","sources":["../../../../src/components/DatePicker/DatePicker.tsx"],"sourcesContent":["import { forwardRef, useEffect, useRef } from \"react\";\n\nimport { useForkRef } from \"@mui/material\";\n\nimport { Calendar } from \"@hitachivantara/uikit-react-icons\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { useControlled } from \"@core/hooks/useControlled\";\nimport { useUniqueId } from \"@core/hooks/useUniqueId\";\nimport { useLabels } from \"@core/hooks/useLabels\";\nimport { ExtractNames } from \"@core/utils/classes\";\nimport { setId } from \"@core/utils/setId\";\nimport { useSavedState } from \"@core/utils/useSavedState\";\nimport {\n isInvalid,\n HvLabel,\n HvFormStatus,\n HvWarningText,\n HvFormElement,\n HvInfoMessage,\n HvFormElementProps,\n} from \"@core/components/Forms\";\nimport { isDate } from \"@core/components/Calendar/utils\";\nimport { HvCalendar, HvCalendarProps } from \"@core/components/Calendar\";\nimport {\n HvBaseDropdown,\n HvBaseDropdownProps,\n} from \"@core/components/BaseDropdown\";\nimport { HvTypography } from \"@core/components/Typography\";\nimport { HvActionBar } from \"@core/components/ActionBar\";\nimport { HvButton } from \"@core/components/Button\";\n\nimport { getDateLabel } from \"./utils\";\nimport useVisibleDate from \"./useVisibleDate\";\nimport { staticClasses, useClasses } from \"./DatePicker.styles\";\n\nexport { staticClasses as datePickerClasses };\n\nexport type HvDatePickerClasses = ExtractNames<typeof useClasses>;\n\nconst DEFAULT_LABELS = {\n applyLabel: \"Apply\",\n cancelLabel: \"Cancel\",\n clearLabel: \"Clear\",\n invalidLabel: \"Invalid date\",\n};\n\n/** @deprecated use `HvFormStatus` instead */\nexport type HvDatePickerStatus = HvFormStatus;\n\nexport interface HvDatePickerProps\n extends Omit<HvFormElementProps, \"onChange\">,\n Pick<\n HvBaseDropdownProps,\n \"disablePortal\" | \"expanded\" | \"defaultExpanded\" | \"onToggle\"\n > {\n /**\n * Identifies the element that provides an error message for the date picker.\n *\n * Will only be used when the validation status is invalid.\n */\n \"aria-errormessage\"?: string;\n /**\n * The callback fired when the value changes.\n */\n onChange?: (date?: Date, endDate?: Date) => void;\n /**\n * The callback fired when user clicks on cancel.\n */\n onCancel?: () => void;\n /**\n * The callback fired when user clicks on clear.\n */\n onClear?: () => void;\n /**\n * An object containing all the labels for the datepicker.\n */\n labels?: {\n /**\n * Apply button label.\n */\n applyLabel?: string;\n /**\n * Cancel button label.\n */\n cancelLabel?: string;\n /**\n * Clear button label.\n */\n clearLabel?: string;\n /**\n * Invalid Date label.\n */\n invalidDateLabel?: string;\n };\n /**\n * The initial value of the input when in single calendar mode.\n */\n value?: Date;\n /**\n * The initial value for the start date when in range mode.\n */\n startValue?: Date;\n /**\n * The initial value for the end date when in range mode.\n */\n endValue?: Date;\n /**\n * Flag informing if the the component should be in range mode or in single mode.\n */\n // TODO: remove this in favour of discriminated union\n rangeMode?: boolean;\n /**\n * The placement where the calendar should be placed according to the input. Options are `left` or `right`.\n * Note this prop only affects the calendar when in `rangeMode`.\n */\n horizontalPlacement?: \"left\" | \"right\";\n /**\n * The calendar locale. If undefined, it uses calendar default\n */\n locale?: string;\n /**\n * Controls if actions buttons are visible at the calendar.\n */\n showActions?: boolean;\n /**\n * Controls if clear button is visible at the calendar,\n * only works if showing actions or in range mode.\n */\n showClear?: boolean;\n /**\n * Sets if the calendar container should follow the date picker input out of the screen or stay visible.\n */\n escapeWithReference?: boolean;\n /**\n * An element placed before the Calendar\n */\n startAdornment?: React.ReactNode;\n /**\n * An object containing props to be passed onto the baseDropdown.\n */\n dropdownProps?: Partial<HvBaseDropdownProps>;\n /**\n * Additional props passed to the HvCalendar component.\n */\n calendarProps?: Partial<HvCalendarProps>;\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvDatePickerClasses;\n}\n\n/**\n * A date picker, popup calendar or date range picker is a graphical user\n * interface widget which allows the user to select a date from a calendar.\n */\nexport const HvDatePicker = forwardRef<HTMLDivElement, HvDatePickerProps>(\n (props, ref) => {\n const {\n classes: classesProp,\n className,\n\n id,\n name,\n\n required = false,\n disabled = false,\n readOnly,\n\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n\n onChange,\n onCancel,\n onClear,\n status,\n statusMessage,\n \"aria-errormessage\": ariaErrorMessage,\n\n placeholder,\n\n labels: labelsProp,\n\n value,\n startValue,\n endValue,\n\n expanded,\n defaultExpanded,\n onToggle,\n rangeMode = false,\n startAdornment,\n horizontalPlacement = \"right\",\n locale: localeProp,\n showActions = false,\n showClear = false,\n disablePortal = true,\n escapeWithReference = true,\n dropdownProps = {},\n calendarProps,\n ...others\n } = useDefaultProps(\"HvDatePicker\", props);\n\n const { classes, cx } = useClasses(classesProp);\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const elementId = useUniqueId(id, \"hvdatepicker\");\n\n const [validationState, setValidationState] = useControlled(\n status,\n \"standBy\"\n );\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const locale = localeProp || \"en-US\";\n\n const [calendarOpen, setCalendarOpen] = useControlled(\n expanded,\n Boolean(defaultExpanded)\n );\n\n const [startDate, setStartDate, rollbackStartDate] = useSavedState(\n rangeMode ? startValue : value\n );\n const [endDate, setEndDate, rollbackEndDate] = useSavedState(endValue);\n\n const [visibleDate, dispatchAction] = useVisibleDate(startDate, endDate);\n\n const focusTarget = useRef<HTMLDivElement>(null);\n\n const { ref: refProp, ...otherDropdownProps } = dropdownProps;\n const dropdownForkedRef = useForkRef(ref, refProp);\n\n useEffect(() => {\n setStartDate(rangeMode ? startValue : value, true);\n setEndDate(endValue, true);\n }, [value, startValue, endValue, rangeMode, setStartDate, setEndDate]);\n\n const endDateIsSet = useRef(false);\n endDateIsSet.current = endDate != null;\n\n useEffect(() => {\n if (startDate != null) {\n dispatchAction({\n type: \"month_year\",\n target: endDateIsSet.current ? \"left\" : \"best\",\n year: startDate.getFullYear(),\n month: startDate.getMonth() + 1,\n });\n }\n }, [dispatchAction, startDate]);\n\n useEffect(() => {\n if (endDate != null) {\n dispatchAction({\n type: \"month_year\",\n target: \"right\",\n year: endDate.getFullYear(),\n month: endDate.getMonth() + 1,\n });\n }\n }, [dispatchAction, endDate]);\n\n /**\n * Handles the `Apply` action. Both single and ranged modes are handled here.\n */\n const handleApply = () => {\n setStartDate(startDate, true);\n setEndDate(endDate ?? startDate, true);\n\n onChange?.(startDate, endDate);\n\n setValidationState(() => {\n // this will only run if status is uncontrolled\n if (\n required &&\n (!isDate(startDate) || (rangeMode && !isDate(endDate)))\n ) {\n return \"invalid\";\n }\n\n return \"valid\";\n });\n\n setCalendarOpen(false);\n };\n\n /**\n * Handles the `Cancel` action. Both single and ranged modes are handled here.\n */\n const handleCancel = () => {\n rollbackStartDate();\n rollbackEndDate();\n\n onCancel?.();\n\n setCalendarOpen(false);\n };\n\n /**\n * Handles the `Cancel` action. Both single and ranged modes are handled here.\n */\n const handleClear = () => {\n setStartDate(undefined, false);\n setEndDate(undefined, false);\n onClear?.();\n };\n\n const handleCalendarClose = () => {\n const shouldSave = !(rangeMode || showActions);\n if (shouldSave) {\n handleApply();\n } else {\n handleCancel();\n }\n };\n\n const handleToggle: HvBaseDropdownProps[\"onToggle\"] = (evt, open) => {\n /* \n If evt is null this toggle wasn't triggered by the user.\n instead it was triggered by the baseDropdown useEffect after\n the datepicker changed the expanded value this baseDropdown behavior needs a review\n */\n if (evt === null) return;\n onToggle?.(evt, open);\n setCalendarOpen(open);\n if (!open) handleCalendarClose();\n };\n\n const focusOnContainer = () => {\n focusTarget.current?.focus();\n };\n\n const handleDateChange: HvCalendarProps[\"onChange\"] = (event, newDate) => {\n if (!isDate(newDate)) return;\n\n const autoSave = !showActions && !rangeMode;\n\n if (rangeMode) {\n if (!startDate || (startDate && endDate) || newDate < startDate) {\n setStartDate(newDate);\n setEndDate(undefined);\n } else {\n setEndDate(newDate);\n }\n } else {\n setStartDate(newDate, autoSave);\n }\n\n if (autoSave) {\n onChange?.(newDate);\n\n setValidationState(() => {\n // this will only run if status is uncontrolled\n if (required && !isDate(newDate)) {\n return \"invalid\";\n }\n\n return \"valid\";\n });\n\n setCalendarOpen(false);\n }\n };\n\n const handleInputDateChange: HvCalendarProps[\"onInputChange\"] = (\n event,\n newDate,\n position\n ) => {\n if (!isDate(newDate)) return;\n\n if (!rangeMode) {\n handleDateChange(event as any, newDate);\n return;\n }\n\n if (position === \"left\") {\n if (endDate) setStartDate(newDate > endDate ? endDate : newDate);\n } else if (position === \"right\") {\n if (!startDate) {\n if (endDate) setStartDate(newDate > endDate ? endDate : newDate);\n return;\n }\n setEndDate(newDate < startDate ? startDate : newDate);\n }\n };\n\n /**\n * Renders the container for the action elements.\n */\n const renderActions = () => (\n <HvActionBar className={cx({ [classes.actionContainer]: showClear })}>\n {showClear && (\n <div className={classes.leftContainer}>\n <HvButton\n id={setId(id, \"action\", \"clear\")}\n className={classes.action}\n variant=\"primaryGhost\"\n onClick={handleClear}\n >\n {labels?.clearLabel}\n </HvButton>\n </div>\n )}\n <div className={classes.rightContainer}>\n <HvButton\n id={setId(id, \"action\", \"apply\")}\n className={classes.action}\n variant=\"primaryGhost\"\n onClick={handleApply}\n >\n {labels?.applyLabel}\n </HvButton>\n <HvButton\n id={setId(id, \"action\", \"cancel\")}\n className={classes.action}\n variant=\"primaryGhost\"\n onClick={handleCancel}\n >\n {labels?.cancelLabel}\n </HvButton>\n </div>\n </HvActionBar>\n );\n\n const renderInput = (dateString: string) => {\n return (\n <HvTypography\n className={cx(classes.inputText, { [classes.dateText]: dateString })}\n variant=\"label\"\n >\n {dateString || placeholder || \"\"}\n </HvTypography>\n );\n };\n const dateValue = rangeMode ? { startDate, endDate } : startDate;\n\n const hasLabel = label != null;\n const hasDescription = description != null;\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 = isInvalid(validationState);\n\n let errorMessageId;\n if (isStateInvalid) {\n errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n }\n\n return (\n <HvFormElement\n id={id}\n name={name}\n value={dateValue}\n status={validationState}\n disabled={disabled}\n required={required}\n className={cx(classes.root, className)}\n readOnly={readOnly}\n {...others}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvBaseDropdown\n ref={dropdownForkedRef}\n role=\"combobox\"\n classes={{\n root: classes.dropdown,\n panel: classes.panel,\n header: cx({ [classes.dropdownHeaderInvalid]: isStateInvalid }),\n headerOpen: classes.dropdownHeaderOpen,\n }}\n readOnly={readOnly}\n disabled={disabled}\n disablePortal={disablePortal}\n variableWidth\n placement={horizontalPlacement}\n expanded={calendarOpen}\n onToggle={handleToggle}\n onClickOutside={handleCalendarClose}\n onContainerCreation={focusOnContainer}\n placeholder={renderInput(getDateLabel(dateValue, rangeMode, locale))}\n adornment={\n <Calendar\n className={classes.icon}\n color={disabled ? \"secondary_80\" : undefined}\n />\n }\n popperProps={{\n modifiers: [\n { name: \"preventOverflow\", enabled: escapeWithReference },\n ],\n }}\n aria-haspopup=\"dialog\"\n aria-label={ariaLabel}\n aria-labelledby={\n [label && setId(elementId, \"label\"), ariaLabelledBy]\n .join(\" \")\n .trim() || undefined\n }\n aria-invalid={isStateInvalid ? true : undefined}\n aria-errormessage={errorMessageId}\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n {...otherDropdownProps}\n >\n <div ref={focusTarget} tabIndex={-1} />\n <HvCalendar\n id={setId(id, \"calendar\")}\n startAdornment={startAdornment}\n onChange={handleDateChange}\n onInputChange={handleInputDateChange}\n onVisibleDateChange={(_event, type, month, target) => {\n dispatchAction({ type, target, month });\n }}\n locale={locale}\n {...visibleDate}\n {...calendarProps}\n invalidDateLabel={labels?.invalidDateLabel}\n />\n {(rangeMode || showActions) && renderActions()}\n </HvBaseDropdown>\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={cx(classes.error)}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n }\n);\n"],"names":["DEFAULT_LABELS","applyLabel","cancelLabel","clearLabel","invalidLabel","HvDatePicker","forwardRef","props","ref","classes","classesProp","className","id","name","required","disabled","readOnly","label","ariaLabel","ariaLabelledBy","description","ariaDescribedBy","onChange","onCancel","onClear","status","statusMessage","ariaErrorMessage","placeholder","labels","labelsProp","value","startValue","endValue","expanded","defaultExpanded","onToggle","rangeMode","startAdornment","horizontalPlacement","locale","localeProp","showActions","showClear","disablePortal","escapeWithReference","dropdownProps","calendarProps","others","useDefaultProps","cx","useClasses","useLabels","elementId","useUniqueId","validationState","setValidationState","useControlled","validationMessage","calendarOpen","setCalendarOpen","Boolean","startDate","setStartDate","rollbackStartDate","useSavedState","endDate","setEndDate","rollbackEndDate","visibleDate","dispatchAction","useVisibleDate","focusTarget","useRef","refProp","otherDropdownProps","dropdownForkedRef","useForkRef","useEffect","endDateIsSet","current","type","target","year","getFullYear","month","getMonth","handleApply","isDate","handleCancel","handleClear","undefined","handleCalendarClose","shouldSave","handleToggle","evt","open","focusOnContainer","focus","handleDateChange","event","newDate","autoSave","handleInputDateChange","position","renderActions","jsxs","HvActionBar","actionContainer","jsx","leftContainer","HvButton","setId","action","rightContainer","renderInput","dateString","HvTypography","inputText","dateText","dateValue","hasLabel","hasDescription","canShowError","isStateInvalid","isInvalid","errorMessageId","HvFormElement","root","labelContainer","HvLabel","HvInfoMessage","HvBaseDropdown","dropdown","panel","header","dropdownHeaderInvalid","headerOpen","dropdownHeaderOpen","getDateLabel","Calendar","icon","modifiers","enabled","join","trim","HvCalendar","_event","invalidDateLabel","HvWarningText","error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAMA,iBAAiB;AAAA,EACrBC,YAAY;AAAA,EACZC,aAAa;AAAA,EACbC,YAAY;AAAA,EACZC,cAAc;AAChB;AA+GO,MAAMC,eAAeC,MAAAA,WAC1B,CAACC,OAAOC,QAAQ;AACR,QAAA;AAAA,IACJC,SAASC;AAAAA,IACTC;AAAAA,IAEAC;AAAAA,IACAC;AAAAA,IAEAC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC;AAAAA,IAEAC;AAAA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A,IAAA,GAC/C;AAAA,IACCkB,gBACCd,2BAAA,IAACwC,2BACC,EAAA,IAAIrC,YAAM3D,WAAW,OAAO,GAC5B,eAAa,MACb,WAAWH,GAAGzC,QAAQ6I,KAAK,GAE1B5F,UACH,mBAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ,CACF;;;"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("@emotion/react/jsx-runtime");
4
4
  const React = require("react");
5
+ const material = require("@mui/material");
5
6
  const useDefaultProps = require("../../hooks/useDefaultProps.cjs");
6
7
  const setId = require("../../utils/setId.cjs");
7
8
  const utils = require("./utils.cjs");
@@ -25,7 +26,7 @@ const DEFAULT_LABELS = {
25
26
  searchPlaceholder: "Search",
26
27
  multiSelectionConjunction: "/"
27
28
  };
28
- const HvDropdown = (props) => {
29
+ const HvDropdown = React.forwardRef((props, ref) => {
29
30
  const {
30
31
  classes: classesProp,
31
32
  className,
@@ -90,6 +91,13 @@ const HvDropdown = (props) => {
90
91
  console.error("Dropdown/List in virtualized mode requires a height. Please define it.");
91
92
  }
92
93
  const dropdownHeaderRef = React.useRef();
94
+ const {
95
+ ref: refProp,
96
+ dropdownHeaderRef: dropdownHeaderRefProp,
97
+ ...otherBaseDropdownProps
98
+ } = baseDropdownProps;
99
+ const headerForkedRef = material.useForkRef(dropdownHeaderRefProp, dropdownHeaderRef);
100
+ const dropdownForkedRef = material.useForkRef(ref, refProp);
93
101
  const handleToggle = (event, open) => {
94
102
  onToggle == null ? void 0 : onToggle(event, open);
95
103
  setIsOpen(open);
@@ -181,7 +189,7 @@ const HvDropdown = (props) => {
181
189
  hasLabel && /* @__PURE__ */ jsxRuntime.jsx(Label.HvLabel, { id: setId.setId(elementId, "label"), label, className: classes.label }),
182
190
  hasDescription && /* @__PURE__ */ jsxRuntime.jsx(InfoMessage.HvInfoMessage, { id: setId.setId(elementId, "description"), className: classes.description, children: description })
183
191
  ] }),
184
- /* @__PURE__ */ jsxRuntime.jsx(BaseDropdown.HvBaseDropdown, { id: setId.setId(id, "dropdown"), classes: {
192
+ /* @__PURE__ */ jsxRuntime.jsx(BaseDropdown.HvBaseDropdown, { ref: dropdownForkedRef, id: setId.setId(id, "dropdown"), classes: {
185
193
  root: cx(classes.dropdown, {
186
194
  [classes.readOnly]: readOnly
187
195
  }),
@@ -190,13 +198,13 @@ const HvDropdown = (props) => {
190
198
  [classes.dropdownHeaderInvalid]: isStateInvalid
191
199
  }),
192
200
  headerOpen: classes.dropdownHeaderOpen
193
- }, expanded: isOpen, disabled, readOnly, required, disablePortal, placement, popperProps, placeholder: buildHeaderLabel(), onToggle: handleToggle, onClickOutside: handleClickOutside, onContainerCreation: setFocusToContent, role: "combobox", variableWidth, "aria-label": ariaLabel, "aria-labelledby": [label && setId.setId(elementId, "label"), ariaLabelledBy].join(" ").trim() || void 0, "aria-invalid": isStateInvalid ? true : void 0, "aria-errormessage": errorMessageId, "aria-describedby": [description && setId.setId(elementId, "description"), ariaDescribedBy].join(" ").trim() || void 0, onFocus, onBlur, dropdownHeaderRef, ...baseDropdownProps, children: /* @__PURE__ */ jsxRuntime.jsx(List.HvDropdownList, { id: setId.setId(elementId, "values"), classes: {
201
+ }, expanded: isOpen, disabled, readOnly, required, disablePortal, placement, popperProps, placeholder: buildHeaderLabel(), onToggle: handleToggle, onClickOutside: handleClickOutside, onContainerCreation: setFocusToContent, role: "combobox", variableWidth, "aria-label": ariaLabel, "aria-labelledby": [label && setId.setId(elementId, "label"), ariaLabelledBy].join(" ").trim() || void 0, "aria-invalid": isStateInvalid ? true : void 0, "aria-errormessage": errorMessageId, "aria-describedby": [description && setId.setId(elementId, "description"), ariaDescribedBy].join(" ").trim() || void 0, onFocus, onBlur, dropdownHeaderRef: headerForkedRef, ...otherBaseDropdownProps, children: /* @__PURE__ */ jsxRuntime.jsx(List.HvDropdownList, { id: setId.setId(elementId, "values"), classes: {
194
202
  rootList: classes.rootList,
195
203
  dropdownListContainer: classes.dropdownListContainer
196
204
  }, values: internalValues, multiSelect, showSearch, onChange: handleSelection, onCancel: handleCancel, labels, notifyChangesOnFirstRender, hasTooltips, singleSelectionToggle, "aria-label": ariaLabel, "aria-labelledby": hasLabel ? setId.setId(elementId, "label") : void 0, height, maxHeight, virtualized, ...listProps }) }),
197
205
  canShowError && /* @__PURE__ */ jsxRuntime.jsx(WarningText.HvWarningText, { id: setId.setId(elementId, "error"), disableBorder: true, className: classes.error, children: validationMessage })
198
206
  ] });
199
- };
207
+ });
200
208
  exports.dropdownClasses = Dropdown_styles.staticClasses;
201
209
  exports.HvDropdown = HvDropdown;
202
210
  //# sourceMappingURL=Dropdown.cjs.map