@coveord/plasma-mantine 56.2.2 → 56.2.4
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/.turbo/turbo-build.log +4 -4
- package/.turbo/turbo-test.log +60 -61
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/components/button/ButtonWithDisabledTooltip.d.ts.map +1 -1
- package/dist/cjs/components/button/ButtonWithDisabledTooltip.js +1 -2
- package/dist/cjs/components/button/ButtonWithDisabledTooltip.js.map +1 -1
- package/dist/cjs/components/collection/Collection.js +1 -0
- package/dist/cjs/components/collection/Collection.js.map +1 -1
- package/dist/cjs/components/collection/Collection.module.css +4 -0
- package/dist/cjs/components/table/table-date-range-picker/TableDateRangePicker.js +1 -1
- package/dist/cjs/components/table/table-date-range-picker/TableDateRangePicker.js.map +1 -1
- package/dist/esm/components/button/ButtonWithDisabledTooltip.d.ts.map +1 -1
- package/dist/esm/components/button/ButtonWithDisabledTooltip.js +0 -1
- package/dist/esm/components/button/ButtonWithDisabledTooltip.js.map +1 -1
- package/dist/esm/components/collection/Collection.js +1 -0
- package/dist/esm/components/collection/Collection.js.map +1 -1
- package/dist/esm/components/collection/Collection.module.css +4 -0
- package/dist/esm/components/table/table-date-range-picker/TableDateRangePicker.js +1 -1
- package/dist/esm/components/table/table-date-range-picker/TableDateRangePicker.js.map +1 -1
- package/package.json +17 -17
- package/src/components/button/ButtonWithDisabledTooltip.tsx +1 -6
- package/src/components/collection/Collection.module.css +4 -0
- package/src/components/collection/Collection.tsx +1 -1
- package/src/components/collection/__tests__/Collection.spec.tsx +5 -3
- package/src/components/date-range-picker/__tests__/DateRangePickerInlineCalendar.spec.tsx +5 -5
- package/src/components/date-range-picker/__tests__/DateRangePickerPresetSelect.spec.tsx +1 -1
- package/src/components/table/__tests__/TableDateRangePicker.spec.tsx +3 -3
- package/src/components/table/__tests__/TablePagination.spec.tsx +5 -3
- package/src/components/table/__tests__/TablePerPage.spec.tsx +1 -1
- package/src/components/table/layouts/__tests__/RowLayout.spec.tsx +1 -1
- package/src/components/table/table-date-range-picker/TableDateRangePicker.tsx +1 -1
- package/src/hooks/__tests__/useControlledList.spec.tsx +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ButtonWithDisabledTooltip.d.ts","sourceRoot":"","sources":["../../../../src/components/button/ButtonWithDisabledTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAC,MAAM,eAAe,CAAC;AACzD,OAAO,EAAC,SAAS,EAAa,MAAM,OAAO,CAAC;AAI5C,MAAM,WAAW,8BAA8B;IAC3C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;OAEG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC,CAAC;IAC7E;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;
|
|
1
|
+
{"version":3,"file":"ButtonWithDisabledTooltip.d.ts","sourceRoot":"","sources":["../../../../src/components/button/ButtonWithDisabledTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAC,MAAM,eAAe,CAAC;AACzD,OAAO,EAAC,SAAS,EAAa,MAAM,OAAO,CAAC;AAI5C,MAAM,WAAW,8BAA8B;IAC3C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;OAEG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC,CAAC;IAC7E;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;AAeD,eAAO,MAAM,yBAAyB;;;;;;mCAErC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/button/ButtonWithDisabledTooltip.tsx"],"sourcesContent":["import {Box, Tooltip, TooltipProps} from '@mantine/core';\nimport {ReactNode, forwardRef} from 'react';\n\nimport {createPolymorphicComponent} from '../../utils/index.js';\n\nexport interface ButtonWithDisabledTooltipProps {\n /**\n * The tooltip message to display when disabled\n */\n disabledTooltip?: string;\n /**\n * Whether the button underneath the tooltip is disabled\n */\n disabled?: boolean;\n children?: ReactNode;\n /**\n * Additional tooltip props to set on the disabled button tooltip\n */\n disabledTooltipProps?: Omit<TooltipProps, 'disabled' | 'label' | 'children'>;\n /**\n * Sets button width to 100% of parent element\n */\n fullWidth?: boolean;\n}\n\nconst _ButtonWithDisabledTooltip = forwardRef<HTMLDivElement, ButtonWithDisabledTooltipProps>(\n ({disabledTooltip, disabled, children, disabledTooltipProps, fullWidth, ...others}, ref) =>\n disabledTooltip ? (\n <Tooltip label={disabledTooltip} disabled={!disabled} {...disabledTooltipProps}>\n <Box
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/button/ButtonWithDisabledTooltip.tsx"],"sourcesContent":["import {Box, Tooltip, TooltipProps} from '@mantine/core';\nimport {ReactNode, forwardRef} from 'react';\n\nimport {createPolymorphicComponent} from '../../utils/index.js';\n\nexport interface ButtonWithDisabledTooltipProps {\n /**\n * The tooltip message to display when disabled\n */\n disabledTooltip?: string;\n /**\n * Whether the button underneath the tooltip is disabled\n */\n disabled?: boolean;\n children?: ReactNode;\n /**\n * Additional tooltip props to set on the disabled button tooltip\n */\n disabledTooltipProps?: Omit<TooltipProps, 'disabled' | 'label' | 'children'>;\n /**\n * Sets button width to 100% of parent element\n */\n fullWidth?: boolean;\n}\n\nconst _ButtonWithDisabledTooltip = forwardRef<HTMLDivElement, ButtonWithDisabledTooltipProps>(\n ({disabledTooltip, disabled, children, disabledTooltipProps, fullWidth, ...others}, ref) =>\n disabledTooltip ? (\n <Tooltip label={disabledTooltip} disabled={!disabled} {...disabledTooltipProps}>\n <Box ref={ref} style={{'&:hover': {cursor: 'not-allowed'}, width: fullWidth && '100%'}} {...others}>\n {children}\n </Box>\n </Tooltip>\n ) : (\n <>{children}</>\n ),\n);\n\nexport const ButtonWithDisabledTooltip = createPolymorphicComponent<'div', ButtonWithDisabledTooltipProps>(\n _ButtonWithDisabledTooltip,\n);\n"],"names":["ButtonWithDisabledTooltip","_ButtonWithDisabledTooltip","forwardRef","ref","disabledTooltip","disabled","children","disabledTooltipProps","fullWidth","others","Tooltip","label","Box","style","cursor","width","createPolymorphicComponent"],"mappings":";;;;+BAsCaA;;;eAAAA;;;;;;;oBAtC4B;qBACL;qBAEK;AAsBzC,IAAMC,2CAA6BC,IAAAA,iBAAU,EACzC,iBAAoFC;QAAlFC,yBAAAA,iBAAiBC,kBAAAA,UAAUC,kBAAAA,UAAUC,8BAAAA,sBAAsBC,mBAAAA,WAAcC;QAAzEL;QAAiBC;QAAUC;QAAUC;QAAsBC;;WACzDJ,gCACI,qBAACM,aAAO;QAACC,OAAOP;QAAiBC,UAAU,CAACA;OAAcE;kBACtD,cAAA,qBAACK,SAAG;YAACT,KAAKA;YAAKU,OAAO;gBAAC,WAAW;oBAACC,QAAQ;gBAAa;gBAAGC,OAAOP,aAAa;YAAM;WAAOC;sBACvFH;;wBAIT;kBAAGA;;;AAIR,IAAMN,4BAA4BgB,IAAAA,iCAA0B,EAC/Df"}
|
|
@@ -134,6 +134,7 @@ var Collection = function(props) {
|
|
|
134
134
|
var _allowAdd;
|
|
135
135
|
var addAllowed = (_allowAdd = allowAdd === null || allowAdd === void 0 ? void 0 : allowAdd(value)) !== null && _allowAdd !== void 0 ? _allowAdd : true;
|
|
136
136
|
var _addButton = canEdit ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_core1.Box, {
|
|
137
|
+
className: _Collectionmodulecss.default.addButtonContainer,
|
|
137
138
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_index1.Button.Quaternary, {
|
|
138
139
|
leftSection: /*#__PURE__*/ (0, _jsxruntime.jsx)(_plasmareacticons.IconPlus, {
|
|
139
140
|
size: 16
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/collection/Collection.tsx"],"sourcesContent":["import {IconPlus} from '@coveord/plasma-react-icons';\nimport {DndContext, DragEndEvent, KeyboardSensor, PointerSensor, useSensor, useSensors} from '@dnd-kit/core';\nimport {restrictToParentElement, restrictToVerticalAxis} from '@dnd-kit/modifiers';\nimport {SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy} from '@dnd-kit/sortable';\nimport {\n __InputWrapperProps,\n Box,\n BoxProps,\n Factory,\n Input,\n MantineSpacing,\n Stack,\n StylesApiProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport {useDidUpdate} from '@mantine/hooks';\nimport {ForwardedRef, ReactNode} from 'react';\n\nimport {CustomComponentThemeExtend, identity} from '../../utils/index.js';\nimport {Button} from '../button/index.js';\nimport classes from './Collection.module.css';\nimport {CollectionProvider} from './CollectionContext.js';\nimport {CollectionItem} from './CollectionItem.js';\n\nexport interface CollectionProps<T> extends __InputWrapperProps, BoxProps, StylesApiProps<CollectionFactory> {\n /**\n * The default value each new item should have\n */\n newItem: T;\n /**\n * A render function called for each item passed in the `value` prop.\n *\n * @param item The current item's value\n * @param index The current item's index\n */\n children: (item: T, index: number) => ReactNode;\n /**\n * The list of items to display inside the collection\n *\n * @default []\n */\n value?: T[];\n /**\n * Defines how each item is uniquely identified. It is highly recommended that you specify this prop to an ID that makes sense.\n *\n * This method is required when using this component with ReactHookForm.\n *\n * @see {@link https://react-hook-form.com/api/usefieldarray/} for using a collection with ReactHookForm.\n *\n * @param originalItem The original item\n * @param itemIndex The index of the original item\n */\n getItemId?: (originalItem: T, itemIndex: number) => string;\n /**\n * Unused, has no effect\n */\n onFocus?: () => void;\n /**\n * Function called whenever the value needs to be updated\n *\n * @param value The whole list of items after the change\n */\n onChange?: (value: T[]) => void;\n /**\n * Function called after an item is removed from the collection using the remove button\n *\n * @param itemIndex The index of the item that was removed\n */\n onRemoveItem?: (itemIndex: number) => void;\n /**\n * Function that gets called whenever a collection item needs to be reordered\n *\n * @param payload The origin and destination index of the item to reorder\n */\n onReorderItem?: (payload: {from: number; to: number}) => void;\n /**\n * Function that gets called when a new item needs to be added to the collection\n *\n * @param value The value of the item to insert\n * @param index The index of the new item to insert\n */\n onInsertItem?: (value: T, index: number) => void;\n /**\n * Whether the collection should have drag and drop behavior enabled\n *\n * @default false\n */\n draggable?: boolean;\n /**\n * Whether the collection is disabled, or in other words in read only mode\n *\n * @default false\n */\n disabled?: boolean;\n /**\n * Whether the collection is readOnly. If true, the collection will not allow adding or removing items\n *\n * @default false\n */\n readOnly?: boolean;\n /**\n * Function that determines if the add item button should be enabled given the current items of the collection.\n * The button is always enabled if this props remains undefined\n *\n * @param values The current items of the collection\n */\n allowAdd?: (values: T[]) => boolean;\n /**\n * The label of the add item button\n *\n * @default \"Add item\"\n */\n addLabel?: string;\n /**\n * The tooltip text displayed when hovering over the disabled add item button\n *\n * @default 'There is already an empty item'\n */\n addDisabledTooltip?: string;\n /**\n * The gap between the colleciton items\n *\n * @default 'xs'\n */\n gap?: MantineSpacing;\n /**\n * Whether the collection is required. When required is true, the collection will hide the remove button if there is only one item\n *\n * @default false\n */\n required?: boolean;\n}\n\nexport type CollectionStylesNames = 'root' | 'item' | 'items' | 'itemDragging' | 'dragHandle';\n\nexport type CollectionFactory = Factory<{\n props: CollectionProps<unknown>;\n ref: HTMLDivElement;\n stylesNames: CollectionStylesNames;\n}>;\n\nconst defaultProps: Partial<CollectionProps<unknown>> = {\n draggable: false,\n addLabel: 'Add item',\n addDisabledTooltip: 'There is already an empty item',\n disabled: false,\n readOnly: false,\n gap: 'md',\n required: false,\n getItemId: ({id}: any) => id,\n};\n\nexport const Collection = <T,>(props: CollectionProps<T> & {ref?: ForwardedRef<HTMLDivElement>}) => {\n const {\n value,\n onChange,\n onRemoveItem,\n onReorderItem,\n onInsertItem,\n disabled,\n readOnly,\n draggable,\n children,\n gap,\n required,\n newItem,\n addLabel,\n addDisabledTooltip,\n allowAdd,\n label,\n labelProps,\n withAsterisk,\n description,\n descriptionProps,\n error,\n errorProps,\n getItemId,\n ref,\n\n // Style props\n style,\n className,\n classNames,\n styles,\n unstyled,\n ...others\n } = useProps('Collection', defaultProps as CollectionProps<T>, props);\n\n const getStyles = useStyles<CollectionFactory>({\n name: 'Collection',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n });\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n }),\n );\n\n const canEdit = !disabled && !readOnly;\n const hasOnlyOneItem = value.length === 1;\n\n /**\n * Enforcing onChange when the value is modified will make sure the errors are carried through.\n */\n useDidUpdate(() => {\n onChange?.(value);\n }, [JSON.stringify(value)]);\n\n const isRequired = typeof withAsterisk === 'boolean' ? withAsterisk : required;\n const _label = label ? (\n <Input.Label required={isRequired} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n const _error = error ? <Input.Error {...errorProps}>{error}</Input.Error> : null;\n const _header =\n _label || _description ? (\n <Stack gap=\"xxs\" pb=\"xs\">\n {_label}\n {_description}\n </Stack>\n ) : null;\n\n const standardizedItems = value.map((item, index) => ({id: getItemId?.(item, index) ?? String(index), data: item}));\n\n const items = standardizedItems.map((item, index) => (\n <CollectionItem\n key={item.id}\n id={item.id}\n disabled={!canEdit}\n draggable={draggable}\n onRemove={() => onRemoveItem?.(index)}\n removable={!(required && hasOnlyOneItem)}\n >\n {children(item.data, index)}\n </CollectionItem>\n ));\n\n const addAllowed = allowAdd?.(value) ?? true;\n\n const _addButton = canEdit ? (\n <Box>\n <Button.Quaternary\n leftSection={<IconPlus size={16} />}\n onClick={() => onInsertItem(newItem, value?.length ?? 0)}\n disabled={!addAllowed}\n disabledTooltip={addDisabledTooltip}\n >\n {addLabel}\n </Button.Quaternary>\n </Box>\n ) : null;\n\n const getIndex = (id: string) => standardizedItems.findIndex((item) => item.id === id);\n\n const handleDragEnd = ({over, active}: DragEndEvent): void => {\n if (over) {\n const activeIndex = getIndex(String(active.id));\n const overIndex = getIndex(String(over.id));\n if (activeIndex !== overIndex) {\n onReorderItem?.({from: activeIndex, to: overIndex});\n }\n }\n };\n\n return (\n <CollectionProvider value={{getStyles}}>\n <DndContext\n onDragEnd={handleDragEnd}\n sensors={sensors}\n modifiers={[restrictToVerticalAxis, restrictToParentElement]}\n >\n <SortableContext items={standardizedItems} strategy={verticalListSortingStrategy}>\n <Box ref={ref} {...others} {...getStyles('root')}>\n {_header}\n <Stack gap={gap} {...getStyles('items')}>\n {items}\n {_addButton}\n {_error}\n </Stack>\n </Box>\n </SortableContext>\n </DndContext>\n </CollectionProvider>\n );\n};\n\nCollection.extend = identity as CustomComponentThemeExtend<CollectionFactory>;\n"],"names":["Collection","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","readOnly","gap","required","getItemId","id","props","useProps","value","onChange","onRemoveItem","onReorderItem","onInsertItem","children","newItem","allowAdd","label","labelProps","withAsterisk","description","descriptionProps","error","errorProps","ref","style","className","classNames","styles","unstyled","others","getStyles","useStyles","name","classes","sensors","useSensors","useSensor","PointerSensor","KeyboardSensor","coordinateGetter","sortableKeyboardCoordinates","canEdit","hasOnlyOneItem","length","useDidUpdate","JSON","stringify","isRequired","_label","Input","Label","_description","Description","_error","Error","_header","Stack","pb","standardizedItems","map","item","index","String","data","items","CollectionItem","onRemove","removable","addAllowed","_addButton","Box","Button","Quaternary","leftSection","IconPlus","size","onClick","disabledTooltip","getIndex","findIndex","handleDragEnd","over","active","activeIndex","overIndex","from","to","CollectionProvider","DndContext","onDragEnd","modifiers","restrictToVerticalAxis","restrictToParentElement","SortableContext","strategy","verticalListSortingStrategy","extend","identity"],"mappings":";;;;+BAyJaA;;;eA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ASM,QAAYC,UAAU;;wBACpCyB;sCACD,sBAACC,YAAK;4BAACtD,KAAKA;2BAAS4B,UAAU;;gCAC1BkC;gCACAK;gCACAhB;;;;;;;;AAO7B;AAEA1D,WAAWqG,MAAM,GAAGC,eAAQ"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/collection/Collection.tsx"],"sourcesContent":["import {IconPlus} from '@coveord/plasma-react-icons';\nimport {DndContext, DragEndEvent, KeyboardSensor, PointerSensor, useSensor, useSensors} from '@dnd-kit/core';\nimport {restrictToParentElement, restrictToVerticalAxis} from '@dnd-kit/modifiers';\nimport {SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy} from '@dnd-kit/sortable';\nimport {\n __InputWrapperProps,\n Box,\n BoxProps,\n Factory,\n Input,\n MantineSpacing,\n Stack,\n StylesApiProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport {useDidUpdate} from '@mantine/hooks';\nimport {ForwardedRef, ReactNode} from 'react';\n\nimport {CustomComponentThemeExtend, identity} from '../../utils/index.js';\nimport {Button} from '../button/index.js';\nimport classes from './Collection.module.css';\nimport {CollectionProvider} from './CollectionContext.js';\nimport {CollectionItem} from './CollectionItem.js';\n\nexport interface CollectionProps<T> extends __InputWrapperProps, BoxProps, StylesApiProps<CollectionFactory> {\n /**\n * The default value each new item should have\n */\n newItem: T;\n /**\n * A render function called for each item passed in the `value` prop.\n *\n * @param item The current item's value\n * @param index The current item's index\n */\n children: (item: T, index: number) => ReactNode;\n /**\n * The list of items to display inside the collection\n *\n * @default []\n */\n value?: T[];\n /**\n * Defines how each item is uniquely identified. It is highly recommended that you specify this prop to an ID that makes sense.\n *\n * This method is required when using this component with ReactHookForm.\n *\n * @see {@link https://react-hook-form.com/api/usefieldarray/} for using a collection with ReactHookForm.\n *\n * @param originalItem The original item\n * @param itemIndex The index of the original item\n */\n getItemId?: (originalItem: T, itemIndex: number) => string;\n /**\n * Unused, has no effect\n */\n onFocus?: () => void;\n /**\n * Function called whenever the value needs to be updated\n *\n * @param value The whole list of items after the change\n */\n onChange?: (value: T[]) => void;\n /**\n * Function called after an item is removed from the collection using the remove button\n *\n * @param itemIndex The index of the item that was removed\n */\n onRemoveItem?: (itemIndex: number) => void;\n /**\n * Function that gets called whenever a collection item needs to be reordered\n *\n * @param payload The origin and destination index of the item to reorder\n */\n onReorderItem?: (payload: {from: number; to: number}) => void;\n /**\n * Function that gets called when a new item needs to be added to the collection\n *\n * @param value The value of the item to insert\n * @param index The index of the new item to insert\n */\n onInsertItem?: (value: T, index: number) => void;\n /**\n * Whether the collection should have drag and drop behavior enabled\n *\n * @default false\n */\n draggable?: boolean;\n /**\n * Whether the collection is disabled, or in other words in read only mode\n *\n * @default false\n */\n disabled?: boolean;\n /**\n * Whether the collection is readOnly. If true, the collection will not allow adding or removing items\n *\n * @default false\n */\n readOnly?: boolean;\n /**\n * Function that determines if the add item button should be enabled given the current items of the collection.\n * The button is always enabled if this props remains undefined\n *\n * @param values The current items of the collection\n */\n allowAdd?: (values: T[]) => boolean;\n /**\n * The label of the add item button\n *\n * @default \"Add item\"\n */\n addLabel?: string;\n /**\n * The tooltip text displayed when hovering over the disabled add item button\n *\n * @default 'There is already an empty item'\n */\n addDisabledTooltip?: string;\n /**\n * The gap between the colleciton items\n *\n * @default 'xs'\n */\n gap?: MantineSpacing;\n /**\n * Whether the collection is required. When required is true, the collection will hide the remove button if there is only one item\n *\n * @default false\n */\n required?: boolean;\n}\n\nexport type CollectionStylesNames = 'root' | 'item' | 'items' | 'itemDragging' | 'dragHandle';\n\nexport type CollectionFactory = Factory<{\n props: CollectionProps<unknown>;\n ref: HTMLDivElement;\n stylesNames: CollectionStylesNames;\n}>;\n\nconst defaultProps: Partial<CollectionProps<unknown>> = {\n draggable: false,\n addLabel: 'Add item',\n addDisabledTooltip: 'There is already an empty item',\n disabled: false,\n readOnly: false,\n gap: 'md',\n required: false,\n getItemId: ({id}: any) => id,\n};\n\nexport const Collection = <T,>(props: CollectionProps<T> & {ref?: ForwardedRef<HTMLDivElement>}) => {\n const {\n value,\n onChange,\n onRemoveItem,\n onReorderItem,\n onInsertItem,\n disabled,\n readOnly,\n draggable,\n children,\n gap,\n required,\n newItem,\n addLabel,\n addDisabledTooltip,\n allowAdd,\n label,\n labelProps,\n withAsterisk,\n description,\n descriptionProps,\n error,\n errorProps,\n getItemId,\n ref,\n\n // Style props\n style,\n className,\n classNames,\n styles,\n unstyled,\n ...others\n } = useProps('Collection', defaultProps as CollectionProps<T>, props);\n\n const getStyles = useStyles<CollectionFactory>({\n name: 'Collection',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n });\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n }),\n );\n\n const canEdit = !disabled && !readOnly;\n const hasOnlyOneItem = value.length === 1;\n\n /**\n * Enforcing onChange when the value is modified will make sure the errors are carried through.\n */\n useDidUpdate(() => {\n onChange?.(value);\n }, [JSON.stringify(value)]);\n\n const isRequired = typeof withAsterisk === 'boolean' ? withAsterisk : required;\n const _label = label ? (\n <Input.Label required={isRequired} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n const _error = error ? <Input.Error {...errorProps}>{error}</Input.Error> : null;\n const _header =\n _label || _description ? (\n <Stack gap=\"xxs\" pb=\"xs\">\n {_label}\n {_description}\n </Stack>\n ) : null;\n\n const standardizedItems = value.map((item, index) => ({id: getItemId?.(item, index) ?? String(index), data: item}));\n\n const items = standardizedItems.map((item, index) => (\n <CollectionItem\n key={item.id}\n id={item.id}\n disabled={!canEdit}\n draggable={draggable}\n onRemove={() => onRemoveItem?.(index)}\n removable={!(required && hasOnlyOneItem)}\n >\n {children(item.data, index)}\n </CollectionItem>\n ));\n\n const addAllowed = allowAdd?.(value) ?? true;\n\n const _addButton = canEdit ? (\n <Box className={classes.addButtonContainer}>\n <Button.Quaternary\n leftSection={<IconPlus size={16} />}\n onClick={() => onInsertItem(newItem, value?.length ?? 0)}\n disabled={!addAllowed}\n disabledTooltip={addDisabledTooltip}\n >\n {addLabel}\n </Button.Quaternary>\n </Box>\n ) : null;\n\n const getIndex = (id: string) => standardizedItems.findIndex((item) => item.id === id);\n\n const handleDragEnd = ({over, active}: DragEndEvent): void => {\n if (over) {\n const activeIndex = getIndex(String(active.id));\n const overIndex = getIndex(String(over.id));\n if (activeIndex !== overIndex) {\n onReorderItem?.({from: activeIndex, to: overIndex});\n }\n }\n };\n\n return (\n <CollectionProvider value={{getStyles}}>\n <DndContext\n onDragEnd={handleDragEnd}\n sensors={sensors}\n modifiers={[restrictToVerticalAxis, restrictToParentElement]}\n >\n <SortableContext items={standardizedItems} strategy={verticalListSortingStrategy}>\n <Box ref={ref} {...others} {...getStyles('root')}>\n {_header}\n <Stack gap={gap} {...getStyles('items')}>\n {items}\n {_addButton}\n {_error}\n </Stack>\n </Box>\n </SortableContext>\n </DndContext>\n </CollectionProvider>\n );\n};\n\nCollection.extend = identity as CustomComponentThemeExtend<CollectionFactory>;\n"],"names":["Collection","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","readOnly","gap","required","getItemId","id","props","useProps","value","onChange","onRemoveItem","onReorderItem","onInsertItem","children","newItem","allowAdd","label","labelProps","withAsterisk","description","descriptionProps","error","errorProps","ref","style","className","classNames","styles","unstyled","others","getStyles","useStyles","name","classes","sensors","useSensors","useSensor","PointerSensor","KeyboardSensor","coordinateGetter","sortableKeyboardCoordinates","canEdit","hasOnlyOneItem","length","useDidUpdate","JSON","stringify","isRequired","_label","Input","Label","_description","Description","_error","Error","_header","Stack","pb","standardizedItems","map","item","index","String","data","items","CollectionItem","onRemove","removable","addAllowed","_addButton","Box","addButtonContainer","Button","Quaternary","leftSection","IconPlus","size","onClick","disabledTooltip","getIndex","findIndex","handleDragEnd","over","active","activeIndex","overIndex","from","to","CollectionProvider","DndContext","onDragEnd","modifiers","restrictToVerticalAxis","restrictToParentElement","SortableContext","strategy","verticalListSortingStrategy","extend","identity"],"mappings":";;;;+BAyJaA;;;eAAAA;;;;;;;;gCAzJU;oBACsE;yBAC/B;wBAC0B;qBAYjF;qBACoB;qBAGwB;sBAC9B;4EACD;iCACa;8BACJ;AAuH7B,IAAMC,eAAkD;IACpDC,WAAW;IACXC,UAAU;IACVC,oBAAoB;IACpBC,UAAU;IACVC,UAAU;IACVC,KAAK;IACLC,UAAU;IACVC,WAAW;YAAEC,WAAAA;eAAaA;;AAC9B;AAEO,IAAMV,aAAa,SAAKW;IAC3B,IAiCIC,YAAAA,IAAAA,eAAQ,EAAC,cAAcX,cAAoCU,QAhC3DE,QAgCAD,UAhCAC,OACAC,WA+BAF,UA/BAE,UACAC,eA8BAH,UA9BAG,cACAC,gBA6BAJ,UA7BAI,eACAC,eA4BAL,UA5BAK,cACAZ,WA2BAO,UA3BAP,UACAC,WA0BAM,UA1BAN,UACAJ,YAyBAU,UAzBAV,WACAgB,WAwBAN,UAxBAM,UACAX,MAuBAK,UAvBAL,KACAC,WAsBAI,UAtBAJ,UACAW,UAqBAP,UArBAO,SACAhB,WAoBAS,UApBAT,UACAC,qBAmBAQ,UAnBAR,oBACAgB,WAkBAR,UAlBAQ,UACAC,QAiBAT,UAjBAS,OACAC,aAgBAV,UAhBAU,YACAC,eAeAX,UAfAW,cACAC,cAcAZ,UAdAY,aACAC,mBAaAb,UAbAa,kBACAC,QAYAd,UAZAc,OACAC,aAWAf,UAXAe,YACAlB,YAUAG,UAVAH,WACAmB,MASAhB,UATAgB,KAEA,cAAc;IACdC,QAMAjB,UANAiB,OACAC,YAKAlB,UALAkB,WACAC,aAIAnB,UAJAmB,YACAC,SAGApB,UAHAoB,QACAC,WAEArB,UAFAqB,UACGC,sCACHtB;QAhCAC;QACAC;QACAC;QACAC;QACAC;QACAZ;QACAC;QACAJ;QACAgB;QACAX;QACAC;QACAW;QACAhB;QACAC;QACAgB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAlB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,yBAAe;gBAAC9B,OAAON;gBAAmBqC,UAAUC,qCAA2B;0BAC5E,cAAA,sBAAC1B,UAAG;oBAAC/C,KAAKA;mBAASM,QAAYC,UAAU;;wBACpCyB;sCACD,sBAACC,YAAK;4BAACtD,KAAKA;2BAAS4B,UAAU;;gCAC1BkC;gCACAK;gCACAhB;;;;;;;;AAO7B;AAEA1D,WAAWsG,MAAM,GAAGC,eAAQ"}
|
|
@@ -48,7 +48,7 @@ var TableDateRangePicker = (0, _core.factory)(function(props, ref) {
|
|
|
48
48
|
setOpened(false);
|
|
49
49
|
};
|
|
50
50
|
var formatDate = function(date) {
|
|
51
|
-
return (0, _dayjs.default)(date).format('MMM
|
|
51
|
+
return (0, _dayjs.default)(date).format('MMM D, YYYY');
|
|
52
52
|
};
|
|
53
53
|
var formattedRange = "".concat(formatDate(store.state.dateRange[0]), " - ").concat(formatDate(store.state.dateRange[1]));
|
|
54
54
|
var dateRangeInitialized = store.state.dateRange.every(function(date) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/table/table-date-range-picker/TableDateRangePicker.tsx"],"sourcesContent":["import {CalendarSize16Px} from '@coveord/plasma-react-icons';\nimport {BoxProps, CompoundStylesApiProps, Factory, factory, Grid, InputBase, Popover, useProps} from '@mantine/core';\nimport dayjs from 'dayjs';\n\nimport {type DatesRangeValue, type DateStringValue} from '@mantine/dates';\nimport {useState} from 'react';\nimport {\n DateRangePickerInlineCalendar,\n DateRangePickerInlineCalendarProps,\n DateRangePickerPreset,\n} from '../../date-range-picker/index.js';\nimport {TableComponentsOrder} from '../Table.js';\nimport {useTableContext} from '../TableContext.js';\n\nexport type TableDateRangePickerStylesNames = 'dateRangeRoot';\n\nexport interface TableDateRangePickerProps\n extends BoxProps,\n CompoundStylesApiProps<TableDateRangePickerFactory>,\n Pick<DateRangePickerInlineCalendarProps, 'startProps' | 'endProps' | 'rangeCalendarProps'> {\n /**\n * An object containing date presets.\n * If empty the preset dropdown won't be shown\n *\n * @example\n * {\n * january: {label: 'January', range: [new Date(2022, 0, 1), new Date(2022, 0, 31)]},\n * february: {label: 'February', range: [new Date(2022, 1, 1), new Date(2022, 1, 28)]}\n * }\n * @default {}\n */\n presets?: Record<string, DateRangePickerPreset>;\n}\n\nexport type TableDateRangePickerFactory = Factory<{\n props: TableDateRangePickerProps;\n ref: HTMLDivElement;\n stylesNames: TableDateRangePickerStylesNames;\n compound: true;\n}>;\n\nconst defaultProps: Partial<TableDateRangePickerProps> = {\n presets: {},\n};\n\nexport const TableDateRangePicker = factory<TableDateRangePickerFactory>((props, ref) => {\n const {store, getStyles} = useTableContext();\n const {presets, rangeCalendarProps, classNames, className, styles, style, vars, ...others} = useProps(\n 'PlasmaTableDateRangePicker',\n defaultProps,\n props,\n );\n const [opened, setOpened] = useState(false);\n\n const onApply = (dates: DatesRangeValue<DateStringValue | null>) => {\n store.setDateRange(dates);\n store.setPagination({pageIndex: 0, pageSize: store.state.pagination.pageSize});\n setOpened(false);\n };\n\n const onCancel = () => {\n setOpened(false);\n };\n\n const formatDate = (date: DateStringValue) => dayjs(date).format('MMM
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/table/table-date-range-picker/TableDateRangePicker.tsx"],"sourcesContent":["import {CalendarSize16Px} from '@coveord/plasma-react-icons';\nimport {BoxProps, CompoundStylesApiProps, Factory, factory, Grid, InputBase, Popover, useProps} from '@mantine/core';\nimport dayjs from 'dayjs';\n\nimport {type DatesRangeValue, type DateStringValue} from '@mantine/dates';\nimport {useState} from 'react';\nimport {\n DateRangePickerInlineCalendar,\n DateRangePickerInlineCalendarProps,\n DateRangePickerPreset,\n} from '../../date-range-picker/index.js';\nimport {TableComponentsOrder} from '../Table.js';\nimport {useTableContext} from '../TableContext.js';\n\nexport type TableDateRangePickerStylesNames = 'dateRangeRoot';\n\nexport interface TableDateRangePickerProps\n extends BoxProps,\n CompoundStylesApiProps<TableDateRangePickerFactory>,\n Pick<DateRangePickerInlineCalendarProps, 'startProps' | 'endProps' | 'rangeCalendarProps'> {\n /**\n * An object containing date presets.\n * If empty the preset dropdown won't be shown\n *\n * @example\n * {\n * january: {label: 'January', range: [new Date(2022, 0, 1), new Date(2022, 0, 31)]},\n * february: {label: 'February', range: [new Date(2022, 1, 1), new Date(2022, 1, 28)]}\n * }\n * @default {}\n */\n presets?: Record<string, DateRangePickerPreset>;\n}\n\nexport type TableDateRangePickerFactory = Factory<{\n props: TableDateRangePickerProps;\n ref: HTMLDivElement;\n stylesNames: TableDateRangePickerStylesNames;\n compound: true;\n}>;\n\nconst defaultProps: Partial<TableDateRangePickerProps> = {\n presets: {},\n};\n\nexport const TableDateRangePicker = factory<TableDateRangePickerFactory>((props, ref) => {\n const {store, getStyles} = useTableContext();\n const {presets, rangeCalendarProps, classNames, className, styles, style, vars, ...others} = useProps(\n 'PlasmaTableDateRangePicker',\n defaultProps,\n props,\n );\n const [opened, setOpened] = useState(false);\n\n const onApply = (dates: DatesRangeValue<DateStringValue | null>) => {\n store.setDateRange(dates);\n store.setPagination({pageIndex: 0, pageSize: store.state.pagination.pageSize});\n setOpened(false);\n };\n\n const onCancel = () => {\n setOpened(false);\n };\n\n const formatDate = (date: DateStringValue) => dayjs(date).format('MMM D, YYYY');\n const formattedRange = `${formatDate(store.state.dateRange[0])} - ${formatDate(store.state.dateRange[1])}`;\n const dateRangeInitialized = store.state.dateRange.every(\n (date: DateStringValue) => typeof date === 'string' && date !== '',\n );\n\n const stylesApiProps = {classNames, styles};\n\n return (\n <Grid.Col\n span=\"content\"\n order={TableComponentsOrder.DateRangePicker}\n ref={ref}\n {...getStyles('dateRangeRoot', {className, style, ...stylesApiProps})}\n {...others}\n >\n <Popover opened={opened} onChange={setOpened}>\n <Popover.Target>\n <InputBase\n component=\"button\"\n leftSection={<CalendarSize16Px height={16} />}\n miw={220}\n onClick={() => setOpened(true)}\n >\n {dateRangeInitialized ? formattedRange : 'Select date range'}\n </InputBase>\n </Popover.Target>\n <Popover.Dropdown p={0}>\n <DateRangePickerInlineCalendar\n initialRange={store.state.dateRange}\n onApply={onApply}\n onCancel={onCancel}\n presets={presets}\n rangeCalendarProps={rangeCalendarProps}\n />\n </Popover.Dropdown>\n </Popover>\n </Grid.Col>\n );\n});\n"],"names":["TableDateRangePicker","defaultProps","presets","factory","props","ref","useTableContext","store","getStyles","useProps","rangeCalendarProps","classNames","className","styles","style","vars","others","useState","opened","setOpened","onApply","dates","setDateRange","setPagination","pageIndex","pageSize","state","pagination","onCancel","formatDate","date","dayjs","format","formattedRange","dateRange","dateRangeInitialized","every","stylesApiProps","Grid","Col","span","order","TableComponentsOrder","DateRangePicker","Popover","onChange","Target","InputBase","component","leftSection","CalendarSize16Px","height","miw","onClick","Dropdown","p","DateRangePickerInlineCalendar","initialRange"],"mappings":";;;;+BA6CaA;;;eAAAA;;;;;;;;;gCA7CkB;oBACsE;8DACnF;qBAGK;qBAKhB;qBAC4B;4BACL;AA6B9B,IAAMC,eAAmD;IACrDC,SAAS,CAAC;AACd;AAEO,IAAMF,uBAAuBG,IAAAA,aAAO,EAA8B,SAACC,OAAOC;IAC7E,IAA2BC,mBAAAA,IAAAA,6BAAe,KAAnCC,QAAoBD,iBAApBC,OAAOC,YAAaF,iBAAbE;IACd,IAA6FC,YAAAA,IAAAA,cAAQ,EACjG,8BACAR,cACAG,QAHGF,UAAsFO,UAAtFP,SAASQ,qBAA6ED,UAA7EC,oBAAoBC,aAAyDF,UAAzDE,YAAYC,YAA6CH,UAA7CG,WAAWC,SAAkCJ,UAAlCI,QAAQC,QAA0BL,UAA1BK,OAAOC,OAAmBN,UAAnBM,MAASC,sCAAUP;QAAtFP;QAASQ;QAAoBC;QAAYC;QAAWC;QAAQC;QAAOC;;IAK1E,IAA4BE,+BAAAA,IAAAA,eAAQ,EAAC,YAA9BC,SAAqBD,cAAbE,YAAaF;IAE5B,IAAMG,UAAU,SAACC;QACbd,MAAMe,YAAY,CAACD;QACnBd,MAAMgB,aAAa,CAAC;YAACC,WAAW;YAAGC,UAAUlB,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tonWithDisabledTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAC,MAAM,eAAe,CAAC;AACzD,OAAO,EAAC,SAAS,EAAa,MAAM,OAAO,CAAC;AAI5C,MAAM,WAAW,8BAA8B;IAC3C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;OAEG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC,CAAC;IAC7E;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;
|
|
1
|
+
{"version":3,"file":"ButtonWithDisabledTooltip.d.ts","sourceRoot":"","sources":["../../../../src/components/button/ButtonWithDisabledTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAC,MAAM,eAAe,CAAC;AACzD,OAAO,EAAC,SAAS,EAAa,MAAM,OAAO,CAAC;AAI5C,MAAM,WAAW,8BAA8B;IAC3C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;OAEG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC,CAAC;IAC7E;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;AAeD,eAAO,MAAM,yBAAyB;;;;;;mCAErC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/button/ButtonWithDisabledTooltip.tsx"],"sourcesContent":["import {Box, Tooltip, TooltipProps} from '@mantine/core';\nimport {ReactNode, forwardRef} from 'react';\n\nimport {createPolymorphicComponent} from '../../utils/index.js';\n\nexport interface ButtonWithDisabledTooltipProps {\n /**\n * The tooltip message to display when disabled\n */\n disabledTooltip?: string;\n /**\n * Whether the button underneath the tooltip is disabled\n */\n disabled?: boolean;\n children?: ReactNode;\n /**\n * Additional tooltip props to set on the disabled button tooltip\n */\n disabledTooltipProps?: Omit<TooltipProps, 'disabled' | 'label' | 'children'>;\n /**\n * Sets button width to 100% of parent element\n */\n fullWidth?: boolean;\n}\n\nconst _ButtonWithDisabledTooltip = forwardRef<HTMLDivElement, ButtonWithDisabledTooltipProps>(\n ({disabledTooltip, disabled, children, disabledTooltipProps, fullWidth, ...others}, ref) =>\n disabledTooltip ? (\n <Tooltip label={disabledTooltip} disabled={!disabled} {...disabledTooltipProps}>\n <Box
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/button/ButtonWithDisabledTooltip.tsx"],"sourcesContent":["import {Box, Tooltip, TooltipProps} from '@mantine/core';\nimport {ReactNode, forwardRef} from 'react';\n\nimport {createPolymorphicComponent} from '../../utils/index.js';\n\nexport interface ButtonWithDisabledTooltipProps {\n /**\n * The tooltip message to display when disabled\n */\n disabledTooltip?: string;\n /**\n * Whether the button underneath the tooltip is disabled\n */\n disabled?: boolean;\n children?: ReactNode;\n /**\n * Additional tooltip props to set on the disabled button tooltip\n */\n disabledTooltipProps?: Omit<TooltipProps, 'disabled' | 'label' | 'children'>;\n /**\n * Sets button width to 100% of parent element\n */\n fullWidth?: boolean;\n}\n\nconst _ButtonWithDisabledTooltip = forwardRef<HTMLDivElement, ButtonWithDisabledTooltipProps>(\n ({disabledTooltip, disabled, children, disabledTooltipProps, fullWidth, ...others}, ref) =>\n disabledTooltip ? (\n <Tooltip label={disabledTooltip} disabled={!disabled} {...disabledTooltipProps}>\n <Box ref={ref} style={{'&:hover': {cursor: 'not-allowed'}, width: fullWidth && '100%'}} {...others}>\n {children}\n </Box>\n </Tooltip>\n ) : (\n <>{children}</>\n ),\n);\n\nexport const ButtonWithDisabledTooltip = createPolymorphicComponent<'div', ButtonWithDisabledTooltipProps>(\n _ButtonWithDisabledTooltip,\n);\n"],"names":["Box","Tooltip","forwardRef","createPolymorphicComponent","_ButtonWithDisabledTooltip","disabledTooltip","disabled","children","disabledTooltipProps","fullWidth","others","ref","label","style","cursor","width","ButtonWithDisabledTooltip"],"mappings":";AAAA,SAAQA,GAAG,EAAEC,OAAO,QAAqB,gBAAgB;AACzD,SAAmBC,UAAU,QAAO,QAAQ;AAE5C,SAAQC,0BAA0B,QAAO,uBAAuB;AAsBhE,MAAMC,2CAA6BF,WAC/B,CAAC,EAACG,eAAe,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,oBAAoB,EAAEC,SAAS,EAAE,GAAGC,QAAO,EAAEC,MAChFN,gCACI,KAACJ;QAAQW,OAAOP;QAAiBC,UAAU,CAACA;QAAW,GAAGE,oBAAoB;kBAC1E,cAAA,KAACR;YAAIW,KAAKA;YAAKE,OAAO;gBAAC,WAAW;oBAACC,QAAQ;gBAAa;gBAAGC,OAAON,aAAa;YAAM;YAAI,GAAGC,MAAM;sBAC7FH;;uBAIT;kBAAGA;;AAIf,OAAO,MAAMS,4BAA4Bb,2BACrCC,4BACF"}
|
|
@@ -81,6 +81,7 @@ export const Collection = (props)=>{
|
|
|
81
81
|
}, item.id));
|
|
82
82
|
const addAllowed = allowAdd?.(value) ?? true;
|
|
83
83
|
const _addButton = canEdit ? /*#__PURE__*/ _jsx(Box, {
|
|
84
|
+
className: classes.addButtonContainer,
|
|
84
85
|
children: /*#__PURE__*/ _jsx(Button.Quaternary, {
|
|
85
86
|
leftSection: /*#__PURE__*/ _jsx(IconPlus, {
|
|
86
87
|
size: 16
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/collection/Collection.tsx"],"sourcesContent":["import {IconPlus} from '@coveord/plasma-react-icons';\nimport {DndContext, DragEndEvent, KeyboardSensor, PointerSensor, useSensor, useSensors} from '@dnd-kit/core';\nimport {restrictToParentElement, restrictToVerticalAxis} from '@dnd-kit/modifiers';\nimport {SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy} from '@dnd-kit/sortable';\nimport {\n __InputWrapperProps,\n Box,\n BoxProps,\n Factory,\n Input,\n MantineSpacing,\n Stack,\n StylesApiProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport {useDidUpdate} from '@mantine/hooks';\nimport {ForwardedRef, ReactNode} from 'react';\n\nimport {CustomComponentThemeExtend, identity} from '../../utils/index.js';\nimport {Button} from '../button/index.js';\nimport classes from './Collection.module.css';\nimport {CollectionProvider} from './CollectionContext.js';\nimport {CollectionItem} from './CollectionItem.js';\n\nexport interface CollectionProps<T> extends __InputWrapperProps, BoxProps, StylesApiProps<CollectionFactory> {\n /**\n * The default value each new item should have\n */\n newItem: T;\n /**\n * A render function called for each item passed in the `value` prop.\n *\n * @param item The current item's value\n * @param index The current item's index\n */\n children: (item: T, index: number) => ReactNode;\n /**\n * The list of items to display inside the collection\n *\n * @default []\n */\n value?: T[];\n /**\n * Defines how each item is uniquely identified. It is highly recommended that you specify this prop to an ID that makes sense.\n *\n * This method is required when using this component with ReactHookForm.\n *\n * @see {@link https://react-hook-form.com/api/usefieldarray/} for using a collection with ReactHookForm.\n *\n * @param originalItem The original item\n * @param itemIndex The index of the original item\n */\n getItemId?: (originalItem: T, itemIndex: number) => string;\n /**\n * Unused, has no effect\n */\n onFocus?: () => void;\n /**\n * Function called whenever the value needs to be updated\n *\n * @param value The whole list of items after the change\n */\n onChange?: (value: T[]) => void;\n /**\n * Function called after an item is removed from the collection using the remove button\n *\n * @param itemIndex The index of the item that was removed\n */\n onRemoveItem?: (itemIndex: number) => void;\n /**\n * Function that gets called whenever a collection item needs to be reordered\n *\n * @param payload The origin and destination index of the item to reorder\n */\n onReorderItem?: (payload: {from: number; to: number}) => void;\n /**\n * Function that gets called when a new item needs to be added to the collection\n *\n * @param value The value of the item to insert\n * @param index The index of the new item to insert\n */\n onInsertItem?: (value: T, index: number) => void;\n /**\n * Whether the collection should have drag and drop behavior enabled\n *\n * @default false\n */\n draggable?: boolean;\n /**\n * Whether the collection is disabled, or in other words in read only mode\n *\n * @default false\n */\n disabled?: boolean;\n /**\n * Whether the collection is readOnly. If true, the collection will not allow adding or removing items\n *\n * @default false\n */\n readOnly?: boolean;\n /**\n * Function that determines if the add item button should be enabled given the current items of the collection.\n * The button is always enabled if this props remains undefined\n *\n * @param values The current items of the collection\n */\n allowAdd?: (values: T[]) => boolean;\n /**\n * The label of the add item button\n *\n * @default \"Add item\"\n */\n addLabel?: string;\n /**\n * The tooltip text displayed when hovering over the disabled add item button\n *\n * @default 'There is already an empty item'\n */\n addDisabledTooltip?: string;\n /**\n * The gap between the colleciton items\n *\n * @default 'xs'\n */\n gap?: MantineSpacing;\n /**\n * Whether the collection is required. When required is true, the collection will hide the remove button if there is only one item\n *\n * @default false\n */\n required?: boolean;\n}\n\nexport type CollectionStylesNames = 'root' | 'item' | 'items' | 'itemDragging' | 'dragHandle';\n\nexport type CollectionFactory = Factory<{\n props: CollectionProps<unknown>;\n ref: HTMLDivElement;\n stylesNames: CollectionStylesNames;\n}>;\n\nconst defaultProps: Partial<CollectionProps<unknown>> = {\n draggable: false,\n addLabel: 'Add item',\n addDisabledTooltip: 'There is already an empty item',\n disabled: false,\n readOnly: false,\n gap: 'md',\n required: false,\n getItemId: ({id}: any) => id,\n};\n\nexport const Collection = <T,>(props: CollectionProps<T> & {ref?: ForwardedRef<HTMLDivElement>}) => {\n const {\n value,\n onChange,\n onRemoveItem,\n onReorderItem,\n onInsertItem,\n disabled,\n readOnly,\n draggable,\n children,\n gap,\n required,\n newItem,\n addLabel,\n addDisabledTooltip,\n allowAdd,\n label,\n labelProps,\n withAsterisk,\n description,\n descriptionProps,\n error,\n errorProps,\n getItemId,\n ref,\n\n // Style props\n style,\n className,\n classNames,\n styles,\n unstyled,\n ...others\n } = useProps('Collection', defaultProps as CollectionProps<T>, props);\n\n const getStyles = useStyles<CollectionFactory>({\n name: 'Collection',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n });\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n }),\n );\n\n const canEdit = !disabled && !readOnly;\n const hasOnlyOneItem = value.length === 1;\n\n /**\n * Enforcing onChange when the value is modified will make sure the errors are carried through.\n */\n useDidUpdate(() => {\n onChange?.(value);\n }, [JSON.stringify(value)]);\n\n const isRequired = typeof withAsterisk === 'boolean' ? withAsterisk : required;\n const _label = label ? (\n <Input.Label required={isRequired} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n const _error = error ? <Input.Error {...errorProps}>{error}</Input.Error> : null;\n const _header =\n _label || _description ? (\n <Stack gap=\"xxs\" pb=\"xs\">\n {_label}\n {_description}\n </Stack>\n ) : null;\n\n const standardizedItems = value.map((item, index) => ({id: getItemId?.(item, index) ?? String(index), data: item}));\n\n const items = standardizedItems.map((item, index) => (\n <CollectionItem\n key={item.id}\n id={item.id}\n disabled={!canEdit}\n draggable={draggable}\n onRemove={() => onRemoveItem?.(index)}\n removable={!(required && hasOnlyOneItem)}\n >\n {children(item.data, index)}\n </CollectionItem>\n ));\n\n const addAllowed = allowAdd?.(value) ?? true;\n\n const _addButton = canEdit ? (\n <Box>\n <Button.Quaternary\n leftSection={<IconPlus size={16} />}\n onClick={() => onInsertItem(newItem, value?.length ?? 0)}\n disabled={!addAllowed}\n disabledTooltip={addDisabledTooltip}\n >\n {addLabel}\n </Button.Quaternary>\n </Box>\n ) : null;\n\n const getIndex = (id: string) => standardizedItems.findIndex((item) => item.id === id);\n\n const handleDragEnd = ({over, active}: DragEndEvent): void => {\n if (over) {\n const activeIndex = getIndex(String(active.id));\n const overIndex = getIndex(String(over.id));\n if (activeIndex !== overIndex) {\n onReorderItem?.({from: activeIndex, to: overIndex});\n }\n }\n };\n\n return (\n <CollectionProvider value={{getStyles}}>\n <DndContext\n onDragEnd={handleDragEnd}\n sensors={sensors}\n modifiers={[restrictToVerticalAxis, restrictToParentElement]}\n >\n <SortableContext items={standardizedItems} strategy={verticalListSortingStrategy}>\n <Box ref={ref} {...others} {...getStyles('root')}>\n {_header}\n <Stack gap={gap} {...getStyles('items')}>\n {items}\n {_addButton}\n {_error}\n </Stack>\n </Box>\n </SortableContext>\n </DndContext>\n </CollectionProvider>\n );\n};\n\nCollection.extend = identity as CustomComponentThemeExtend<CollectionFactory>;\n"],"names":["IconPlus","DndContext","KeyboardSensor","PointerSensor","useSensor","useSensors","restrictToParentElement","restrictToVerticalAxis","SortableContext","sortableKeyboardCoordinates","verticalListSortingStrategy","Box","Input","Stack","useProps","useStyles","useDidUpdate","identity","Button","classes","CollectionProvider","CollectionItem","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","readOnly","gap","required","getItemId","id","Collection","props","value","onChange","onRemoveItem","onReorderItem","onInsertItem","children","newItem","allowAdd","label","labelProps","withAsterisk","description","descriptionProps","error","errorProps","ref","style","className","classNames","styles","unstyled","others","getStyles","name","sensors","coordinateGetter","canEdit","hasOnlyOneItem","length","JSON","stringify","isRequired","_label","Label","_description","Description","_error","Error","_header","pb","standardizedItems","map","item","index","String","data","items","onRemove","removable","addAllowed","_addButton","Quaternary","leftSection","size","onClick","disabledTooltip","getIndex","findIndex","handleDragEnd","over","active","activeIndex","overIndex","from","to","onDragEnd","modifiers","strategy","extend"],"mappings":";AAAA,SAAQA,QAAQ,QAAO,8BAA8B;AACrD,SAAQC,UAAU,EAAgBC,cAAc,EAAEC,aAAa,EAAEC,SAAS,EAAEC,UAAU,QAAO,gBAAgB;AAC7G,SAAQC,uBAAuB,EAAEC,sBAAsB,QAAO,qBAAqB;AACnF,SAAQC,eAAe,EAAEC,2BAA2B,EAAEC,2BAA2B,QAAO,oBAAoB;AAC5G,SAEIC,GAAG,EAGHC,KAAK,EAELC,KAAK,EAELC,QAAQ,EACRC,SAAS,QACN,gBAAgB;AACvB,SAAQC,YAAY,QAAO,iBA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AO/D,EAAE;YAC7C,MAAMiE,YAAYN,SAASZ,OAAOe,KAAK9D,EAAE;YACzC,IAAIgE,gBAAgBC,WAAW;gBAC3B3D,gBAAgB;oBAAC4D,MAAMF;oBAAaG,IAAIF;gBAAS;YACrD;QACJ;IACJ;IAEA,qBACI,KAAC5E;QAAmBc,OAAO;YAACsB;QAAS;kBACjC,cAAA,KAACvD;YACGkG,WAAWP;YACXlC,SAASA;YACT0C,WAAW;gBAAC7F;gBAAwBD;aAAwB;sBAE5D,cAAA,KAACE;gBAAgBwE,OAAON;gBAAmB2B,UAAU3F;0BACjD,cAAA,MAACC;oBAAIsC,KAAKA;oBAAM,GAAGM,MAAM;oBAAG,GAAGC,UAAU,OAAO;;wBAC3CgB;sCACD,MAAC3D;4BAAMe,KAAKA;4BAAM,GAAG4B,UAAU,QAAQ;;gCAClCwB;gCACAI;gCACAd;;;;;;;;AAO7B,EAAE;AAEFtC,WAAWsE,MAAM,GAAGrF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/collection/Collection.tsx"],"sourcesContent":["import {IconPlus} from '@coveord/plasma-react-icons';\nimport {DndContext, DragEndEvent, KeyboardSensor, PointerSensor, useSensor, useSensors} from '@dnd-kit/core';\nimport {restrictToParentElement, restrictToVerticalAxis} from '@dnd-kit/modifiers';\nimport {SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy} from '@dnd-kit/sortable';\nimport {\n __InputWrapperProps,\n Box,\n BoxProps,\n Factory,\n Input,\n MantineSpacing,\n Stack,\n StylesApiProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport {useDidUpdate} from '@mantine/hooks';\nimport {ForwardedRef, ReactNode} from 'react';\n\nimport {CustomComponentThemeExtend, identity} from '../../utils/index.js';\nimport {Button} from '../button/index.js';\nimport classes from './Collection.module.css';\nimport {CollectionProvider} from './CollectionContext.js';\nimport {CollectionItem} from './CollectionItem.js';\n\nexport interface CollectionProps<T> extends __InputWrapperProps, BoxProps, StylesApiProps<CollectionFactory> {\n /**\n * The default value each new item should have\n */\n newItem: T;\n /**\n * A render function called for each item passed in the `value` prop.\n *\n * @param item The current item's value\n * @param index The current item's index\n */\n children: (item: T, index: number) => ReactNode;\n /**\n * The list of items to display inside the collection\n *\n * @default []\n */\n value?: T[];\n /**\n * Defines how each item is uniquely identified. It is highly recommended that you specify this prop to an ID that makes sense.\n *\n * This method is required when using this component with ReactHookForm.\n *\n * @see {@link https://react-hook-form.com/api/usefieldarray/} for using a collection with ReactHookForm.\n *\n * @param originalItem The original item\n * @param itemIndex The index of the original item\n */\n getItemId?: (originalItem: T, itemIndex: number) => string;\n /**\n * Unused, has no effect\n */\n onFocus?: () => void;\n /**\n * Function called whenever the value needs to be updated\n *\n * @param value The whole list of items after the change\n */\n onChange?: (value: T[]) => void;\n /**\n * Function called after an item is removed from the collection using the remove button\n *\n * @param itemIndex The index of the item that was removed\n */\n onRemoveItem?: (itemIndex: number) => void;\n /**\n * Function that gets called whenever a collection item needs to be reordered\n *\n * @param payload The origin and destination index of the item to reorder\n */\n onReorderItem?: (payload: {from: number; to: number}) => void;\n /**\n * Function that gets called when a new item needs to be added to the collection\n *\n * @param value The value of the item to insert\n * @param index The index of the new item to insert\n */\n onInsertItem?: (value: T, index: number) => void;\n /**\n * Whether the collection should have drag and drop behavior enabled\n *\n * @default false\n */\n draggable?: boolean;\n /**\n * Whether the collection is disabled, or in other words in read only mode\n *\n * @default false\n */\n disabled?: boolean;\n /**\n * Whether the collection is readOnly. If true, the collection will not allow adding or removing items\n *\n * @default false\n */\n readOnly?: boolean;\n /**\n * Function that determines if the add item button should be enabled given the current items of the collection.\n * The button is always enabled if this props remains undefined\n *\n * @param values The current items of the collection\n */\n allowAdd?: (values: T[]) => boolean;\n /**\n * The label of the add item button\n *\n * @default \"Add item\"\n */\n addLabel?: string;\n /**\n * The tooltip text displayed when hovering over the disabled add item button\n *\n * @default 'There is already an empty item'\n */\n addDisabledTooltip?: string;\n /**\n * The gap between the colleciton items\n *\n * @default 'xs'\n */\n gap?: MantineSpacing;\n /**\n * Whether the collection is required. When required is true, the collection will hide the remove button if there is only one item\n *\n * @default false\n */\n required?: boolean;\n}\n\nexport type CollectionStylesNames = 'root' | 'item' | 'items' | 'itemDragging' | 'dragHandle';\n\nexport type CollectionFactory = Factory<{\n props: CollectionProps<unknown>;\n ref: HTMLDivElement;\n stylesNames: CollectionStylesNames;\n}>;\n\nconst defaultProps: Partial<CollectionProps<unknown>> = {\n draggable: false,\n addLabel: 'Add item',\n addDisabledTooltip: 'There is already an empty item',\n disabled: false,\n readOnly: false,\n gap: 'md',\n required: false,\n getItemId: ({id}: any) => id,\n};\n\nexport const Collection = <T,>(props: CollectionProps<T> & {ref?: ForwardedRef<HTMLDivElement>}) => {\n const {\n value,\n onChange,\n onRemoveItem,\n onReorderItem,\n onInsertItem,\n disabled,\n readOnly,\n draggable,\n children,\n gap,\n required,\n newItem,\n addLabel,\n addDisabledTooltip,\n allowAdd,\n label,\n labelProps,\n withAsterisk,\n description,\n descriptionProps,\n error,\n errorProps,\n getItemId,\n ref,\n\n // Style props\n style,\n className,\n classNames,\n styles,\n unstyled,\n ...others\n } = useProps('Collection', defaultProps as CollectionProps<T>, props);\n\n const getStyles = useStyles<CollectionFactory>({\n name: 'Collection',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n });\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n }),\n );\n\n const canEdit = !disabled && !readOnly;\n const hasOnlyOneItem = value.length === 1;\n\n /**\n * Enforcing onChange when the value is modified will make sure the errors are carried through.\n */\n useDidUpdate(() => {\n onChange?.(value);\n }, [JSON.stringify(value)]);\n\n const isRequired = typeof withAsterisk === 'boolean' ? withAsterisk : required;\n const _label = label ? (\n <Input.Label required={isRequired} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n const _error = error ? <Input.Error {...errorProps}>{error}</Input.Error> : null;\n const _header =\n _label || _description ? (\n <Stack gap=\"xxs\" pb=\"xs\">\n {_label}\n {_description}\n </Stack>\n ) : null;\n\n const standardizedItems = value.map((item, index) => ({id: getItemId?.(item, index) ?? String(index), data: item}));\n\n const items = standardizedItems.map((item, index) => (\n <CollectionItem\n key={item.id}\n id={item.id}\n disabled={!canEdit}\n draggable={draggable}\n onRemove={() => onRemoveItem?.(index)}\n removable={!(required && hasOnlyOneItem)}\n >\n {children(item.data, index)}\n </CollectionItem>\n ));\n\n const addAllowed = allowAdd?.(value) ?? true;\n\n const _addButton = canEdit ? (\n <Box className={classes.addButtonContainer}>\n <Button.Quaternary\n leftSection={<IconPlus size={16} />}\n onClick={() => onInsertItem(newItem, value?.length ?? 0)}\n disabled={!addAllowed}\n disabledTooltip={addDisabledTooltip}\n >\n {addLabel}\n </Button.Quaternary>\n </Box>\n ) : null;\n\n const getIndex = (id: string) => standardizedItems.findIndex((item) => item.id === id);\n\n const handleDragEnd = ({over, active}: DragEndEvent): void => {\n if (over) {\n const activeIndex = getIndex(String(active.id));\n const overIndex = getIndex(String(over.id));\n if (activeIndex !== overIndex) {\n onReorderItem?.({from: activeIndex, to: overIndex});\n }\n }\n };\n\n return (\n <CollectionProvider value={{getStyles}}>\n <DndContext\n onDragEnd={handleDragEnd}\n sensors={sensors}\n modifiers={[restrictToVerticalAxis, restrictToParentElement]}\n >\n <SortableContext items={standardizedItems} strategy={verticalListSortingStrategy}>\n <Box ref={ref} {...others} {...getStyles('root')}>\n {_header}\n <Stack gap={gap} {...getStyles('items')}>\n {items}\n {_addButton}\n {_error}\n </Stack>\n </Box>\n </SortableContext>\n </DndContext>\n </CollectionProvider>\n );\n};\n\nCollection.extend = identity as CustomComponentThemeExtend<CollectionFactory>;\n"],"names":["IconPlus","DndContext","KeyboardSensor","PointerSensor","useSensor","useSensors","restrictToParentElement","restrictToVerticalAxis","SortableContext","sortableKeyboardCoordinates","verticalListSortingStrategy","Box","Input","Stack","useProps","useStyles","useDidUpdate","identity","Button","classes","CollectionProvider","CollectionItem","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","readOnly","gap","required","getItemId","id","Collection","props","value","onChange","onRemoveItem","onReorderItem","onInsertItem","children","newItem","allowAdd","label","labelProps","withAsterisk","description","descriptionProps","error","errorProps","ref","style","className","classNames","styles","unstyled","others","getStyles","name","sensors","coordinateGetter","canEdit","hasOnlyOneItem","length","JSON","stringify","isRequired","_label","Label","_description","Description","_error","Error","_header","pb","standardizedItems","map","item","index","String","data","items","onRemove","removable","addAllowed","_addButton","addButtonContainer","Quaternary","leftSection","size","onClick","disabledTooltip","getIndex","findIndex","handleDragEnd","over","active","activeIndex","overIndex","from","to","onDragEnd","modifiers","strategy","extend"],"mappings":";AAAA,SAAQA,QAAQ,QAAO,8BAA8B;AACrD,SAAQC,UAAU,EAAgBC,cAAc,EAAEC,aAAa,EAAEC,SAAS,EAAEC,UAAU,QAAO,gBAAgB;AAC7G,SAAQC,uBAAuB,EAAEC,sBAAsB,QAAO,qBAAqB;AACnF,SAAQC,eAAe,EAAEC,2BAA2B,EAAEC,2BAA2B,QAAO,oBAAoB;AAC5G,SAEIC,GAAG,EAGHC,KAAK,EAELC,KAAK,EAELC,QAAQ,EACRC,SAAS,QACN,gBAAgB;AACvB,SAAQC,YAAY,QAAO,iBAAiB;AAG5C,SAAoCC,QAAQ,QAAO,uBAAuB;AAC1E,SAAQC,MAAM,QAAO,qBAAqB;AAC1C,OAAOC,aAAa,0BAA0B;AAC9C,SAAQC,kBAAkB,QAAO,yBAAyB;AAC1D,SAAQC,cAAc,QAAO,sBAAsB;AAuHnD,MAAMC,eAAkD;IACpDC,WAAW;IACXC,UAAU;IACVC,oBAAoB;IACpBC,UAAU;IACVC,UAAU;IACVC,KAAK;IACLC,UAAU;IACVC,WAAW,CAAC,EAACC,EAAE,EAAM,GAAKA;AAC9B;AAEA,OAAO,MAAMC,aAAa,CAAKC;IAC3B,MAAM,EACFC,KAAK,EAC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BACjD,cAAA,MAACC;oBAAIsC,KAAKA;oBAAM,GAAGM,MAAM;oBAAG,GAAGC,UAAU,OAAO;;wBAC3CgB;sCACD,MAAC3D;4BAAMe,KAAKA;4BAAM,GAAG4B,UAAU,QAAQ;;gCAClCwB;gCACAI;gCACAd;;;;;;;;AAO7B,EAAE;AAEFtC,WAAWuE,MAAM,GAAGtF"}
|
|
@@ -24,7 +24,7 @@ export const TableDateRangePicker = factory((props, ref)=>{
|
|
|
24
24
|
const onCancel = ()=>{
|
|
25
25
|
setOpened(false);
|
|
26
26
|
};
|
|
27
|
-
const formatDate = (date)=>dayjs(date).format('MMM
|
|
27
|
+
const formatDate = (date)=>dayjs(date).format('MMM D, YYYY');
|
|
28
28
|
const formattedRange = `${formatDate(store.state.dateRange[0])} - ${formatDate(store.state.dateRange[1])}`;
|
|
29
29
|
const dateRangeInitialized = store.state.dateRange.every((date)=>typeof date === 'string' && date !== '');
|
|
30
30
|
const stylesApiProps = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/table/table-date-range-picker/TableDateRangePicker.tsx"],"sourcesContent":["import {CalendarSize16Px} from '@coveord/plasma-react-icons';\nimport {BoxProps, CompoundStylesApiProps, Factory, factory, Grid, InputBase, Popover, useProps} from '@mantine/core';\nimport dayjs from 'dayjs';\n\nimport {type DatesRangeValue, type DateStringValue} from '@mantine/dates';\nimport {useState} from 'react';\nimport {\n DateRangePickerInlineCalendar,\n DateRangePickerInlineCalendarProps,\n DateRangePickerPreset,\n} from '../../date-range-picker/index.js';\nimport {TableComponentsOrder} from '../Table.js';\nimport {useTableContext} from '../TableContext.js';\n\nexport type TableDateRangePickerStylesNames = 'dateRangeRoot';\n\nexport interface TableDateRangePickerProps\n extends BoxProps,\n CompoundStylesApiProps<TableDateRangePickerFactory>,\n Pick<DateRangePickerInlineCalendarProps, 'startProps' | 'endProps' | 'rangeCalendarProps'> {\n /**\n * An object containing date presets.\n * If empty the preset dropdown won't be shown\n *\n * @example\n * {\n * january: {label: 'January', range: [new Date(2022, 0, 1), new Date(2022, 0, 31)]},\n * february: {label: 'February', range: [new Date(2022, 1, 1), new Date(2022, 1, 28)]}\n * }\n * @default {}\n */\n presets?: Record<string, DateRangePickerPreset>;\n}\n\nexport type TableDateRangePickerFactory = Factory<{\n props: TableDateRangePickerProps;\n ref: HTMLDivElement;\n stylesNames: TableDateRangePickerStylesNames;\n compound: true;\n}>;\n\nconst defaultProps: Partial<TableDateRangePickerProps> = {\n presets: {},\n};\n\nexport const TableDateRangePicker = factory<TableDateRangePickerFactory>((props, ref) => {\n const {store, getStyles} = useTableContext();\n const {presets, rangeCalendarProps, classNames, className, styles, style, vars, ...others} = useProps(\n 'PlasmaTableDateRangePicker',\n defaultProps,\n props,\n );\n const [opened, setOpened] = useState(false);\n\n const onApply = (dates: DatesRangeValue<DateStringValue | null>) => {\n store.setDateRange(dates);\n store.setPagination({pageIndex: 0, pageSize: store.state.pagination.pageSize});\n setOpened(false);\n };\n\n const onCancel = () => {\n setOpened(false);\n };\n\n const formatDate = (date: DateStringValue) => dayjs(date).format('MMM
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/table/table-date-range-picker/TableDateRangePicker.tsx"],"sourcesContent":["import {CalendarSize16Px} from '@coveord/plasma-react-icons';\nimport {BoxProps, CompoundStylesApiProps, Factory, factory, Grid, InputBase, Popover, useProps} from '@mantine/core';\nimport dayjs from 'dayjs';\n\nimport {type DatesRangeValue, type DateStringValue} from '@mantine/dates';\nimport {useState} from 'react';\nimport {\n DateRangePickerInlineCalendar,\n DateRangePickerInlineCalendarProps,\n DateRangePickerPreset,\n} from '../../date-range-picker/index.js';\nimport {TableComponentsOrder} from '../Table.js';\nimport {useTableContext} from '../TableContext.js';\n\nexport type TableDateRangePickerStylesNames = 'dateRangeRoot';\n\nexport interface TableDateRangePickerProps\n extends BoxProps,\n CompoundStylesApiProps<TableDateRangePickerFactory>,\n Pick<DateRangePickerInlineCalendarProps, 'startProps' | 'endProps' | 'rangeCalendarProps'> {\n /**\n * An object containing date presets.\n * If empty the preset dropdown won't be shown\n *\n * @example\n * {\n * january: {label: 'January', range: [new Date(2022, 0, 1), new Date(2022, 0, 31)]},\n * february: {label: 'February', range: [new Date(2022, 1, 1), new Date(2022, 1, 28)]}\n * }\n * @default {}\n */\n presets?: Record<string, DateRangePickerPreset>;\n}\n\nexport type TableDateRangePickerFactory = Factory<{\n props: TableDateRangePickerProps;\n ref: HTMLDivElement;\n stylesNames: TableDateRangePickerStylesNames;\n compound: true;\n}>;\n\nconst defaultProps: Partial<TableDateRangePickerProps> = {\n presets: {},\n};\n\nexport const TableDateRangePicker = factory<TableDateRangePickerFactory>((props, ref) => {\n const {store, getStyles} = useTableContext();\n const {presets, rangeCalendarProps, classNames, className, styles, style, vars, ...others} = useProps(\n 'PlasmaTableDateRangePicker',\n defaultProps,\n props,\n );\n const [opened, setOpened] = useState(false);\n\n const onApply = (dates: DatesRangeValue<DateStringValue | null>) => {\n store.setDateRange(dates);\n store.setPagination({pageIndex: 0, pageSize: store.state.pagination.pageSize});\n setOpened(false);\n };\n\n const onCancel = () => {\n setOpened(false);\n };\n\n const formatDate = (date: DateStringValue) => dayjs(date).format('MMM D, YYYY');\n const formattedRange = `${formatDate(store.state.dateRange[0])} - ${formatDate(store.state.dateRange[1])}`;\n const dateRangeInitialized = store.state.dateRange.every(\n (date: DateStringValue) => typeof date === 'string' && date !== '',\n );\n\n const stylesApiProps = {classNames, styles};\n\n return (\n <Grid.Col\n span=\"content\"\n order={TableComponentsOrder.DateRangePicker}\n ref={ref}\n {...getStyles('dateRangeRoot', {className, style, ...stylesApiProps})}\n {...others}\n >\n <Popover opened={opened} onChange={setOpened}>\n <Popover.Target>\n <InputBase\n component=\"button\"\n leftSection={<CalendarSize16Px height={16} />}\n miw={220}\n onClick={() => setOpened(true)}\n >\n {dateRangeInitialized ? formattedRange : 'Select date range'}\n </InputBase>\n </Popover.Target>\n <Popover.Dropdown p={0}>\n <DateRangePickerInlineCalendar\n initialRange={store.state.dateRange}\n onApply={onApply}\n onCancel={onCancel}\n presets={presets}\n rangeCalendarProps={rangeCalendarProps}\n />\n </Popover.Dropdown>\n </Popover>\n </Grid.Col>\n );\n});\n"],"names":["CalendarSize16Px","factory","Grid","InputBase","Popover","useProps","dayjs","useState","DateRangePickerInlineCalendar","TableComponentsOrder","useTableContext","defaultProps","presets","TableDateRangePicker","props","ref","store","getStyles","rangeCalendarProps","classNames","className","styles","style","vars","others","opened","setOpened","onApply","dates","setDateRange","setPagination","pageIndex","pageSize","state","pagination","onCancel","formatDate","date","format","formattedRange","dateRange","dateRangeInitialized","every","stylesApiProps","Col","span","order","DateRangePicker","onChange","Target","component","leftSection","height","miw","onClick","Dropdown","p","initialRange"],"mappings":";AAAA,SAAQA,gBAAgB,QAAO,8BAA8B;AAC7D,SAAmDC,OAAO,EAAEC,IAAI,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAO,gBAAgB;AACrH,OAAOC,WAAW,QAAQ;AAG1B,SAAQC,QAAQ,QAAO,QAAQ;AAC/B,SACIC,6BAA6B,QAG1B,mCAAmC;AAC1C,SAAQC,oBAAoB,QAAO,cAAc;AACjD,SAAQC,eAAe,QAAO,qBAAqB;AA6BnD,MAAMC,eAAmD;IACrDC,SAAS,CAAC;AACd;AAEA,OAAO,MAAMC,uBAAuBZ,QAAqC,CAACa,OAAOC;IAC7E,MAAM,EAACC,KAAK,EAAEC,SAAS,EAAC,GAAGP;IAC3B,MAAM,EAACE,OAAO,EAAEM,kBAAkB,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,KAAK,EAAEC,IAAI,EAAE,GAAGC,QAAO,GAAGnB,SACzF,8BACAM,cACAG;IAEJ,MAAM,CAACW,QAAQC,UAAU,GAAGnB,SAAS;IAErC,MAAMoB,UAAU,CAACC;QACbZ,MAAMa,YAAY,CAACD;QACnBZ,MAAMc,aAAa,CAAC;YAACC,WAAW;YAAGC,UAAUhB,MAAMiB,KAAK,CAACC,UAAU,CAACF,QAAQ;QAAA;QAC5EN,UAAU;IACd;IAEA,MAAMS,WAAW;QACbT,UAAU;IACd;IAEA,MAAMU,aAAa,CAACC,OAA0B/B,MAAM+B,MAAMC,MAAM,CAAC;IACjE,MAAMC,iBAAiB,GAAGH,WAAWpB,MAAMiB,KAAK,CAACO,SAAS,CAAC,EAAE,EAAE,GAAG,EAAEJ,WAAWpB,MAAMiB,KAAK,CAACO,SAAS,CAAC,EAAE,GAAG;IAC1G,MAAMC,uBAAuBzB,MAAMiB,KAAK,CAACO,SAAS,CAACE,KAAK,CACpD,CAACL,OAA0B,OAAOA,SAAS,YAAYA,SAAS;IAGpE,MAAMM,iBAAiB;QAACxB;QAAYE;IAAM;IAE1C,qBACI,KAACnB,KAAK0C,GAAG;QACLC,MAAK;QACLC,OAAOrC,qBAAqBsC,eAAe;QAC3ChC,KAAKA;QACJ,GAAGE,UAAU,iBAAiB;YAACG;YAAWE;YAAO,GAAGqB,cAAc;QAAA,EAAE;QACpE,GAAGnB,MAAM;kBAEV,cAAA,MAACpB;YAAQqB,QAAQA;YAAQuB,UAAUtB;;8BAC/B,KAACtB,QAAQ6C,MAAM;8BACX,cAAA,KAAC9C;wBACG+C,WAAU;wBACVC,2BAAa,KAACnD;4BAAiBoD,QAAQ;;wBACvCC,KAAK;wBACLC,SAAS,IAAM5B,UAAU;kCAExBe,uBAAuBF,iBAAiB;;;8BAGjD,KAACnC,QAAQmD,QAAQ;oBAACC,GAAG;8BACjB,cAAA,KAAChD;wBACGiD,cAAczC,MAAMiB,KAAK,CAACO,SAAS;wBACnCb,SAASA;wBACTQ,UAAUA;wBACVvB,SAASA;wBACTM,oBAAoBA;;;;;;AAM5C,GAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coveord/plasma-mantine",
|
|
3
|
-
"version": "56.2.
|
|
3
|
+
"version": "56.2.4",
|
|
4
4
|
"description": "A Plasma flavoured Mantine theme",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plasma",
|
|
@@ -40,29 +40,29 @@
|
|
|
40
40
|
"dayjs": "1.11.18",
|
|
41
41
|
"fast-deep-equal": "3.1.3",
|
|
42
42
|
"lodash.defaultsdeep": "4.6.1",
|
|
43
|
-
"monaco-editor": "0.
|
|
44
|
-
"@coveord/plasma-react-icons": "56.2.
|
|
45
|
-
"@coveord/plasma-tokens": "56.2.
|
|
43
|
+
"monaco-editor": "0.54.0",
|
|
44
|
+
"@coveord/plasma-react-icons": "56.2.3",
|
|
45
|
+
"@coveord/plasma-tokens": "56.2.3"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@mantine/carousel": "8.3.
|
|
49
|
-
"@mantine/code-highlight": "8.3.
|
|
50
|
-
"@mantine/core": "8.3.
|
|
51
|
-
"@mantine/dates": "8.3.
|
|
52
|
-
"@mantine/form": "8.3.
|
|
53
|
-
"@mantine/hooks": "8.3.
|
|
54
|
-
"@mantine/modals": "8.3.
|
|
55
|
-
"@mantine/notifications": "8.3.
|
|
48
|
+
"@mantine/carousel": "8.3.3",
|
|
49
|
+
"@mantine/code-highlight": "8.3.3",
|
|
50
|
+
"@mantine/core": "8.3.3",
|
|
51
|
+
"@mantine/dates": "8.3.3",
|
|
52
|
+
"@mantine/form": "8.3.3",
|
|
53
|
+
"@mantine/hooks": "8.3.3",
|
|
54
|
+
"@mantine/modals": "8.3.3",
|
|
55
|
+
"@mantine/notifications": "8.3.3",
|
|
56
56
|
"@swc/cli": "0.7.8",
|
|
57
57
|
"@swc/core": "1.13.5",
|
|
58
58
|
"@testing-library/dom": "10.4.1",
|
|
59
|
-
"@testing-library/jest-dom": "6.
|
|
59
|
+
"@testing-library/jest-dom": "6.9.1",
|
|
60
60
|
"@testing-library/react": "16.3.0",
|
|
61
61
|
"@testing-library/user-event": "14.6.1",
|
|
62
62
|
"@types/lodash.defaultsdeep": "4.6.9",
|
|
63
|
-
"@types/react": "18.3.
|
|
63
|
+
"@types/react": "18.3.26",
|
|
64
64
|
"@types/react-dom": "18.3.7",
|
|
65
|
-
"@vitest/eslint-plugin": "1.
|
|
65
|
+
"@vitest/eslint-plugin": "1.3.16",
|
|
66
66
|
"cross-env": "7.0.3",
|
|
67
67
|
"embla-carousel": "8.6.0",
|
|
68
68
|
"embla-carousel-react": "8.6.0",
|
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
"postcss": "8.5.6",
|
|
73
73
|
"postcss-preset-mantine": "^1.11.0",
|
|
74
74
|
"postcss-simple-vars": "^7.0.1",
|
|
75
|
-
"publint": "0.3.
|
|
75
|
+
"publint": "0.3.14",
|
|
76
76
|
"react": "18.3.1",
|
|
77
77
|
"react-dom": "18.3.1",
|
|
78
78
|
"rimraf": "6.0.1",
|
|
79
79
|
"tslib": "2.8.1",
|
|
80
|
-
"typescript": "5.9.
|
|
80
|
+
"typescript": "5.9.3",
|
|
81
81
|
"vitest": "3.2.4"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
@@ -27,12 +27,7 @@ const _ButtonWithDisabledTooltip = forwardRef<HTMLDivElement, ButtonWithDisabled
|
|
|
27
27
|
({disabledTooltip, disabled, children, disabledTooltipProps, fullWidth, ...others}, ref) =>
|
|
28
28
|
disabledTooltip ? (
|
|
29
29
|
<Tooltip label={disabledTooltip} disabled={!disabled} {...disabledTooltipProps}>
|
|
30
|
-
<Box
|
|
31
|
-
ref={ref}
|
|
32
|
-
style={{'&:hover': {cursor: 'not-allowed'}, width: fullWidth && '100%'}}
|
|
33
|
-
display="inline-block"
|
|
34
|
-
{...others}
|
|
35
|
-
>
|
|
30
|
+
<Box ref={ref} style={{'&:hover': {cursor: 'not-allowed'}, width: fullWidth && '100%'}} {...others}>
|
|
36
31
|
{children}
|
|
37
32
|
</Box>
|
|
38
33
|
</Tooltip>
|
|
@@ -251,7 +251,7 @@ export const Collection = <T,>(props: CollectionProps<T> & {ref?: ForwardedRef<H
|
|
|
251
251
|
const addAllowed = allowAdd?.(value) ?? true;
|
|
252
252
|
|
|
253
253
|
const _addButton = canEdit ? (
|
|
254
|
-
<Box>
|
|
254
|
+
<Box className={classes.addButtonContainer}>
|
|
255
255
|
<Button.Quaternary
|
|
256
256
|
leftSection={<IconPlus size={16} />}
|
|
257
257
|
onClick={() => onInsertItem(newItem, value?.length ?? 0)}
|
|
@@ -166,12 +166,14 @@ describe('Collection', () => {
|
|
|
166
166
|
const removeOrange = await within(screen.queryByTestId('item-1')).findByRole('button', {name: /remove/i});
|
|
167
167
|
await user.click(removeOrange);
|
|
168
168
|
|
|
169
|
-
expect(onRemoveItemSpy).
|
|
169
|
+
expect(onRemoveItemSpy).toHaveBeenCalledExactlyOnceWith(1);
|
|
170
|
+
|
|
171
|
+
onRemoveItemSpy.mockReset();
|
|
170
172
|
|
|
171
173
|
const removeBanana = await within(screen.queryByTestId('item-0')).findByRole('button', {name: /remove/i});
|
|
172
174
|
await user.click(removeBanana);
|
|
173
175
|
|
|
174
|
-
expect(onRemoveItemSpy).
|
|
176
|
+
expect(onRemoveItemSpy).toHaveBeenCalledExactlyOnceWith(0);
|
|
175
177
|
});
|
|
176
178
|
|
|
177
179
|
it('does not render the remove button when disabled', async () => {
|
|
@@ -278,7 +280,7 @@ describe('Collection', () => {
|
|
|
278
280
|
|
|
279
281
|
const {rerender} = render(<Fixture />);
|
|
280
282
|
expect(screen.getByRole('button', {name: /add/i})).toBeDisabled();
|
|
281
|
-
expect(allowAdd).
|
|
283
|
+
expect(allowAdd).toHaveBeenCalledExactlyOnceWith(['banana', 'orange']);
|
|
282
284
|
|
|
283
285
|
allowAdd.mockImplementation(() => true);
|
|
284
286
|
rerender(<Fixture />);
|
|
@@ -13,7 +13,7 @@ describe('DateRangePickerInlineCalendar', () => {
|
|
|
13
13
|
await user.click(screen.getByRole('button', {name: 'Apply'}));
|
|
14
14
|
|
|
15
15
|
expect(onApply).toHaveBeenCalledTimes(1);
|
|
16
|
-
expect(onApply).
|
|
16
|
+
expect(onApply).toHaveBeenCalledExactlyOnceWith([null, null]);
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it('calls onCancel when the user clicks on the cancel button', async () => {
|
|
@@ -54,7 +54,7 @@ describe('DateRangePickerInlineCalendar', () => {
|
|
|
54
54
|
await user.click(screen.getByRole('option', {name: 'select me'}));
|
|
55
55
|
await user.click(screen.getByRole('button', {name: 'Apply'}));
|
|
56
56
|
|
|
57
|
-
expect(onApply).
|
|
57
|
+
expect(onApply).toHaveBeenCalledExactlyOnceWith([new Date(1999, 11, 31), endOfDay(2000, 0, 1)]);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
it('calls onApply with the selected dates when clicking in the calendar', async () => {
|
|
@@ -69,7 +69,7 @@ describe('DateRangePickerInlineCalendar', () => {
|
|
|
69
69
|
|
|
70
70
|
await user.click(screen.getByRole('button', {name: 'Apply'}));
|
|
71
71
|
|
|
72
|
-
expect(onApply).
|
|
72
|
+
expect(onApply).toHaveBeenCalledExactlyOnceWith(['2022-01-08T00:00:00.000Z', '2022-01-14T23:59:59.999Z']);
|
|
73
73
|
|
|
74
74
|
vi.useRealTimers();
|
|
75
75
|
});
|
|
@@ -82,7 +82,7 @@ describe('DateRangePickerInlineCalendar', () => {
|
|
|
82
82
|
await user.click(screen.getAllByRole('button', {name: /8 january 2022/i})[0]);
|
|
83
83
|
await user.click(screen.getByRole('button', {name: 'Apply'}));
|
|
84
84
|
|
|
85
|
-
expect(onApply).
|
|
85
|
+
expect(onApply).toHaveBeenCalledExactlyOnceWith(['2022-01-08T00:00:00.000Z', '2022-01-08T23:59:59.999Z']);
|
|
86
86
|
|
|
87
87
|
vi.useRealTimers();
|
|
88
88
|
});
|
|
@@ -107,7 +107,7 @@ describe('DateRangePickerInlineCalendar', () => {
|
|
|
107
107
|
|
|
108
108
|
await user.click(screen.getByRole('button', {name: 'Apply'}));
|
|
109
109
|
|
|
110
|
-
expect(onApply).
|
|
110
|
+
expect(onApply).toHaveBeenCalledExactlyOnceWith(['2022-01-08T00:00:00.000Z', '2022-01-14T23:59:59.999Z']);
|
|
111
111
|
vi.useRealTimers();
|
|
112
112
|
});
|
|
113
113
|
});
|
|
@@ -23,7 +23,7 @@ describe('DateRangePickerPresetSelect', () => {
|
|
|
23
23
|
);
|
|
24
24
|
await user.click(screen.getByRole('option', {name: 'select me'}));
|
|
25
25
|
|
|
26
|
-
expect(onChange).
|
|
26
|
+
expect(onChange).toHaveBeenCalledExactlyOnceWith([new Date(1999, 11, 31), new Date(2000, 0, 1)]);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
it('autoselects the preset that match the value', () => {
|
|
@@ -27,7 +27,7 @@ describe('Table.DateRangePicker', () => {
|
|
|
27
27
|
};
|
|
28
28
|
render(<Fixture />);
|
|
29
29
|
|
|
30
|
-
expect(screen.getByRole('button', {name: /jan
|
|
30
|
+
expect(screen.getByRole('button', {name: /jan 1, 2022 - jan 7, 2022/i})).toBeVisible();
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
describe('when url sync is activated', () => {
|
|
@@ -51,7 +51,7 @@ describe('Table.DateRangePicker', () => {
|
|
|
51
51
|
);
|
|
52
52
|
};
|
|
53
53
|
render(<Fixture />);
|
|
54
|
-
await user.click(screen.getByRole('button', {name: /jan
|
|
54
|
+
await user.click(screen.getByRole('button', {name: /jan 1, 2022 - jan 7, 2022/i}));
|
|
55
55
|
await screen.findByRole('dialog');
|
|
56
56
|
await user.clear(screen.getByRole('textbox', {name: /start/i}));
|
|
57
57
|
await user.type(screen.getByRole('textbox', {name: /start/i}), '2022-01-02');
|
|
@@ -77,7 +77,7 @@ describe('Table.DateRangePicker', () => {
|
|
|
77
77
|
);
|
|
78
78
|
};
|
|
79
79
|
render(<Fixture />);
|
|
80
|
-
expect(screen.getByRole('button', {name: /jan
|
|
80
|
+
expect(screen.getByRole('button', {name: /jan 2, 2022 - jan 8, 2022/i})).toBeVisible();
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
83
|
});
|
|
@@ -120,7 +120,7 @@ describe('Table.Pagination', () => {
|
|
|
120
120
|
await user.click(screen.queryByRole('button', {name: '2'}));
|
|
121
121
|
|
|
122
122
|
await waitFor(() => {
|
|
123
|
-
expect(onChangePage).
|
|
123
|
+
expect(onChangePage).toHaveBeenCalledExactlyOnceWith(1);
|
|
124
124
|
});
|
|
125
125
|
});
|
|
126
126
|
|
|
@@ -182,7 +182,7 @@ describe('Table.Pagination', () => {
|
|
|
182
182
|
await user.click(screen.getByTestId('remove-page'));
|
|
183
183
|
|
|
184
184
|
// The page is 2, but the index is 1
|
|
185
|
-
expect(onChangePage).
|
|
185
|
+
expect(onChangePage).toHaveBeenCalledExactlyOnceWith(1);
|
|
186
186
|
|
|
187
187
|
buttons = screen.getAllByRole('button');
|
|
188
188
|
expect(buttons).toHaveLength(5);
|
|
@@ -192,11 +192,13 @@ describe('Table.Pagination', () => {
|
|
|
192
192
|
expect(buttons[3]).toHaveAccessibleName('2');
|
|
193
193
|
expect(buttons[4]).toHaveAccessibleName('next page');
|
|
194
194
|
|
|
195
|
+
onChangePage.mockReset();
|
|
196
|
+
|
|
195
197
|
// remove a page
|
|
196
198
|
await user.click(screen.getByTestId('remove-page'));
|
|
197
199
|
|
|
198
200
|
// The page is 1, but the index is 0
|
|
199
|
-
expect(onChangePage).
|
|
201
|
+
expect(onChangePage).toHaveBeenCalledExactlyOnceWith(0);
|
|
200
202
|
|
|
201
203
|
buttons = screen.getAllByRole('button');
|
|
202
204
|
expect(buttons).toHaveLength(4);
|
|
@@ -103,7 +103,7 @@ describe('Table.PerPage', () => {
|
|
|
103
103
|
await user.click(screen.getByRole('radio', {name: /100/i}));
|
|
104
104
|
|
|
105
105
|
await waitFor(() => {
|
|
106
|
-
expect(onPerPageChange).
|
|
106
|
+
expect(onPerPageChange).toHaveBeenCalledExactlyOnceWith(100);
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
|