@coveord/plasma-mantine 56.1.1 → 56.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +3 -3
- package/.turbo/turbo-test.log +53 -53
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/components/button/ButtonWithDisabledTooltip.d.ts.map +1 -1
- package/dist/cjs/components/button/ButtonWithDisabledTooltip.js +2 -1
- package/dist/cjs/components/button/ButtonWithDisabledTooltip.js.map +1 -1
- package/dist/cjs/components/collection/Collection.d.ts.map +1 -1
- package/dist/cjs/components/collection/Collection.js +13 -11
- package/dist/cjs/components/collection/Collection.js.map +1 -1
- package/dist/cjs/components/prompt/Prompt.d.ts +7 -3
- package/dist/cjs/components/prompt/Prompt.d.ts.map +1 -1
- package/dist/cjs/components/prompt/Prompt.js +4 -1
- package/dist/cjs/components/prompt/Prompt.js.map +1 -1
- package/dist/esm/components/button/ButtonWithDisabledTooltip.d.ts.map +1 -1
- package/dist/esm/components/button/ButtonWithDisabledTooltip.js +1 -0
- package/dist/esm/components/button/ButtonWithDisabledTooltip.js.map +1 -1
- package/dist/esm/components/collection/Collection.d.ts.map +1 -1
- package/dist/esm/components/collection/Collection.js +10 -8
- package/dist/esm/components/collection/Collection.js.map +1 -1
- package/dist/esm/components/prompt/Prompt.d.ts +7 -3
- package/dist/esm/components/prompt/Prompt.d.ts.map +1 -1
- package/dist/esm/components/prompt/Prompt.js +4 -1
- package/dist/esm/components/prompt/Prompt.js.map +1 -1
- package/package.json +3 -3
- package/src/components/button/ButtonWithDisabledTooltip.tsx +6 -1
- package/src/components/collection/Collection.tsx +10 -8
- package/src/components/prompt/Prompt.tsx +4 -2
|
@@ -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;AAoBD,eAAO,MAAM,yBAAyB,gHAfqC,MAAO,YACjF;;;;;eAGqC,MAClB,WAAP;mCAYZ,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';\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';\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\n ref={ref}\n style={{'&:hover': {cursor: 'not-allowed'}, width: fullWidth && '100%'}}\n display=\"inline-block\"\n {...others}\n >\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","display","createPolymorphicComponent"],"mappings":";;;;+BA2CaA;;;eAAAA;;;;;;;oBA3C4B;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;YACAT,KAAKA;YACLU,OAAO;gBAAC,WAAW;oBAACC,QAAQ;gBAAa;gBAAGC,OAAOP,aAAa;YAAM;YACtEQ,SAAQ;WACJP;sBAEHH;;wBAIT;kBAAGA;;;AAIR,IAAMN,4BAA4BiB,IAAAA,iCAA0B,EAC/DhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../../../src/components/collection/Collection.tsx"],"names":[],"mappings":"AAIA,OAAO,EACH,mBAAmB,EAEnB,QAAQ,EACR,OAAO,EAEP,cAAc,EAEd,cAAc,EAGjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAC,YAAY,EAAE,SAAS,EAAC,MAAM,OAAO,CAAC;AAE9C,OAAO,EAAC,0BAA0B,EAAW,MAAM,aAAa,CAAC;AAMjE,MAAM,WAAW,eAAe,CAAC,CAAC,CAAE,SAAQ,mBAAmB,EAAE,QAAQ,EAAE,cAAc,CAAC,iBAAiB,CAAC;IACxG;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC;IACX;;;;;OAKG;IACH,QAAQ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+133,19 @@ var Collection = function(props) {
|
|
|
133
133
|
});
|
|
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
|
-
var _addButton = canEdit ? /*#__PURE__*/ (0, _jsxruntime.jsx)(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
136
|
+
var _addButton = canEdit ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_core1.Box, {
|
|
137
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_button.Button.Quaternary, {
|
|
138
|
+
leftSection: /*#__PURE__*/ (0, _jsxruntime.jsx)(_plasmareacticons.IconPlus, {
|
|
139
|
+
size: 16
|
|
140
|
+
}),
|
|
141
|
+
onClick: function() {
|
|
142
|
+
var _value_length;
|
|
143
|
+
return onInsertItem(newItem, (_value_length = value === null || value === void 0 ? void 0 : value.length) !== null && _value_length !== void 0 ? _value_length : 0);
|
|
144
|
+
},
|
|
145
|
+
disabled: !addAllowed,
|
|
146
|
+
disabledTooltip: addDisabledTooltip,
|
|
147
|
+
children: addLabel
|
|
148
|
+
})
|
|
147
149
|
}) : null;
|
|
148
150
|
var getIndex = function(id) {
|
|
149
151
|
return standardizedItems.findIndex(function(item) {
|
|
@@ -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 {ReorderPayload} from '@mantine/form/lib/types';\nimport {useDidUpdate} from '@mantine/hooks';\nimport {ForwardedRef, ReactNode} from 'react';\n\nimport {CustomComponentThemeExtend, identity} from '../../utils';\nimport {Button} from '../button';\nimport classes from './Collection.module.css';\nimport {CollectionProvider} from './CollectionContext';\nimport {CollectionItem} from './CollectionItem';\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: ReorderPayload) => 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 <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 ) : 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","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","Box","extend","identity"],"mappings":";;;;+BA0JaA;;;eAAAA;;;;;;;;gCA1JU;oBACsE;yBAC/B;wBAC0B;qBAYjF;qBAEoB;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,U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AOmC,MAAM,cAAbnC,2BAAAA,gBAAiB;;QACtDR,UAAU,CAACoE;QACXQ,iBAAiB7E;kBAEhBD;SAEL;IAEJ,IAAM+E,WAAW,SAACxE;eAAeqD,kBAAkBoB,SAAS,CAAC,SAAClB;mBAASA,KAAKvD,EAAE,KAAKA;;;IAEnF,IAAM0E,gBAAgB;YAAEC,aAAAA,MAAMC,eAAAA;QAC1B,IAAID,MAAM;YACN,IAAME,cAAcL,SAASf,OAAOmB,OAAO5E,EAAE;YAC7C,IAAM8E,YAAYN,SAASf,OAAOkB,KAAK3E,EAAE;YACzC,IAAI6E,gBAAgBC,WAAW;gBAC3BxE,0BAAAA,oCAAAA,cAAgB;oBAACyE,MAAMF;oBAAaG,IAAIF;gBAAS;YACrD;QACJ;IACJ;IAEA,qBACI,qBAACG,qCAAkB;QAAC9E,OAAO;YAACsB,WAAAA;QAAS;kBACjC,cAAA,qBAACyD,gBAAU;YACPC,WAAWT;YACX7C,SAASA;YACTuD,WAAW;gBAACC,iCAAsB;gBAAEC,kCAAuB;aAAC;sBAE5D,cAAA,qBAACC,yBAAe;gBAAC5B,OAAON;gBAAmBmC,UAAUC,qCAA2B;0BAC5E,cAAA,sBAACC,UAAG;oBAACxE,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 {ReorderPayload} from '@mantine/form/lib/types';\nimport {useDidUpdate} from '@mantine/hooks';\nimport {ForwardedRef, ReactNode} from 'react';\n\nimport {CustomComponentThemeExtend, identity} from '../../utils';\nimport {Button} from '../button';\nimport classes from './Collection.module.css';\nimport {CollectionProvider} from './CollectionContext';\nimport {CollectionItem} from './CollectionItem';\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: ReorderPayload) => 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":";;;;+BA0JaA;;;eAAAA;;;;;;;;gCA1JU;oBACsE;yBAC/B;wBAC0B;qBAYjF;qBAEoB;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,c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E,SAASN,CAAAA,gBAAAA,kBAAAA,4BAAAA,MAAOmC,MAAM,cAAbnC,2BAAAA,gBAAiB;;YACtDR,UAAU,CAACoE;YACXS,iBAAiB9E;sBAEhBD;;SAGT;IAEJ,IAAMgF,WAAW,SAACzE;eAAeqD,kBAAkBqB,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,6 +1,5 @@
|
|
|
1
1
|
import { Factory, ModalRootProps, ModalStylesNames, StylesApiProps } from '@mantine/core';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { Modal } from '../modal';
|
|
4
3
|
import { PromptCancelButton, PromptCancelButtonStylesNamesVariant } from './PromptCancelButton';
|
|
5
4
|
import { PromptConfirmButton, PromptConfirmButtonStylesNamesVariant } from './PromptConfirmButton';
|
|
6
5
|
export type PromptVariant = 'success' | 'warning' | 'critical' | 'info';
|
|
@@ -27,7 +26,7 @@ export type PromptFactory = Factory<{
|
|
|
27
26
|
staticComponents: {
|
|
28
27
|
CancelButton: typeof PromptCancelButton;
|
|
29
28
|
ConfirmButton: typeof PromptConfirmButton;
|
|
30
|
-
Footer: typeof
|
|
29
|
+
Footer: typeof PromptFooter;
|
|
31
30
|
};
|
|
32
31
|
}>;
|
|
33
32
|
export declare const Prompt: import("@mantine/core").MantineComponent<{
|
|
@@ -39,7 +38,12 @@ export declare const Prompt: import("@mantine/core").MantineComponent<{
|
|
|
39
38
|
staticComponents: {
|
|
40
39
|
CancelButton: typeof PromptCancelButton;
|
|
41
40
|
ConfirmButton: typeof PromptConfirmButton;
|
|
42
|
-
Footer: typeof
|
|
41
|
+
Footer: typeof PromptFooter;
|
|
43
42
|
};
|
|
44
43
|
}>;
|
|
44
|
+
declare const PromptFooter: import("react").ForwardRefExoticComponent<import("../modal").ModalFooterProps & import("react").RefAttributes<HTMLDivElement> & {
|
|
45
|
+
component?: any;
|
|
46
|
+
renderRoot?: (props: Record<string, any>) => React.ReactNode;
|
|
47
|
+
}>;
|
|
48
|
+
export {};
|
|
45
49
|
//# sourceMappingURL=Prompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Prompt.d.ts","sourceRoot":"","sources":["../../../../src/components/prompt/Prompt.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGH,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,cAAc,EAIjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAwC,SAAS,EAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Prompt.d.ts","sourceRoot":"","sources":["../../../../src/components/prompt/Prompt.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGH,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,cAAc,EAIjB,MAAM,eAAe,CAAC;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MAAM,EAAE,OAAO,YAAY,CAAC;KAC/B;EA8DH,CAAC;AAEH,QAAA,MAAM,YAAY;;iDAtDN,MAAQ,SAAQ;EAsDwB,CAAC"}
|
|
@@ -107,8 +107,11 @@ var Prompt = (0, _core.factory)(function(_props, ref) {
|
|
|
107
107
|
}))
|
|
108
108
|
});
|
|
109
109
|
});
|
|
110
|
+
var PromptFooter = _modal.Modal.Footer.withProps({
|
|
111
|
+
pt: 0
|
|
112
|
+
});
|
|
110
113
|
Prompt.CancelButton = _PromptCancelButton.PromptCancelButton;
|
|
111
114
|
Prompt.ConfirmButton = _PromptConfirmButton.PromptConfirmButton;
|
|
112
|
-
Prompt.Footer =
|
|
115
|
+
Prompt.Footer = PromptFooter;
|
|
113
116
|
|
|
114
117
|
//# sourceMappingURL=Prompt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/prompt/Prompt.tsx"],"sourcesContent":["import {\n Box,\n factory,\n Factory,\n ModalRootProps,\n ModalStylesNames,\n StylesApiProps,\n Title,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport {Children, ComponentType, ReactElement, ReactNode} from 'react';\nimport {Modal} from '../modal';\nimport {PromptContextProvider} from './Prompt.context';\nimport classes from './Prompt.module.css';\nimport {PromptCancelButton, PromptCancelButtonStylesNamesVariant} from './PromptCancelButton';\nimport {PromptConfirmButton, PromptConfirmButtonStylesNamesVariant} from './PromptConfirmButton';\nimport CriticalIcon from './icons/CriticalIcon';\nimport InfoIcon from './icons/InfoIcon';\nimport SuccessIcon from './icons/SuccessIcon';\nimport WarningIcon from './icons/WarningIcon';\n\nexport type PromptVariant = 'success' | 'warning' | 'critical' | 'info';\nexport type PromptVars = {root: '--prompt-icon-size'};\nexport type PromptStylesNames =\n | Exclude<ModalStylesNames, 'title'>\n | 'icon'\n | PromptCancelButtonStylesNamesVariant\n | PromptConfirmButtonStylesNamesVariant;\n\nexport interface PromptProps\n extends StylesApiProps<PromptFactory>,\n Omit<ModalRootProps, 'classNames' | 'styles' | 'vars'> {\n /**\n * Controls prompt appearance\n *\n * @default \"info\"\n */\n variant?: PromptVariant;\n children: ReactNode;\n title: ReactNode;\n}\n\nexport type PromptFactory = Factory<{\n props: PromptProps;\n ref: HTMLDivElement;\n vars: PromptVars;\n variant: PromptVariant;\n stylesNames: PromptStylesNames;\n staticComponents: {\n CancelButton: typeof PromptCancelButton;\n ConfirmButton: typeof PromptConfirmButton;\n Footer: typeof
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/prompt/Prompt.tsx"],"sourcesContent":["import {\n Box,\n factory,\n Factory,\n ModalRootProps,\n ModalStylesNames,\n StylesApiProps,\n Title,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport {Children, ComponentType, ReactElement, ReactNode} from 'react';\nimport {Modal} from '../modal';\nimport {PromptContextProvider} from './Prompt.context';\nimport classes from './Prompt.module.css';\nimport {PromptCancelButton, PromptCancelButtonStylesNamesVariant} from './PromptCancelButton';\nimport {PromptConfirmButton, PromptConfirmButtonStylesNamesVariant} from './PromptConfirmButton';\nimport CriticalIcon from './icons/CriticalIcon';\nimport InfoIcon from './icons/InfoIcon';\nimport SuccessIcon from './icons/SuccessIcon';\nimport WarningIcon from './icons/WarningIcon';\n\nexport type PromptVariant = 'success' | 'warning' | 'critical' | 'info';\nexport type PromptVars = {root: '--prompt-icon-size'};\nexport type PromptStylesNames =\n | Exclude<ModalStylesNames, 'title'>\n | 'icon'\n | PromptCancelButtonStylesNamesVariant\n | PromptConfirmButtonStylesNamesVariant;\n\nexport interface PromptProps\n extends StylesApiProps<PromptFactory>,\n Omit<ModalRootProps, 'classNames' | 'styles' | 'vars'> {\n /**\n * Controls prompt appearance\n *\n * @default \"info\"\n */\n variant?: PromptVariant;\n children: ReactNode;\n title: ReactNode;\n}\n\nexport type PromptFactory = Factory<{\n props: PromptProps;\n ref: HTMLDivElement;\n vars: PromptVars;\n variant: PromptVariant;\n stylesNames: PromptStylesNames;\n staticComponents: {\n CancelButton: typeof PromptCancelButton;\n ConfirmButton: typeof PromptConfirmButton;\n Footer: typeof PromptFooter;\n };\n}>;\n\nconst PromptVariantIconsMapping: Record<PromptVariant, ComponentType> = {\n success: SuccessIcon,\n warning: WarningIcon,\n critical: CriticalIcon,\n info: InfoIcon,\n};\n\nconst defaultProps: Partial<PromptProps> = {\n variant: 'info',\n centered: true,\n};\n\nexport const Prompt = factory<PromptFactory>((_props, ref) => {\n const props = useProps('Prompt', defaultProps, _props);\n const {variant, title, children, className, classNames, style, styles, unstyled, vars, ...others} = props;\n const getStyles = useStyles<PromptFactory>({\n name: 'Prompt',\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n vars,\n });\n const stylesApiProps = {classNames, styles};\n\n const footers: ReactElement[] = [];\n const otherChildren: ReactElement[] = [];\n\n Children.forEach(children, (child: ReactElement) => {\n (child.type === Prompt.Footer ? footers : otherChildren).push(child);\n });\n\n const IconComponent = PromptVariantIconsMapping[variant];\n\n return (\n <PromptContextProvider value={{variant, getStyles}}>\n <Modal.Root ref={ref} variant=\"prompt\" size=\"sm\" {...others} {...getStyles('root')}>\n <Modal.Overlay {...getStyles('overlay', stylesApiProps)} />\n <Modal.Content {...getStyles('content', stylesApiProps)}>\n <Modal.Header {...getStyles('header', stylesApiProps)}>\n <IconComponent />\n <Modal.Title>\n <Title order={3} component=\"div\">\n {title}\n </Title>\n </Modal.Title>\n <Modal.CloseButton {...getStyles('close', stylesApiProps)} />\n </Modal.Header>\n <Modal.Body {...getStyles('body', stylesApiProps)}>\n <Box {...getStyles('inner', stylesApiProps)}>{otherChildren}</Box>\n </Modal.Body>\n {footers}\n </Modal.Content>\n </Modal.Root>\n </PromptContextProvider>\n );\n});\n\nconst PromptFooter = Modal.Footer.withProps({pt: 0});\n\nPrompt.CancelButton = PromptCancelButton;\nPrompt.ConfirmButton = PromptConfirmButton;\nPrompt.Footer = PromptFooter;\n"],"names":["Prompt","PromptVariantIconsMapping","success","SuccessIcon","warning","WarningIcon","critical","CriticalIcon","info","InfoIcon","defaultProps","variant","centered","factory","_props","ref","props","useProps","title","children","className","classNames","style","styles","unstyled","vars","others","getStyles","useStyles","name","classes","stylesApiProps","footers","otherChildren","Children","forEach","child","type","Footer","push","IconComponent","PromptContextProvider","value","Modal","Root","size","Overlay","Content","Header","Title","order","component","CloseButton","Body","Box","PromptFooter","withProps","pt","CancelButton","PromptCancelButton","ConfirmButton","PromptConfirmButton"],"mappings":";;;;+BAoEaA;;;eAAAA;;;;;;;;oBA1DN;qBACwD;qBAC3C;6BACgB;wEAChB;kCACmD;mCACE;qEAChD;iEACJ;oEACG;oEACA;AAoCxB,IAAMC,4BAAkE;IACpEC,SAASC,oBAAW;IACpBC,SAASC,oBAAW;IACpBC,UAAUC,qBAAY;IACtBC,MAAMC,iBAAQ;AAClB;AAEA,IAAMC,eAAqC;IACvCC,SAAS;IACTC,UAAU;AACd;AAEO,IAAMZ,SAASa,IAAAA,aAAO,EAAgB,SAACC,QAAQC;IAClD,IAAMC,QAAQC,IAAAA,cAAQ,EAAC,UAAUP,cAAcI;IAC/C,IAAOH,UAA6FK,MAA7FL,SAASO,QAAoFF,MAApFE,OAAOC,WAA6EH,MAA7EG,UAAUC,YAAmEJ,MAAnEI,WAAWC,aAAwDL,MAAxDK,YAAYC,QAA4CN,MAA5CM,OAAOC,SAAqCP,MAArCO,QAAQC,WAA6BR,MAA7BQ,UAAUC,OAAmBT,MAAnBS,MAASC,sCAAUV;QAA7FL;QAASO;QAAOC;QAAUC;QAAWC;QAAYC;QAAOC;QAAQC;QAAUC;;IACjF,IAAME,YAAYC,IAAAA,eAAS,EAAgB;QACvCC,MAAM;QACNb,OAAAA;QACAc,SAAAA,wBAAO;QACPV,WAAAA;QACAE,OAAAA;QACAD,YAAAA;QACAE,QAAAA;QACAC,UAAAA;QACAC,MAAAA;IACJ;IACA,IAAMM,iBAAiB;QAACV,YAAAA;QAAYE,QAAAA;IAAM;IAE1C,IAAMS,UAA0B,EAAE;IAClC,IAAMC,gBAAgC,EAAE;IAExCC,eAAQ,CAACC,OAAO,CAAChB,UAAU,SAACiB;QACvBA,CAAAA,MAAMC,IAAI,KAAKrC,OAAOsC,MAAM,GAAGN,UAAUC,aAAY,EAAGM,IAAI,CAACH;IAClE;IAEA,IAAMI,gBAAgBvC,yBAAyB,CAACU,QAAQ;IAExD,qBACI,qBAAC8B,oCAAqB;QAACC,OAAO;YAAC/B,SAAAA;YAASgB,WAAAA;QAAS;kBAC7C,cAAA,sBAACgB,YAAK,CAACC,IAAI;YAAC7B,KAAKA;YAAKJ,SAAQ;YAASkC,MAAK;WAASnB,QAAYC,UAAU;;8BACvE,qBAACgB,YAAK,CAACG,OAAO,uBAAKnB,UAAU,WAAWI;8BACxC,sBAACY,YAAK,CAACI,OAAO,8CAAKpB,UAAU,WAAWI;;sCACpC,sBAACY,YAAK,CAACK,MAAM,8CAAKrB,UAAU,UAAUI;;8CAClC,qBAACS;8CACD,qBAACG,YAAK,CAACM,KAAK;8CACR,cAAA,qBAACA,WAAK;wCAACC,OAAO;wCAAGC,WAAU;kDACtBjC;;;8CAGT,qBAACyB,YAAK,CAACS,WAAW,uBAAKzB,UAAU,SAASI;;;sCAE9C,qBAACY,YAAK,CAACU,IAAI,8CAAK1B,UAAU,QAAQI;sCAC9B,cAAA,qBAACuB,SAAG,8CAAK3B,UAAU,SAASI;0CAAkBE;;;wBAEjDD;;;;;;AAKrB;AAEA,IAAMuB,eAAeZ,YAAK,CAACL,MAAM,CAACkB,SAAS,CAAC;IAACC,IAAI;AAAC;AAElDzD,OAAO0D,YAAY,GAAGC,sCAAkB;AACxC3D,OAAO4D,aAAa,GAAGC,wCAAmB;AAC1C7D,OAAOsC,MAAM,GAAGiB"}
|
|
@@ -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;AAoBD,eAAO,MAAM,yBAAyB,gHAfqC,MAAO,YACjF;;;;;eAGqC,MAClB,WAAP;mCAYZ,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';\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';\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\n ref={ref}\n style={{'&:hover': {cursor: 'not-allowed'}, width: fullWidth && '100%'}}\n display=\"inline-block\"\n {...others}\n >\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","display","ButtonWithDisabledTooltip"],"mappings":";AAAA,SAAQA,GAAG,EAAEC,OAAO,QAAqB,gBAAgB;AACzD,SAAmBC,UAAU,QAAO,QAAQ;AAE5C,SAAQC,0BAA0B,QAAO,cAAc;AAsBvD,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;YACGW,KAAKA;YACLE,OAAO;gBAAC,WAAW;oBAACC,QAAQ;gBAAa;gBAAGC,OAAON,aAAa;YAAM;YACtEO,SAAQ;YACP,GAAGN,MAAM;sBAETH;;uBAIT;kBAAGA;;AAIf,OAAO,MAAMU,4BAA4Bd,2BACrCC,4BACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../../../src/components/collection/Collection.tsx"],"names":[],"mappings":"AAIA,OAAO,EACH,mBAAmB,EAEnB,QAAQ,EACR,OAAO,EAEP,cAAc,EAEd,cAAc,EAGjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAC,YAAY,EAAE,SAAS,EAAC,MAAM,OAAO,CAAC;AAE9C,OAAO,EAAC,0BAA0B,EAAW,MAAM,aAAa,CAAC;AAMjE,MAAM,WAAW,eAAe,CAAC,CAAC,CAAE,SAAQ,mBAAmB,EAAE,QAAQ,EAAE,cAAc,CAAC,iBAAiB,CAAC;IACxG;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC;IACX;;;;;OAKG;I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@ -80,14 +80,16 @@ export const Collection = (props)=>{
|
|
|
80
80
|
children: children(item.data, index)
|
|
81
81
|
}, item.id));
|
|
82
82
|
const addAllowed = allowAdd?.(value) ?? true;
|
|
83
|
-
const _addButton = canEdit ? /*#__PURE__*/ _jsx(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
const _addButton = canEdit ? /*#__PURE__*/ _jsx(Box, {
|
|
84
|
+
children: /*#__PURE__*/ _jsx(Button.Quaternary, {
|
|
85
|
+
leftSection: /*#__PURE__*/ _jsx(IconPlus, {
|
|
86
|
+
size: 16
|
|
87
|
+
}),
|
|
88
|
+
onClick: ()=>onInsertItem(newItem, value?.length ?? 0),
|
|
89
|
+
disabled: !addAllowed,
|
|
90
|
+
disabledTooltip: addDisabledTooltip,
|
|
91
|
+
children: addLabel
|
|
92
|
+
})
|
|
91
93
|
}) : null;
|
|
92
94
|
const getIndex = (id)=>standardizedItems.findIndex((item)=>item.id === id);
|
|
93
95
|
const handleDragEnd = ({ over, active })=>{
|
|
@@ -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 {ReorderPayload} from '@mantine/form/lib/types';\nimport {useDidUpdate} from '@mantine/hooks';\nimport {ForwardedRef, ReactNode} from 'react';\n\nimport {CustomComponentThemeExtend, identity} from '../../utils';\nimport {Button} from '../button';\nimport classes from './Collection.module.css';\nimport {CollectionProvider} from './CollectionContext';\nimport {CollectionItem} from './CollectionItem';\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: ReorderPayload) => 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 <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 ) : 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;AAEvB,SAAQC,YAAY,QAAO,iBAAiB;AAG5C,SAAoCC,QAAQ,QAAO,cAAc;AACjE,SAAQC,MAAM,QAAO,YAAY;AACjC,OAAOC,aAAa,0BAA0B;AAC9C,SAAQC,kBAAkB,QAAO,sBAAsB;AACvD,SAAQC,cAAc,QAAO,mBAAmB;AAuHhD,MAAMC,eAAkD;IACpDC,WAAW;IACXC,UAAU;IACVC,oBAAoB;IACpBC,UAAU;IACVC,UAAU;IACVC,KAAK;IACLC,UAAU;IACVC,WAAW,CAAC,EAACC,EAAE,EAA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;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 {ReorderPayload} from '@mantine/form/lib/types';\nimport {useDidUpdate} from '@mantine/hooks';\nimport {ForwardedRef, ReactNode} from 'react';\n\nimport {CustomComponentThemeExtend, identity} from '../../utils';\nimport {Button} from '../button';\nimport classes from './Collection.module.css';\nimport {CollectionProvider} from './CollectionContext';\nimport {CollectionItem} from './CollectionItem';\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: ReorderPayload) => 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;AAEvB,SAAQC,YAAY,QAAO,iBAAiB;AAG5C,SAAoCC,QAAQ,QAAO,cAAc;AACjE,SAAQC,MAAM,QAAO,YAAY;AACjC,OAAOC,aAAa,0BAA0B;AAC9C,SAAQC,kBAAkB,QAAO,sBAAsB;AACvD,SAAQC,cAAc,QAAO,mBAAmB;AAuHhD,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,WAAW,EACXC,gBAAgB,EAChBC,KAAK,EACLC,UAAU,EACVlB,SAAS,EACTmB,GAAG,EAEH,cAAc;IACdC,KAAK,EACLC,SAAS,EACTC,UAAU,EACVC,MAAM,E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AK7C,EAAE;IAWpB,MAAMoD,aAAa1C,WAAWP,UAAU;IAExC,MAAMkD,aAAaxB,wBACf,KAACjD;kBACG,cAAA,KAACO,OAAOmE,UAAU;YACdC,2BAAa,KAACtF;gBAASuF,MAAM;;YAC7BC,SAAS,IAAMlD,aAAaE,SAASN,OAAO4B,UAAU;YACtDpC,UAAU,CAACyD;YACXM,iBAAiBhE;sBAEhBD;;SAGT;IAEJ,MAAMkE,WAAW,CAAC3D,KAAe2C,kBAAkBiB,SAAS,CAAC,CAACf,OAASA,KAAK7C,EAAE,KAAKA;IAEnF,MAAM6D,gBAAgB,CAAC,EAACC,IAAI,EAAEC,MAAM,EAAe;QAC/C,IAAID,MAAM;YACN,MAAME,cAAcL,SAASZ,OAAOgB,OAAO/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,6 +1,5 @@
|
|
|
1
1
|
import { Factory, ModalRootProps, ModalStylesNames, StylesApiProps } from '@mantine/core';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { Modal } from '../modal';
|
|
4
3
|
import { PromptCancelButton, PromptCancelButtonStylesNamesVariant } from './PromptCancelButton';
|
|
5
4
|
import { PromptConfirmButton, PromptConfirmButtonStylesNamesVariant } from './PromptConfirmButton';
|
|
6
5
|
export type PromptVariant = 'success' | 'warning' | 'critical' | 'info';
|
|
@@ -27,7 +26,7 @@ export type PromptFactory = Factory<{
|
|
|
27
26
|
staticComponents: {
|
|
28
27
|
CancelButton: typeof PromptCancelButton;
|
|
29
28
|
ConfirmButton: typeof PromptConfirmButton;
|
|
30
|
-
Footer: typeof
|
|
29
|
+
Footer: typeof PromptFooter;
|
|
31
30
|
};
|
|
32
31
|
}>;
|
|
33
32
|
export declare const Prompt: import("@mantine/core").MantineComponent<{
|
|
@@ -39,7 +38,12 @@ export declare const Prompt: import("@mantine/core").MantineComponent<{
|
|
|
39
38
|
staticComponents: {
|
|
40
39
|
CancelButton: typeof PromptCancelButton;
|
|
41
40
|
ConfirmButton: typeof PromptConfirmButton;
|
|
42
|
-
Footer: typeof
|
|
41
|
+
Footer: typeof PromptFooter;
|
|
43
42
|
};
|
|
44
43
|
}>;
|
|
44
|
+
declare const PromptFooter: import("react").ForwardRefExoticComponent<import("../modal").ModalFooterProps & import("react").RefAttributes<HTMLDivElement> & {
|
|
45
|
+
component?: any;
|
|
46
|
+
renderRoot?: (props: Record<string, any>) => React.ReactNode;
|
|
47
|
+
}>;
|
|
48
|
+
export {};
|
|
45
49
|
//# sourceMappingURL=Prompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Prompt.d.ts","sourceRoot":"","sources":["../../../../src/components/prompt/Prompt.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGH,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,cAAc,EAIjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAwC,SAAS,EAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Prompt.d.ts","sourceRoot":"","sources":["../../../../src/components/prompt/Prompt.tsx"],"names":[],"mappings":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Z;QACd,YAAY,EAAE,OAAO,kBAAkB,CAAC;QACxC,aAAa,EAAE,OAAO,mBAAmB,CAAC;QAC1C,MAAM,EAAE,OAAO,YAAY,CAAC;KAC/B;EA8DH,CAAC;AAEH,QAAA,MAAM,YAAY;;iDAtDN,MAAQ,SAAQ;EAsDwB,CAAC"}
|
|
@@ -92,8 +92,11 @@ export const Prompt = factory((_props, ref)=>{
|
|
|
92
92
|
})
|
|
93
93
|
});
|
|
94
94
|
});
|
|
95
|
+
const PromptFooter = Modal.Footer.withProps({
|
|
96
|
+
pt: 0
|
|
97
|
+
});
|
|
95
98
|
Prompt.CancelButton = PromptCancelButton;
|
|
96
99
|
Prompt.ConfirmButton = PromptConfirmButton;
|
|
97
|
-
Prompt.Footer =
|
|
100
|
+
Prompt.Footer = PromptFooter;
|
|
98
101
|
|
|
99
102
|
//# sourceMappingURL=Prompt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/prompt/Prompt.tsx"],"sourcesContent":["import {\n Box,\n factory,\n Factory,\n ModalRootProps,\n ModalStylesNames,\n StylesApiProps,\n Title,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport {Children, ComponentType, ReactElement, ReactNode} from 'react';\nimport {Modal} from '../modal';\nimport {PromptContextProvider} from './Prompt.context';\nimport classes from './Prompt.module.css';\nimport {PromptCancelButton, PromptCancelButtonStylesNamesVariant} from './PromptCancelButton';\nimport {PromptConfirmButton, PromptConfirmButtonStylesNamesVariant} from './PromptConfirmButton';\nimport CriticalIcon from './icons/CriticalIcon';\nimport InfoIcon from './icons/InfoIcon';\nimport SuccessIcon from './icons/SuccessIcon';\nimport WarningIcon from './icons/WarningIcon';\n\nexport type PromptVariant = 'success' | 'warning' | 'critical' | 'info';\nexport type PromptVars = {root: '--prompt-icon-size'};\nexport type PromptStylesNames =\n | Exclude<ModalStylesNames, 'title'>\n | 'icon'\n | PromptCancelButtonStylesNamesVariant\n | PromptConfirmButtonStylesNamesVariant;\n\nexport interface PromptProps\n extends StylesApiProps<PromptFactory>,\n Omit<ModalRootProps, 'classNames' | 'styles' | 'vars'> {\n /**\n * Controls prompt appearance\n *\n * @default \"info\"\n */\n variant?: PromptVariant;\n children: ReactNode;\n title: ReactNode;\n}\n\nexport type PromptFactory = Factory<{\n props: PromptProps;\n ref: HTMLDivElement;\n vars: PromptVars;\n variant: PromptVariant;\n stylesNames: PromptStylesNames;\n staticComponents: {\n CancelButton: typeof PromptCancelButton;\n ConfirmButton: typeof PromptConfirmButton;\n Footer: typeof
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/prompt/Prompt.tsx"],"sourcesContent":["import {\n Box,\n factory,\n Factory,\n ModalRootProps,\n ModalStylesNames,\n StylesApiProps,\n Title,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport {Children, ComponentType, ReactElement, ReactNode} from 'react';\nimport {Modal} from '../modal';\nimport {PromptContextProvider} from './Prompt.context';\nimport classes from './Prompt.module.css';\nimport {PromptCancelButton, PromptCancelButtonStylesNamesVariant} from './PromptCancelButton';\nimport {PromptConfirmButton, PromptConfirmButtonStylesNamesVariant} from './PromptConfirmButton';\nimport CriticalIcon from './icons/CriticalIcon';\nimport InfoIcon from './icons/InfoIcon';\nimport SuccessIcon from './icons/SuccessIcon';\nimport WarningIcon from './icons/WarningIcon';\n\nexport type PromptVariant = 'success' | 'warning' | 'critical' | 'info';\nexport type PromptVars = {root: '--prompt-icon-size'};\nexport type PromptStylesNames =\n | Exclude<ModalStylesNames, 'title'>\n | 'icon'\n | PromptCancelButtonStylesNamesVariant\n | PromptConfirmButtonStylesNamesVariant;\n\nexport interface PromptProps\n extends StylesApiProps<PromptFactory>,\n Omit<ModalRootProps, 'classNames' | 'styles' | 'vars'> {\n /**\n * Controls prompt appearance\n *\n * @default \"info\"\n */\n variant?: PromptVariant;\n children: ReactNode;\n title: ReactNode;\n}\n\nexport type PromptFactory = Factory<{\n props: PromptProps;\n ref: HTMLDivElement;\n vars: PromptVars;\n variant: PromptVariant;\n stylesNames: PromptStylesNames;\n staticComponents: {\n CancelButton: typeof PromptCancelButton;\n ConfirmButton: typeof PromptConfirmButton;\n Footer: typeof PromptFooter;\n };\n}>;\n\nconst PromptVariantIconsMapping: Record<PromptVariant, ComponentType> = {\n success: SuccessIcon,\n warning: WarningIcon,\n critical: CriticalIcon,\n info: InfoIcon,\n};\n\nconst defaultProps: Partial<PromptProps> = {\n variant: 'info',\n centered: true,\n};\n\nexport const Prompt = factory<PromptFactory>((_props, ref) => {\n const props = useProps('Prompt', defaultProps, _props);\n const {variant, title, children, className, classNames, style, styles, unstyled, vars, ...others} = props;\n const getStyles = useStyles<PromptFactory>({\n name: 'Prompt',\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n vars,\n });\n const stylesApiProps = {classNames, styles};\n\n const footers: ReactElement[] = [];\n const otherChildren: ReactElement[] = [];\n\n Children.forEach(children, (child: ReactElement) => {\n (child.type === Prompt.Footer ? footers : otherChildren).push(child);\n });\n\n const IconComponent = PromptVariantIconsMapping[variant];\n\n return (\n <PromptContextProvider value={{variant, getStyles}}>\n <Modal.Root ref={ref} variant=\"prompt\" size=\"sm\" {...others} {...getStyles('root')}>\n <Modal.Overlay {...getStyles('overlay', stylesApiProps)} />\n <Modal.Content {...getStyles('content', stylesApiProps)}>\n <Modal.Header {...getStyles('header', stylesApiProps)}>\n <IconComponent />\n <Modal.Title>\n <Title order={3} component=\"div\">\n {title}\n </Title>\n </Modal.Title>\n <Modal.CloseButton {...getStyles('close', stylesApiProps)} />\n </Modal.Header>\n <Modal.Body {...getStyles('body', stylesApiProps)}>\n <Box {...getStyles('inner', stylesApiProps)}>{otherChildren}</Box>\n </Modal.Body>\n {footers}\n </Modal.Content>\n </Modal.Root>\n </PromptContextProvider>\n );\n});\n\nconst PromptFooter = Modal.Footer.withProps({pt: 0});\n\nPrompt.CancelButton = PromptCancelButton;\nPrompt.ConfirmButton = PromptConfirmButton;\nPrompt.Footer = PromptFooter;\n"],"names":["Box","factory","Title","useProps","useStyles","Children","Modal","PromptContextProvider","classes","PromptCancelButton","PromptConfirmButton","CriticalIcon","InfoIcon","SuccessIcon","WarningIcon","PromptVariantIconsMapping","success","warning","critical","info","defaultProps","variant","centered","Prompt","_props","ref","props","title","children","className","classNames","style","styles","unstyled","vars","others","getStyles","name","stylesApiProps","footers","otherChildren","forEach","child","type","Footer","push","IconComponent","value","Root","size","Overlay","Content","Header","order","component","CloseButton","Body","PromptFooter","withProps","pt","CancelButton","ConfirmButton"],"mappings":";AAAA,SACIA,GAAG,EACHC,OAAO,EAKPC,KAAK,EACLC,QAAQ,EACRC,SAAS,QACN,gBAAgB;AACvB,SAAQC,QAAQ,QAA+C,QAAQ;AACvE,SAAQC,KAAK,QAAO,WAAW;AAC/B,SAAQC,qBAAqB,QAAO,mBAAmB;AACvD,OAAOC,aAAa,sBAAsB;AAC1C,SAAQC,kBAAkB,QAA6C,uBAAuB;AAC9F,SAAQC,mBAAmB,QAA8C,wBAAwB;AACjG,OAAOC,kBAAkB,uBAAuB;AAChD,OAAOC,cAAc,mBAAmB;AACxC,OAAOC,iBAAiB,sBAAsB;AAC9C,OAAOC,iBAAiB,sBAAsB;AAoC9C,MAAMC,4BAAkE;IACpEC,SAASH;IACTI,SAASH;IACTI,UAAUP;IACVQ,MAAMP;AACV;AAEA,MAAMQ,eAAqC;IACvCC,SAAS;IACTC,UAAU;AACd;AAEA,OAAO,MAAMC,SAAStB,QAAuB,CAACuB,QAAQC;IAClD,MAAMC,QAAQvB,SAAS,UAAUiB,cAAcI;IAC/C,MAAM,EAACH,OAAO,EAAEM,KAAK,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAAE,GAAGC,QAAO,GAAGT;IACpG,MAAMU,YAAYhC,UAAyB;QACvCiC,MAAM;QACNX;QACAlB;QACAqB;QACAE;QACAD;QACAE;QACAC;QACAC;IACJ;IACA,MAAMI,iBA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"version": "56.1.
|
|
3
|
+
"version": "56.1.2",
|
|
4
4
|
"description": "A Plasma flavoured Mantine theme",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plasma",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"lodash.debounce": "4.0.8",
|
|
43
43
|
"lodash.defaultsdeep": "4.6.1",
|
|
44
44
|
"monaco-editor": "0.52.2",
|
|
45
|
-
"@coveord/plasma-
|
|
46
|
-
"@coveord/plasma-
|
|
45
|
+
"@coveord/plasma-react-icons": "55.8.2",
|
|
46
|
+
"@coveord/plasma-tokens": "55.8.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@mantine/carousel": "8.0.2",
|
|
@@ -27,7 +27,12 @@ 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
|
|
30
|
+
<Box
|
|
31
|
+
ref={ref}
|
|
32
|
+
style={{'&:hover': {cursor: 'not-allowed'}, width: fullWidth && '100%'}}
|
|
33
|
+
display="inline-block"
|
|
34
|
+
{...others}
|
|
35
|
+
>
|
|
31
36
|
{children}
|
|
32
37
|
</Box>
|
|
33
38
|
</Tooltip>
|
|
@@ -252,14 +252,16 @@ export const Collection = <T,>(props: CollectionProps<T> & {ref?: ForwardedRef<H
|
|
|
252
252
|
const addAllowed = allowAdd?.(value) ?? true;
|
|
253
253
|
|
|
254
254
|
const _addButton = canEdit ? (
|
|
255
|
-
<
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
255
|
+
<Box>
|
|
256
|
+
<Button.Quaternary
|
|
257
|
+
leftSection={<IconPlus size={16} />}
|
|
258
|
+
onClick={() => onInsertItem(newItem, value?.length ?? 0)}
|
|
259
|
+
disabled={!addAllowed}
|
|
260
|
+
disabledTooltip={addDisabledTooltip}
|
|
261
|
+
>
|
|
262
|
+
{addLabel}
|
|
263
|
+
</Button.Quaternary>
|
|
264
|
+
</Box>
|
|
263
265
|
) : null;
|
|
264
266
|
|
|
265
267
|
const getIndex = (id: string) => standardizedItems.findIndex((item) => item.id === id);
|
|
@@ -50,7 +50,7 @@ export type PromptFactory = Factory<{
|
|
|
50
50
|
staticComponents: {
|
|
51
51
|
CancelButton: typeof PromptCancelButton;
|
|
52
52
|
ConfirmButton: typeof PromptConfirmButton;
|
|
53
|
-
Footer: typeof
|
|
53
|
+
Footer: typeof PromptFooter;
|
|
54
54
|
};
|
|
55
55
|
}>;
|
|
56
56
|
|
|
@@ -115,6 +115,8 @@ export const Prompt = factory<PromptFactory>((_props, ref) => {
|
|
|
115
115
|
);
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
+
const PromptFooter = Modal.Footer.withProps({pt: 0});
|
|
119
|
+
|
|
118
120
|
Prompt.CancelButton = PromptCancelButton;
|
|
119
121
|
Prompt.ConfirmButton = PromptConfirmButton;
|
|
120
|
-
Prompt.Footer =
|
|
122
|
+
Prompt.Footer = PromptFooter;
|