@coveord/plasma-mantine 48.28.3 → 49.0.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.
Files changed (46) hide show
  1. package/.turbo/turbo-build.log +3 -3
  2. package/.turbo/turbo-test.log +8 -8
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/cjs/components/collection/Collection.js +21 -23
  5. package/dist/cjs/components/collection/Collection.js.map +1 -1
  6. package/dist/cjs/form/FormProvider.js +38 -0
  7. package/dist/cjs/form/FormProvider.js.map +1 -0
  8. package/dist/cjs/form/index.js +9 -0
  9. package/dist/cjs/form/index.js.map +1 -0
  10. package/dist/cjs/form/useForm.js +43 -0
  11. package/dist/cjs/form/useForm.js.map +1 -0
  12. package/dist/cjs/index.js +8 -1
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/theme/Theme.js +5 -0
  15. package/dist/cjs/theme/Theme.js.map +1 -1
  16. package/dist/definitions/components/collection/Collection.d.ts +14 -4
  17. package/dist/definitions/components/collection/Collection.d.ts.map +1 -1
  18. package/dist/definitions/form/FormProvider.d.ts +8 -0
  19. package/dist/definitions/form/FormProvider.d.ts.map +1 -0
  20. package/dist/definitions/form/index.d.ts +3 -0
  21. package/dist/definitions/form/index.d.ts.map +1 -0
  22. package/dist/definitions/form/useForm.d.ts +3 -0
  23. package/dist/definitions/form/useForm.d.ts.map +1 -0
  24. package/dist/definitions/index.d.ts +2 -1
  25. package/dist/definitions/index.d.ts.map +1 -1
  26. package/dist/definitions/theme/Theme.d.ts.map +1 -1
  27. package/dist/esm/components/collection/Collection.js +22 -24
  28. package/dist/esm/components/collection/Collection.js.map +1 -1
  29. package/dist/esm/form/FormProvider.js +27 -0
  30. package/dist/esm/form/FormProvider.js.map +1 -0
  31. package/dist/esm/form/index.js +4 -0
  32. package/dist/esm/form/index.js.map +1 -0
  33. package/dist/esm/form/useForm.js +33 -0
  34. package/dist/esm/form/useForm.js.map +1 -0
  35. package/dist/esm/index.js +2 -1
  36. package/dist/esm/index.js.map +1 -1
  37. package/dist/esm/theme/Theme.js +5 -0
  38. package/dist/esm/theme/Theme.js.map +1 -1
  39. package/package.json +3 -2
  40. package/src/components/collection/Collection.tsx +32 -19
  41. package/src/components/collection/__tests__/Collection.spec.tsx +1 -1
  42. package/src/form/FormProvider.tsx +38 -0
  43. package/src/form/index.ts +2 -0
  44. package/src/form/useForm.ts +26 -0
  45. package/src/index.ts +3 -1
  46. package/src/theme/Theme.tsx +5 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/collection/Collection.tsx"],"sourcesContent":["import {AddSize16Px} from '@coveord/plasma-react-icons';\nimport {\n Box,\n Button,\n DefaultProps,\n Group,\n Input,\n InputWrapperBaseProps,\n MantineNumberSize,\n Selectors,\n Stack,\n Tooltip,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useId} from '@mantine/hooks';\nimport {ReactNode} from 'react';\nimport {DragDropContext, Droppable} from 'react-beautiful-dnd';\nimport {useControlledList} from '../../hooks';\nimport {CollectionItem} from './CollectionItem';\nimport useStyles from './Collection.styles';\n\ninterface CollectionProps<T>\n extends Omit<InputWrapperBaseProps, 'inputContainer' | 'inputWrapperOrder'>,\n DefaultProps<Selectors<typeof useStyles>> {\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 * The initial items of the collection (for uncontrolled usage only)\n */\n defaultValue?: T[];\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 * 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 * 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 spacing between the colleciton items\n *\n * @default 'xs'\n */\n spacing?: MantineNumberSize;\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\nconst defaultProps: Partial<CollectionProps<unknown>> = {\n draggable: false,\n addLabel: 'Add item',\n addDisabledTooltip: 'There is already an empty item',\n disabled: false,\n spacing: 'xs',\n required: false,\n};\n\nexport const Collection = <T,>(props: CollectionProps<T>) => {\n const {\n value,\n defaultValue,\n onChange,\n onRemoveItem,\n disabled,\n draggable,\n children,\n spacing,\n required,\n newItem,\n addLabel,\n addDisabledTooltip,\n allowAdd,\n label,\n labelProps,\n description,\n descriptionProps,\n error,\n errorProps,\n\n // Style props\n classNames,\n className,\n styles,\n unstyled,\n\n ...others\n } = useComponentDefaultProps('Collection', defaultProps as CollectionProps<T>, props);\n const {classes, cx} = useStyles(null, {classNames, name: 'Collection', styles, unstyled});\n const collectionID = useId('dnd-droppable');\n\n const [values, {append, remove, reorder}] = useControlledList({value, onChange, defaultValue});\n const hasOnlyOneItem = values.length === 1;\n const removeItem = (index: number) => () => {\n remove(index);\n onRemoveItem?.(index);\n };\n\n const _label = label ? (\n <Input.Label required={required} {...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 <Box mb=\"sm\">\n {_label}\n {_description}\n </Box>\n ) : null;\n\n const items = values.map((item, index) => (\n <CollectionItem\n key={index}\n disabled={disabled}\n draggable={draggable}\n index={index}\n onRemove={removeItem(index)}\n styles={styles}\n removable={!(required && hasOnlyOneItem)}\n >\n {children(item, index)}\n </CollectionItem>\n ));\n\n const addAllowed = allowAdd?.(values) ?? true;\n\n const _addButton = disabled ? null : (\n <Group>\n <Tooltip label={addDisabledTooltip} disabled={addAllowed}>\n <Box>\n <Button\n variant=\"subtle\"\n leftIcon={<AddSize16Px height={16} />}\n onClick={() => append(newItem)}\n disabled={!addAllowed}\n >\n {addLabel}\n </Button>\n </Box>\n </Tooltip>\n </Group>\n );\n\n return (\n <DragDropContext\n onDragEnd={({destination, source}) => reorder({from: source.index, to: destination?.index || 0})}\n >\n <Droppable direction=\"vertical\" droppableId={collectionID}>\n {(provided) => (\n <Box\n {...provided.droppableProps}\n ref={provided.innerRef}\n className={cx(classes.root, className)}\n {...others}\n >\n {_header}\n <Stack spacing={spacing}>\n {items}\n {provided.placeholder}\n {_addButton}\n {_error}\n </Stack>\n </Box>\n )}\n </Droppable>\n </DragDropContext>\n );\n};\n"],"names":["AddSize16Px","Box","Button","Group","Input","Stack","Tooltip","useComponentDefaultProps","useId","DragDropContext","Droppable","useControlledList","CollectionItem","useStyles","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","spacing","required","Collection","props","value","defaultValue","onChange","onRemoveItem","children","newItem","allowAdd","label","labelProps","description","descriptionProps","error","errorProps","classNames","className","styles","unstyled","others","name","classes","cx","collectionID","values","append","remove","reorder","hasOnlyOneItem","length","removeItem","index","_label","Label","_description","Description","_error","Error","_header","mb","items","map","item","onRemove","removable","addAllowed","_addButton","variant","leftIcon","height","onClick","onDragEnd","destination","source","from","to","direction","droppableId","provided","droppableProps","ref","innerRef","root","placeholder"],"mappings":"AAAA;;;;;AAAA,SAAQA,WAAW,QAAO,8BAA8B;AACxD,SACIC,GAAG,EACHC,MAAM,EAENC,KAAK,EAC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UAAUgD;sBAC1C,cAAA,KAACjE;0BACG,cAAA,KAACC;oBACGkE,SAAQ;oBACRC,wBAAU,KAACrE;wBAAYsE,QAAQ;;oBAC/BC,SAAS;+BAAMzB,OAAOlB;;oBACtBV,UAAU,CAACgD;8BAEVlD;;;;MAKpB;IAED,qBACI,KAACP;QACG+D,WAAW;gBAAEC,oBAAAA,aAAaC,eAAAA;YAAY1B,OAAAA,QAAQ;gBAAC2B,MAAMD,OAAOtB,KAAK;gBAAEwB,IAAIH,CAAAA,wBAAAA,yBAAAA,KAAAA,IAAAA,YAAarB,KAAK,AAAD,KAAK;YAAC;;kBAE9F,cAAA,KAAC1C;YAAUmE,WAAU;YAAWC,aAAalC;sBACxC,SAACmC;qCACE,MAAC9E,iFACO8E,SAASC,cAAc;oBAC3BC,KAAKF,SAASG,QAAQ;oBACtB7C,WAAWM,GAAGD,QAAQyC,IAAI,EAAE9C;oBACxBG;;wBAEHmB;sCACD,MAACtD;4BAAMc,SAASA;;gCACX0C;gCACAkB,SAASK,WAAW;gCACpBjB;gCACAV;;;;;;;;AAO7B,EAAE"}
1
+ {"version":3,"sources":["../../../../src/components/collection/Collection.tsx"],"sourcesContent":["import {AddSize16Px} from '@coveord/plasma-react-icons';\nimport {\n Box,\n Button,\n DefaultProps,\n Group,\n Input,\n InputWrapperBaseProps,\n MantineNumberSize,\n Selectors,\n Stack,\n Tooltip,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {ReorderPayload} from '@mantine/form/lib/types';\nimport {useDidUpdate, useId} from '@mantine/hooks';\nimport {ReactNode} from 'react';\nimport {DragDropContext, Droppable} from 'react-beautiful-dnd';\n\nimport useStyles from './Collection.styles';\nimport {CollectionItem} from './CollectionItem';\n\ninterface CollectionProps<T>\n extends Omit<InputWrapperBaseProps, 'inputContainer' | 'inputWrapperOrder'>,\n DefaultProps<Selectors<typeof useStyles>> {\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 * 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 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 * 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 spacing between the colleciton items\n *\n * @default 'xs'\n */\n spacing?: MantineNumberSize;\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\nconst defaultProps: Partial<CollectionProps<unknown>> = {\n draggable: false,\n addLabel: 'Add item',\n addDisabledTooltip: 'There is already an empty item',\n disabled: false,\n spacing: 'xs',\n required: false,\n};\n\nexport const Collection = <T,>(props: CollectionProps<T>) => {\n const {\n value,\n onChange,\n onRemoveItem,\n onReorderItem,\n onInsertItem,\n disabled,\n draggable,\n children,\n spacing,\n required,\n newItem,\n addLabel,\n addDisabledTooltip,\n allowAdd,\n label,\n labelProps,\n description,\n descriptionProps,\n error,\n errorProps,\n\n // Style props\n classNames,\n className,\n styles,\n unstyled,\n\n ...others\n } = useComponentDefaultProps('Collection', defaultProps as CollectionProps<T>, props);\n const {classes, cx} = useStyles(null, {classNames, name: 'Collection', styles, unstyled});\n const collectionID = useId('dnd-droppable');\n\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 _label = label ? (\n <Input.Label required={required} {...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 <Box mb=\"sm\">\n {_label}\n {_description}\n </Box>\n ) : null;\n\n const items = value.map((item, index) => (\n <CollectionItem\n key={index}\n disabled={disabled}\n draggable={draggable}\n index={index}\n onRemove={() => onRemoveItem?.(index)}\n styles={styles}\n removable={!(required && hasOnlyOneItem)}\n >\n {children(item, index)}\n </CollectionItem>\n ));\n\n const addAllowed = allowAdd?.(value) ?? true;\n\n const _addButton = disabled ? null : (\n <Group>\n <Tooltip label={addDisabledTooltip} disabled={addAllowed}>\n <Box>\n <Button\n variant=\"subtle\"\n leftIcon={<AddSize16Px height={16} />}\n onClick={() => onInsertItem(newItem, value?.length ?? 0)}\n disabled={!addAllowed}\n >\n {addLabel}\n </Button>\n </Box>\n </Tooltip>\n </Group>\n );\n\n return (\n <DragDropContext\n onDragEnd={({destination, source}) => onReorderItem({from: source.index, to: destination?.index || 0})}\n >\n <Droppable direction=\"vertical\" droppableId={collectionID}>\n {(provided) => (\n <Box\n {...provided.droppableProps}\n ref={provided.innerRef}\n className={cx(classes.root, className)}\n {...others}\n >\n {_header}\n <Stack spacing={spacing}>\n {items}\n {provided.placeholder}\n {_addButton}\n {_error}\n </Stack>\n </Box>\n )}\n </Droppable>\n </DragDropContext>\n );\n};\n"],"names":["AddSize16Px","Box","Button","Group","Input","Stack","Tooltip","useComponentDefaultProps","useDidUpdate","useId","DragDropContext","Droppable","useStyles","CollectionItem","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","spacing","required","Collection","props","value","onChange","onRemoveItem","onReorderItem","onInsertItem","children","newItem","allowAdd","label","labelProps","description","descriptionProps","error","errorProps","classNames","className","styles","unstyled","others","name","classes","cx","collectionID","hasOnlyOneItem","length","JSON","stringify","_label","Label","_description","Description","_error","Error","_header","mb","items","map","item","index","onRemove","removable","addAllowed","_addButton","variant","leftIcon","height","onClick","onDragEnd","destination","source","from","to","direction","droppableId","provided","droppableProps","ref","innerRef","root","placeholder"],"mappings":"AAAA;;;;AAAA,SAAQA,WAAW,QAAO,8BAA8B;AACxD,SACIC,GAAG,EACHC,MAAM,EAENC,KAAK,EACLC,KAAK,EAILC,KAAK,EACLC,OAAO,EACPC,wBAAwB,QACrB,gBAAgB;AAEvB,SAAQC,YAAY,EAAEC,KAAK,QAAO,iBAAiB;AAEnD,SAAQC,eAAe,EAAEC,SAAS,QAAO,sBAAsB;AAE/D,OAAOC,eAAe,sBAAsB;AAC5C,SAAQC,cAAc,QAAO,mBAAmB;AAgGhD,IAAMC,eAAkD;IACpDC,WAAW,KAAK;IAChBC,UAAU;IACVC,oBAAoB;IACpBC,UAAU,KAAK;IACfC,SAAS;IACTC,UAAU,KAAK;AACnB;AAEA,OAAO,IAAMC,aAAa,SAAKC,OAA8B;IACzD,IA6BIf,4BAAAA,yBAAyB,cAAcO,cAAoCQ,QA5B3EC,QA4BAhB,0BA5BAgB,OACAC,WA2BAjB,0BA3BAiB,UACAC,eA0BAlB,0BA1BAkB,cACAC,gBAyBAnB,0BAzBAmB,eACAC,eAwBApB,0BAxBAoB,cACAT,WAuBAX,0BAvBAW,UACAH,YAsBAR,0BAtBAQ,WACAa,WAqBArB,0BArBAqB,UACAT,UAoBAZ,0BApB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K,WAAW;gCACpBjB;gCACAX;;;;;;;;AAO7B,EAAE"}
@@ -0,0 +1,27 @@
1
+ /* eslint-disable prefer-arrow/prefer-arrow-functions */ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React, { createContext, useContext } from "react";
3
+ import { useForm } from "./useForm";
4
+ export function createFormContext() {
5
+ var FormProvider = function FormProvider(param) {
6
+ var form = param.form, children = param.children;
7
+ return /*#__PURE__*/ _jsx(FormContext.Provider, {
8
+ value: form,
9
+ children: children
10
+ });
11
+ };
12
+ var useFormContext = function useFormContext() {
13
+ var ctx = useContext(FormContext);
14
+ if (!ctx) {
15
+ throw new Error("useFormContext was called outside of FormProvider context");
16
+ }
17
+ return ctx;
18
+ };
19
+ var FormContext = /*#__PURE__*/ createContext(null);
20
+ return [
21
+ FormProvider,
22
+ useFormContext,
23
+ useForm
24
+ ];
25
+ }
26
+
27
+ //# sourceMappingURL=FormProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/form/FormProvider.tsx"],"sourcesContent":["/* eslint-disable prefer-arrow/prefer-arrow-functions */\nimport {_TransformValues, UseForm, UseFormReturnType} from '@mantine/form/lib/types';\nimport React, {createContext, useContext} from 'react';\n\nimport {useForm} from './useForm';\n\nexport interface FormProviderProps<Form> {\n form: Form;\n children: React.ReactNode;\n}\n\nexport function createFormContext<\n Values,\n TransformValues extends _TransformValues<Values> = (values: Values) => Values\n>() {\n type Form = UseFormReturnType<Values, TransformValues>;\n\n const FormContext = createContext<Form>(null);\n\n function FormProvider({form, children}: FormProviderProps<Form>) {\n return <FormContext.Provider value={form}>{children}</FormContext.Provider>;\n }\n\n function useFormContext() {\n const ctx = useContext(FormContext);\n if (!ctx) {\n throw new Error('useFormContext was called outside of FormProvider context');\n }\n\n return ctx;\n }\n\n return [FormProvider, useFormContext, useForm] as [\n React.FC<FormProviderProps<Form>>,\n () => Form,\n UseForm<Values, TransformValues>\n ];\n}\n"],"names":["React","createContext","useContext","useForm","createFormContext","FormProvider","form","children","FormContext","Provider","value","useFormContext","ctx","Error"],"mappings":"AAAA,sDAAsD,GACtD;AACA,OAAOA,SAAQC,aAAa,EAAEC,UAAU,QAAO,QAAQ;AAEvD,SAAQC,OAAO,QAAO,YAAY;AAOlC,OAAO,SAASC,oBAGZ;QAKSC,eAAT,SAASA,aAAa,KAAyC,EAAE;YAA1CC,OAAD,MAACA,MAAMC,WAAP,MAAOA;QACzB,qBAAO,KAACC,YAAYC,QAAQ;YAACC,OAAOJ;sBAAOC;;IAC/C;QAESI,iBAAT,SAASA,iBAAiB;QACtB,IAAMC,MAAMV,WAAWM;QACvB,IAAI,CAACI,KAAK;YACN,MAAM,IAAIC,MAAM,6DAA6D;QACjF,CAAC;QAED,OAAOD;IACX;IAbA,IAAMJ,4BAAcP,cAAoB,IAAI;IAe5C,OAAO;QAACI;QAAcM;QAAgBR;KAAQ;AAKlD,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./useForm";
2
+ export * from "./FormProvider";
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/form/index.ts"],"sourcesContent":["export * from './useForm';\nexport * from './FormProvider';\n"],"names":[],"mappings":"AAAA,cAAc,YAAY;AAC1B,cAAc,iBAAiB"}
@@ -0,0 +1,33 @@
1
+ import _object_spread from "@swc/helpers/src/_object_spread.mjs";
2
+ import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
3
+ import { useForm as useMantineForm } from "@mantine/form";
4
+ export var useForm = function(options) {
5
+ var form = useMantineForm(options);
6
+ var getInputProps = function(path) {
7
+ var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, _ref_type = _ref.type, type = _ref_type === void 0 ? "input" : _ref_type, _ref_withError = _ref.withError, withError = _ref_withError === void 0 ? type === "input" : _ref_withError, _ref_withFocus = _ref.withFocus, withFocus = _ref_withFocus === void 0 ? true : _ref_withFocus;
8
+ var originalPayload = form.getInputProps(path, {
9
+ type: type,
10
+ withError: withError,
11
+ withFocus: withFocus
12
+ });
13
+ if (Array.isArray(originalPayload.value)) {
14
+ return _object_spread_props(_object_spread({}, originalPayload), {
15
+ onReorderItem: function(payload) {
16
+ return form.reorderListItem(path, payload);
17
+ },
18
+ onRemoveItem: function(index) {
19
+ return form.removeListItem(path, index);
20
+ },
21
+ onInsertItem: function(valueToInsert, index) {
22
+ return form.insertListItem(path, valueToInsert, index);
23
+ }
24
+ });
25
+ }
26
+ return originalPayload;
27
+ };
28
+ return _object_spread_props(_object_spread({}, form), {
29
+ getInputProps: getInputProps
30
+ });
31
+ };
32
+
33
+ //# sourceMappingURL=useForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/form/useForm.ts"],"sourcesContent":["import {useForm as useMantineForm} from '@mantine/form';\nimport {GetInputProps} from '@mantine/form/lib/types';\n\nexport const useForm: typeof useMantineForm = (options) => {\n const form = useMantineForm(options);\n\n const getInputProps: GetInputProps<Record<string, unknown>> = (\n path,\n {type = 'input', withError = type === 'input', withFocus = true} = {}\n ) => {\n const originalPayload = form.getInputProps(path, {type, withError, withFocus});\n if (Array.isArray(originalPayload.value)) {\n return {\n ...originalPayload,\n onReorderItem: (payload: Record<'from' | 'to', number>) => form.reorderListItem(path, payload),\n onRemoveItem: (index: number) => form.removeListItem(path, index),\n onInsertItem: (valueToInsert: unknown, index: number) =>\n form.insertListItem(path, valueToInsert, index),\n };\n }\n\n return originalPayload;\n };\n\n return {...form, getInputProps};\n};\n"],"names":["useForm","useMantineForm","options","form","getInputProps","path","type","withError","withFocus","originalPayload","Array","isArray","value","onReorderItem","payload","reorderListItem","onRemoveItem","index","removeListItem","onInsertItem","valueToInsert","insertListItem"],"mappings":"AAAA;;AAAA,SAAQA,WAAWC,cAAc,QAAO,gBAAgB;AAGxD,OAAO,IAAMD,UAAiC,SAACE,SAAY;IACvD,IAAMC,OAAOF,eAAeC;IAE5B,IAAME,gBAAwD,SAC1DC,MAEC;oFADkE,CAAC,oBAAnEC,MAAAA,8BAAO,2CAASC,WAAAA,wCAAYD,SAAS,gDAASE,WAAAA,wCAAY,IAAI;QAE/D,IAAMC,kBAAkBN,KAAKC,aAAa,CAACC,MAAM;YAACC,MAAAA;YAAMC,WAAAA;YAAWC,WAAAA;QAAS;QAC5E,IAAIE,MAAMC,OAAO,CAACF,gBAAgBG,KAAK,GAAG;YACtC,OAAO,wCACAH;gBACHI,eAAe,SAACC;2BAA2CX,KAAKY,eAAe,CAACV,MAAMS;;gBACtFE,cAAc,SAACC;2BAAkBd,KAAKe,cAAc,CAACb,MAAMY;;gBAC3DE,cAAc,SAACC,eAAwBH;2BACnCd,KAAKkB,cAAc,CAAChB,MAAMe,eAAeH;;;QAErD,CAAC;QAED,OAAOR;IACX;IAEA,OAAO,wCAAIN;QAAMC,eAAAA;;AACrB,EAAE"}
package/dist/esm/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  export * from "@mantine/carousel";
2
2
  export * from "@mantine/core";
3
- export * from "@mantine/form";
4
3
  export * from "@mantine/hooks";
5
4
  export { createColumnHelper } from "@tanstack/table-core";
6
5
  export * from "./components";
6
+ export * from "@mantine/form";
7
7
  // explicitly overriding mantine components
8
8
  export { Header, Table, Modal } from "./components";
9
+ export { useForm, createFormContext } from "./form";
9
10
  export * from "./theme";
10
11
 
11
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import {Tuple} from '@mantine/core';\n\nimport {PlasmaColors} from './theme/PlasmaColors';\n\nexport * from '@mantine/carousel';\nexport * from '@mantine/core';\nexport * from '@mantine/form';\nexport type {FormValidateInput} from '@mantine/form/lib/types';\nexport * from '@mantine/hooks';\nexport {createColumnHelper, type ColumnDef} from '@tanstack/table-core';\nexport * from './components';\n// explicitly overriding mantine components\nexport {Header, Table, type HeaderProps, Modal} from './components';\nexport * from './theme';\n\ndeclare module '@mantine/core' {\n export interface MantineThemeColorsOverride {\n // eslint-disable-next-line @typescript-eslint/ban-types\n colors: Record<keyof typeof PlasmaColors | (string & {}), Tuple<string, 10>>;\n }\n}\n"],"names":["createColumnHelper","Header","Table","Modal"],"mappings":"AAIA,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAC9B,cAAc,gBAAgB;AAE9B,cAAc,iBAAiB;AAC/B,SAAQA,kBAAkB,QAAuB,uBAAuB;AACxE,cAAc,eAAe;AAC7B,2CAA2C;AAC3C,SAAQC,MAAM,EAAEC,KAAK,EAAoBC,KAAK,QAAO,eAAe;AACpE,cAAc,UAAU"}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import {Tuple} from '@mantine/core';\n\nimport {PlasmaColors} from './theme/PlasmaColors';\n\nexport * from '@mantine/carousel';\nexport * from '@mantine/core';\nexport type {FormValidateInput} from '@mantine/form/lib/types';\nexport * from '@mantine/hooks';\nexport {createColumnHelper, type ColumnDef} from '@tanstack/table-core';\nexport * from './components';\nexport * from '@mantine/form';\n// explicitly overriding mantine components\nexport {Header, Table, type HeaderProps, Modal} from './components';\nexport {useForm, createFormContext} from './form';\n\nexport * from './theme';\n\ndeclare module '@mantine/core' {\n export interface MantineThemeColorsOverride {\n // eslint-disable-next-line @typescript-eslint/ban-types\n colors: Record<keyof typeof PlasmaColors | (string & {}), Tuple<string, 10>>;\n }\n}\n"],"names":["createColumnHelper","Header","Table","Modal","useForm","createFormContext"],"mappings":"AAIA,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAE9B,cAAc,iBAAiB;AAC/B,SAAQA,kBAAkB,QAAuB,uBAAuB;AACxE,cAAc,eAAe;AAC7B,cAAc,gBAAgB;AAC9B,2CAA2C;AAC3C,SAAQC,MAAM,EAAEC,KAAK,EAAoBC,KAAK,QAAO,eAAe;AACpE,SAAQC,OAAO,EAAEC,iBAAiB,QAAO,SAAS;AAElD,cAAc,UAAU"}
@@ -227,6 +227,11 @@ export var plasmaTheme = {
227
227
  fontWeight: 500
228
228
  }
229
229
  }
230
+ },
231
+ ColorSwatch: {
232
+ defaultProps: {
233
+ size: 8
234
+ }
230
235
  }
231
236
  }
