@onewelcome/react-lib-components 0.1.4-alpha → 0.1.7-alpha
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/Button/IconButton.d.ts +2 -1
- package/dist/ContextMenu/ContextMenu.d.ts +2 -3
- package/dist/ContextMenu/ContextMenuItem.d.ts +10 -3
- package/dist/Form/Checkbox/Checkbox.d.ts +2 -2
- package/dist/Form/Toggle/Toggle.d.ts +1 -1
- package/dist/Link/Link.d.ts +4 -3
- package/dist/Notifications/BaseModal/BaseModal.d.ts +4 -2
- package/dist/Notifications/SlideInModal/SlideInModal.d.ts +4 -0
- package/dist/StatusIndicator/StatusIndicator.d.ts +9 -0
- package/dist/index.d.ts +43 -42
- package/dist/react-lib-components.cjs.development.js +2208 -2033
- package/dist/react-lib-components.cjs.development.js.map +1 -1
- package/dist/react-lib-components.cjs.production.min.js +1 -1
- package/dist/react-lib-components.cjs.production.min.js.map +1 -1
- package/dist/react-lib-components.esm.js +2207 -2034
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/Button/BaseButton.module.scss +3 -18
- package/src/Button/Button.module.scss +4 -311
- package/src/Button/IconButton.module.scss +21 -128
- package/src/Button/IconButton.test.tsx +24 -0
- package/src/Button/IconButton.tsx +6 -1
- package/src/ContextMenu/ContextMenu.test.tsx +121 -6
- package/src/ContextMenu/ContextMenu.tsx +84 -6
- package/src/ContextMenu/ContextMenuItem.tsx +57 -9
- package/src/Form/Checkbox/Checkbox.test.tsx +144 -8
- package/src/Form/Checkbox/Checkbox.tsx +8 -8
- package/src/Form/Toggle/Toggle.test.tsx +45 -19
- package/src/Form/Toggle/Toggle.tsx +3 -3
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +1 -1
- package/src/Link/Link.module.scss +20 -0
- package/src/Link/Link.test.tsx +33 -0
- package/src/Link/Link.tsx +8 -2
- package/src/Notifications/BaseModal/BaseModal.test.tsx +75 -11
- package/src/Notifications/BaseModal/BaseModal.tsx +27 -6
- package/src/Notifications/Dialog/Dialog.tsx +1 -1
- package/src/Notifications/SlideInModal/SlideInModal.module.scss +36 -0
- package/src/Notifications/SlideInModal/SlideInModal.test.tsx +69 -0
- package/src/Notifications/SlideInModal/SlideInModal.tsx +31 -0
- package/src/StatusIndicator/StatusIndicator.module.scss +27 -0
- package/src/StatusIndicator/StatusIndicator.test.tsx +127 -0
- package/src/StatusIndicator/StatusIndicator.tsx +25 -0
- package/src/Tiles/Tile.module.scss +1 -1
- package/src/Tiles/Tile.test.tsx +4 -4
- package/src/index.ts +79 -47
- package/src/mixins.module.scss +171 -0
- package/src/readyclasses.module.scss +0 -30
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { Toggle } from './Toggle';
|
|
1
|
+
import React, { useRef, useEffect } from 'react';
|
|
2
|
+
import { Toggle, Props } from './Toggle';
|
|
3
3
|
import { render } from '@testing-library/react';
|
|
4
4
|
|
|
5
|
+
const defaultParams: Props = {
|
|
6
|
+
children: 'label',
|
|
7
|
+
name: 'example toggle',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const createToggle = (params?: (defaultParams: Props) => Props) => {
|
|
11
|
+
let parameters: Props = defaultParams;
|
|
12
|
+
if (params) {
|
|
13
|
+
parameters = params(defaultParams);
|
|
14
|
+
}
|
|
15
|
+
const queries = render(
|
|
16
|
+
<Toggle {...parameters} data-testid="toggle">
|
|
17
|
+
toggle content
|
|
18
|
+
</Toggle>
|
|
19
|
+
);
|
|
20
|
+
const toggle = queries.getByTestId('toggle');
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
...queries,
|
|
24
|
+
toggle,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
5
28
|
describe('Toggle should render', () => {
|
|
6
29
|
it('renders without crashing', () => {
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
30
|
+
const { toggle } = createToggle();
|
|
31
|
+
|
|
32
|
+
expect(toggle).toBeDefined();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('Toggle attributes', () => {
|
|
37
|
+
it('should be checked', () => {
|
|
38
|
+
const { toggle } = createToggle((defaultParams) => ({ ...defaultParams, checked: true }));
|
|
39
|
+
|
|
40
|
+
expect(toggle).toHaveAttribute('aria-checked', 'true');
|
|
14
41
|
});
|
|
15
42
|
});
|
|
16
43
|
|
|
@@ -29,7 +56,7 @@ describe('ref should work', () => {
|
|
|
29
56
|
}
|
|
30
57
|
}, [ref]);
|
|
31
58
|
|
|
32
|
-
return <Toggle
|
|
59
|
+
return <Toggle {...defaultParams} data-ref="testing" ref={ref} />;
|
|
33
60
|
};
|
|
34
61
|
|
|
35
62
|
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
@@ -40,16 +67,15 @@ describe('ref should work', () => {
|
|
|
40
67
|
});
|
|
41
68
|
});
|
|
42
69
|
|
|
43
|
-
describe('
|
|
44
|
-
it('
|
|
45
|
-
const { getByTestId } =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
70
|
+
describe('helperProps should be properly propagated down', () => {
|
|
71
|
+
it('renders an anchor tag as helper', () => {
|
|
72
|
+
const { getByTestId } = createToggle((defaultParams) => ({
|
|
73
|
+
...defaultParams,
|
|
74
|
+
helperProps: { children: <a data-testid="helpertextanchor">test</a> },
|
|
75
|
+
}));
|
|
50
76
|
|
|
51
|
-
const
|
|
77
|
+
const helperTextAnchor = getByTestId('helpertextanchor');
|
|
52
78
|
|
|
53
|
-
expect(
|
|
79
|
+
expect(helperTextAnchor).toBeTruthy();
|
|
54
80
|
});
|
|
55
81
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ComponentPropsWithRef } from 'react';
|
|
2
|
-
import { Checkbox, CheckboxProps } from '../Checkbox/Checkbox';
|
|
2
|
+
import { Checkbox, Props as CheckboxProps } from '../Checkbox/Checkbox';
|
|
3
3
|
import classes from './Toggle.module.scss';
|
|
4
4
|
|
|
5
5
|
export interface Props
|
|
@@ -9,14 +9,14 @@ export interface Props
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const Toggle = React.forwardRef<HTMLInputElement, Props>(
|
|
12
|
-
({ children, checked, disabled, ...rest }: Props, ref) => (
|
|
12
|
+
({ children, checked, disabled, helperProps, ...rest }: Props, ref) => (
|
|
13
13
|
<div className={classes['toggle-wrapper']}>
|
|
14
14
|
<Checkbox
|
|
15
15
|
{...rest}
|
|
16
16
|
ref={ref}
|
|
17
17
|
checked={checked}
|
|
18
18
|
className={classes['checkbox']}
|
|
19
|
-
helperProps={{ className: classes['toggle-helper'] }}
|
|
19
|
+
helperProps={{ className: classes['toggle-helper'], ...helperProps }}
|
|
20
20
|
disabled={disabled}
|
|
21
21
|
label={children}
|
|
22
22
|
>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useRef } from 'react';
|
|
2
2
|
import { CheckboxWrapper, Props } from './CheckboxWrapper';
|
|
3
|
-
import { Checkbox, CheckboxProps } from '../../Checkbox/Checkbox';
|
|
3
|
+
import { Checkbox, Props as CheckboxProps } from '../../Checkbox/Checkbox';
|
|
4
4
|
import { render } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
const defaultParentParams: CheckboxProps = {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
@import '../mixins.module.scss';
|
|
2
|
+
|
|
1
3
|
.link {
|
|
2
4
|
font-family: var(--font-family);
|
|
3
5
|
font-size: var(--font-size);
|
|
@@ -44,3 +46,21 @@
|
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
}
|
|
49
|
+
|
|
50
|
+
.button {
|
|
51
|
+
@include buttonBase('link');
|
|
52
|
+
|
|
53
|
+
text-decoration: none;
|
|
54
|
+
|
|
55
|
+
&.fill {
|
|
56
|
+
@include button('fill', 'link');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
&.outline {
|
|
60
|
+
@include button('outline', 'link');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&.text {
|
|
64
|
+
@include button('text', 'link');
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/Link/Link.test.tsx
CHANGED
|
@@ -99,6 +99,39 @@ describe('Link should render', () => {
|
|
|
99
99
|
|
|
100
100
|
expect(link).toHaveClass('classname');
|
|
101
101
|
});
|
|
102
|
+
|
|
103
|
+
it('should render as a filled button ', () => {
|
|
104
|
+
const { link } = createLink((defaultParams) => ({
|
|
105
|
+
...defaultParams,
|
|
106
|
+
display: 'button',
|
|
107
|
+
buttonVariant: 'fill',
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
expect(link).toHaveClass('button');
|
|
111
|
+
expect(link).toHaveClass('fill');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should render as a text button ', () => {
|
|
115
|
+
const { link } = createLink((defaultParams) => ({
|
|
116
|
+
...defaultParams,
|
|
117
|
+
display: 'button',
|
|
118
|
+
buttonVariant: 'text',
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
expect(link).toHaveClass('button');
|
|
122
|
+
expect(link).toHaveClass('text');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should render as an outline button ', () => {
|
|
126
|
+
const { link } = createLink((defaultParams) => ({
|
|
127
|
+
...defaultParams,
|
|
128
|
+
display: 'button',
|
|
129
|
+
buttonVariant: 'outline',
|
|
130
|
+
}));
|
|
131
|
+
|
|
132
|
+
expect(link).toHaveClass('button');
|
|
133
|
+
expect(link).toHaveClass('outline');
|
|
134
|
+
});
|
|
102
135
|
});
|
|
103
136
|
|
|
104
137
|
describe('ref should work', () => {
|
package/src/Link/Link.tsx
CHANGED
|
@@ -7,11 +7,13 @@ import React, {
|
|
|
7
7
|
import classes from './Link.module.scss';
|
|
8
8
|
import { LinkProps } from './types';
|
|
9
9
|
|
|
10
|
-
type AnchorType = 'external' | 'internal' | 'download';
|
|
10
|
+
export type AnchorType = 'external' | 'internal' | 'download';
|
|
11
11
|
|
|
12
12
|
export interface Props extends ComponentPropsWithRef<'a'> {
|
|
13
13
|
children?: ReactNode;
|
|
14
14
|
color?: 'primary' | 'secondary' | 'tertiary';
|
|
15
|
+
display?: 'link' | 'button';
|
|
16
|
+
buttonVariant?: 'outline' | 'text' | 'fill';
|
|
15
17
|
type?: AnchorType;
|
|
16
18
|
to: string;
|
|
17
19
|
disabled?: boolean;
|
|
@@ -27,6 +29,8 @@ export const Link = React.forwardRef<HTMLAnchorElement, Props>(
|
|
|
27
29
|
to,
|
|
28
30
|
color = 'primary',
|
|
29
31
|
type = 'internal',
|
|
32
|
+
display = 'link',
|
|
33
|
+
buttonVariant = 'fill',
|
|
30
34
|
component,
|
|
31
35
|
...rest
|
|
32
36
|
}: Props,
|
|
@@ -44,7 +48,9 @@ export const Link = React.forwardRef<HTMLAnchorElement, Props>(
|
|
|
44
48
|
return '';
|
|
45
49
|
};
|
|
46
50
|
|
|
47
|
-
const classNames = [classes[
|
|
51
|
+
const classNames = [classes[color]];
|
|
52
|
+
display === 'link' && classNames.push(classes['link']);
|
|
53
|
+
display === 'button' && classNames.push(classes['button'], classes[buttonVariant]);
|
|
48
54
|
disabled && classNames.push(classes['disabled']);
|
|
49
55
|
className && classNames.push(className);
|
|
50
56
|
|
|
@@ -6,48 +6,112 @@ import userEvent from '@testing-library/user-event';
|
|
|
6
6
|
const classNames = ['class11', 'class12'];
|
|
7
7
|
const containerClassNames = ['class21', 'class22'];
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const defaultParams: Props = {
|
|
10
10
|
id: 'modal',
|
|
11
11
|
open: true,
|
|
12
12
|
onClose: jest.fn(),
|
|
13
13
|
className: classNames.join(' '),
|
|
14
|
-
|
|
14
|
+
containerProps: { className: containerClassNames.join(' ') },
|
|
15
15
|
children: 'This is example dialog content.',
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
const createBaseModal = (params?: (defaultParams: Props) => Props) => {
|
|
19
|
+
let parameters: Props = defaultParams;
|
|
20
|
+
if (params) {
|
|
21
|
+
parameters = params(defaultParams);
|
|
22
|
+
}
|
|
23
|
+
const queries = render(<BaseModal {...parameters} data-testid="BaseModal" />);
|
|
24
|
+
const slideInModal = queries.getByTestId('BaseModal');
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
...queries,
|
|
28
|
+
slideInModal,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
18
32
|
describe('BaseModal', () => {
|
|
19
33
|
it('renders without crashing', () => {
|
|
20
|
-
const { getByRole } =
|
|
34
|
+
const { getByRole } = createBaseModal();
|
|
21
35
|
const dialog = getByRole('dialog');
|
|
36
|
+
|
|
22
37
|
expect(dialog).toHaveAttribute('aria-modal', 'true');
|
|
23
38
|
expect(dialog).toHaveAttribute('aria-labelledby', 'modal-label');
|
|
24
39
|
expect(dialog).toHaveAttribute('aria-describedby', 'modal-description');
|
|
25
40
|
expect(dialog).toHaveAttribute('data-hidden', 'false');
|
|
26
41
|
expect(dialog).toHaveAttribute('aria-hidden', 'false');
|
|
27
|
-
expect(getByText(dialog,
|
|
42
|
+
expect(getByText(dialog, defaultParams.children as string)).toBeDefined();
|
|
28
43
|
expect(document.body).toHaveStyle('overflow: hidden');
|
|
29
44
|
});
|
|
30
45
|
|
|
31
|
-
it('should render
|
|
32
|
-
const { queryByRole } =
|
|
46
|
+
it('should render closed modal without content', () => {
|
|
47
|
+
const { queryByRole } = createBaseModal((params) => ({ ...params, open: false }));
|
|
48
|
+
|
|
33
49
|
const dialogByRole = queryByRole('dialog');
|
|
34
50
|
const dialog = document.body.children[1] as HTMLElement;
|
|
51
|
+
|
|
35
52
|
expect(dialogByRole).toBeNull();
|
|
36
53
|
expect(dialog).toHaveAttribute('aria-hidden', 'true');
|
|
37
|
-
expect(queryByText(dialog,
|
|
54
|
+
expect(queryByText(dialog, defaultParams.children as string)).toBeNull();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should render closed modal with content when forceContainerOpen is provided', () => {
|
|
58
|
+
const { getByRole } = createBaseModal((params) => ({
|
|
59
|
+
...params,
|
|
60
|
+
open: false,
|
|
61
|
+
forceContainerOpen: true,
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
const modal = getByRole('dialog', { hidden: true });
|
|
65
|
+
const container = modal.querySelector('.container') as HTMLElement;
|
|
66
|
+
|
|
67
|
+
expect(container).toBeInTheDocument();
|
|
68
|
+
expect(container).toHaveAttribute('aria-hidden', 'true');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('propagates containerProps to container element', () => {
|
|
72
|
+
const { getByRole } = createBaseModal((params) => ({
|
|
73
|
+
...params,
|
|
74
|
+
open: true,
|
|
75
|
+
containerProps: {
|
|
76
|
+
id: 'container',
|
|
77
|
+
},
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
const modal = getByRole('dialog');
|
|
81
|
+
const container = modal.querySelector('.container') as HTMLElement;
|
|
82
|
+
|
|
83
|
+
expect(container).toBeInTheDocument();
|
|
84
|
+
expect(container).toHaveAttribute('id', 'container');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('propagates backdropProps to backdrop element', () => {
|
|
88
|
+
const { getByRole } = createBaseModal((params) => ({
|
|
89
|
+
...params,
|
|
90
|
+
open: true,
|
|
91
|
+
backdropProps: {
|
|
92
|
+
id: 'backdrop',
|
|
93
|
+
},
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
const modal = getByRole('dialog');
|
|
97
|
+
const backdrop = modal.querySelector('.backdrop') as HTMLElement;
|
|
98
|
+
|
|
99
|
+
expect(backdrop).toBeInTheDocument();
|
|
100
|
+
expect(backdrop).toHaveAttribute('id', 'backdrop');
|
|
38
101
|
});
|
|
39
102
|
|
|
40
103
|
it('should handle clicking on backdrop & ESC key', () => {
|
|
41
|
-
const { getByRole } =
|
|
104
|
+
const { getByRole } = createBaseModal();
|
|
105
|
+
|
|
42
106
|
const modal = getByRole('dialog');
|
|
43
107
|
const backdrop = modal.querySelector('.backdrop') as HTMLElement;
|
|
44
|
-
expect(
|
|
108
|
+
expect(defaultParams.onClose).toHaveBeenCalledTimes(0);
|
|
45
109
|
|
|
46
110
|
userEvent.click(backdrop);
|
|
47
|
-
expect(
|
|
111
|
+
expect(defaultParams.onClose).toHaveBeenCalledTimes(1);
|
|
48
112
|
|
|
49
113
|
fireEvent.keyDown(modal, { key: 'Escape' });
|
|
50
|
-
expect(
|
|
114
|
+
expect(defaultParams.onClose).toHaveBeenCalledTimes(2);
|
|
51
115
|
});
|
|
52
116
|
});
|
|
53
117
|
|
|
@@ -12,11 +12,13 @@ export interface Props extends ComponentPropsWithRef<'div'> {
|
|
|
12
12
|
open: boolean;
|
|
13
13
|
onClose?: (event?: React.MouseEvent<HTMLElement>) => unknown;
|
|
14
14
|
className?: string;
|
|
15
|
-
|
|
15
|
+
containerProps?: ComponentPropsWithRef<'div'>;
|
|
16
|
+
backdropProps?: ComponentPropsWithRef<'div'>;
|
|
16
17
|
labelledby?: string;
|
|
17
18
|
describedby?: string;
|
|
18
19
|
disableEscapeKeyDown?: boolean;
|
|
19
20
|
disableBackdrop?: boolean;
|
|
21
|
+
forceContainerOpen?: boolean;
|
|
20
22
|
zIndex?: number;
|
|
21
23
|
domRoot?: HTMLElement;
|
|
22
24
|
}
|
|
@@ -51,11 +53,13 @@ export const BaseModal = React.forwardRef<HTMLDivElement, Props>(
|
|
|
51
53
|
open,
|
|
52
54
|
onClose,
|
|
53
55
|
className = '',
|
|
54
|
-
|
|
56
|
+
containerProps,
|
|
57
|
+
backdropProps,
|
|
55
58
|
labelledby,
|
|
56
59
|
describedby,
|
|
57
60
|
disableEscapeKeyDown = false,
|
|
58
61
|
disableBackdrop = false,
|
|
62
|
+
forceContainerOpen = false,
|
|
59
63
|
zIndex,
|
|
60
64
|
domRoot = document.body,
|
|
61
65
|
...rest
|
|
@@ -78,7 +82,7 @@ export const BaseModal = React.forwardRef<HTMLDivElement, Props>(
|
|
|
78
82
|
{...rest}
|
|
79
83
|
ref={ref}
|
|
80
84
|
id={id}
|
|
81
|
-
className={`${classes['modal']} ${open
|
|
85
|
+
className={`${classes['modal']} ${open ? classes['visible'] : ''} ${className}`}
|
|
82
86
|
role="dialog"
|
|
83
87
|
aria-modal="true"
|
|
84
88
|
aria-labelledby={labelledby || labelId(id)}
|
|
@@ -89,14 +93,31 @@ export const BaseModal = React.forwardRef<HTMLDivElement, Props>(
|
|
|
89
93
|
onKeyDown={handleEscKeyPress}
|
|
90
94
|
style={{ zIndex }}
|
|
91
95
|
>
|
|
92
|
-
<div
|
|
93
|
-
|
|
96
|
+
<div
|
|
97
|
+
{...backdropProps}
|
|
98
|
+
className={`${classes['backdrop']} ${backdropProps?.className ?? ''}`}
|
|
99
|
+
onClick={handleBackdropClick}
|
|
100
|
+
></div>
|
|
101
|
+
{forceContainerOpen ? (
|
|
94
102
|
<div
|
|
103
|
+
{...containerProps}
|
|
104
|
+
aria-hidden={!open}
|
|
105
|
+
hidden={!open}
|
|
95
106
|
style={{ zIndex: zIndex && zIndex + 1 }}
|
|
96
|
-
className={`${classes['container']} ${
|
|
107
|
+
className={`${classes['container']} ${containerProps?.className ?? ''}`}
|
|
97
108
|
>
|
|
98
109
|
{children}
|
|
99
110
|
</div>
|
|
111
|
+
) : (
|
|
112
|
+
open && (
|
|
113
|
+
<div
|
|
114
|
+
{...containerProps}
|
|
115
|
+
style={{ zIndex: zIndex && zIndex + 1 }}
|
|
116
|
+
className={`${classes['container']} ${containerProps?.className ?? ''}`}
|
|
117
|
+
>
|
|
118
|
+
{children}
|
|
119
|
+
</div>
|
|
120
|
+
)
|
|
100
121
|
)}
|
|
101
122
|
</div>,
|
|
102
123
|
domRoot
|
|
@@ -74,7 +74,7 @@ export const Dialog = React.forwardRef<HTMLDivElement, Props>(
|
|
|
74
74
|
ref={ref}
|
|
75
75
|
id={dialogId}
|
|
76
76
|
className={classes['dialog']}
|
|
77
|
-
|
|
77
|
+
containerProps={{ className: classes['container'] }}
|
|
78
78
|
open={open}
|
|
79
79
|
disableBackdrop
|
|
80
80
|
onClose={onClose}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.slide-in-modal {
|
|
2
|
+
justify-content: flex-end;
|
|
3
|
+
|
|
4
|
+
visibility: visible;
|
|
5
|
+
|
|
6
|
+
transition: transform 0.5s ease-in-out;
|
|
7
|
+
transform: translate(120%);
|
|
8
|
+
|
|
9
|
+
&.hidden {
|
|
10
|
+
visibility: hidden;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&.visible {
|
|
14
|
+
visibility: visible;
|
|
15
|
+
transform: translate(0%);
|
|
16
|
+
|
|
17
|
+
.backdrop-slide {
|
|
18
|
+
background-color: transparent;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.backdrop-slide {
|
|
24
|
+
background-color: transparent;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@media only screen and (min-width: 50rem) {
|
|
28
|
+
.container {
|
|
29
|
+
margin-top: 0;
|
|
30
|
+
width: 50rem;
|
|
31
|
+
height: 100%;
|
|
32
|
+
max-height: unset;
|
|
33
|
+
border-radius: 0;
|
|
34
|
+
box-shadow: 0 1.875rem 3.125rem var(--modal-shadow-color);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { SlideInModal } from './SlideInModal';
|
|
3
|
+
import { Props } from '../Modal/Modal';
|
|
4
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
const defaultParams: Props = {
|
|
7
|
+
id: '',
|
|
8
|
+
children: undefined,
|
|
9
|
+
open: false,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const createSlideInModal = (params?: (defaultParams: Props) => Props) => {
|
|
13
|
+
let parameters: Props = defaultParams;
|
|
14
|
+
if (params) {
|
|
15
|
+
parameters = params(defaultParams);
|
|
16
|
+
}
|
|
17
|
+
const queries = render(<SlideInModal {...parameters} data-testid="SlideInModal" />);
|
|
18
|
+
const slideInModal = queries.getByTestId('SlideInModal');
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
...queries,
|
|
22
|
+
slideInModal,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('SlideInModal should render', () => {
|
|
27
|
+
it('renders without crashing', () => {
|
|
28
|
+
const { slideInModal } = createSlideInModal();
|
|
29
|
+
|
|
30
|
+
expect(slideInModal).toBeDefined();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("makes modal content's container visible after opening transition ends", () => {
|
|
34
|
+
const { slideInModal, rerender } = createSlideInModal();
|
|
35
|
+
|
|
36
|
+
expect(slideInModal).toHaveClass('hidden');
|
|
37
|
+
|
|
38
|
+
rerender(<SlideInModal {...defaultParams} open />);
|
|
39
|
+
fireEvent.transitionEnd(slideInModal);
|
|
40
|
+
|
|
41
|
+
expect(slideInModal).not.toHaveClass('hidden');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('ref should work', () => {
|
|
46
|
+
it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
|
|
47
|
+
const ExampleComponent = ({
|
|
48
|
+
propagateRef,
|
|
49
|
+
}: {
|
|
50
|
+
propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
|
|
51
|
+
}) => {
|
|
52
|
+
const ref = useRef(null);
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (ref.current) {
|
|
56
|
+
propagateRef && propagateRef(ref);
|
|
57
|
+
}
|
|
58
|
+
}, [ref]);
|
|
59
|
+
|
|
60
|
+
return <SlideInModal {...defaultParams} data-ref="testing" ref={ref} />;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
64
|
+
expect(ref.current).toHaveAttribute('data-ref', 'testing');
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
render(<ExampleComponent propagateRef={refCheck} />);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Props as ModalProps, Modal } from '../Modal/Modal';
|
|
3
|
+
import classes from './SlideInModal.module.scss';
|
|
4
|
+
|
|
5
|
+
export const SlideInModal = React.forwardRef<HTMLDivElement, ModalProps>(
|
|
6
|
+
({ children, id, open, ...rest }: ModalProps, ref) => {
|
|
7
|
+
const [classHideOnTransition, setClassHideOnTransition] = useState<'hidden' | ''>('hidden');
|
|
8
|
+
|
|
9
|
+
const onTransitionEnd = () => setClassHideOnTransition((prev) => (prev ? '' : 'hidden'));
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<Modal
|
|
13
|
+
{...rest}
|
|
14
|
+
id={id}
|
|
15
|
+
open={open}
|
|
16
|
+
className={`${classes['slide-in-modal']} ${open ? classes['visible'] : ''} ${
|
|
17
|
+
!open ? classes[classHideOnTransition] : ''
|
|
18
|
+
}`}
|
|
19
|
+
containerProps={{ className: classes['container'] }}
|
|
20
|
+
backdropProps={{ className: classes['backdrop-slide'] }}
|
|
21
|
+
forceContainerOpen
|
|
22
|
+
onTransitionEnd={onTransitionEnd}
|
|
23
|
+
ref={ref}
|
|
24
|
+
>
|
|
25
|
+
{children}
|
|
26
|
+
</Modal>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export { Props } from '../Modal/Modal';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
.status-indicator {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.status-badge {
|
|
7
|
+
width: 0.75rem;
|
|
8
|
+
height: 0.75rem;
|
|
9
|
+
margin-right: 0.5rem;
|
|
10
|
+
border-radius: 50%;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.active {
|
|
14
|
+
background-color: var(--success);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.error {
|
|
18
|
+
background-color: var(--error);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.neutral {
|
|
22
|
+
background-color: var(--greyed-out);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.warning {
|
|
26
|
+
background-color: var(--warning);
|
|
27
|
+
}
|