@newtonschool/grauity 0.1.10 → 1.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/README.md +7 -0
- package/dist/fonts/grauity-icons.eot +0 -0
- package/dist/fonts/grauity-icons.ttf +0 -0
- package/dist/fonts/grauity-icons.woff +0 -0
- package/dist/fonts/grauity-icons.woff2 +0 -0
- package/dist/index.d.ts +280 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/main.cjs +1 -1
- package/dist/main.cjs.map +1 -1
- package/dist/main.css +1 -1
- package/dist/main.css.map +1 -1
- package/dist/module.css +1 -1
- package/dist/module.css.map +1 -1
- package/dist/module.mjs +1 -1
- package/dist/module.mjs.map +1 -1
- package/dist/stories/elements/MultiSelectDropdown/index.stories.d.ts +11 -0
- package/dist/stories/elements/MultiSelectDropdown/index.stories.d.ts.map +1 -0
- package/dist/stories/elements/SelectDropdown/index.stories.d.ts +11 -0
- package/dist/stories/elements/SelectDropdown/index.stories.d.ts.map +1 -0
- package/dist/ui/core/icons/iconTags.d.ts +279 -28
- package/dist/ui/core/icons/iconTags.d.ts.map +1 -1
- package/dist/ui/core/icons/iconTypes.d.ts +281 -30
- package/dist/ui/core/icons/iconTypes.d.ts.map +1 -1
- package/dist/ui/elements/Button/Button.d.ts.map +1 -1
- package/dist/ui/elements/Icon/Icon.styles.d.ts.map +1 -1
- package/dist/ui/elements/MultiSelectDropdown/DropdownListItem.d.ts +4 -0
- package/dist/ui/elements/MultiSelectDropdown/DropdownListItem.d.ts.map +1 -0
- package/dist/ui/elements/MultiSelectDropdown/MultiSelectDropdown.d.ts +5 -0
- package/dist/ui/elements/MultiSelectDropdown/MultiSelectDropdown.d.ts.map +1 -0
- package/dist/ui/elements/MultiSelectDropdown/MultiSelectDropdown.styles.d.ts +14 -0
- package/dist/ui/elements/MultiSelectDropdown/MultiSelectDropdown.styles.d.ts.map +1 -0
- package/dist/ui/elements/MultiSelectDropdown/MultiSelectDropdown.test.d.ts +2 -0
- package/dist/ui/elements/MultiSelectDropdown/MultiSelectDropdown.test.d.ts.map +1 -0
- package/dist/ui/elements/MultiSelectDropdown/index.d.ts +3 -0
- package/dist/ui/elements/MultiSelectDropdown/index.d.ts.map +1 -0
- package/dist/ui/elements/MultiSelectDropdown/types.d.ts +70 -0
- package/dist/ui/elements/MultiSelectDropdown/types.d.ts.map +1 -0
- package/dist/ui/elements/SelectDropdown/SelectDropdown.d.ts +5 -0
- package/dist/ui/elements/SelectDropdown/SelectDropdown.d.ts.map +1 -0
- package/dist/ui/elements/SelectDropdown/SelectDropdown.styles.d.ts +10 -0
- package/dist/ui/elements/SelectDropdown/SelectDropdown.styles.d.ts.map +1 -0
- package/dist/ui/elements/SelectDropdown/SelectDropdown.test.d.ts +2 -0
- package/dist/ui/elements/SelectDropdown/SelectDropdown.test.d.ts.map +1 -0
- package/dist/ui/elements/SelectDropdown/index.d.ts +3 -0
- package/dist/ui/elements/SelectDropdown/index.d.ts.map +1 -0
- package/dist/ui/elements/SelectDropdown/types.d.ts +59 -0
- package/dist/ui/elements/SelectDropdown/types.d.ts.map +1 -0
- package/package.json +7 -2
- package/ui/.gitkeep +0 -0
- package/ui/README.md +0 -3
- package/ui/core/README.md +0 -4
- package/ui/core/colors/colorTypes.ts +0 -3
- package/ui/core/colors/index.ts +0 -25
- package/ui/core/icons/iconTags.ts +0 -596
- package/ui/core/icons/iconTypes.ts +0 -435
- package/ui/core/icons/index.ts +0 -3
- package/ui/core/index.ts +0 -14
- package/ui/core/miscellaneous-choices/index.ts +0 -24
- package/ui/core/miscellaneous-choices/miscellaneousTypes.ts +0 -3
- package/ui/core/sizes/index.ts +0 -29
- package/ui/core/sizes/sizeTypes.ts +0 -26
- package/ui/css/animations.scss +0 -8
- package/ui/css/fonts.scss +0 -9
- package/ui/css/index.scss +0 -3
- package/ui/css/reset.scss +0 -512
- package/ui/elements/Alert/Alert.styles.ts +0 -66
- package/ui/elements/Alert/Alert.test.tsx +0 -81
- package/ui/elements/Alert/Alert.tsx +0 -153
- package/ui/elements/Alert/constants.ts +0 -169
- package/ui/elements/Alert/index.ts +0 -6
- package/ui/elements/Alert/types.ts +0 -150
- package/ui/elements/Alert/utils.ts +0 -0
- package/ui/elements/AlertBanner/AlertBanner.styles.ts +0 -35
- package/ui/elements/AlertBanner/AlertBanner.test.tsx +0 -70
- package/ui/elements/AlertBanner/AlertBanner.tsx +0 -137
- package/ui/elements/AlertBanner/constants.ts +0 -179
- package/ui/elements/AlertBanner/index.ts +0 -6
- package/ui/elements/AlertBanner/types.ts +0 -133
- package/ui/elements/AlertBanner/utils.ts +0 -52
- package/ui/elements/Button/Button.styles.ts +0 -88
- package/ui/elements/Button/Button.test.tsx +0 -78
- package/ui/elements/Button/Button.tsx +0 -134
- package/ui/elements/Button/ButtonGroup.styles.ts +0 -7
- package/ui/elements/Button/ButtonGroup.tsx +0 -21
- package/ui/elements/Button/IconButton.test.tsx +0 -39
- package/ui/elements/Button/IconButton.tsx +0 -118
- package/ui/elements/Button/constants.ts +0 -304
- package/ui/elements/Button/index.ts +0 -8
- package/ui/elements/Button/types.ts +0 -282
- package/ui/elements/Button/utils.ts +0 -0
- package/ui/elements/Icon/Icon.styles.ts +0 -98
- package/ui/elements/Icon/Icon.tsx +0 -139
- package/ui/elements/Icon/index.ts +0 -2
- package/ui/elements/Icon/types.ts +0 -96
- package/ui/elements/Modal/ConfirmationDialog/index.test.tsx +0 -116
- package/ui/elements/Modal/ConfirmationDialog/index.tsx +0 -151
- package/ui/elements/Modal/Modal.styles.ts +0 -230
- package/ui/elements/Modal/Modal.test.tsx +0 -117
- package/ui/elements/Modal/Modal.tsx +0 -179
- package/ui/elements/Modal/MultiStepModal/index.test.tsx +0 -116
- package/ui/elements/Modal/MultiStepModal/index.tsx +0 -184
- package/ui/elements/Modal/constants.ts +0 -0
- package/ui/elements/Modal/index.ts +0 -4
- package/ui/elements/Modal/types.ts +0 -379
- package/ui/elements/Modal/utils.tsx +0 -0
- package/ui/elements/Table/Table.styles.ts +0 -178
- package/ui/elements/Table/Table.test.tsx +0 -72
- package/ui/elements/Table/Table.tsx +0 -118
- package/ui/elements/Table/constants.ts +0 -0
- package/ui/elements/Table/index.ts +0 -2
- package/ui/elements/Table/types.ts +0 -270
- package/ui/elements/Table/utils.ts +0 -0
- package/ui/elements/Typography/Typography.styles.ts +0 -29
- package/ui/elements/Typography/Typography.tsx +0 -70
- package/ui/elements/Typography/constants.ts +0 -292
- package/ui/elements/Typography/index.ts +0 -9
- package/ui/elements/Typography/types.ts +0 -116
- package/ui/elements/Typography/utils.ts +0 -11
- package/ui/fonts/Switzer-Variable.ttf +0 -0
- package/ui/fonts/grauity-icons.eot +0 -0
- package/ui/fonts/grauity-icons.ttf +0 -0
- package/ui/fonts/grauity-icons.woff +0 -0
- package/ui/fonts/grauity-icons.woff2 +0 -0
- package/ui/helpers/README.md +0 -3
- package/ui/helpers/classNameBuilders.ts +0 -48
- package/ui/helpers/index.ts +0 -7
- package/ui/index.ts +0 -48
- package/ui/init/GrauityInit.tsx +0 -85
- package/ui/init/index.ts +0 -2
- package/ui/themes/GlobalStyle.ts +0 -273
- package/ui/themes/ThemeContext.tsx +0 -140
- package/ui/themes/constants.ts +0 -8
- package/ui/themes/darkThemeConstants.ts +0 -73
- package/ui/themes/lightThemeConstants.ts +0 -73
- package/ui/themes/tokens.ts +0 -0
- package/ui/themes/types.ts +0 -77
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import PropTypes from 'prop-types';
|
|
2
|
-
import React, { forwardRef, useId, useImperativeHandle, useRef } from 'react';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
useClickAway,
|
|
6
|
-
useDisableBodyScroll,
|
|
7
|
-
useKeyboardEvent,
|
|
8
|
-
} from '../../../hooks';
|
|
9
|
-
import { IconButton } from '../Button';
|
|
10
|
-
import {
|
|
11
|
-
StyledModal,
|
|
12
|
-
StyledModalAction,
|
|
13
|
-
StyledModalBanner,
|
|
14
|
-
StyledModalBody,
|
|
15
|
-
StyledModalDescription,
|
|
16
|
-
StyledModalDivider,
|
|
17
|
-
StyledModalMain,
|
|
18
|
-
StyledModalTitle,
|
|
19
|
-
StyledModalWrapper,
|
|
20
|
-
} from './Modal.styles';
|
|
21
|
-
import { ModalProps } from './types';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* A modal is used to display content that temporarily blocks
|
|
25
|
-
* interactions with the main view of a site or to get user attention
|
|
26
|
-
* on a specific action or information.
|
|
27
|
-
*/
|
|
28
|
-
const Modal = forwardRef<HTMLDivElement, ModalProps>((props, ref) => {
|
|
29
|
-
const {
|
|
30
|
-
banner,
|
|
31
|
-
title,
|
|
32
|
-
description,
|
|
33
|
-
body,
|
|
34
|
-
action,
|
|
35
|
-
width,
|
|
36
|
-
height,
|
|
37
|
-
minHeight,
|
|
38
|
-
onHide,
|
|
39
|
-
mobileBottomFullWidth,
|
|
40
|
-
modalPadding,
|
|
41
|
-
modalBodyMargin,
|
|
42
|
-
showCloseButton,
|
|
43
|
-
hideOnClickAway,
|
|
44
|
-
blurBackground,
|
|
45
|
-
} = props;
|
|
46
|
-
const modalRef = useRef<HTMLDivElement>(null);
|
|
47
|
-
|
|
48
|
-
useImperativeHandle(ref, () => modalRef.current);
|
|
49
|
-
|
|
50
|
-
useDisableBodyScroll();
|
|
51
|
-
|
|
52
|
-
useKeyboardEvent(() => {
|
|
53
|
-
if (hideOnClickAway) {
|
|
54
|
-
onHide();
|
|
55
|
-
}
|
|
56
|
-
}, ['Escape']);
|
|
57
|
-
|
|
58
|
-
useClickAway(modalRef, () => {
|
|
59
|
-
if (hideOnClickAway) {
|
|
60
|
-
onHide();
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const id = useId();
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<StyledModalWrapper blurBackground={blurBackground} data-testid="testid-modalwrapper">
|
|
68
|
-
<StyledModal
|
|
69
|
-
onClick={(e: Event) => e.stopPropagation()}
|
|
70
|
-
ref={modalRef}
|
|
71
|
-
width={width}
|
|
72
|
-
height={height}
|
|
73
|
-
minHeight={minHeight}
|
|
74
|
-
mobileBottomFullWidth={mobileBottomFullWidth}
|
|
75
|
-
modalPadding={modalPadding}
|
|
76
|
-
aria-labelledby={`modal-title-${id}`}
|
|
77
|
-
aria-describedby={`modal-description-${id}`}
|
|
78
|
-
aria-modal="true"
|
|
79
|
-
role="dialog"
|
|
80
|
-
data-testid="testid-modal"
|
|
81
|
-
>
|
|
82
|
-
<StyledModalMain>
|
|
83
|
-
{showCloseButton && (
|
|
84
|
-
<StyledModalAction justifyContent="end">
|
|
85
|
-
<IconButton
|
|
86
|
-
onClick={onHide}
|
|
87
|
-
variant="secondary-outlined"
|
|
88
|
-
icon="close"
|
|
89
|
-
ariaLabel="Close"
|
|
90
|
-
/>
|
|
91
|
-
</StyledModalAction>
|
|
92
|
-
)}
|
|
93
|
-
|
|
94
|
-
{banner && <StyledModalBanner>{banner}</StyledModalBanner>}
|
|
95
|
-
|
|
96
|
-
{title && (
|
|
97
|
-
<StyledModalTitle id={`modal-title-${id}`}>
|
|
98
|
-
{title}
|
|
99
|
-
</StyledModalTitle>
|
|
100
|
-
)}
|
|
101
|
-
|
|
102
|
-
{description && (
|
|
103
|
-
<StyledModalDescription id={`modal-description-${id}`}>
|
|
104
|
-
{description}
|
|
105
|
-
</StyledModalDescription>
|
|
106
|
-
)}
|
|
107
|
-
|
|
108
|
-
{body && (
|
|
109
|
-
<StyledModalBody modalBodyMargin={modalBodyMargin}>
|
|
110
|
-
{body}
|
|
111
|
-
</StyledModalBody>
|
|
112
|
-
)}
|
|
113
|
-
</StyledModalMain>
|
|
114
|
-
|
|
115
|
-
{action && <StyledModalAction>{action}</StyledModalAction>}
|
|
116
|
-
</StyledModal>
|
|
117
|
-
</StyledModalWrapper>
|
|
118
|
-
);
|
|
119
|
-
}) as React.ForwardRefExoticComponent<
|
|
120
|
-
ModalProps & React.RefAttributes<HTMLDivElement>
|
|
121
|
-
> & {
|
|
122
|
-
Wrapper: typeof StyledModalWrapper;
|
|
123
|
-
Modal: typeof StyledModal;
|
|
124
|
-
Main: typeof StyledModalMain;
|
|
125
|
-
Banner: typeof StyledModalBanner;
|
|
126
|
-
Title: typeof StyledModalTitle;
|
|
127
|
-
Description: typeof StyledModalDescription;
|
|
128
|
-
Body: typeof StyledModalBody;
|
|
129
|
-
Action: typeof StyledModalAction;
|
|
130
|
-
Divider: typeof StyledModalDivider;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
Modal.propTypes = {
|
|
134
|
-
banner: PropTypes.string || PropTypes.node,
|
|
135
|
-
title: PropTypes.string || PropTypes.node,
|
|
136
|
-
description: PropTypes.string,
|
|
137
|
-
body: PropTypes.string || PropTypes.node,
|
|
138
|
-
action: PropTypes.string || PropTypes.node,
|
|
139
|
-
hideOnClickAway: PropTypes.bool,
|
|
140
|
-
blurBackground: PropTypes.bool,
|
|
141
|
-
onHide: PropTypes.func,
|
|
142
|
-
mobileBottomFullWidth: PropTypes.bool,
|
|
143
|
-
modalPadding: PropTypes.string,
|
|
144
|
-
modalBodyMargin: PropTypes.string,
|
|
145
|
-
width: PropTypes.string,
|
|
146
|
-
height: PropTypes.string,
|
|
147
|
-
minHeight: PropTypes.string,
|
|
148
|
-
showCloseButton: PropTypes.bool,
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
Modal.defaultProps = {
|
|
152
|
-
banner: null,
|
|
153
|
-
title: null,
|
|
154
|
-
description: null,
|
|
155
|
-
body: null,
|
|
156
|
-
action: null,
|
|
157
|
-
hideOnClickAway: false,
|
|
158
|
-
blurBackground: false,
|
|
159
|
-
onHide: () => {},
|
|
160
|
-
mobileBottomFullWidth: false,
|
|
161
|
-
modalPadding: '20px',
|
|
162
|
-
modalBodyMargin: null,
|
|
163
|
-
width: null,
|
|
164
|
-
height: null,
|
|
165
|
-
minHeight: null,
|
|
166
|
-
showCloseButton: false,
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
Modal.Wrapper = StyledModalWrapper;
|
|
170
|
-
Modal.Modal = StyledModal;
|
|
171
|
-
Modal.Main = StyledModalMain;
|
|
172
|
-
Modal.Banner = StyledModalBanner;
|
|
173
|
-
Modal.Title = StyledModalTitle;
|
|
174
|
-
Modal.Description = StyledModalDescription;
|
|
175
|
-
Modal.Body = StyledModalBody;
|
|
176
|
-
Modal.Action = StyledModalAction;
|
|
177
|
-
Modal.Divider = StyledModalDivider;
|
|
178
|
-
|
|
179
|
-
export default Modal;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
2
|
-
|
|
3
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
|
|
6
|
-
import { MultiStepModalProps } from '../types';
|
|
7
|
-
import MultiStepModal from '.';
|
|
8
|
-
|
|
9
|
-
describe('MultiStepModal', () => {
|
|
10
|
-
const defaultProps: MultiStepModalProps = {
|
|
11
|
-
modalSteps: [
|
|
12
|
-
{
|
|
13
|
-
banner: (
|
|
14
|
-
<img
|
|
15
|
-
src="https://via.placeholder.com/300x100"
|
|
16
|
-
alt="Banner"
|
|
17
|
-
/>
|
|
18
|
-
),
|
|
19
|
-
title: 'Step 1',
|
|
20
|
-
description: 'Description for step 1',
|
|
21
|
-
body: 'Body for step 1',
|
|
22
|
-
nextButtonText: 'Next',
|
|
23
|
-
showBackButton: false,
|
|
24
|
-
buttonVariant: 'primary',
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
banner: 'Banner 2',
|
|
28
|
-
title: 'Step 2',
|
|
29
|
-
description: 'Description for step 2',
|
|
30
|
-
body: <div>Body for step 2</div>,
|
|
31
|
-
nextButtonText: 'Finish',
|
|
32
|
-
showBackButton: true,
|
|
33
|
-
buttonVariant: 'secondary',
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
hideOnClickAway: false,
|
|
37
|
-
blurBackground: false,
|
|
38
|
-
onHide: jest.fn(),
|
|
39
|
-
onFinalStep: jest.fn(),
|
|
40
|
-
mobileBottomFullWidth: false,
|
|
41
|
-
onStepChange: jest.fn(),
|
|
42
|
-
showModalStepsPagination: true,
|
|
43
|
-
modalPadding: '20px',
|
|
44
|
-
modalBodyMargin: '12px 0 0 0',
|
|
45
|
-
width: '500px',
|
|
46
|
-
height: 'auto',
|
|
47
|
-
minHeight: 'auto',
|
|
48
|
-
showCloseButton: true,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
it('renders the first step correctly', () => {
|
|
52
|
-
render(<MultiStepModal {...defaultProps} />);
|
|
53
|
-
expect(screen.getByText('Step 1')).toBeInTheDocument();
|
|
54
|
-
expect(screen.getByText('Description for step 1')).toBeInTheDocument();
|
|
55
|
-
expect(screen.getByAltText('Banner')).toBeInTheDocument();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('navigates to the next step when the next button is clicked', () => {
|
|
59
|
-
render(<MultiStepModal {...defaultProps} />);
|
|
60
|
-
fireEvent.click(screen.getByText('Next'));
|
|
61
|
-
expect(screen.getByText('Step 2')).toBeInTheDocument();
|
|
62
|
-
expect(screen.getByText('Description for step 2')).toBeInTheDocument();
|
|
63
|
-
expect(screen.getByText('Body for step 2')).toBeInTheDocument();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('navigates to the previous step when the back button is clicked', () => {
|
|
67
|
-
render(<MultiStepModal {...defaultProps} />);
|
|
68
|
-
fireEvent.click(screen.getByText('Next'));
|
|
69
|
-
fireEvent.click(screen.getByText('Back'));
|
|
70
|
-
expect(screen.getByText('Step 1')).toBeInTheDocument();
|
|
71
|
-
expect(screen.getByText('Description for step 1')).toBeInTheDocument();
|
|
72
|
-
expect(screen.getByAltText('Banner')).toBeInTheDocument();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('calls onStepChange when the step changes', () => {
|
|
76
|
-
const onStepChange = jest.fn();
|
|
77
|
-
render(<MultiStepModal {...defaultProps} onStepChange={onStepChange} />);
|
|
78
|
-
fireEvent.click(screen.getByText('Next'));
|
|
79
|
-
expect(onStepChange).toHaveBeenCalledTimes(1);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('calls onFinalStep and onHide when the final step button is clicked', () => {
|
|
83
|
-
const onFinalStep = jest.fn();
|
|
84
|
-
const onHide = jest.fn();
|
|
85
|
-
render(
|
|
86
|
-
<MultiStepModal
|
|
87
|
-
{...defaultProps}
|
|
88
|
-
onFinalStep={onFinalStep}
|
|
89
|
-
onHide={onHide}
|
|
90
|
-
/>
|
|
91
|
-
);
|
|
92
|
-
fireEvent.click(screen.getByText('Next'));
|
|
93
|
-
fireEvent.click(screen.getByText('Finish'));
|
|
94
|
-
expect(onFinalStep).toHaveBeenCalledTimes(1);
|
|
95
|
-
expect(onHide).toHaveBeenCalledTimes(1);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('renders the close button when stated', () => {
|
|
99
|
-
render(<MultiStepModal {...defaultProps} showCloseButton />);
|
|
100
|
-
expect(screen.getByTestId('testid-iconbutton')).toBeInTheDocument();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('renders the close button and calls onHide when clicked', () => {
|
|
104
|
-
const onHide = jest.fn();
|
|
105
|
-
render(<MultiStepModal {...defaultProps} showCloseButton onHide={onHide} />);
|
|
106
|
-
fireEvent.click(screen.getByTestId('testid-iconbutton'));
|
|
107
|
-
expect(onHide).toHaveBeenCalledTimes(1);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('does not render the close button when showCloseButton is false', () => {
|
|
111
|
-
render(<MultiStepModal {...defaultProps} showCloseButton={false} />);
|
|
112
|
-
expect(
|
|
113
|
-
screen.queryByTestId('testid-iconbutton')
|
|
114
|
-
).not.toBeInTheDocument();
|
|
115
|
-
});
|
|
116
|
-
});
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import PropTypes from 'prop-types';
|
|
2
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import useClickAway from '../../../../hooks/useClickAway';
|
|
5
|
-
import useDisableBodyScroll from '../../../../hooks/useDisableBodyScroll';
|
|
6
|
-
import Button from '../../Button';
|
|
7
|
-
import Modal from '../Modal';
|
|
8
|
-
import {
|
|
9
|
-
StyledModalPaginatedActions,
|
|
10
|
-
StyledModalPagination,
|
|
11
|
-
StyledModalPaginationItem,
|
|
12
|
-
} from '../Modal.styles';
|
|
13
|
-
import { MultiStepModalProps } from '../types';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A multi-step modal is a modal that has multiple steps.
|
|
17
|
-
*/
|
|
18
|
-
const MultiStepModal = ({
|
|
19
|
-
modalSteps,
|
|
20
|
-
showModalStepsPagination,
|
|
21
|
-
hideOnClickAway,
|
|
22
|
-
blurBackground,
|
|
23
|
-
onHide,
|
|
24
|
-
onFinalStep,
|
|
25
|
-
mobileBottomFullWidth,
|
|
26
|
-
onStepChange,
|
|
27
|
-
modalPadding,
|
|
28
|
-
modalBodyMargin,
|
|
29
|
-
width,
|
|
30
|
-
height,
|
|
31
|
-
minHeight,
|
|
32
|
-
showCloseButton,
|
|
33
|
-
}: MultiStepModalProps) => {
|
|
34
|
-
const [currentStep, setCurrentStep] = useState(0);
|
|
35
|
-
const hasMounted = useRef(false);
|
|
36
|
-
const modalRef = useRef(null);
|
|
37
|
-
|
|
38
|
-
const {
|
|
39
|
-
banner,
|
|
40
|
-
title,
|
|
41
|
-
description,
|
|
42
|
-
body,
|
|
43
|
-
nextButtonText,
|
|
44
|
-
showBackButton,
|
|
45
|
-
buttonVariant,
|
|
46
|
-
} = modalSteps[currentStep] || {};
|
|
47
|
-
|
|
48
|
-
const isLastStep = currentStep === modalSteps.length - 1;
|
|
49
|
-
const isFirstStep = currentStep === 0;
|
|
50
|
-
|
|
51
|
-
useDisableBodyScroll();
|
|
52
|
-
|
|
53
|
-
useClickAway(modalRef, () => {
|
|
54
|
-
if (hideOnClickAway) {
|
|
55
|
-
onHide();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
if (
|
|
61
|
-
hasMounted.current &&
|
|
62
|
-
onStepChange &&
|
|
63
|
-
typeof onStepChange === 'function'
|
|
64
|
-
) {
|
|
65
|
-
onStepChange();
|
|
66
|
-
} else {
|
|
67
|
-
hasMounted.current = true;
|
|
68
|
-
}
|
|
69
|
-
}, [currentStep]);
|
|
70
|
-
|
|
71
|
-
if (modalSteps.length === 0) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<Modal
|
|
77
|
-
banner={banner}
|
|
78
|
-
title={title}
|
|
79
|
-
description={description}
|
|
80
|
-
body={body}
|
|
81
|
-
hideOnClickAway={hideOnClickAway}
|
|
82
|
-
blurBackground={blurBackground}
|
|
83
|
-
onHide={onHide}
|
|
84
|
-
mobileBottomFullWidth={mobileBottomFullWidth}
|
|
85
|
-
modalPadding={modalPadding}
|
|
86
|
-
modalBodyMargin={modalBodyMargin}
|
|
87
|
-
width={width}
|
|
88
|
-
height={height}
|
|
89
|
-
minHeight={minHeight}
|
|
90
|
-
showCloseButton={showCloseButton}
|
|
91
|
-
action={
|
|
92
|
-
<StyledModalPaginatedActions>
|
|
93
|
-
{showModalStepsPagination && modalSteps.length > 1 && (
|
|
94
|
-
<StyledModalPagination>
|
|
95
|
-
{modalSteps.map((item, index) => (
|
|
96
|
-
<StyledModalPaginationItem
|
|
97
|
-
key={`modal-pagination-item-${index + 1}`}
|
|
98
|
-
active={index === currentStep}
|
|
99
|
-
onClick={() => setCurrentStep(index)}
|
|
100
|
-
/>
|
|
101
|
-
))}
|
|
102
|
-
</StyledModalPagination>
|
|
103
|
-
)}
|
|
104
|
-
|
|
105
|
-
<Modal.Action>
|
|
106
|
-
{showBackButton && !isFirstStep && (
|
|
107
|
-
<Button
|
|
108
|
-
variant="secondary-outlined"
|
|
109
|
-
onClick={() => {
|
|
110
|
-
setCurrentStep(currentStep - 1);
|
|
111
|
-
}}
|
|
112
|
-
icon="arrow-right"
|
|
113
|
-
iconPosition="left"
|
|
114
|
-
>
|
|
115
|
-
Back
|
|
116
|
-
</Button>
|
|
117
|
-
)}
|
|
118
|
-
|
|
119
|
-
{nextButtonText && (
|
|
120
|
-
<Button
|
|
121
|
-
variant={buttonVariant || 'secondary'}
|
|
122
|
-
fullWidth
|
|
123
|
-
onClick={() => {
|
|
124
|
-
if (isLastStep) {
|
|
125
|
-
onFinalStep();
|
|
126
|
-
onHide();
|
|
127
|
-
} else {
|
|
128
|
-
setCurrentStep(currentStep + 1);
|
|
129
|
-
}
|
|
130
|
-
}}
|
|
131
|
-
icon={isLastStep ? null : 'arrow-left'}
|
|
132
|
-
iconPosition="right"
|
|
133
|
-
>
|
|
134
|
-
{nextButtonText}
|
|
135
|
-
</Button>
|
|
136
|
-
)}
|
|
137
|
-
</Modal.Action>
|
|
138
|
-
</StyledModalPaginatedActions>
|
|
139
|
-
}
|
|
140
|
-
/>
|
|
141
|
-
);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
MultiStepModal.propTypes = {
|
|
145
|
-
modalSteps: PropTypes.array,
|
|
146
|
-
showModalStepsPagination: PropTypes.bool,
|
|
147
|
-
hideOnClickAway: PropTypes.bool,
|
|
148
|
-
blurBackground: PropTypes.bool,
|
|
149
|
-
onHide: PropTypes.func,
|
|
150
|
-
onFinalStep: PropTypes.func,
|
|
151
|
-
mobileBottomFullWidth: PropTypes.bool,
|
|
152
|
-
onStepChange: PropTypes.func,
|
|
153
|
-
modalPadding: PropTypes.string,
|
|
154
|
-
modalBodyMargin: PropTypes.string,
|
|
155
|
-
width: PropTypes.string,
|
|
156
|
-
height: PropTypes.string,
|
|
157
|
-
minHeight: PropTypes.string,
|
|
158
|
-
showCloseButton: PropTypes.bool,
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
MultiStepModal.defaultProps = {
|
|
162
|
-
modalSteps: [],
|
|
163
|
-
showModalStepsPagination: true,
|
|
164
|
-
hideOnClickAway: false,
|
|
165
|
-
blurBackground: false,
|
|
166
|
-
onHide: () => {},
|
|
167
|
-
onFinalStep: () => {},
|
|
168
|
-
mobileBottomFullWidth: false,
|
|
169
|
-
onStepChange: () => {},
|
|
170
|
-
modalPadding: '20px',
|
|
171
|
-
modalBodyMargin: '12px 0 0 0',
|
|
172
|
-
width: null,
|
|
173
|
-
height: null,
|
|
174
|
-
minHeight: null,
|
|
175
|
-
showCloseButton: false,
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
MultiStepModal.PaginatedActions = StyledModalPaginatedActions;
|
|
179
|
-
MultiStepModal.Pagination = StyledModalPagination;
|
|
180
|
-
MultiStepModal.PaginationItem = StyledModalPaginationItem;
|
|
181
|
-
|
|
182
|
-
export { MultiStepModalProps };
|
|
183
|
-
|
|
184
|
-
export default MultiStepModal;
|
|
File without changes
|