@onewelcome/react-lib-components 0.1.6-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 -43
- package/dist/react-lib-components.cjs.development.js +2210 -2037
- 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 +2210 -2038
- 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.tsx +1 -1
- 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 -48
- package/src/mixins.module.scss +171 -0
- package/src/readyclasses.module.scss +0 -30
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
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { StatusIndicator, Props } from './StatusIndicator';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
const defaultParams: Props = {
|
|
6
|
+
status: 'active',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const createStatusIndicator = (params?: (defaultParams: Props) => Props) => {
|
|
10
|
+
let parameters: Props = defaultParams;
|
|
11
|
+
if (params) {
|
|
12
|
+
parameters = params(defaultParams);
|
|
13
|
+
}
|
|
14
|
+
const queries = render(
|
|
15
|
+
<StatusIndicator {...parameters} data-testid="StatusIndicator">
|
|
16
|
+
content
|
|
17
|
+
</StatusIndicator>
|
|
18
|
+
);
|
|
19
|
+
const statusIndicator = queries.getByTestId('StatusIndicator');
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
...queries,
|
|
23
|
+
statusIndicator,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe('StatusIndicator should render', () => {
|
|
28
|
+
it('renders without crashing', () => {
|
|
29
|
+
const { statusIndicator, getByText } = createStatusIndicator();
|
|
30
|
+
|
|
31
|
+
expect(statusIndicator).toBeDefined();
|
|
32
|
+
expect(getByText('content')).toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('passes through custom typography props', () => {
|
|
36
|
+
const { statusIndicator, getByText } = createStatusIndicator((params) => ({
|
|
37
|
+
...params,
|
|
38
|
+
typographyProps: {
|
|
39
|
+
variant: 'body',
|
|
40
|
+
children: <strong>custom children</strong>,
|
|
41
|
+
},
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
expect(statusIndicator).toBeDefined();
|
|
45
|
+
expect(getByText('custom children')).toBeInTheDocument();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('passes through custom props', () => {
|
|
49
|
+
const { statusIndicator } = createStatusIndicator((params) => ({
|
|
50
|
+
...params,
|
|
51
|
+
'aria-label': 'status indicator',
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
expect(statusIndicator).toBeDefined();
|
|
55
|
+
expect(statusIndicator).toHaveAttribute('aria-label', 'status indicator');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should set "active" class on status badge', () => {
|
|
59
|
+
const { statusIndicator } = createStatusIndicator((params) => ({
|
|
60
|
+
...params,
|
|
61
|
+
status: 'active',
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
expect(statusIndicator.firstChild).toHaveClass('active');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should set "error" class on status badge', () => {
|
|
68
|
+
const { statusIndicator } = createStatusIndicator((params) => ({ ...params, status: 'error' }));
|
|
69
|
+
|
|
70
|
+
expect(statusIndicator.firstChild).toHaveClass('error');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should set "neutral" class on status badge', () => {
|
|
74
|
+
const { statusIndicator } = createStatusIndicator((params) => ({
|
|
75
|
+
...params,
|
|
76
|
+
status: 'neutral',
|
|
77
|
+
}));
|
|
78
|
+
|
|
79
|
+
expect(statusIndicator.firstChild).toHaveClass('neutral');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should pass "warning" class to status badge', () => {
|
|
83
|
+
const { statusIndicator } = createStatusIndicator((params) => ({
|
|
84
|
+
...params,
|
|
85
|
+
status: 'warning',
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
expect(statusIndicator.firstChild).toHaveClass('warning');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should pass custom class to status badge', () => {
|
|
92
|
+
const { statusIndicator } = createStatusIndicator((params) => ({
|
|
93
|
+
...params,
|
|
94
|
+
badgeProps: { className: 'custom' },
|
|
95
|
+
}));
|
|
96
|
+
|
|
97
|
+
expect(statusIndicator.firstChild).toHaveClass('custom');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('ref should work', () => {
|
|
102
|
+
it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
|
|
103
|
+
const ExampleComponent = ({
|
|
104
|
+
propagateRef,
|
|
105
|
+
}: {
|
|
106
|
+
propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
|
|
107
|
+
}) => {
|
|
108
|
+
const ref = useRef(null);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (ref.current) {
|
|
112
|
+
propagateRef && propagateRef(ref);
|
|
113
|
+
}
|
|
114
|
+
}, [ref]);
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<StatusIndicator id="test" children="test" data-ref="testing" ref={ref} status="active" />
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
122
|
+
expect(ref.current).toHaveAttribute('data-ref', 'testing');
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
render(<ExampleComponent propagateRef={refCheck} />);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { ComponentPropsWithRef, ReactNode } from 'react';
|
|
2
|
+
import { Typography, Props as TypographyProps } from '../Typography/Typography';
|
|
3
|
+
import classes from './StatusIndicator.module.scss';
|
|
4
|
+
|
|
5
|
+
export interface Props extends ComponentPropsWithRef<'div'> {
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
status: 'active' | 'error' | 'neutral' | 'warning';
|
|
8
|
+
badgeProps?: ComponentPropsWithRef<'div'>;
|
|
9
|
+
typographyProps?: TypographyProps;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const StatusIndicator = React.forwardRef<HTMLDivElement, Props>(
|
|
13
|
+
({ children, status, badgeProps, typographyProps, ...rest }: Props, ref) => {
|
|
14
|
+
return (
|
|
15
|
+
<div {...rest} className={classes['status-indicator']} ref={ref}>
|
|
16
|
+
<div
|
|
17
|
+
className={`${classes['status-badge']} ${classes[status]} ${badgeProps?.className ?? ''}`}
|
|
18
|
+
/>
|
|
19
|
+
<Typography {...typographyProps} spacing={{ margin: '0' }} variant="body" tag="div">
|
|
20
|
+
{typographyProps?.children || children}
|
|
21
|
+
</Typography>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
);
|
package/src/Tiles/Tile.test.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useRef } from 'react';
|
|
2
2
|
import { Tile, Props } from './Tile';
|
|
3
|
-
import { render
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
4
|
import { Icon, Icons } from '../Icon/Icon';
|
|
5
5
|
import { ContextMenu } from '../ContextMenu/ContextMenu';
|
|
6
6
|
import { IconButton } from '../Button/IconButton';
|
|
@@ -130,9 +130,9 @@ describe('contextmenu', () => {
|
|
|
130
130
|
expect(popover).toHaveClass('show');
|
|
131
131
|
expect(popover).toHaveStyle({ opacity: '1;' });
|
|
132
132
|
|
|
133
|
-
userEvent.click(
|
|
134
|
-
userEvent.click(
|
|
135
|
-
userEvent.click(
|
|
133
|
+
userEvent.click(menuitem1);
|
|
134
|
+
userEvent.click(menuitem2);
|
|
135
|
+
userEvent.click(menuitem3);
|
|
136
136
|
|
|
137
137
|
expect(contextMenuItemOnClick).toHaveBeenCalledTimes(3);
|
|
138
138
|
});
|