232
237
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/theme/Theme.tsx"],"sourcesContent":["import {ArrowHeadRightSize24Px, InfoSize24Px} from '@coveord/plasma-react-icons';\nimport {color} from '@coveord/plasma-tokens';\nimport {ButtonStylesParams, MantineThemeOverride, ModalStylesParams} from '@mantine/core';\n\nimport {PlasmaColors} from './PlasmaColors';\n\nexport const plasmaTheme: MantineThemeOverride = {\n // These are overrides over https://github.com/mantinedev/mantine/blob/master/src/mantine-styles/src/theme/default-theme.ts\n colorScheme: 'light',\n fontFamily: 'canada-type-gibson, sans-serif',\n black: color.primary.gray[9],\n defaultRadius: 8,\n spacing: {\n xs: 8,\n sm: 16,\n md: 24,\n lg: 32,\n xl: 40,\n },\n primaryColor: 'action',\n headings: {\n fontFamily: 'canada-type-gibson, sans-serif',\n fontWeight: 500,\n sizes: {\n h1: {fontSize: 48, lineHeight: '56px', fontWeight: undefined},\n h2: {fontSize: 32, lineHeight: '40px', fontWeight: undefined},\n h3: {fontSize: 28, lineHeight: '40px', fontWeight: undefined},\n h4: {fontSize: 24, lineHeight: '32px', fontWeight: undefined},\n h5: {fontSize: 18, lineHeight: '28px', fontWeight: undefined},\n h6: {fontSize: 16, lineHeight: '24px', fontWeight: undefined},\n },\n },\n shadows: {\n xs: '0px 1px 0px rgba(4, 8, 31, 0.08)',\n sm: '0px 2px 4px rgba(4, 8, 31, 0.12)',\n md: '0px 4px 8px rgba(4, 8, 31, 0.08)',\n lg: '0px 8px 16px rgba(7, 12, 41, 0.06)',\n xl: '0px 16px 24px rgba(4, 8, 31, 0.06)',\n },\n colors: PlasmaColors,\n components: {\n Alert: {\n defaultProps: {\n icon: <InfoSize24Px height={24} />,\n color: 'navy',\n },\n styles: {\n title: {\n fontWeight: 500,\n },\n },\n },\n Title: {\n styles: (theme) => ({\n root: {\n '&:is(h1,h2,h3,h4,h5,h6)': {letterSpacing: '0.011em', color: theme.colors.gray[9]},\n },\n }),\n },\n Button: {\n styles: (theme, params: ButtonStylesParams) => ({\n root: {\n fontWeight: 400,\n backgroundColor: params.variant === 'outline' ? 'white' : undefined,\n },\n }),\n },\n Modal: {\n styles: (theme, {size, fullScreen}: ModalStylesParams) => ({\n modal: {\n width: fullScreen\n ? undefined\n : theme.fn.size({size, sizes: {xs: 440, sm: 550, md: 800, lg: 1334, xl: '85%'}}),\n },\n }),\n defaultProps: {\n overlayColor: color.primary.navy[9],\n overlayOpacity: 0.9,\n },\n },\n InputWrapper: {\n defaultProps: {\n withAsterisk: false,\n },\n styles: (theme) => ({\n label: {\n marginBottom: theme.spacing.xs,\n lineHeight: '20px',\n },\n description: {\n lineHeight: '20px',\n fontSize: theme.fontSizes.sm,\n color: theme.colors.gray[7],\n marginBottom: theme.spacing.xs,\n },\n invalid: {\n color: theme.colors.red[9],\n borderColor: theme.colors.red[6],\n },\n error: {\n color: theme.colors.red[9],\n },\n }),\n },\n TextInput: {\n defaultProps: {\n radius: 8,\n },\n },\n Tooltip: {\n defaultProps: {\n color: 'navy',\n withArrow: true,\n withinPortal: true,\n },\n },\n Breadcrumbs: {\n defaultProps: {\n separator: <ArrowHeadRightSize24Px height={24} />,\n },\n },\n Loader: {\n defaultProps: {\n variant: 'dots',\n color: 'action',\n },\n },\n DateRangePicker: {\n styles: {\n cell: {\n textAlign: 'center',\n },\n },\n },\n Anchor: {\n defaultProps: {\n color: 'action',\n },\n styles: (theme) => ({\n root: {\n ...theme.fn.hover({\n textDecoration: 'underline',\n color: theme.colors.action[8],\n }),\n },\n }),\n },\n Checkbox: {\n defaultProps: {\n radius: 'sm',\n },\n },\n List: {\n styles: () => ({\n root: {\n listStyleType: 'disc',\n },\n }),\n },\n Radio: {\n styles: {\n labelWrapper: {\n display: 'flex',\n alignItems: 'flex-start',\n },\n },\n },\n Popover: {\n defaultProps: {\n shadow: 'md',\n withArrow: true,\n },\n },\n Badge: {\n styles: {\n root: {\n textTransform: 'none',\n padding: '4px 8px',\n fontWeight: 500,\n },\n },\n },\n },\n};\n"],"names":["ArrowHeadRightSize24Px","InfoSize24Px","color","PlasmaColors","plasmaTheme","colorScheme","fontFamily","black","primary","gray","defaultRadius","spacing","xs","sm","md","lg","xl","primaryColor","headings","fontWeight","sizes","h1","fontSize","lineHeight","undefined","h2","h3","h4","h5","h6","shadows","colors","components","Alert","defaultProps","icon","height","styles","title","Title","theme","root","letterSpacing","Button","params","backgroundColor","variant","Modal","size","fullScreen","modal","width","fn","overlayColor","navy","overlayOpacity","InputWrapper","withAsterisk","label","marginBottom","description","fontSizes","invalid","red","borderColor","error","TextInput","radius","Tooltip","withArrow","withinPortal","Breadcrumbs","separator","Loader","DateRangePicker","cell","textAlign","Anchor","hover","textDecoration","action","Checkbox","List","listStyleType","Radio","labelWrapper","display","alignItems","Popover","shadow","Badge","textTransform","padding"],"mappings":"AAAA;;AAAA,SAAQA,sBAAsB,EAAEC,YAAY,QAAO,8BAA8B;AACjF,SAAQC,KAAK,QAAO,yBAAyB;AAG7C,SAAQC,YAAY,QAAO,iBAAiB;AAE5C,OAAO,IAAMC,cAAoC;IAC7C,2HAA2H;IAC3HC,aAAa;IACbC,YAAY;IACZC,OAAOL,MAAMM,OAAO,CAACC,IAAI,CAAC,EAAE;IAC5BC,eAAe;IACfC,SAAS;QACLC,IAAI;QACJC,IAAI;QACJC,IAAI;QACJC,IAAI;QACJC,IAAI;IACR;IACAC,cAAc;IACdC,UAAU;QACNZ,YAAY;QACZa,YAAY;QACZC,OAAO;YACHC,IAAI;gBAACC,UAAU;gBAAIC,YAAY;gBAAQJ,YAAYK;YAAS;YAC5DC,IAAI;gBAACH,UAAU;gBAAIC,YAAY;gBAAQJ,YAAYK;YAAS;YAC5DE,IAAI;gBAACJ,UAAU;gBAAIC,YAAY;gBAAQJ,YAAYK;YAAS;YAC5DG,IAAI;gBAACL,UAAU;gBAAIC,YAAY;gBAAQJ,YAAYK;YAAS;YAC5DI,IAAI;gBAACN,UAAU;gBAAIC,Y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cAAc;gBACVuD,QAAQ;gBACRpB,WAAW,IAAI;YACnB;QACJ;QACAqB,OAAO;YACHrD,QAAQ;gBACJI,MAAM;oBACFkD,eAAe;oBACfC,SAAS;oBACTzE,YAAY;gBAChB;YACJ;QACJ;IACJ;AACJ,EAAE"}
1
+ {"version":3,"sources":["../../../src/theme/Theme.tsx"],"sourcesContent":["import {ArrowHeadRightSize24Px, InfoSize24Px} from '@coveord/plasma-react-icons';\nimport {color} from '@coveord/plasma-tokens';\nimport {ButtonStylesParams, MantineThemeOverride, ModalStylesParams} from '@mantine/core';\n\nimport {PlasmaColors} from './PlasmaColors';\n\nexport const plasmaTheme: MantineThemeOverride = {\n // These are overrides over https://github.com/mantinedev/mantine/blob/master/src/mantine-styles/src/theme/default-theme.ts\n colorScheme: 'light',\n fontFamily: 'canada-type-gibson, sans-serif',\n black: color.primary.gray[9],\n defaultRadius: 8,\n spacing: {\n xs: 8,\n sm: 16,\n md: 24,\n lg: 32,\n xl: 40,\n },\n primaryColor: 'action',\n headings: {\n fontFamily: 'canada-type-gibson, sans-serif',\n fontWeight: 500,\n sizes: {\n h1: {fontSize: 48, lineHeight: '56px', fontWeight: undefined},\n h2: {fontSize: 32, lineHeight: '40px', fontWeight: undefined},\n h3: {fontSize: 28, lineHeight: '40px', fontWeight: undefined},\n h4: {fontSize: 24, lineHeight: '32px', fontWeight: undefined},\n h5: {fontSize: 18, lineHeight: '28px', fontWeight: undefined},\n h6: {fontSize: 16, lineHeight: '24px', fontWeight: undefined},\n },\n },\n shadows: {\n xs: '0px 1px 0px rgba(4, 8, 31, 0.08)',\n sm: '0px 2px 4px rgba(4, 8, 31, 0.12)',\n md: '0px 4px 8px rgba(4, 8, 31, 0.08)',\n lg: '0px 8px 16px rgba(7, 12, 41, 0.06)',\n xl: '0px 16px 24px rgba(4, 8, 31, 0.06)',\n },\n colors: PlasmaColors,\n components: {\n Alert: {\n defaultProps: {\n icon: <InfoSize24Px height={24} />,\n color: 'navy',\n },\n styles: {\n title: {\n fontWeight: 500,\n },\n },\n },\n Title: {\n styles: (theme) => ({\n root: {\n '&:is(h1,h2,h3,h4,h5,h6)': {letterSpacing: '0.011em', color: theme.colors.gray[9]},\n },\n }),\n },\n Button: {\n styles: (theme, params: ButtonStylesParams) => ({\n root: {\n fontWeight: 400,\n backgroundColor: params.variant === 'outline' ? 'white' : undefined,\n },\n }),\n },\n Modal: {\n styles: (theme, {size, fullScreen}: ModalStylesParams) => ({\n modal: {\n width: fullScreen\n ? undefined\n : theme.fn.size({size, sizes: {xs: 440, sm: 550, md: 800, lg: 1334, xl: '85%'}}),\n },\n }),\n defaultProps: {\n overlayColor: color.primary.navy[9],\n overlayOpacity: 0.9,\n },\n },\n InputWrapper: {\n defaultProps: {\n withAsterisk: false,\n },\n styles: (theme) => ({\n label: {\n marginBottom: theme.spacing.xs,\n lineHeight: '20px',\n },\n description: {\n lineHeight: '20px',\n fontSize: theme.fontSizes.sm,\n color: theme.colors.gray[7],\n marginBottom: theme.spacing.xs,\n },\n invalid: {\n color: theme.colors.red[9],\n borderColor: theme.colors.red[6],\n },\n error: {\n color: theme.colors.red[9],\n },\n }),\n },\n TextInput: {\n defaultProps: {\n radius: 8,\n },\n },\n Tooltip: {\n defaultProps: {\n color: 'navy',\n withArrow: true,\n withinPortal: true,\n },\n },\n Breadcrumbs: {\n defaultProps: {\n separator: <ArrowHeadRightSize24Px height={24} />,\n },\n },\n Loader: {\n defaultProps: {\n variant: 'dots',\n color: 'action',\n },\n },\n DateRangePicker: {\n styles: {\n cell: {\n textAlign: 'center',\n },\n },\n },\n Anchor: {\n defaultProps: {\n color: 'action',\n },\n styles: (theme) => ({\n root: {\n ...theme.fn.hover({\n textDecoration: 'underline',\n color: theme.colors.action[8],\n }),\n },\n }),\n },\n Checkbox: {\n defaultProps: {\n radius: 'sm',\n },\n },\n List: {\n styles: () => ({\n root: {\n listStyleType: 'disc',\n },\n }),\n },\n Radio: {\n styles: {\n labelWrapper: {\n display: 'flex',\n alignItems: 'flex-start',\n },\n },\n },\n Popover: {\n defaultProps: {\n shadow: 'md',\n withArrow: true,\n },\n },\n Badge: {\n styles: {\n root: {\n textTransform: 'none',\n padding: '4px 8px',\n fontWeight: 500,\n },\n },\n },\n ColorSwatch: {\n defaultProps: {\n size: 8,\n },\n },\n },\n};\n"],"names":["ArrowHeadRightSize24Px","InfoSize24Px","color","PlasmaColors","plasmaTheme","colorScheme","fontFamily","black","primary","gray","defaultRadius","spacing","xs","sm","md","lg","xl","primaryColor","headings","fontWeight","sizes","h1","fontSize","lineHeight","undefined","h2","h3","h4","h5","h6","shadows","colors","components","Alert","defaultProps","icon","height","styles","title","Title","theme","root","letterSpacing","Button","params","backgroundColor","variant","Modal","size","fullScreen","modal","width","fn","overlayColor","navy","overlayOpacity","InputWrapper","withAsterisk","label","marginBottom","description","fontSizes","invalid","red","borderColor","error","TextInput","radius","Tooltip","withArrow","withinPortal","Breadcrumbs","separator","Loader","DateRangePicker","cell","textAlign","Anchor","hover","textDecoration","action","Checkbox","List","listStyleType","Radio","labelWrapper","display","alignItems","Popover","shadow","Badge","textTransform","padding","ColorSwatch"],"mappings":"AAAA;;AAAA,SAAQA,sBAAsB,EAAEC,YAAY,QAAO,8BAA8B;AACjF,SAAQC,KAAK,QAAO,yBAAyB;AAG7C,SAAQC,YAAY,QAAO,iBAAiB;AAE5C,OAAO,IAAMC,cAAoC;IAC7C,2HAA2H;IAC3HC,aAAa;IACbC,YAAY;IACZC,OAAOL,MAAMM,OAAO,CAACC,IAAI,CAAC,EAAE;IAC5BC,eAAe;IACfC,SAAS;QACLC,IAAI;QACJC,IAAI;QACJC,IAAI;QACJC,IAAI;QACJC,IAAI;IACR;IACAC,cAAc;IACdC,UAAU;QACNZ,YAAY;QACZa,YAAY;QACZC,OAAO;YACHC,IAAI;gBAACC,UAAU;gBAAIC,YAAY;gBAAQJ,YAAYK;YAAS;YAC5DC,IAAI;gBAACH,UAAU;gBAAIC,YAAY;gBAAQJ,YAAYK;YAAS;YAC5DE,I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AO;oBACXI,MAAM;wBACF0C,eAAe;oBACnB;gBACJ;;QACJ;QACAC,OAAO;YACH/C,QAAQ;gBACJgD,cAAc;oBACVC,SAAS;oBACTC,YAAY;gBAChB;YACJ;QACJ;QACAC,SAAS;YACLtD,cAAc;gBACVuD,QAAQ;gBACRpB,WAAW,IAAI;YACnB;QACJ;QACAqB,OAAO;YACHrD,QAAQ;gBACJI,MAAM;oBACFkD,eAAe;oBACfC,SAAS;oBACTzE,YAAY;gBAChB;YACJ;QACJ;QACA0E,aAAa;YACT3D,cAAc;gBACVc,MAAM;YACV;QACJ;IACJ;AACJ,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coveord/plasma-mantine",
3
- "version": "48.28.3",
3
+ "version": "49.0.2",
4
4
  "description": "A Plasma flavoured Mantine theme",
5
5
  "keywords": [
6
6
  "plasma",
@@ -77,6 +77,7 @@
77
77
  "clean": "rimraf dist",
78
78
  "start": "node ../../scripts/start",
79
79
  "test": "jest --maxWorkers=65%",
80
- "test:watch": "jest --watchAll"
80
+ "test:watch": "jest --watchAll",
81
+ "test:debug": "node --inspect-brk node_modules/jest/bin/jest --runInBand --watchAll --detectOpenHandles --forceExit"
81
82
  }
82
83
  }
@@ -12,12 +12,13 @@ import {
12
12
  Tooltip,
13
13
  useComponentDefaultProps,
14
14
  } from '@mantine/core';
15
- import {useId} from '@mantine/hooks';
15
+ import {ReorderPayload} from '@mantine/form/lib/types';
16
+ import {useDidUpdate, useId} from '@mantine/hooks';
16
17
  import {ReactNode} from 'react';
17
18
  import {DragDropContext, Droppable} from 'react-beautiful-dnd';
18
- import {useControlledList} from '../../hooks';
19
- import {CollectionItem} from './CollectionItem';
19
+
20
20
  import useStyles from './Collection.styles';
21
+ import {CollectionItem} from './CollectionItem';
21
22
 
22
23
  interface CollectionProps<T>
23
24
  extends Omit<InputWrapperBaseProps, 'inputContainer' | 'inputWrapperOrder'>,
@@ -39,10 +40,6 @@ interface CollectionProps<T>
39
40
  * @default []
40
41
  */
41
42
  value?: T[];
42
- /**
43
- * The initial items of the collection (for uncontrolled usage only)
44
- */
45
- defaultValue?: T[];
46
43
  /**
47
44
  * Unused, has no effect
48
45
  */
@@ -59,6 +56,19 @@ interface CollectionProps<T>
59
56
  * @param itemIndex The index of the item that was removed
60
57
  */
61
58
  onRemoveItem?: (itemIndex: number) => void;
59
+ /**
60
+ * Function that gets called whenever a collection item needs to be reordered
61
+ *
62
+ * @param payload The origin and destination index of the item to reorder
63
+ */
64
+ onReorderItem?: (payload: ReorderPayload) => void;
65
+ /**
66
+ * Function that gets called when a new item needs to be added to the collection
67
+ *
68
+ * @param value The the value of the item to insert
69
+ * @param index The index of the new item to insert
70
+ */
71
+ onInsertItem?: (value: T, index: number) => void;
62
72
  /**
63
73
  * Whether the collection should have drag and drop behavior enabled
64
74
  *
@@ -116,9 +126,10 @@ const defaultProps: Partial<CollectionProps<unknown>> = {
116
126
  export const Collection = <T,>(props: CollectionProps<T>) => {
117
127
  const {
118
128
  value,
119
- defaultValue,
120
129
  onChange,
121
130
  onRemoveItem,
131
+ onReorderItem,
132
+ onInsertItem,
122
133
  disabled,
123
134
  draggable,
124
135
  children,
@@ -146,12 +157,14 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
146
157
  const {classes, cx} = useStyles(null, {classNames, name: 'Collection', styles, unstyled});
147
158
  const collectionID = useId('dnd-droppable');
148
159
 
149
- const [values, {append, remove, reorder}] = useControlledList({value, onChange, defaultValue});
150
- const hasOnlyOneItem = values.length === 1;
151
- const removeItem = (index: number) => () => {
152
- remove(index);
153
- onRemoveItem?.(index);
154
- };
160
+ const hasOnlyOneItem = value.length === 1;
161
+
162
+ /**
163
+ * Enforcing onChange when the value is modified will make sure the errors are carried through.
164
+ */
165
+ useDidUpdate(() => {
166
+ onChange?.(value);
167
+ }, [JSON.stringify(value)]);
155
168
 
156
169
  const _label = label ? (
157
170
  <Input.Label required={required} {...labelProps}>
@@ -171,13 +184,13 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
171
184
  </Box>
172
185
  ) : null;
173
186
 
174
- const items = values.map((item, index) => (
187
+ const items = value.map((item, index) => (
175
188
  <CollectionItem
176
189
  key={index}
177
190
  disabled={disabled}
178
191
  draggable={draggable}
179
192
  index={index}
180
- onRemove={removeItem(index)}
193
+ onRemove={() => onRemoveItem?.(index)}
181
194
  styles={styles}
182
195
  removable={!(required && hasOnlyOneItem)}
183
196
  >
@@ -185,7 +198,7 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
185
198
  </CollectionItem>
186
199
  ));
187
200
 
188
- const addAllowed = allowAdd?.(values) ?? true;
201
+ const addAllowed = allowAdd?.(value) ?? true;
189
202
 
190
203
  const _addButton = disabled ? null : (
191
204
  <Group>
@@ -194,7 +207,7 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
194
207
  <Button
195
208
  variant="subtle"
196
209
  leftIcon={<AddSize16Px height={16} />}
197
- onClick={() => append(newItem)}
210
+ onClick={() => onInsertItem(newItem, value?.length ?? 0)}
198
211
  disabled={!addAllowed}
199
212
  >
200
213
  {addLabel}
@@ -206,7 +219,7 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
206
219
 
207
220
  return (
208
221
  <DragDropContext
209
- onDragEnd={({destination, source}) => reorder({from: source.index, to: destination?.index || 0})}
222
+ onDragEnd={({destination, source}) => onReorderItem({from: source.index, to: destination?.index || 0})}
210
223
  >
211
224
  <Droppable direction="vertical" droppableId={collectionID}>
212
225
  {(provided) => (
@@ -1,7 +1,7 @@
1
- import {useForm} from '@mantine/form';
2
1
  import {render, screen, userEvent, within} from '@test-utils';
3
2
  import {useState} from 'react';
4
3
 
4
+ import {useForm} from '../../../form';
5
5
  import {Collection} from '../Collection';
6
6
 
7
7
  describe('Collection', () => {
@@ -0,0 +1,38 @@
1
+ /* eslint-disable prefer-arrow/prefer-arrow-functions */
2
+ import {_TransformValues, UseForm, UseFormReturnType} from '@mantine/form/lib/types';
3
+ import React, {createContext, useContext} from 'react';
4
+
5
+ import {useForm} from './useForm';
6
+
7
+ export interface FormProviderProps<Form> {
8
+ form: Form;
9
+ children: React.ReactNode;
10
+ }
11
+
12
+ export function createFormContext<
13
+ Values,
14
+ TransformValues extends _TransformValues<Values> = (values: Values) => Values
15
+ >() {
16
+ type Form = UseFormReturnType<Values, TransformValues>;
17
+
18
+ const FormContext = createContext<Form>(null);
19
+
20
+ function FormProvider({form, children}: FormProviderProps<Form>) {
21
+ return <FormContext.Provider value={form}>{children}</FormContext.Provider>;
22
+ }
23
+
24
+ function useFormContext() {
25
+ const ctx = useContext(FormContext);
26
+ if (!ctx) {
27
+ throw new Error('useFormContext was called outside of FormProvider context');
28
+ }
29
+
30
+ return ctx;
31
+ }
32
+
33
+ return [FormProvider, useFormContext, useForm] as [
34
+ React.FC<FormProviderProps<Form>>,
35
+ () => Form,
36
+ UseForm<Values, TransformValues>
37
+ ];
38
+ }
@@ -0,0 +1,2 @@
1
+ export * from './useForm';
2
+ export * from './FormProvider';
@@ -0,0 +1,26 @@
1
+ import {useForm as useMantineForm} from '@mantine/form';
2
+ import {GetInputProps} from '@mantine/form/lib/types';
3
+
4
+ export const useForm: typeof useMantineForm = (options) => {
5
+ const form = useMantineForm(options);
6
+
7
+ const getInputProps: GetInputProps<Record<string, unknown>> = (
8
+ path,
9
+ {type = 'input', withError = type === 'input', withFocus = true} = {}
10
+ ) => {
11
+ const originalPayload = form.getInputProps(path, {type, withError, withFocus});
12
+ if (Array.isArray(originalPayload.value)) {
13
+ return {
14
+ ...originalPayload,
15
+ onReorderItem: (payload: Record<'from' | 'to', number>) => form.reorderListItem(path, payload),
16
+ onRemoveItem: (index: number) => form.removeListItem(path, index),
17
+ onInsertItem: (valueToInsert: unknown, index: number) =>
18
+ form.insertListItem(path, valueToInsert, index),
19
+ };
20
+ }
21
+
22
+ return originalPayload;
23
+ };
24
+
25
+ return {...form, getInputProps};
26
+ };
package/src/index.ts CHANGED
@@ -4,13 +4,15 @@ import {PlasmaColors} from './theme/PlasmaColors';
4
4
 
5
5
  export * from '@mantine/carousel';
6
6
  export * from '@mantine/core';
7
- export * from '@mantine/form';
8
7
  export type {FormValidateInput} from '@mantine/form/lib/types';
9
8
  export * from '@mantine/hooks';
10
9
  export {createColumnHelper, type ColumnDef} from '@tanstack/table-core';
11
10
  export * from './components';
11
+ export * from '@mantine/form';
12
12
  // explicitly overriding mantine components
13
13
  export {Header, Table, type HeaderProps, Modal} from './components';
14
+ export {useForm, createFormContext} from './form';
15
+
14
16
  export * from './theme';
15
17
 
16
18
  declare module '@mantine/core' {
@@ -180,5 +180,10 @@ export const plasmaTheme: MantineThemeOverride = {
180
180
  },
181
181
  },
182
182
  },
183
+ ColorSwatch: {
184
+ defaultProps: {
185
+ size: 8,
186
+ },
187
+ },
183
188
  },
184
189
  };