@coveord/plasma-mantine 56.2.3 → 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 +55 -56
- 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/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/package.json +1 -1
- 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
|
@@ -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;;;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,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BqB,SAAS,CAAC,SAACnB;mBAASA,KAAKvD,EAAE,KAAKA;;;IAEnF,IAAM2E,gBAAgB;YAAEC,aAAAA,MAAMC,eAAAA;QAC1B,IAAID,MAAM;YACN,IAAME,cAAcL,SAAShB,OAAOoB,OAAO7E,EAAE;YAC7C,IAAM+E,YAAYN,SAAShB,OAAOmB,KAAK5E,EAAE;YACzC,IAAI8E,gBAAgBC,WAAW;gBAC3BzE,0BAAAA,oCAAAA,cAAgB;oBAAC0E,MAAMF;oBAAaG,IAAIF;gBAAS;YACrD;QACJ;IACJ;IAEA,qBACI,qBAACG,qCAAkB;QAAC/E,OAAO;YAACsB,WAAAA;QAAS;kBACjC,cAAA,qBAAC0D,gBAAU;YACPC,WAAWT;YACX9C,SAASA;YACTwD,WAAW;gBAACC,iCAAsB;gBAAEC,kCAAuB;aAAC;sBAE5D,cAAA,qBAACC,yBAAe;gBAAC7B,OAAON;gBAAmBoC,UAAUC,qCAA2B;0BAC5E,cAAA,sBAACzB,UAAG;oBAAC/C,KAAKA;mBAASM,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,WAC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;;YACtDR,UAAU,CAACoE;YACXU,iBAAiB/E;sBAEhBD;;SAGT;IAEJ,IAAMiF,WAAW,SAAC1E;eAAeqD,kBAAkBsB,SAAS,CAAC,SAACpB;mBAASA,KAAKvD,EAAE,KAAKA;;;IAEnF,IAAM4E,gBAAgB;YAAEC,aAAAA,MAAMC,eAAAA;QAC1B,IAAID,MAAM;YACN,IAAME,cAAcL,SAASjB,OAAOqB,OAAO9E,EAAE;YAC7C,IAAMgF,YAAYN,SAASjB,OAAOoB,KAAK7E,EAAE;YACzC,IAAI+E,gBAAgBC,WAAW;gBAC3B1E,0BAAAA,oCAAAA,cAAgB;oBAAC2E,MAAMF;oBAAaG,IAAIF;gBAAS;YACrD;QACJ;IACJ;IAEA,qBACI,qBAACG,qCAAkB;QAAChF,OAAO;YAACsB,WAAAA;QAAS;kBACjC,cAAA,qBAAC2D,gBAAU;YACPC,WAAWT;YACX/C,SAASA;YACTyD,WAAW;gBAACC,iCAAsB;gBAAEC,kCAAuB;aAAC;sBAE5D,cAAA,qBAACC,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"}
|
|
@@ -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":["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,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;I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AAA,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,EACLC,QAAQ,EACRC,YAAY,EACZC,aAAa,EACbC,YAAY,EACZZ,QAAQ,EACRC,QAAQ,EACRJ,SAAS,EACTgB,QAAQ,EACRX,GAAG,EACHC,QAAQ,EACRW,OAAO,EACPhB,QAAQ,EACRC,kBAAkB,EAClBgB,QAAQ,EACRC,KAAK,EACLC,UAAU,EACVC,YAAY,EACZC,W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tF"}
|
package/package.json
CHANGED
|
@@ -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)}
|