@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
@@ -12,15 +12,13 @@ var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.
12
12
  var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default;
13
13
  var _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default;
14
14
  var _objectWithoutProperties = require("@swc/helpers/lib/_object_without_properties.js").default;
15
- var _slicedToArray = require("@swc/helpers/lib/_sliced_to_array.js").default;
16
15
  var _jsxRuntime = require("react/jsx-runtime");
17
16
  var _plasmaReactIcons = require("@coveord/plasma-react-icons");
18
17
  var _core = require("@mantine/core");
19
18
  var _hooks = require("@mantine/hooks");
20
19
  var _reactBeautifulDnd = require("react-beautiful-dnd");
21
- var _hooks1 = require("../../hooks");
22
- var _collectionItem = require("./CollectionItem");
23
20
  var _collectionStyles = /*#__PURE__*/ _interopRequireDefault(require("./Collection.styles"));
21
+ var _collectionItem = require("./CollectionItem");
24
22
  var defaultProps = {
25
23
  draggable: false,
26
24
  addLabel: "Add item",
@@ -30,12 +28,13 @@ var defaultProps = {
30
28
  required: false
31
29
  };
32
30
  var Collection = function(props) {
33
- var _useComponentDefaultProps = (0, _core.useComponentDefaultProps)("Collection", defaultProps, props), value = _useComponentDefaultProps.value, defaultValue = _useComponentDefaultProps.defaultValue, onChange = _useComponentDefaultProps.onChange, onRemoveItem = _useComponentDefaultProps.onRemoveItem, disabled = _useComponentDefaultProps.disabled, draggable = _useComponentDefaultProps.draggable, children = _useComponentDefaultProps.children, spacing = _useComponentDefaultProps.spacing, required = _useComponentDefaultProps.required, newItem = _useComponentDefaultProps.newItem, addLabel = _useComponentDefaultProps.addLabel, addDisabledTooltip = _useComponentDefaultProps.addDisabledTooltip, allowAdd = _useComponentDefaultProps.allowAdd, label = _useComponentDefaultProps.label, labelProps = _useComponentDefaultProps.labelProps, description = _useComponentDefaultProps.description, descriptionProps = _useComponentDefaultProps.descriptionProps, error = _useComponentDefaultProps.error, errorProps = _useComponentDefaultProps.errorProps, // Style props
31
+ var _useComponentDefaultProps = (0, _core.useComponentDefaultProps)("Collection", defaultProps, props), value = _useComponentDefaultProps.value, onChange = _useComponentDefaultProps.onChange, onRemoveItem = _useComponentDefaultProps.onRemoveItem, onReorderItem = _useComponentDefaultProps.onReorderItem, onInsertItem = _useComponentDefaultProps.onInsertItem, disabled = _useComponentDefaultProps.disabled, draggable = _useComponentDefaultProps.draggable, children = _useComponentDefaultProps.children, spacing = _useComponentDefaultProps.spacing, required = _useComponentDefaultProps.required, newItem = _useComponentDefaultProps.newItem, addLabel = _useComponentDefaultProps.addLabel, addDisabledTooltip = _useComponentDefaultProps.addDisabledTooltip, allowAdd = _useComponentDefaultProps.allowAdd, label = _useComponentDefaultProps.label, labelProps = _useComponentDefaultProps.labelProps, description = _useComponentDefaultProps.description, descriptionProps = _useComponentDefaultProps.descriptionProps, error = _useComponentDefaultProps.error, errorProps = _useComponentDefaultProps.errorProps, // Style props
34
32
  classNames = _useComponentDefaultProps.classNames, className = _useComponentDefaultProps.className, styles = _useComponentDefaultProps.styles, unstyled = _useComponentDefaultProps.unstyled, others = _objectWithoutProperties(_useComponentDefaultProps, [
35
33
  "value",
36
- "defaultValue",
37
34
  "onChange",
38
35
  "onRemoveItem",
36
+ "onReorderItem",
37
+ "onInsertItem",
39
38
  "disabled",
40
39
  "draggable",
41
40
  "children",
@@ -63,18 +62,14 @@ var Collection = function(props) {
63
62
  unstyled: unstyled
64
63
  }), classes = _useStyles.classes, cx = _useStyles.cx;
65
64
  var collectionID = (0, _hooks.useId)("dnd-droppable");
66
- var _useControlledList = _slicedToArray((0, _hooks1.useControlledList)({
67
- value: value,
68
- onChange: onChange,
69
- defaultValue: defaultValue
70
- }), 2), values = _useControlledList[0], _useControlledList_ = _useControlledList[1], append = _useControlledList_.append, remove = _useControlledList_.remove, reorder = _useControlledList_.reorder;
71
- var hasOnlyOneItem = values.length === 1;
72
- var removeItem = function(index) {
73
- return function() {
74
- remove(index);
75
- onRemoveItem === null || onRemoveItem === void 0 ? void 0 : onRemoveItem(index);
76
- };
77
- };
65
+ var hasOnlyOneItem = value.length === 1;
66
+ /**
67
+ * Enforcing onChange when the value is modified will make sure the errors are carried through.
68
+ */ (0, _hooks.useDidUpdate)(function() {
69
+ onChange === null || onChange === void 0 ? void 0 : onChange(value);
70
+ }, [
71
+ JSON.stringify(value)
72
+ ]);
78
73
  var _label = label ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_core.Input.Label, _objectSpreadProps(_objectSpread({
79
74
  required: required
80
75
  }, labelProps), {
@@ -93,19 +88,22 @@ var Collection = function(props) {
93
88
  _description
94
89
  ]
95
90
  }) : null;
96
- var items = values.map(function(item, index) {
97
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_collectionItem.CollectionItem, {
91
+ var items = value.map(function(item, index) {
92
+ /*#__PURE__*/ return (0, _jsxRuntime.jsx)(_collectionItem.CollectionItem, {
98
93
  disabled: disabled,
99
94
  draggable: draggable,
100
95
  index: index,
101
- onRemove: removeItem(index),
96
+ onRemove: function() {
97
+ return onRemoveItem === null || onRemoveItem === void 0 ? void 0 : onRemoveItem(index);
98
+ },
102
99
  styles: styles,
103
100
  removable: !(required && hasOnlyOneItem),
104
101
  children: children(item, index)
105
102
  }, index);
106
103
  });
107
104
  var _allowAdd;
108
- var addAllowed = (_allowAdd = allowAdd === null || allowAdd === void 0 ? void 0 : allowAdd(values)) !== null && _allowAdd !== void 0 ? _allowAdd : true;
105
+ var addAllowed = (_allowAdd = allowAdd === null || allowAdd === void 0 ? void 0 : allowAdd(value)) !== null && _allowAdd !== void 0 ? _allowAdd : true;
106
+ var _value_length;
109
107
  var _addButton = disabled ? null : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_core.Group, {
110
108
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_core.Tooltip, {
111
109
  label: addDisabledTooltip,
@@ -117,7 +115,7 @@ var Collection = function(props) {
117
115
  height: 16
118
116
  }),
119
117
  onClick: function() {
120
- return append(newItem);
118
+ return onInsertItem(newItem, (_value_length = value === null || value === void 0 ? void 0 : value.length) !== null && _value_length !== void 0 ? _value_length : 0);
121
119
  },
122
120
  disabled: !addAllowed,
123
121
  children: addLabel
@@ -128,7 +126,7 @@ var Collection = function(props) {
128
126
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactBeautifulDnd.DragDropContext, {
129
127
  onDragEnd: function(param) {
130
128
  var destination = param.destination, source = param.source;
131
- return reorder({
129
+ return onReorderItem({
132
130
  from: source.index,
133
131
  to: (destination === null || destination === void 0 ? void 0 : destination.index) || 0
134
132
  });
@@ -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":["Collection","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","spacing","required","props","useComponentDefaultProps","value","defaultValue","onChange","onRemoveItem","children","newItem","allowAdd","label","labelProps","description","descriptionProps","error","errorProps","classNames","className","styles","unstyled","others","useStyles","name","classes","cx","collectionID","useId","useControlledList","values","append","remove","reorder","hasOnlyOneItem","length","removeItem","index","_label","Input","Label","_description","Description","_error","Error","_header","Box","mb","items","map","item","CollectionItem","onRemove","removable","addAllowed","_addButton","Group","Tooltip","Button","variant","leftIcon","AddSize16Px","height","onClick","DragDropContext","onDragEnd","destination","source","from","to","Droppable","direction","droppableId","provided","droppableProps","ref","innerRef","root","Stack","placeholder"],"mappings":"AAAA;;;;+BAmHaA;;;eAAAA;;;;;;;;;gCAnHa;oBAanB;qBACa;iCAEqB;sBACT;8BACH;qEACP;AAuFtB,IAAMC,eAAkD;IACpDC,WAAW,KAAK;IAChBC,UAAU;IACVC,oBAAoB;IACpBC,UAAU,KAAK;IACfC,SAAS;IACTC,UAAU,KAAK;AACnB;AAEO,IAAMP,aAAa,SAAKQ,OAA8B;IACzD,IA4BIC,4BAAAA,IAAAA,8BAAwB,EAAC,cAAcR,cAAoCO,QA3B3EE,QA2BAD,0BA3BAC,OACAC,eA0BAF,0BA1BAE,cACAC,WAyBAH,0BAzBAG,UACAC,eAwBAJ,0BAxBAI,cACAR,WAuBAI,0BAvBAJ,UACAH,YAsBAO,0BAtBAP,WACAY,WAqBAL,0BArBAK,UACAR,UAoBAG,0BApBAH,SACAC,WAmBAE,0BAnBAF,UACAQ,UAkBAN,0BAlBAM,SACAZ,WAiBAM,0BAjBAN,UACAC,qBAgBAK,0BAhBAL,oBACAY,WAeAP,0BAfAO,UACAC,QAcAR,0BAdAQ,OACAC,aAaAT,0BAbAS,YACAC,cAYAV,0BAZAU,aACAC,mBAWAX,0BAXAW,kBACAC,QAUAZ,0BAVAY,OACAC,aASAb,0BATAa,YAEA,cAAc;IACdC,aAMAd,0BANAc,YACAC,YAKAf,0BALAe,WACAC,SAIAhB,0BAJAgB,QACAC,WAGAjB,0BAHAiB,UAEGC,kCACHlB;QA3BAC;QACAC;QACAC;QACAC;QACAR;QACAH;QACAY;QACAR;QACAC;QACAQ;QACAZ;QACAC;QACAY;QACAC;QACAC;QACAC;QACAC;QACAC;QACA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mB,qBAAXnB,uBAAAA,YAAsB,IAAI;IAE7C,IAAM4C,aAAavD,WAAW,IAAI,iBAC9B,qBAACwD,WAAK;kBACF,cAAA,qBAACC,aAAO;YAAC7C,OAAOb;YAAoBC,UAAUsD;sBAC1C,cAAA,qBAACR,SAAG;0BACA,cAAA,qBAACY,YAAM;oBACHC,SAAQ;oBACRC,wBAAU,qBAACC,6BAAW;wBAACC,QAAQ;;oBAC/BC,SAAS;+BAAMhC,OAAOrB;;oBACtBV,UAAU,CAACsD;8BAEVxD;;;;MAKpB;IAED,qBACI,qBAACkE,kCAAe;QACZC,WAAW;gBAAEC,oBAAAA,aAAaC,eAAAA;YAAYlC,OAAAA,QAAQ;gBAACmC,MAAMD,OAAO9B,KAAK;gBAAEgC,IAAIH,CAAAA,wBAAAA,yBAAAA,KAAAA,IAAAA,YAAa7B,KAAK,AAAD,KAAK;YAAC;;kBAE9F,cAAA,qBAACiC,4BAAS;YAACC,WAAU;YAAWC,aAAa7C;sBACxC,SAAC8C;qCACE,sBAAC3B,SAAG,wEACI2B,SAASC,cAAc;oBAC3BC,KAAKF,SAASG,QAAQ;oBACtBzD,WAAWO,GAAGD,QAAQoD,IAAI,EAAE1D;oBACxBG;;wBAEHuB;sCACD,sBAACiC,WAAK;4BAAC7E,SAASA;;gCACX+C;gCACAyB,SAASM,WAAW;gCACpBxB;gCACAZ;;;;;;;;AAO7B"}
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":["Collection","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","spacing","required","props","useComponentDefaultProps","value","onChange","onRemoveItem","onReorderItem","onInsertItem","children","newItem","allowAdd","label","labelProps","description","descriptionProps","error","errorProps","classNames","className","styles","unstyled","others","useStyles","name","classes","cx","collectionID","useId","hasOnlyOneItem","length","useDidUpdate","JSON","stringify","_label","Input","Label","_description","Description","_error","Error","_header","Box","mb","items","map","item","index","CollectionItem","onRemove","removable","addAllowed","_addButton","Group","Tooltip","Button","variant","leftIcon","AddSize16Px","height","onClick","DragDropContext","onDragEnd","destination","source","from","to","Droppable","direction","droppableId","provided","droppableProps","ref","innerRef","root","Stack","placeholder"],"mappings":"AAAA;;;;+BA6HaA;;;eAAAA;;;;;;;;gCA7Ha;oBAanB;qBAE2B;iCAEO;qEAEnB;8BACO;AAgG7B,IAAMC,eAAkD;IACpDC,WAAW,KAAK;IAChBC,UAAU;IACVC,oBAAoB;IACpBC,UAAU,KAAK;IACfC,SAAS;IACTC,UAAU,KAAK;AACnB;AAEO,IAAMP,aAAa,SAAKQ,OAA8B;IACzD,IA6BIC,4BAAAA,IAAAA,8BAAwB,EAAC,cAAcR,cAAoCO,QA5B3EE,QA4BAD,0BA5BAC,OACAC,WA2BAF,0BA3BAE,UACAC,eA0BAH,0BA1BAG,cACAC,gBAyBAJ,0BAzBAI,eACAC,eAwBAL,0BAxBAK,cACAT,WAuBAI,0BAvBAJ,UACAH,YAsBAO,0BAtBAP,WACAa,WAqBAN,0BArBAM,UACAT,UAoBAG,0BApBAH,SACAC,WAmBAE,0BAnBAF,UACAS,UAkBAP,0BA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CACD,sBAACkC,WAAK;4BAAC3E,SAASA;;gCACX4C;gCACA0B,SAASM,WAAW;gCACpBxB;gCACAb;;;;;;;;AAO7B"}
@@ -0,0 +1,38 @@
1
+ /* eslint-disable prefer-arrow/prefer-arrow-functions */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createFormContext", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createFormContext;
9
+ }
10
+ });
11
+ var _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ var _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
14
+ var _useForm = require("./useForm");
15
+ function createFormContext() {
16
+ var FormProvider = function FormProvider(param) {
17
+ var form = param.form, children = param.children;
18
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(FormContext.Provider, {
19
+ value: form,
20
+ children: children
21
+ });
22
+ };
23
+ var useFormContext = function useFormContext() {
24
+ var ctx = (0, _react.useContext)(FormContext);
25
+ if (!ctx) {
26
+ throw new Error("useFormContext was called outside of FormProvider context");
27
+ }
28
+ return ctx;
29
+ };
30
+ var FormContext = /*#__PURE__*/ (0, _react.createContext)(null);
31
+ return [
32
+ FormProvider,
33
+ useFormContext,
34
+ _useForm.useForm
35
+ ];
36
+ }
37
+
38
+ //# 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":["createFormContext","FormProvider","form","children","FormContext","Provider","value","useFormContext","ctx","useContext","Error","createContext","useForm"],"mappings":"AAAA,sDAAsD,GACtD;;;;+BAUgBA;;;eAAAA;;;;;2DAT+B;uBAEzB;AAOf,SAASA,oBAGZ;QAKSC,eAAT,SAASA,aAAa,KAAyC,EAAE;YAA1CC,OAAD,MAACA,MAAMC,WAAP,MAAOA;QACzB,qBAAO,qBAACC,YAAYC,QAAQ;YAACC,OAAOJ;sBAAOC;;IAC/C;QAESI,iBAAT,SAASA,iBAAiB;QACtB,IAAMC,MAAMC,IAAAA,iBAAU,EAACL;QACvB,IAAI,CAACI,KAAK;YACN,MAAM,IAAIE,MAAM,6DAA6D;QACjF,CAAC;QAED,OAAOF;IACX;IAbA,IAAMJ,4BAAcO,IAAAA,oBAAa,EAAO,IAAI;IAe5C,OAAO;QAACV;QAAcM;QAAgBK,gBAAO;KAAC;AAKlD"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ var _exportStar = require("@swc/helpers/lib/_export_star.js").default;
6
+ _exportStar(require("./useForm"), exports);
7
+ _exportStar(require("./FormProvider"), exports);
8
+
9
+ //# 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;;;;;oBAAc;oBACA"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useForm", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useForm;
9
+ }
10
+ });
11
+ var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default;
12
+ var _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default;
13
+ var _form = require("@mantine/form");
14
+ var useForm = function(options) {
15
+ var form = (0, _form.useForm)(options);
16
+ var getInputProps = function(path) {
17
+ 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;
18
+ var originalPayload = form.getInputProps(path, {
19
+ type: type,
20
+ withError: withError,
21
+ withFocus: withFocus
22
+ });
23
+ if (Array.isArray(originalPayload.value)) {
24
+ return _objectSpreadProps(_objectSpread({}, originalPayload), {
25
+ onReorderItem: function(payload) {
26
+ return form.reorderListItem(path, payload);
27
+ },
28
+ onRemoveItem: function(index) {
29
+ return form.removeListItem(path, index);
30
+ },
31
+ onInsertItem: function(valueToInsert, index) {
32
+ return form.insertListItem(path, valueToInsert, index);
33
+ }
34
+ });
35
+ }
36
+ return originalPayload;
37
+ };
38
+ return _objectSpreadProps(_objectSpread({}, form), {
39
+ getInputProps: getInputProps
40
+ });
41
+ };
42
+
43
+ //# 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","options","form","useMantineForm","getInputProps","path","type","withError","withFocus","originalPayload","Array","isArray","value","onReorderItem","payload","reorderListItem","onRemoveItem","index","removeListItem","onInsertItem","valueToInsert","insertListItem"],"mappings":"AAAA;;;;+BAGaA;;;eAAAA;;;;;oBAH2B;AAGjC,IAAMA,UAAiC,SAACC,SAAY;IACvD,IAAMC,OAAOC,IAAAA,aAAc,EAACF;IAE5B,IAAMG,gBAAwD,SAC1DC,MAEC;oFADkE,CAAC,oBAAnEC,MAAAA,8BAAO,2CAASC,WAAAA,wCAAYD,SAAS,gDAASE,WAAAA,wCAAY,IAAI;QAE/D,IAAMC,kBAAkBP,KAAKE,aAAa,CAACC,MAAM;YAACC,MAAAA;YAAMC,WAAAA;YAAWC,WAAAA;QAAS;QAC5E,IAAIE,MAAMC,OAAO,CAACF,gBAAgBG,KAAK,GAAG;YACtC,OAAO,qCACAH;gBACHI,eAAe,SAACC;2BAA2CZ,KAAKa,eAAe,CAACV,MAAMS;;gBACtFE,cAAc,SAACC;2BAAkBf,KAAKgB,cAAc,CAACb,MAAMY;;gBAC3DE,cAAc,SAACC,eAAwBH;2BACnCf,KAAKmB,cAAc,CAAChB,MAAMe,eAAeH;;;QAErD,CAAC;QAED,OAAOR;IACX;IAEA,OAAO,qCAAIP;QAAME,eAAAA;;AACrB"}
package/dist/cjs/index.js CHANGED
@@ -20,15 +20,22 @@ _export(exports, {
20
20
  },
21
21
  Modal: function() {
22
22
  return _components.Modal;
23
+ },
24
+ useForm: function() {
25
+ return _form.useForm;
26
+ },
27
+ createFormContext: function() {
28
+ return _form.createFormContext;
23
29
  }
24
30
  });
25
31
  var _exportStar = require("@swc/helpers/lib/_export_star.js").default;
26
32
  _exportStar(require("@mantine/carousel"), exports);
27
33
  _exportStar(require("@mantine/core"), exports);
28
- _exportStar(require("@mantine/form"), exports);
29
34
  _exportStar(require("@mantine/hooks"), exports);
30
35
  var _tableCore = require("@tanstack/table-core");
31
36
  var _components = _exportStar(require("./components"), exports);
37
+ _exportStar(require("@mantine/form"), exports);
38
+ var _form = require("./form");
32
39
  _exportStar(require("./theme"), exports);
33
40
 
34
41
  //# 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":"AAAA;;;;;;;;;;;IASQA,kBAAkB;eAAlBA,6BAAkB;;IAGlBC,MAAM;eAANA,kBAAM;;IAAEC,KAAK;eAALA,iBAAK;;IAAoBC,KAAK;eAALA,iBAAK;;;;oBARhC;oBACA;oBACA;oBAEA;yBACmC;sCACnC;oBAGA"}
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":"AAAA;;;;;;;;;;;IAQQA,kBAAkB;eAAlBA,6BAAkB;;IAIlBC,MAAM;eAANA,kBAAM;;IAAEC,KAAK;eAALA,iBAAK;;IAAoBC,KAAK;eAALA,iBAAK;;IACtCC,OAAO;eAAPA,aAAO;;IAAEC,iBAAiB;eAAjBA,uBAAiB;;;;oBATpB;oBACA;oBAEA;yBACmC;sCACnC;oBACA;oBAG2B;oBAE3B"}
@@ -237,6 +237,11 @@ var plasmaTheme = {
237
237
  fontWeight: 500
238
238
  }
239
239
  }
240
+ },
241
+ ColorSwatch: {
242
+ defaultProps: {
243
+ size: 8
244
+ }
240
245
  }
241
246
  }
242
247
  };
@@ -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":["plasmaTheme","colorScheme","fontFamily","black","color","primary","gray","defaultRadius","spacing","xs","sm","md","lg","xl","primaryColor","headings","fontWeight","sizes","h1","fontSize","lineHeight","undefined","h2","h3","h4","h5","h6","shadows","colors","PlasmaColors","components","Alert","defaultProps","icon","InfoSize24Px","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","ArrowHeadRightSize24Px","Loader","DateRangePicker","cell","textAlign","Anchor","hover","textDecoration","action","Checkbox","List","listStyleType","Radio","labelWrapper","display","alignItems","Popover","shadow","Badge","textTransform","padding"],"mappings":"AAAA;;;;+BAMaA;;;eAAAA;;;;;gCANsC;4BA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sC,QAAQ;YACJzC,cAAc;gBACVa,SAAS;gBACTzC,OAAO;YACX;QACJ;QACAsE,iBAAiB;YACbtC,QAAQ;gBACJuC,MAAM;oBACFC,WAAW;gBACf;YACJ;QACJ;QACAC,QAAQ;YACJ7C,cAAc;gBACV5B,OAAO;YACX;YACAgC,QAAQ,SAACG;uBAAW;oBAChBC,MAAM,kBACCD,MAAMY,EAAE,CAAC2B,KAAK,CAAC;wBACdC,gBAAgB;wBAChB3E,OAAOmC,MAAMX,MAAM,CAACoD,MAAM,CAAC,EAAE;oBACjC;gBAER;;QACJ;QACAC,UAAU;YACNjD,cAAc;gBACVkC,QAAQ;YACZ;QACJ;QACAgB,MAAM;YACF9C,QAAQ;uBAAO;oBACXI,MAAM;wBACF2C,eAAe;oBACnB;gBACJ;;QACJ;QACAC,OAAO;YACHhD,QAAQ;gBACJiD,cAAc;oBACVC,SAAS;oBACTC,YAAY;gBAChB;YACJ;QACJ;QACAC,SAAS;YACLxD,cAAc;gBACVyD,QAAQ;gBACRrB,WAAW,IAAI;YACnB;QACJ;QACAsB,OAAO;YACHtD,QAAQ;gBACJI,MAAM;oBACFmD,eAAe;oBACfC,SAAS;oBACT5E,YAAY;gBAChB;YACJ;QACJ;IACJ;AACJ"}
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":["plasmaTheme","colorScheme","fontFamily","black","color","primary","gray","defaultRadius","spacing","xs","sm","md","lg","xl","primaryColor","headings","fontWeight","sizes","h1","fontSize","lineHeight","undefined","h2","h3","h4","h5","h6","shadows","colors","PlasmaColors","components","Alert","defaultProps","icon","InfoSize24Px","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","ArrowHeadRightSize24Px","Loader","DateRangePicker","cell","textAlign","Anchor","hover","textDecoration","action","Checkbox","List","listStyleType","Radio","labelWrapper","display","alignItems","Popover","shadow","Badge","textTransform","padding","ColorSwatch"],"mappings":"AAAA;;;;+BAMaA;;;eAAAA;;;;;gCANsC;4BAC/B;4BAGO;AAEpB,IAAMA,cAAoC;IAC7C,2HAA2H;IAC3HC,aAAa;IACbC,YAAY;IACZC,OAAOC,mBAAK,CAACC,OAAO,CAACC,IAAI,CAAC,EAAE;IAC5BC,eAAe;IACfC,SAAS;QACLC,IAAI;QACJC,IAAI;QACJC,IAAI;QACJC,IAAI;QACJC,IAAI;IACR;IACAC,cAAc;IACdC,UAAU;QACNb,YAAY;QACZc,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,YAAY;gBAAQJ,YAAYK;YAAS;YAC5DK,IAAI;gBAACP,UAAU;gBAAIC,YAAY;gBAAQJ,YAAYK;YAAS;QAChE;IACJ;IACAM,SAAS;QACLlB,IAAI;QACJC,IAAI;QACJC,IAAI;QACJC,IAAI;QACJC,IAAI;IACR;IACAe,QAAQC,0BAAY;IACpBC,YAAY;QACRC,OAAO;YACHC,cAAc;gBACVC,oBAAM,qBAACC,8BAAY;oBAACC,QAAQ;;gBAC5B/B,OAAO;YACX;YACAgC,QAAQ;gBACJC,OAAO;oBACHrB,YAAY;gBAChB;YACJ;QACJ;QACAsB,OAAO;YACHF,QAAQ,SAACG;uBAAW;oBAChBC,MAAM;wBACF,2BAA2B;4BAACC,eAAe;4BAAWrC,OAAOmC,MAAMX,MAAM,CAACtB,IAAI,CAAC,EAAE;wBAAA;oBACrF;gBACJ;;QACJ;QACAoC,QAA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AI;YACtB;QACJ;QACAC,aAAa;YACTtC,cAAc;gBACVuC,yBAAW,qBAACC,wCAAsB;oBAACrC,QAAQ;;YAC/C;QACJ;QACAsC,QAAQ;YACJzC,cAAc;gBACVa,SAAS;gBACTzC,OAAO;YACX;QACJ;QACAsE,iBAAiB;YACbtC,QAAQ;gBACJuC,MAAM;oBACFC,WAAW;gBACf;YACJ;QACJ;QACAC,QAAQ;YACJ7C,cAAc;gBACV5B,OAAO;YACX;YACAgC,QAAQ,SAACG;uBAAW;oBAChBC,MAAM,kBACCD,MAAMY,EAAE,CAAC2B,KAAK,CAAC;wBACdC,gBAAgB;wBAChB3E,OAAOmC,MAAMX,MAAM,CAACoD,MAAM,CAAC,EAAE;oBACjC;gBAER;;QACJ;QACAC,UAAU;YACNjD,cAAc;gBACVkC,QAAQ;YACZ;QACJ;QACAgB,MAAM;YACF9C,QAAQ;uBAAO;oBACXI,MAAM;wBACF2C,eAAe;oBACnB;gBACJ;;QACJ;QACAC,OAAO;YACHhD,QAAQ;gBACJiD,cAAc;oBACVC,SAAS;oBACTC,YAAY;gBAChB;YACJ;QACJ;QACAC,SAAS;YACLxD,cAAc;gBACVyD,QAAQ;gBACRrB,WAAW,IAAI;YACnB;QACJ;QACAsB,OAAO;YACHtD,QAAQ;gBACJI,MAAM;oBACFmD,eAAe;oBACfC,SAAS;oBACT5E,YAAY;gBAChB;YACJ;QACJ;QACA6E,aAAa;YACT7D,cAAc;gBACVe,MAAM;YACV;QACJ;IACJ;AACJ"}
@@ -1,4 +1,5 @@
1
1
  import { DefaultProps, InputWrapperBaseProps, MantineNumberSize, Selectors } from '@mantine/core';
2
+ import { ReorderPayload } from '@mantine/form/lib/types';
2
3
  import { ReactNode } from 'react';
3
4
  import useStyles from './Collection.styles';
4
5
  interface CollectionProps<T> extends Omit<InputWrapperBaseProps, 'inputContainer' | 'inputWrapperOrder'>, DefaultProps<Selectors<typeof useStyles>> {
@@ -19,10 +20,6 @@ interface CollectionProps<T> extends Omit<InputWrapperBaseProps, 'inputContainer
19
20
  * @default []
20
21
  */
21
22
  value?: T[];
22
- /**
23
- * The initial items of the collection (for uncontrolled usage only)
24
- */
25
- defaultValue?: T[];
26
23
  /**
27
24
  * Unused, has no effect
28
25
  */
@@ -39,6 +36,19 @@ interface CollectionProps<T> extends Omit<InputWrapperBaseProps, 'inputContainer
39
36
  * @param itemIndex The index of the item that was removed
40
37
  */
41
38
  onRemoveItem?: (itemIndex: number) => void;
39
+ /**
40
+ * Function that gets called whenever a collection item needs to be reordered
41
+ *
42
+ * @param payload The origin and destination index of the item to reorder
43
+ */
44
+ onReorderItem?: (payload: ReorderPayload) => void;
45
+ /**
46
+ * Function that gets called when a new item needs to be added to the collection
47
+ *
48
+ * @param value The the value of the item to insert
49
+ * @param index The index of the new item to insert
50
+ */
51
+ onInsertItem?: (value: T, index: number) => void;
42
52
  /**
43
53
  * Whether the collection should have drag and drop behavior enabled
44
54
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../../../src/components/collection/Collection.tsx"],"names":[],"mappings":"AACA,OAAO,EAGH,YAAY,EAGZ,qBAAqB,EACrB,iBAAiB,EACjB,SAAS,EAIZ,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAIhC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAE5C,UAAU,eAAe,CAAC,CAAC,CACvB,SAAQ,IAAI,CAAC,qBAAqB,EAAE,gBAAgB,GAAG,mBAAmB,CAAC,EACvE,YAAY,CAAC,SAAS,CAAC,OAAO,SAAS,CAAC,CAAC;IAC7C;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC;IACX;;;;;OAKG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;IAChD;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;IACZ;;OAEG;IACH,YAAY,CAAC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Q,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;IAChD;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;IACZ;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;IAChC;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAClD;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAWD,eAAO,MAAM,UAAU,+CAsHtB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { _TransformValues, UseForm, UseFormReturnType } from '@mantine/form/lib/types';
2
+ import React from 'react';
3
+ export interface FormProviderProps<Form> {
4
+ form: Form;
5
+ children: React.ReactNode;
6
+ }
7
+ export declare function createFormContext<Values, TransformValues extends _TransformValues<Values> = (values: Values) => Values>(): [React.FC<FormProviderProps<UseFormReturnType<Values, TransformValues>>>, () => UseFormReturnType<Values, TransformValues>, UseForm<Values, TransformValues>];
8
+ //# sourceMappingURL=FormProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormProvider.d.ts","sourceRoot":"","sources":["../../../src/form/FormProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAE,OAAO,EAAE,iBAAiB,EAAC,MAAM,yBAAyB,CAAC;AACrF,OAAO,KAAkC,MAAM,OAAO,CAAC;AAIvD,MAAM,WAAW,iBAAiB,CAAC,IAAI;IACnC,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC7B;AAED,wBAAgB,iBAAiB,CAC7B,MAAM,EACN,eAAe,SAAS,gBAAgB,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,mKAwBhF"}
@@ -0,0 +1,3 @@
1
+ export * from './useForm';
2
+ export * from './FormProvider';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/form/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { useForm as useMantineForm } from '@mantine/form';
2
+ export declare const useForm: typeof useMantineForm;
3
+ //# sourceMappingURL=useForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../../src/form/useForm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,eAAe,CAAC;AAGxD,eAAO,MAAM,OAAO,EAAE,OAAO,cAsB5B,CAAC"}
@@ -2,12 +2,13 @@ import { Tuple } from '@mantine/core';
2
2
  import { PlasmaColors } from './theme/PlasmaColors';
3
3
  export * from '@mantine/carousel';
4
4
  export * from '@mantine/core';
5
- export * from '@mantine/form';
6
5
  export type { FormValidateInput } from '@mantine/form/lib/types';
7
6
  export * from '@mantine/hooks';
8
7
  export { createColumnHelper, type ColumnDef } from '@tanstack/table-core';
9
8
  export * from './components';
9
+ export * from '@mantine/form';
10
10
  export { Header, Table, type HeaderProps, Modal } from './components';
11
+ export { useForm, createFormContext } from './form';
11
12
  export * from './theme';
12
13
  declare module '@mantine/core' {
13
14
  interface MantineThemeColorsOverride {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAElD,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,YAAY,EAAC,iBAAiB,EAAC,MAAM,yBAAyB,CAAC;AAC/D,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAC,kBAAkB,EAAE,KAAK,SAAS,EAAC,MAAM,sBAAsB,CAAC;AACxE,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,WAAW,EAAE,KAAK,EAAC,MAAM,cAAc,CAAC;AACpE,cAAc,SAAS,CAAC;AAExB,OAAO,QAAQ,eAAe,CAAC;IAC3B,UAAiB,0BAA0B;QAEvC,MAAM,EAAE,MAAM,CAAC,MAAM,OAAO,YAAY,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;KAChF;CACJ"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAElD,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,YAAY,EAAC,iBAAiB,EAAC,MAAM,yBAAyB,CAAC;AAC/D,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAC,kBAAkB,EAAE,KAAK,SAAS,EAAC,MAAM,sBAAsB,CAAC;AACxE,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAE9B,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,WAAW,EAAE,KAAK,EAAC,MAAM,cAAc,CAAC;AACpE,OAAO,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,QAAQ,CAAC;AAElD,cAAc,SAAS,CAAC;AAExB,OAAO,QAAQ,eAAe,CAAC;IAC3B,UAAiB,0BAA0B;QAEvC,MAAM,EAAE,MAAM,CAAC,MAAM,OAAO,YAAY,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;KAChF;CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"Theme.d.ts","sourceRoot":"","sources":["../../../src/theme/Theme.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAqB,oBAAoB,EAAoB,MAAM,eAAe,CAAC;AAI1F,eAAO,MAAM,WAAW,EAAE,oBAiLzB,CAAC"}
1
+ {"version":3,"file":"Theme.d.ts","sourceRoot":"","sources":["../../../src/theme/Theme.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAqB,oBAAoB,EAAoB,MAAM,eAAe,CAAC;AAI1F,eAAO,MAAM,WAAW,EAAE,oBAsLzB,CAAC"}
@@ -1,15 +1,13 @@
1
1
  import _object_spread from "@swc/helpers/src/_object_spread.mjs";
2
2
  import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
3
3
  import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs";
4
- import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs";
5
4
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
5
  import { AddSize16Px } from "@coveord/plasma-react-icons";
7
6
  import { Box, Button, Group, Input, Stack, Tooltip, useComponentDefaultProps } from "@mantine/core";
8
- import { useId } from "@mantine/hooks";
7
+ import { useDidUpdate, useId } from "@mantine/hooks";
9
8
  import { DragDropContext, Droppable } from "react-beautiful-dnd";
10
- import { useControlledList } from "../../hooks";
11
- import { CollectionItem } from "./CollectionItem";
12
9
  import useStyles from "./Collection.styles";
10
+ import { CollectionItem } from "./CollectionItem";
13
11
  var defaultProps = {
14
12
  draggable: false,
15
13
  addLabel: "Add item",
@@ -19,12 +17,13 @@ var defaultProps = {
19
17
  required: false
20
18
  };
21
19
  export var Collection = function(props) {
22
- var _useComponentDefaultProps = useComponentDefaultProps("Collection", defaultProps, props), value = _useComponentDefaultProps.value, defaultValue = _useComponentDefaultProps.defaultValue, onChange = _useComponentDefaultProps.onChange, onRemoveItem = _useComponentDefaultProps.onRemoveItem, disabled = _useComponentDefaultProps.disabled, draggable = _useComponentDefaultProps.draggable, children = _useComponentDefaultProps.children, spacing = _useComponentDefaultProps.spacing, required = _useComponentDefaultProps.required, newItem = _useComponentDefaultProps.newItem, addLabel = _useComponentDefaultProps.addLabel, addDisabledTooltip = _useComponentDefaultProps.addDisabledTooltip, allowAdd = _useComponentDefaultProps.allowAdd, label = _useComponentDefaultProps.label, labelProps = _useComponentDefaultProps.labelProps, description = _useComponentDefaultProps.description, descriptionProps = _useComponentDefaultProps.descriptionProps, error = _useComponentDefaultProps.error, errorProps = _useComponentDefaultProps.errorProps, // Style props
20
+ var _useComponentDefaultProps = useComponentDefaultProps("Collection", defaultProps, props), value = _useComponentDefaultProps.value, onChange = _useComponentDefaultProps.onChange, onRemoveItem = _useComponentDefaultProps.onRemoveItem, onReorderItem = _useComponentDefaultProps.onReorderItem, onInsertItem = _useComponentDefaultProps.onInsertItem, disabled = _useComponentDefaultProps.disabled, draggable = _useComponentDefaultProps.draggable, children = _useComponentDefaultProps.children, spacing = _useComponentDefaultProps.spacing, required = _useComponentDefaultProps.required, newItem = _useComponentDefaultProps.newItem, addLabel = _useComponentDefaultProps.addLabel, addDisabledTooltip = _useComponentDefaultProps.addDisabledTooltip, allowAdd = _useComponentDefaultProps.allowAdd, label = _useComponentDefaultProps.label, labelProps = _useComponentDefaultProps.labelProps, description = _useComponentDefaultProps.description, descriptionProps = _useComponentDefaultProps.descriptionProps, error = _useComponentDefaultProps.error, errorProps = _useComponentDefaultProps.errorProps, // Style props
23
21
  classNames = _useComponentDefaultProps.classNames, className = _useComponentDefaultProps.className, styles = _useComponentDefaultProps.styles, unstyled = _useComponentDefaultProps.unstyled, others = _object_without_properties(_useComponentDefaultProps, [
24
22
  "value",
25
- "defaultValue",
26
23
  "onChange",
27
24
  "onRemoveItem",
25
+ "onReorderItem",
26
+ "onInsertItem",
28
27
  "disabled",
29
28
  "draggable",
30
29
  "children",
@@ -52,18 +51,14 @@ export var Collection = function(props) {
52
51
  unstyled: unstyled
53
52
  }), classes = _useStyles.classes, cx = _useStyles.cx;
54
53
  var collectionID = useId("dnd-droppable");
55
- var _useControlledList = _sliced_to_array(useControlledList({
56
- value: value,
57
- onChange: onChange,
58
- defaultValue: defaultValue
59
- }), 2), values = _useControlledList[0], _useControlledList_ = _useControlledList[1], append = _useControlledList_.append, remove = _useControlledList_.remove, reorder = _useControlledList_.reorder;
60
- var hasOnlyOneItem = values.length === 1;
61
- var removeItem = function(index) {
62
- return function() {
63
- remove(index);
64
- onRemoveItem === null || onRemoveItem === void 0 ? void 0 : onRemoveItem(index);
65
- };
66
- };
54
+ var hasOnlyOneItem = value.length === 1;
55
+ /**
56
+ * Enforcing onChange when the value is modified will make sure the errors are carried through.
57
+ */ useDidUpdate(function() {
58
+ onChange === null || onChange === void 0 ? void 0 : onChange(value);
59
+ }, [
60
+ JSON.stringify(value)
61
+ ]);
67
62
  var _label = label ? /*#__PURE__*/ _jsx(Input.Label, _object_spread_props(_object_spread({
68
63
  required: required
69
64
  }, labelProps), {
@@ -82,19 +77,22 @@ export var Collection = function(props) {
82
77
  _description
83
78
  ]
84
79
  }) : null;
85
- var items = values.map(function(item, index) {
86
- return /*#__PURE__*/ _jsx(CollectionItem, {
80
+ var items = value.map(function(item, index) {
81
+ /*#__PURE__*/ return _jsx(CollectionItem, {
87
82
  disabled: disabled,
88
83
  draggable: draggable,
89
84
  index: index,
90
- onRemove: removeItem(index),
85
+ onRemove: function() {
86
+ return onRemoveItem === null || onRemoveItem === void 0 ? void 0 : onRemoveItem(index);
87
+ },
91
88
  styles: styles,
92
89
  removable: !(required && hasOnlyOneItem),
93
90
  children: children(item, index)
94
91
  }, index);
95
92
  });
96
93
  var _allowAdd;
97
- var addAllowed = (_allowAdd = allowAdd === null || allowAdd === void 0 ? void 0 : allowAdd(values)) !== null && _allowAdd !== void 0 ? _allowAdd : true;
94
+ var addAllowed = (_allowAdd = allowAdd === null || allowAdd === void 0 ? void 0 : allowAdd(value)) !== null && _allowAdd !== void 0 ? _allowAdd : true;
95
+ var _value_length;
98
96
  var _addButton = disabled ? null : /*#__PURE__*/ _jsx(Group, {
99
97
  children: /*#__PURE__*/ _jsx(Tooltip, {
100
98
  label: addDisabledTooltip,
@@ -106,7 +104,7 @@ export var Collection = function(props) {
106
104
  height: 16
107
105
  }),
108
106
  onClick: function() {
109
- return append(newItem);
107
+ return onInsertItem(newItem, (_value_length = value === null || value === void 0 ? void 0 : value.length) !== null && _value_length !== void 0 ? _value_length : 0);
110
108
  },
111
109
  disabled: !addAllowed,
112
110
  children: addLabel
@@ -117,7 +115,7 @@ export var Collection = function(props) {
117
115
  return /*#__PURE__*/ _jsx(DragDropContext, {
118
116
  onDragEnd: function(param) {
119
117
  var destination = param.destination, source = param.source;
120
- return reorder({
118
+ return onReorderItem({
121
119
  from: source.index,
122
120
  to: (destination === null || destination === void 0 ? void 0 : destination.index) || 0
123
121
  });