@onewelcome/react-lib-components 3.0.1 → 4.0.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.
- package/dist/cjs/Notifications/BaseModal/BaseModal.cjs.js +1 -1
- package/dist/cjs/Notifications/BaseModal/BaseModalActions/BaseModalActions.cjs.js +1 -1
- package/dist/cjs/Notifications/Dialog/DialogActions/DialogActions.cjs.js +1 -1
- package/dist/cjs/Notifications/Dialog/DialogActions/DialogActions.module.cjs.js +1 -1
- package/dist/cjs/Wizard/WizardActions/WizardActions.cjs.js +1 -1
- package/dist/cjs/src/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.d.ts +5 -3
- package/dist/cjs/src/components/Wizard/WizardActions/WizardActions.d.ts +0 -6
- package/dist/esm/Notifications/BaseModal/BaseModal.esm.js +1 -1
- package/dist/esm/Notifications/BaseModal/BaseModalActions/BaseModalActions.esm.js +1 -1
- package/dist/esm/Notifications/Dialog/DialogActions/DialogActions.esm.js +1 -1
- package/dist/esm/Notifications/Dialog/DialogActions/DialogActions.module.esm.js +1 -1
- package/dist/esm/Wizard/WizardActions/WizardActions.esm.js +1 -1
- package/dist/esm/src/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.d.ts +5 -3
- package/dist/esm/src/components/Wizard/WizardActions/WizardActions.d.ts +0 -6
- package/package.json +1 -1
- package/src/components/Notifications/BaseModal/BaseModal.tsx +19 -3
- package/src/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +7 -22
- package/src/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.tsx +20 -20
- package/src/components/Notifications/Dialog/Dialog.test.tsx +1 -2
- package/src/components/Notifications/Dialog/DialogActions/DialogActions.module.scss +14 -0
- package/src/components/Notifications/Dialog/DialogActions/DialogActions.tsx +2 -1
- package/src/components/Wizard/Wizard.test.tsx +3 -13
- package/src/components/Wizard/WizardActions/WizardActions.test.tsx +6 -18
- package/src/components/Wizard/WizardActions/WizardActions.tsx +0 -15
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),l=require("react-dom"),a=require("../../src/hooks/useGetDomRoot.cjs.js"),d=require("./BaseModal.module.cjs.js"),o=require("./BaseModalContext.cjs.js");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(e);const n="overflow",s=l=>{e.useEffect((()=>{l?document.body.style[n]="hidden":0===document.querySelectorAll("[role=dialog][data-hidden=false]").length&&document.body.style.removeProperty(n)}),[l])},i=r.default.forwardRef((({id:t,children:n,open:i,onClose:u,className:c="",containerProps:f,backdropProps:m,labelledby:v,describedby:p,disableEscapeKeyDown:b=!1,disableBackdrop:y=!1,forceContainerOpen:E=!1,zIndex:h,domRoot:x,...$},j)=>{var N,C,I;s(i);const g=e.useRef(null),{root:k}=a.useGetDomRoot(x,g);e.useEffect((()=>{var e;i&&(null===(e=g.current)||void 0===e||e.focus())}),[i]);const q=()=>r.default.Children.map(n,(e=>{var l;return r.default.isValidElement(e)?r.default.cloneElement(e,{onClose:null!==(l=e.props.onClose)&&void 0!==l?l:u}):e}));return r.default.createElement("div",{ref:g},l.createPortal(r.default.createElement("div",{...$,ref:j,id:t,className:`${d.default.modal} ${i?d.default.visible:""} ${c}`,role:"dialog","aria-modal":"true","aria-labelledby":null!=v?v:o.labelId(t),"aria-describedby":null!=p?p:o.descriptionId(t),"aria-hidden":!i,tabIndex:-1,"data-hidden":!i,onKeyDown:e=>{b||"Escape"!==e.key||(e.stopPropagation(),null==u||u())},style:{zIndex:h}},r.default.createElement("div",{...m,className:`${d.default.backdrop} ${null!==(N=null==m?void 0:m.className)&&void 0!==N?N:""}`,onClick:()=>!y&&u&&u()}),E?r.default.createElement("div",{...f,"aria-hidden":!i,"data-element":"dialog",hidden:!i,style:{zIndex:h&&h+1},className:`${d.default.container} ${null!==(C=null==f?void 0:f.className)&&void 0!==C?C:""}`},q()):i&&r.default.createElement("div",{...f,"data-element":"dialog",style:{zIndex:h&&h+1},className:`${d.default.container} ${null!==(I=null==f?void 0:f.className)&&void 0!==I?I:""}`},q())),k))}));exports.BaseModal=i,exports.useSetBodyScroll=s;
|
|
2
2
|
//# sourceMappingURL=BaseModal.cjs.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./BaseModalActions.module.cjs.js"),a=require("../../../Button/Button.cjs.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=l(e);const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./BaseModalActions.module.cjs.js"),a=require("../../../Button/Button.cjs.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=l(e);const n=c.default.forwardRef((({children:l,cancelAction:n,cancelActionsClassName:r="",onClose:o,className:s="",...u},d)=>{const f=c.default.createRef()||d,i=e.useRef(null),m=e.useRef(null),v=c.default.createElement(a.Button,{variant:"text",color:"default",...null==n?void 0:n.cancelButtonProps,onClick:o},null==n?void 0:n.label);return c.default.createElement("div",{...u,ref:f,className:`${t.default.actions} ${s}`},n&&c.default.createElement("div",{className:`${t.default["cancel-action"]} ${r}`,ref:i},v),l&&c.default.createElement("div",{ref:m,className:t.default["primary-actions"]},l))}));exports.BaseModalActions=n;
|
|
2
2
|
//# sourceMappingURL=BaseModalActions.cjs.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),a=require("../../BaseModal/BaseModalActions/BaseModalActions.cjs.js"),o=require("./DialogActions.module.cjs.js");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=t(e);const s=c.default.forwardRef((({children:e,cancelAction:t,onClose:s,...l},n)=>c.default.createElement(a.BaseModalActions,{...l,cancelAction:t,cancelActionsClassName:o.default["cancel-action"],onClose:s,ref:n,className:o.default.actions},e)));exports.DialogActions=s;
|
|
2
2
|
//# sourceMappingURL=DialogActions.cjs.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=".
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=".DialogActions_module_actions__3e00d0bf *+*{margin-left:.5rem}@media screen and (max-width:640px){.DialogActions_module_actions__3e00d0bf .DialogActions_module_cancelAction__3e00d0bf{align-items:flex-end;display:block;flex-direction:column;margin-bottom:.5rem;margin-left:0}.DialogActions_module_actions__3e00d0bf .DialogActions_module_cancelAction__3e00d0bf>*{width:100%}}";require("../../../node_modules/rollup-plugin-styles/dist/runtime/inject-css.cjs.js").default(e,{}),exports.css=e,exports.default={actions:"DialogActions_module_actions__3e00d0bf","cancel-action":"DialogActions_module_cancelAction__3e00d0bf"};
|
|
2
2
|
//# sourceMappingURL=DialogActions.module.cjs.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../../Button/Button.cjs.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../../Button/Button.cjs.js"),r=require("../WizardStateProvider.cjs.js"),n=require("../wizardStateReducer.cjs.js");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=a(e);exports.WizardActions=({actions:a})=>{const{state:{mode:o,steps:i,currentStepNo:u},dispatch:d}=e.useContext(r.WizardStateContext),s=((t,r,n)=>e.useMemo(((e,t)=>()=>e.findIndex(((e,r)=>r>t&&!e.disabled)))(n,r),[t,r,n]))(o,u,i),c=-1!==s,f=((t,r,n)=>e.useMemo(((e,t)=>()=>{const r=e.length-1-t,n=[...e].reverse().findIndex(((e,t)=>t>r&&!e.disabled));return n>0?e.length-1-n:-1})(n,r),[t,r,n]))(o,u,i),v=-1!==f,C=!c||"edit"===o,p=e=>{"forward"===e?c&&d(n.changeCurrentStepNo(s)):v&&d(n.changeCurrentStepNo(f))};return l.default.createElement(e.Fragment,null,v&&l.default.createElement(t.Button,{variant:"outline",onClick:()=>{var e,t;null===(t=(e=a.previous).onClick)||void 0===t||t.call(e),p("backward")}},a.previous.label),c&&l.default.createElement(t.Button,{variant:"edit"===o?"outline":"fill",onClick:()=>{a.next.onClick(u)&&p("forward")}},a.next.label),C&&l.default.createElement(t.Button,{onClick:()=>{a.saveAndClose.onClick(u)}},a.saveAndClose.label))};
|
|
2
2
|
//# sourceMappingURL=WizardActions.cjs.js.map
|
package/dist/cjs/src/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React, { ComponentPropsWithRef } from "react";
|
|
2
|
+
import { Props as ButtonProps } from "../../../Button/Button";
|
|
2
3
|
export interface Props extends ComponentPropsWithRef<"div"> {
|
|
3
4
|
children?: React.ReactNode;
|
|
4
|
-
onClose
|
|
5
|
+
onClose?: () => void;
|
|
5
6
|
cancelAction?: CancelAction;
|
|
7
|
+
cancelActionsClassName?: string;
|
|
6
8
|
}
|
|
7
9
|
export interface CancelAction {
|
|
8
|
-
label
|
|
9
|
-
|
|
10
|
+
label: string;
|
|
11
|
+
cancelButtonProps?: ButtonProps;
|
|
10
12
|
}
|
|
11
13
|
export declare const BaseModalActions: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -2,12 +2,6 @@ import React from "react";
|
|
|
2
2
|
import { Props as ButtonProps } from "../../Button/Button";
|
|
3
3
|
export interface Props extends React.HTMLProps<HTMLDivElement> {
|
|
4
4
|
actions: {
|
|
5
|
-
cancel: {
|
|
6
|
-
label?: string;
|
|
7
|
-
hide?: boolean;
|
|
8
|
-
onClick?: () => void;
|
|
9
|
-
cancelButtonProps?: ButtonProps;
|
|
10
|
-
};
|
|
11
5
|
previous: {
|
|
12
6
|
label: string;
|
|
13
7
|
onClick: () => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e,{useRef as o,useEffect as
|
|
1
|
+
import e,{useRef as o,useEffect as l}from"react";import{createPortal as a}from"react-dom";import{useGetDomRoot as d}from"../../src/hooks/useGetDomRoot.esm.js";import n from"./BaseModal.module.esm.js";import{labelId as r,descriptionId as t}from"./BaseModalContext.esm.js";const s="overflow",i=e=>{l((()=>{e?document.body.style[s]="hidden":0===document.querySelectorAll("[role=dialog][data-hidden=false]").length&&document.body.style.removeProperty(s)}),[e])},m=e.forwardRef((({id:s,children:m,open:c,onClose:u,className:p="",containerProps:v,backdropProps:b,labelledby:y,describedby:f,disableEscapeKeyDown:h=!1,disableBackdrop:E=!1,forceContainerOpen:$=!1,zIndex:N,domRoot:x,...C},g)=>{var k,I,w;i(c);const z=o(null),{root:P}=d(x,z);l((()=>{var e;c&&(null===(e=z.current)||void 0===e||e.focus())}),[c]);const j=()=>e.Children.map(m,(o=>{var l;return e.isValidElement(o)?e.cloneElement(o,{onClose:null!==(l=o.props.onClose)&&void 0!==l?l:u}):o}));return e.createElement("div",{ref:z},a(e.createElement("div",{...C,ref:g,id:s,className:`${n.modal} ${c?n.visible:""} ${p}`,role:"dialog","aria-modal":"true","aria-labelledby":null!=y?y:r(s),"aria-describedby":null!=f?f:t(s),"aria-hidden":!c,tabIndex:-1,"data-hidden":!c,onKeyDown:e=>{h||"Escape"!==e.key||(e.stopPropagation(),null==u||u())},style:{zIndex:N}},e.createElement("div",{...b,className:`${n.backdrop} ${null!==(k=null==b?void 0:b.className)&&void 0!==k?k:""}`,onClick:()=>!E&&u&&u()}),$?e.createElement("div",{...v,"aria-hidden":!c,"data-element":"dialog",hidden:!c,style:{zIndex:N&&N+1},className:`${n.container} ${null!==(I=null==v?void 0:v.className)&&void 0!==I?I:""}`},j()):c&&e.createElement("div",{...v,"data-element":"dialog",style:{zIndex:N&&N+1},className:`${n.container} ${null!==(w=null==v?void 0:v.className)&&void 0!==w?w:""}`},j())),P))}));export{m as BaseModal,i as useSetBodyScroll};
|
|
2
2
|
//# sourceMappingURL=BaseModal.esm.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e,{useRef as
|
|
1
|
+
import e,{useRef as t}from"react";import a from"./BaseModalActions.module.esm.js";import{Button as l}from"../../../Button/Button.esm.js";const c=e.forwardRef((({children:c,cancelAction:o,cancelActionsClassName:n="",onClose:r,className:s="",...m},i)=>{const d=e.createRef()||i,f=t(null),u=t(null),p=e.createElement(l,{variant:"text",color:"default",...null==o?void 0:o.cancelButtonProps,onClick:r},null==o?void 0:o.label);return e.createElement("div",{...m,ref:d,className:`${a.actions} ${s}`},o&&e.createElement("div",{className:`${a["cancel-action"]} ${n}`,ref:f},p),c&&e.createElement("div",{ref:u,className:a["primary-actions"]},c))}));export{c as BaseModalActions};
|
|
2
2
|
//# sourceMappingURL=BaseModalActions.esm.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import o from"react";import{BaseModalActions as e}from"../../BaseModal/BaseModalActions/BaseModalActions.esm.js";import
|
|
1
|
+
import o from"react";import{BaseModalActions as e}from"../../BaseModal/BaseModalActions/BaseModalActions.esm.js";import c from"./DialogActions.module.esm.js";const a=o.forwardRef((({children:a,cancelAction:s,onClose:n,...t},l)=>o.createElement(e,{...t,cancelAction:s,cancelActionsClassName:c["cancel-action"],onClose:n,ref:l,className:c.actions},a)));export{a as DialogActions};
|
|
2
2
|
//# sourceMappingURL=DialogActions.esm.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var containers=[],styleTags=[];const o = function(e,t){if(e&&"undefined"!=typeof document){var n,s=!0===t.prepend?"prepend":"append",r=!0===t.singleTag,a="string"==typeof t.container?document.querySelector(t.container):document.getElementsByTagName("head")[0];if(r){var i=containers.indexOf(a);-1===i&&(i=containers.push(a)-1,styleTags[i]={}),n=styleTags[i]&&styleTags[i][s]?styleTags[i][s]:styleTags[i][s]=c()}else n=c();65279===e.charCodeAt(0)&&(e=e.substring(1)),n.styleSheet?n.styleSheet.cssText+=e:n.appendChild(document.createTextNode(e))}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),t.attributes)for(var n=Object.keys(t.attributes),r=0;r<n.length;r++)e.setAttribute(n[r],t.attributes[n[r]]);var i="prepend"===s?"afterbegin":"beforeend";return a.insertAdjacentElement(i,e),e}};var
|
|
1
|
+
var containers=[],styleTags=[];const o = function(e,t){if(e&&"undefined"!=typeof document){var n,s=!0===t.prepend?"prepend":"append",r=!0===t.singleTag,a="string"==typeof t.container?document.querySelector(t.container):document.getElementsByTagName("head")[0];if(r){var i=containers.indexOf(a);-1===i&&(i=containers.push(a)-1,styleTags[i]={}),n=styleTags[i]&&styleTags[i][s]?styleTags[i][s]:styleTags[i][s]=c()}else n=c();65279===e.charCodeAt(0)&&(e=e.substring(1)),n.styleSheet?n.styleSheet.cssText+=e:n.appendChild(document.createTextNode(e))}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),t.attributes)for(var n=Object.keys(t.attributes),r=0;r<n.length;r++)e.setAttribute(n[r],t.attributes[n[r]]);var i="prepend"===s?"afterbegin":"beforeend";return a.insertAdjacentElement(i,e),e}};var i=".DialogActions_module_actions__3e00d0bf *+*{margin-left:.5rem}@media screen and (max-width:640px){.DialogActions_module_actions__3e00d0bf .DialogActions_module_cancelAction__3e00d0bf{align-items:flex-end;display:block;flex-direction:column;margin-bottom:.5rem;margin-left:0}.DialogActions_module_actions__3e00d0bf .DialogActions_module_cancelAction__3e00d0bf>*{width:100%}}",e={actions:"DialogActions_module_actions__3e00d0bf","cancel-action":"DialogActions_module_cancelAction__3e00d0bf"};o(i,{});export{i as css,e as default};
|
|
2
2
|
//# sourceMappingURL=DialogActions.module.esm.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e,{useContext as t,Fragment as
|
|
1
|
+
import e,{useContext as t,Fragment as r,useMemo as n}from"react";import{Button as o}from"../../Button/Button.esm.js";import{WizardStateContext as l}from"../WizardStateProvider.esm.js";import{changeCurrentStepNo as a}from"../wizardStateReducer.esm.js";const i=({actions:i})=>{const{state:{mode:s,steps:d,currentStepNo:c},dispatch:m}=t(l),u=((e,t,r)=>n(((e,t)=>()=>e.findIndex(((e,r)=>r>t&&!e.disabled)))(r,t),[e,t,r]))(s,c,d),p=-1!==u,v=((e,t,r)=>n(((e,t)=>()=>{const r=e.length-1-t,n=[...e].reverse().findIndex(((e,t)=>t>r&&!e.disabled));return n>0?e.length-1-n:-1})(r,t),[e,t,r]))(s,c,d),f=-1!==v,C=!p||"edit"===s,k=e=>{"forward"===e?p&&m(a(u)):f&&m(a(v))};return e.createElement(r,null,f&&e.createElement(o,{variant:"outline",onClick:()=>{var e,t;null===(t=(e=i.previous).onClick)||void 0===t||t.call(e),k("backward")}},i.previous.label),p&&e.createElement(o,{variant:"edit"===s?"outline":"fill",onClick:()=>{i.next.onClick(c)&&k("forward")}},i.next.label),C&&e.createElement(o,{onClick:()=>{i.saveAndClose.onClick(c)}},i.saveAndClose.label))};export{i as WizardActions};
|
|
2
2
|
//# sourceMappingURL=WizardActions.esm.js.map
|
package/dist/esm/src/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React, { ComponentPropsWithRef } from "react";
|
|
2
|
+
import { Props as ButtonProps } from "../../../Button/Button";
|
|
2
3
|
export interface Props extends ComponentPropsWithRef<"div"> {
|
|
3
4
|
children?: React.ReactNode;
|
|
4
|
-
onClose
|
|
5
|
+
onClose?: () => void;
|
|
5
6
|
cancelAction?: CancelAction;
|
|
7
|
+
cancelActionsClassName?: string;
|
|
6
8
|
}
|
|
7
9
|
export interface CancelAction {
|
|
8
|
-
label
|
|
9
|
-
|
|
10
|
+
label: string;
|
|
11
|
+
cancelButtonProps?: ButtonProps;
|
|
10
12
|
}
|
|
11
13
|
export declare const BaseModalActions: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -2,12 +2,6 @@ import React from "react";
|
|
|
2
2
|
import { Props as ButtonProps } from "../../Button/Button";
|
|
3
3
|
export interface Props extends React.HTMLProps<HTMLDivElement> {
|
|
4
4
|
actions: {
|
|
5
|
-
cancel: {
|
|
6
|
-
label?: string;
|
|
7
|
-
hide?: boolean;
|
|
8
|
-
onClick?: () => void;
|
|
9
|
-
cancelButtonProps?: ButtonProps;
|
|
10
|
-
};
|
|
11
5
|
previous: {
|
|
12
6
|
label: string;
|
|
13
7
|
onClick: () => void;
|
package/package.json
CHANGED
|
@@ -14,7 +14,13 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import React, {
|
|
17
|
+
import React, {
|
|
18
|
+
ForwardRefRenderFunction,
|
|
19
|
+
ComponentPropsWithRef,
|
|
20
|
+
useEffect,
|
|
21
|
+
useRef,
|
|
22
|
+
ReactElement
|
|
23
|
+
} from "react";
|
|
18
24
|
import { createPortal } from "react-dom";
|
|
19
25
|
import { useGetDomRoot } from "../../../hooks/useGetDomRoot";
|
|
20
26
|
import classes from "./BaseModal.module.scss";
|
|
@@ -101,6 +107,16 @@ const BaseModalComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
|
|
|
101
107
|
|
|
102
108
|
const handleBackdropClick = () => !disableBackdrop && onClose && onClose();
|
|
103
109
|
|
|
110
|
+
const renderChildren = () =>
|
|
111
|
+
React.Children.map(children, child => {
|
|
112
|
+
if (React.isValidElement(child)) {
|
|
113
|
+
return React.cloneElement(child as ReactElement, {
|
|
114
|
+
onClose: child.props.onClose ?? onClose
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return child;
|
|
118
|
+
});
|
|
119
|
+
|
|
104
120
|
return (
|
|
105
121
|
<div ref={wrappingDivRef}>
|
|
106
122
|
{createPortal(
|
|
@@ -133,7 +149,7 @@ const BaseModalComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
|
|
|
133
149
|
style={{ zIndex: zIndex && zIndex + 1 }}
|
|
134
150
|
className={`${classes["container"]} ${containerProps?.className ?? ""}`}
|
|
135
151
|
>
|
|
136
|
-
{
|
|
152
|
+
{renderChildren()}
|
|
137
153
|
</div>
|
|
138
154
|
) : (
|
|
139
155
|
open && (
|
|
@@ -143,7 +159,7 @@ const BaseModalComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
|
|
|
143
159
|
style={{ zIndex: zIndex && zIndex + 1 }}
|
|
144
160
|
className={`${classes["container"]} ${containerProps?.className ?? ""}`}
|
|
145
161
|
>
|
|
146
|
-
{
|
|
162
|
+
{renderChildren()}
|
|
147
163
|
</div>
|
|
148
164
|
)
|
|
149
165
|
)}
|
|
@@ -23,9 +23,7 @@ describe("BaseModalActions", () => {
|
|
|
23
23
|
const children = "Content";
|
|
24
24
|
const classNames = ["class1", "class2"];
|
|
25
25
|
const { container } = render(
|
|
26
|
-
<BaseModalActions
|
|
27
|
-
{children}
|
|
28
|
-
</BaseModalActions>
|
|
26
|
+
<BaseModalActions className={classNames.join(" ")}>{children}</BaseModalActions>
|
|
29
27
|
);
|
|
30
28
|
|
|
31
29
|
const dialogActionsContainer = container.children[0];
|
|
@@ -33,34 +31,21 @@ describe("BaseModalActions", () => {
|
|
|
33
31
|
expect(dialogActionsContainer).toHaveTextContent(children);
|
|
34
32
|
});
|
|
35
33
|
|
|
36
|
-
it("
|
|
37
|
-
const { container } = render(<BaseModalActions
|
|
34
|
+
it("Shouldn't render cancel button if we don't pass label", () => {
|
|
35
|
+
const { container } = render(<BaseModalActions />);
|
|
38
36
|
const dialogActionsContainer = container.children[0];
|
|
39
37
|
expect(dialogActionsContainer).toHaveClass("actions");
|
|
40
|
-
expect(dialogActionsContainer).toHaveTextContent("Cancel");
|
|
38
|
+
expect(dialogActionsContainer).not.toHaveTextContent("Cancel");
|
|
41
39
|
});
|
|
42
40
|
|
|
43
|
-
it("
|
|
44
|
-
const cancelAction = { label: "Close"
|
|
45
|
-
const { container } = render(
|
|
46
|
-
<BaseModalActions onClose={jest.fn()} cancelAction={cancelAction} />
|
|
47
|
-
);
|
|
41
|
+
it("Should render a cancel button with a `Close` label", () => {
|
|
42
|
+
const cancelAction = { label: "Close" };
|
|
43
|
+
const { container } = render(<BaseModalActions cancelAction={cancelAction} />);
|
|
48
44
|
|
|
49
45
|
const dialogActionsContainer = container.children[0];
|
|
50
46
|
expect(dialogActionsContainer).toHaveClass("actions");
|
|
51
47
|
expect(dialogActionsContainer).toHaveTextContent(cancelAction.label);
|
|
52
48
|
});
|
|
53
|
-
|
|
54
|
-
it("Shouldn't render a label because of disabled cancel action", () => {
|
|
55
|
-
const cancelAction = { label: "Close", disable: true };
|
|
56
|
-
const { container } = render(
|
|
57
|
-
<BaseModalActions onClose={jest.fn()} cancelAction={cancelAction} />
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const dialogActionsContainer = container.children[0];
|
|
61
|
-
expect(dialogActionsContainer).toHaveClass("actions");
|
|
62
|
-
expect(dialogActionsContainer).not.toHaveTextContent(cancelAction.label);
|
|
63
|
-
});
|
|
64
49
|
});
|
|
65
50
|
describe("ref should work", () => {
|
|
66
51
|
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
@@ -16,49 +16,49 @@
|
|
|
16
16
|
|
|
17
17
|
import React, { ForwardRefRenderFunction, ComponentPropsWithRef, useRef } from "react";
|
|
18
18
|
import classes from "./BaseModalActions.module.scss";
|
|
19
|
-
import { Button } from "../../../Button/Button";
|
|
19
|
+
import { Button, Props as ButtonProps } from "../../../Button/Button";
|
|
20
20
|
|
|
21
21
|
export interface Props extends ComponentPropsWithRef<"div"> {
|
|
22
22
|
children?: React.ReactNode;
|
|
23
|
-
onClose
|
|
23
|
+
onClose?: () => void;
|
|
24
24
|
cancelAction?: CancelAction;
|
|
25
|
+
cancelActionsClassName?: string;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export interface CancelAction {
|
|
28
|
-
label
|
|
29
|
-
|
|
29
|
+
label: string;
|
|
30
|
+
cancelButtonProps?: ButtonProps;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
const BaseModalActionsComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
|
|
33
|
-
{
|
|
34
|
-
children,
|
|
35
|
-
onClose,
|
|
36
|
-
cancelAction = { label: undefined, disable: false },
|
|
37
|
-
className = "",
|
|
38
|
-
...rest
|
|
39
|
-
}: Props,
|
|
34
|
+
{ children, cancelAction, cancelActionsClassName = "", onClose, className = "", ...rest }: Props,
|
|
40
35
|
ref
|
|
41
36
|
) => {
|
|
42
37
|
const innerRef = (React.createRef() as React.RefObject<HTMLDivElement>) || ref;
|
|
43
38
|
const cancelButtonRef = useRef<HTMLDivElement>(null);
|
|
44
39
|
const primaryActionsRef = useRef<HTMLDivElement>(null);
|
|
45
40
|
|
|
46
|
-
const
|
|
47
|
-
<Button
|
|
48
|
-
{cancelAction?.label
|
|
41
|
+
const cancelButton = (
|
|
42
|
+
<Button variant="text" color="default" {...cancelAction?.cancelButtonProps} onClick={onClose}>
|
|
43
|
+
{cancelAction?.label}
|
|
49
44
|
</Button>
|
|
50
45
|
);
|
|
51
46
|
|
|
52
47
|
return (
|
|
53
48
|
<div {...rest} ref={innerRef} className={`${classes["actions"]} ${className}`}>
|
|
54
|
-
{
|
|
55
|
-
<div
|
|
56
|
-
{
|
|
49
|
+
{cancelAction && (
|
|
50
|
+
<div
|
|
51
|
+
className={`${classes["cancel-action"]} ${cancelActionsClassName}`}
|
|
52
|
+
ref={cancelButtonRef}
|
|
53
|
+
>
|
|
54
|
+
{cancelButton}
|
|
55
|
+
</div>
|
|
56
|
+
)}
|
|
57
|
+
{children && (
|
|
58
|
+
<div ref={primaryActionsRef} className={classes["primary-actions"]}>
|
|
59
|
+
{children}
|
|
57
60
|
</div>
|
|
58
61
|
)}
|
|
59
|
-
<div ref={primaryActionsRef} className={classes["primary-actions"]}>
|
|
60
|
-
{children}
|
|
61
|
-
</div>
|
|
62
62
|
</div>
|
|
63
63
|
);
|
|
64
64
|
};
|
|
@@ -18,4 +18,18 @@
|
|
|
18
18
|
& * + * {
|
|
19
19
|
margin-left: 0.5rem;
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
@media screen and (max-width: 640px) {
|
|
23
|
+
.cancel-action {
|
|
24
|
+
display: block;
|
|
25
|
+
flex-direction: column;
|
|
26
|
+
align-items: flex-end;
|
|
27
|
+
margin-left: 0;
|
|
28
|
+
margin-bottom: 0.5rem;
|
|
29
|
+
|
|
30
|
+
> * {
|
|
31
|
+
width: 100%;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
21
35
|
}
|
|
@@ -33,7 +33,8 @@ const DialogActionsComponent: ForwardRefRenderFunction<HTMLDivElement, Props> =
|
|
|
33
33
|
return (
|
|
34
34
|
<BaseModalActions
|
|
35
35
|
{...rest}
|
|
36
|
-
cancelAction={
|
|
36
|
+
cancelAction={cancelAction}
|
|
37
|
+
cancelActionsClassName={classes["cancel-action"]}
|
|
37
38
|
onClose={onClose}
|
|
38
39
|
ref={ref}
|
|
39
40
|
className={classes["actions"]}
|
|
@@ -56,10 +56,6 @@ const initWizardStepsProps = {
|
|
|
56
56
|
|
|
57
57
|
const initWizardActionsProps: WizardActionProps = {
|
|
58
58
|
actions: {
|
|
59
|
-
cancel: {
|
|
60
|
-
label: "Cancel",
|
|
61
|
-
onClick: jest.fn()
|
|
62
|
-
},
|
|
63
59
|
next: {
|
|
64
60
|
label: "Next",
|
|
65
61
|
onClick: jest.fn()
|
|
@@ -102,9 +98,6 @@ const getStepButtons = (container: HTMLElement) =>
|
|
|
102
98
|
|
|
103
99
|
const getActionsButtons = (container: HTMLElement) => {
|
|
104
100
|
const actionsContainer = getByTestId(container, "wizard-actions");
|
|
105
|
-
const cancel = queryByRole(actionsContainer, "button", {
|
|
106
|
-
name: initWizardActionsProps.actions.cancel.label
|
|
107
|
-
});
|
|
108
101
|
const next = queryByRole(actionsContainer, "button", {
|
|
109
102
|
name: initWizardActionsProps.actions.next.label
|
|
110
103
|
});
|
|
@@ -114,13 +107,13 @@ const getActionsButtons = (container: HTMLElement) => {
|
|
|
114
107
|
const save = queryByRole(actionsContainer, "button", {
|
|
115
108
|
name: initWizardActionsProps.actions.saveAndClose.label
|
|
116
109
|
});
|
|
117
|
-
return {
|
|
110
|
+
return { next, prev, save };
|
|
118
111
|
};
|
|
119
112
|
|
|
120
113
|
describe("Wizard", () => {
|
|
121
114
|
it("renders without crashing", () => {
|
|
122
115
|
const { container } = renderWizard();
|
|
123
|
-
const {
|
|
116
|
+
const { prev, next, save } = getActionsButtons(container);
|
|
124
117
|
const stepButtons = getStepButtons(container);
|
|
125
118
|
const wizardContent = getWizardContent(container);
|
|
126
119
|
|
|
@@ -130,7 +123,6 @@ describe("Wizard", () => {
|
|
|
130
123
|
expect(getByText(stepButtons[2], "3")).toBeDefined();
|
|
131
124
|
expect(getByText(stepButtons[3], "4")).toBeDefined();
|
|
132
125
|
expect(wizardContent).toHaveTextContent("Step 1");
|
|
133
|
-
expect(cancel).toBeDefined();
|
|
134
126
|
expect(next).toBeDefined();
|
|
135
127
|
expect(prev).toBeNull();
|
|
136
128
|
expect(save).toBeNull();
|
|
@@ -151,15 +143,13 @@ describe("Wizard", () => {
|
|
|
151
143
|
await findByText(wizardContent, "Step 2");
|
|
152
144
|
next && (await userEvent.click(next));
|
|
153
145
|
await findByText(wizardContent, "Step 4");
|
|
154
|
-
const { save, prev
|
|
146
|
+
const { save, prev } = getActionsButtons(container);
|
|
155
147
|
save && (await userEvent.click(save));
|
|
156
148
|
expect(initWizardActionsProps.actions.saveAndClose.onClick).toBeCalledWith(3);
|
|
157
149
|
prev && (await userEvent.click(prev));
|
|
158
150
|
await findByText(wizardContent, "Step 2");
|
|
159
151
|
prev && (await userEvent.click(prev));
|
|
160
152
|
await findByText(wizardContent, "Step 1");
|
|
161
|
-
cancel && (await userEvent.click(cancel));
|
|
162
|
-
expect(initWizardActionsProps.actions.cancel.onClick).toBeCalledTimes(1);
|
|
163
153
|
});
|
|
164
154
|
|
|
165
155
|
it("should not be able to click over whole wizard via steps buttons in add mode", async () => {
|
|
@@ -43,10 +43,6 @@ const initWizardState: WizardStateType = {
|
|
|
43
43
|
|
|
44
44
|
const initParams: Props = {
|
|
45
45
|
actions: {
|
|
46
|
-
cancel: {
|
|
47
|
-
label: "Cancel",
|
|
48
|
-
onClick: jest.fn()
|
|
49
|
-
},
|
|
50
46
|
next: {
|
|
51
47
|
label: "Next",
|
|
52
48
|
onClick: jest.fn()
|
|
@@ -89,36 +85,32 @@ const renderWizardActions = (initReducerState?: WizardStateType, props?: Props)
|
|
|
89
85
|
};
|
|
90
86
|
|
|
91
87
|
const getActionsButtons = (container: HTMLElement) => {
|
|
92
|
-
const cancel = queryByRole(container, "button", { name: initParams.actions.cancel.label });
|
|
93
88
|
const next = queryByRole(container, "button", { name: initParams.actions.next.label });
|
|
94
89
|
const prev = queryByRole(container, "button", { name: initParams.actions.previous.label });
|
|
95
90
|
const save = queryByRole(container, "button", { name: initParams.actions.saveAndClose.label });
|
|
96
|
-
return {
|
|
91
|
+
return { next, prev, save };
|
|
97
92
|
};
|
|
98
93
|
|
|
99
94
|
describe("WizardActions", () => {
|
|
100
95
|
it("renders without crashing", async () => {
|
|
101
96
|
const { container, dispatch } = renderWizardActions();
|
|
102
|
-
const {
|
|
97
|
+
const { prev, next, save } = getActionsButtons(container);
|
|
103
98
|
(
|
|
104
99
|
initParams.actions.next.onClick as jest.MockedFunction<typeof initParams.actions.next.onClick>
|
|
105
100
|
).mockReturnValueOnce(true);
|
|
106
101
|
|
|
107
|
-
expect(cancel).toBeDefined();
|
|
108
|
-
cancel && (await userEvent.click(cancel));
|
|
109
102
|
expect(next).toBeDefined();
|
|
110
103
|
next && (await userEvent.click(next));
|
|
111
104
|
expect(prev).toBeNull();
|
|
112
105
|
expect(save).toBeNull();
|
|
113
106
|
|
|
114
|
-
expect(initParams.actions.cancel.onClick).toBeCalledTimes(1);
|
|
115
107
|
expect(initParams.actions.next.onClick).toHaveBeenCalledWith(0);
|
|
116
108
|
expect(dispatch).toBeCalledWith(changeCurrentStepNo(1));
|
|
117
109
|
});
|
|
118
110
|
|
|
119
111
|
it("should allow going prev and forward when there are prev step and next step (next step is disabled but next one can be used)", async () => {
|
|
120
112
|
const { container, dispatch } = renderWizardActions({ ...initWizardState, currentStepNo: 1 });
|
|
121
|
-
const {
|
|
113
|
+
const { prev, next, save } = getActionsButtons(container);
|
|
122
114
|
(
|
|
123
115
|
initParams.actions.next.onClick as jest.MockedFunction<typeof initParams.actions.next.onClick>
|
|
124
116
|
).mockReturnValueOnce(true);
|
|
@@ -133,15 +125,13 @@ describe("WizardActions", () => {
|
|
|
133
125
|
expect(initParams.actions.next.onClick).toHaveBeenCalledWith(1);
|
|
134
126
|
expect(dispatch).toBeCalledWith(changeCurrentStepNo(3));
|
|
135
127
|
|
|
136
|
-
expect(cancel).toBeDefined();
|
|
137
128
|
expect(save).toBeNull();
|
|
138
129
|
});
|
|
139
130
|
|
|
140
131
|
it("should render save button but not next button when current step is the last step", async () => {
|
|
141
132
|
const { container } = renderWizardActions({ ...initWizardState, currentStepNo: 3 });
|
|
142
|
-
const {
|
|
133
|
+
const { prev, next, save } = getActionsButtons(container);
|
|
143
134
|
|
|
144
|
-
expect(cancel).toBeDefined();
|
|
145
135
|
expect(prev).toBeDefined();
|
|
146
136
|
expect(next).toBeNull();
|
|
147
137
|
expect(save).toBeDefined();
|
|
@@ -161,9 +151,8 @@ describe("WizardActions", () => {
|
|
|
161
151
|
steps: steps,
|
|
162
152
|
currentStepNo: 0
|
|
163
153
|
});
|
|
164
|
-
const {
|
|
154
|
+
const { prev, next, save } = getActionsButtons(container);
|
|
165
155
|
|
|
166
|
-
expect(cancel).toBeDefined();
|
|
167
156
|
expect(prev).toBeNull();
|
|
168
157
|
expect(next).toBeNull();
|
|
169
158
|
expect(save).toBeDefined();
|
|
@@ -174,9 +163,8 @@ describe("WizardActions", () => {
|
|
|
174
163
|
|
|
175
164
|
it("should show save button on middle step when mode is `edit`", async () => {
|
|
176
165
|
const { container } = renderWizardActions({ ...initWizardState, mode: "edit" });
|
|
177
|
-
const {
|
|
166
|
+
const { prev, next, save } = getActionsButtons(container);
|
|
178
167
|
|
|
179
|
-
expect(cancel).toBeDefined();
|
|
180
168
|
expect(prev).toBeNull();
|
|
181
169
|
expect(next).toBeDefined();
|
|
182
170
|
expect(save).toBeDefined();
|
|
@@ -23,12 +23,6 @@ import { changeCurrentStepNo } from "../wizardStateReducer";
|
|
|
23
23
|
|
|
24
24
|
export interface Props extends React.HTMLProps<HTMLDivElement> {
|
|
25
25
|
actions: {
|
|
26
|
-
cancel: {
|
|
27
|
-
label?: string;
|
|
28
|
-
hide?: boolean;
|
|
29
|
-
onClick?: () => void;
|
|
30
|
-
cancelButtonProps?: ButtonProps;
|
|
31
|
-
};
|
|
32
26
|
previous: {
|
|
33
27
|
label: string;
|
|
34
28
|
onClick: () => void;
|
|
@@ -101,15 +95,6 @@ export const WizardActions = ({ actions }: Props) => {
|
|
|
101
95
|
|
|
102
96
|
return (
|
|
103
97
|
<Fragment>
|
|
104
|
-
{!actions.cancel.hide && (
|
|
105
|
-
<Button
|
|
106
|
-
variant="text"
|
|
107
|
-
onClick={actions.cancel.onClick}
|
|
108
|
-
{...actions.cancel.cancelButtonProps}
|
|
109
|
-
>
|
|
110
|
-
{actions.cancel.label}
|
|
111
|
-
</Button>
|
|
112
|
-
)}
|
|
113
98
|
{hasPreviousStep && (
|
|
114
99
|
<Button variant="outline" onClick={onPreviousWrapper}>
|
|
115
100
|
{actions.previous.label}
|