@manuscripts/style-guide 3.8.3 → 3.8.4
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/components/Dialog.js +4 -2
- package/dist/cjs/components/StyledModal.js +28 -10
- package/dist/es/components/Dialog.js +5 -3
- package/dist/es/components/StyledModal.js +29 -11
- package/dist/types/components/Dialog.d.ts +3 -0
- package/dist/types/components/StyledModal.d.ts +2 -2
- package/package.json +1 -1
|
@@ -107,6 +107,7 @@ class Dialog extends react_1.default.Component {
|
|
|
107
107
|
this.state = {
|
|
108
108
|
primaryActionDisabled: true,
|
|
109
109
|
};
|
|
110
|
+
this.Parent = this.props.portaled ? StyledModal_1.StyledModal : StyledModal_1.StyledModalContent;
|
|
110
111
|
this.renderButtons = (props, disabled) => ((0, jsx_runtime_1.jsx)(ButtonsContainer, { children: props.actions.secondary ? (!props.actions.primary.isDestructive ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SecondaryAction, { action: props.actions.secondary.action, hasForm: !!this.props.confirmFieldText, title: props.actions.secondary.title, variant: props.actions.secondary.variant ?? 'default' }), (0, jsx_runtime_1.jsx)(PrimaryAction, { action: props.actions.primary.action, disabled: disabled, title: props.actions.primary.title || 'Dismiss' })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(PrimaryAction, { action: props.actions.primary.action, disabled: disabled, isDestructive: true, hasForm: !!this.props.confirmFieldText, title: props.actions.primary.title || 'Dismiss' }), (0, jsx_runtime_1.jsx)(SecondaryAction, { action: props.actions.secondary.action, title: props.actions.secondary.title, variant: props.actions.secondary.variant ?? 'default' })] }))) : ((0, jsx_runtime_1.jsx)(PrimaryAction, { action: props.actions.primary.action, disabled: disabled, isDestructive: props.actions.primary.isDestructive, hasForm: !!this.props.confirmFieldText, title: props.actions.primary.title || 'Dismiss' })) }));
|
|
111
112
|
this.checkInputValue = (event) => {
|
|
112
113
|
const testingVal = this.props.confirmFieldText && this.props.confirmFieldText.toUpperCase();
|
|
@@ -129,9 +130,10 @@ class Dialog extends react_1.default.Component {
|
|
|
129
130
|
this.setDisabledBtnState(!!this.props.confirmFieldText);
|
|
130
131
|
}
|
|
131
132
|
render() {
|
|
132
|
-
const { actions, isOpen, header, message, category, children, confirmFieldText, className, } = this.props;
|
|
133
|
+
const { actions, isOpen, header, message, category, children, confirmFieldText, className, onExited } = this.props;
|
|
133
134
|
const { primaryActionDisabled } = this.state;
|
|
134
|
-
|
|
135
|
+
const { Parent } = this;
|
|
136
|
+
return ((0, jsx_runtime_1.jsx)(Parent, { isOpen: isOpen, onRequestClose: actions.onClose, shouldCloseOnOverlayClick: true, className: className, onExited: onExited, children: (0, jsx_runtime_1.jsxs)(exports.DialogModalBody, { children: [(0, jsx_runtime_1.jsxs)(HeaderContainer, { children: [category === Category.error && ((0, jsx_runtime_1.jsx)(Icon, { children: (0, jsx_runtime_1.jsx)(icons_1.AttentionRedIcon, {}) })), category === Category.warning && ((0, jsx_runtime_1.jsx)(Icon, { children: (0, jsx_runtime_1.jsx)(icons_1.AttentionOrangeIcon, {}) })), category === Category.success && ((0, jsx_runtime_1.jsx)(Icon, { children: (0, jsx_runtime_1.jsx)(icons_1.AttentionGreenIcon, {}) })), header] }), (0, jsx_runtime_1.jsxs)(exports.MessageContainer, { children: [message, confirmFieldText && ((0, jsx_runtime_1.jsx)("form", { id: "formDialog", onSubmit: this.handleSubmit, children: (0, jsx_runtime_1.jsx)(ConfirmationTextField, { autoFocus: true, onChange: this.checkInputValue, placeholder: 'Please type: ' + confirmFieldText, required: true }) })), children] }), this.renderButtons(this.props, primaryActionDisabled)] }) }));
|
|
135
137
|
}
|
|
136
138
|
}
|
|
137
139
|
exports.Dialog = Dialog;
|
|
@@ -40,12 +40,18 @@ const react_dom_1 = require("react-dom");
|
|
|
40
40
|
const styled_components_1 = __importStar(require("styled-components"));
|
|
41
41
|
const Button_1 = require("./Button");
|
|
42
42
|
const Sidebar_1 = require("./Sidebar");
|
|
43
|
-
const StyledModalContent = ({ isOpen, onRequestClose, shouldCloseOnOverlayClick = true, hideOverlay = false, pointerEventsOnBackdrop, children, className, style, ariaLabelledby, id, }) => {
|
|
43
|
+
const StyledModalContent = ({ isOpen, onRequestClose, shouldCloseOnOverlayClick = true, hideOverlay = false, pointerEventsOnBackdrop, children, className, style, ariaLabelledby, id, onExited, }) => {
|
|
44
44
|
const dialogRef = (0, react_1.useRef)(null);
|
|
45
45
|
const closedByCancelRef = (0, react_1.useRef)(false);
|
|
46
|
+
const [visible, setVisible] = (0, react_1.useState)(false);
|
|
47
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
48
|
+
if (isOpen) {
|
|
49
|
+
setVisible(true);
|
|
50
|
+
}
|
|
51
|
+
}, [isOpen]);
|
|
46
52
|
(0, react_1.useEffect)(() => {
|
|
47
53
|
const dialog = dialogRef.current;
|
|
48
|
-
if (!dialog) {
|
|
54
|
+
if (!dialog || !visible) {
|
|
49
55
|
return;
|
|
50
56
|
}
|
|
51
57
|
if (isOpen && !dialog.open) {
|
|
@@ -57,9 +63,14 @@ const StyledModalContent = ({ isOpen, onRequestClose, shouldCloseOnOverlayClick
|
|
|
57
63
|
}
|
|
58
64
|
}
|
|
59
65
|
else if (!isOpen && dialog.open) {
|
|
66
|
+
const timeout = setTimeout(() => {
|
|
67
|
+
setVisible(false);
|
|
68
|
+
onExited?.();
|
|
69
|
+
}, TRANSITION_TIME + 50);
|
|
60
70
|
dialog.close();
|
|
71
|
+
return () => clearTimeout(timeout);
|
|
61
72
|
}
|
|
62
|
-
}, [isOpen]);
|
|
73
|
+
}, [isOpen, setVisible, visible]);
|
|
63
74
|
(0, react_1.useEffect)(() => {
|
|
64
75
|
const dialog = dialogRef.current;
|
|
65
76
|
if (!dialog) {
|
|
@@ -71,7 +82,10 @@ const StyledModalContent = ({ isOpen, onRequestClose, shouldCloseOnOverlayClick
|
|
|
71
82
|
}
|
|
72
83
|
closedByCancelRef.current = false;
|
|
73
84
|
};
|
|
74
|
-
const listener = () =>
|
|
85
|
+
const listener = (e) => {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
handleNativeClose(isOpen);
|
|
88
|
+
};
|
|
75
89
|
dialog.addEventListener('close', listener);
|
|
76
90
|
return () => dialog.removeEventListener('close', listener);
|
|
77
91
|
}, [isOpen, onRequestClose]);
|
|
@@ -92,6 +106,9 @@ const StyledModalContent = ({ isOpen, onRequestClose, shouldCloseOnOverlayClick
|
|
|
92
106
|
onRequestClose?.();
|
|
93
107
|
}
|
|
94
108
|
};
|
|
109
|
+
if (!visible) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
95
112
|
return ((0, jsx_runtime_1.jsx)(Dialog, { ref: dialogRef, onClick: (e) => {
|
|
96
113
|
e.stopPropagation();
|
|
97
114
|
handleBackdropClick(e);
|
|
@@ -102,6 +119,7 @@ const StyledModal = (props) => {
|
|
|
102
119
|
return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)(exports.StyledModalContent, { ...props }), document.body);
|
|
103
120
|
};
|
|
104
121
|
exports.StyledModal = StyledModal;
|
|
122
|
+
const TRANSITION_TIME = 500;
|
|
105
123
|
const Dialog = styled_components_1.default.dialog `
|
|
106
124
|
background: transparent;
|
|
107
125
|
border: none;
|
|
@@ -112,9 +130,9 @@ const Dialog = styled_components_1.default.dialog `
|
|
|
112
130
|
z-index: 100;
|
|
113
131
|
opacity: 1;
|
|
114
132
|
transition:
|
|
115
|
-
opacity
|
|
116
|
-
display
|
|
117
|
-
overlay
|
|
133
|
+
opacity ${TRANSITION_TIME}ms ease-in-out,
|
|
134
|
+
display ${TRANSITION_TIME}ms ease allow-discrete,
|
|
135
|
+
overlay ${TRANSITION_TIME}ms ease allow-discrete;
|
|
118
136
|
|
|
119
137
|
&:not([open]) {
|
|
120
138
|
opacity: 0;
|
|
@@ -145,9 +163,9 @@ const Dialog = styled_components_1.default.dialog `
|
|
|
145
163
|
opacity: 1;
|
|
146
164
|
pointer-events: ${(props) => props.$pointerEventsOnBackdrop || 'auto'};
|
|
147
165
|
transition:
|
|
148
|
-
opacity
|
|
149
|
-
display
|
|
150
|
-
overlay
|
|
166
|
+
opacity ${TRANSITION_TIME}ms ease-in-out,
|
|
167
|
+
display ${TRANSITION_TIME}ms ease allow-discrete,
|
|
168
|
+
overlay ${TRANSITION_TIME}ms ease allow-discrete;
|
|
151
169
|
}
|
|
152
170
|
|
|
153
171
|
&:not([open])::backdrop {
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import styled from 'styled-components';
|
|
4
4
|
import { ButtonGroup, PrimaryButton, SecondaryButton } from './Button';
|
|
5
5
|
import { AttentionGreenIcon, AttentionOrangeIcon, AttentionRedIcon, } from './icons';
|
|
6
|
-
import { StyledModal } from './StyledModal';
|
|
6
|
+
import { StyledModal, StyledModalContent } from './StyledModal';
|
|
7
7
|
import { TextField } from './TextField';
|
|
8
8
|
const Icon = styled.div `
|
|
9
9
|
margin-right: 6px;
|
|
@@ -101,6 +101,7 @@ export class Dialog extends React.Component {
|
|
|
101
101
|
this.state = {
|
|
102
102
|
primaryActionDisabled: true,
|
|
103
103
|
};
|
|
104
|
+
this.Parent = this.props.portaled ? StyledModal : StyledModalContent;
|
|
104
105
|
this.renderButtons = (props, disabled) => (_jsx(ButtonsContainer, { children: props.actions.secondary ? (!props.actions.primary.isDestructive ? (_jsxs(_Fragment, { children: [_jsx(SecondaryAction, { action: props.actions.secondary.action, hasForm: !!this.props.confirmFieldText, title: props.actions.secondary.title, variant: props.actions.secondary.variant ?? 'default' }), _jsx(PrimaryAction, { action: props.actions.primary.action, disabled: disabled, title: props.actions.primary.title || 'Dismiss' })] })) : (_jsxs(_Fragment, { children: [_jsx(PrimaryAction, { action: props.actions.primary.action, disabled: disabled, isDestructive: true, hasForm: !!this.props.confirmFieldText, title: props.actions.primary.title || 'Dismiss' }), _jsx(SecondaryAction, { action: props.actions.secondary.action, title: props.actions.secondary.title, variant: props.actions.secondary.variant ?? 'default' })] }))) : (_jsx(PrimaryAction, { action: props.actions.primary.action, disabled: disabled, isDestructive: props.actions.primary.isDestructive, hasForm: !!this.props.confirmFieldText, title: props.actions.primary.title || 'Dismiss' })) }));
|
|
105
106
|
this.checkInputValue = (event) => {
|
|
106
107
|
const testingVal = this.props.confirmFieldText && this.props.confirmFieldText.toUpperCase();
|
|
@@ -123,8 +124,9 @@ export class Dialog extends React.Component {
|
|
|
123
124
|
this.setDisabledBtnState(!!this.props.confirmFieldText);
|
|
124
125
|
}
|
|
125
126
|
render() {
|
|
126
|
-
const { actions, isOpen, header, message, category, children, confirmFieldText, className, } = this.props;
|
|
127
|
+
const { actions, isOpen, header, message, category, children, confirmFieldText, className, onExited } = this.props;
|
|
127
128
|
const { primaryActionDisabled } = this.state;
|
|
128
|
-
|
|
129
|
+
const { Parent } = this;
|
|
130
|
+
return (_jsx(Parent, { isOpen: isOpen, onRequestClose: actions.onClose, shouldCloseOnOverlayClick: true, className: className, onExited: onExited, children: _jsxs(DialogModalBody, { children: [_jsxs(HeaderContainer, { children: [category === Category.error && (_jsx(Icon, { children: _jsx(AttentionRedIcon, {}) })), category === Category.warning && (_jsx(Icon, { children: _jsx(AttentionOrangeIcon, {}) })), category === Category.success && (_jsx(Icon, { children: _jsx(AttentionGreenIcon, {}) })), header] }), _jsxs(MessageContainer, { children: [message, confirmFieldText && (_jsx("form", { id: "formDialog", onSubmit: this.handleSubmit, children: _jsx(ConfirmationTextField, { autoFocus: true, onChange: this.checkInputValue, placeholder: 'Please type: ' + confirmFieldText, required: true }) })), children] }), this.renderButtons(this.props, primaryActionDisabled)] }) }));
|
|
129
131
|
}
|
|
130
132
|
}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef, useState, } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import styled, { css } from 'styled-components';
|
|
5
5
|
import { RoundIconButton } from './Button';
|
|
6
6
|
import { SidebarStyles } from './Sidebar';
|
|
7
|
-
export const StyledModalContent = ({ isOpen, onRequestClose, shouldCloseOnOverlayClick = true, hideOverlay = false, pointerEventsOnBackdrop, children, className, style, ariaLabelledby, id, }) => {
|
|
7
|
+
export const StyledModalContent = ({ isOpen, onRequestClose, shouldCloseOnOverlayClick = true, hideOverlay = false, pointerEventsOnBackdrop, children, className, style, ariaLabelledby, id, onExited, }) => {
|
|
8
8
|
const dialogRef = useRef(null);
|
|
9
9
|
const closedByCancelRef = useRef(false);
|
|
10
|
+
const [visible, setVisible] = useState(false);
|
|
11
|
+
useLayoutEffect(() => {
|
|
12
|
+
if (isOpen) {
|
|
13
|
+
setVisible(true);
|
|
14
|
+
}
|
|
15
|
+
}, [isOpen]);
|
|
10
16
|
useEffect(() => {
|
|
11
17
|
const dialog = dialogRef.current;
|
|
12
|
-
if (!dialog) {
|
|
18
|
+
if (!dialog || !visible) {
|
|
13
19
|
return;
|
|
14
20
|
}
|
|
15
21
|
if (isOpen && !dialog.open) {
|
|
@@ -21,9 +27,14 @@ export const StyledModalContent = ({ isOpen, onRequestClose, shouldCloseOnOverla
|
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
else if (!isOpen && dialog.open) {
|
|
30
|
+
const timeout = setTimeout(() => {
|
|
31
|
+
setVisible(false);
|
|
32
|
+
onExited?.();
|
|
33
|
+
}, TRANSITION_TIME + 50);
|
|
24
34
|
dialog.close();
|
|
35
|
+
return () => clearTimeout(timeout);
|
|
25
36
|
}
|
|
26
|
-
}, [isOpen]);
|
|
37
|
+
}, [isOpen, setVisible, visible]);
|
|
27
38
|
useEffect(() => {
|
|
28
39
|
const dialog = dialogRef.current;
|
|
29
40
|
if (!dialog) {
|
|
@@ -35,7 +46,10 @@ export const StyledModalContent = ({ isOpen, onRequestClose, shouldCloseOnOverla
|
|
|
35
46
|
}
|
|
36
47
|
closedByCancelRef.current = false;
|
|
37
48
|
};
|
|
38
|
-
const listener = () =>
|
|
49
|
+
const listener = (e) => {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
handleNativeClose(isOpen);
|
|
52
|
+
};
|
|
39
53
|
dialog.addEventListener('close', listener);
|
|
40
54
|
return () => dialog.removeEventListener('close', listener);
|
|
41
55
|
}, [isOpen, onRequestClose]);
|
|
@@ -56,6 +70,9 @@ export const StyledModalContent = ({ isOpen, onRequestClose, shouldCloseOnOverla
|
|
|
56
70
|
onRequestClose?.();
|
|
57
71
|
}
|
|
58
72
|
};
|
|
73
|
+
if (!visible) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
59
76
|
return (_jsx(Dialog, { ref: dialogRef, onClick: (e) => {
|
|
60
77
|
e.stopPropagation();
|
|
61
78
|
handleBackdropClick(e);
|
|
@@ -64,6 +81,7 @@ export const StyledModalContent = ({ isOpen, onRequestClose, shouldCloseOnOverla
|
|
|
64
81
|
export const StyledModal = (props) => {
|
|
65
82
|
return createPortal(_jsx(StyledModalContent, { ...props }), document.body);
|
|
66
83
|
};
|
|
84
|
+
const TRANSITION_TIME = 500;
|
|
67
85
|
const Dialog = styled.dialog `
|
|
68
86
|
background: transparent;
|
|
69
87
|
border: none;
|
|
@@ -74,9 +92,9 @@ const Dialog = styled.dialog `
|
|
|
74
92
|
z-index: 100;
|
|
75
93
|
opacity: 1;
|
|
76
94
|
transition:
|
|
77
|
-
opacity
|
|
78
|
-
display
|
|
79
|
-
overlay
|
|
95
|
+
opacity ${TRANSITION_TIME}ms ease-in-out,
|
|
96
|
+
display ${TRANSITION_TIME}ms ease allow-discrete,
|
|
97
|
+
overlay ${TRANSITION_TIME}ms ease allow-discrete;
|
|
80
98
|
|
|
81
99
|
&:not([open]) {
|
|
82
100
|
opacity: 0;
|
|
@@ -107,9 +125,9 @@ const Dialog = styled.dialog `
|
|
|
107
125
|
opacity: 1;
|
|
108
126
|
pointer-events: ${(props) => props.$pointerEventsOnBackdrop || 'auto'};
|
|
109
127
|
transition:
|
|
110
|
-
opacity
|
|
111
|
-
display
|
|
112
|
-
overlay
|
|
128
|
+
opacity ${TRANSITION_TIME}ms ease-in-out,
|
|
129
|
+
display ${TRANSITION_TIME}ms ease allow-discrete,
|
|
130
|
+
overlay ${TRANSITION_TIME}ms ease allow-discrete;
|
|
113
131
|
}
|
|
114
132
|
|
|
115
133
|
&:not([open])::backdrop {
|
|
@@ -40,6 +40,8 @@ interface DialogProps {
|
|
|
40
40
|
message: string | React.ReactElement;
|
|
41
41
|
className?: string;
|
|
42
42
|
children?: React.ReactNode;
|
|
43
|
+
portaled?: boolean;
|
|
44
|
+
onExited?: () => void;
|
|
43
45
|
}
|
|
44
46
|
export declare enum Category {
|
|
45
47
|
error = "error",
|
|
@@ -50,6 +52,7 @@ export declare enum Category {
|
|
|
50
52
|
export declare class Dialog extends React.Component<DialogProps, DialogState> {
|
|
51
53
|
state: DialogState;
|
|
52
54
|
componentDidMount(): void;
|
|
55
|
+
Parent: React.FC<import("./StyledModal").StyledModalProps>;
|
|
53
56
|
render(): React.JSX.Element;
|
|
54
57
|
private renderButtons;
|
|
55
58
|
private checkInputValue;
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import React from 'react';
|
|
17
|
-
interface StyledModalProps {
|
|
17
|
+
export interface StyledModalProps {
|
|
18
18
|
isOpen: boolean;
|
|
19
19
|
onRequestClose?: (e?: Event) => void;
|
|
20
|
+
onExited?: () => void;
|
|
20
21
|
shouldCloseOnOverlayClick?: boolean;
|
|
21
22
|
hideOverlay?: boolean;
|
|
22
23
|
pointerEventsOnBackdrop?: 'all' | 'none' | 'auto';
|
|
@@ -549,4 +550,3 @@ export declare const ModalCardBody: import("styled-components/dist/types").IStyl
|
|
|
549
550
|
$width?: number | string;
|
|
550
551
|
}, never>>> & string;
|
|
551
552
|
export declare const ModalTitle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, never> & Partial<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, never>>> & string;
|
|
552
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/style-guide",
|
|
3
3
|
"description": "Shared components for Manuscripts applications",
|
|
4
|
-
"version": "3.8.
|
|
4
|
+
"version": "3.8.4",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-style-guide",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|