@hitachivantara/uikit-react-core 5.30.0 → 5.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/ActionBar/ActionBar.styles.cjs +1 -1
- package/dist/cjs/components/ActionBar/ActionBar.styles.cjs.map +1 -1
- package/dist/cjs/components/BaseCheckBox/BaseCheckBox.cjs +4 -4
- package/dist/cjs/components/BaseCheckBox/BaseCheckBox.cjs.map +1 -1
- package/dist/cjs/components/BaseDropdown/BaseDropdown.cjs +38 -44
- package/dist/cjs/components/BaseDropdown/BaseDropdown.cjs.map +1 -1
- package/dist/cjs/components/BaseRadio/BaseRadio.cjs +3 -3
- package/dist/cjs/components/BaseRadio/BaseRadio.cjs.map +1 -1
- package/dist/cjs/components/BaseSwitch/BaseSwitch.cjs +3 -3
- package/dist/cjs/components/BaseSwitch/BaseSwitch.cjs.map +1 -1
- package/dist/cjs/components/Calendar/Calendar.styles.cjs +1 -1
- package/dist/cjs/components/Calendar/Calendar.styles.cjs.map +1 -1
- package/dist/cjs/components/CheckBox/CheckBox.cjs +3 -3
- package/dist/cjs/components/CheckBox/CheckBox.cjs.map +1 -1
- package/dist/cjs/components/CheckBoxGroup/CheckBoxGroup.cjs +3 -3
- package/dist/cjs/components/CheckBoxGroup/CheckBoxGroup.cjs.map +1 -1
- package/dist/cjs/components/ColorPicker/ColorPicker.cjs +4 -3
- package/dist/cjs/components/ColorPicker/ColorPicker.cjs.map +1 -1
- package/dist/cjs/components/DatePicker/DatePicker.cjs +14 -9
- package/dist/cjs/components/DatePicker/DatePicker.cjs.map +1 -1
- package/dist/cjs/components/Dropdown/Dropdown.cjs +12 -4
- package/dist/cjs/components/Dropdown/Dropdown.cjs.map +1 -1
- package/dist/cjs/components/EmptyState/EmptyState.cjs +1 -1
- package/dist/cjs/components/EmptyState/EmptyState.cjs.map +1 -1
- package/dist/cjs/components/FilterGroup/FilterContent/FilterContent.cjs +3 -3
- package/dist/cjs/components/FilterGroup/FilterContent/FilterContent.cjs.map +1 -1
- package/dist/cjs/components/FilterGroup/FilterGroup.cjs +4 -3
- package/dist/cjs/components/FilterGroup/FilterGroup.cjs.map +1 -1
- package/dist/cjs/components/Header/Navigation/MenuItem/MenuItem.cjs +12 -1
- package/dist/cjs/components/Header/Navigation/MenuItem/MenuItem.cjs.map +1 -1
- package/dist/cjs/components/List/List.cjs.map +1 -1
- package/dist/cjs/components/ListContainer/ListContainer.cjs +2 -2
- package/dist/cjs/components/ListContainer/ListContainer.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/Context.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/QueryBuilder.cjs.map +1 -1
- package/dist/cjs/components/Radio/Radio.cjs +3 -3
- package/dist/cjs/components/Radio/Radio.cjs.map +1 -1
- package/dist/cjs/components/RadioGroup/RadioGroup.cjs +3 -3
- package/dist/cjs/components/RadioGroup/RadioGroup.cjs.map +1 -1
- package/dist/cjs/components/SelectionList/SelectionList.cjs +7 -5
- package/dist/cjs/components/SelectionList/SelectionList.cjs.map +1 -1
- package/dist/cjs/components/Slider/Slider.cjs +5 -5
- package/dist/cjs/components/Slider/Slider.cjs.map +1 -1
- package/dist/cjs/components/Switch/Switch.cjs +3 -3
- package/dist/cjs/components/Switch/Switch.cjs.map +1 -1
- package/dist/cjs/components/TagsInput/TagsInput.cjs +5 -3
- package/dist/cjs/components/TagsInput/TagsInput.cjs.map +1 -1
- package/dist/cjs/components/TimePicker/TimePicker.cjs +14 -8
- package/dist/cjs/components/TimePicker/TimePicker.cjs.map +1 -1
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/utils/useSavedState.cjs.map +1 -1
- package/dist/esm/components/ActionBar/ActionBar.styles.js +1 -1
- package/dist/esm/components/ActionBar/ActionBar.styles.js.map +1 -1
- package/dist/esm/components/BaseCheckBox/BaseCheckBox.js +5 -5
- package/dist/esm/components/BaseCheckBox/BaseCheckBox.js.map +1 -1
- package/dist/esm/components/BaseDropdown/BaseDropdown.js +39 -45
- package/dist/esm/components/BaseDropdown/BaseDropdown.js.map +1 -1
- package/dist/esm/components/BaseRadio/BaseRadio.js +4 -4
- package/dist/esm/components/BaseRadio/BaseRadio.js.map +1 -1
- package/dist/esm/components/BaseSwitch/BaseSwitch.js +4 -4
- package/dist/esm/components/BaseSwitch/BaseSwitch.js.map +1 -1
- package/dist/esm/components/Calendar/Calendar.styles.js +1 -1
- package/dist/esm/components/Calendar/Calendar.styles.js.map +1 -1
- package/dist/esm/components/CheckBox/CheckBox.js +4 -4
- package/dist/esm/components/CheckBox/CheckBox.js.map +1 -1
- package/dist/esm/components/CheckBoxGroup/CheckBoxGroup.js +4 -4
- package/dist/esm/components/CheckBoxGroup/CheckBoxGroup.js.map +1 -1
- package/dist/esm/components/ColorPicker/ColorPicker.js +4 -3
- package/dist/esm/components/ColorPicker/ColorPicker.js.map +1 -1
- package/dist/esm/components/DatePicker/DatePicker.js +15 -10
- package/dist/esm/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/components/Dropdown/Dropdown.js +13 -5
- package/dist/esm/components/Dropdown/Dropdown.js.map +1 -1
- package/dist/esm/components/EmptyState/EmptyState.js +1 -1
- package/dist/esm/components/EmptyState/EmptyState.js.map +1 -1
- package/dist/esm/components/FilterGroup/FilterContent/FilterContent.js +4 -4
- package/dist/esm/components/FilterGroup/FilterContent/FilterContent.js.map +1 -1
- package/dist/esm/components/FilterGroup/FilterGroup.js +4 -3
- package/dist/esm/components/FilterGroup/FilterGroup.js.map +1 -1
- package/dist/esm/components/Header/Navigation/MenuItem/MenuItem.js +12 -1
- package/dist/esm/components/Header/Navigation/MenuItem/MenuItem.js.map +1 -1
- package/dist/esm/components/List/List.js.map +1 -1
- package/dist/esm/components/ListContainer/ListContainer.js +2 -2
- package/dist/esm/components/ListContainer/ListContainer.js.map +1 -1
- package/dist/esm/components/QueryBuilder/Context.js.map +1 -1
- package/dist/esm/components/QueryBuilder/QueryBuilder.js.map +1 -1
- package/dist/esm/components/Radio/Radio.js +4 -4
- package/dist/esm/components/Radio/Radio.js.map +1 -1
- package/dist/esm/components/RadioGroup/RadioGroup.js +4 -4
- package/dist/esm/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/esm/components/SelectionList/SelectionList.js +8 -6
- package/dist/esm/components/SelectionList/SelectionList.js.map +1 -1
- package/dist/esm/components/Slider/Slider.js +5 -5
- package/dist/esm/components/Slider/Slider.js.map +1 -1
- package/dist/esm/components/Switch/Switch.js +4 -4
- package/dist/esm/components/Switch/Switch.js.map +1 -1
- package/dist/esm/components/TagsInput/TagsInput.js +6 -4
- package/dist/esm/components/TagsInput/TagsInput.js.map +1 -1
- package/dist/esm/components/TimePicker/TimePicker.js +15 -9
- package/dist/esm/components/TimePicker/TimePicker.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/useSavedState.js.map +1 -1
- package/dist/types/index.d.ts +349 -189
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuItem.js","sources":["../../../../../../src/components/Header/Navigation/MenuItem/MenuItem.tsx"],"sourcesContent":["import React, { MouseEvent, useContext } from \"react\";\n\nimport { HvTypography } from \"@core/components/Typography\";\nimport { HvBaseProps } from \"@core/types/generic\";\nimport { isKey } from \"@core/utils/keyboardUtils\";\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { useDefaultProps } from \"@core/hooks\";\nimport { FocusContext } from \"../utils/FocusContext\";\nimport { SelectionContext } from \"../utils/SelectionContext\";\nimport { useClasses, staticClasses } from \"./MenuItem.styles\";\nimport { HvHeaderNavigationItemProp } from \"../useSelectionPath\";\nimport { Bar } from \"../MenuBar/Bar\";\n\nexport { staticClasses as headerMenuItemClasses };\n\nexport type HvHeaderMenuItemClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvHeaderMenuItemProps\n extends HvBaseProps<HTMLDivElement, \"onClick\"> {\n item: HvHeaderNavigationItemProp;\n type?: string;\n onClick?: (event: MouseEvent, selection: HvHeaderNavigationItemProp) => void;\n levels: number;\n currentLevel: number;\n classes?: HvHeaderMenuItemClasses;\n}\n\n// Traverse the tree of items and return the first href it finds\nconst traverseItem = (node: HvHeaderNavigationItemProp) => {\n let href;\n let target;\n\n if (node?.href) {\n href = node?.href;\n target = node?.target;\n } else if (node?.data != null && node?.data?.length > 0) {\n let i = 0;\n while (href == null && i < node.data.length) {\n const childNavItem = traverseItem(node?.data[i]);\n if (childNavItem?.href != null) {\n href = childNavItem?.href;\n target = childNavItem?.target;\n break;\n }\n\n i += 1;\n }\n }\n\n return { href, target };\n};\n\nexport const HvHeaderMenuItem = (props: HvHeaderMenuItemProps) => {\n const {\n id,\n item,\n type,\n onClick,\n levels,\n currentLevel,\n classes: classesProp,\n className,\n } = useDefaultProps(\"HvHeaderMenuItem\", props);\n const { classes, cx } = useClasses(classesProp);\n\n const selectionPath = useContext(SelectionContext);\n\n const { dispatch } = useContext(FocusContext);\n\n const { data } = item;\n\n const hasSubLevel = data && data.length;\n\n const isMenu = type === \"menu\";\n\n const isSelected = selectionPath?.[isMenu ? 1 : 0] === item.id;\n\n // true: if the item is part of the selection path but is not the current page the user is seeing, i.e has more sub levels\n // page: used when the selected item is actually the current page the user is seeing\n const isCurrent = isSelected ? (hasSubLevel ? true : \"page\") : undefined;\n\n const actionHandler = (event: any) => {\n if (\n event.type === \"click\" ||\n isKey(event, \"Enter\") ||\n isKey(event, \"Space\")\n ) {\n if (event.type === \"click\") {\n event.currentTarget.blur();\n }\n\n onClick?.(event, item);\n }\n };\n\n const handleFocus = (event: React.FocusEvent) => {\n dispatch?.({ type: \"setItemFocused\", itemFocused: event.currentTarget });\n };\n\n const itemProps = {\n onClick: actionHandler,\n onKeyDown: actionHandler,\n onFocus: handleFocus,\n };\n\n const label = (\n <HvTypography\n component=\"span\"\n variant={isSelected ? \"label\" : \"body\"}\n data-text={item.label}\n >\n {item.label}\n </HvTypography>\n );\n\n let itemHref = item?.href;\n let itemTarget = item?.target;\n\n // apps should configure the href even on parent items without content\n // so the fallback logic is theirs, but if not we'll do our best to find a link\n if (item?.href == null) {\n const { href, target } = traverseItem(item);\n itemHref = href;\n itemTarget = target;\n }\n\n return (\n <li\n id={id}\n key={item.label}\n className={cx(\n classes.root,\n {\n [classes.menu]: isMenu,\n [classes.menubar]: !isMenu,\n [classes.selected]: !!isSelected,\n },\n className\n )}\n >\n {itemHref ? (\n <a\n className={classes.link}\n href={itemHref}\n target={itemTarget}\n {...itemProps}\n aria-current={isCurrent}\n >\n {label}\n </a>\n ) : (\n // keeping this code path for backwards compatibility, but\n // shouldn't really be used as it's not accessible\n <div\n className={classes.button}\n role=\"button\"\n {...itemProps}\n tabIndex={0}\n aria-current={isCurrent}\n >\n {label}\n </div>\n )}\n {/* Limits levels to no more than 2. More than that is not expected and not in DS. */}\n {hasSubLevel && currentLevel < levels && currentLevel < 2 && (\n <Bar data={data} type=\"menu\">\n {data.map((itm: HvHeaderNavigationItemProp) => (\n <HvHeaderMenuItem\n key={itm.id}\n item={itm}\n type=\"menu\"\n onClick={onClick}\n levels={levels}\n currentLevel={currentLevel + 1}\n />\n ))}\n </Bar>\n )}\n </li>\n );\n};\n"],"names":["traverseItem","node","href","target","data","length","i","childNavItem","HvHeaderMenuItem","props","id","item","type","onClick","levels","currentLevel","classes","classesProp","className","useDefaultProps","cx","useClasses","selectionPath","useContext","SelectionContext","dispatch","FocusContext","hasSubLevel","isMenu","isSelected","isCurrent","undefined","actionHandler","event","isKey","currentTarget","blur","handleFocus","itemFocused","itemProps","onKeyDown","onFocus","label","itemHref","itemTarget","root","menu","menubar","selected","link","button","map","itm"],"mappings":";;;;;;;;;;AA6BA,MAAMA,eAAeA,CAACC,SAAqC;;AACrDC,MAAAA;AACAC,MAAAA;AAEJ,MAAIF,6BAAMC,MAAM;AACdA,WAAOD,6BAAMC;AACbC,aAASF,6BAAME;AAAAA,EAAAA,YACNF,6BAAMG,SAAQ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AACJ,UAA4B;AACpC,yCAAA;AAAA,MAAErB,MAAM;AAAA,MAAkB0B,aAAaL,MAAME;AAAAA,IAAAA;AAAAA,EAAe;AAGzE,QAAMI,YAAY;AAAA,IAChB1B,SAASmB;AAAAA,IACTQ,WAAWR;AAAAA,IACXS,SAASJ;AAAAA,EAAAA;AAGX,QAAMK,QACJ,oBAAC,cACC,EAAA,WAAU,QACV,SAASb,aAAa,UAAU,QAChC,aAAWlB,KAAK+B,OAEf/B,eAAK+B,MACR,CAAA;AAGF,MAAIC,WAAWhC,6BAAMT;AACrB,MAAI0C,aAAajC,6BAAMR;AAInBQ,OAAAA,6BAAMT,SAAQ,MAAM;AAChB,UAAA;AAAA,MAAEA;AAAAA,MAAMC;AAAAA,IAAAA,IAAWH,aAAaW,IAAI;AAC/BT,eAAAA;AACEC,iBAAAA;AAAAA,EACf;AAEA,8BACG,MACC,EAAA,IAEA,WAAWiB,GACTJ,QAAQ6B,MACR;AAAA,IACE,CAAC7B,QAAQ8B,IAAI,GAAGlB;AAAAA,IAChB,CAACZ,QAAQ+B,OAAO,GAAG,CAACnB;AAAAA,IACpB,CAACZ,QAAQgC,QAAQ,GAAG,CAAC,CAACnB;AAAAA,EAAAA,GAExBX,SACF,GAECyB,UAAAA;AAAAA,
|
|
1
|
+
{"version":3,"file":"MenuItem.js","sources":["../../../../../../src/components/Header/Navigation/MenuItem/MenuItem.tsx"],"sourcesContent":["import React, { MouseEvent, useContext } from \"react\";\n\nimport { HvTypography } from \"@core/components/Typography\";\nimport { HvBaseProps } from \"@core/types/generic\";\nimport { isKey } from \"@core/utils/keyboardUtils\";\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { useDefaultProps } from \"@core/hooks\";\nimport { FocusContext } from \"../utils/FocusContext\";\nimport { SelectionContext } from \"../utils/SelectionContext\";\nimport { useClasses, staticClasses } from \"./MenuItem.styles\";\nimport { HvHeaderNavigationItemProp } from \"../useSelectionPath\";\nimport { Bar } from \"../MenuBar/Bar\";\n\nexport { staticClasses as headerMenuItemClasses };\n\nexport type HvHeaderMenuItemClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvHeaderMenuItemProps\n extends HvBaseProps<HTMLDivElement, \"onClick\"> {\n item: HvHeaderNavigationItemProp;\n type?: string;\n onClick?: (event: MouseEvent, selection: HvHeaderNavigationItemProp) => void;\n levels: number;\n currentLevel: number;\n classes?: HvHeaderMenuItemClasses;\n}\n\n// Traverse the tree of items and return the first href it finds\nconst traverseItem = (node: HvHeaderNavigationItemProp) => {\n let href;\n let target;\n\n if (node?.href) {\n href = node?.href;\n target = node?.target;\n } else if (node?.data != null && node?.data?.length > 0) {\n let i = 0;\n while (href == null && i < node.data.length) {\n const childNavItem = traverseItem(node?.data[i]);\n if (childNavItem?.href != null) {\n href = childNavItem?.href;\n target = childNavItem?.target;\n break;\n }\n\n i += 1;\n }\n }\n\n return { href, target };\n};\n\nexport const HvHeaderMenuItem = (props: HvHeaderMenuItemProps) => {\n const {\n id,\n item,\n type,\n onClick,\n levels,\n currentLevel,\n classes: classesProp,\n className,\n } = useDefaultProps(\"HvHeaderMenuItem\", props);\n const { classes, cx } = useClasses(classesProp);\n\n const selectionPath = useContext(SelectionContext);\n\n const { dispatch } = useContext(FocusContext);\n\n const { data } = item;\n\n const hasSubLevel = data && data.length;\n\n const isMenu = type === \"menu\";\n\n const isSelected = selectionPath?.[isMenu ? 1 : 0] === item.id;\n\n // true: if the item is part of the selection path but is not the current page the user is seeing, i.e has more sub levels\n // page: used when the selected item is actually the current page the user is seeing\n const isCurrent = isSelected ? (hasSubLevel ? true : \"page\") : undefined;\n\n const actionHandler = (event: any) => {\n if (\n event.type === \"click\" ||\n isKey(event, \"Enter\") ||\n isKey(event, \"Space\")\n ) {\n if (event.type === \"click\") {\n event.currentTarget.blur();\n }\n\n onClick?.(event, item);\n }\n };\n\n const handleFocus = (event: React.FocusEvent) => {\n dispatch?.({ type: \"setItemFocused\", itemFocused: event.currentTarget });\n };\n\n const itemProps = {\n onClick: actionHandler,\n onKeyDown: actionHandler,\n onFocus: handleFocus,\n };\n\n const label = (\n <HvTypography\n component=\"span\"\n variant={isSelected ? \"label\" : \"body\"}\n data-text={item.label}\n >\n {item.label}\n </HvTypography>\n );\n\n let itemHref = item?.href;\n let itemTarget = item?.target;\n\n // apps should configure the href even on parent items without content\n // so the fallback logic is theirs, but if not we'll do our best to find a link\n if (item?.href == null) {\n const { href, target } = traverseItem(item);\n itemHref = href;\n itemTarget = target;\n }\n\n return (\n <li\n id={id}\n key={item.label}\n className={cx(\n classes.root,\n {\n [classes.menu]: isMenu,\n [classes.menubar]: !isMenu,\n [classes.selected]: !!isSelected,\n },\n className\n )}\n >\n {itemHref ? (\n <a\n className={classes.link}\n href={itemHref}\n target={itemTarget}\n {...itemProps}\n aria-current={isCurrent}\n // Fix for a possible bug in playwright where, even though hidden from screen readers and not appearing in the accessibility\n // tree, due to the styling duplication (span::after - using 'data-text'), locators have to double the name.\n aria-label={item.label}\n >\n {label}\n </a>\n ) : (\n // keeping this code path for backwards compatibility, but\n // shouldn't really be used as it's not accessible\n <div\n className={classes.button}\n role=\"button\"\n {...itemProps}\n tabIndex={0}\n aria-current={isCurrent}\n >\n {label}\n </div>\n )}\n {/* Limits levels to no more than 2. More than that is not expected and not in DS. */}\n {hasSubLevel && currentLevel < levels && currentLevel < 2 && (\n <Bar data={data} type=\"menu\">\n {data.map((itm: HvHeaderNavigationItemProp) => (\n <HvHeaderMenuItem\n key={itm.id}\n item={itm}\n type=\"menu\"\n onClick={onClick}\n levels={levels}\n currentLevel={currentLevel + 1}\n />\n ))}\n </Bar>\n )}\n </li>\n );\n};\n"],"names":["traverseItem","node","href","target","data","length","i","childNavItem","HvHeaderMenuItem","props","id","item","type","onClick","levels","currentLevel","classes","classesProp","className","useDefaultProps","cx","useClasses","selectionPath","useContext","SelectionContext","dispatch","FocusContext","hasSubLevel","isMenu","isSelected","isCurrent","undefined","actionHandler","event","isKey","currentTarget","blur","handleFocus","itemFocused","itemProps","onKeyDown","onFocus","label","itemHref","itemTarget","root","menu","menubar","selected","link","button","map","itm"],"mappings":";;;;;;;;;;AA6BA,MAAMA,eAAeA,CAACC,SAAqC;;AACrDC,MAAAA;AACAC,MAAAA;AAEJ,MAAIF,6BAAMC,MAAM;AACdA,WAAOD,6BAAMC;AACbC,aAASF,6BAAME;AAAAA,EAAAA,YACNF,6BAAMG,SAAQ,UAAQH,kCAAMG,SAANH,mBAAYI,UAAS,GAAG;AACvD,QAAIC,IAAI;AACR,WAAOJ,QAAQ,QAAQI,IAAIL,KAAKG,KAAKC,QAAQ;AAC3C,YAAME,eAAeP,aAAaC,6BAAMG,KAAKE,EAAE;AAC3CC,WAAAA,6CAAcL,SAAQ,MAAM;AAC9BA,eAAOK,6CAAcL;AACrBC,iBAASI,6CAAcJ;AACvB;AAAA,MACF;AAEK,WAAA;AAAA,IACP;AAAA,EACF;AAEO,SAAA;AAAA,IAAED;AAAAA,IAAMC;AAAAA,EAAAA;AACjB;AAEaK,MAAAA,mBAAmBA,CAACC,UAAiC;AAC1D,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,SAASC;AAAAA,IACTC;AAAAA,EAAAA,IACEC,gBAAgB,oBAAoBV,KAAK;AACvC,QAAA;AAAA,IAAEO;AAAAA,IAASI;AAAAA,EAAAA,IAAOC,WAAWJ,WAAW;AAExCK,QAAAA,gBAAgBC,WAAWC,gBAAgB;AAE3C,QAAA;AAAA,IAAEC;AAAAA,EAAAA,IAAaF,WAAWG,YAAY;AAEtC,QAAA;AAAA,IAAEtB;AAAAA,EAASO,IAAAA;AAEXgB,QAAAA,cAAcvB,QAAQA,KAAKC;AAEjC,QAAMuB,SAAShB,SAAS;AAExB,QAAMiB,cAAaP,+CAAgBM,SAAS,IAAI,QAAOjB,KAAKD;AAI5D,QAAMoB,YAAYD,aAAcF,cAAc,OAAO,SAAUI;AAEzDC,QAAAA,gBAAgBA,C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A;AAAAA,IACH;AAAA;AAAA;AAAA,MAIC,oBAAA,OAAA,EACC,WAAW1B,QAAQkC,QACnB,MAAK,UACDX,GAAAA,WACJ,UAAU,GACV,gBAAcT,WAEbY,UACH,OAAA;AAAA;AAAA,IAGDf,eAAeZ,eAAeD,UAAUC,eAAe,KACtD,oBAAC,KAAI,EAAA,MAAY,MAAK,QACnBX,UAAK+C,KAAAA,IAAI,CAACC,QACR,oBAAA,kBAAA,EAEC,MAAMA,KACN,MAAK,QACL,SACA,QACA,cAAcrC,eAAe,EALxBqC,GAAAA,IAAI1C,EAKsB,CAElC,EACH,CAAA;AAAA,EAAA,KAlDGC,KAAK+B,KAoDZ;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.js","sources":["../../../../src/components/List/List.tsx"],"sourcesContent":["import {\n AriaRole,\n forwardRef,\n isValidElement,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\n\nimport { FixedSizeList } from \"react-window\";\n\nimport { DropRightXS } from \"@hitachivantara/uikit-react-icons\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { HvBaseProps } from \"@core/types/generic\";\nimport { HvListContainer, HvListItem } from \"@core/components/ListContainer\";\nimport { HvTypography } from \"@core/components/Typography\";\nimport { setId } from \"@core/utils/setId\";\nimport { wrapperTooltip } from \"@core/utils/wrapperTooltip\";\nimport { ExtractNames } from \"@core/utils/classes\";\nimport { HvCheckBox } from \"@core/components/CheckBox\";\nimport { HvLink } from \"@core/components/Link\";\nimport { HvRadio } from \"@core/components/Radio\";\n\nimport { staticClasses, useClasses } from \"./List.styles\";\nimport { useSelectableList } from \"./useSelectableList\";\nimport { parseList } from \"./utils\";\nimport { HvListLabels, HvListValue } from \"./types\";\n\nexport { staticClasses as listClasses };\n\nexport type HvListClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvListProps\n extends HvBaseProps<HTMLUListElement, \"onChange\" | \"onClick\"> {\n /**\n * A list containing the elements to be rendered.\n *\n * - id: The id of the item.\n * - label: The label of the element to be rendered.\n * - selected: The selection state of the element.\n * - disabled: The disabled state of the element.\n * - isHidden: Is item visible.\n * - icon: The icon.\n * - showNavIcon: If true renders the navigation icon on the right.\n * - path: The path to navigate to.\n */\n values: HvListValue[];\n /** If true renders a multi select list. */\n multiSelect?: boolean;\n /**\n * If true renders select all option for multi selection lists with selectors.\n * note: It will only be rendered if multiSelect and useSelector props are set to true.\n */\n showSelectAll?: boolean;\n /** An object containing all the labels for the dropdown. */\n labels?: HvListLabels;\n /** If true renders list items with radio or checkbox selectors. */\n useSelector?: boolean;\n /** Call back fired when list item is selected. Returns selection state. */\n onChange?: (value: HvListValue[]) => void;\n /** Call back fired when list item is selected. Returns selected item. */\n onClick?: (\n event: React.ChangeEvent<HTMLLIElement>,\n value: HvListValue\n ) => void;\n /** If `true` the list items will show the selection state. */\n selectable?: boolean;\n /** If `true`, selection can be toggled when single selection. */\n singleSelectionToggle?: boolean;\n /** If `true` the list will be rendered without vertical spacing. */\n condensed?: boolean;\n /** If `true` the dropdown will show tooltips when user mouseenter text in list */\n hasTooltips?: boolean;\n /** Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used */\n height?: number;\n /** Experimental. Uses dropdown in a virtualized form, where not all options are rendered initially. Good for use cases with a lot of options. */\n virtualized?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvListClasses;\n}\n\nconst DEFAULT_LABELS = {\n selectAll: \"Select All\",\n selectionConjunction: \"/\",\n};\n\n/**\n * Component used to show a set of related data to the user.\n */\nexport const HvList = (props: HvListProps) => {\n const {\n id,\n classes: classesProp,\n className,\n multiSelect = false,\n hasTooltips = false,\n showSelectAll = false,\n labels = DEFAULT_LABELS,\n useSelector = false,\n selectable = true,\n singleSelectionToggle = true,\n condensed = false,\n onChange,\n onClick,\n values: valuesProp = [],\n height,\n virtualized = false,\n ...others\n } = useDefaultProps(\"HvList\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const [list, setList, selection] = useSelectableList(valuesProp);\n const listRef = useRef<any>(null);\n\n useEffect(() => {\n const passedProps = { multiSelect, selectable, singleSelectionToggle };\n const parsedList: HvListValue[] = parseList(\n undefined,\n passedProps,\n undefined,\n valuesProp\n );\n\n setList(parsedList);\n }, [valuesProp, multiSelect, selectable, singleSelectionToggle, setList]);\n\n const [role, itemRole] = useMemo<[AriaRole, AriaRole]>(() => {\n // selectors are responsible for the role & selection state\n if (selectable && useSelector) return [\"list\", \"listitem\"];\n\n if (selectable) return [\"listbox\", \"option\"];\n return [\"menu\", \"menuitem\"];\n }, [selectable, useSelector]);\n\n const handleSelect = (evt, item) => {\n if (!item.path) evt.preventDefault();\n if (item.disabled) return;\n\n const passedProps = { multiSelect, selectable, singleSelectionToggle };\n const parsedList = parseList(item, passedProps, undefined, list);\n setList(parsedList);\n\n onClick?.(evt, item);\n onChange?.(parsedList);\n };\n\n const handleSelectAll = () => {\n const passedProps = { multiSelect, selectable, singleSelectionToggle };\n const anySelectableSelected = list.some(\n (elem) => elem.selected || elem.disabled\n );\n const parsedList = parseList(\n undefined,\n passedProps,\n !anySelectableSelected,\n list\n );\n setList(parsedList);\n\n onChange?.(parsedList);\n };\n\n const renderLeftIcon = (item) => {\n return isValidElement(item.icon)\n ? item.icon\n : item.icon?.({\n isSelected: item.selected,\n isDisabled: item.disabled,\n });\n };\n\n const renderSelectAll = () => {\n const { selectAll, selectionConjunction } = labels;\n\n const anySelected = !!selection?.length;\n const allSelected = selection.length === list.length;\n\n const selectionLabel = (\n <HvTypography component=\"span\">\n {!anySelected ? (\n <>\n <b>{selectAll}</b>\n {` (${list.length})`}\n </>\n ) : (\n <>\n <b>{selection.length}</b>\n {`\\xa0${selectionConjunction}\\xa0`}\n {list.length}\n </>\n )}\n </HvTypography>\n );\n\n return (\n <HvCheckBox\n id={setId(id, \"select-all\")}\n label={selectionLabel}\n onChange={handleSelectAll}\n className={classes.selectAllSelector}\n indeterminate={anySelected && !allSelected}\n checked={allSelected}\n />\n );\n };\n\n const renderItemText = (item) => {\n const ItemText = wrapperTooltip(hasTooltips, item.label, item.label);\n\n return !multiSelect && item.path ? (\n <HvLink key={item.label} route={item.path} classes={{ a: classes.link }}>\n <ItemText />\n </HvLink>\n ) : (\n <ItemText />\n );\n };\n\n const renderMultiSelectItem = (item, itemId) => {\n if (useSelector) {\n const Selection = wrapperTooltip(\n hasTooltips,\n <HvCheckBox\n id={setId(itemId, \"selector\")}\n label={item.label}\n checked={item.selected}\n disabled={item.disabled}\n onChange={(evt) => handleSelect(evt, item)}\n classes={{\n root: classes.selectorRoot,\n container: classes.selectorContainer,\n label: classes.truncate,\n }}\n />,\n item.label\n );\n return <Selection />;\n }\n\n return renderItemText(item);\n };\n\n const renderSingleSelectItem = (item, itemId) => {\n if (useSelector) {\n const Selection = wrapperTooltip(\n hasTooltips,\n <HvRadio\n id={setId(itemId, \"selector\")}\n label={item.label}\n checked={item.selected}\n disabled={item.disabled}\n classes={{\n root: classes.selectorRoot,\n container: classes.selectorContainer,\n label: classes.truncate,\n }}\n />,\n item.label\n );\n return <Selection />;\n }\n return renderItemText(item);\n };\n\n const renderListItem = (item, i, otherProps = {}) => {\n const itemId = setId(id, \"item\", i);\n const selected = item.selected || false;\n\n let startAdornment = null;\n if (!useSelector && item.icon) {\n startAdornment = renderLeftIcon(item);\n }\n\n return (\n <HvListItem\n key={i}\n id={itemId}\n role={itemRole}\n disabled={item.disabled || undefined}\n className={classes.item}\n classes={{\n selected: cx({\n [classes.itemSelector]: useSelector || multiSelect,\n }),\n }}\n selected={multiSelect || selected ? selected : undefined}\n onClick={(evt) => handleSelect(evt, item)}\n startAdornment={startAdornment}\n endAdornment={\n item.showNavIcon && (\n <DropRightXS className={classes.box} iconSize=\"XS\" />\n )\n }\n {...otherProps}\n >\n {multiSelect\n ? renderMultiSelectItem(item, itemId)\n : renderSingleSelectItem(item, itemId)}\n </HvListItem>\n );\n };\n\n const filteredList = list.filter((it) => !it.isHidden);\n const anySelected = list\n .map((item) => item.selected && !item.disabled)\n .reduce((result, selected) => result || selected, false);\n\n const selectedItemIndex = list.findIndex((item) => item.selected);\n useEffect(() => {\n if (selectedItemIndex >= 0 && listRef.current !== null) {\n listRef.current.scrollToItem(selectedItemIndex);\n }\n }, [listRef, selectedItemIndex]);\n\n const renderVirtualizedListItem = ({ index, style }) => {\n const item = filteredList[index];\n const tabIndex =\n item.tabIndex ||\n (!anySelected && index === 0) ||\n (item.selected && !item.disabled)\n ? 0\n : -1;\n\n return renderListItem(item, index, {\n style: {\n ...style,\n top: `${parseFloat(style.top) + 5}px`,\n left: `${parseFloat(style.left) + 5}px`,\n width: `calc(${parseFloat(style.width)}% - 10px)`,\n },\n tabIndex,\n interactive: true,\n condensed,\n disableGutters: useSelector,\n });\n };\n\n const ariaMultiSelectable = (role === \"listbox\" && multiSelect) || undefined;\n\n const ListContainer = useMemo(() => {\n return forwardRef(({ ...rest }, ref) => (\n <HvListContainer\n id={id}\n className={cx(classes.root, className)}\n role={role}\n interactive\n condensed={condensed}\n disableGutters={useSelector}\n aria-multiselectable={ariaMultiSelectable}\n ref={ref}\n {...rest}\n />\n ));\n }, [\n cx,\n id,\n useSelector,\n className,\n classes.root,\n role,\n condensed,\n ariaMultiSelectable,\n ]);\n\n // Render nothing if there are no items\n if (filteredList.length === 0) return null;\n\n return (\n <>\n {multiSelect && useSelector && showSelectAll && renderSelectAll()}\n\n {!virtualized ? (\n <HvListContainer\n id={id}\n className={cx(classes.root, className)}\n role={role}\n interactive\n condensed={condensed}\n disableGutters={useSelector}\n aria-multiselectable={ariaMultiSelectable}\n {...others}\n >\n {filteredList.map((item, i) => renderListItem(item, i))}\n </HvListContainer>\n ) : (\n <FixedSizeList\n ref={listRef}\n className={classes.virtualizedRoot}\n height={(height || 0) + 5}\n width=\"100%\"\n itemCount={filteredList.length}\n itemSize={condensed ? 32 : 40}\n innerElementType={ListContainer}\n {...others}\n >\n {renderVirtualizedListItem}\n </FixedSizeList>\n )}\n </>\n );\n};\n"],"names":["DEFAULT_LABELS","selectAll","selectionConjunction","HvList","props","id","classes","classesProp","className","multiSelect","hasTooltips","showSelectAll","labels","useSelector","selectable","singleSelectionToggle","condensed","onChange","onClick","values","valuesProp","height","virtualized","others","useDefaultProps","cx","useClasses","list","setList","selection","useSelectableList","listRef","useRef","useEffect","passedProps","parsedList","parseList","undefined","role","itemRole","useMemo","handleSelect","evt","item","path","preventDefault","disabled","handleSelectAll","anySelectableSelected","some","elem","selected","renderLeftIcon","isValidElement","icon","isSelected","isDisabled","renderSelectAll","anySelected","length","allSelected","selectionLabel","setId","selectAllSelector","renderItemText","ItemText","wrapperTooltip","label","a","link","renderMultiSelectItem","itemId","Selection","root","selectorRoot","container","selectorContainer","truncate","renderSingleSelectItem","renderListItem","i","otherProps","startAdornment","itemSelector","showNavIcon","box","filteredList","filter","it","isHidden","map","reduce","result","selectedItemIndex","findIndex","current","scrollToItem","renderVirtualizedListItem","index","style","tabIndex","top","parseFloat","left","width","interactive","disableGutters","ariaMultiSelectable","ListContainer","forwardRef","rest","ref","virtualizedRoot"],"mappings":";;;;;;;;;;;;;;;;;AAkFA,MAAMA,iBAAiB;AAAA,EACrBC,WAAW;AAAA,EACXC,sBAAsB;AACxB;AAKaC,MAAAA,SAASA,CAACC,UAAuB;AACtC,QAAA;AAAA,IACJC;AAAAA,IACAC,SAASC;AAAAA,IACTC;AAAAA,IACAC,cAAc;AAAA,IACdC,cAAc;AAAA,IACdC,gBAAgB;AAAA,IAChBC,SAASZ;AAAAA,IACTa,cAAc;AAAA,IACdC,aAAa;AAAA,IACbC,wBAAwB;AAAA,IACxBC,YAAY;AAAA,IACZC;AAAAA,IACAC;AAAAA,IACAC,QAAQC,aAAa,CAAE;AAAA,IACvBC;AAAAA,IACAC,cAAc;AAAA,IACd,GAAGC;AAAAA,EAAAA,IACDC,gBAAgB,UAAUpB,KAAK;AAE7B,QAAA;AAAA,IAAEE;AAAAA,IAASmB;AAAAA,EAAAA,IAA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kBAAkB4F,eAClB,GAAIrF,QAEH0E,UACH,0BAAA,CAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"List.js","sources":["../../../../src/components/List/List.tsx"],"sourcesContent":["import {\n AriaRole,\n forwardRef,\n isValidElement,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\n\nimport { FixedSizeList } from \"react-window\";\n\nimport { DropRightXS } from \"@hitachivantara/uikit-react-icons\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { HvBaseProps } from \"@core/types/generic\";\nimport {\n HvListContainer,\n HvListContainerProps,\n HvListItem,\n} from \"@core/components/ListContainer\";\nimport { HvTypography } from \"@core/components/Typography\";\nimport { setId } from \"@core/utils/setId\";\nimport { wrapperTooltip } from \"@core/utils/wrapperTooltip\";\nimport { ExtractNames } from \"@core/utils/classes\";\nimport { HvCheckBox } from \"@core/components/CheckBox\";\nimport { HvLink } from \"@core/components/Link\";\nimport { HvRadio } from \"@core/components/Radio\";\n\nimport { staticClasses, useClasses } from \"./List.styles\";\nimport { useSelectableList } from \"./useSelectableList\";\nimport { parseList } from \"./utils\";\nimport { HvListLabels, HvListValue } from \"./types\";\n\nexport { staticClasses as listClasses };\n\nexport type HvListClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvListProps\n extends HvBaseProps<HTMLUListElement, \"onChange\" | \"onClick\"> {\n /**\n * A list containing the elements to be rendered.\n *\n * - id: The id of the item.\n * - label: The label of the element to be rendered.\n * - selected: The selection state of the element.\n * - disabled: The disabled state of the element.\n * - isHidden: Is item visible.\n * - icon: The icon.\n * - showNavIcon: If true renders the navigation icon on the right.\n * - path: The path to navigate to.\n */\n values: HvListValue[];\n /** If true renders a multi select list. */\n multiSelect?: boolean;\n /**\n * If true renders select all option for multi selection lists with selectors.\n * note: It will only be rendered if multiSelect and useSelector props are set to true.\n */\n showSelectAll?: boolean;\n /** An object containing all the labels for the dropdown. */\n labels?: HvListLabels;\n /** If true renders list items with radio or checkbox selectors. */\n useSelector?: boolean;\n /** Call back fired when list item is selected. Returns selection state. */\n onChange?: (value: HvListValue[]) => void;\n /** Call back fired when list item is selected. Returns selected item. */\n onClick?: (\n event: React.ChangeEvent<HTMLLIElement>,\n value: HvListValue\n ) => void;\n /** If `true` the list items will show the selection state. */\n selectable?: boolean;\n /** If `true`, selection can be toggled when single selection. */\n singleSelectionToggle?: boolean;\n /** If `true` the list will be rendered without vertical spacing. */\n condensed?: boolean;\n /** If `true` the dropdown will show tooltips when user mouseenter text in list */\n hasTooltips?: boolean;\n /** Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used */\n height?: number;\n /** Experimental. Uses dropdown in a virtualized form, where not all options are rendered initially. Good for use cases with a lot of options. */\n virtualized?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvListClasses;\n}\n\nconst DEFAULT_LABELS = {\n selectAll: \"Select All\",\n selectionConjunction: \"/\",\n};\n\n/**\n * Component used to show a set of related data to the user.\n */\nexport const HvList = (props: HvListProps) => {\n const {\n id,\n classes: classesProp,\n className,\n multiSelect = false,\n hasTooltips = false,\n showSelectAll = false,\n labels = DEFAULT_LABELS,\n useSelector = false,\n selectable = true,\n singleSelectionToggle = true,\n condensed = false,\n onChange,\n onClick,\n values: valuesProp = [],\n height,\n virtualized = false,\n ...others\n } = useDefaultProps(\"HvList\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const [list, setList, selection] = useSelectableList(valuesProp);\n const listRef = useRef<any>(null);\n\n useEffect(() => {\n const passedProps = { multiSelect, selectable, singleSelectionToggle };\n const parsedList: HvListValue[] = parseList(\n undefined,\n passedProps,\n undefined,\n valuesProp\n );\n\n setList(parsedList);\n }, [valuesProp, multiSelect, selectable, singleSelectionToggle, setList]);\n\n const [role, itemRole] = useMemo<[AriaRole, AriaRole]>(() => {\n // selectors are responsible for the role & selection state\n if (selectable && useSelector) return [\"list\", \"listitem\"];\n\n if (selectable) return [\"listbox\", \"option\"];\n return [\"menu\", \"menuitem\"];\n }, [selectable, useSelector]);\n\n const handleSelect = (evt, item) => {\n if (!item.path) evt.preventDefault();\n if (item.disabled) return;\n\n const passedProps = { multiSelect, selectable, singleSelectionToggle };\n const parsedList = parseList(item, passedProps, undefined, list);\n setList(parsedList);\n\n onClick?.(evt, item);\n onChange?.(parsedList);\n };\n\n const handleSelectAll = () => {\n const passedProps = { multiSelect, selectable, singleSelectionToggle };\n const anySelectableSelected = list.some(\n (elem) => elem.selected || elem.disabled\n );\n const parsedList = parseList(\n undefined,\n passedProps,\n !anySelectableSelected,\n list\n );\n setList(parsedList);\n\n onChange?.(parsedList);\n };\n\n const renderLeftIcon = (item) => {\n return isValidElement(item.icon)\n ? item.icon\n : item.icon?.({\n isSelected: item.selected,\n isDisabled: item.disabled,\n });\n };\n\n const renderSelectAll = () => {\n const { selectAll, selectionConjunction } = labels;\n\n const anySelected = !!selection?.length;\n const allSelected = selection.length === list.length;\n\n const selectionLabel = (\n <HvTypography component=\"span\">\n {!anySelected ? (\n <>\n <b>{selectAll}</b>\n {` (${list.length})`}\n </>\n ) : (\n <>\n <b>{selection.length}</b>\n {`\\xa0${selectionConjunction}\\xa0`}\n {list.length}\n </>\n )}\n </HvTypography>\n );\n\n return (\n <HvCheckBox\n id={setId(id, \"select-all\")}\n label={selectionLabel}\n onChange={handleSelectAll}\n className={classes.selectAllSelector}\n indeterminate={anySelected && !allSelected}\n checked={allSelected}\n />\n );\n };\n\n const renderItemText = (item) => {\n const ItemText = wrapperTooltip(hasTooltips, item.label, item.label);\n\n return !multiSelect && item.path ? (\n <HvLink key={item.label} route={item.path} classes={{ a: classes.link }}>\n <ItemText />\n </HvLink>\n ) : (\n <ItemText />\n );\n };\n\n const renderMultiSelectItem = (item, itemId) => {\n if (useSelector) {\n const Selection = wrapperTooltip(\n hasTooltips,\n <HvCheckBox\n id={setId(itemId, \"selector\")}\n label={item.label}\n checked={item.selected}\n disabled={item.disabled}\n onChange={(evt) => handleSelect(evt, item)}\n classes={{\n root: classes.selectorRoot,\n container: classes.selectorContainer,\n label: classes.truncate,\n }}\n />,\n item.label\n );\n return <Selection />;\n }\n\n return renderItemText(item);\n };\n\n const renderSingleSelectItem = (item, itemId) => {\n if (useSelector) {\n const Selection = wrapperTooltip(\n hasTooltips,\n <HvRadio\n id={setId(itemId, \"selector\")}\n label={item.label}\n checked={item.selected}\n disabled={item.disabled}\n classes={{\n root: classes.selectorRoot,\n container: classes.selectorContainer,\n label: classes.truncate,\n }}\n />,\n item.label\n );\n return <Selection />;\n }\n return renderItemText(item);\n };\n\n const renderListItem = (item, i, otherProps = {}) => {\n const itemId = setId(id, \"item\", i);\n const selected = item.selected || false;\n\n let startAdornment = null;\n if (!useSelector && item.icon) {\n startAdornment = renderLeftIcon(item);\n }\n\n return (\n <HvListItem\n key={i}\n id={itemId}\n role={itemRole}\n disabled={item.disabled || undefined}\n className={classes.item}\n classes={{\n selected: cx({\n [classes.itemSelector]: useSelector || multiSelect,\n }),\n }}\n selected={multiSelect || selected ? selected : undefined}\n onClick={(evt) => handleSelect(evt, item)}\n startAdornment={startAdornment}\n endAdornment={\n item.showNavIcon && (\n <DropRightXS className={classes.box} iconSize=\"XS\" />\n )\n }\n {...otherProps}\n >\n {multiSelect\n ? renderMultiSelectItem(item, itemId)\n : renderSingleSelectItem(item, itemId)}\n </HvListItem>\n );\n };\n\n const filteredList = list.filter((it) => !it.isHidden);\n const anySelected = list\n .map((item) => item.selected && !item.disabled)\n .reduce((result, selected) => result || selected, false);\n\n const selectedItemIndex = list.findIndex((item) => item.selected);\n useEffect(() => {\n if (selectedItemIndex >= 0 && listRef.current !== null) {\n listRef.current.scrollToItem(selectedItemIndex);\n }\n }, [listRef, selectedItemIndex]);\n\n const renderVirtualizedListItem = ({ index, style }) => {\n const item = filteredList[index];\n const tabIndex =\n item.tabIndex ||\n (!anySelected && index === 0) ||\n (item.selected && !item.disabled)\n ? 0\n : -1;\n\n return renderListItem(item, index, {\n style: {\n ...style,\n top: `${parseFloat(style.top) + 5}px`,\n left: `${parseFloat(style.left) + 5}px`,\n width: `calc(${parseFloat(style.width)}% - 10px)`,\n },\n tabIndex,\n interactive: true,\n condensed,\n disableGutters: useSelector,\n });\n };\n\n const ariaMultiSelectable = (role === \"listbox\" && multiSelect) || undefined;\n\n const ListContainer = useMemo(() => {\n return forwardRef<HTMLUListElement, HvListContainerProps>(\n ({ ...rest }, ref) => (\n <HvListContainer\n id={id}\n className={cx(classes.root, className)}\n role={role}\n interactive\n condensed={condensed}\n disableGutters={useSelector}\n aria-multiselectable={ariaMultiSelectable}\n ref={ref}\n {...rest}\n />\n )\n );\n }, [\n cx,\n id,\n useSelector,\n className,\n classes.root,\n role,\n condensed,\n ariaMultiSelectable,\n ]);\n\n // Render nothing if there are no items\n if (filteredList.length === 0) return null;\n\n return (\n <>\n {multiSelect && useSelector && showSelectAll && renderSelectAll()}\n\n {!virtualized ? (\n <HvListContainer\n id={id}\n className={cx(classes.root, className)}\n role={role}\n interactive\n condensed={condensed}\n disableGutters={useSelector}\n aria-multiselectable={ariaMultiSelectable}\n {...others}\n >\n {filteredList.map((item, i) => renderListItem(item, i))}\n </HvListContainer>\n ) : (\n <FixedSizeList\n ref={listRef}\n className={classes.virtualizedRoot}\n height={(height || 0) + 5}\n width=\"100%\"\n itemCount={filteredList.length}\n itemSize={condensed ? 32 : 40}\n innerElementType={ListContainer}\n {...others}\n >\n {renderVirtualizedListItem}\n </FixedSizeList>\n )}\n </>\n );\n};\n"],"names":["DEFAULT_LABELS","selectAll","selectionConjunction","HvList","props","id","classes","classesProp","className","multiSelect","hasTooltips","showSelectAll","labels","useSelector","selectable","singleSelectionToggle","condensed","onChange","onClick","values","valuesProp","height","virtualized","others","useDefaultProps","cx","useClasses","list","setList","selection","useSelectableList","listRef","useRef","useEffect","passedProps","parsedList","parseList","undefined","role","itemRole","useMemo","handleSelect","evt","item","path","preventDefault","disabled","handleSelectAll","anySelectableSelected","some","elem","selected","renderLeftIcon","isValidElement","icon","isSelected","isDisabled","renderSelectAll","anySelected","length","allSelected","selectionLabel","setId","selectAllSelector","renderItemText","ItemText","wrapperTooltip","label","a","link","renderMultiSelectItem","itemId","Selection","root","selectorRoot","container","selectorContainer","truncate","renderSingleSelectItem","renderListItem","i","otherProps","startAdornment","itemSelector","showNavIcon","box","filteredList","filter","it","isHidden","map","reduce","result","selectedItemIndex","findIndex","current","scrollToItem","renderVirtualizedListItem","index","style","tabIndex","top","parseFloat","left","width","interactive","disableGutters","ariaMultiSelectable","ListContainer","forwardRef","rest","ref","virtualizedRoot"],"mappings":";;;;;;;;;;;;;;;;;AAsFA,MAAMA,iBAAiB;AAAA,EACrBC,WAAW;AAAA,EACXC,sBAAsB;AACxB;AAKaC,MAAAA,SAASA,CAACC,UAAuB;AACtC,QAAA;AAAA,IACJC;AAAAA,IACAC,SAASC;AAAAA,IACTC;AAAAA,IACAC,cAAc;AAAA,IACdC,cAAc;AAAA,IACdC,gBAAgB;AAAA,IAChBC,SAASZ;AAAAA,IACTa,cAAc;AAAA,IACdC,aAAa;AAAA,IACbC,wBAAwB;AAAA,IACxBC,YAAY;AAAA,IACZC;AAAAA,IACAC;AAAAA,IACAC,QAAQC,aAAa,CAAE;AAAA,IACvBC;AAAAA,IACAC,cAAc;AAAA,IACd,GAAGC;AAAAA,EAAAA,IACDC,gBAAgB,UAAUpB,KAAK;AAE7B,QAAA;AAAA,IAAEE;AAAAA,IAASmB;AAAAA,EAAAA,IAAOC,WAAWnB,WAAW;AAE9C,QAAM,CAACoB,MAAMC,SAASC,SAAS,IAAIC,kBAAkBV,UAAU;AACzDW,QAAAA,UAAUC,OAAY,IAAI;AAEhCC,YAAU,MAAM;AACd,UAAMC,cAAc;AAAA,MAAEzB;AAAAA,MAAaK;AAAAA,MAAYC;AAAAA,IAAAA;AAC/C,UAAMoB,aAA4BC,UAChCC,QACAH,aACAG,QACAjB,UACF;AAEAQ,YAAQO,UAAU;AAAA,EAAA,GACjB,CAACf,YA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AAuBrE,SAAS,aAAa7B,eAAgB4B;AAE7DuE,QAAAA,gBAAgBpE,QAAQ,MAAM;AAClC,WAAOqE,WACL,CAAC;AAAA,MAAE,GAAGC;AAAAA,IAAK,GAAGC,QACX,oBAAA,iBAAA,EACC,IACA,WAAWtF,GAAGnB,QAAQmE,MAAMjE,SAAS,GACrC,MACA,aAAW,MACX,WACA,gBAAgBK,aAChB,wBAAsB8F,qBACtB,KACA,GAAIG,OAGV;AAAA,EACF,GAAG,CACDrF,IACApB,IACAQ,aACAL,WACAF,QAAQmE,MACRnC,MACAtB,WACA2F,mBAAmB,CACpB;AAGD,MAAIrB,aAAa3B,WAAW;AAAU,WAAA;AAEtC,SAEKlD,qBAAAA,UAAAA,EAAAA,UAAAA;AAAAA,IAAeI,eAAAA,eAAeF,iBAAiB8C,gBAAgB;AAAA,IAE/D,CAACnC,cACA,oBAAC,iBACC,EAAA,IACA,WAAWG,GAAGnB,QAAQmE,MAAMjE,SAAS,GACrC,MACA,aAAW,MACX,WACA,gBAAgBK,aAChB,wBAAsB8F,qBAClBpF,GAAAA,QAEH+D,UAAAA,aAAaI,IAAI,CAAC/C,MAAMqC,MAAMD,eAAepC,MAAMqC,CAAC,CAAC,EACxD,CAAA,IAEA,oBAAC,eACC,EAAA,KAAKjD,SACL,WAAWzB,QAAQ0G,iBACnB,SAAS3F,UAAU,KAAK,GACxB,OAAM,QACN,WAAWiE,aAAa3B,QACxB,UAAU3C,YAAY,KAAK,IAC3B,kBAAkB4F,eAClB,GAAIrF,QAEH0E,UACH,0BAAA,CAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ;"}
|
|
@@ -5,7 +5,7 @@ import { useDefaultProps } from "../../hooks/useDefaultProps.js";
|
|
|
5
5
|
import { useClasses } from "./ListContainer.styles.js";
|
|
6
6
|
import { staticClasses } from "./ListContainer.styles.js";
|
|
7
7
|
import HvListContext from "./ListContext/ListContext.js";
|
|
8
|
-
const HvListContainer = forwardRef((props,
|
|
8
|
+
const HvListContainer = forwardRef((props, ref) => {
|
|
9
9
|
const {
|
|
10
10
|
id,
|
|
11
11
|
classes: classesProp,
|
|
@@ -45,7 +45,7 @@ const HvListContainer = forwardRef((props, externalRef) => {
|
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
|
-
const handleRef = useForkRef(
|
|
48
|
+
const handleRef = useForkRef(ref, containerRef);
|
|
49
49
|
return /* @__PURE__ */ jsx(HvListContext.Provider, { value: listContext, children: /* @__PURE__ */ jsx("ul", { ref: handleRef, id, className: cx(classes.root, className), ...others, children: renderChildren() }) });
|
|
50
50
|
});
|
|
51
51
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListContainer.js","sources":["../../../../src/components/ListContainer/ListContainer.tsx"],"sourcesContent":["import React, { useRef, useContext, useMemo, forwardRef } from \"react\";\n\nimport { HvBaseProps } from \"@core/types/generic\";\nimport { useForkRef } from \"@core/hooks/useForkRef\";\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { staticClasses, useClasses } from \"./ListContainer.styles\";\nimport HvListContext from \"./ListContext\";\n\nexport { staticClasses as listContainerClasses };\n\nexport type HvListContainerClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvListContainerProps extends HvBaseProps<HTMLUListElement> {\n /**\n * If the list items should be focusable and react to mouse over events.\n * Defaults to true if the list is selectable, false otherwise.\n */\n interactive?: boolean;\n /** If `true` compact the vertical spacing between list items. */\n condensed?: boolean;\n /** If `true`, the list items' left and right padding is removed. */\n disableGutters?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvListContainerClasses;\n}\n\n/**\n * A <b>list</b> is any enumeration of a set of items.\n * The simple list is for continuous <b>vertical indexes of text or icons+text</b>. The content of these lists must be simple: ideally simples fields.\n * This pattern is ideal for <b>selections</b>. It should be used inside a HvPanel.\n */\nexport const HvListContainer = forwardRef
|
|
1
|
+
{"version":3,"file":"ListContainer.js","sources":["../../../../src/components/ListContainer/ListContainer.tsx"],"sourcesContent":["import React, { useRef, useContext, useMemo, forwardRef } from \"react\";\n\nimport { HvBaseProps } from \"@core/types/generic\";\nimport { useForkRef } from \"@core/hooks/useForkRef\";\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { staticClasses, useClasses } from \"./ListContainer.styles\";\nimport HvListContext from \"./ListContext\";\n\nexport { staticClasses as listContainerClasses };\n\nexport type HvListContainerClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvListContainerProps extends HvBaseProps<HTMLUListElement> {\n /**\n * If the list items should be focusable and react to mouse over events.\n * Defaults to true if the list is selectable, false otherwise.\n */\n interactive?: boolean;\n /** If `true` compact the vertical spacing between list items. */\n condensed?: boolean;\n /** If `true`, the list items' left and right padding is removed. */\n disableGutters?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvListContainerClasses;\n}\n\n/**\n * A <b>list</b> is any enumeration of a set of items.\n * The simple list is for continuous <b>vertical indexes of text or icons+text</b>. The content of these lists must be simple: ideally simples fields.\n * This pattern is ideal for <b>selections</b>. It should be used inside a HvPanel.\n */\nexport const HvListContainer = forwardRef<\n HTMLUListElement,\n HvListContainerProps\n>((props, ref) => {\n const {\n id,\n classes: classesProp,\n className,\n interactive = false,\n condensed,\n disableGutters,\n children,\n ...others\n } = useDefaultProps(\"HvListContainer\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const containerRef = useRef(null);\n\n const { topContainerRef, nesting = -1 } = useContext(HvListContext);\n\n const listContext = useMemo(\n () => ({\n topContainerRef: topContainerRef || containerRef,\n condensed,\n disableGutters,\n interactive,\n nesting: nesting + 1,\n }),\n [condensed, disableGutters, interactive, nesting, topContainerRef]\n );\n\n const renderChildren = () => {\n if (!interactive) {\n return children;\n }\n\n const anySelected = React.Children.toArray(children)\n .map((child: any) => child.props.selected && !child.props.disabled)\n .reduce((result, selected) => result || selected, false);\n\n return React.Children.map(children, (child: any, i) => {\n const tabIndex =\n child.props.tabIndex ||\n (!anySelected && i === 0) ||\n (child.props.selected && !child.props.disabled)\n ? 0\n : -1;\n\n return React.cloneElement(child, {\n tabIndex,\n interactive,\n });\n });\n };\n\n const handleRef = useForkRef(ref, containerRef);\n\n return (\n <HvListContext.Provider value={listContext}>\n <ul\n ref={handleRef}\n id={id}\n className={cx(classes.root, className)}\n {...others}\n >\n {renderChildren()}\n </ul>\n </HvListContext.Provider>\n );\n});\n"],"names":["HvListContainer","forwardRef","props","ref","id","classes","classesProp","className","interactive","condensed","disableGutters","children","others","useDefaultProps","cx","useClasses","containerRef","useRef","topContainerRef","nesting","useContext","HvListContext","listContext","useMemo","renderChildren","anySelected","React","Children","toArray","map","child","selected","disabled","reduce","result","i","tabIndex","cloneElement","handleRef","useForkRef","root"],"mappings":";;;;;;;AAiCO,MAAMA,kBAAkBC,WAG7B,CAACC,OAAOC,QAAQ;AACV,QAAA;AAAA,IACJC;AAAAA,IACAC,SAASC;AAAAA,IACTC;AAAAA,IACAC,cAAc;AAAA,IACdC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACA,GAAGC;AAAAA,EAAAA,IACDC,gBAAgB,mBAAmBX,KAAK;AAEtC,QAAA;AAAA,IAAEG;AAAAA,IAASS;AAAAA,EAAAA,IAAOC,WAAWT,WAAW;AAExCU,QAAAA,eAAeC,OAAO,IAAI;AAE1B,QAAA;AAAA,IAAEC;AAAAA,IAAiBC,UAAU;AAAA,EAAA,IAAOC,WAAWC,aAAa;AAE5DC,QAAAA,cAAcC,QAClB,OAAO;AAAA,IACLL,iBAAiBA,mBAAmBF;AAAAA,IACpCP;AAAAA,IACAC;AAAAA,IACAF;AAAAA,IACAW,SAASA,UAAU;AAAA,EAAA,IAErB,CAACV,WAAWC,gBAAgBF,aAAaW,SAASD,eAAe,CACnE;AAEA,QAAMM,iBAAiBA,MAAM;AAC3B,QAAI,CAAChB,aAAa;AACTG,aAAAA;AAAAA,IACT;AAEMc,UAAAA,cAAcC,eAAMC,SAASC,QAAQjB,QAAQ,EAChDkB,IAAI,CAACC,UAAeA,MAAM5B,MAAM6B,YAAY,CAACD,MAAM5B,MAAM8B,QAAQ,EACjEC,OAAO,CAACC,QAAQH,aAAaG,UAAUH,UAAU,KAAK;AAEzD,WAAOL,eAAMC,SAASE,IAAIlB,UAAU,CAACmB,OAAYK,MAAM;AACrD,YAAMC,WACJN,MAAM5B,MAAMkC,YACX,CAACX,eAAeU,MAAM,KACtBL,MAAM5B,MAAM6B,YAAY,CAACD,MAAM5B,MAAM8B,WAClC,IACA;AAECN,aAAAA,eAAMW,aAAaP,OAAO;AAAA,QAC/BM;AAAAA,QACA5B;AAAAA,MAAAA,CACD;AAAA,IAAA,CACF;AAAA,EAAA;AAGG8B,QAAAA,YAAYC,WAAWpC,KAAKa,YAAY;AAG5C,SAAA,oBAAC,cAAc,UAAd,EAAuB,OAAOM,aAC7B,UAAA,oBAAC,QACC,KAAKgB,WACL,IACA,WAAWxB,GAAGT,QAAQmC,MAAMjC,SAAS,GACrC,GAAIK,QAEHY,UAAe,iBAClB,CAAA,EACF,CAAA;AAEJ,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","sources":["../../../../src/components/QueryBuilder/Context.tsx"],"sourcesContent":["import { createContext } from \"react\";\nimport {\n AskAction,\n Attribute,\n QueryAction,\n QueryBuilderLabels,\n QueryCombinator,\n QueryOperator,\n} from \"./types\";\n\nexport const defaultOperators = {\n numeric: [\n {\n operator: \"greaterThan\",\n label: \"Greater than (>)\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThan\",\n label: \"Less than (<)\",\n combinators: [\"and\"],\n },\n {\n operator: \"equalsTo\",\n label: \"Equal to (=)\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"greaterThanEq\",\n label: \"Greater than or equal to (>=)\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThanEq\",\n label: \"Less than or equal to (<=)\",\n combinators: [\"and\"],\n },\n {\n operator: \"notEqual\",\n label: \"Not equal to (!=)\",\n combinators: [\"and\"],\n },\n {\n operator: \"range\",\n label: \"Range\",\n combinators: [\"and\"],\n },\n ],\n text: [\n {\n operator: \"equals\",\n label: \"Equals\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"equalsIgnoreCase\",\n label: \"Equals Ignore Case\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"Contains\",\n label: \"Contains\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"StartsWith\",\n label: \"A string begins with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"EndsWith\",\n label: \"A string ends with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"IsNotEmpty\",\n label: \"Is Not empty\",\n combinators: [\"and\"],\n },\n {\n operator: \"IsNot\",\n label: \"Is Not\",\n combinators: [\"and\"],\n },\n {\n operator: \"Empty\",\n label: \"Empty\",\n combinators: [\"and\"],\n },\n ],\n textarea: [\n {\n operator: \"equals\",\n label: \"Equals\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"equalsIgnoreCase\",\n label: \"Equals Ignore Case\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"Contains\",\n label: \"Contains\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"StartsWith\",\n label: \"A string begins with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"EndsWith\",\n label: \"A string ends with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"IsNotEmpty\",\n label: \"Is Not empty\",\n combinators: [\"and\"],\n },\n {\n operator: \"IsNot\",\n label: \"Is Not\",\n combinators: [\"and\"],\n },\n {\n operator: \"Empty\",\n label: \"Empty\",\n combinators: [\"and\"],\n },\n ],\n boolean: [\n {\n operator: \"equalsTo\",\n label: \"=\",\n combinators: [\"and\", \"or\"],\n },\n ],\n dateandtime: [\n {\n operator: \"greaterThan\",\n label: \"Greater than\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThan\",\n label: \"Less than\",\n combinators: [\"and\"],\n },\n {\n operator: \"equalsTo\",\n label: \"Equal to\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"greaterThanEq\",\n label: \"Greater than or equal to\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThanEq\",\n label: \"Less than or equal to\",\n combinators: [\"and\"],\n },\n {\n operator: \"notEqual\",\n label: \"Not equal to\",\n combinators: [\"and\"],\n },\n {\n operator: \"range\",\n label: \"Range\",\n combinators: [\"and\"],\n },\n ],\n};\n\nexport const defaultCombinators = [\n { operand: \"and\", label: \"AND\" },\n { operand: \"or\", label: \"OR\" },\n];\n\nexport const defaultLabels = {\n query: {\n delete: {\n ariaLabel: \"Reset query\",\n tooltip: \"Reset query\",\n dialogTitle: \"Remove all conditions?\",\n dialogMessage:\n \"Are you sure you want to remove all the conditions? They will be removed permanently.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n },\n rule: {\n attribute: {\n label: \"Attribute\",\n placeholder: \"Select attribute...\",\n exists: \"Attribute already exists.\",\n },\n operator: {\n label: \"Operator\",\n placeholder: \"Select operator...\",\n },\n value: {\n distance: {\n label: \"Value\",\n connectorText: \"radius miles from\",\n button: \"Select location\",\n validation: {\n required: \"The value is required.\",\n invalid: \"Value must be a positive number.\",\n },\n },\n text: {\n label: \"Value\",\n placeholder: \"Enter value...\",\n validation: {\n required: \"The value is required.\",\n },\n },\n boolean: {\n label: \"Value\",\n placeholder: \"Enter value\",\n options: {\n true: \"True\",\n false: \"False\",\n },\n },\n numeric: {\n label: \"Value\",\n placeholder: \"Enter value\",\n validation: {\n required: \"The value is required.\",\n invalid: \"Value must be a number.\",\n equal: \"Cannot be equal.\",\n greaterThan: \"Needs to be greater.\",\n },\n range: {\n leftLabel: \"From\",\n rightLabel: \"To\",\n },\n },\n datetime: {\n dateLabel: \"Date\",\n datePlaceholder: \"Select Date\",\n timeLabel: \"Time\",\n timePlaceholder: \"Select Time\",\n startDateLabel: \"Start Date\",\n startDatePlaceholder: \"Select Start Date\",\n startTimeLabel: \"Start Time\",\n startTimePlaceholder: \"Select Start Time\",\n endDateLabel: \"End Date\",\n endDatePlaceholder: \"Select End Date\",\n endTimeLabel: \"End Time\",\n endTimePlaceholder: \"Select End Time\",\n validation: {\n required: \"The value is required.\",\n invalidInterval:\n \"End date and time must be after start date and time.\",\n },\n },\n },\n delete: {\n ariaLabel: \"Remove condition\",\n tooltip: \"Remove condition\",\n dialogTitle: \"Remove condition?\",\n dialogMessage:\n \"Are you sure you want to remove the condition? It will be removed permanently.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n },\n group: {\n delete: {\n ariaLabel: \"Remove group\",\n tooltip: \"Remove group\",\n dialogTitle: \"Remove group?\",\n dialogMessage:\n \"Are you sure you want to remove the group? It will be removed permanently.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n reset: {\n ariaLabel: \"Change operator\",\n tooltip: \"Change operator query\",\n dialogTitle: \"Change conditional operator?\",\n dialogMessage:\n \"Do you want to change conditional operator? You won't be able to undo this operation. Conditions and/or groups will be removed.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n addRule: {\n label: \"Add condition\",\n },\n addGroup: {\n label: \"Add group\",\n },\n },\n empty: {\n title: \"No conditions created yet\",\n createCondition: \"Create a condition\",\n createGroup: \"condition group\",\n spacer: \" or a \",\n },\n};\n\ninterface QueryBuilderContextValue {\n dispatchAction: React.Dispatch<QueryAction>;\n askAction: React.Dispatch<React.SetStateAction<AskAction | undefined>>;\n selectLocation?: React.Dispatch<unknown>;\n attributes?: Record<string, Attribute>;\n operators: Record<string, QueryOperator[]>;\n combinators: QueryCombinator[];\n maxDepth: number;\n labels: QueryBuilderLabels;\n initialTouched: boolean;\n readOnly: boolean;\n}\n\nexport const QueryBuilderContext = createContext<QueryBuilderContextValue>({\n dispatchAction: () => ({}),\n askAction: () => ({}),\n selectLocation: () => ({}),\n attributes: {},\n operators: defaultOperators,\n combinators: defaultCombinators,\n maxDepth: 1,\n labels: defaultLabels,\n initialTouched: false,\n readOnly: false,\n});\n"],"names":["defaultOperators","numeric","operator","label","combinators","text","textarea","boolean","dateandtime","defaultCombinators","operand","defaultLabels","query","delete","ariaLabel","tooltip","dialogTitle","dialogMessage","dialogConfirm","dialogCancel","dialogCloseTooltip","rule","attribute","placeholder","exists","value","distance","connectorText","button","validation","required","invalid","options","true","false","equal","greaterThan","range","leftLabel","rightLabel","datetime","dateLabel","datePlaceholder","timeLabel","timePlaceholder","startDateLabel","startDatePlaceholder","startTimeLabel","startTimePlaceholder","endDateLabel","endDatePlaceholder","endTimeLabel","endTimePlaceholder","invalidInterval","group","reset","addRule","addGroup","empty","title","createCondition","createGroup","spacer","QueryBuilderContext","createContext","dispatchAction","askAction","selectLocation","attributes","operators","maxDepth","labels","initialTouched","readOnly"],"mappings":";AAUO,MAAMA,mBAAmB;AAAA,EAC9BC,SAAS,CACP;AAAA,IACEC,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,OAAO,IAAI;AAAA,EAAA,GAE3B;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IACEF,UAAU;AAAA,IACV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oB;AAAA,QACpBvB,YAAY;AAAA,UACVC,UAAU;AAAA,UACVuB,iBACE;AAAA,QACJ;AAAA,MACF;AAAA,IACF;AAAA,IACAxC,QAAQ;AAAA,MACNC,WAAW;AAAA,MACXC,SAAS;AAAA,MACTC,aAAa;AAAA,MACbC,eACE;AAAA,MACFC,eAAe;AAAA,MACfC,cAAc;AAAA,MACdC,oBAAoB;AAAA,IACtB;AAAA,EACF;AAAA,EACAkC,OAAO;AAAA,IACLzC,QAAQ;AAAA,MACNC,WAAW;AAAA,MACXC,SAAS;AAAA,MACTC,aAAa;AAAA,MACbC,eACE;AAAA,MACFC,eAAe;AAAA,MACfC,cAAc;AAAA,MACdC,oBAAoB;AAAA,IACtB;AAAA,IACAmC,OAAO;AAAA,MACLzC,WAAW;AAAA,MACXC,SAAS;AAAA,MACTC,aAAa;AAAA,MACbC,eACE;AAAA,MACFC,eAAe;AAAA,MACfC,cAAc;AAAA,MACdC,oBAAoB;AAAA,IACtB;AAAA,IACAoC,SAAS;AAAA,MACPrD,OAAO;AAAA,IACT;AAAA,IACAsD,UAAU;AAAA,MACRtD,OAAO;AAAA,IACT;AAAA,EACF;AAAA,EACAuD,OAAO;AAAA,IACLC,OAAO;AAAA,IACPC,iBAAiB;AAAA,IACjBC,aAAa;AAAA,IACbC,QAAQ;AAAA,EACV;AACF;AAeO,MAAMC,sBAAsBC,cAAwC;AAAA,EACzEC,gBAAgBA,OAAO,CAAA;AAAA,EACvBC,WAAWA,OAAO,CAAA;AAAA,EAClBC,gBAAgBA,OAAO,CAAA;AAAA,EACvBC,YAAY,CAAC;AAAA,EACbC,WAAWrE;AAAAA,EACXI,aAAaK;AAAAA,EACb6D,UAAU;AAAA,EACVC,QAAQ5D;AAAAA,EACR6D,gBAAgB;AAAA,EAChBC,UAAU;AACZ,CAAC;"}
|
|
1
|
+
{"version":3,"file":"Context.js","sources":["../../../../src/components/QueryBuilder/Context.tsx"],"sourcesContent":["import { createContext } from \"react\";\nimport {\n AskAction,\n HvQueryBuilderAttribute,\n QueryAction,\n HvQueryBuilderLabels,\n HvQueryBuilderQueryCombinator,\n HvQueryBuilderQueryOperator,\n} from \"./types\";\n\nexport const defaultOperators = {\n numeric: [\n {\n operator: \"greaterThan\",\n label: \"Greater than (>)\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThan\",\n label: \"Less than (<)\",\n combinators: [\"and\"],\n },\n {\n operator: \"equalsTo\",\n label: \"Equal to (=)\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"greaterThanEq\",\n label: \"Greater than or equal to (>=)\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThanEq\",\n label: \"Less than or equal to (<=)\",\n combinators: [\"and\"],\n },\n {\n operator: \"notEqual\",\n label: \"Not equal to (!=)\",\n combinators: [\"and\"],\n },\n {\n operator: \"range\",\n label: \"Range\",\n combinators: [\"and\"],\n },\n ],\n text: [\n {\n operator: \"equals\",\n label: \"Equals\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"equalsIgnoreCase\",\n label: \"Equals Ignore Case\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"Contains\",\n label: \"Contains\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"StartsWith\",\n label: \"A string begins with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"EndsWith\",\n label: \"A string ends with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"IsNotEmpty\",\n label: \"Is Not empty\",\n combinators: [\"and\"],\n },\n {\n operator: \"IsNot\",\n label: \"Is Not\",\n combinators: [\"and\"],\n },\n {\n operator: \"Empty\",\n label: \"Empty\",\n combinators: [\"and\"],\n },\n ],\n textarea: [\n {\n operator: \"equals\",\n label: \"Equals\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"equalsIgnoreCase\",\n label: \"Equals Ignore Case\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"Contains\",\n label: \"Contains\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"StartsWith\",\n label: \"A string begins with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"EndsWith\",\n label: \"A string ends with\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"IsNotEmpty\",\n label: \"Is Not empty\",\n combinators: [\"and\"],\n },\n {\n operator: \"IsNot\",\n label: \"Is Not\",\n combinators: [\"and\"],\n },\n {\n operator: \"Empty\",\n label: \"Empty\",\n combinators: [\"and\"],\n },\n ],\n boolean: [\n {\n operator: \"equalsTo\",\n label: \"=\",\n combinators: [\"and\", \"or\"],\n },\n ],\n dateandtime: [\n {\n operator: \"greaterThan\",\n label: \"Greater than\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThan\",\n label: \"Less than\",\n combinators: [\"and\"],\n },\n {\n operator: \"equalsTo\",\n label: \"Equal to\",\n combinators: [\"and\", \"or\"],\n },\n {\n operator: \"greaterThanEq\",\n label: \"Greater than or equal to\",\n combinators: [\"and\"],\n },\n {\n operator: \"lessThanEq\",\n label: \"Less than or equal to\",\n combinators: [\"and\"],\n },\n {\n operator: \"notEqual\",\n label: \"Not equal to\",\n combinators: [\"and\"],\n },\n {\n operator: \"range\",\n label: \"Range\",\n combinators: [\"and\"],\n },\n ],\n};\n\nexport const defaultCombinators = [\n { operand: \"and\", label: \"AND\" },\n { operand: \"or\", label: \"OR\" },\n];\n\nexport const defaultLabels = {\n query: {\n delete: {\n ariaLabel: \"Reset query\",\n tooltip: \"Reset query\",\n dialogTitle: \"Remove all conditions?\",\n dialogMessage:\n \"Are you sure you want to remove all the conditions? They will be removed permanently.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n },\n rule: {\n attribute: {\n label: \"Attribute\",\n placeholder: \"Select attribute...\",\n exists: \"Attribute already exists.\",\n },\n operator: {\n label: \"Operator\",\n placeholder: \"Select operator...\",\n },\n value: {\n distance: {\n label: \"Value\",\n connectorText: \"radius miles from\",\n button: \"Select location\",\n validation: {\n required: \"The value is required.\",\n invalid: \"Value must be a positive number.\",\n },\n },\n text: {\n label: \"Value\",\n placeholder: \"Enter value...\",\n validation: {\n required: \"The value is required.\",\n },\n },\n boolean: {\n label: \"Value\",\n placeholder: \"Enter value\",\n options: {\n true: \"True\",\n false: \"False\",\n },\n },\n numeric: {\n label: \"Value\",\n placeholder: \"Enter value\",\n validation: {\n required: \"The value is required.\",\n invalid: \"Value must be a number.\",\n equal: \"Cannot be equal.\",\n greaterThan: \"Needs to be greater.\",\n },\n range: {\n leftLabel: \"From\",\n rightLabel: \"To\",\n },\n },\n datetime: {\n dateLabel: \"Date\",\n datePlaceholder: \"Select Date\",\n timeLabel: \"Time\",\n timePlaceholder: \"Select Time\",\n startDateLabel: \"Start Date\",\n startDatePlaceholder: \"Select Start Date\",\n startTimeLabel: \"Start Time\",\n startTimePlaceholder: \"Select Start Time\",\n endDateLabel: \"End Date\",\n endDatePlaceholder: \"Select End Date\",\n endTimeLabel: \"End Time\",\n endTimePlaceholder: \"Select End Time\",\n validation: {\n required: \"The value is required.\",\n invalidInterval:\n \"End date and time must be after start date and time.\",\n },\n },\n },\n delete: {\n ariaLabel: \"Remove condition\",\n tooltip: \"Remove condition\",\n dialogTitle: \"Remove condition?\",\n dialogMessage:\n \"Are you sure you want to remove the condition? It will be removed permanently.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n },\n group: {\n delete: {\n ariaLabel: \"Remove group\",\n tooltip: \"Remove group\",\n dialogTitle: \"Remove group?\",\n dialogMessage:\n \"Are you sure you want to remove the group? It will be removed permanently.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n reset: {\n ariaLabel: \"Change operator\",\n tooltip: \"Change operator query\",\n dialogTitle: \"Change conditional operator?\",\n dialogMessage:\n \"Do you want to change conditional operator? You won't be able to undo this operation. Conditions and/or groups will be removed.\",\n dialogConfirm: \"Yes\",\n dialogCancel: \"No\",\n dialogCloseTooltip: \"Close\",\n },\n addRule: {\n label: \"Add condition\",\n },\n addGroup: {\n label: \"Add group\",\n },\n },\n empty: {\n title: \"No conditions created yet\",\n createCondition: \"Create a condition\",\n createGroup: \"condition group\",\n spacer: \" or a \",\n },\n};\n\ninterface QueryBuilderContextValue {\n dispatchAction: React.Dispatch<QueryAction>;\n askAction: React.Dispatch<React.SetStateAction<AskAction | undefined>>;\n selectLocation?: React.Dispatch<unknown>;\n attributes?: Record<string, HvQueryBuilderAttribute>;\n operators: Record<string, HvQueryBuilderQueryOperator[]>;\n combinators: HvQueryBuilderQueryCombinator[];\n maxDepth: number;\n labels: HvQueryBuilderLabels;\n initialTouched: boolean;\n readOnly: boolean;\n}\n\nexport const QueryBuilderContext = createContext<QueryBuilderContextValue>({\n dispatchAction: () => ({}),\n askAction: () => ({}),\n selectLocation: () => ({}),\n attributes: {},\n operators: defaultOperators,\n combinators: defaultCombinators,\n maxDepth: 1,\n labels: defaultLabels,\n initialTouched: false,\n readOnly: false,\n});\n"],"names":["defaultOperators","numeric","operator","label","combinators","text","textarea","boolean","dateandtime","defaultCombinators","operand","defaultLabels","query","delete","ariaLabel","tooltip","dialogTitle","dialogMessage","dialogConfirm","dialogCancel","dialogCloseTooltip","rule","attribute","placeholder","exists","value","distance","connectorText","button","validation","required","invalid","options","true","false","equal","greaterThan","range","leftLabel","rightLabel","datetime","dateLabel","datePlaceholder","timeLabel","timePlaceholder","startDateLabel","startDatePlaceholder","startTimeLabel","startTimePlaceholder","endDateLabel","endDatePlaceholder","endTimeLabel","endTimePlaceholder","invalidInterval","group","reset","addRule","addGroup","empty","title","createCondition","createGroup","spacer","QueryBuilderContext","createContext","dispatchAction","askAction","selectLocation","attributes","operators","maxDepth","labels","initialTouched","readOnly"],"mappings":";AAUO,MAAMA,mBAAmB;AAAA,EAC9BC,SAAS,CACP;AAAA,IACEC,UAAU;AAAA,IACVC,OAAO;AAAA,IACPC,aAAa,CAAC,KAAK;AAAA,EAAA,GAErB;AAAA,IAC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,aAAa;AAAA,IACbC,QAAQ;AAAA,EACV;AACF;AAeO,MAAMC,sBAAsBC,cAAwC;AAAA,EACzEC,gBAAgBA,OAAO,CAAA;AAAA,EACvBC,WAAWA,OAAO,CAAA;AAAA,EAClBC,gBAAgBA,OAAO,CAAA;AAAA,EACvBC,YAAY,CAAC;AAAA,EACbC,WAAWrE;AAAAA,EACXI,aAAaK;AAAAA,EACb6D,UAAU;AAAA,EACVC,QAAQ5D;AAAAA,EACR6D,gBAAgB;AAAA,EAChBC,UAAU;AACZ,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBuilder.js","sources":["../../../../src/components/QueryBuilder/QueryBuilder.tsx"],"sourcesContent":["import cloneDeep from \"lodash/cloneDeep\";\nimport isEqual from \"lodash/isEqual\";\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\n\nimport {\n useContext,\n useEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n} from \"react\";\n\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { ConfirmationDialog } from \"./ConfirmationDialog\";\nimport { QueryBuilderContext } from \"./Context\";\nimport { RuleGroup } from \"./RuleGroup\";\nimport {\n AskAction,\n
|
|
1
|
+
{"version":3,"file":"QueryBuilder.js","sources":["../../../../src/components/QueryBuilder/QueryBuilder.tsx"],"sourcesContent":["import cloneDeep from \"lodash/cloneDeep\";\nimport isEqual from \"lodash/isEqual\";\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\n\nimport {\n useContext,\n useEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n} from \"react\";\n\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { ConfirmationDialog } from \"./ConfirmationDialog\";\nimport { QueryBuilderContext } from \"./Context\";\nimport { RuleGroup } from \"./RuleGroup\";\nimport {\n AskAction,\n HvQueryBuilderAttribute,\n HvQueryBuilderQuery,\n HvQueryBuilderLabels,\n HvQueryBuilderQueryCombinator,\n HvQueryBuilderQueryOperator,\n} from \"./types\";\nimport { clearNodeIds, emptyGroup } from \"./utils\";\nimport reducer from \"./utils/reducer\";\nimport { useClasses, staticClasses } from \"./QueryBuilder.styles\";\n\nexport { staticClasses as queryBuilderClasses };\n\nexport type HvQueryBuilderClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvQueryBuilderProps {\n attributes?: Record<string, HvQueryBuilderAttribute>;\n /**\n * The query rules operators by attribute type and combinator.\n */\n operators?: Record<string, HvQueryBuilderQueryOperator[]>;\n /**\n * The query combinators operands.\n */\n combinators?: HvQueryBuilderQueryCombinator[];\n /**\n * The initial query representation.\n */\n query?: HvQueryBuilderQuery;\n /**\n * Callback fired when query changes.\n * @param value - the query representation.\n */\n onChange?: (value: HvQueryBuilderQuery) => void;\n /**\n * Max depth of nested query groups.\n */\n maxDepth?: number;\n /**\n * An object containing all the labels.\n */\n labels?: HvQueryBuilderLabels;\n /**\n * A flag indicating if the Query Builder is in read only mode.\n */\n readOnly?: boolean;\n /**\n * Override or extend the styles applied to the component.\n * See CSS API tab for more details.\n */\n classes?: HvQueryBuilderClasses;\n}\n\n/**\n * **HvQueryBuilder** component allows you to create conditions and group them using logical operators.\n * It outputs a structured set of rules which can be easily parsed to create SQL/NoSQL/whatever queries.\n */\nexport const HvQueryBuilder = (props: HvQueryBuilderProps) => {\n const {\n attributes,\n query,\n onChange,\n operators,\n combinators,\n maxDepth = 1,\n labels,\n readOnly = false,\n classes: classesProp,\n } = useDefaultProps(\"HvQueryBuilder\", props);\n const { classes } = useClasses(classesProp);\n\n const [pendingAction, askAction] = useState<AskAction>();\n const currentAttributes = useRef<\n Record<string, HvQueryBuilderAttribute> | undefined | null\n >(null);\n const [state, dispatchAction] = useReducer(\n reducer,\n query,\n (initialState) => initialState || emptyGroup()\n );\n\n const initialState = query === state;\n const [prevState, setPrevState] = useState();\n\n const defaultContext = useContext(QueryBuilderContext);\n\n const context = useMemo(\n () => ({\n dispatchAction,\n askAction,\n attributes,\n /* eslint-disable react/destructuring-assignment */\n operators: operators ?? defaultContext.operators,\n combinators: combinators ?? defaultContext.combinators,\n maxDepth: maxDepth ?? defaultContext.maxDepth,\n labels: labels ?? defaultContext.labels,\n initialTouched: initialState,\n readOnly,\n }),\n [\n attributes,\n operators,\n defaultContext.operators,\n defaultContext.combinators,\n defaultContext.maxDepth,\n defaultContext.labels,\n combinators,\n maxDepth,\n labels,\n readOnly,\n initialState,\n ]\n );\n\n useEffect(() => {\n if (currentAttributes.current == null) {\n // first run, nothing to do\n currentAttributes.current = attributes;\n } else if (currentAttributes.current !== attributes) {\n // attributes changed, the existing query is almost certain invalid, so reset it\n currentAttributes.current = attributes;\n dispatchAction({ type: \"reset-query\" });\n }\n }, [attributes]);\n\n // Propagate the change if the query is modified.\n useEffect(() => {\n if (!initialState && !isEqual(state, prevState)) {\n onChange?.(clearNodeIds(state));\n setPrevState(cloneDeep(state));\n }\n }, [state, prevState, initialState, onChange]);\n\n const onConfirmHandler = () => {\n if (pendingAction) {\n askAction(undefined);\n pendingAction.actions.forEach((action) => dispatchAction(action));\n }\n };\n\n const onCancelHandler = () => {\n askAction(undefined);\n };\n\n return (\n <QueryBuilderContext.Provider value={context}>\n <RuleGroup\n level={0}\n id={state.id}\n combinator={state.combinator}\n rules={state.rules}\n classes={classes}\n />\n <ConfirmationDialog\n isOpen={pendingAction != null}\n onConfirm={onConfirmHandler}\n onCancel={onCancelHandler}\n title={pendingAction?.dialog.dialogTitle || \"\"}\n message={pendingAction?.dialog.dialogMessage || \"\"}\n confirmButtonLabel={pendingAction?.dialog.dialogConfirm || \"\"}\n cancelButtonLabel={pendingAction?.dialog.dialogCancel || \"\"}\n closeButtonTooltip={pendingAction?.dialog.dialogCloseTooltip || \"\"}\n />\n </QueryBuilderContext.Provider>\n );\n};\n"],"names":["HvQueryBuilder","props","attributes","query","onChange","operators","combinators","maxDepth","labels","readOnly","classes","classesProp","useDefaultProps","useClasses","pendingAction","askAction","useState","currentAttributes","useRef","state","dispatchAction","useReducer","reducer","initialState","emptyGroup","prevState","setPrevState","defaultContext","useContext","QueryBuilderContext","context","useMemo","initialTouched","useEffect","current","type","isEqual","clearNodeIds","cloneDeep","onConfirmHandler","undefined","actions","forEach","action","onCancelHandler","id","combinator","rules","dialog","dialogTitle","dialogMessage","dialogConfirm","dialogCancel","dialogCloseTooltip"],"mappings":";;;;;;;;;;;;AA4EaA,MAAAA,iBAAiBA,CAACC,UAA+B;AACtD,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,WAAW;AAAA,IACXC;AAAAA,IACAC,WAAW;AAAA,IACXC,SAASC;AAAAA,EAAAA,IACPC,gBAAgB,kBAAkBX,KAAK;AACrC,QAAA;AAAA,IAAES;AAAAA,EAAAA,IAAYG,WAAWF,WAAW;AAE1C,QAAM,CAACG,eAAeC,SAAS,IAAIC,SAAoB;AACjDC,QAAAA,oBAAoBC,OAExB,IAAI;AACA,QAAA,CAACC,OAAOC,cAAc,IAAIC,WAC9BC,SACAnB,OACCoB,CAAAA,kBAAiBA,iBAAgBC,WACpC,CAAA;AAEA,QAAMD,eAAepB,UAAUgB;AAC/B,QAAM,CAACM,WAAWC,YAAY,IAAIV,SAAS;AAErCW,QAAAA,iBAAiBC,WAAWC,mBAAmB;AAE/CC,QAAAA,UAAUC,QACd,OAAO;AAAA,IACLX;AAAAA,IACAL;AAAAA,IACAb;AAAAA;AAAAA,IAEAG,WAAWA,aAAasB,eAAetB;AAAAA,IACvCC,aAAaA,eAAeqB,eAAerB;AAAAA,IAC3CC,UAAUA,YAAYoB,eAAepB;AAAAA,IACrCC,QAAQA,UAAUmB,eAAenB;AAAAA,IACjCwB,gBAAgBT;AAAAA,IAChBd;AAAAA,EAAAA,IAEF,CACEP,YACAG,WACAsB,eAAetB,WACfsB,eAAerB,aACfqB,eAAepB,UACfoB,eAAenB,QACfF,aACAC,UACAC,QACAC,UACAc,YAAY,CAEhB;AAEAU,YAAU,MAAM;AACVhB,QAAAA,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|
|
2
|
-
import { useState, useCallback } from "react";
|
|
2
|
+
import { forwardRef, useState, useCallback } from "react";
|
|
3
3
|
import { useDefaultProps } from "../../hooks/useDefaultProps.js";
|
|
4
4
|
import { useUniqueId } from "../../hooks/useUniqueId.js";
|
|
5
5
|
import { useControlled } from "../../hooks/useControlled.js";
|
|
@@ -11,7 +11,7 @@ import { isInvalid } from "../Forms/FormElement/validationStates.js";
|
|
|
11
11
|
import { HvFormElement } from "../Forms/FormElement/FormElement.js";
|
|
12
12
|
import { HvLabel } from "../Forms/Label/Label.js";
|
|
13
13
|
import { HvWarningText } from "../Forms/WarningText/WarningText.js";
|
|
14
|
-
const HvRadio = (props) => {
|
|
14
|
+
const HvRadio = forwardRef((props, ref) => {
|
|
15
15
|
const {
|
|
16
16
|
classes: classesProp,
|
|
17
17
|
className,
|
|
@@ -64,7 +64,7 @@ const HvRadio = (props) => {
|
|
|
64
64
|
if (isStateInvalid) {
|
|
65
65
|
errorMessageId = canShowError ? setId(elementId, "error") : ariaErrorMessage;
|
|
66
66
|
}
|
|
67
|
-
const radio = /* @__PURE__ */ jsx(HvBaseRadio, { id: label ? setId(elementId, "input") : setId(id, "input"), name, className: cx(classes.radio, {
|
|
67
|
+
const radio = /* @__PURE__ */ jsx(HvBaseRadio, { ref, id: label ? setId(elementId, "input") : setId(id, "input"), name, className: cx(classes.radio, {
|
|
68
68
|
[classes.invalidRadio]: isStateInvalid
|
|
69
69
|
}), disabled, readOnly, onChange: onLocalChange, value, checked: isChecked, semantic, inputProps: {
|
|
70
70
|
"aria-invalid": isStateInvalid ? true : void 0,
|
|
@@ -85,7 +85,7 @@ const HvRadio = (props) => {
|
|
|
85
85
|
] }) : radio,
|
|
86
86
|
canShowError && /* @__PURE__ */ jsx(HvWarningText, { id: setId(elementId, "error"), disableBorder: true, children: statusMessage })
|
|
87
87
|
] });
|
|
88
|
-
};
|
|
88
|
+
});
|
|
89
89
|
export {
|
|
90
90
|
HvRadio,
|
|
91
91
|
staticClasses as radioClasses
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Radio.js","sources":["../../../../src/components/Radio/Radio.tsx"],"sourcesContent":["import React, { useCallback, useState } from \"react\";\n\nimport { RadioProps as MuiRadioProps } from \"@mui/material\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { HvBaseProps } from \"@core/types/generic\";\nimport { HvBaseRadio } from \"@core/components/BaseRadio\";\nimport {\n HvWarningText,\n HvLabelProps,\n isInvalid,\n HvFormElement,\n HvLabel,\n} from \"@core/components/Forms\";\nimport { useUniqueId } from \"@core/hooks/useUniqueId\";\nimport { useControlled } from \"@core/hooks/useControlled\";\nimport { setId } from \"@core/utils/setId\";\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { staticClasses, useClasses } from \"./Radio.styles\";\n\nexport { staticClasses as radioClasses };\n\nexport type HvRadioClasses = ExtractNames<typeof useClasses>;\n\nexport type HvRadioStatus = \"standBy\" | \"valid\" | \"invalid\";\n\nexport interface HvRadioProps\n extends Omit<MuiRadioProps, \"onChange\" | \"classes\">,\n HvBaseProps<HTMLButtonElement, \"onChange\" | \"color\"> {\n /**\n * A Jss Object used to override or extend the styles applied to the radio button.\n */\n classes?: HvRadioClasses;\n /**\n * The form element name.\n */\n name?: string;\n /**\n * The value of the form element.\n *\n * The default value is \"on\".\n */\n value?: any;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided.\n */\n label?: React.ReactNode;\n /**\n * Properties passed on to the label element.\n */\n labelProps?: HvLabelProps;\n /**\n * Indicates that user input is required on the form element.\n *\n * If a single radio button in a group has the required attribute, a radio button in\n * that group must be check, though it doesn't have to be the one with the attribute is applied.\n *\n * For that reason, the component doesn't make any uncontrolled changes to its validation status.\n * That should ideally be managed in the context of a radio button group.\n */\n required?: boolean;\n /**\n * Indicates that the form element is not editable.\n */\n readOnly?: boolean;\n /**\n * Indicates that the form element is disabled.\n */\n disabled?: boolean;\n /**\n * If `true` the radio button is selected, if set to `false` the radio button is not selected.\n *\n * When defined the radio button state becomes controlled.\n */\n checked?: boolean;\n /**\n * When uncontrolled, defines the initial checked state.\n */\n defaultChecked?: 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 status?: HvRadioStatus;\n /**\n * The error message to show when `status` is \"invalid\".\n */\n statusMessage?: string;\n /**\n * Identifies the element that provides an error message for the radio button.\n *\n * Will only be used when the validation status is invalid.\n */\n \"aria-errormessage\"?: string;\n /**\n * The callback fired when the radio button is pressed.\n */\n onChange?: (\n event: React.ChangeEvent<HTMLInputElement>,\n checked: boolean,\n value: any\n ) => void;\n /**\n * Whether the selector should use semantic colors.\n */\n semantic?: boolean;\n /**\n * Properties passed on to the input element.\n */\n inputProps?: React.InputHTMLAttributes<HTMLInputElement>;\n /**\n * Callback fired when the component is focused with a keyboard.\n * We trigger a `onFocus` callback too.\n */\n onFocusVisible?: (event: React.FocusEvent<any>) => void;\n /** @ignore */\n ref?: MuiRadioProps[\"ref\"];\n /** @ignore */\n component?: MuiRadioProps[\"component\"];\n}\n\n/**\n * A Radio Button is a mechanism that allows user to select just an option from a group of options.\n *\n * It should used in a Radio Button Group to present the user with a range of options from\n * which the user <b>may select just one option</b> to complete their task.\n *\n * Individual use of radio buttons, at least uncontrolled, is unadvised as React state management doesn't\n * respond to the browser's native management of radio inputs checked state.\n */\nexport const HvRadio = (props: HvRadioProps) => {\n const {\n classes: classesProp,\n className,\n id,\n name,\n value = \"on\",\n required = false,\n readOnly = false,\n disabled = false,\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n labelProps,\n checked,\n defaultChecked = false,\n onChange,\n status = \"standBy\",\n statusMessage,\n \"aria-errormessage\": ariaErrorMessage,\n semantic = false,\n inputProps,\n onFocusVisible,\n onBlur,\n ...others\n } = useDefaultProps(\"HvRadio\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const elementId = useUniqueId(id, \"hvradio\");\n\n const [focusVisible, setFocusVisible] = useState(false);\n\n const onFocusVisibleCallback = useCallback(\n (evt: React.FocusEvent<any>) => {\n setFocusVisible(true);\n onFocusVisible?.(evt);\n },\n [onFocusVisible]\n );\n\n const onBlurCallback = useCallback(\n (evt: React.FocusEvent<any>) => {\n setFocusVisible(false);\n onBlur?.(evt);\n },\n [onBlur]\n );\n\n const [isChecked, setIsChecked] = useControlled(\n checked,\n Boolean(defaultChecked)\n );\n\n const onLocalChange = useCallback(\n (evt: React.ChangeEvent<HTMLInputElement>, newChecked: boolean) => {\n setIsChecked(newChecked);\n\n onChange?.(evt, newChecked, value);\n },\n [onChange, setIsChecked, value]\n );\n\n // the error message area will only be created if:\n // - an external element that provides an error message isn't identified via aria-errormessage AND\n // - both status and statusMessage properties are being controlled\n const canShowError =\n ariaErrorMessage == null &&\n status !== undefined &&\n statusMessage !== undefined;\n\n const hasLabel = label != null;\n\n const isStateInvalid = isInvalid(status);\n\n let errorMessageId: string | undefined;\n if (isStateInvalid) {\n errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n }\n\n const radio = (\n <HvBaseRadio\n id={label ? setId(elementId, \"input\") : setId(id, \"input\")}\n name={name}\n className={cx(classes.radio, { [classes.invalidRadio]: isStateInvalid })}\n disabled={disabled}\n readOnly={readOnly}\n onChange={onLocalChange}\n value={value}\n checked={isChecked}\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={status || \"standBy\"}\n disabled={disabled}\n required={required}\n readOnly={readOnly}\n className={cx(classes.root, className)}\n >\n {hasLabel ? (\n <div\n className={cx(classes.container, {\n [classes.disabled]: disabled,\n [classes.focusVisible]: !!(focusVisible && label),\n [classes.invalidContainer]: isStateInvalid,\n })}\n >\n {radio}\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 radio\n )}\n {canShowError && (\n <HvWarningText id={setId(elementId, \"error\")} disableBorder>\n {statusMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n};\n"],"names":["HvRadio","props","classes","classesProp","className","id","name","value","required","readOnly","disabled","label","ariaLabel","ariaLabelledBy","ariaDescribedBy","labelProps","checked","defaultChecked","onChange","status","statusMessage","ariaErrorMessage","semantic","inputProps","onFocusVisible","onBlur","others","useDefaultProps","cx","useClasses","elementId","useUniqueId","focusVisible","setFocusVisible","useState","onFocusVisibleCallback","useCallback","evt","onBlurCallback","isChecked","setIsChecked","useControlled","Boolean","onLocalChange","newChecked","canShowError","undefined","hasLabel","isStateInvalid","isInvalid","errorMessageId","setId","radio","invalidRadio","root","container","invalidContainer"],"mappings":";;;;;;;;;;;;;AAuIaA,MAAAA,UAAUA,CAACC,UAAwB;AACxC,QAAA;AAAA,IACJC,SAASC;AAAAA,IACTC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,QAAQ;AAAA,IACRC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC;AAAAA,IACA,cAAcC;AAAAA,IACd,mBAAmBC;AAAAA,IACnB,oBAAoBC;AAAAA,IACpBC;AAAAA,IACAC;AAAAA,IACAC,iBAAiB;AAAA,IACjBC;AAAAA,IACAC,SAAS;AAAA,IACTC;AAAAA,IACA,qBAAqBC;AAAAA,IACrBC,WAAW;AAAA,IACXC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACA,GAAGC;AAAAA,EAAAA,IACDC,gBAAgB,WAAW1B,KAAK;AAE9B,QAAA;AAAA,IAAEC;AAAAA,I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oBAAoBC;AAAAA,IACpB,GAAGS;AAAAA,EAAAA,GAEL,gBAAgBY,wBAChB,QAAQG,gBACJZ,GAAAA,OAEP,CAAA;AAED,SACG,qBAAA,eAAA,EACC,IACA,MACA,QAAQP,UAAU,WAClB,UACA,UACA,UACA,WAAWS,GAAG1B,QAAQoD,MAAMlD,SAAS,GAEpC2C,UAAAA;AAAAA,IAAAA,WACE,qBAAA,OAAA,EACC,WAAWnB,GAAG1B,QAAQqD,WAAW;AAAA,MAC/B,CAACrD,QAAQQ,QAAQ,GAAGA;AAAAA,MACpB,CAACR,QAAQ8B,YAAY,GAAG,CAAC,EAAEA,gBAAgBrB;AAAAA,MAC3C,CAACT,QAAQsD,gBAAgB,GAAGR;AAAAA,IAC7B,CAAA,GAEAI,UAAAA;AAAAA,MAAAA;AAAAA,0BACA,SACC,EAAA,IAAID,MAAMrB,WAAW,OAAO,GAC5B,SAASqB,MAAMrB,WAAW,OAAO,GACjC,OACA,WAAW5B,QAAQS,OACnB,GAAII,YAAW;AAAA,IAAA,EAAA,CAEnB,IAEAqC;AAAAA,IAEDP,gBACE,oBAAA,eAAA,EAAc,IAAIM,MAAMrB,WAAW,OAAO,GAAG,eAAa,MACxDV,UACH,cAAA,CAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"Radio.js","sources":["../../../../src/components/Radio/Radio.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useState } from \"react\";\n\nimport { RadioProps as MuiRadioProps } from \"@mui/material\";\n\nimport { useDefaultProps } from \"@core/hooks/useDefaultProps\";\nimport { HvBaseProps } from \"@core/types/generic\";\nimport { HvBaseRadio } from \"@core/components/BaseRadio\";\nimport {\n HvWarningText,\n HvLabelProps,\n isInvalid,\n HvFormElement,\n HvLabel,\n} from \"@core/components/Forms\";\nimport { useUniqueId } from \"@core/hooks/useUniqueId\";\nimport { useControlled } from \"@core/hooks/useControlled\";\nimport { setId } from \"@core/utils/setId\";\nimport { ExtractNames } from \"@core/utils/classes\";\n\nimport { staticClasses, useClasses } from \"./Radio.styles\";\n\nexport { staticClasses as radioClasses };\n\nexport type HvRadioClasses = ExtractNames<typeof useClasses>;\n\nexport type HvRadioStatus = \"standBy\" | \"valid\" | \"invalid\";\n\nexport interface HvRadioProps\n extends Omit<MuiRadioProps, \"onChange\" | \"classes\">,\n HvBaseProps<HTMLButtonElement, \"onChange\" | \"color\"> {\n /**\n * A Jss Object used to override or extend the styles applied to the radio button.\n */\n classes?: HvRadioClasses;\n /**\n * The form element name.\n */\n name?: string;\n /**\n * The value of the form element.\n *\n * The default value is \"on\".\n */\n value?: any;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided.\n */\n label?: React.ReactNode;\n /**\n * Properties passed on to the label element.\n */\n labelProps?: HvLabelProps;\n /**\n * Indicates that user input is required on the form element.\n *\n * If a single radio button in a group has the required attribute, a radio button in\n * that group must be check, though it doesn't have to be the one with the attribute is applied.\n *\n * For that reason, the component doesn't make any uncontrolled changes to its validation status.\n * That should ideally be managed in the context of a radio button group.\n */\n required?: boolean;\n /**\n * Indicates that the form element is not editable.\n */\n readOnly?: boolean;\n /**\n * Indicates that the form element is disabled.\n */\n disabled?: boolean;\n /**\n * If `true` the radio button is selected, if set to `false` the radio button is not selected.\n *\n * When defined the radio button state becomes controlled.\n */\n checked?: boolean;\n /**\n * When uncontrolled, defines the initial checked state.\n */\n defaultChecked?: 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 status?: HvRadioStatus;\n /**\n * The error message to show when `status` is \"invalid\".\n */\n statusMessage?: string;\n /**\n * Identifies the element that provides an error message for the radio button.\n *\n * Will only be used when the validation status is invalid.\n */\n \"aria-errormessage\"?: string;\n /**\n * The callback fired when the radio button is pressed.\n */\n onChange?: (\n event: React.ChangeEvent<HTMLInputElement>,\n checked: boolean,\n value: any\n ) => void;\n /**\n * Whether the selector should use semantic colors.\n */\n semantic?: boolean;\n /**\n * Properties passed on to the input element.\n */\n inputProps?: React.InputHTMLAttributes<HTMLInputElement>;\n /**\n * Callback fired when the component is focused with a keyboard.\n * We trigger a `onFocus` callback too.\n */\n onFocusVisible?: (event: React.FocusEvent<any>) => void;\n /** @ignore */\n ref?: MuiRadioProps[\"ref\"];\n /** @ignore */\n component?: MuiRadioProps[\"component\"];\n}\n\n/**\n * A Radio Button is a mechanism that allows user to select just an option from a group of options.\n *\n * It should used in a Radio Button Group to present the user with a range of options from\n * which the user <b>may select just one option</b> to complete their task.\n *\n * Individual use of radio buttons, at least uncontrolled, is unadvised as React state management doesn't\n * respond to the browser's native management of radio inputs checked state.\n */\nexport const HvRadio = forwardRef<HTMLButtonElement, HvRadioProps>(\n (props, ref) => {\n const {\n classes: classesProp,\n className,\n id,\n name,\n value = \"on\",\n required = false,\n readOnly = false,\n disabled = false,\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n labelProps,\n checked,\n defaultChecked = false,\n onChange,\n status = \"standBy\",\n statusMessage,\n \"aria-errormessage\": ariaErrorMessage,\n semantic = false,\n inputProps,\n onFocusVisible,\n onBlur,\n ...others\n } = useDefaultProps(\"HvRadio\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const elementId = useUniqueId(id, \"hvradio\");\n\n const [focusVisible, setFocusVisible] = useState(false);\n\n const onFocusVisibleCallback = useCallback(\n (evt: React.FocusEvent<any>) => {\n setFocusVisible(true);\n onFocusVisible?.(evt);\n },\n [onFocusVisible]\n );\n\n const onBlurCallback = useCallback(\n (evt: React.FocusEvent<any>) => {\n setFocusVisible(false);\n onBlur?.(evt);\n },\n [onBlur]\n );\n\n const [isChecked, setIsChecked] = useControlled(\n checked,\n Boolean(defaultChecked)\n );\n\n const onLocalChange = useCallback(\n (evt: React.ChangeEvent<HTMLInputElement>, newChecked: boolean) => {\n setIsChecked(newChecked);\n\n onChange?.(evt, newChecked, value);\n },\n [onChange, setIsChecked, value]\n );\n\n // the error message area will only be created if:\n // - an external element that provides an error message isn't identified via aria-errormessage AND\n // - both status and statusMessage properties are being controlled\n const canShowError =\n ariaErrorMessage == null &&\n status !== undefined &&\n statusMessage !== undefined;\n\n const hasLabel = label != null;\n\n const isStateInvalid = isInvalid(status);\n\n let errorMessageId: string | undefined;\n if (isStateInvalid) {\n errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n }\n\n const radio = (\n <HvBaseRadio\n ref={ref}\n id={label ? setId(elementId, \"input\") : setId(id, \"input\")}\n name={name}\n className={cx(classes.radio, {\n [classes.invalidRadio]: isStateInvalid,\n })}\n disabled={disabled}\n readOnly={readOnly}\n onChange={onLocalChange}\n value={value}\n checked={isChecked}\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={status || \"standBy\"}\n disabled={disabled}\n required={required}\n readOnly={readOnly}\n className={cx(classes.root, className)}\n >\n {hasLabel ? (\n <div\n className={cx(classes.container, {\n [classes.disabled]: disabled,\n [classes.focusVisible]: !!(focusVisible && label),\n [classes.invalidContainer]: isStateInvalid,\n })}\n >\n {radio}\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 radio\n )}\n {canShowError && (\n <HvWarningText id={setId(elementId, \"error\")} disableBorder>\n {statusMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n }\n);\n"],"names":["HvRadio","forwardRef","props","ref","classes","classesProp","className","id","name","value","required","readOnly","disabled","label","ariaLabel","ariaLabelledBy","ariaDescribedBy","labelProps","checked","defaultChecked","onChange","status","statusMessage","ariaErrorMessage","semantic","inputProps","onFocusVisible","onBlur","others","useDefaultProps","cx","useClasses","elementId","useUniqueId","focusVisible","setFocusVisible","useState","onFocusVisibleCallback","useCallback","evt","onBlurCallback","isChecked","setIsChecked","useControlled","Boolean","onLocalChange","newChecked","canShowError","undefined","hasLabel","isStateInvalid","isInvalid","errorMessageId","setId","radio","invalidRadio","root","container","invalidContainer"],"mappings":";;;;;;;;;;;;;AAuIO,MAAMA,UAAUC,WACrB,CAACC,OAAOC,QAAQ;AACR,QAAA;AAAA,IACJC,SAASC;AAAAA,IACTC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,QAAQ;AAAA,IACRC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC;AAAAA,IACA,cAAcC;AAAAA,IACd,mBAAmBC;AAAAA,IACnB,oBAAoBC;AAAAA,IACpBC;AAAAA,IACAC;AAAAA,IACAC,iBAAiB;AAAA,IACjBC;AAAAA,IACAC,SAAS;AAAA,IACTC;AAAAA,IACA,qBAAqBC;AAAAA,IACrBC,WAAW;AAAA,IACXC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACA,GAAGC;AAAAA,EAAAA,IACDC,gBAAgB,WAAW3B,KAAK;AAE9B,QAAA;AAAA,IAAEE;AAAAA,IAAS0B;AAAAA,EAAAA,IAAOC,WAAW1B,WAAW;AAExC2B,QAAAA,YAAYC,YAAY1B,IAAI,SAAS;AAE3C,QAAM,CAAC2B,cAAcC,eAAe,IAAIC,SAAS,KAAK;AAEhDC,QAAAA,yBAAyBC,YAC7B,CAACC,QAA+B;AAC9BJ,oBAAgB,IAAI;AACpBT,qDAAiBa;AAAAA,EAAG,GAEtB,CAACb,cAAc,CACjB;AAEMc,QAAAA,iBAAiBF,YACrB,CAACC,QAA+B;AAC9BJ,oBAAgB,KAAK;AACrBR,qCAASY;AAAAA,EAAG,GAEd,CAACZ,MAAM,C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AG,CAAC,EAAEA,gBAAgBrB;AAAAA,MAC3C,CAACT,QAAQsD,gBAAgB,GAAGR;AAAAA,IAC7B,CAAA,GAEAI,UAAAA;AAAAA,MAAAA;AAAAA,0BACA,SACC,EAAA,IAAID,MAAMrB,WAAW,OAAO,GAC5B,SAASqB,MAAMrB,WAAW,OAAO,GACjC,OACA,WAAW5B,QAAQS,OACnB,GAAII,YAAW;AAAA,IAAA,EAAA,CAEnB,IAEAqC;AAAAA,IAEDP,gBACE,oBAAA,eAAA,EAAc,IAAIM,MAAMrB,WAAW,OAAO,GAAG,eAAa,MACxDV,UACH,cAAA,CAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ,CACF;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs, jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import { useCallback, useMemo, Children, cloneElement } from "react";
|
|
2
|
+
import { forwardRef, useCallback, useMemo, Children, cloneElement } from "react";
|
|
3
3
|
import { useDefaultProps } from "../../hooks/useDefaultProps.js";
|
|
4
4
|
import { useUniqueId } from "../../hooks/useUniqueId.js";
|
|
5
5
|
import { useControlled } from "../../hooks/useControlled.js";
|
|
@@ -24,7 +24,7 @@ const getValueFromSelectedChildren = (children) => {
|
|
|
24
24
|
}
|
|
25
25
|
return null;
|
|
26
26
|
};
|
|
27
|
-
const HvRadioGroup = (props) => {
|
|
27
|
+
const HvRadioGroup = forwardRef((props, ref) => {
|
|
28
28
|
const {
|
|
29
29
|
id,
|
|
30
30
|
classes: classesProp,
|
|
@@ -92,14 +92,14 @@ const HvRadioGroup = (props) => {
|
|
|
92
92
|
return /* @__PURE__ */ jsxs(HvFormElement, { id, name, status: status || "standBy", disabled, required, readOnly, className: cx(classes.root, className), children: [
|
|
93
93
|
label && /* @__PURE__ */ jsx(HvLabel, { id: setId(elementId, "label"), label, className: classes.label }),
|
|
94
94
|
description && /* @__PURE__ */ jsx(HvInfoMessage, { id: setId(elementId, "description"), children: description }),
|
|
95
|
-
/* @__PURE__ */ jsx("div", { role: "radiogroup", "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy || label && setId(elementId, "label") || void 0, "aria-invalid": status === "invalid" ? true : void 0, "aria-errormessage": status === "invalid" ? errorMessageId : void 0, "aria-describedby": [description && setId(elementId, "description"), ariaDescribedBy].join(" ").trim() || void 0, className: cx(classes.group, {
|
|
95
|
+
/* @__PURE__ */ jsx("div", { ref, role: "radiogroup", "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy || label && setId(elementId, "label") || void 0, "aria-invalid": status === "invalid" ? true : void 0, "aria-errormessage": status === "invalid" ? errorMessageId : void 0, "aria-describedby": [description && setId(elementId, "description"), ariaDescribedBy].join(" ").trim() || void 0, className: cx(classes.group, {
|
|
96
96
|
[classes.vertical]: orientation === "vertical",
|
|
97
97
|
[classes.horizontal]: orientation === "horizontal",
|
|
98
98
|
[classes.invalid]: status === "invalid"
|
|
99
99
|
}), ...others, children: modifiedChildren }),
|
|
100
100
|
canShowError && /* @__PURE__ */ jsx(HvWarningText, { id: setId(elementId, "error"), disableBorder: true, className: classes.error, children: statusMessage })
|
|
101
101
|
] });
|
|
102
|
-
};
|
|
102
|
+
});
|
|
103
103
|
export {
|
|
104
104
|
HvRadioGroup,
|
|
105
105
|
staticClasses as radioGroupClasses
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioGroup.js","sources":["../../../../src/components/RadioGroup/RadioGroup.tsx"],"sourcesContent":["import { Children, useMemo, useCallback, cloneElement } 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 {\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 \"./RadioGroup.styles\";\n\nexport { staticClasses as radioGroupClasses };\n\nexport type HvRadioGroupClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvRadioGroupProps\n extends HvBaseProps<HTMLDivElement, \"onChange\"> {\n /**\n * The form element name.\n *\n * It is propagated to the children radio buttons, unless they already have one (which they shouldn't).\n */\n name?: string;\n /**\n * The value of the form element, represented in one of the child radio buttons values.\n *\n * When defined the radio button 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 radio buttons.\n */\n disabled?: boolean;\n /**\n * Indicates that the form element is not editable.\n * If `true` the state is propagated to the children radio buttons.\n */\n readOnly?: boolean;\n /**\n * Indicates that user input is required on the form element.\n * If `true` the state is propagated to the children radio buttons' input 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 `status` is \"invalid\".\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 radio buttons group's orientation is horizontal or vertical.\n *\n * Defaults to vertical.\n */\n orientation?: \"vertical\" | \"horizontal\";\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvRadioGroupClasses;\n}\n\nconst getValueFromSelectedChildren = (children: React.ReactNode) => {\n const childrenArray = Children.toArray(children);\n const childrenCount = childrenArray.length;\n for (let i = 0; i !== childrenCount; i += 1) {\n const child: any = childrenArray[i];\n\n const childIsControlled = child?.props?.checked !== undefined;\n const childIsSelected = childIsControlled\n ? child?.props?.checked\n : child?.props?.defaultChecked;\n\n if (childIsSelected) {\n return child?.props?.value;\n }\n }\n\n return null;\n};\n\n/**\n * A group of radio buttons.\n *\n * A radio group is a type of selection list that can only have a single entry checked at any one time.\n */\nexport const HvRadioGroup = (props: HvRadioGroupProps) => {\n const {\n id,\n classes: classesProp,\n className,\n children,\n name,\n value: valueProp,\n defaultValue,\n label,\n description,\n status,\n statusMessage,\n required = false,\n readOnly = false,\n disabled = false,\n orientation = \"vertical\",\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-errormessage\": ariaErrorMessage,\n onChange,\n ...others\n } = useDefaultProps(\"HvRadioGroup\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const elementId = useUniqueId(id, \"hvradiogroup\");\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 onChildChangeInterceptor = useCallback(\n (\n childOnChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n checked: boolean,\n value: any\n ) => void,\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean,\n newValue: any\n ) => {\n childOnChange?.(event, isChecked, newValue);\n\n onChange?.(event, newValue);\n\n setValue(newValue);\n },\n [onChange, setValue]\n );\n\n const modifiedChildren = useMemo(() => {\n return Children.map(children, (child: any) => {\n const childValue = child?.props?.value ?? \"on\";\n\n const childIsSelected = childValue === value;\n\n return cloneElement(child, {\n checked: childIsSelected,\n name: child?.props?.name || name || elementId,\n onChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean,\n newValue: any\n ) =>\n onChildChangeInterceptor(\n child?.props?.onChange,\n event,\n isChecked,\n newValue\n ),\n inputProps: {\n ...child?.props?.inputProps,\n // Set the required attribute directly in the input\n // the radio form element context shouldn't be aware so the\n // label doesn't show redundant asterisk\n required,\n },\n disabled: disabled || child?.props?.disabled,\n readOnly: readOnly || child?.props?.readOnly,\n });\n });\n }, [\n children,\n disabled,\n elementId,\n name,\n onChildChangeInterceptor,\n readOnly,\n required,\n value,\n ]);\n\n // The error message area will only be created if:\n // - an external element that provides an error message isn't identified via aria-errormessage AND\n // - both status and statusMessage properties are being controlled OR\n // - status is uncontrolled and 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={status || \"standBy\"}\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=\"radiogroup\"\n aria-label={ariaLabel}\n aria-labelledby={\n ariaLabelledBy || (label && setId(elementId, \"label\")) || undefined\n }\n aria-invalid={status === \"invalid\" ? true : undefined}\n aria-errormessage={status === \"invalid\" ? errorMessageId : undefined}\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]: status === \"invalid\",\n })}\n {...others}\n >\n {modifiedChildren}\n </div>\n\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {statusMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n};\n"],"names":["getValueFromSelectedChildren","children","childrenArray","Children","toArray","childrenCount","length","i","child","childIsControlled","props","checked","undefined","childIsSelected","defaultChecked","value","HvRadioGroup","id","classes","classesProp","className","name","valueProp","defaultValue","label","description","status","statusMessage","required","readOnly","disabled","orientation","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaErrorMessage","onChange","others","useDefaultProps","cx","useClasses","elementId","useUniqueId","setValue","useControlled","onChildChangeInterceptor","useCallback","childOnChange","event","isChecked","newValue","modifiedChildren","useMemo","map","childValue","cloneElement","inputProps","canShowError","errorMessageId","setId","root","join","trim","group","vertical","horizontal","invalid","error"],"mappings":";;;;;;;;;;;;AA+FA,MAAMA,+BAA+BA,CAACC,aAA8B;;AAC5DC,QAAAA,gBAAgBC,SAASC,QAAQH,QAAQ;AAC/C,QAAMI,gBAAgBH,cAAcI;AACpC,WAASC,IAAI,GAAGA,MAAMF,eAAeE,KAAK,GAAG;AACrCC,UAAAA,QAAaN,cAAcK,CAAC;AAE5BE,UAAAA,sBAAoBD,oCAAOE,UAAPF,mBAAcG,aAAYC;AACpD,UAAMC,kBAAkBJ,qBACpBD,oCAAOE,UAAPF,mBAAcG,WACdH,oCAAOE,UAAPF,mBAAcM;AAElB,QAAID,iBAAiB;AACnB,cAAOL,oCAAOE,UAAPF,mBAAcO;AAAAA,IACvB;AAAA,EACF;AAEO,SAAA;AACT;AAOaC,MAAAA,eAAeA,CAACN,UAA6B;AAClD,QAAA;AAAA,IACJO;AAAAA,IACAC,SAASC;AAAAA,IACTC;AAAAA,IACAnB;AAAAA,IACAoB;AAAAA,IACAN,OAAOO;AAAAA,IACPC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,WAAW;AAAA,IACXC,cAAc;AAAA,IACd,cAAcC;AAAAA,IACd,mBAAmBC;AAAAA,IACnB,oBAAoBC;AAAAA,IACpB,qBAAqBC;AAAAA,IACrBC;AAAAA,IACA,GAAGC;AAAAA,EAAAA,IACDC,gBAAgB,gBAAgB5B,KAAK;AAEnC,QAAA;AAAA,IAAEQ;AAAAA,IAASqB;AAA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E7B,QAAM8B,iBAAiBD,eACnBE,MAAMlB,WAAW,OAAO,IACxBN;AAEJ,SACG,qBAAA,eAAA,EACC,IACA,MACA,QAAQT,UAAU,WAClB,UACA,UACA,UACA,WAAWa,GAAGrB,QAAQ0C,MAAMxC,SAAS,GAEpCI,UAAAA;AAAAA,IACC,SAAA,oBAAC,SACC,EAAA,IAAImC,MAAMlB,WAAW,OAAO,GAC5B,OACA,WAAWvB,QAAQM,MAEtB,CAAA;AAAA,IAEAC,mCACE,eAAc,EAAA,IAAIkC,MAAMlB,WAAW,aAAa,GAC9ChB,UACH,aAAA;AAAA,wBAGD,OACC,EAAA,MAAK,cACL,cAAYO,WACZ,mBACEC,kBAAmBT,SAASmC,MAAMlB,WAAW,OAAO,KAAM7B,QAE5D,gBAAcc,WAAW,YAAY,OAAOd,QAC5C,qBAAmBc,WAAW,YAAYgC,iBAAiB9C,QAC3D,oBACE,CAACa,eAAekC,MAAMlB,WAAW,aAAa,GAAGP,eAAe,EAC7D2B,KAAK,GAAG,EACRC,UAAUlD,QAEf,WAAW2B,GAAGrB,QAAQ6C,OAAO;AAAA,MAC3B,CAAC7C,QAAQ8C,QAAQ,GAAGjC,gBAAgB;AAAA,MACpC,CAACb,QAAQ+C,UAAU,GAAGlC,gBAAgB;AAAA,MACtC,CAACb,QAAQgD,OAAO,GAAGxC,WAAW;AAAA,IAC/B,CAAA,GACD,GAAIW,QAEHc,UACH,iBAAA,CAAA;AAAA,IAECM,gBACC,oBAAC,eACC,EAAA,IAAIE,MAAMlB,WAAW,OAAO,GAC5B,eAAa,MACb,WAAWvB,QAAQiD,OAElBxC,UACH,eAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"RadioGroup.js","sources":["../../../../src/components/RadioGroup/RadioGroup.tsx"],"sourcesContent":["import {\n Children,\n useMemo,\n useCallback,\n cloneElement,\n forwardRef,\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 {\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 \"./RadioGroup.styles\";\n\nexport { staticClasses as radioGroupClasses };\n\nexport type HvRadioGroupClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvRadioGroupProps\n extends HvBaseProps<HTMLDivElement, \"onChange\"> {\n /**\n * The form element name.\n *\n * It is propagated to the children radio buttons, unless they already have one (which they shouldn't).\n */\n name?: string;\n /**\n * The value of the form element, represented in one of the child radio buttons values.\n *\n * When defined the radio button 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 radio buttons.\n */\n disabled?: boolean;\n /**\n * Indicates that the form element is not editable.\n * If `true` the state is propagated to the children radio buttons.\n */\n readOnly?: boolean;\n /**\n * Indicates that user input is required on the form element.\n * If `true` the state is propagated to the children radio buttons' input 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 `status` is \"invalid\".\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 radio buttons group's orientation is horizontal or vertical.\n *\n * Defaults to vertical.\n */\n orientation?: \"vertical\" | \"horizontal\";\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvRadioGroupClasses;\n}\n\nconst getValueFromSelectedChildren = (children: React.ReactNode) => {\n const childrenArray = Children.toArray(children);\n const childrenCount = childrenArray.length;\n for (let i = 0; i !== childrenCount; i += 1) {\n const child: any = childrenArray[i];\n\n const childIsControlled = child?.props?.checked !== undefined;\n const childIsSelected = childIsControlled\n ? child?.props?.checked\n : child?.props?.defaultChecked;\n\n if (childIsSelected) {\n return child?.props?.value;\n }\n }\n\n return null;\n};\n\n/**\n * A group of radio buttons.\n *\n * A radio group is a type of selection list that can only have a single entry checked at any one time.\n */\nexport const HvRadioGroup = forwardRef<HTMLDivElement, HvRadioGroupProps>(\n (props, ref) => {\n const {\n id,\n classes: classesProp,\n className,\n children,\n name,\n value: valueProp,\n defaultValue,\n label,\n description,\n status,\n statusMessage,\n required = false,\n readOnly = false,\n disabled = false,\n orientation = \"vertical\",\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-errormessage\": ariaErrorMessage,\n onChange,\n ...others\n } = useDefaultProps(\"HvRadioGroup\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const elementId = useUniqueId(id, \"hvradiogroup\");\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 onChildChangeInterceptor = useCallback(\n (\n childOnChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n checked: boolean,\n value: any\n ) => void,\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean,\n newValue: any\n ) => {\n childOnChange?.(event, isChecked, newValue);\n\n onChange?.(event, newValue);\n\n setValue(newValue);\n },\n [onChange, setValue]\n );\n\n const modifiedChildren = useMemo(() => {\n return Children.map(children, (child: any) => {\n const childValue = child?.props?.value ?? \"on\";\n\n const childIsSelected = childValue === value;\n\n return cloneElement(child, {\n checked: childIsSelected,\n name: child?.props?.name || name || elementId,\n onChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean,\n newValue: any\n ) =>\n onChildChangeInterceptor(\n child?.props?.onChange,\n event,\n isChecked,\n newValue\n ),\n inputProps: {\n ...child?.props?.inputProps,\n // Set the required attribute directly in the input\n // the radio form element context shouldn't be aware so the\n // label doesn't show redundant asterisk\n required,\n },\n disabled: disabled || child?.props?.disabled,\n readOnly: readOnly || child?.props?.readOnly,\n });\n });\n }, [\n children,\n disabled,\n elementId,\n name,\n onChildChangeInterceptor,\n readOnly,\n required,\n value,\n ]);\n\n // The error message area will only be created if:\n // - an external element that provides an error message isn't identified via aria-errormessage AND\n // - both status and statusMessage properties are being controlled OR\n // - status is uncontrolled and 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={status || \"standBy\"}\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=\"radiogroup\"\n aria-label={ariaLabel}\n aria-labelledby={\n ariaLabelledBy || (label && setId(elementId, \"label\")) || undefined\n }\n aria-invalid={status === \"invalid\" ? true : undefined}\n aria-errormessage={status === \"invalid\" ? errorMessageId : undefined}\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]: status === \"invalid\",\n })}\n {...others}\n >\n {modifiedChildren}\n </div>\n\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {statusMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n }\n);\n"],"names":["getValueFromSelectedChildren","children","childrenArray","Children","toArray","childrenCount","length","i","child","childIsControlled","props","checked","undefined","childIsSelected","defaultChecked","value","HvRadioGroup","forwardRef","ref","id","classes","classesProp","className","name","valueProp","defaultValue","label","description","status","statusMessage","required","readOnly","disabled","orientation","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaErrorMessage","onChange","others","useDefaultProps","cx","useClasses","elementId","useUniqueId","setValue","useControlled","onChildChangeInterceptor","useCallback","childOnChange","event","isChecked","newValue","modifiedChildren","useMemo","map","childValue","cloneElement","inputProps","canShowError","errorMessageId","setId","root","join","trim","group","vertical","horizontal","invalid","error"],"mappings":";;;;;;;;;;;;AAqGA,MAAMA,+BAA+BA,CAACC,aAA8B;;AAC5DC,QAAAA,gBAAgBC,SAASC,QAAQH,QAAQ;AAC/C,QAAMI,gBAAgBH,cAAcI;AACpC,WAASC,IAAI,GAAGA,MAAMF,eAAeE,KAAK,GAAG;AACrCC,UAAAA,QAAaN,cAAcK,CAAC;AAE5BE,UAAAA,sBAAoBD,oCAAOE,UAAPF,mBAAcG,aAAYC;AACpD,UAAMC,kBAAkBJ,qBACpBD,oCAAOE,UAAPF,mBAAcG,WACdH,oCAAOE,UAAPF,mBAAcM;AAElB,QAAID,iBAAiB;AACnB,cAAOL,oCAAOE,UAAPF,mBAAcO;AAAAA,IACvB;AAAA,EACF;AAEO,SAAA;AACT;AAOO,MAAMC,eAAeC,WAC1B,CAACP,OAAOQ,QAAQ;AACR,QAAA;AAAA,IACJC;AAAAA,IACAC,SAASC;AAAAA,IACTC;AAAAA,IACArB;AAAAA,IACAsB;AAAAA,IACAR,OAAOS;AAAAA,IACPC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,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oBAAC,eACC,EAAA,IAAIE,MAAMlB,WAAW,OAAO,GAC5B,eAAa,MACb,WAAWvB,QAAQiD,OAElBxC,UACH,eAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ,CACF;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import React__default, { useMemo, useRef, useEffect, useCallback } from "react";
|
|
2
|
+
import React__default, { forwardRef, useMemo, useRef, useEffect, useCallback } from "react";
|
|
3
|
+
import { useForkRef } from "@mui/material";
|
|
3
4
|
import { useDefaultProps } from "../../hooks/useDefaultProps.js";
|
|
4
5
|
import { useUniqueId } from "../../hooks/useUniqueId.js";
|
|
5
6
|
import { useControlled } from "../../hooks/useControlled.js";
|
|
@@ -22,7 +23,7 @@ const getValueFromSelectedChildren = (children, multiple) => {
|
|
|
22
23
|
}).filter((v) => v !== void 0);
|
|
23
24
|
return multiple ? selectedValues : selectedValues == null ? void 0 : selectedValues[0];
|
|
24
25
|
};
|
|
25
|
-
const HvSelectionList = (props) => {
|
|
26
|
+
const HvSelectionList = forwardRef((props, ref) => {
|
|
26
27
|
const {
|
|
27
28
|
id,
|
|
28
29
|
classes: classesProp,
|
|
@@ -73,11 +74,12 @@ const HvSelectionList = (props) => {
|
|
|
73
74
|
return [childValues, childSelectedState];
|
|
74
75
|
}, [children, multiple, value]);
|
|
75
76
|
const selectionAnchor = useRef(void 0);
|
|
76
|
-
const
|
|
77
|
+
const listRef = useRef(null);
|
|
78
|
+
const listForkedRef = useForkRef(ref, listRef);
|
|
77
79
|
useEffect(() => {
|
|
78
80
|
const handleMeta = (event) => {
|
|
79
81
|
const tempArray = [];
|
|
80
|
-
if (isKey(event, "ArrowUp") && event.shiftKey &&
|
|
82
|
+
if (isKey(event, "ArrowUp") && event.shiftKey && listRef.current.contains(event.target) || isKey(event, "ArrowDown") && event.shiftKey && listRef.current.contains(event.target)) {
|
|
81
83
|
selectedState.forEach((isSelected, i) => {
|
|
82
84
|
if (i === event.target.value - 1) {
|
|
83
85
|
if (!isSelected) {
|
|
@@ -140,10 +142,10 @@ const HvSelectionList = (props) => {
|
|
|
140
142
|
[classes.vertical]: orientation === "vertical",
|
|
141
143
|
[classes.horizontal]: orientation === "horizontal",
|
|
142
144
|
[classes.invalid]: validationState === "invalid"
|
|
143
|
-
}), ref:
|
|
145
|
+
}), ref: listForkedRef, ...others, children: modifiedChildren }),
|
|
144
146
|
canShowError && /* @__PURE__ */ jsx(HvWarningText, { id: setId(elementId, "error"), disableBorder: true, className: classes.error, children: validationMessage })
|
|
145
147
|
] });
|
|
146
|
-
};
|
|
148
|
+
});
|
|
147
149
|
export {
|
|
148
150
|
HvSelectionList,
|
|
149
151
|
staticClasses as selectionListClasses
|