@coveord/plasma-mantine 49.5.3 → 49.6.0

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.
@@ -8,25 +8,96 @@ Object.defineProperty(exports, "Button", {
8
8
  return Button;
9
9
  }
10
10
  });
11
+ var _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default;
12
+ var _instanceof = require("@swc/helpers/lib/_instanceof.js").default;
11
13
  var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default;
12
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
+ var _tsGenerator = require("@swc/helpers/lib/_ts_generator.js").default;
13
17
  var _jsxRuntime = require("react/jsx-runtime");
14
18
  var _core = require("@mantine/core");
15
19
  var _react = require("react");
16
20
  var _utils = require("../../utils");
17
21
  var _buttonWithDisabledTooltip = require("./ButtonWithDisabledTooltip");
18
- var _Button = /*#__PURE__*/ (0, _react.forwardRef)(function(_param, ref) /*#__PURE__*/ {
19
- var disabledTooltip = _param.disabledTooltip, disabled = _param.disabled, disabledTooltipProps = _param.disabledTooltipProps, others = _objectWithoutProperties(_param, [
22
+ var useLoadingHandler = function(handler) {
23
+ var _useState = _slicedToArray((0, _react.useState)(false), 2), isLoading = _useState[0], setIsLoading = _useState[1];
24
+ var handleClick = function() {
25
+ var _ref = _asyncToGenerator(function(event) {
26
+ var possiblePromise, err;
27
+ return _tsGenerator(this, function(_state) {
28
+ switch(_state.label){
29
+ case 0:
30
+ possiblePromise = handler(event);
31
+ _state.label = 1;
32
+ case 1:
33
+ _state.trys.push([
34
+ 1,
35
+ 4,
36
+ ,
37
+ 5
38
+ ]);
39
+ if (!_instanceof(possiblePromise, Promise)) return [
40
+ 3,
41
+ 3
42
+ ];
43
+ setIsLoading(true);
44
+ return [
45
+ 4,
46
+ possiblePromise
47
+ ];
48
+ case 2:
49
+ _state.sent();
50
+ setIsLoading(false);
51
+ _state.label = 3;
52
+ case 3:
53
+ return [
54
+ 3,
55
+ 5
56
+ ];
57
+ case 4:
58
+ err = _state.sent();
59
+ setIsLoading(false);
60
+ console.error(err);
61
+ return [
62
+ 3,
63
+ 5
64
+ ];
65
+ case 5:
66
+ return [
67
+ 2
68
+ ];
69
+ }
70
+ });
71
+ });
72
+ return function handleClick(event) {
73
+ return _ref.apply(this, arguments);
74
+ };
75
+ }();
76
+ return {
77
+ isLoading: isLoading,
78
+ handleClick: handleClick
79
+ };
80
+ };
81
+ var _Button = /*#__PURE__*/ (0, _react.forwardRef)(function(_param, ref) {
82
+ var disabledTooltip = _param.disabledTooltip, disabled = _param.disabled, disabledTooltipProps = _param.disabledTooltipProps, loading = _param.loading, onClick = _param.onClick, others = _objectWithoutProperties(_param, [
20
83
  "disabledTooltip",
21
84
  "disabled",
22
- "disabledTooltipProps"
85
+ "disabledTooltipProps",
86
+ "loading",
87
+ "onClick"
23
88
  ]);
24
- return (0, _jsxRuntime.jsx)(_buttonWithDisabledTooltip.ButtonWithDisabledTooltip, {
89
+ var _useLoadingHandler = useLoadingHandler(onClick), isLoading = _useLoadingHandler.isLoading, handleClick = _useLoadingHandler.handleClick;
90
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_buttonWithDisabledTooltip.ButtonWithDisabledTooltip, {
25
91
  disabled: disabled,
26
92
  disabledTooltip: disabledTooltip,
27
93
  disabledTooltipProps: disabledTooltipProps,
28
94
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_core.Button, _objectSpread({
95
+ loaderProps: {
96
+ variant: "oval"
97
+ },
29
98
  ref: ref,
99
+ loading: isLoading || loading,
100
+ onClick: handleClick,
30
101
  disabled: disabled
31
102
  }, others))
32
103
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/button/Button.tsx"],"sourcesContent":["import {Button as MantineButton, ButtonProps as MantineButtonProps} from '@mantine/core';\nimport {forwardRef} from 'react';\n\nimport {createPolymorphicComponent} from '../../utils';\nimport {ButtonWithDisabledTooltip, ButtonWithDisabledTooltipProps} from './ButtonWithDisabledTooltip';\n\nexport interface ButtonProps extends MantineButtonProps, ButtonWithDisabledTooltipProps {}\n\nconst _Button = forwardRef<HTMLButtonElement, ButtonProps>(\n ({disabledTooltip, disabled, disabledTooltipProps, ...others}, ref) => (\n <ButtonWithDisabledTooltip\n disabled={disabled}\n disabledTooltip={disabledTooltip}\n disabledTooltipProps={disabledTooltipProps}\n >\n <MantineButton ref={ref} disabled={disabled} {...others} />\n </ButtonWithDisabledTooltip>\n )\n);\n\nexport const Button = createPolymorphicComponent<'button', ButtonProps, {Group: typeof MantineButton.Group}>(_Button);\nButton.Group = MantineButton.Group;\n"],"names":["Button","_Button","forwardRef","ref","disabledTooltip","disabled","disabledTooltipProps","others","ButtonWithDisabledTooltip","MantineButton","createPolymorphicComponent","Group"],"mappings":";;;;+BAoBaA;;;eAAAA;;;;;;oBApB4D;qBAChD;qBAEgB;yCAC+B;AAIxE,IAAMC,wBAAUC,IAAAA,iBAAU,EACtB,iBAA+DC,mBAC3D;QADFC,yBAAAA,iBAAiBC,kBAAAA,UAAUC,8BAAAA,sBAAyBC;QAApDH;QAAiBC;QAAUC;;WACzB,qBAACE,oDAAyB;QACtBH,UAAUA;QACVD,iBAAiBA;QACjBE,sBAAsBA;kBAEtB,cAAA,qBAACG,YAAa;YAACN,KAAKA;YAAKE,UAAUA;WAAcE;;AAC1B;AAI5B,IAAMP,SAASU,IAAAA,iCAA0B,EAA6DT;AAC7GD,OAAOW,KAAK,GAAGF,YAAa,CAACE,KAAK"}
1
+ {"version":3,"sources":["../../../../src/components/button/Button.tsx"],"sourcesContent":["import {Button as MantineButton, ButtonProps as MantineButtonProps} from '@mantine/core';\nimport {forwardRef, useState, MouseEventHandler, MouseEvent} from 'react';\n\nimport {createPolymorphicComponent} from '../../utils';\nimport {ButtonWithDisabledTooltip, ButtonWithDisabledTooltipProps} from './ButtonWithDisabledTooltip';\n\nexport interface ButtonProps extends MantineButtonProps, ButtonWithDisabledTooltipProps {\n /* Handler executed on click */\n onClick?: MouseEventHandler<HTMLButtonElement>;\n}\n\nconst useLoadingHandler = (handler: MouseEventHandler<HTMLButtonElement>) => {\n const [isLoading, setIsLoading] = useState(false);\n\n const handleClick = async (event: MouseEvent<HTMLButtonElement>) => {\n const possiblePromise: unknown = handler(event);\n try {\n if (possiblePromise instanceof Promise) {\n setIsLoading(true);\n await possiblePromise;\n setIsLoading(false);\n }\n } catch (err) {\n setIsLoading(false);\n console.error(err);\n }\n };\n\n return {isLoading, handleClick};\n};\n\nconst _Button = forwardRef<HTMLButtonElement, ButtonProps>(\n ({disabledTooltip, disabled, disabledTooltipProps, loading, onClick, ...others}, ref) => {\n const {isLoading, handleClick} = useLoadingHandler(onClick);\n return (\n <ButtonWithDisabledTooltip\n disabled={disabled}\n disabledTooltip={disabledTooltip}\n disabledTooltipProps={disabledTooltipProps}\n >\n <MantineButton\n loaderProps={{variant: 'oval'}}\n ref={ref}\n loading={isLoading || loading}\n onClick={handleClick}\n disabled={disabled}\n {...others}\n />\n </ButtonWithDisabledTooltip>\n );\n }\n);\n\nexport const Button = createPolymorphicComponent<'button', ButtonProps, {Group: typeof MantineButton.Group}>(_Button);\nButton.Group = MantineButton.Group;\n"],"names":["Button","useLoadingHandler","handler","useState","isLoading","setIsLoading","handleClick","event","possiblePromise","err","Promise","console","error","_Button","forwardRef","ref","disabledTooltip","disabled","disabledTooltipProps","loading","onClick","others","ButtonWithDisabledTooltip","MantineButton","loaderProps","variant","createPolymorphicComponent","Group"],"mappings":";;;;+BAqDaA;;;eAAAA;;;;;;;;;;oBArD4D;qBACP;qBAEzB;yCAC+B;AAOxE,IAAMC,oBAAoB,SAACC,SAAkD;IACzE,IAAkCC,2BAAAA,IAAAA,eAAQ,EAAC,KAAK,OAAzCC,YAA2BD,cAAhBE,eAAgBF;IAElC,IAAMG;mBAAc,kBAAA,SAAOC,OAAyC;gBAC1DC,iBAOGC;;;;wBAPHD,kBAA2BN,QAAQK;;;;;;;;;6BAEjCC,AAAe,YAAfA,iBAA2BE,UAA3BF;;;;wBACAH,aAAa,IAAI;wBACjB;;4BAAMG;;;wBAAN;wBACAH,aAAa,KAAK;;;;;;;;wBAEjBI;wBACLJ,aAAa,KAAK;wBAClBM,QAAQC,KAAK,CAACH;;;;;;;;;;;QAEtB;wBAZMH,YAAqBC;;;;IAc3B,OAAO;QAACH,WAAAA;QAAWE,aAAAA;IAAW;AAClC;AAEA,IAAMO,wBAAUC,IAAAA,iBAAU,EACtB,iBAAiFC,KAAQ;QAAvFC,yBAAAA,iBAAiBC,kBAAAA,UAAUC,8BAAAA,sBAAsBC,iBAAAA,SAASC,iBAAAA,SAAYC;QAAtEL;QAAiBC;QAAUC;QAAsBC;QAASC;;IACxD,IAAiCnB,qBAAAA,kBAAkBmB,UAA5ChB,YAA0BH,mBAA1BG,WAAWE,cAAeL,mBAAfK;IAClB,qBACI,qBAACgB,oDAAyB;QACtBL,UAAUA;QACVD,iBAAiBA;QACjBE,sBAAsBA;kBAEtB,cAAA,qBAACK,YAAa;YACVC,aAAa;gBAACC,SAAS;YAAM;YAC7BV,KAAKA;YACLI,SAASf,aAAae;YACtBC,SAASd;YACTW,UAAUA;WACNI;;AAIpB;AAGG,IAAMrB,SAAS0B,IAAAA,iCAA0B,EAA6Db;AAC7Gb,OAAO2B,KAAK,GAAGJ,YAAa,CAACI,KAAK"}
package/dist/cjs/index.js CHANGED
@@ -9,6 +9,9 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
+ NotificationProps: function() {
13
+ return _notifications.NotificationProps;
14
+ },
12
15
  Pagination: function() {
13
16
  return _core.Pagination;
14
17
  },
@@ -35,6 +38,7 @@ _export(exports, {
35
38
  }
36
39
  });
37
40
  var _exportStar = require("@swc/helpers/lib/_export_star.js").default;
41
+ var _notifications = _exportStar(require("@mantine/notifications"), exports);
38
42
  _exportStar(require("@mantine/carousel"), exports);
39
43
  var _core = _exportStar(require("@mantine/core"), exports);
40
44
  _exportStar(require("@mantine/hooks"), exports);
@@ -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 type {FormValidateInput} from '@mantine/form/lib/types';\nexport * from '@mantine/hooks';\nexport * from '@tanstack/table-core';\nexport * from './components';\nexport * from '@mantine/form';\nexport {Pagination} from '@mantine/core';\n// explicitly overriding mantine components\nexport {\n Header,\n Table,\n type TableProps,\n type TableState,\n type InitialTableState,\n type HeaderProps,\n Modal,\n Button,\n type ButtonProps,\n Menu,\n type MenuItemProps,\n} 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":["Pagination","Header","Table","Modal","Button","Menu","useForm","createFormContext"],"mappings":";;;;;;;;;;;IAWQA,UAAU;eAAVA,gBAAU;;IAGdC,MAAM;eAANA,kBAAM;;IACNC,KAAK;eAALA,iBAAK;;IAKLC,KAAK;eAALA,iBAAK;;IACLC,MAAM;eAANA,kBAAM;;IAENC,IAAI;eAAJA,gBAAI;;IAGAC,OAAO;eAAPA,aAAO;;IAAEC,iBAAiB;eAAjBA,uBAAiB;;;;oBAtBpB;gCACA;oBAEA;oBACA;sCACA;oBACA;oBAgB2B;oBAE3B"}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import {Tuple} from '@mantine/core';\n\nimport {PlasmaColors} from './theme/PlasmaColors';\n\nexport * from '@mantine/notifications';\nexport * from '@mantine/carousel';\nexport * from '@mantine/core';\nexport type {FormValidateInput} from '@mantine/form/lib/types';\nexport * from '@mantine/hooks';\nexport * from '@tanstack/table-core';\nexport * from './components';\nexport * from '@mantine/form';\nexport {NotificationProps} from '@mantine/notifications';\nexport {Pagination} from '@mantine/core';\n// explicitly overriding mantine components\nexport {\n Header,\n Table,\n type TableProps,\n type TableState,\n type InitialTableState,\n type HeaderProps,\n Modal,\n Button,\n type ButtonProps,\n Menu,\n type MenuItemProps,\n} 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":["NotificationProps","Pagination","Header","Table","Modal","Button","Menu","useForm","createFormContext"],"mappings":";;;;;;;;;;;IAYQA,iBAAiB;eAAjBA,gCAAiB;;IACjBC,UAAU;eAAVA,gBAAU;;IAGdC,MAAM;eAANA,kBAAM;;IACNC,KAAK;eAALA,iBAAK;;IAKLC,KAAK;eAALA,iBAAK;;IACLC,MAAM;eAANA,kBAAM;;IAENC,IAAI;eAAJA,gBAAI;;IAGAC,OAAO;eAAPA,aAAO;;IAAEC,iBAAiB;eAAjBA,uBAAiB;;;;yCAxBpB;oBACA;gCACA;oBAEA;oBACA;sCACA;oBACA;oBAiB2B;oBAE3B"}
@@ -1,7 +1,8 @@
1
- /// <reference types="react" />
2
1
  import { Button as MantineButton, ButtonProps as MantineButtonProps } from '@mantine/core';
2
+ import { MouseEventHandler } from 'react';
3
3
  import { ButtonWithDisabledTooltipProps } from './ButtonWithDisabledTooltip';
4
4
  export interface ButtonProps extends MantineButtonProps, ButtonWithDisabledTooltipProps {
5
+ onClick?: MouseEventHandler<HTMLButtonElement>;
5
6
  }
6
7
  export declare const Button: (<C = "button">(props: import("@mantine/utils").PolymorphicComponentProps<C, ButtonProps>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) & Omit<import("react").FunctionComponent<(ButtonProps & {
7
8
  component?: any;
@@ -1 +1 @@
1
- {"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../../../src/components/button/Button.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,IAAI,aAAa,EAAE,WAAW,IAAI,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAIzF,OAAO,EAA4B,8BAA8B,EAAC,MAAM,6BAA6B,CAAC;AAEtG,MAAM,WAAW,WAAY,SAAQ,kBAAkB,EAAE,8BAA8B;CAAG;AAc1F,eAAO,MAAM,MAAM;;;;;;;WAA6D,OAAO,cAAc,KAAK;CAAW,CAAC"}
1
+ {"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../../../src/components/button/Button.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,IAAI,aAAa,EAAE,WAAW,IAAI,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACzF,OAAO,EAAuB,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAG1E,OAAO,EAA4B,8BAA8B,EAAC,MAAM,6BAA6B,CAAC;AAEtG,MAAM,WAAW,WAAY,SAAQ,kBAAkB,EAAE,8BAA8B;IAEnF,OAAO,CAAC,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;CAClD;AA4CD,eAAO,MAAM,MAAM;;;;;;;WAA6D,OAAO,cAAc,KAAK;CAAW,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { Tuple } from '@mantine/core';
2
2
  import { PlasmaColors } from './theme/PlasmaColors';
3
+ export * from '@mantine/notifications';
3
4
  export * from '@mantine/carousel';
4
5
  export * from '@mantine/core';
5
6
  export type { FormValidateInput } from '@mantine/form/lib/types';
@@ -7,6 +8,7 @@ export * from '@mantine/hooks';
7
8
  export * from '@tanstack/table-core';
8
9
  export * from './components';
9
10
  export * from '@mantine/form';
11
+ export { NotificationProps } from '@mantine/notifications';
10
12
  export { Pagination } from '@mantine/core';
11
13
  export { Header, Table, type TableProps, type TableState, type InitialTableState, type HeaderProps, Modal, Button, type ButtonProps, Menu, type MenuItemProps, } from './components';
12
14
  export { useForm, createFormContext } from './form';
@@ -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,YAAY,EAAC,iBAAiB,EAAC,MAAM,yBAAyB,CAAC;AAC/D,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC,OAAO,EACH,MAAM,EACN,KAAK,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,EACL,MAAM,EACN,KAAK,WAAW,EAChB,IAAI,EACJ,KAAK,aAAa,GACrB,MAAM,cAAc,CAAC;AACtB,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
+ {"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,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,YAAY,EAAC,iBAAiB,EAAC,MAAM,yBAAyB,CAAC;AAC/D,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAC,iBAAiB,EAAC,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC,OAAO,EACH,MAAM,EACN,KAAK,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,EACL,MAAM,EACN,KAAK,WAAW,EAChB,IAAI,EACJ,KAAK,aAAa,GACrB,MAAM,cAAc,CAAC;AACtB,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,22 +1,93 @@
1
+ import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs";
2
+ import _instanceof from "@swc/helpers/src/_instanceof.mjs";
1
3
  import _object_spread from "@swc/helpers/src/_object_spread.mjs";
2
4
  import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs";
5
+ import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs";
6
+ import _ts_generator from "@swc/helpers/src/_ts_generator.mjs";
3
7
  import { jsx as _jsx } from "react/jsx-runtime";
4
8
  import { Button as MantineButton } from "@mantine/core";
5
- import { forwardRef } from "react";
9
+ import { forwardRef, useState } from "react";
6
10
  import { createPolymorphicComponent } from "../../utils";
7
11
  import { ButtonWithDisabledTooltip } from "./ButtonWithDisabledTooltip";
8
- var _Button = /*#__PURE__*/ forwardRef(function(_param, ref) /*#__PURE__*/ {
9
- var disabledTooltip = _param.disabledTooltip, disabled = _param.disabled, disabledTooltipProps = _param.disabledTooltipProps, others = _object_without_properties(_param, [
12
+ var useLoadingHandler = function(handler) {
13
+ var _useState = _sliced_to_array(useState(false), 2), isLoading = _useState[0], setIsLoading = _useState[1];
14
+ var handleClick = function() {
15
+ var _ref = _async_to_generator(function(event) {
16
+ var possiblePromise, err;
17
+ return _ts_generator(this, function(_state) {
18
+ switch(_state.label){
19
+ case 0:
20
+ possiblePromise = handler(event);
21
+ _state.label = 1;
22
+ case 1:
23
+ _state.trys.push([
24
+ 1,
25
+ 4,
26
+ ,
27
+ 5
28
+ ]);
29
+ if (!_instanceof(possiblePromise, Promise)) return [
30
+ 3,
31
+ 3
32
+ ];
33
+ setIsLoading(true);
34
+ return [
35
+ 4,
36
+ possiblePromise
37
+ ];
38
+ case 2:
39
+ _state.sent();
40
+ setIsLoading(false);
41
+ _state.label = 3;
42
+ case 3:
43
+ return [
44
+ 3,
45
+ 5
46
+ ];
47
+ case 4:
48
+ err = _state.sent();
49
+ setIsLoading(false);
50
+ console.error(err);
51
+ return [
52
+ 3,
53
+ 5
54
+ ];
55
+ case 5:
56
+ return [
57
+ 2
58
+ ];
59
+ }
60
+ });
61
+ });
62
+ return function handleClick(event) {
63
+ return _ref.apply(this, arguments);
64
+ };
65
+ }();
66
+ return {
67
+ isLoading: isLoading,
68
+ handleClick: handleClick
69
+ };
70
+ };
71
+ var _Button = /*#__PURE__*/ forwardRef(function(_param, ref) {
72
+ var disabledTooltip = _param.disabledTooltip, disabled = _param.disabled, disabledTooltipProps = _param.disabledTooltipProps, loading = _param.loading, onClick = _param.onClick, others = _object_without_properties(_param, [
10
73
  "disabledTooltip",
11
74
  "disabled",
12
- "disabledTooltipProps"
75
+ "disabledTooltipProps",
76
+ "loading",
77
+ "onClick"
13
78
  ]);
14
- return _jsx(ButtonWithDisabledTooltip, {
79
+ var _useLoadingHandler = useLoadingHandler(onClick), isLoading = _useLoadingHandler.isLoading, handleClick = _useLoadingHandler.handleClick;
80
+ return /*#__PURE__*/ _jsx(ButtonWithDisabledTooltip, {
15
81
  disabled: disabled,
16
82
  disabledTooltip: disabledTooltip,
17
83
  disabledTooltipProps: disabledTooltipProps,
18
84
  children: /*#__PURE__*/ _jsx(MantineButton, _object_spread({
85
+ loaderProps: {
86
+ variant: "oval"
87
+ },
19
88
  ref: ref,
89
+ loading: isLoading || loading,
90
+ onClick: handleClick,
20
91
  disabled: disabled
21
92
  }, others))
22
93
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/button/Button.tsx"],"sourcesContent":["import {Button as MantineButton, ButtonProps as MantineButtonProps} from '@mantine/core';\nimport {forwardRef} from 'react';\n\nimport {createPolymorphicComponent} from '../../utils';\nimport {ButtonWithDisabledTooltip, ButtonWithDisabledTooltipProps} from './ButtonWithDisabledTooltip';\n\nexport interface ButtonProps extends MantineButtonProps, ButtonWithDisabledTooltipProps {}\n\nconst _Button = forwardRef<HTMLButtonElement, ButtonProps>(\n ({disabledTooltip, disabled, disabledTooltipProps, ...others}, ref) => (\n <ButtonWithDisabledTooltip\n disabled={disabled}\n disabledTooltip={disabledTooltip}\n disabledTooltipProps={disabledTooltipProps}\n >\n <MantineButton ref={ref} disabled={disabled} {...others} />\n </ButtonWithDisabledTooltip>\n )\n);\n\nexport const Button = createPolymorphicComponent<'button', ButtonProps, {Group: typeof MantineButton.Group}>(_Button);\nButton.Group = MantineButton.Group;\n"],"names":["Button","MantineButton","forwardRef","createPolymorphicComponent","ButtonWithDisabledTooltip","_Button","ref","disabledTooltip","disabled","disabledTooltipProps","others","Group"],"mappings":";;;AAAA,SAAQA,UAAUC,aAAa,QAA0C,gBAAgB;AACzF,SAAQC,UAAU,QAAO,QAAQ;AAEjC,SAAQC,0BAA0B,QAAO,cAAc;AACvD,SAAQC,yBAAyB,QAAuC,8BAA8B;AAItG,IAAMC,wBAAUH,WACZ,iBAA+DI,mBAC3D;QADFC,yBAAAA,iBAAiBC,kBAAAA,UAAUC,8BAAAA,sBAAyBC;QAApDH;QAAiBC;QAAUC;;WACzB,KAACL;QACGI,UAAUA;QACVD,iBAAiBA;QACjBE,sBAAsBA;kBAEtB,cAAA,KAACR;YAAcK,KAAKA;YAAKE,UAAUA;WAAcE;;AAC1B;AAInC,OAAO,IAAMV,SAASG,2BAAuFE,SAAS;AACtHL,OAAOW,KAAK,GAAGV,cAAcU,KAAK"}
1
+ {"version":3,"sources":["../../../../src/components/button/Button.tsx"],"sourcesContent":["import {Button as MantineButton, ButtonProps as MantineButtonProps} from '@mantine/core';\nimport {forwardRef, useState, MouseEventHandler, MouseEvent} from 'react';\n\nimport {createPolymorphicComponent} from '../../utils';\nimport {ButtonWithDisabledTooltip, ButtonWithDisabledTooltipProps} from './ButtonWithDisabledTooltip';\n\nexport interface ButtonProps extends MantineButtonProps, ButtonWithDisabledTooltipProps {\n /* Handler executed on click */\n onClick?: MouseEventHandler<HTMLButtonElement>;\n}\n\nconst useLoadingHandler = (handler: MouseEventHandler<HTMLButtonElement>) => {\n const [isLoading, setIsLoading] = useState(false);\n\n const handleClick = async (event: MouseEvent<HTMLButtonElement>) => {\n const possiblePromise: unknown = handler(event);\n try {\n if (possiblePromise instanceof Promise) {\n setIsLoading(true);\n await possiblePromise;\n setIsLoading(false);\n }\n } catch (err) {\n setIsLoading(false);\n console.error(err);\n }\n };\n\n return {isLoading, handleClick};\n};\n\nconst _Button = forwardRef<HTMLButtonElement, ButtonProps>(\n ({disabledTooltip, disabled, disabledTooltipProps, loading, onClick, ...others}, ref) => {\n const {isLoading, handleClick} = useLoadingHandler(onClick);\n return (\n <ButtonWithDisabledTooltip\n disabled={disabled}\n disabledTooltip={disabledTooltip}\n disabledTooltipProps={disabledTooltipProps}\n >\n <MantineButton\n loaderProps={{variant: 'oval'}}\n ref={ref}\n loading={isLoading || loading}\n onClick={handleClick}\n disabled={disabled}\n {...others}\n />\n </ButtonWithDisabledTooltip>\n );\n }\n);\n\nexport const Button = createPolymorphicComponent<'button', ButtonProps, {Group: typeof MantineButton.Group}>(_Button);\nButton.Group = MantineButton.Group;\n"],"names":["Button","MantineButton","forwardRef","useState","createPolymorphicComponent","ButtonWithDisabledTooltip","useLoadingHandler","handler","isLoading","setIsLoading","handleClick","event","possiblePromise","err","Promise","console","error","_Button","ref","disabledTooltip","disabled","disabledTooltipProps","loading","onClick","others","loaderProps","variant","Group"],"mappings":";;;;;;;AAAA,SAAQA,UAAUC,aAAa,QAA0C,gBAAgB;AACzF,SAAQC,UAAU,EAAEC,QAAQ,QAAsC,QAAQ;AAE1E,SAAQC,0BAA0B,QAAO,cAAc;AACvD,SAAQC,yBAAyB,QAAuC,8BAA8B;AAOtG,IAAMC,oBAAoB,SAACC,SAAkD;IACzE,IAAkCJ,6BAAAA,SAAS,KAAK,OAAzCK,YAA2BL,cAAhBM,eAAgBN;IAElC,IAAMO;mBAAc,oBAAA,SAAOC,OAAyC;gBAC1DC,iBAOGC;;;;wBAPHD,kBAA2BL,QAAQI;;;;;;;;;6BAEjCC,AAAe,YAAfA,iBAA2BE,UAA3BF;;;;wBACAH,aAAa,IAAI;wBACjB;;4BAAMG;;;wBAAN;wBACAH,aAAa,KAAK;;;;;;;;wBAEjBI;wBACLJ,aAAa,KAAK;wBAClBM,QAAQC,KAAK,CAACH;;;;;;;;;;;QAEtB;wBAZMH,YAAqBC;;;;IAc3B,OAAO;QAACH,WAAAA;QAAWE,aAAAA;IAAW;AAClC;AAEA,IAAMO,wBAAUf,WACZ,iBAAiFgB,KAAQ;QAAvFC,yBAAAA,iBAAiBC,kBAAAA,UAAUC,8BAAAA,sBAAsBC,iBAAAA,SAASC,iBAAAA,SAAYC;QAAtEL;QAAiBC;QAAUC;QAAsBC;QAASC;;IACxD,IAAiCjB,qBAAAA,kBAAkBiB,UAA5Cf,YAA0BF,mBAA1BE,WAAWE,cAAeJ,mBAAfI;IAClB,qBACI,KAACL;QACGe,UAAUA;QACVD,iBAAiBA;QACjBE,sBAAsBA;kBAEtB,cAAA,KAACpB;YACGwB,aAAa;gBAACC,SAAS;YAAM;YAC7BR,KAAKA;YACLI,SAASd,aAAac;YACtBC,SAASb;YACTU,UAAUA;WACNI;;AAIpB;AAGJ,OAAO,IAAMxB,SAASI,2BAAuFa,SAAS;AACtHjB,OAAO2B,KAAK,GAAG1B,cAAc0B,KAAK"}
package/dist/esm/index.js CHANGED
@@ -1,9 +1,11 @@
1
+ export * from "@mantine/notifications";
1
2
  export * from "@mantine/carousel";
2
3
  export * from "@mantine/core";
3
4
  export * from "@mantine/hooks";
4
5
  export * from "@tanstack/table-core";
5
6
  export * from "./components";
6
7
  export * from "@mantine/form";
8
+ export { NotificationProps } from "@mantine/notifications";
7
9
  export { Pagination } from "@mantine/core";
8
10
  // explicitly overriding mantine components
9
11
  export { Header, Table, Modal, Button, Menu } from "./components";
@@ -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 type {FormValidateInput} from '@mantine/form/lib/types';\nexport * from '@mantine/hooks';\nexport * from '@tanstack/table-core';\nexport * from './components';\nexport * from '@mantine/form';\nexport {Pagination} from '@mantine/core';\n// explicitly overriding mantine components\nexport {\n Header,\n Table,\n type TableProps,\n type TableState,\n type InitialTableState,\n type HeaderProps,\n Modal,\n Button,\n type ButtonProps,\n Menu,\n type MenuItemProps,\n} 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":["Pagination","Header","Table","Modal","Button","Menu","useForm","createFormContext"],"mappings":"AAIA,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAE9B,cAAc,iBAAiB;AAC/B,cAAc,uBAAuB;AACrC,cAAc,eAAe;AAC7B,cAAc,gBAAgB;AAC9B,SAAQA,UAAU,QAAO,gBAAgB;AACzC,2CAA2C;AAC3C,SACIC,MAAM,EACNC,KAAK,EAKLC,KAAK,EACLC,MAAM,EAENC,IAAI,QAED,eAAe;AACtB,SAAQC,OAAO,EAAEC,iBAAiB,QAAO,SAAS;AAElD,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/notifications';\nexport * from '@mantine/carousel';\nexport * from '@mantine/core';\nexport type {FormValidateInput} from '@mantine/form/lib/types';\nexport * from '@mantine/hooks';\nexport * from '@tanstack/table-core';\nexport * from './components';\nexport * from '@mantine/form';\nexport {NotificationProps} from '@mantine/notifications';\nexport {Pagination} from '@mantine/core';\n// explicitly overriding mantine components\nexport {\n Header,\n Table,\n type TableProps,\n type TableState,\n type InitialTableState,\n type HeaderProps,\n Modal,\n Button,\n type ButtonProps,\n Menu,\n type MenuItemProps,\n} 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":["NotificationProps","Pagination","Header","Table","Modal","Button","Menu","useForm","createFormContext"],"mappings":"AAIA,cAAc,yBAAyB;AACvC,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAE9B,cAAc,iBAAiB;AAC/B,cAAc,uBAAuB;AACrC,cAAc,eAAe;AAC7B,cAAc,gBAAgB;AAC9B,SAAQA,iBAAiB,QAAO,yBAAyB;AACzD,SAAQC,UAAU,QAAO,gBAAgB;AACzC,2CAA2C;AAC3C,SACIC,MAAM,EACNC,KAAK,EAKLC,KAAK,EACLC,MAAM,EAENC,IAAI,QAED,eAAe;AACtB,SAAQC,OAAO,EAAEC,iBAAiB,QAAO,SAAS;AAElD,cAAc,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coveord/plasma-mantine",
3
- "version": "49.5.3",
3
+ "version": "49.6.0",
4
4
  "description": "A Plasma flavoured Mantine theme",
5
5
  "keywords": [
6
6
  "plasma",
@@ -36,6 +36,7 @@
36
36
  "@mantine/form": "5.9.2",
37
37
  "@mantine/hooks": "5.9.2",
38
38
  "@mantine/modals": "5.9.2",
39
+ "@mantine/notifications": "5.9.2",
39
40
  "@swc/cli": "0.1.62",
40
41
  "@swc/core": "1.3.35",
41
42
  "@swc/jest": "0.2.23",
@@ -1,21 +1,54 @@
1
1
  import {Button as MantineButton, ButtonProps as MantineButtonProps} from '@mantine/core';
2
- import {forwardRef} from 'react';
2
+ import {forwardRef, useState, MouseEventHandler, MouseEvent} from 'react';
3
3
 
4
4
  import {createPolymorphicComponent} from '../../utils';
5
5
  import {ButtonWithDisabledTooltip, ButtonWithDisabledTooltipProps} from './ButtonWithDisabledTooltip';
6
6
 
7
- export interface ButtonProps extends MantineButtonProps, ButtonWithDisabledTooltipProps {}
7
+ export interface ButtonProps extends MantineButtonProps, ButtonWithDisabledTooltipProps {
8
+ /* Handler executed on click */
9
+ onClick?: MouseEventHandler<HTMLButtonElement>;
10
+ }
11
+
12
+ const useLoadingHandler = (handler: MouseEventHandler<HTMLButtonElement>) => {
13
+ const [isLoading, setIsLoading] = useState(false);
14
+
15
+ const handleClick = async (event: MouseEvent<HTMLButtonElement>) => {
16
+ const possiblePromise: unknown = handler(event);
17
+ try {
18
+ if (possiblePromise instanceof Promise) {
19
+ setIsLoading(true);
20
+ await possiblePromise;
21
+ setIsLoading(false);
22
+ }
23
+ } catch (err) {
24
+ setIsLoading(false);
25
+ console.error(err);
26
+ }
27
+ };
28
+
29
+ return {isLoading, handleClick};
30
+ };
8
31
 
9
32
  const _Button = forwardRef<HTMLButtonElement, ButtonProps>(
10
- ({disabledTooltip, disabled, disabledTooltipProps, ...others}, ref) => (
11
- <ButtonWithDisabledTooltip
12
- disabled={disabled}
13
- disabledTooltip={disabledTooltip}
14
- disabledTooltipProps={disabledTooltipProps}
15
- >
16
- <MantineButton ref={ref} disabled={disabled} {...others} />
17
- </ButtonWithDisabledTooltip>
18
- )
33
+ ({disabledTooltip, disabled, disabledTooltipProps, loading, onClick, ...others}, ref) => {
34
+ const {isLoading, handleClick} = useLoadingHandler(onClick);
35
+ return (
36
+ <ButtonWithDisabledTooltip
37
+ disabled={disabled}
38
+ disabledTooltip={disabledTooltip}
39
+ disabledTooltipProps={disabledTooltipProps}
40
+ >
41
+ <MantineButton
42
+ loaderProps={{variant: 'oval'}}
43
+ ref={ref}
44
+ loading={isLoading || loading}
45
+ onClick={handleClick}
46
+ disabled={disabled}
47
+ {...others}
48
+ />
49
+ </ButtonWithDisabledTooltip>
50
+ );
51
+ }
19
52
  );
20
53
 
21
54
  export const Button = createPolymorphicComponent<'button', ButtonProps, {Group: typeof MantineButton.Group}>(_Button);
@@ -1,4 +1,4 @@
1
- import {render} from '@test-utils';
1
+ import {render, screen, userEvent, waitFor, within} from '@test-utils';
2
2
 
3
3
  import {Button} from '../Button';
4
4
 
@@ -9,4 +9,79 @@ describe('Button', () => {
9
9
  render(<Button.Group></Button.Group>);
10
10
  }).not.toThrow();
11
11
  });
12
+
13
+ describe('onClick Promise handler', () => {
14
+ it('uses the native loading prop if passed', () => {
15
+ render(
16
+ <>
17
+ <Button loading={true}>I am loading</Button>
18
+ <Button loading={false}>I am not loading</Button>
19
+ </>
20
+ );
21
+ expect(within(screen.getByRole('button', {name: /I am loading/i})).getByRole('presentation')).toBeVisible();
22
+ expect(
23
+ within(screen.queryByRole('button', {name: /I am not loading/i})).queryByRole('presentation')
24
+ ).not.toBeInTheDocument();
25
+ });
26
+
27
+ it('shows a loader while the promise is waiting to be resolved', async () => {
28
+ let resolve: () => void;
29
+ let isResolved = false;
30
+
31
+ const promise = () =>
32
+ new Promise<void>((res) => {
33
+ resolve = res;
34
+ }).then(() => {
35
+ isResolved = true;
36
+ });
37
+
38
+ render(<Button onClick={promise}>promise handler</Button>);
39
+
40
+ userEvent.click(screen.getByRole('button', {name: /promise handler/i}));
41
+
42
+ expect(
43
+ await within(screen.getByRole('button', {name: /promise handler/i})).findByRole('presentation')
44
+ ).toBeVisible();
45
+
46
+ resolve();
47
+
48
+ await waitFor(() => {
49
+ expect(isResolved).toBeTruthy();
50
+ });
51
+
52
+ expect(
53
+ within(screen.queryByRole('button', {name: /promise handler/i})).queryByRole('presentation')
54
+ ).not.toBeInTheDocument();
55
+ });
56
+
57
+ it('removes the loading if a promise is rejected', async () => {
58
+ let reject: () => void;
59
+ let isRejected = false;
60
+
61
+ const promise = () =>
62
+ new Promise<void>((res, rej) => {
63
+ reject = rej;
64
+ }).catch(() => {
65
+ isRejected = true;
66
+ });
67
+
68
+ render(<Button onClick={promise}>promise handler</Button>);
69
+
70
+ userEvent.click(screen.getByRole('button', {name: /promise handler/i}));
71
+
72
+ expect(
73
+ await within(screen.getByRole('button', {name: /promise handler/i})).findByRole('presentation')
74
+ ).toBeVisible();
75
+
76
+ reject();
77
+
78
+ await waitFor(() => {
79
+ expect(isRejected).toBeTruthy();
80
+ });
81
+
82
+ expect(
83
+ within(screen.queryByRole('button', {name: /promise handler/i})).queryByRole('presentation')
84
+ ).not.toBeInTheDocument();
85
+ });
86
+ });
12
87
  });
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ import {Tuple} from '@mantine/core';
2
2
 
3
3
  import {PlasmaColors} from './theme/PlasmaColors';
4
4
 
5
+ export * from '@mantine/notifications';
5
6
  export * from '@mantine/carousel';
6
7
  export * from '@mantine/core';
7
8
  export type {FormValidateInput} from '@mantine/form/lib/types';
@@ -9,6 +10,7 @@ export * from '@mantine/hooks';
9
10
  export * from '@tanstack/table-core';
10
11
  export * from './components';
11
12
  export * from '@mantine/form';
13
+ export {NotificationProps} from '@mantine/notifications';
12
14
  export {Pagination} from '@mantine/core';
13
15
  // explicitly overriding mantine components
14
16
  export {