@economic/taco 1.4.0 → 1.4.2
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/components/Accordion/Accordion.stories.d.ts +26 -0
- package/dist/components/Backdrop/Backdrop.stories.d.ts +7 -0
- package/dist/components/Badge/Badge.stories.d.ts +15 -0
- package/dist/components/Banner/Banner.stories.d.ts +23 -0
- package/dist/components/Button/Button.stories.d.ts +69 -0
- package/dist/components/Calendar/Calendar.stories.d.ts +13 -0
- package/dist/components/Card/Card.stories.d.ts +12 -0
- package/dist/components/Datepicker/Datepicker.stories.d.ts +43 -0
- package/dist/components/Dialog/Dialog.d.ts +1 -1
- package/dist/components/Dialog/Dialog.stories.d.ts +54 -0
- package/dist/components/Field/Field.stories.d.ts +14 -0
- package/dist/components/Form/Form.stories.d.ts +14 -0
- package/dist/components/Group/Group.stories.d.ts +23 -0
- package/dist/components/Hanger/Hanger.stories.d.ts +11 -0
- package/dist/components/HoverCard/HoverCard.stories.d.ts +28 -0
- package/dist/components/Icon/Icon.stories.d.ts +24 -0
- package/dist/components/IconButton/IconButton.stories.d.ts +45 -0
- package/dist/components/Input/Input.stories.d.ts +43 -0
- package/dist/components/Listbox/Listbox.stories.d.ts +44 -0
- package/dist/components/Menu/Menu.stories.d.ts +93 -0
- package/dist/components/Navigation/Navigation.stories.d.ts +7 -0
- package/dist/components/Pagination/Pagination.stories.d.ts +28 -0
- package/dist/components/Popover/Popover.stories.d.ts +14 -0
- package/dist/components/Progress/Progress.stories.d.ts +8 -0
- package/dist/components/RadioGroup/RadioGroup.stories.d.ts +49 -0
- package/dist/components/SearchInput/SearchInput.stories.d.ts +41 -0
- package/dist/components/Select/Select.stories.d.ts +35 -0
- package/dist/components/Spinner/Spinner.stories.d.ts +15 -0
- package/dist/components/Table/Table.stories.d.ts +32 -0
- package/dist/components/Table/util/rowIndexPath.d.ts +2 -2
- package/dist/components/Tabs/Tabs.stories.d.ts +19 -0
- package/dist/components/Textarea/Textarea.stories.d.ts +40 -0
- package/dist/components/Toast/Toast.stories.d.ts +12 -0
- package/dist/components/Tooltip/Tooltip.stories.d.ts +25 -0
- package/dist/components/Tour/Tour.stories.d.ts +11 -0
- package/dist/css/Typography.stories.d.ts +6 -0
- package/dist/esm/components/Dialog/Dialog.js.map +1 -1
- package/dist/esm/components/Listbox/useMultiListbox.js +1 -1
- package/dist/esm/components/Listbox/useMultiListbox.js.map +1 -1
- package/dist/esm/components/Navigation/Navigation.js +2 -1
- package/dist/esm/components/Navigation/Navigation.js.map +1 -1
- package/dist/esm/components/Table/hooks/plugins/useRowActions.js +1 -1
- package/dist/esm/components/Table/hooks/plugins/useRowActions.js.map +1 -1
- package/dist/esm/components/Table/hooks/useTableKeyboardNavigation.js +7 -1
- package/dist/esm/components/Table/hooks/useTableKeyboardNavigation.js.map +1 -1
- package/dist/esm/components/Table/util/rowIndexPath.js.map +1 -1
- package/dist/esm/components/Toast/Toaster.js.map +1 -1
- package/dist/esm/primitives/Button.js.map +1 -1
- package/dist/primitives/Button.d.ts +2 -1
- package/dist/taco.cjs.development.js +11 -4
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/package.json +3 -3
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Dialog.js","sources":["../../../../src/components/Dialog/Dialog.tsx"],"sourcesContent":["import * as React from 'react';\nimport * as DialogPrimitive from '@radix-ui/react-dialog';\nimport './Dialog.css';\nimport { DialogTriggerProps, Trigger } from './components/Trigger';\nimport {\n Content,\n Title,\n Footer,\n Close,\n DialogContentProps,\n DialogContentRenderProps,\n DialogContentDrawerRenderProps,\n DialogTitleProps,\n DialogFooterProps,\n DialogCloseProps,\n} from './components/Content';\nimport { DialogDrawerProps, DialogDrawerRenderProps, Drawer } from './components/Drawer';\nimport { DialogExtraProps, Extra } from './components/Extra';\nimport { DialogContext } from './Context';\nimport { DialogSize } from './types';\n\nexport {\n DialogCloseProps,\n DialogContentDrawerRenderProps,\n DialogContentProps,\n DialogContentRenderProps,\n DialogDrawerProps,\n DialogDrawerRenderProps,\n DialogFooterProps,\n DialogSize,\n DialogTitleProps,\n};\n\nexport type DialogTexts = {\n /**\n * Aria-label for close icon button in dialog.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n close: string;\n drag: string;\n};\n\nexport type DialogProps = {\n children: React.ReactNode | React.ReactNode[];\n /** When `true`, pressing escape will close the dialog */\n closeOnEscape?: boolean;\n /** Set whether the dialog is open by default or not, use when not providing a trigger */\n defaultOpen?: boolean;\n /** Allows dragging the dialog around the screen (window constrained) */\n draggable?: boolean;\n /** Handler called when dialog closes by user interaction */\n onClose?: () => void;\n /** Called when the dialog opens or closes, must be used in conjunction with open */\n onChange?: (open: boolean) => void;\n /** Control the open state of the dialog from outside the component */\n open?: boolean;\n /** Shows the close icon button of the dialog */\n showCloseButton?: boolean;\n /** Size of the dialog. This is the recommended way to set a size for dialog component. */\n size?: DialogSize;\n /** A trigger to be used for the dialog, should not be set if `children` already contains a trigger */\n trigger?: JSX.Element;\n};\n\nconst useSeparatedChildren = initialChildren => {\n return React.useMemo(() => {\n const children: any[] = [];\n let drawer;\n let extra;\n\n React.Children.toArray(initialChildren).forEach((child: any) => {\n if (child.type?.displayName === Drawer.displayName) {\n drawer = child;\n } else if (child.type?.displayName === Extra.displayName) {\n extra = child;\n } else {\n children.push(child);\n }\n });\n\n return [children, drawer, extra];\n }, [initialChildren]);\n};\n\nexport type ForwardedDialogWithStatics = React.ForwardRefExoticComponent<DialogProps & React.RefAttributes<HTMLElement>> & {\n Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>;\n Content: React.ForwardRefExoticComponent<DialogContentProps & React.RefAttributes<HTMLDivElement>>;\n Title: React.ForwardRefExoticComponent<DialogTitleProps & React.RefAttributes<HTMLHeadingElement>>;\n Footer: React.ForwardRefExoticComponent<DialogFooterProps & React.RefAttributes<HTMLDivElement>>;\n Extra: React.ForwardRefExoticComponent<DialogExtraProps & React.RefAttributes<HTMLDivElement>>;\n Drawer: React.ForwardRefExoticComponent<DialogDrawerProps & React.RefAttributes<HTMLDivElement>>;\n Close: React.ForwardRefExoticComponent<DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;\n};\n\nexport const Dialog = React.forwardRef(function Dialog(props: DialogProps, ref: React.Ref<HTMLElement>) {\n const {\n children: initialChildren,\n closeOnEscape = true,\n defaultOpen,\n draggable = false,\n onChange,\n onClose,\n open,\n showCloseButton = true,\n size = 'sm',\n trigger,\n ...otherProps\n } = props;\n const [children, drawer, extra] = useSeparatedChildren(initialChildren);\n const [drawerOpen, setDrawerOpen] = React.useState(false);\n\n const context = React.useMemo(\n () => ({\n closeOnEscape,\n draggable,\n drawer: {\n open: drawerOpen,\n toggle: () => setDrawerOpen(isDrawerOpen => !isDrawerOpen),\n },\n elements: {\n drawer,\n extra,\n },\n onClose,\n props: otherProps,\n showCloseButton,\n size,\n ref,\n }),\n [closeOnEscape, drawerOpen, draggable, drawer, extra, open, otherProps, showCloseButton]\n );\n\n return (\n <DialogContext.Provider value={context}>\n <DialogPrimitive.Root defaultOpen={defaultOpen} open={open} onOpenChange={onChange}>\n {trigger && <Trigger>{trigger}</Trigger>}\n {children}\n </DialogPrimitive.Root>\n </DialogContext.Provider>\n );\n}) as ForwardedDialogWithStatics;\n\nDialog.Trigger = Trigger;\nDialog.Content = Content;\nDialog.Title = Title;\nDialog.Footer = Footer;\nDialog.Extra = Extra;\nDialog.Drawer = Drawer;\nDialog.Close = Close;\n"],"names":["useSeparatedChildren","initialChildren","React","children","drawer","extra","toArray","forEach","child","type","displayName","Drawer","Extra","push","Dialog","props","ref","closeOnEscape","defaultOpen","draggable","onChange","onClose","open","showCloseButton","size","trigger","otherProps","drawerOpen","setDrawerOpen","context","toggle","isDrawerOpen","elements","DialogContext","Provider","value","DialogPrimitive","onOpenChange","Trigger","Content","Title","Footer","Close"],"mappings":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AAMF,aAAa,CAACG,YAAY,IAAI,CAACA,YAAlB;KAL5B;IAOHC,QAAQ,EAAE;MACN5B,MADM;MAENC;KATD;IAWHgB,OAXG;IAYHN,KAAK,EAAEW,UAZJ;IAaHH,eAbG;IAcHC,IAdG;IAeHR;GAfJ,CADY,EAkBZ,CAACC,aAAD,EAAgBU,UAAhB,EAA4BR,SAA5B,EAAuCf,MAAvC,EAA+CC,KAA/C,EAAsDiB,IAAtD,EAA4DI,UAA5D,EAAwEH,eAAxE,CAlBY,CAAhB;EAqBA,OACIrB,aAAA,CAAC+B,aAAa,CAACC,QAAf;IAAwBC,KAAK,EAAEN;GAA/B,EACI3B,aAAA,CAACkC,IAAD;IAAsBlB,WAAW,EAAEA;IAAaI,IAAI,EAAEA;IAAMe,YAAY,EAAEjB;GAA1E,EACKK,OAAO,IAAIvB,aAAA,CAACoC,OAAD,MAAA,EAAUb,OAAV,CADhB,EAEKtB,QAFL,CADJ,CADJ;AAQH,CA9CqB;AAgDtBW,MAAM,CAACwB,OAAP,GAAiBA,OAAjB;AACAxB,MAAM,CAACyB,OAAP,GAAiBA,OAAjB;AACAzB,MAAM,CAAC0B,KAAP,GAAeA,KAAf;AACA1B,MAAM,CAAC2B,MAAP,GAAgBA,MAAhB;AACA3B,MAAM,CAACF,KAAP,GAAeA,KAAf;AACAE,MAAM,CAACH,MAAP,GAAgBA,MAAhB;AACAG,MAAM,CAAC4B,KAAP,GAAeA,KAAf;;;;"}
|
1
|
+
{"version":3,"file":"Dialog.js","sources":["../../../../src/components/Dialog/Dialog.tsx"],"sourcesContent":["import * as React from 'react';\nimport * as DialogPrimitive from '@radix-ui/react-dialog';\nimport './Dialog.css';\nimport { DialogTriggerProps, Trigger } from './components/Trigger';\nimport {\n Content,\n Title,\n Footer,\n Close,\n DialogContentProps,\n DialogContentRenderProps,\n DialogContentDrawerRenderProps,\n DialogTitleProps,\n DialogFooterProps,\n DialogCloseProps,\n} from './components/Content';\nimport { DialogDrawerProps, DialogDrawerRenderProps, Drawer } from './components/Drawer';\nimport { DialogExtraProps, Extra } from './components/Extra';\nimport { DialogContext } from './Context';\nimport { DialogSize } from './types';\n\nexport type {\n DialogCloseProps,\n DialogContentDrawerRenderProps,\n DialogContentProps,\n DialogContentRenderProps,\n DialogDrawerProps,\n DialogDrawerRenderProps,\n DialogFooterProps,\n DialogSize,\n DialogTitleProps,\n};\n\nexport type DialogTexts = {\n /**\n * Aria-label for close icon button in dialog.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n close: string;\n drag: string;\n};\n\nexport type DialogProps = {\n children: React.ReactNode | React.ReactNode[];\n /** When `true`, pressing escape will close the dialog */\n closeOnEscape?: boolean;\n /** Set whether the dialog is open by default or not, use when not providing a trigger */\n defaultOpen?: boolean;\n /** Allows dragging the dialog around the screen (window constrained) */\n draggable?: boolean;\n /** Handler called when dialog closes by user interaction */\n onClose?: () => void;\n /** Called when the dialog opens or closes, must be used in conjunction with open */\n onChange?: (open: boolean) => void;\n /** Control the open state of the dialog from outside the component */\n open?: boolean;\n /** Shows the close icon button of the dialog */\n showCloseButton?: boolean;\n /** Size of the dialog. This is the recommended way to set a size for dialog component. */\n size?: DialogSize;\n /** A trigger to be used for the dialog, should not be set if `children` already contains a trigger */\n trigger?: JSX.Element;\n};\n\nconst useSeparatedChildren = initialChildren => {\n return React.useMemo(() => {\n const children: any[] = [];\n let drawer;\n let extra;\n\n React.Children.toArray(initialChildren).forEach((child: any) => {\n if (child.type?.displayName === Drawer.displayName) {\n drawer = child;\n } else if (child.type?.displayName === Extra.displayName) {\n extra = child;\n } else {\n children.push(child);\n }\n });\n\n return [children, drawer, extra];\n }, [initialChildren]);\n};\n\nexport type ForwardedDialogWithStatics = React.ForwardRefExoticComponent<DialogProps & React.RefAttributes<HTMLElement>> & {\n Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>;\n Content: React.ForwardRefExoticComponent<DialogContentProps & React.RefAttributes<HTMLDivElement>>;\n Title: React.ForwardRefExoticComponent<DialogTitleProps & React.RefAttributes<HTMLHeadingElement>>;\n Footer: React.ForwardRefExoticComponent<DialogFooterProps & React.RefAttributes<HTMLDivElement>>;\n Extra: React.ForwardRefExoticComponent<DialogExtraProps & React.RefAttributes<HTMLDivElement>>;\n Drawer: React.ForwardRefExoticComponent<DialogDrawerProps & React.RefAttributes<HTMLDivElement>>;\n Close: React.ForwardRefExoticComponent<DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;\n};\n\nexport const Dialog = React.forwardRef(function Dialog(props: DialogProps, ref: React.Ref<HTMLElement>) {\n const {\n children: initialChildren,\n closeOnEscape = true,\n defaultOpen,\n draggable = false,\n onChange,\n onClose,\n open,\n showCloseButton = true,\n size = 'sm',\n trigger,\n ...otherProps\n } = props;\n const [children, drawer, extra] = useSeparatedChildren(initialChildren);\n const [drawerOpen, setDrawerOpen] = React.useState(false);\n\n const context = React.useMemo(\n () => ({\n closeOnEscape,\n draggable,\n drawer: {\n open: drawerOpen,\n toggle: () => setDrawerOpen(isDrawerOpen => !isDrawerOpen),\n },\n elements: {\n drawer,\n extra,\n },\n onClose,\n props: otherProps,\n showCloseButton,\n size,\n ref,\n }),\n [closeOnEscape, drawerOpen, draggable, drawer, extra, open, otherProps, showCloseButton]\n );\n\n return (\n <DialogContext.Provider value={context}>\n <DialogPrimitive.Root defaultOpen={defaultOpen} open={open} onOpenChange={onChange}>\n {trigger && <Trigger>{trigger}</Trigger>}\n {children}\n </DialogPrimitive.Root>\n </DialogContext.Provider>\n );\n}) as ForwardedDialogWithStatics;\n\nDialog.Trigger = Trigger;\nDialog.Content = Content;\nDialog.Title = Title;\nDialog.Footer = Footer;\nDialog.Extra = Extra;\nDialog.Drawer = Drawer;\nDialog.Close = Close;\n"],"names":["useSeparatedChildren","initialChildren","React","children","drawer","extra","toArray","forEach","child","type","displayName","Drawer","Extra","push","Dialog","props","ref","closeOnEscape","defaultOpen","draggable","onChange","onClose","open","showCloseButton","size","trigger","otherProps","drawerOpen","setDrawerOpen","context","toggle","isDrawerOpen","elements","DialogContext","Provider","value","DialogPrimitive","onOpenChange","Trigger","Content","Title","Footer","Close"],"mappings":";;;;;;;;AAgEA,MAAMA,oBAAoB,GAAGC,eAAe;EACxC,OAAOC,OAAA,CAAc;IACjB,MAAMC,QAAQ,GAAU,EAAxB;IACA,IAAIC,MAAJ;IACA,IAAIC,KAAJ;IAEAH,QAAA,CAAeI,OAAf,CAAuBL,eAAvB,EAAwCM,OAAxC,CAAiDC,KAAD;;;MAC5C,IAAI,gBAAAA,KAAK,CAACC,IAAN,4DAAYC,WAAZ,MAA4BC,MAAM,CAACD,WAAvC,EAAoD;QAChDN,MAAM,GAAGI,KAAT;OADJ,MAEO,IAAI,iBAAAA,KAAK,CAACC,IAAN,8DAAYC,WAAZ,MAA4BE,KAAK,CAACF,WAAtC,EAAmD;QACtDL,KAAK,GAAGG,KAAR;OADG,MAEA;QACHL,QAAQ,CAACU,IAAT,CAAcL,KAAd;;KANR;IAUA,OAAO,CAACL,QAAD,EAAWC,MAAX,EAAmBC,KAAnB,CAAP;GAfG,EAgBJ,CAACJ,eAAD,CAhBI,CAAP;AAiBH,CAlBD;;MA8Baa,MAAM,gBAAGZ,UAAA,CAAiB,SAASY,MAAT,CAAgBC,KAAhB,EAAoCC,GAApC;EACnC,MAAM;IACFb,QAAQ,EAAEF,eADR;IAEFgB,aAAa,GAAG,IAFd;IAGFC,WAHE;IAIFC,SAAS,GAAG,KAJV;IAKFC,QALE;IAMFC,OANE;IAOFC,IAPE;IAQFC,eAAe,GAAG,IARhB;IASFC,IAAI,GAAG,IATL;IAUFC,OAVE;IAWF,GAAGC;MACHX,KAZJ;EAaA,MAAM,CAACZ,QAAD,EAAWC,MAAX,EAAmBC,KAAnB,IAA4BL,oBAAoB,CAACC,eAAD,CAAtD;EACA,MAAM,CAAC0B,UAAD,EAAaC,aAAb,IAA8B1B,QAAA,CAAe,KAAf,CAApC;EAEA,MAAM2B,OAAO,GAAG3B,OAAA,CACZ,OAAO;IACHe,aADG;IAEHE,SAFG;IAGHf,MAAM,EAAE;MACJkB,IAAI,EAAEK,UADF;MAEJG,MAAM,EAAE,MAAMF,aAAa,CAACG,YAAY,IAAI,CAACA,YAAlB;KAL5B;IAOHC,QAAQ,EAAE;MACN5B,MADM;MAENC;KATD;IAWHgB,OAXG;IAYHN,KAAK,EAAEW,UAZJ;IAaHH,eAbG;IAcHC,IAdG;IAeHR;GAfJ,CADY,EAkBZ,CAACC,aAAD,EAAgBU,UAAhB,EAA4BR,SAA5B,EAAuCf,MAAvC,EAA+CC,KAA/C,EAAsDiB,IAAtD,EAA4DI,UAA5D,EAAwEH,eAAxE,CAlBY,CAAhB;EAqBA,OACIrB,aAAA,CAAC+B,aAAa,CAACC,QAAf;IAAwBC,KAAK,EAAEN;GAA/B,EACI3B,aAAA,CAACkC,IAAD;IAAsBlB,WAAW,EAAEA;IAAaI,IAAI,EAAEA;IAAMe,YAAY,EAAEjB;GAA1E,EACKK,OAAO,IAAIvB,aAAA,CAACoC,OAAD,MAAA,EAAUb,OAAV,CADhB,EAEKtB,QAFL,CADJ,CADJ;AAQH,CA9CqB;AAgDtBW,MAAM,CAACwB,OAAP,GAAiBA,OAAjB;AACAxB,MAAM,CAACyB,OAAP,GAAiBA,OAAjB;AACAzB,MAAM,CAAC0B,KAAP,GAAeA,KAAf;AACA1B,MAAM,CAAC2B,MAAP,GAAgBA,MAAhB;AACA3B,MAAM,CAACF,KAAP,GAAeA,KAAf;AACAE,MAAM,CAACH,MAAP,GAAgBA,MAAhB;AACAG,MAAM,CAAC4B,KAAP,GAAeA,KAAf;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useMultiListbox.js","sources":["../../../../src/components/Listbox/useMultiListbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { useLocalization } from '../Provider/Provider';\nimport { ListboxProps } from './Listbox';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { setInputValueByRef, getIndexFromValue, getSelectedIndexesFromValue, findByValue, getActiveDescendant } from './util';\nimport { ScrollableListProps, ScrollableListItem, ScrollableListItemValue } from './ScrollableList';\nimport { useTypeahead } from './useTypeahead';\n\ntype useListbox = {\n list: ScrollableListProps;\n input: Omit<React.HTMLAttributes<HTMLInputElement>, 'defaultValue'>;\n};\n\nexport const useMultiListbox = (\n {\n data: externalData = [],\n defaultValue,\n disabled,\n emptyValue: _,\n id: nativeId,\n name,\n onClick,\n onChange,\n onFocus,\n onKeyDown,\n value,\n ...otherProps\n }: ListboxProps,\n ref: React.Ref<HTMLInputElement>\n): useListbox => {\n const { texts } = useLocalization();\n const id = React.useMemo(() => nativeId || uuid(), [nativeId]);\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\n const data = React.useMemo(() => {\n return [{ text: texts.listbox.allOption, value: '#ALL-OPTIONS#' }, ...externalData];\n }, [externalData]);\n const [currentIndex, setCurrentIndex] = React.useState(getIndexFromValue(data, value) || 0);\n const [allOptionsSelected, setAllOptionsSelected] = React.useState(false);\n const { getNextIndex } = useTypeahead({ data, currentIndex });\n const [selectedIndexes, setSelectedIndexes] = React.useState(getSelectedIndexesFromValue(data, value));\n\n React.useEffect(() => {\n if (defaultValue && !value) {\n setInputValueByRef(inputRef.current, defaultValue.toString());\n }\n }, []);\n\n React.useEffect(() => {\n const selectableItemsCount = data.filter(item => !item.disabled).length - 1;\n\n if (selectableItemsCount === selectedIndexes.length) {\n setAllOptionsSelected(true);\n } else {\n setAllOptionsSelected(false);\n }\n }, [selectedIndexes, data]);\n\n const setInputValueByIndex = (index: number | undefined): void => {\n if (index !== undefined) {\n const option = data[index];\n\n if (option && !option.disabled) {\n let newInputValue: ScrollableListItemValue = '';\n const currentInputValue = inputRef.current?.value;\n const currentValuesArray = currentInputValue?.split(',') || [];\n const optionAlreadySelected = currentValuesArray.findIndex(val => val === String(option.value)) !== -1;\n\n // Handling the select_all option\n if (option.value === '#ALL-OPTIONS#') {\n if (!allOptionsSelected) {\n newInputValue = data\n .filter((option, index) => index !== 0 && !option.disabled)\n .map(option => option.value)\n .join(',');\n } else {\n newInputValue = '';\n }\n } else {\n // Handling rest options\n if (optionAlreadySelected) {\n newInputValue = currentValuesArray.filter(val => val !== String(option.value)).join(',');\n } else {\n newInputValue = currentInputValue ? `${currentInputValue},${option.value}` : option.value;\n }\n }\n\n setInputValueByRef(inputRef.current, newInputValue);\n }\n }\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>, index: number): void => {\n event.preventDefault();\n\n if (!data[index].disabled) {\n setCurrentIndex(index);\n setInputValueByIndex(index);\n }\n\n if (onClick) {\n onClick(event);\n }\n };\n\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>, index: number): void => {\n const charKey = event.key;\n\n // event.key always returns the whole string (String.fromCharCode(event.keyCode) does not)\n // We need to filter out only alphabetical or numeric letters, that's why that condition has been changed\n if (charKey.length === 1 && /(\\w)/g.test(charKey)) {\n const nextIndex = getNextIndex(charKey);\n\n if (nextIndex > -1 && nextIndex !== currentIndex) {\n setCurrentIndex(nextIndex);\n }\n return;\n }\n\n switch (event.key) {\n case ' ': {\n event.preventDefault();\n setInputValueByIndex(index);\n break;\n }\n\n case 'Enter': {\n setInputValueByIndex(index);\n break;\n }\n\n default:\n }\n setCurrentIndex(index);\n\n if (onKeyDown) {\n event.persist();\n onKeyDown(event);\n }\n };\n\n const handleListboxFocus = (event: React.FocusEvent<HTMLElement>): void => {\n if (onFocus) {\n event.persist();\n onFocus(event);\n }\n };\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n event.persist();\n\n setSelectedIndexes(getSelectedIndexesFromValue(data, event.target.value));\n\n if (onChange) {\n const detail: ScrollableListItem[] = [];\n const valuesArray = event.target.value.split(',');\n\n valuesArray.forEach(val => {\n const item = findByValue(data, val);\n if (item) {\n detail.push(item);\n }\n });\n (event as any).detail = detail;\n\n onChange(event);\n }\n };\n\n const list = {\n ...otherProps,\n 'aria-activedescendant': getActiveDescendant(data, currentIndex, id),\n 'aria-multiselectable': true,\n data,\n disabled,\n id,\n onChange: () => null,\n onClick: handleListboxClick,\n onFocus: handleListboxFocus,\n onKeyDown: handleListboxKeyDown,\n scrollOnFocus: false,\n tabIndex: disabled ? -1 : otherProps.tabIndex ? otherProps.tabIndex : 0,\n value: currentIndex,\n selectedIndexes,\n multiselect: true,\n allOptionsSelected,\n };\n\n const input = {\n name,\n onChange: handleInputChange,\n ref: inputRef,\n tabIndex: -1,\n value: value ?? '',\n };\n\n return { list, input };\n};\n"],"names":["useMultiListbox","data","externalData","defaultValue","disabled","emptyValue","_","id","nativeId","name","onClick","onChange","onFocus","onKeyDown","value","otherProps","ref","texts","useLocalization","React","uuid","inputRef","useProxiedRef","text","listbox","allOption","currentIndex","setCurrentIndex","getIndexFromValue","allOptionsSelected","setAllOptionsSelected","getNextIndex","useTypeahead","selectedIndexes","setSelectedIndexes","getSelectedIndexesFromValue","setInputValueByRef","current","toString","selectableItemsCount","filter","item","length","setInputValueByIndex","index","undefined","option","newInputValue","currentInputValue","currentValuesArray","split","optionAlreadySelected","findIndex","val","String","map","join","handleListboxClick","event","preventDefault","handleListboxKeyDown","charKey","key","test","nextIndex","persist","handleListboxFocus","handleInputChange","target","detail","valuesArray","forEach","findByValue","push","list","getActiveDescendant","scrollOnFocus","tabIndex","multiselect","input"],"mappings":";;;;;;;MAcaA,eAAe,GAAG,CAC3B;EACIC,IAAI,EAAEC,YAAY,GAAG,EADzB;EAEIC,YAFJ;EAGIC,QAHJ;EAIIC,UAAU,EAAEC,CAJhB;EAKIC,EAAE,EAAEC,QALR;EAMIC,IANJ;EAOIC,OAPJ;EAQIC,QARJ;EASIC,OATJ;EAUIC,SAVJ;EAWIC,KAXJ;EAYI,GAAGC;AAZP,CAD2B,EAe3BC,GAf2B;EAiB3B,MAAM;IAAEC;MAAUC,eAAe,EAAjC;EACA,MAAMX,EAAE,GAAGY,OAAA,CAAc,MAAMX,QAAQ,IAAIY,EAAI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GAAW;GALpB;EAQA,OAAO;IAAE4D,IAAF;IAAQK;GAAf;AACH;;;;"}
|
1
|
+
{"version":3,"file":"useMultiListbox.js","sources":["../../../../src/components/Listbox/useMultiListbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { useLocalization } from '../Provider/Provider';\nimport { ListboxProps } from './Listbox';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { setInputValueByRef, getIndexFromValue, getSelectedIndexesFromValue, findByValue, getActiveDescendant } from './util';\nimport { ScrollableListProps, ScrollableListItem, ScrollableListItemValue } from './ScrollableList';\nimport { useTypeahead } from './useTypeahead';\n\ntype useListbox = {\n list: ScrollableListProps;\n input: Omit<React.HTMLAttributes<HTMLInputElement>, 'defaultValue'>;\n};\n\nexport const useMultiListbox = (\n {\n data: externalData = [],\n defaultValue,\n disabled,\n emptyValue: _,\n id: nativeId,\n name,\n onClick,\n onChange,\n onFocus,\n onKeyDown,\n value,\n ...otherProps\n }: ListboxProps,\n ref: React.Ref<HTMLInputElement>\n): useListbox => {\n const { texts } = useLocalization();\n const id = React.useMemo(() => nativeId || uuid(), [nativeId]);\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\n const data = React.useMemo(() => {\n return [{ text: texts.listbox.allOption, value: '#ALL-OPTIONS#' }, ...externalData];\n }, [externalData]);\n const [currentIndex, setCurrentIndex] = React.useState(getIndexFromValue(data, value) || 0);\n const [allOptionsSelected, setAllOptionsSelected] = React.useState(false);\n const { getNextIndex } = useTypeahead({ data, currentIndex });\n const [selectedIndexes, setSelectedIndexes] = React.useState(getSelectedIndexesFromValue(data, value));\n\n React.useEffect(() => {\n if (defaultValue && !value) {\n setInputValueByRef(inputRef.current, defaultValue.toString());\n }\n }, []);\n\n React.useEffect(() => {\n const selectableItemsCount = data.filter(item => !item.disabled).length - 1;\n\n if (selectableItemsCount === selectedIndexes.length) {\n setAllOptionsSelected(true);\n } else {\n setAllOptionsSelected(false);\n }\n }, [selectedIndexes, data]);\n\n const setInputValueByIndex = (index: number | undefined): void => {\n if (index !== undefined) {\n const option = data[index];\n\n if (option && !option.disabled) {\n let newInputValue: ScrollableListItemValue = '';\n const currentInputValue = inputRef.current?.value;\n const currentValuesArray = currentInputValue?.split(',') || [];\n const optionAlreadySelected = currentValuesArray.findIndex(val => val === String(option.value)) !== -1;\n\n // Handling the select_all option\n if (option.value === '#ALL-OPTIONS#') {\n if (!allOptionsSelected) {\n newInputValue = data\n .filter((option, index) => index !== 0 && !option.disabled)\n .map(option => option.value)\n .join(',');\n } else {\n newInputValue = '';\n }\n } else {\n // Handling rest options\n if (optionAlreadySelected) {\n newInputValue = currentValuesArray.filter(val => val !== String(option.value)).join(',');\n } else {\n newInputValue = currentInputValue ? `${currentInputValue},${option.value}` : option.value;\n }\n }\n\n setInputValueByRef(inputRef.current, newInputValue);\n }\n }\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>, index: number): void => {\n event.preventDefault();\n\n if (!data[index].disabled) {\n setCurrentIndex(index);\n setInputValueByIndex(index);\n }\n\n if (onClick) {\n onClick(event);\n }\n };\n\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>, index?: number): void => {\n const charKey = event.key;\n\n // event.key always returns the whole string (String.fromCharCode(event.keyCode) does not)\n // We need to filter out only alphabetical or numeric letters, that's why that condition has been changed\n if (charKey.length === 1 && /(\\w)/g.test(charKey)) {\n const nextIndex = getNextIndex(charKey);\n\n if (nextIndex > -1 && nextIndex !== currentIndex) {\n setCurrentIndex(nextIndex);\n }\n return;\n }\n\n switch (event.key) {\n case ' ': {\n event.preventDefault();\n setInputValueByIndex(index);\n break;\n }\n\n case 'Enter': {\n setInputValueByIndex(index);\n break;\n }\n\n default:\n }\n setCurrentIndex(index !== undefined ? index : 0);\n\n if (onKeyDown) {\n event.persist();\n onKeyDown(event);\n }\n };\n\n const handleListboxFocus = (event: React.FocusEvent<HTMLElement>): void => {\n if (onFocus) {\n event.persist();\n onFocus(event);\n }\n };\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n event.persist();\n\n setSelectedIndexes(getSelectedIndexesFromValue(data, event.target.value));\n\n if (onChange) {\n const detail: ScrollableListItem[] = [];\n const valuesArray = event.target.value.split(',');\n\n valuesArray.forEach(val => {\n const item = findByValue(data, val);\n if (item) {\n detail.push(item);\n }\n });\n (event as any).detail = detail;\n\n onChange(event);\n }\n };\n\n const list = {\n ...otherProps,\n 'aria-activedescendant': getActiveDescendant(data, currentIndex, id),\n 'aria-multiselectable': true,\n data,\n disabled,\n id,\n onChange: () => null,\n onClick: handleListboxClick,\n onFocus: handleListboxFocus,\n onKeyDown: handleListboxKeyDown,\n scrollOnFocus: false,\n tabIndex: disabled ? -1 : otherProps.tabIndex ? otherProps.tabIndex : 0,\n value: currentIndex,\n selectedIndexes,\n multiselect: true,\n allOptionsSelected,\n };\n\n const input = {\n name,\n onChange: handleInputChange,\n ref: inputRef,\n tabIndex: -1,\n value: value ?? '',\n };\n\n return { list, input };\n};\n"],"names":["useMultiListbox","data","externalData","defaultValue","disabled","emptyValue","_","id","nativeId","name","onClick","onChange","onFocus","onKeyDown","value","otherProps","ref","texts","useLocalization","React","uuid","inputRef","useProxiedRef","text","listbox","allOption","currentIndex","setCurrentIndex","getIndexFromValue","allOptionsSelected","setAllOptionsSelected","getNextIndex","useTypeahead","selectedIndexes","setSelectedIndexes","getSelectedIndexesFromValue","setInputValueByRef","current","toString","selectableItemsCount","filter","item","length","setInputValueByIndex","index","undefined","option","newInputValue","currentInputValue","currentValuesArray","split","optionAlreadySelected","findIndex","val","String","map","join","handleListboxClick","event","preventDefault","handleListboxKeyDown","charKey","key","test","nextIndex","persist","handleListboxFocus","handleInputChange","target","detail","valuesArray","forEach","findByValue","push","list","getActiveDescendant","scrollOnFocus","tabIndex","multiselect","input"],"mappings":";;;;;;;MAcaA,eAAe,GAAG,CAC3B;EACIC,IAAI,EAAEC,YAAY,GAAG,EADzB;EAEIC,YAFJ;EAGI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U,CAAC8D,QAAX,GAAsB9D,UAAU,CAAC8D,QAAjC,GAA4C,CAZ7D;IAaT/D,KAAK,EAAEY,YAbE;IAcTO,eAdS;IAeT6C,WAAW,EAAE,IAfJ;IAgBTjD;GAhBJ;EAmBA,MAAMkD,KAAK,GAAG;IACVtE,IADU;IAEVE,QAAQ,EAAEwD,iBAFA;IAGVnD,GAAG,EAAEK,QAHK;IAIVwD,QAAQ,EAAE,CAAC,CAJD;IAKV/D,KAAK,EAAEA,KAAF,aAAEA,KAAF,cAAEA,KAAF,GAAW;GALpB;EAQA,OAAO;IAAE4D,IAAF;IAAQK;GAAf;AACH;;;;"}
|
@@ -81,7 +81,8 @@ const MenuGroup = /*#__PURE__*/React__default.forwardRef(function MenuGroup(prop
|
|
81
81
|
const Menu = /*#__PURE__*/React__default.forwardRef(function Menu(props, ref) {
|
82
82
|
const scrollableAreas = React__default.useMemo(() => {
|
83
83
|
const scrollableAreas = [];
|
84
|
-
React__default.Children.toArray(props.children).filter(child => !!child)
|
84
|
+
const children = React__default.Children.toArray(props.children).filter(child => !!child);
|
85
|
+
children.forEach(child => {
|
85
86
|
if (child.props.fixed) {
|
86
87
|
scrollableAreas.push(child);
|
87
88
|
} else {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Navigation.js","sources":["../../../../src/components/Navigation/Navigation.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { TreeviewProps, Treeview, TreeviewGroupProps, TreeviewItemProps } from '../Treeview/Treeview';\nimport { Icon } from '../Icon/Icon';\nimport { useDropTarget } from '../../utils/hooks/useDropTarget';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport './Navigation.css';\n\n// Item\nexport type NavigationItemProps = Omit<TreeviewItemProps, 'prefix'> & {\n /** Change the style to indicate the link is selected */\n active?: boolean;\n /** Handler to be used when dropping a dragged element over the navigation link */\n onDrop?: React.DragEventHandler;\n /**\n * Small amount of information placed next to the text of the link.\n * This can be any valid react element, for e.g. a `span`.\n * Should be used to indicate a relevant information of the link,\n * for e.g. the number of unread notifications\n */\n postfix?: React.ReactNode;\n /**\n * Small amount of information placed before the text of the link.\n * This can be any valid react element, for e.g. a `span`.\n * Should be used to indicate a feedback for user,\n * for e.g. display some sort of visual informational state or a relevant icon.\n */\n prefix?: React.ReactNode;\n /** Target of the link */\n target?: string;\n};\n\nconst Item = React.forwardRef(function Item(props: NavigationItemProps, ref: React.Ref<HTMLAnchorElement>) {\n const { active, children, onDrop, postfix, prefix, role, ...otherProps } = props;\n const proxyRef = useProxiedRef<HTMLAnchorElement>(ref);\n const [isDraggedOver, dropTargetProps] = useDropTarget(onDrop);\n const isTreeitem = role === 'treeitem';\n const className = cn(\n 'yt-navigation__item cursor-pointer',\n {\n 'w-full mb-px py-1 px-3 flex items-center hover:bg-grey-dark': isTreeitem,\n 'bg-white w-full h-10 px-3 flex-shrink-0 flex items-center justify-between cursor-pointer': !isTreeitem,\n 'yt-navigation__item--active': active && !isDraggedOver,\n 'bg-grey-dark': isTreeitem && active && !isDraggedOver,\n 'yt-navigation__item--dropping bg-blue': isDraggedOver,\n },\n props.className\n );\n\n const handleClick = (event: React.MouseEvent<HTMLSpanElement>): void => {\n if (event.target instanceof HTMLAnchorElement || event.target instanceof HTMLButtonElement) {\n return;\n }\n\n if (proxyRef.current) {\n proxyRef.current.click();\n }\n };\n\n return (\n <span {...dropTargetProps} className={className} onClick={handleClick} role={role}>\n {prefix && <span className=\"yt-navigation__item__prefix flex items-center\">{prefix}</span>}\n <a {...otherProps} className=\"block flex-grow truncate\" ref={proxyRef}>\n {children}\n </a>\n {postfix && <span className=\"yt-navigation__item__postfix ml-1\">{postfix}</span>}\n </span>\n );\n});\n\n// Panel\nexport type NavigationPanelProps = React.HTMLAttributes<HTMLDivElement>;\n\nconst Panel = React.forwardRef(function Panel(props: NavigationPanelProps, ref: React.Ref<HTMLDivElement>) {\n return <div {...props} className={cn('w-full bg-white p-3', props.className)} ref={ref} />;\n});\n\n// Group\nexport type NavigationMenuGroupProps = TreeviewGroupProps;\n\nconst MenuGroup = React.forwardRef(function MenuGroup(props: NavigationMenuGroupProps, ref: React.Ref<HTMLDivElement>) {\n const className = cn(\n 'flex-shrink-0 space-y-1 outline-none',\n {\n 'bg-white pb-2': props.fixed,\n },\n props.className\n );\n const title = (expanded: boolean): JSX.Element => {\n const className = cn('bg-white h-10 pl-3 pr-1 flex items-center justify-between w-full', {\n 'mb-1': expanded,\n 'cursor-pointer hover:text-blue': !props.fixed,\n });\n\n return (\n <span className={className}>\n {typeof props.title === 'function' ? props.title(expanded) : props.title}\n {!props.fixed && <Icon name={expanded ? 'chevron-up' : 'chevron-down'} />}\n </span>\n );\n };\n\n return <Treeview.Group {...props} className={className} title={title} ref={ref} />;\n});\n\n// Menu\nexport type NavigationMenuProps = React.PropsWithChildren<TreeviewProps>;\n\nexport type ForwardedNavigationMenuWithStatics = React.ForwardRefExoticComponent<\n NavigationMenuProps & React.RefAttributes<HTMLDivElement>\n> & {\n /** Expandable region reprezenting a group of related links */\n Group: React.ForwardRefExoticComponent<NavigationMenuGroupProps & React.RefAttributes<HTMLDivElement>>;\n};\n\nconst Menu = React.forwardRef(function Menu(props: NavigationMenuProps, ref: React.Ref<HTMLDivElement>) {\n const scrollableAreas = React.useMemo(() => {\n const scrollableAreas: any[] = [];\n\n React.Children.toArray(props.children)\n .filter(child => !!child)\n .map((child: React.ReactElement<NavigationMenuGroupProps>) => {\n if (child.props.fixed) {\n scrollableAreas.push(child);\n } else {\n const x = scrollableAreas[scrollableAreas.length - 1];\n if (Array.isArray(x)) {\n x.push(child);\n } else {\n scrollableAreas.push([child]);\n }\n }\n });\n\n return scrollableAreas;\n }, [props.children]);\n\n return (\n <Treeview\n {...props}\n className={cn('divide-grey-light flex flex-grow flex-col divide-y-2 overflow-y-auto', props.className)}\n ref={ref}>\n {scrollableAreas.map((area, i) =>\n Array.isArray(area) ? (\n <div\n className=\"divide-grey-light flex h-0 flex-auto flex-shrink-0 flex-grow flex-col divide-y-2 overflow-y-auto\"\n key={i}>\n {area}\n </div>\n ) : (\n area\n )\n )}\n </Treeview>\n );\n}) as ForwardedNavigationMenuWithStatics;\n\nMenu.Group = MenuGroup;\n\n// Navigation\nexport type NavigationProps = React.HTMLAttributes<HTMLDivElement>;\n\nexport type ForwardedNavigationWithStatics = React.ForwardRefExoticComponent<\n NavigationProps & React.RefAttributes<HTMLDivElement>\n> & {\n /** Navigation link */\n Item: React.ForwardRefExoticComponent<NavigationItemProps & React.RefAttributes<HTMLAnchorElement>>;\n /**\n * Container for the expandable groups that hold navigation links.\n * Should be used as a direct child of Navigation component, e.g. `Navigation.Menu`.\n * Should have the menu groups as a direct child, e.g. `Navigation.Menu.Group`\n */\n Menu: ForwardedNavigationMenuWithStatics;\n /**\n * Isolated container within the Navigation.\n * This can be used to create a region in the Navigation that is usually not scrollable, nor expandable,\n * containing useful information for user and quick actions\n */\n Panel: React.ForwardRefExoticComponent<NavigationPanelProps & React.RefAttributes<HTMLDivElement>>;\n};\n\nexport const Navigation = React.forwardRef(function Navigation(props: NavigationProps, ref: React.Ref<HTMLDivElement>) {\n const { children, ...otherProps } = props;\n const className = cn('h-full flex flex-col bg-grey-light divide-y-2 divide-grey-light', props.className);\n\n return (\n <div {...otherProps} className={className} data-taco=\"navigation\" ref={ref}>\n {children}\n </div>\n );\n}) as ForwardedNavigationWithStatics;\n\nNavigation.Menu = Menu;\nNavigation.Item = Item;\nNavigation.Panel = Panel;\n"],"names":["Item","React","forwardRef","props","ref","active","children","onDrop","postfix","prefix","role","otherProps","proxyRef","useProxiedRef","isDraggedOver","dropTargetProps","useDropTarget","isTreeitem","className","cn","handleClick","event","target","HTMLAnchorElement","HTMLButtonElement","current","click","onClick","Panel","MenuGroup","fixed","title","expanded","Icon","name","Treeview","Group","Menu","scrollableAreas","useMemo","Children","toArray","filter","child","map","push","x","length","Array","isArray","area","i","key","Navigation"],"mappings":";;;;;;;AAgCA,MAAMA,IAAI,gBAAGC,cAAK,CAACC,UAAN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KAAK,CAACe,SAA1E,CAApB;EAEA,OACIjB,4BAAA,MAAA,oBAASU;IAAYO,SAAS,EAAEA;iBAAqB;IAAad,GAAG,EAAEA;IAAvE,EACKE,QADL,CADJ;AAKH,CATyB;AAW1B+C,UAAU,CAAChB,IAAX,GAAkBA,IAAlB;AACAgB,UAAU,CAACrD,IAAX,GAAkBA,IAAlB;AACAqD,UAAU,CAACzB,KAAX,GAAmBA,KAAnB;;;;"}
|
1
|
+
{"version":3,"file":"Navigation.js","sources":["../../../../src/components/Navigation/Navigation.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { TreeviewProps, Treeview, TreeviewGroupProps, TreeviewItemProps } from '../Treeview/Treeview';\nimport { Icon } from '../Icon/Icon';\nimport { useDropTarget } from '../../utils/hooks/useDropTarget';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport './Navigation.css';\n\n// Item\nexport type NavigationItemProps = Omit<TreeviewItemProps, 'prefix'> & {\n /** Change the style to indicate the link is selected */\n active?: boolean;\n /** Handler to be used when dropping a dragged element over the navigation link */\n onDrop?: React.DragEventHandler;\n /**\n * Small amount of information placed next to the text of the link.\n * This can be any valid react element, for e.g. a `span`.\n * Should be used to indicate a relevant information of the link,\n * for e.g. the number of unread notifications\n */\n postfix?: React.ReactNode;\n /**\n * Small amount of information placed before the text of the link.\n * This can be any valid react element, for e.g. a `span`.\n * Should be used to indicate a feedback for user,\n * for e.g. display some sort of visual informational state or a relevant icon.\n */\n prefix?: React.ReactNode;\n /** Target of the link */\n target?: string;\n};\n\nconst Item = React.forwardRef(function Item(props: NavigationItemProps, ref: React.Ref<HTMLAnchorElement>) {\n const { active, children, onDrop, postfix, prefix, role, ...otherProps } = props;\n const proxyRef = useProxiedRef<HTMLAnchorElement>(ref);\n const [isDraggedOver, dropTargetProps] = useDropTarget(onDrop);\n const isTreeitem = role === 'treeitem';\n const className = cn(\n 'yt-navigation__item cursor-pointer',\n {\n 'w-full mb-px py-1 px-3 flex items-center hover:bg-grey-dark': isTreeitem,\n 'bg-white w-full h-10 px-3 flex-shrink-0 flex items-center justify-between cursor-pointer': !isTreeitem,\n 'yt-navigation__item--active': active && !isDraggedOver,\n 'bg-grey-dark': isTreeitem && active && !isDraggedOver,\n 'yt-navigation__item--dropping bg-blue': isDraggedOver,\n },\n props.className\n );\n\n const handleClick = (event: React.MouseEvent<HTMLSpanElement>): void => {\n if (event.target instanceof HTMLAnchorElement || event.target instanceof HTMLButtonElement) {\n return;\n }\n\n if (proxyRef.current) {\n proxyRef.current.click();\n }\n };\n\n return (\n <span {...dropTargetProps} className={className} onClick={handleClick} role={role}>\n {prefix && <span className=\"yt-navigation__item__prefix flex items-center\">{prefix}</span>}\n <a {...otherProps} className=\"block flex-grow truncate\" ref={proxyRef}>\n {children}\n </a>\n {postfix && <span className=\"yt-navigation__item__postfix ml-1\">{postfix}</span>}\n </span>\n );\n});\n\n// Panel\nexport type NavigationPanelProps = React.HTMLAttributes<HTMLDivElement>;\n\nconst Panel = React.forwardRef(function Panel(props: NavigationPanelProps, ref: React.Ref<HTMLDivElement>) {\n return <div {...props} className={cn('w-full bg-white p-3', props.className)} ref={ref} />;\n});\n\n// Group\nexport type NavigationMenuGroupProps = TreeviewGroupProps;\n\nconst MenuGroup = React.forwardRef(function MenuGroup(props: NavigationMenuGroupProps, ref: React.Ref<HTMLDivElement>) {\n const className = cn(\n 'flex-shrink-0 space-y-1 outline-none',\n {\n 'bg-white pb-2': props.fixed,\n },\n props.className\n );\n const title = (expanded: boolean): JSX.Element => {\n const className = cn('bg-white h-10 pl-3 pr-1 flex items-center justify-between w-full', {\n 'mb-1': expanded,\n 'cursor-pointer hover:text-blue': !props.fixed,\n });\n\n return (\n <span className={className}>\n {typeof props.title === 'function' ? props.title(expanded) : props.title}\n {!props.fixed && <Icon name={expanded ? 'chevron-up' : 'chevron-down'} />}\n </span>\n );\n };\n\n return <Treeview.Group {...props} className={className} title={title} ref={ref} />;\n});\n\n// Menu\nexport type NavigationMenuProps = React.PropsWithChildren<TreeviewProps>;\n\nexport type ForwardedNavigationMenuWithStatics = React.ForwardRefExoticComponent<\n NavigationMenuProps & React.RefAttributes<HTMLDivElement>\n> & {\n /** Expandable region reprezenting a group of related links */\n Group: React.ForwardRefExoticComponent<NavigationMenuGroupProps & React.RefAttributes<HTMLDivElement>>;\n};\n\nconst Menu = React.forwardRef(function Menu(props: NavigationMenuProps, ref: React.Ref<HTMLDivElement>) {\n const scrollableAreas = React.useMemo(() => {\n const scrollableAreas: any[] = [];\n\n const children = React.Children.toArray(props.children).filter(\n child => !!child\n ) as React.ReactElement<NavigationMenuGroupProps>[];\n\n children.forEach(child => {\n if (child.props.fixed) {\n scrollableAreas.push(child);\n } else {\n const x = scrollableAreas[scrollableAreas.length - 1];\n if (Array.isArray(x)) {\n x.push(child);\n } else {\n scrollableAreas.push([child]);\n }\n }\n });\n\n return scrollableAreas;\n }, [props.children]);\n\n return (\n <Treeview\n {...props}\n className={cn('divide-grey-light flex flex-grow flex-col divide-y-2 overflow-y-auto', props.className)}\n ref={ref}>\n {scrollableAreas.map((area, i) =>\n Array.isArray(area) ? (\n <div\n className=\"divide-grey-light flex h-0 flex-auto flex-shrink-0 flex-grow flex-col divide-y-2 overflow-y-auto\"\n key={i}>\n {area}\n </div>\n ) : (\n area\n )\n )}\n </Treeview>\n );\n}) as ForwardedNavigationMenuWithStatics;\n\nMenu.Group = MenuGroup;\n\n// Navigation\nexport type NavigationProps = React.HTMLAttributes<HTMLDivElement>;\n\nexport type ForwardedNavigationWithStatics = React.ForwardRefExoticComponent<\n NavigationProps & React.RefAttributes<HTMLDivElement>\n> & {\n /** Navigation link */\n Item: React.ForwardRefExoticComponent<NavigationItemProps & React.RefAttributes<HTMLAnchorElement>>;\n /**\n * Container for the expandable groups that hold navigation links.\n * Should be used as a direct child of Navigation component, e.g. `Navigation.Menu`.\n * Should have the menu groups as a direct child, e.g. `Navigation.Menu.Group`\n */\n Menu: ForwardedNavigationMenuWithStatics;\n /**\n * Isolated container within the Navigation.\n * This can be used to create a region in the Navigation that is usually not scrollable, nor expandable,\n * containing useful information for user and quick actions\n */\n Panel: React.ForwardRefExoticComponent<NavigationPanelProps & React.RefAttributes<HTMLDivElement>>;\n};\n\nexport const Navigation = React.forwardRef(function Navigation(props: NavigationProps, ref: React.Ref<HTMLDivElement>) {\n const { children, ...otherProps } = props;\n const className = cn('h-full flex flex-col bg-grey-light divide-y-2 divide-grey-light', props.className);\n\n return (\n <div {...otherProps} className={className} data-taco=\"navigation\" ref={ref}>\n {children}\n </div>\n );\n}) as ForwardedNavigationWithStatics;\n\nNavigation.Menu = Menu;\nNavigation.Item = Item;\nNavigation.Panel = Panel;\n"],"names":["Item","React","forwardRef","props","ref","active","children","onDrop","postfix","prefix","role","otherProps","proxyRef","useProxiedRef","isDraggedOver","dropTargetProps","useDropTarget","isTreeitem","className","cn","handleClick","event","target","HTMLAnchorElement","HTMLButtonElement","current","click","onClick","Panel","MenuGroup","fixed","title","expanded","Icon","name","Treeview","Group","Menu","scrollableAreas","useMemo","Children","toArray","filter","child","forEach","push","x","length","Array","isArray","map","area","i","key","Navigation"],"mappings":";;;;;;;AAgCA,MAAMA,IAAI,gBAAGC,cAAK,CAACC,UAAN,CAAiB,SAASF,IAAT,CAAcG,KAAd,EAA0CC,GAA1C;EAC1B,MAAM;IAAEC,MAAF;IAAUC,QAAV;IAAoBC,MAApB;IAA4BC,OAA5B;IAAqCC,MAArC;IAA6CC,IAA7C;IAAmD,GAAGC;MAAeR,KAA3E;EACA,MAAMS,QAAQ,GAAGC,aAAa,CAAoBT,GAApB,CAA9B;EACA,MAAM,CAACU,aAAD,EAAgBC,eAAhB,IAAmCC,aAAa,CAACT,MAAD,CAAtD;EACA,MAAMU,UAAU,GAAGP,IAAI,KAAK,UAA5B;EACA,MAAMQ,SAAS,GAAGC,EAAE,CAChB,oCADgB,EAEhB;IACI,+DAA+DF,UADnE;IAEI,4FAA4F,CAACA,UAFjG;IAGI,+BAA+BZ,MAAM,IA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d,CAAJ,EAAsB;UAClBA,CAAC,CAACD,IAAF,CAAOF,KAAP;SADJ,MAEO;UACHL,eAAe,CAACO,IAAhB,CAAqB,CAACF,KAAD,CAArB;;;KARZ;IAaA,OAAOL,eAAP;GApBoB,EAqBrB,CAACnC,KAAK,CAACG,QAAP,CArBqB,CAAxB;EAuBA,OACIL,4BAAA,CAACkC,QAAD,oBACQhC;IACJe,SAAS,EAAEC,EAAE,CAAC,sEAAD,EAAyEhB,KAAK,CAACe,SAA/E;IACbd,GAAG,EAAEA;IAHT,EAIKkC,eAAe,CAACY,GAAhB,CAAoB,CAACC,IAAD,EAAOC,CAAP,KACjBJ,KAAK,CAACC,OAAN,CAAcE,IAAd,IACIlD,4BAAA,MAAA;IACIiB,SAAS,EAAC;IACVmC,GAAG,EAAED;GAFT,EAGKD,IAHL,CADJ,GAOIA,IARP,CAJL,CADJ;AAkBH,CA1CY,CAAb;AA4CAd,IAAI,CAACD,KAAL,GAAaP,SAAb;MAwBayB,UAAU,gBAAGrD,cAAK,CAACC,UAAN,CAAiB,SAASoD,UAAT,CAAoBnD,KAApB,EAA4CC,GAA5C;EACvC,MAAM;IAAEE,QAAF;IAAY,GAAGK;MAAeR,KAApC;EACA,MAAMe,SAAS,GAAGC,EAAE,CAAC,iEAAD,EAAoEhB,KAAK,CAACe,SAA1E,CAApB;EAEA,OACIjB,4BAAA,MAAA,oBAASU;IAAYO,SAAS,EAAEA;iBAAqB;IAAad,GAAG,EAAEA;IAAvE,EACKE,QADL,CADJ;AAKH,CATyB;AAW1BgD,UAAU,CAACjB,IAAX,GAAkBA,IAAlB;AACAiB,UAAU,CAACtD,IAAX,GAAkBA,IAAlB;AACAsD,UAAU,CAAC1B,KAAX,GAAmBA,KAAnB;;;;"}
|
@@ -15,7 +15,7 @@ const getActions = (actions, row = undefined) => {
|
|
15
15
|
const secondary = [];
|
16
16
|
|
17
17
|
if (actions) {
|
18
|
-
let visibleActions = actions.filter(x => !!x);
|
18
|
+
let visibleActions = actions.filter(x => !!x && typeof x !== 'boolean');
|
19
19
|
|
20
20
|
if (row) {
|
21
21
|
visibleActions = visibleActions.filter(action => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useRowActions.js","sources":["../../../../../../src/components/Table/hooks/plugins/useRowActions.tsx"],"sourcesContent":["import React from 'react';\nimport { PluginHook } from 'react-table';\nimport { InView } from 'react-intersection-observer';\nimport { sanitizeRowProps } from '../../util';\nimport { IconButton } from '../../../IconButton/IconButton';\nimport { LocalizationTexts } from '../../../Provider/Provider';\nimport { Menu } from '../../../Menu/Menu';\nimport { RowAction, RowActionHandler, TableRow } from '../../types';\n\nconst actionGroupClassName = '-mt-1 -mb-1 h-8 flex';\n\nconst hasActions = (inlineEditingUniqueId: any, handlers: any, actions: RowActionHandler<any>[] | undefined): number => {\n return (\n !!actions ||\n handlers.onRowCreate ||\n handlers.onRowCopy ||\n handlers.onRowDelete ||\n !!inlineEditingUniqueId ||\n handlers.onRowEdit\n );\n};\n\nconst getActions = (\n actions: RowActionHandler<any>[] | undefined,\n row: TableRow<any> | undefined = undefined\n): [RowAction<any>[], RowAction<any>[]] => {\n const primary: RowAction<any>[] = [];\n const secondary: RowAction<any>[] = [];\n\n if (actions) {\n let visibleActions = actions.filter(x => !!x);\n\n if (row) {\n visibleActions = visibleActions.filter((action: RowAction<any>) => {\n if (action.visible !== undefined) {\n if (typeof action.visible === 'function') {\n return action.visible(row);\n }\n\n return action.visible;\n }\n\n return true;\n });\n }\n\n visibleActions.forEach((action: RowAction<any>) => {\n if (action.showOnRow) {\n primary.push(action);\n } else {\n secondary.push(action);\n }\n });\n }\n\n return [primary, secondary];\n};\n\nconst getLength = (inlineEditingUniqueId: any, handlers: any, actions: RowActionHandler<any>[] | undefined): number => {\n const [primaryActions, secondaryActions] = getActions(actions);\n\n let length = primaryActions.length + (secondaryActions.length ? 1 : 0);\n\n if (handlers.onRowCreate) {\n length++;\n }\n\n if (handlers.onRowCopy) {\n length++;\n }\n\n if (handlers.onRowDelete) {\n length++;\n }\n\n if (!!inlineEditingUniqueId || handlers.onRowEdit) {\n length++;\n\n if (length < 2) {\n length++;\n }\n }\n\n return length;\n};\n\nconst getActionProps = (action: RowAction<any>, row: TableRow<any>) => {\n return {\n 'aria-label': typeof action.tooltip === 'function' ? action.tooltip(row) : action.tooltip,\n disabled: typeof action.disabled === 'function' ? action.disabled(row) : action.disabled,\n onClick: (event: React.MouseEvent<HTMLElement>) => {\n action.onClick(row, event);\n },\n };\n};\n\nconst EditModeActions = () => {\n React.useEffect(() => {\n const listener = (event: any) => {\n if (event.key === 'Escape' && event.target?.form?.reset) {\n event.preventDefault();\n event.target.form.reset();\n }\n };\n\n document.addEventListener('keydown', listener);\n\n return () => {\n document.removeEventListener('keydown', listener);\n };\n }, []);\n\n return (\n <div className={actionGroupClassName}>\n <IconButton appearance=\"primary\" icon=\"tick\" type=\"submit\" className=\"mr-2\" />\n <IconButton appearance=\"ghost\" icon=\"close\" type=\"reset\" />\n </div>\n );\n};\n\nexport const useRowActions = <T extends {}>(\n inlineEditingUniqueId: keyof T | undefined,\n handlers: any,\n actions: RowActionHandler<T>[] | undefined,\n rowExpansionRenderer: any,\n texts: LocalizationTexts,\n windowed = false\n): PluginHook<{}> => {\n const inlineEditing = !!inlineEditingUniqueId;\n const actionsLength = getLength(inlineEditingUniqueId, handlers, actions);\n\n const plugin = (hooks: any): void => {\n if (hasActions(inlineEditingUniqueId, handlers, actions)) {\n hooks.visibleColumns.push((columns: any) => [\n ...columns,\n {\n id: '_actions',\n className: 'flex justify-end px-1 overflow-visible',\n flex: `0 0 calc((${actionsLength} * 2rem) + .5rem)`,\n Cell: ({ row }: any) => {\n if (row.isEditing) {\n return <EditModeActions />;\n }\n\n const sanitizedRow = sanitizeRowProps(row, rowExpansionRenderer);\n const [primaryActions, secondaryActions] = getActions(actions, sanitizedRow);\n\n const output = (\n <>\n {handlers.onRowCreate && (\n <IconButton\n appearance=\"discrete\"\n icon=\"circle-plus\"\n aria-label={texts.table.newSubRow}\n tooltip={texts.table.newSubRow}\n disabled={inlineEditing && !row.canEdit}\n onClick={(event: React.MouseEvent) => {\n event.stopPropagation();\n event.persist();\n row.setActive();\n\n if (!row.isExpanded) {\n row.toggleRowExpanded();\n }\n\n handlers.onRowCreate(sanitizedRow, event);\n }}\n />\n )}\n {(inlineEditing || handlers.onRowEdit) && (\n <IconButton\n appearance=\"discrete\"\n icon=\"edit\"\n aria-label={texts.table.edit}\n tooltip={texts.table.edit}\n disabled={inlineEditing && !row.canEdit}\n onClick={(event: React.MouseEvent) => {\n event.stopPropagation();\n row.setActive();\n\n if (inlineEditing) {\n row.toggleRowEditing();\n } else if (handlers.onRowEdit) {\n event.persist();\n handlers.onRowEdit(sanitizedRow, event);\n }\n }}\n />\n )}\n {handlers.onRowCopy && (\n <IconButton\n appearance=\"discrete\"\n icon=\"copy\"\n aria-label={texts.table.copy}\n tooltip={texts.table.copy}\n disabled={inlineEditing && !row.canEdit}\n onClick={(event: React.MouseEvent) => {\n event.stopPropagation();\n event.persist();\n row.setActive();\n handlers.onRowCopy(sanitizedRow, event);\n }}\n />\n )}\n {handlers.onRowDelete && (\n <IconButton\n appearance=\"discrete\"\n icon=\"delete\"\n aria-label={texts.table.del}\n tooltip={texts.table.del}\n disabled={inlineEditing && !row.canEdit}\n onClick={(event: React.MouseEvent) => {\n event.stopPropagation();\n event.persist();\n row.setActive();\n handlers.onRowDelete(sanitizedRow, event);\n }}\n />\n )}\n {primaryActions.map((action: RowAction<T>, index: number) => (\n <IconButton\n {...getActionProps(action, sanitizedRow)}\n key={index}\n appearance=\"discrete\"\n icon={typeof action.icon === 'function' ? action.icon(sanitizedRow) : action.icon}\n tooltip={\n typeof action.tooltip === 'function' ? action.tooltip(sanitizedRow) : action.tooltip\n }\n />\n ))}\n {secondaryActions.length ? (\n <Menu>\n <Menu.Trigger>\n <IconButton\n appearance=\"discrete\"\n icon=\"ellipsis-vertical\"\n aria-label={texts.table.actions}\n tooltip={texts.table.actions}\n disabled={inlineEditing && !row.canEdit}\n onClick={(event: React.MouseEvent) => {\n event.stopPropagation();\n row.setActive();\n }}\n />\n </Menu.Trigger>\n <Menu.Content>\n {secondaryActions.map((action: RowAction<T>, index: number) => (\n <Menu.Item\n key={index}\n icon={\n typeof action.icon === 'function'\n ? action.icon(sanitizedRow)\n : action.icon\n }\n {...getActionProps(action, sanitizedRow)}>\n {typeof action.text === 'function' ? action.text(sanitizedRow) : action.text}\n </Menu.Item>\n ))}\n </Menu.Content>\n </Menu>\n ) : null}\n </>\n );\n\n if (windowed) {\n return <div className={actionGroupClassName}>{output}</div>;\n }\n\n return (\n <InView rootMargin=\"100px 0px\">\n {({ inView, ref }) => (\n <div className={actionGroupClassName} ref={ref}>\n {inView ? output : null}\n </div>\n )}\n </InView>\n );\n },\n },\n ]);\n }\n };\n plugin.pluginName = 'useRowActions';\n return plugin;\n};\n"],"names":["actionGroupClassName","hasActions","inlineEditingUniqueId","handlers","actions","onRowCreate","onRowCopy","onRowDelete","onRowEdit","getActions","row","undefined","primary","secondary","visibleActions","filter","x","action","visible","forEach","showOnRow","push","getLength","primaryActions","secondaryActions","length","getActionProps","tooltip","disabled","onClick","event","EditModeActions","React","useEffect","listener","key","target","form","reset","preventDefault","document","addEventListener","removeEventListener","className","IconButton","appearance","icon","type","useRowActions","rowExpansionRenderer","texts","windowed","inlineEditing","actionsLength","plugin","hooks","visibleColumns","columns","id","flex","Cell","isEditing","sanitizedRow","sanitizeRowProps","output","table","newSubRow","canEdit","stopPropagation","persist","setActive","isExpanded","toggleRowExpanded","edit","toggleRowEditing","copy","del","map","index","Menu","Trigger","Content","Item","text","InView","rootMargin","inView","ref","pluginName"],"mappings":";;;;;;AASA,MAAMA,oBAAoB,GAAG,sBAA7B;;AAEA,MAAMC,UAAU,GAAG,CAACC,qBAAD,EAA6BC,QAA7B,EAA4CC,OAA5C;EACf,OACI,CAAC,CAACA,OAAF,IACAD,QAAQ,CAACE,WADT,IAEAF,QAAQ,CAACG,SAFT,IAGAH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ChCtC,OAAO,EAAGC,KAAD;cACLA,KAAK,CAACsC,eAAN;cACA1D,GAAG,CAAC4D,SAAJ;;WARR,CADJ,CADJ,EAcItC,4BAAA,CAAC+C,IAAI,CAACE,OAAN,MAAA,EACKzD,gBAAgB,CAACqD,GAAjB,CAAqB,CAAC5D,MAAD,EAAuB6D,KAAvB,KAClB9C,4BAAA,CAAC+C,IAAI,CAACG,IAAN;YACI/C,GAAG,EAAE2C;YACLhC,IAAI,EACA,OAAO7B,MAAM,CAAC6B,IAAd,KAAuB,UAAvB,GACM7B,MAAM,CAAC6B,IAAP,CAAYgB,YAAZ,CADN,GAEM7C,MAAM,CAAC6B;aAEbpB,cAAc,CAACT,MAAD,EAAS6C,YAAT,EAPtB,EAQK,OAAO7C,MAAM,CAACkE,IAAd,KAAuB,UAAvB,GAAoClE,MAAM,CAACkE,IAAP,CAAYrB,YAAZ,CAApC,GAAgE7C,MAAM,CAACkE,IAR5E,CADH,CADL,CAdJ,CADH,GA8BG,IAhHR,CADJ;;UAqHA,IAAIhC,QAAJ,EAAc;YACV,OAAOnB,4BAAA,MAAA;cAAKW,SAAS,EAAE3C;aAAhB,EAAuCgE,MAAvC,CAAP;;;UAGJ,OACIhC,4BAAA,CAACoD,MAAD;YAAQC,UAAU,EAAC;WAAnB,EACK,CAAC;YAAEC,MAAF;YAAUC;WAAX,KACGvD,4BAAA,MAAA;YAAKW,SAAS,EAAE3C;YAAsBuF,GAAG,EAAEA;WAA3C,EACKD,MAAM,GAAGtB,MAAH,GAAY,IADvB,CAFR,CADJ;;OAvIgC,CAA5C;;GAFR;;EAuJAV,MAAM,CAACkC,UAAP,GAAoB,eAApB;EACA,OAAOlC,MAAP;AACH;;;;"}
|
1
|
+
{"version":3,"file":"useRowActions.js","sources":["../../../../../../src/components/Table/hooks/plugins/useRowActions.tsx"],"sourcesContent":["import React from 'react';\nimport { PluginHook } from 'react-table';\nimport { InView } from 'react-intersection-observer';\nimport { sanitizeRowProps } from '../../util';\nimport { IconButton } from '../../../IconButton/IconButton';\nimport { LocalizationTexts } from '../../../Provider/Provider';\nimport { Menu } from '../../../Menu/Menu';\nimport { RowAction, RowActionHandler, TableRow } from '../../types';\n\nconst actionGroupClassName = '-mt-1 -mb-1 h-8 flex';\n\nconst hasActions = (inlineEditingUniqueId: any, handlers: any, actions: RowActionHandler<any>[] | undefined): number => {\n return (\n !!actions ||\n handlers.onRowCreate ||\n handlers.onRowCopy ||\n handlers.onRowDelete ||\n !!inlineEditingUniqueId ||\n handlers.onRowEdit\n );\n};\n\nconst getActions = (\n actions: RowActionHandler<any>[] | undefined,\n row: TableRow<any> | undefined = undefined\n): [RowAction<any>[], RowAction<any>[]] => {\n const primary: RowAction<any>[] = [];\n const secondary: RowAction<any>[] = [];\n\n if (actions) {\n let visibleActions = actions.filter(x => !!x && typeof x !== 'boolean') as RowAction<any>[];\n\n if (row) {\n visibleActions = visibleActions.filter(action => {\n if (action.visible !== undefined) {\n if (typeof action.visible === 'function') {\n return action.visible(row);\n }\n\n return action.visible;\n }\n\n return true;\n });\n }\n\n visibleActions.forEach(action => {\n if (action.showOnRow) {\n primary.push(action);\n } else {\n secondary.push(action);\n }\n });\n }\n\n return [primary, secondary];\n};\n\nconst getLength = (inlineEditingUniqueId: any, handlers: any, actions: RowActionHandler<any>[] | undefined): number => {\n const [primaryActions, secondaryActions] = getActions(actions);\n\n let length = primaryActions.length + (secondaryActions.length ? 1 : 0);\n\n if (handlers.onRowCreate) {\n length++;\n }\n\n if (handlers.onRowCopy) {\n length++;\n }\n\n if (handlers.onRowDelete) {\n length++;\n }\n\n if (!!inlineEditingUniqueId || handlers.onRowEdit) {\n length++;\n\n if (length < 2) {\n length++;\n }\n }\n\n return length;\n};\n\nconst getActionProps = (action: RowAction<any>, row: TableRow<any>) => {\n return {\n 'aria-label': typeof action.tooltip === 'function' ? action.tooltip(row) : action.tooltip,\n disabled: typeof action.disabled === 'function' ? action.disabled(row) : action.disabled,\n onClick: (event: React.MouseEvent<HTMLElement>) => {\n action.onClick(row, event);\n },\n };\n};\n\nconst EditModeActions = () => {\n React.useEffect(() => {\n const listener = (event: any) => {\n if (event.key === 'Escape' && event.target?.form?.reset) {\n event.preventDefault();\n event.target.form.reset();\n }\n };\n\n document.addEventListener('keydown', listener);\n\n return () => {\n document.removeEventListener('keydown', listener);\n };\n }, []);\n\n return (\n <div className={actionGroupClassName}>\n <IconButton appearance=\"primary\" icon=\"tick\" type=\"submit\" className=\"mr-2\" />\n <IconButton appearance=\"ghost\" icon=\"close\" type=\"reset\" />\n </div>\n );\n};\n\nexport const useRowActions = <T extends {}>(\n inlineEditingUniqueId: keyof T | undefined,\n handlers: any,\n actions: RowActionHandler<T>[] | undefined,\n rowExpansionRenderer: any,\n texts: LocalizationTexts,\n windowed = false\n): PluginHook<{}> => {\n const inlineEditing = !!inlineEditingUniqueId;\n const actionsLength = getLength(inlineEditingUniqueId, handlers, actions);\n\n const plugin = (hooks: any): void => {\n if (hasActions(inlineEditingUniqueId, handlers, actions)) {\n hooks.visibleColumns.push((columns: any) => [\n ...columns,\n {\n id: '_actions',\n className: 'flex justify-end px-1 overflow-visible',\n flex: `0 0 calc((${actionsLength} * 2rem) + .5rem)`,\n Cell: ({ row }: any) => {\n if (row.isEditing) {\n return <EditModeActions />;\n }\n\n const sanitizedRow = sanitizeRowProps(row, rowExpansionRenderer);\n const [primaryActions, secondaryActions] = getActions(actions, sanitizedRow);\n\n const output = (\n <>\n {handlers.onRowCreate && (\n <IconButton\n appearance=\"discrete\"\n icon=\"circle-plus\"\n aria-label={texts.table.newSubRow}\n tooltip={texts.table.newSubRow}\n disabled={inlineEditing && !row.canEdit}\n onClick={(event: React.MouseEvent) => {\n event.stopPropagation();\n event.persist();\n row.setActive();\n\n if (!row.isExpanded) {\n row.toggleRowExpanded();\n }\n\n handlers.onRowCreate(sanitizedRow, event);\n }}\n />\n )}\n {(inlineEditing || handlers.onRowEdit) && (\n <IconButton\n appearance=\"discrete\"\n icon=\"edit\"\n aria-label={texts.table.edit}\n tooltip={texts.table.edit}\n disabled={inlineEditing && !row.canEdit}\n onClick={(event: React.MouseEvent) => {\n event.stopPropagation();\n row.setActive();\n\n if (inlineEditing) {\n row.toggleRowEditing();\n } else if (handlers.onRowEdit) {\n event.persist();\n handlers.onRowEdit(sanitizedRow, event);\n }\n }}\n />\n )}\n {handlers.onRowCopy && (\n <IconButton\n appearance=\"discrete\"\n icon=\"copy\"\n aria-label={texts.table.copy}\n tooltip={texts.table.copy}\n disabled={inlineEditing && !row.canEdit}\n onClick={(event: React.MouseEvent) => {\n event.stopPropagation();\n event.persist();\n row.setActive();\n handlers.onRowCopy(sanitizedRow, event);\n }}\n />\n )}\n {handlers.onRowDelete && (\n <IconButton\n appearance=\"discrete\"\n icon=\"delete\"\n aria-label={texts.table.del}\n tooltip={texts.table.del}\n disabled={inlineEditing && !row.canEdit}\n onClick={(event: React.MouseEvent) => {\n event.stopPropagation();\n event.persist();\n row.setActive();\n handlers.onRowDelete(sanitizedRow, event);\n }}\n />\n )}\n {primaryActions.map((action: RowAction<T>, index: number) => (\n <IconButton\n {...getActionProps(action, sanitizedRow)}\n key={index}\n appearance=\"discrete\"\n icon={typeof action.icon === 'function' ? action.icon(sanitizedRow) : action.icon}\n tooltip={\n typeof action.tooltip === 'function' ? action.tooltip(sanitizedRow) : action.tooltip\n }\n />\n ))}\n {secondaryActions.length ? (\n <Menu>\n <Menu.Trigger>\n <IconButton\n appearance=\"discrete\"\n icon=\"ellipsis-vertical\"\n aria-label={texts.table.actions}\n tooltip={texts.table.actions}\n disabled={inlineEditing && !row.canEdit}\n onClick={(event: React.MouseEvent) => {\n event.stopPropagation();\n row.setActive();\n }}\n />\n </Menu.Trigger>\n <Menu.Content>\n {secondaryActions.map((action: RowAction<T>, index: number) => (\n <Menu.Item\n key={index}\n icon={\n typeof action.icon === 'function'\n ? action.icon(sanitizedRow)\n : action.icon\n }\n {...getActionProps(action, sanitizedRow)}>\n {typeof action.text === 'function' ? action.text(sanitizedRow) : action.text}\n </Menu.Item>\n ))}\n </Menu.Content>\n </Menu>\n ) : null}\n </>\n );\n\n if (windowed) {\n return <div className={actionGroupClassName}>{output}</div>;\n }\n\n return (\n <InView rootMargin=\"100px 0px\">\n {({ inView, ref }) => (\n <div className={actionGroupClassName} ref={ref}>\n {inView ? output : null}\n </div>\n )}\n </InView>\n );\n },\n },\n ]);\n }\n };\n plugin.pluginName = 'useRowActions';\n return plugin;\n};\n"],"names":["actionGroupClassName","hasActions","inlineEditingUniqueId","handlers","actions","onRowCreate","onRowCopy","onRowDelete","onRowEdit","getActions","row","undefined","primary","secondary","visibleActions","filter","x","action","visible","forEach","showOnRow","push","getLength","primaryActions","secondaryActions","length","getActionProps","tooltip","disabled","onClick","event","EditModeActions","React","useEffect","listener","key","target","form","reset","preventDefault","document","addEventListener","removeEventListener","className","IconButton","appearance","icon","type","useRowActions","rowExpansionRenderer","texts","windowed","inlineEditing","actionsLength","plugin","hooks","visibleColumns","columns","id","flex","Cell","isEditing","sanitizedRow","sanitizeRowProps","output","table","newSubRow","canEdit","stopPropagation","persist","setActive","isExpanded","toggleRowExpanded","edit","toggleRowEditing","copy","del","map","index","Menu","Trigger","Content","Item","text","InView","rootMargin","inView","ref","pluginName"],"mappings":";;;;;;AASA,MAAMA,oBAAoB,GAAG,sBAA7B;;AAEA,MAAMC,UAAU,GAAG,CAACC,qBAAD,EAA6BC,QAA7B,EAA4CC,OAA5C;EACf,OACI,CAAC,CAACA,OAAF,IACAD,QAAQ,CAACE,WADT,IAEAF,QAAQ,CAACG,SAFT,IAGAH,QAAQ,CAACI,WAHT,IAIA,CAAC,CAACL,qBAJF,IAKAC,QAAQ,CAACK,SANb;AAQH,CATD;;AAWA,MAAMC,UAAU,GAAG,CACfL,OADe,EAEfM,MAAiCC,SAFlB;EAIf,MAAMC,OAAO,GAAqB,EAAlC;EACA,MAAMC,SAAS,GAAqB,EAApC;;EAEA,IAAIT,OAAJ,EAAa;IACT,IAAIU,cAAc,GAAGV,OAAO,CAACW,MAA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AACG,IAAN;YACI/C,GAAG,EAAE2C;YACLhC,IAAI,EACA,OAAO7B,MAAM,CAAC6B,IAAd,KAAuB,UAAvB,GACM7B,MAAM,CAAC6B,IAAP,CAAYgB,YAAZ,CADN,GAEM7C,MAAM,CAAC6B;aAEbpB,cAAc,CAACT,MAAD,EAAS6C,YAAT,EAPtB,EAQK,OAAO7C,MAAM,CAACkE,IAAd,KAAuB,UAAvB,GAAoClE,MAAM,CAACkE,IAAP,CAAYrB,YAAZ,CAApC,GAAgE7C,MAAM,CAACkE,IAR5E,CADH,CADL,CAdJ,CADH,GA8BG,IAhHR,CADJ;;UAqHA,IAAIhC,QAAJ,EAAc;YACV,OAAOnB,4BAAA,MAAA;cAAKW,SAAS,EAAE3C;aAAhB,EAAuCgE,MAAvC,CAAP;;;UAGJ,OACIhC,4BAAA,CAACoD,MAAD;YAAQC,UAAU,EAAC;WAAnB,EACK,CAAC;YAAEC,MAAF;YAAUC;WAAX,KACGvD,4BAAA,MAAA;YAAKW,SAAS,EAAE3C;YAAsBuF,GAAG,EAAEA;WAA3C,EACKD,MAAM,GAAGtB,MAAH,GAAY,IADvB,CAFR,CADJ;;OAvIgC,CAA5C;;GAFR;;EAuJAV,MAAM,CAACkC,UAAP,GAAoB,eAApB;EACA,OAAOlC,MAAP;AACH;;;;"}
|
@@ -8,7 +8,13 @@ const useTableKeyboardNavigation = (props, rows, rowProps, ref) => {
|
|
8
8
|
const [activeIndex, setActiveIndex] = useControllableState({
|
9
9
|
prop: props.activeIndex,
|
10
10
|
defaultProp: props.defaultActiveIndex !== undefined ? props.defaultActiveIndex : useGlobalKeyboardNavigation ? 0 : undefined,
|
11
|
-
onChange:
|
11
|
+
onChange: index => {
|
12
|
+
if (index !== undefined) {
|
13
|
+
var _props$onChangeActive;
|
14
|
+
|
15
|
+
(_props$onChangeActive = props.onChangeActiveIndex) === null || _props$onChangeActive === void 0 ? void 0 : _props$onChangeActive.call(props, index);
|
16
|
+
}
|
17
|
+
}
|
12
18
|
});
|
13
19
|
|
14
20
|
const onKeyDown = event => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTableKeyboardNavigation.js","sources":["../../../../../src/components/Table/hooks/useTableKeyboardNavigation.ts"],"sourcesContent":["import React from 'react';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { getNextIndexFromKey } from '../../../utils/hooks/useListKeyboardNavigation';\nimport { sanitizeRowProps } from '../util';\nimport { TableProps } from '../types';\n\nexport const useTableKeyboardNavigation = <T extends {}>(\n props: TableProps<T>,\n rows: any[],\n rowProps: any,\n ref: React.RefObject<HTMLDivElement>\n): [\n number | undefined,\n (index: number) => void,\n (event: React.KeyboardEvent<HTMLElement>) => void,\n (event: React.FocusEvent<HTMLElement>) => void\n] => {\n const useGlobalKeyboardNavigation = props.dangerouslyHijackGlobalKeyboardNavigation;\n\n const [activeIndex, setActiveIndex] = useControllableState<number | undefined>({\n prop: props.activeIndex,\n defaultProp:\n props.defaultActiveIndex !== undefined ? props.defaultActiveIndex : useGlobalKeyboardNavigation ? 0 : undefined,\n onChange: props.onChangeActiveIndex,\n });\n\n const onKeyDown = (event: KeyboardEvent): void => {\n const isModifierKeyPressed = event.metaKey || event.ctrlKey || event.altKey || event.shiftKey;\n\n if (\n useGlobalKeyboardNavigation &&\n document.activeElement !== ref.current &&\n document.activeElement?.getAttribute('type') !== 'search' &&\n document.activeElement !== document.body\n ) {\n return;\n }\n // abort key handling if other elements inside table are focused and we don't use global keyboard navigation\n if (!useGlobalKeyboardNavigation && document.activeElement !== ref.current) {\n return;\n }\n\n if (activeIndex !== undefined) {\n const currentRow = rows[activeIndex];\n\n if (currentRow) {\n const sanitizedRow = sanitizeRowProps(currentRow, rowProps.rowExpansionRenderer);\n\n if (rowProps.onRowClick && event.key === 'Enter') {\n event.preventDefault();\n rowProps.onRowClick(sanitizedRow);\n return;\n }\n\n if (currentRow.toggleRowSelected && event.key === ' ') {\n event.preventDefault();\n currentRow.toggleRowSelected();\n return;\n }\n\n if (currentRow.toggleRowExpanded) {\n if (currentRow.isExpanded && event.key === 'ArrowLeft') {\n event.preventDefault();\n currentRow.toggleRowExpanded();\n return;\n } else if (!currentRow.isExpanded && event.key === 'ArrowRight') {\n event.preventDefault();\n currentRow.toggleRowExpanded();\n return;\n }\n }\n\n // inline editing\n if (currentRow.toggleRowEditing) {\n if (currentRow.canEdit && !currentRow.isEditing) {\n if (rowProps.onRowCreate && event.shiftKey && event.key === 'n') {\n event.preventDefault();\n\n if (!currentRow.isExpanded) {\n currentRow.toggleRowExpanded();\n }\n\n rowProps.onRowCreate(sanitizedRow, event);\n return;\n }\n\n if (event.key === 'e') {\n event.preventDefault();\n currentRow.toggleRowEditing();\n return;\n }\n }\n }\n\n if (rowProps.onRowEdit && event.key === 'e' && !isModifierKeyPressed) {\n event.preventDefault();\n rowProps.onRowEdit(sanitizedRow, event);\n return;\n }\n\n if (rowProps.onRowCopy && event.key === 'c' && !isModifierKeyPressed) {\n event.preventDefault();\n rowProps.onRowCopy(sanitizedRow, event);\n return;\n }\n\n if (rowProps.onRowDelete && event.key === 'Delete' && !isModifierKeyPressed) {\n event.preventDefault();\n rowProps.onRowDelete(sanitizedRow, event);\n return;\n }\n }\n }\n\n const nextIndex = getNextIndexFromKey(event.key, rows.length, activeIndex);\n\n if (nextIndex !== undefined) {\n event.preventDefault();\n setActiveIndex(nextIndex);\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLElement>): void => {\n if (!useGlobalKeyboardNavigation) {\n onKeyDown(event.nativeEvent);\n }\n };\n\n React.useEffect(() => {\n if (useGlobalKeyboardNavigation) {\n window.addEventListener('keydown', onKeyDown);\n }\n\n return () => {\n if (useGlobalKeyboardNavigation) {\n window.removeEventListener('keydown', onKeyDown);\n }\n };\n }, [onKeyDown]);\n\n const handleFocus = (): void => {\n if (activeIndex === undefined && rows.length) {\n setActiveIndex(0);\n }\n };\n\n return [activeIndex, setActiveIndex, handleKeyDown, handleFocus];\n};\n"],"names":["useTableKeyboardNavigation","props","rows","rowProps","ref","useGlobalKeyboardNavigation","dangerouslyHijackGlobalKeyboardNavigation","activeIndex","setActiveIndex","useControllableState","prop","defaultProp","defaultActiveIndex","undefined","onChange","onChangeActiveIndex","onKeyDown","event","isModifierKeyPressed","metaKey","ctrlKey","altKey","shiftKey","document","activeElement","current","getAttribute","body","currentRow","sanitizedRow","sanitizeRowProps","rowExpansionRenderer","onRowClick","key","preventDefault","toggleRowSelected","toggleRowExpanded","isExpanded","toggleRowEditing","canEdit","isEditing","onRowCreate","onRowEdit","onRowCopy","onRowDelete","nextIndex","getNextIndexFromKey","length","handleKeyDown","nativeEvent","React","useEffect","window","addEventListener","removeEventListener","handleFocus"],"mappings":";;;;;MAMaA,0BAA0B,GAAG,CACtCC,KADsC,EAEtCC,IAFsC,EAGtCC,QAHsC,EAItCC,GAJsC;EAWtC,MAAMC,2BAA2B,GAAGJ,KAAK,CAACK,yCAA1C;EAEA,MAAM,CAACC,WAAD,EAAcC,cAAd,IAAgCC,oBAAoB,CAAqB;IAC3EC,IAAI,EAAET,KAAK,CAACM,WAD+D;IAE3EI,WAAW,EACPV,KAAK,CAACW,kBAAN,KAA6BC,SAA7B,GAAyCZ,KAAK,CAACW,kBAA/C,GAAoEP,2BAA2B,GAAG,CAAH,GAAOQ,SAH/B;IAI3EC,QAAQ,
|
1
|
+
{"version":3,"file":"useTableKeyboardNavigation.js","sources":["../../../../../src/components/Table/hooks/useTableKeyboardNavigation.ts"],"sourcesContent":["import React from 'react';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { getNextIndexFromKey } from '../../../utils/hooks/useListKeyboardNavigation';\nimport { sanitizeRowProps } from '../util';\nimport { TableProps } from '../types';\n\nexport const useTableKeyboardNavigation = <T extends {}>(\n props: TableProps<T>,\n rows: any[],\n rowProps: any,\n ref: React.RefObject<HTMLDivElement>\n): [\n number | undefined,\n (index: number) => void,\n (event: React.KeyboardEvent<HTMLElement>) => void,\n (event: React.FocusEvent<HTMLElement>) => void\n] => {\n const useGlobalKeyboardNavigation = props.dangerouslyHijackGlobalKeyboardNavigation;\n\n const [activeIndex, setActiveIndex] = useControllableState<number | undefined>({\n prop: props.activeIndex,\n defaultProp:\n props.defaultActiveIndex !== undefined ? props.defaultActiveIndex : useGlobalKeyboardNavigation ? 0 : undefined,\n onChange: index => {\n if (index !== undefined) {\n props.onChangeActiveIndex?.(index);\n }\n },\n });\n\n const onKeyDown = (event: KeyboardEvent): void => {\n const isModifierKeyPressed = event.metaKey || event.ctrlKey || event.altKey || event.shiftKey;\n\n if (\n useGlobalKeyboardNavigation &&\n document.activeElement !== ref.current &&\n document.activeElement?.getAttribute('type') !== 'search' &&\n document.activeElement !== document.body\n ) {\n return;\n }\n // abort key handling if other elements inside table are focused and we don't use global keyboard navigation\n if (!useGlobalKeyboardNavigation && document.activeElement !== ref.current) {\n return;\n }\n\n if (activeIndex !== undefined) {\n const currentRow = rows[activeIndex];\n\n if (currentRow) {\n const sanitizedRow = sanitizeRowProps(currentRow, rowProps.rowExpansionRenderer);\n\n if (rowProps.onRowClick && event.key === 'Enter') {\n event.preventDefault();\n rowProps.onRowClick(sanitizedRow);\n return;\n }\n\n if (currentRow.toggleRowSelected && event.key === ' ') {\n event.preventDefault();\n currentRow.toggleRowSelected();\n return;\n }\n\n if (currentRow.toggleRowExpanded) {\n if (currentRow.isExpanded && event.key === 'ArrowLeft') {\n event.preventDefault();\n currentRow.toggleRowExpanded();\n return;\n } else if (!currentRow.isExpanded && event.key === 'ArrowRight') {\n event.preventDefault();\n currentRow.toggleRowExpanded();\n return;\n }\n }\n\n // inline editing\n if (currentRow.toggleRowEditing) {\n if (currentRow.canEdit && !currentRow.isEditing) {\n if (rowProps.onRowCreate && event.shiftKey && event.key === 'n') {\n event.preventDefault();\n\n if (!currentRow.isExpanded) {\n currentRow.toggleRowExpanded();\n }\n\n rowProps.onRowCreate(sanitizedRow, event);\n return;\n }\n\n if (event.key === 'e') {\n event.preventDefault();\n currentRow.toggleRowEditing();\n return;\n }\n }\n }\n\n if (rowProps.onRowEdit && event.key === 'e' && !isModifierKeyPressed) {\n event.preventDefault();\n rowProps.onRowEdit(sanitizedRow, event);\n return;\n }\n\n if (rowProps.onRowCopy && event.key === 'c' && !isModifierKeyPressed) {\n event.preventDefault();\n rowProps.onRowCopy(sanitizedRow, event);\n return;\n }\n\n if (rowProps.onRowDelete && event.key === 'Delete' && !isModifierKeyPressed) {\n event.preventDefault();\n rowProps.onRowDelete(sanitizedRow, event);\n return;\n }\n }\n }\n\n const nextIndex = getNextIndexFromKey(event.key, rows.length, activeIndex);\n\n if (nextIndex !== undefined) {\n event.preventDefault();\n setActiveIndex(nextIndex);\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLElement>): void => {\n if (!useGlobalKeyboardNavigation) {\n onKeyDown(event.nativeEvent);\n }\n };\n\n React.useEffect(() => {\n if (useGlobalKeyboardNavigation) {\n window.addEventListener('keydown', onKeyDown);\n }\n\n return () => {\n if (useGlobalKeyboardNavigation) {\n window.removeEventListener('keydown', onKeyDown);\n }\n };\n }, [onKeyDown]);\n\n const handleFocus = (): void => {\n if (activeIndex === undefined && rows.length) {\n setActiveIndex(0);\n }\n };\n\n return [activeIndex, setActiveIndex, handleKeyDown, handleFocus];\n};\n"],"names":["useTableKeyboardNavigation","props","rows","rowProps","ref","useGlobalKeyboardNavigation","dangerouslyHijackGlobalKeyboardNavigation","activeIndex","setActiveIndex","useControllableState","prop","defaultProp","defaultActiveIndex","undefined","onChange","index","onChangeActiveIndex","onKeyDown","event","isModifierKeyPressed","metaKey","ctrlKey","altKey","shiftKey","document","activeElement","current","getAttribute","body","currentRow","sanitizedRow","sanitizeRowProps","rowExpansionRenderer","onRowClick","key","preventDefault","toggleRowSelected","toggleRowExpanded","isExpanded","toggleRowEditing","canEdit","isEditing","onRowCreate","onRowEdit","onRowCopy","onRowDelete","nextIndex","getNextIndexFromKey","length","handleKeyDown","nativeEvent","React","useEffect","window","addEventListener","removeEventListener","handleFocus"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AA6BX,IAAI,CAAC8C,MAAtC,EAA8C;MAC1CxC,cAAc,CAAC,CAAD,CAAd;;GAFR;;EAMA,OAAO,CAACD,WAAD,EAAcC,cAAd,EAA8ByC,aAA9B,EAA6CO,WAA7C,CAAP;AACH;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rowIndexPath.js","sources":["../../../../../src/components/Table/util/rowIndexPath.ts"],"sourcesContent":["import set from 'lodash/set';\nimport { Row, RowIndexPath } from '../types';\n\nexport const convertRowIndexPathToNumberArray = (rowIndexPath: RowIndexPath): number[] =>\n rowIndexPath?.split('.').map(Number) ?? [];\n\nexport const getByRowIndexPath = <TRow>(data: Row<TRow>[], rowIndexPath: RowIndexPath): Row<TRow> | undefined => {\n if (!rowIndexPath) {\n return undefined;\n }\n\n const currenTRow = [...data];\n const indexes = convertRowIndexPathToNumberArray(String(rowIndexPath));\n\n if (indexes.length) {\n const startIndex = indexes.shift() as number;\n return indexes.reduce((value, index) => value?.subRows?.[index]
|
1
|
+
{"version":3,"file":"rowIndexPath.js","sources":["../../../../../src/components/Table/util/rowIndexPath.ts"],"sourcesContent":["import set from 'lodash/set';\nimport { Row, RowIndexPath } from '../types';\n\nexport const convertRowIndexPathToNumberArray = (rowIndexPath: RowIndexPath): number[] =>\n rowIndexPath?.split('.').map(Number) ?? [];\n\nexport const getByRowIndexPath = <TRow extends {}>(data: Row<TRow>[], rowIndexPath: RowIndexPath): Row<TRow> | undefined => {\n if (!rowIndexPath) {\n return undefined;\n }\n\n const currenTRow = [...data];\n const indexes = convertRowIndexPathToNumberArray(String(rowIndexPath));\n\n if (indexes.length) {\n const startIndex = indexes.shift() as number;\n return indexes.reduce((value, index) => value?.subRows?.[index] as Row<TRow>, currenTRow[startIndex]);\n }\n\n return undefined;\n};\n\nexport const setByRowIndexPath = <TRow extends {}>(data: Row<TRow>[], rowIndexPath: RowIndexPath, values: any): Row<TRow>[] => {\n const nexTRow = [...data];\n\n const rowIndexes = convertRowIndexPathToNumberArray(rowIndexPath);\n const rootIndex = rowIndexes.shift() as number;\n\n if (rowIndexes.length) {\n const path = rowIndexes.map(index => `subRows[${index}]`).join('.');\n set(nexTRow[rootIndex], path, values);\n } else {\n nexTRow[rootIndex] = values;\n }\n\n return nexTRow;\n};\n\nexport const getParentRowIndexPath = (rowIndexPath: RowIndexPath): RowIndexPath => {\n let parentIndexPath;\n\n if (rowIndexPath) {\n const rowIndexes = convertRowIndexPathToNumberArray(rowIndexPath);\n rowIndexes.pop();\n\n if (rowIndexes.length) {\n parentIndexPath = rowIndexes.join('.');\n }\n }\n\n return parentIndexPath;\n};\n"],"names":["convertRowIndexPathToNumberArray","rowIndexPath","split","map","Number","getByRowIndexPath","data","undefined","currenTRow","indexes","String","length","startIndex","shift","reduce","value","index","subRows","setByRowIndexPath","values","nexTRow","rowIndexes","rootIndex","path","join","set","getParentRowIndexPath","parentIndexPath","pop"],"mappings":";;MAGaA,gCAAgC,GAAIC,YAAD;EAAA;;EAAA,gCAC5CA,YAD4C,aAC5CA,YAD4C,uBAC5CA,YAAY,CAAEC,KAAd,CAAoB,GAApB,EAAyBC,GAAzB,CAA6BC,MAA7B,CAD4C,yEACJ,EADI;AAAA;MAGnCC,iBAAiB,GAAG,CAAkBC,IAAlB,EAAqCL,YAArC;EAC7B,IAAI,CAACA,YAAL,EAAmB;IACf,OAAOM,SAAP;;;EAGJ,MAAMC,UAAU,GAAG,CAAC,GAAGF,IAAJ,CAAnB;EACA,MAAMG,OAAO,GAAGT,gCAAgC,CAACU,MAAM,CAACT,YAAD,CAAP,CAAhD;;EAEA,IAAIQ,OAAO,CAACE,MAAZ,EAAoB;IAChB,MAAMC,UAAU,GAAGH,OAAO,CAACI,KAAR,EAAnB;IACA,OAAOJ,OAAO,CAACK,MAAR,CAAe,CAACC,KAAD,EAAQC,KAAR;MAAA;;MAAA,OAAkBD,KAAlB,aAAkBA,KAAlB,yCAAkBA,KAAK,CAAEE,OAAzB,mDAAkB,eAAiBD,KAAjB,CAAlB;KAAf,EAAuER,UAAU,CAACI,UAAD,CAAjF,CAAP;;;EAGJ,OAAOL,SAAP;AACH;MAEYW,iBAAiB,GAAG,CAAkBZ,IAAlB,EAAqCL,YAArC,EAAiEkB,MAAjE;EAC7B,MAAMC,OAAO,GAAG,CAAC,GAAGd,IAAJ,CAAhB;EAEA,MAAMe,UAAU,GAAGrB,gCAAgC,CAACC,YAAD,CAAnD;EACA,MAAMqB,SAAS,GAAGD,UAAU,CAACR,KAAX,EAAlB;;EAEA,IAAIQ,UAAU,CAACV,MAAf,EAAuB;IACnB,MAAMY,IAAI,GAAGF,UAAU,CAAClB,GAAX,CAAea,KAAK,eAAeA,QAAnC,EAA6CQ,IAA7C,CAAkD,GAAlD,CAAb;IACAC,GAAG,CAACL,OAAO,CAACE,SAAD,CAAR,EAAqBC,IAArB,EAA2BJ,MAA3B,CAAH;GAFJ,MAGO;IACHC,OAAO,CAACE,SAAD,CAAP,GAAqBH,MAArB;;;EAGJ,OAAOC,OAAP;AACH;MAEYM,qBAAqB,GAAIzB,YAAD;EACjC,IAAI0B,eAAJ;;EAEA,IAAI1B,YAAJ,EAAkB;IACd,MAAMoB,UAAU,GAAGrB,gCAAgC,CAACC,YAAD,CAAnD;IACAoB,UAAU,CAACO,GAAX;;IAEA,IAAIP,UAAU,CAACV,MAAf,EAAuB;MACnBgB,eAAe,GAAGN,UAAU,CAACG,IAAX,CAAgB,GAAhB,CAAlB;;;;EAIR,OAAOG,eAAP;AACH;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Toaster.js","sources":["../../../../src/components/Toast/Toaster.tsx"],"sourcesContent":["import * as React from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { AnimatePresence, motion } from 'framer-motion';\nimport { ToastOptions, Toast, ToastProps, ToastContent } from './Toast';\nimport './Toast.css';\n\nconst DEFAULT_AUTO_CLOSE_TIMEOUT = 7500;\n\ntype ToastCreator<T> = (content: ToastContent | ((close: () => void) => ToastContent), options?: ToastOptions) => T;\n\nexport interface Toaster<T> extends ToastCreator<T> {\n success: ToastCreator<T>;\n error: ToastCreator<T>;\n warning: ToastCreator<T>;\n information: ToastCreator<T>;\n loading: ToastCreator<T>;\n}\n\nexport interface ToastReference {\n /** Show a success toast */\n success: ToastCreator<void>;\n /** Show an error toast */\n error: ToastCreator<void>;\n /** Show a warning toast */\n warning: ToastCreator<void>;\n /** Show an information toast */\n information: ToastCreator<void>;\n /** Show a loading toast */\n loading: ToastCreator<void>;\n /**\n * Close an existing toast.\n * The toast function returns a reference to the active toast,\n * allowing you to programmatically close it when needed\n */\n close: () => void;\n}\n\nconst ToastContext = React.createContext<Toaster<ToastReference>>({} as Toaster<ToastReference>);\n\nexport interface ToastProviderProps {\n children: React.ReactNode;\n}\n\ntype InternalToast = Omit<ToastProps, 'onClose'>;\n\nconst insertToastWithoutDuplicates = (\n currentToasts: InternalToast[],\n id: string,\n content: ToastContent,\n options: ToastOptions,\n close: () => void\n): InternalToast[] => {\n const nextToasts = [...currentToasts];\n const existingToastIndex = currentToasts.findIndex(toast => JSON.stringify(toast.content) === JSON.stringify(content));\n\n if (existingToastIndex > -1) {\n nextToasts[existingToastIndex].lastDuplicateId = id;\n nextToasts[existingToastIndex].lastUpdated = Date.now();\n } else {\n nextToasts.push({\n id,\n content: typeof content === 'function' ? content(close) : content,\n options,\n });\n }\n\n return nextToasts;\n};\n\nexport const ToastProvider = ({ children, ...props }: ToastProviderProps): JSX.Element => {\n const [toasts, setToasts] = React.useState<InternalToast[]>([]);\n\n const handleClose = (id: string): void => {\n setToasts(currentToasts => currentToasts.filter(toast => toast.id !== id));\n };\n\n // memoize (useCallback) this function,\n // it is the value of the context provider and we don't want it to trigger state tree re-renders on provider children\n const toaster = React.useCallback((content: ToastContent, options: ToastOptions): ToastReference => {\n const id = uuid();\n const close = (): void => handleClose(id);\n\n setToasts(currentToasts => insertToastWithoutDuplicates(currentToasts, id, content, options, close));\n\n const update = (content: ToastContent, options: ToastOptions): void => {\n setToasts(currentToasts => {\n const nextToasts = currentToasts.filter(toast => {\n if (toast.lastDuplicateId) {\n return toast.lastDuplicateId !== id;\n }\n\n return toast.id !== id;\n });\n return insertToastWithoutDuplicates(nextToasts, uuid(), content, options, close);\n });\n };\n\n const success = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT, ...options, type: 'success' });\n };\n const error = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'error' });\n };\n const warning = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'warning' });\n };\n const information = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'information' });\n };\n const loading = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'loading' });\n };\n\n return {\n success,\n error,\n warning,\n information,\n loading,\n close,\n };\n }, []) as Toaster<ToastReference>;\n\n // no need to rebind these every render, do them once in an effect\n React.useEffect(() => {\n toaster.success = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT, ...options, type: 'success' });\n toaster.error = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'error' });\n toaster.warning = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'warning' });\n toaster.information = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'information' });\n toaster.loading = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'loading' });\n }, []);\n\n return (\n <ToastContext.Provider {...props} value={toaster}>\n {children}\n <div\n id=\"yt-toast__container\"\n className=\"pointer-events-all absolute bottom-0 right-0 !left-auto z-[1000] mb-4 mr-4 flex max-w-md flex-col items-end justify-end\"\n role=\"log\">\n <AnimatePresence initial={false}>\n {toasts.map((toast: ToastProps) => (\n <motion.div\n key={toast.id}\n transition={{\n type: 'spring',\n damping: 20,\n stiffness: 300,\n }}\n initial={{ opacity: 0, y: 10, scale: 0.5 }}\n animate={{ opacity: 1, y: 0, scale: 1 }}\n exit={{ opacity: 0, scale: 0.5, transition: { duration: 0.2 } }}>\n <Toast {...toast} onClose={() => handleClose(toast.id)} />\n </motion.div>\n ))}\n </AnimatePresence>\n </div>\n </ToastContext.Provider>\n );\n};\n\nexport const useToast = (): Toaster<ToastReference> => React.useContext(ToastContext);\n"],"names":["DEFAULT_AUTO_CLOSE_TIMEOUT","ToastContext","React","insertToastWithoutDuplicates","currentToasts","id","content","options","close","nextToasts","existingToastIndex","findIndex","toast","JSON","stringify","lastDuplicateId","lastUpdated","Date","now","push","ToastProvider","children","props","toasts","setToasts","handleClose","filter","toaster","uuid","update","success","autoClose","type","error","warning","information","loading","Provider","value","className","role","AnimatePresence","initial","map","motion","div","key","transition","damping","stiffness","opacity","y","scale","animate","exit","duration","Toast","onClose","useToast"],"mappings":";;;;;AAMA,MAAMA,0BAA0B,GAAG,IAAnC;AA+BA,MAAMC,YAAY,gBAAGC,aAAA,CAA6C,EAA7C,CAArB;;AAQA,MAAMC,4BAA4B,GAAG,CACjCC,aADiC,EAEjCC,EAFiC,EAGjCC,OAHiC,EAIjCC,OAJiC,EAKjCC,KALiC;EAOjC,MAAMC,UAAU,GAAG,CAAC,GAAGL,aAAJ,CAAnB;EACA,MAAMM,kBAAkB,GAAGN,aAAa,CAACO,SAAd,CAAwBC,KAAK,IAAIC,IAAI,CAACC,SAAL,CAAeF,KAAK,CAACN,OAArB,MAAkCO,IAAI,CAACC,SAAL,CAAeR,OAAf,CAAnE,CAA3B;;EAEA,IAAII,kBAAkB,GAAG,CAAC,CAA1B,EAA6B;IACzBD,UAAU,CAACC,kBAAD,CAAV,CAA+BK,eAA/B,GAAiDV,EAAjD;IACAI,UAAU,CAACC,kBAAD,CAAV,C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Q,EAAE;;;GAT5D,EAUIrD,aAAA,CAACsD,KAAD,oBAAW5C;IAAO6C,OAAO,EAAE,MAAMhC,WAAW,CAACb,KAAK,CAACP,EAAP;IAA5C,CAVJ,CADH,CADL,CAJJ,CAFJ,CADJ;AA0BH;MAEYqD,QAAQ,GAAG,MAA+BxD,UAAA,CAAiBD,YAAjB;;;;"}
|
1
|
+
{"version":3,"file":"Toaster.js","sources":["../../../../src/components/Toast/Toaster.tsx"],"sourcesContent":["import * as React from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { AnimatePresence, motion } from 'framer-motion';\nimport { ToastOptions, Toast, ToastProps, ToastContent } from './Toast';\nimport './Toast.css';\n\nconst DEFAULT_AUTO_CLOSE_TIMEOUT = 7500;\n\ntype ToastCreator<T> = (content: ToastContent | ((close: () => void) => ToastContent), options?: ToastOptions) => T;\n\nexport interface Toaster<T> extends ToastCreator<T> {\n success: ToastCreator<T>;\n error: ToastCreator<T>;\n warning: ToastCreator<T>;\n information: ToastCreator<T>;\n loading: ToastCreator<T>;\n}\n\nexport interface ToastReference {\n /** Show a success toast */\n success: ToastCreator<void>;\n /** Show an error toast */\n error: ToastCreator<void>;\n /** Show a warning toast */\n warning: ToastCreator<void>;\n /** Show an information toast */\n information: ToastCreator<void>;\n /** Show a loading toast */\n loading: ToastCreator<void>;\n /**\n * Close an existing toast.\n * The toast function returns a reference to the active toast,\n * allowing you to programmatically close it when needed\n */\n close: () => void;\n}\n\nconst ToastContext = React.createContext<Toaster<ToastReference>>({} as Toaster<ToastReference>);\n\nexport interface ToastProviderProps {\n children: React.ReactNode;\n}\n\ntype InternalToast = Omit<ToastProps, 'onClose'>;\n\nconst insertToastWithoutDuplicates = (\n currentToasts: InternalToast[],\n id: string,\n content: ToastContent,\n options: ToastOptions,\n close: () => void\n): InternalToast[] => {\n const nextToasts = [...currentToasts];\n const existingToastIndex = currentToasts.findIndex(toast => JSON.stringify(toast.content) === JSON.stringify(content));\n\n if (existingToastIndex > -1) {\n nextToasts[existingToastIndex].lastDuplicateId = id;\n nextToasts[existingToastIndex].lastUpdated = Date.now();\n } else {\n nextToasts.push({\n id,\n content: typeof content === 'function' ? content(close) : content,\n options,\n });\n }\n\n return nextToasts;\n};\n\nexport const ToastProvider = ({ children, ...props }: ToastProviderProps): JSX.Element => {\n const [toasts, setToasts] = React.useState<InternalToast[]>([]);\n\n const handleClose = (id: string): void => {\n setToasts(currentToasts => currentToasts.filter(toast => toast.id !== id));\n };\n\n // memoize (useCallback) this function,\n // it is the value of the context provider and we don't want it to trigger state tree re-renders on provider children\n const toaster = React.useCallback((content: ToastContent, options: ToastOptions): ToastReference => {\n const id = uuid();\n const close = (): void => handleClose(id);\n\n setToasts(currentToasts => insertToastWithoutDuplicates(currentToasts, id, content, options, close));\n\n const update = (content: ToastContent, options: ToastOptions): void => {\n setToasts(currentToasts => {\n const nextToasts = currentToasts.filter(toast => {\n if (toast.lastDuplicateId) {\n return toast.lastDuplicateId !== id;\n }\n\n return toast.id !== id;\n });\n return insertToastWithoutDuplicates(nextToasts, uuid(), content, options, close);\n });\n };\n\n const success = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT, ...options, type: 'success' });\n };\n const error = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'error' });\n };\n const warning = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'warning' });\n };\n const information = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'information' });\n };\n const loading = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'loading' });\n };\n\n return {\n success,\n error,\n warning,\n information,\n loading,\n close,\n };\n }, []) as Toaster<ToastReference>;\n\n // no need to rebind these every render, do them once in an effect\n React.useEffect(() => {\n toaster.success = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT, ...options, type: 'success' });\n toaster.error = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'error' });\n toaster.warning = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'warning' });\n toaster.information = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'information' });\n toaster.loading = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'loading' });\n }, []);\n\n return (\n <ToastContext.Provider {...props} value={toaster}>\n {children}\n <div\n id=\"yt-toast__container\"\n className=\"pointer-events-all absolute bottom-0 right-0 !left-auto z-[1000] mb-4 mr-4 flex max-w-md flex-col items-end justify-end\"\n role=\"log\">\n <AnimatePresence initial={false}>\n {toasts.map((toast: InternalToast) => (\n <motion.div\n key={toast.id}\n transition={{\n type: 'spring',\n damping: 20,\n stiffness: 300,\n }}\n initial={{ opacity: 0, y: 10, scale: 0.5 }}\n animate={{ opacity: 1, y: 0, scale: 1 }}\n exit={{ opacity: 0, scale: 0.5, transition: { duration: 0.2 } }}>\n <Toast {...toast} onClose={() => handleClose(toast.id)} />\n </motion.div>\n ))}\n </AnimatePresence>\n </div>\n </ToastContext.Provider>\n );\n};\n\nexport const useToast = (): Toaster<ToastReference> => React.useContext(ToastContext);\n"],"names":["DEFAULT_AUTO_CLOSE_TIMEOUT","ToastContext","React","insertToastWithoutDuplicates","currentToasts","id","content","options","close","nextToasts","existingToastIndex","findIndex","toast","JSON","stringify","lastDuplicateId","lastUpdated","Date","now","push","ToastProvider","children","props","toasts","setToasts","handleClose","filter","toaster","uuid","update","success","autoClose","type","error","warning","information","loading","Provider","value","className","role","AnimatePresence","initial","map","motion","div","key","transition","damping","stiffness","opacity","y","scale","animate","exit","duration","Toast","onClose","useToast"],"mappings":";;;;;AAMA,MAAMA,0BAA0B,GAAG,IAAnC;A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AAD;IAAiBC,OAAO,EAAE;GAA1B,EACKnB,MAAM,CAACoB,GAAP,CAAY/B,KAAD,IACRV,aAAA,CAAC0C,MAAM,CAACC,GAAR;IACIC,GAAG,EAAElC,KAAK,CAACP;IACX0C,UAAU,EAAE;MACRf,IAAI,EAAE,QADE;MAERgB,OAAO,EAAE,EAFD;MAGRC,SAAS,EAAE;;IAEfP,OAAO,EAAE;MAAEQ,OAAO,EAAE,CAAX;MAAcC,CAAC,EAAE,EAAjB;MAAqBC,KAAK,EAAE;;IACrCC,OAAO,EAAE;MAAEH,OAAO,EAAE,CAAX;MAAcC,CAAC,EAAE,CAAjB;MAAoBC,KAAK,EAAE;;IACpCE,IAAI,EAAE;MAAEJ,OAAO,EAAE,CAAX;MAAcE,KAAK,EAAE,GAArB;MAA0BL,UAAU,EAAE;QAAEQ,QAAQ,EAAE;;;GAT5D,EAUIrD,aAAA,CAACsD,KAAD,oBAAW5C;IAAO6C,OAAO,EAAE,MAAMhC,WAAW,CAACb,KAAK,CAACP,EAAP;IAA5C,CAVJ,CADH,CADL,CAJJ,CAFJ,CADJ;AA0BH;MAEYqD,QAAQ,GAAG,MAA+BxD,UAAA,CAAiBD,YAAjB;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Button.js","sources":["../../../src/primitives/Button.tsx"],"sourcesContent":["import * as React from 'react';\n\ntype ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement | HTMLAnchorElement> & {\n /** Content should be a text */\n children: React.ReactNode;\n /** Provides url for buttons being used as a link */\n href?: string;\n /** Provides target for buttons being used as a link */\n target?: '_self' | '_blank' | '_parent' | '_top';\n};\n\nconst Button = React.forwardRef(function Button(props: ButtonProps, ref: React.Ref<HTMLButtonElement | HTMLAnchorElement>) {\n const { disabled, target, type = 'button', ...otherProps } = props;\n\n const Tag = props.href ? 'a' : 'button';\n\n return (\n <Tag\n {...otherProps}\n aria-disabled={disabled ? 'true' : undefined}\n disabled={disabled}\n target={Tag === 'a' ? target : undefined}\n type={Tag !== 'a' ? type : undefined}\n ref={ref as any}>\n {React.Children.count(props.children) > 1\n ? React.Children.map(props.children, child => (typeof child === 'string' ? <span>{child}</span> : child))\n : props.children}\n </Tag>\n );\n});\n\nexport { Button
|
1
|
+
{"version":3,"file":"Button.js","sources":["../../../src/primitives/Button.tsx"],"sourcesContent":["import * as React from 'react';\n\ntype ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement | HTMLAnchorElement> & {\n /** Content should be a text */\n children: React.ReactNode;\n /** Provides url for buttons being used as a link */\n href?: string;\n /** Provides target for buttons being used as a link */\n target?: '_self' | '_blank' | '_parent' | '_top';\n};\n\nconst Button = React.forwardRef(function Button(props: ButtonProps, ref: React.Ref<HTMLButtonElement | HTMLAnchorElement>) {\n const { disabled, target, type = 'button', ...otherProps } = props;\n\n const Tag = props.href ? 'a' : 'button';\n\n return (\n <Tag\n {...otherProps}\n aria-disabled={disabled ? 'true' : undefined}\n disabled={disabled}\n target={Tag === 'a' ? target : undefined}\n type={Tag !== 'a' ? type : undefined}\n ref={ref as any}>\n {React.Children.count(props.children) > 1\n ? React.Children.map(props.children, child => (typeof child === 'string' ? <span>{child}</span> : child))\n : props.children}\n </Tag>\n );\n});\n\nexport { Button };\nexport type { ButtonProps };\n"],"names":["Button","React","props","ref","disabled","target","type","otherProps","Tag","href","undefined","count","children","map","child"],"mappings":";;MAWMA,MAAM,gBAAGC,UAAA,CAAiB,SAASD,MAAT,CAAgBE,KAAhB,EAAoCC,GAApC;EAC5B,MAAM;IAAEC,QAAF;IAAYC,MAAZ;IAAoBC,IAAI,GAAG,QAA3B;IAAqC,GAAGC;MAAeL,KAA7D;EAEA,MAAMM,GAAG,GAAGN,KAAK,CAACO,IAAN,GAAa,GAAb,GAAmB,QAA/B;EAEA,OACIR,aAAA,CAACO,GAAD,oBACQD;qBACWH,QAAQ,GAAG,MAAH,GAAYM;IACnCN,QAAQ,EAAEA;IACVC,MAAM,EAAEG,GAAG,KAAK,GAAR,GAAcH,MAAd,GAAuBK;IAC/BJ,IAAI,EAAEE,GAAG,KAAK,GAAR,GAAcF,IAAd,GAAqBI;IAC3BP,GAAG,EAAEA;IANT,EAOKF,QAAA,CAAeU,KAAf,CAAqBT,KAAK,CAACU,QAA3B,IAAuC,CAAvC,GACKX,QAAA,CAAeY,GAAf,CAAmBX,KAAK,CAACU,QAAzB,EAAmCE,KAAK,IAAK,OAAOA,KAAP,KAAiB,QAAjB,GAA4Bb,aAAA,OAAA,MAAA,EAAOa,KAAP,CAA5B,GAAmDA,KAAhG,CADL,GAEKZ,KAAK,CAACU,QAThB,CADJ;AAaH,CAlBc;;;;"}
|
@@ -15,4 +15,5 @@ declare const Button: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes
|
|
15
15
|
/** Provides target for buttons being used as a link */
|
16
16
|
target?: "_self" | "_blank" | "_parent" | "_top" | undefined;
|
17
17
|
} & React.RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
|
18
|
-
export { Button
|
18
|
+
export { Button };
|
19
|
+
export type { ButtonProps };
|
@@ -6337,7 +6337,7 @@ const useMultiListbox = ({
|
|
6337
6337
|
}
|
6338
6338
|
}
|
6339
6339
|
|
6340
|
-
setCurrentIndex(index);
|
6340
|
+
setCurrentIndex(index !== undefined ? index : 0);
|
6341
6341
|
|
6342
6342
|
if (onKeyDown) {
|
6343
6343
|
event.persist();
|
@@ -6995,7 +6995,8 @@ const MenuGroup = /*#__PURE__*/React__default.forwardRef(function MenuGroup(prop
|
|
6995
6995
|
const Menu$2 = /*#__PURE__*/React__default.forwardRef(function Menu(props, ref) {
|
6996
6996
|
const scrollableAreas = React__default.useMemo(() => {
|
6997
6997
|
const scrollableAreas = [];
|
6998
|
-
React__default.Children.toArray(props.children).filter(child => !!child)
|
6998
|
+
const children = React__default.Children.toArray(props.children).filter(child => !!child);
|
6999
|
+
children.forEach(child => {
|
6999
7000
|
if (child.props.fixed) {
|
7000
7001
|
scrollableAreas.push(child);
|
7001
7002
|
} else {
|
@@ -7822,7 +7823,7 @@ const getActions = (actions, row = undefined) => {
|
|
7822
7823
|
const secondary = [];
|
7823
7824
|
|
7824
7825
|
if (actions) {
|
7825
|
-
let visibleActions = actions.filter(x => !!x);
|
7826
|
+
let visibleActions = actions.filter(x => !!x && typeof x !== 'boolean');
|
7826
7827
|
|
7827
7828
|
if (row) {
|
7828
7829
|
visibleActions = visibleActions.filter(action => {
|
@@ -8145,7 +8146,13 @@ const useTableKeyboardNavigation = (props, rows, rowProps, ref) => {
|
|
8145
8146
|
const [activeIndex, setActiveIndex] = reactUseControllableState.useControllableState({
|
8146
8147
|
prop: props.activeIndex,
|
8147
8148
|
defaultProp: props.defaultActiveIndex !== undefined ? props.defaultActiveIndex : useGlobalKeyboardNavigation ? 0 : undefined,
|
8148
|
-
onChange:
|
8149
|
+
onChange: index => {
|
8150
|
+
if (index !== undefined) {
|
8151
|
+
var _props$onChangeActive;
|
8152
|
+
|
8153
|
+
(_props$onChangeActive = props.onChangeActiveIndex) === null || _props$onChangeActive === void 0 ? void 0 : _props$onChangeActive.call(props, index);
|
8154
|
+
}
|
8155
|
+
}
|
8149
8156
|
});
|
8150
8157
|
|
8151
8158
|
const onKeyDown = event => {
|