@onewelcome/react-lib-components 0.1.7-alpha → 0.1.10-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/DataGrid/DataGrid.d.ts +32 -0
- package/dist/DataGrid/DataGridActions/DataGridActions.d.ts +14 -0
- package/dist/DataGrid/DataGridActions/DataGridColumnsToggle.d.ts +13 -0
- package/dist/DataGrid/DataGridBody/DataGridBody.d.ts +17 -0
- package/dist/DataGrid/DataGridBody/DataGridCell.d.ts +10 -0
- package/dist/DataGrid/DataGridBody/DataGridRow.d.ts +9 -0
- package/dist/DataGrid/DataGridHeader/DataGridHeader.d.ts +11 -0
- package/dist/DataGrid/DataGridHeader/DataGridHeaderCell.d.ts +10 -0
- package/dist/DataGrid/datagrid.interfaces.d.ts +13 -0
- package/dist/Form/Select/Option.d.ts +9 -4
- package/dist/Form/Select/Select.d.ts +8 -2
- package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +1 -1
- package/dist/Icon/Icon.d.ts +1 -0
- package/dist/Skeleton/Skeleton.d.ts +7 -0
- package/dist/_BaseStyling_/BaseStyling.d.ts +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/react-lib-components.cjs.development.js +1082 -279
- 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 +1079 -280
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +11 -13
- package/src/ContextMenu/ContextMenu.tsx +16 -1
- package/src/DataGrid/DataGrid.module.scss +25 -0
- package/src/DataGrid/DataGrid.test.tsx +421 -0
- package/src/DataGrid/DataGrid.tsx +157 -0
- package/src/DataGrid/DataGridActions/DataGridActions.module.scss +35 -0
- package/src/DataGrid/DataGridActions/DataGridActions.test.tsx +184 -0
- package/src/DataGrid/DataGridActions/DataGridActions.tsx +109 -0
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.module.scss +41 -0
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +83 -0
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.tsx +88 -0
- package/src/DataGrid/DataGridBody/DataGridBody.module.scss +10 -0
- package/src/DataGrid/DataGridBody/DataGridBody.test.tsx +123 -0
- package/src/DataGrid/DataGridBody/DataGridBody.tsx +80 -0
- package/src/DataGrid/DataGridBody/DataGridCell.module.scss +33 -0
- package/src/DataGrid/DataGridBody/DataGridCell.test.tsx +74 -0
- package/src/DataGrid/DataGridBody/DataGridCell.tsx +58 -0
- package/src/DataGrid/DataGridBody/DataGridRow.module.scss +7 -0
- package/src/DataGrid/DataGridBody/DataGridRow.test.tsx +101 -0
- package/src/DataGrid/DataGridBody/DataGridRow.tsx +42 -0
- package/src/DataGrid/DataGridBody/__snapshots__/DataGridBody.test.tsx.snap +258 -0
- package/src/DataGrid/DataGridHeader/DataGridHeader.module.scss +26 -0
- package/src/DataGrid/DataGridHeader/DataGridHeader.test.tsx +255 -0
- package/src/DataGrid/DataGridHeader/DataGridHeader.tsx +103 -0
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.module.scss +68 -0
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +128 -0
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.tsx +72 -0
- package/src/DataGrid/datagrid.interfaces.ts +14 -0
- package/src/Form/Select/Option.tsx +39 -21
- package/src/Form/Select/Select.module.scss +1 -1
- package/src/Form/Select/Select.test.tsx +235 -56
- package/src/Form/Select/Select.tsx +194 -34
- package/src/Form/Toggle/Toggle.module.scss +1 -0
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +44 -0
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +4 -2
- package/src/Form/Wrapper/Wrapper/Wrapper.module.scss +1 -0
- package/src/Icon/Icon.module.scss +4 -0
- package/src/Icon/Icon.tsx +1 -0
- package/src/Notifications/BaseModal/BaseModal.module.scss +1 -1
- package/src/Notifications/BaseModal/BaseModal.test.tsx +2 -1
- package/src/Notifications/Dialog/Dialog.module.scss +1 -1
- package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.module.scss +1 -1
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.scss +1 -1
- package/src/Pagination/Pagination.module.scss +74 -74
- package/src/Pagination/Pagination.tsx +22 -8
- package/src/Skeleton/Skeleton.module.scss +20 -0
- package/src/Skeleton/Skeleton.test.tsx +96 -0
- package/src/Skeleton/Skeleton.tsx +29 -0
- package/src/_BaseStyling_/BaseStyling.tsx +10 -6
- package/src/index.ts +7 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
.actions {
|
|
2
|
+
margin-bottom: 1rem;
|
|
3
|
+
padding: 0 1rem;
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-wrap: wrap;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.left-actions {
|
|
9
|
+
flex: 1;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.right-actions {
|
|
13
|
+
display: flex;
|
|
14
|
+
gap: 1rem;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.desktop {
|
|
18
|
+
display: none;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@media only screen and (min-width: 50em) {
|
|
22
|
+
.actions {
|
|
23
|
+
padding: 0 1.25rem;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@media only screen and (min-width: 30em) {
|
|
28
|
+
.desktop {
|
|
29
|
+
display: block;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.mobile {
|
|
33
|
+
display: none;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { DataGridActions, Props } from './DataGridActions';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
5
|
+
|
|
6
|
+
const defaultParams: Props = {
|
|
7
|
+
headers: [],
|
|
8
|
+
onColumnToggled: jest.fn(),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const createDataGridActions = (params?: (defaultParams: Props) => Props) => {
|
|
12
|
+
let parameters: Props = defaultParams;
|
|
13
|
+
if (params) {
|
|
14
|
+
parameters = params(defaultParams);
|
|
15
|
+
}
|
|
16
|
+
const queries = render(<DataGridActions {...parameters} data-testid="dataGridActions" />);
|
|
17
|
+
const dataGridActions = queries.getByTestId('dataGridActions');
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
...queries,
|
|
21
|
+
dataGridActions,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('DataGridActions should render', () => {
|
|
26
|
+
it('renders without crashing', () => {
|
|
27
|
+
const { container } = render(<DataGridActions {...defaultParams} />);
|
|
28
|
+
|
|
29
|
+
expect(container).toBeEmptyDOMElement();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('renders all buttons', () => {
|
|
33
|
+
const { dataGridActions, getAllByRole } = createDataGridActions((params) => ({
|
|
34
|
+
...params,
|
|
35
|
+
enableAddBtn: true,
|
|
36
|
+
enableColumnsBtn: true,
|
|
37
|
+
enableSearchBtn: true,
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
expect(dataGridActions).toBeDefined();
|
|
41
|
+
const buttons = getAllByRole('button');
|
|
42
|
+
expect(buttons).toHaveLength(5);
|
|
43
|
+
expect(buttons[0]).toHaveTextContent('Add item');
|
|
44
|
+
expect(buttons[1]).toHaveTextContent('Columns');
|
|
45
|
+
expect(buttons[2]).toHaveTextContent('Show/hide columns');
|
|
46
|
+
expect(buttons[3]).toHaveTextContent('Search');
|
|
47
|
+
expect(buttons[4]).toHaveTextContent('Search');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('renders only add button', () => {
|
|
51
|
+
const { dataGridActions, getAllByRole } = createDataGridActions((params) => ({
|
|
52
|
+
...params,
|
|
53
|
+
enableAddBtn: true,
|
|
54
|
+
}));
|
|
55
|
+
|
|
56
|
+
expect(dataGridActions).toBeDefined();
|
|
57
|
+
const buttons = getAllByRole('button');
|
|
58
|
+
expect(buttons).toHaveLength(1);
|
|
59
|
+
expect(buttons[0]).toHaveTextContent('Add item');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('renders only columns button', () => {
|
|
63
|
+
const { dataGridActions, getAllByRole } = createDataGridActions((params) => ({
|
|
64
|
+
...params,
|
|
65
|
+
enableColumnsBtn: true,
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
expect(dataGridActions).toBeDefined();
|
|
69
|
+
const buttons = getAllByRole('button');
|
|
70
|
+
expect(buttons).toHaveLength(2);
|
|
71
|
+
expect(buttons[0]).toHaveTextContent('Columns');
|
|
72
|
+
expect(buttons[1]).toHaveTextContent('Show/hide columns');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('renders only search button', () => {
|
|
76
|
+
const { dataGridActions, getAllByRole } = createDataGridActions((params) => ({
|
|
77
|
+
...params,
|
|
78
|
+
enableSearchBtn: true,
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
expect(dataGridActions).toBeDefined();
|
|
82
|
+
const buttons = getAllByRole('button');
|
|
83
|
+
expect(buttons).toHaveLength(2);
|
|
84
|
+
expect(buttons[0]).toHaveTextContent('Search');
|
|
85
|
+
expect(buttons[1]).toHaveTextContent('Search');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('renders buttons with overwritten props', () => {
|
|
89
|
+
const addBtnProps = { children: 'button1', title: 'title1' };
|
|
90
|
+
const columnsBtnProps = { children: 'button2', title: 'title2' };
|
|
91
|
+
const searchBtnProps = { children: 'button3', title: 'title3' };
|
|
92
|
+
const { dataGridActions, getAllByRole } = createDataGridActions((params) => ({
|
|
93
|
+
...params,
|
|
94
|
+
enableAddBtn: true,
|
|
95
|
+
enableColumnsBtn: true,
|
|
96
|
+
enableSearchBtn: true,
|
|
97
|
+
addBtnProps,
|
|
98
|
+
columnsBtnProps,
|
|
99
|
+
searchBtnProps,
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
expect(dataGridActions).toBeDefined();
|
|
103
|
+
const [addBtn, desktopColumnsBtn, mobileColumnsBtn, desktopSearchBtn, mobileSearchBtn] =
|
|
104
|
+
getAllByRole('button');
|
|
105
|
+
expect(addBtn).toHaveTextContent(addBtnProps.children);
|
|
106
|
+
expect(addBtn).toHaveAttribute('title', addBtnProps.title);
|
|
107
|
+
expect(desktopColumnsBtn).toHaveTextContent(columnsBtnProps.children);
|
|
108
|
+
expect(desktopColumnsBtn).toHaveAttribute('title', columnsBtnProps.title);
|
|
109
|
+
expect(mobileColumnsBtn).toHaveTextContent(columnsBtnProps.title);
|
|
110
|
+
expect(desktopSearchBtn).toHaveTextContent(searchBtnProps.children);
|
|
111
|
+
expect(desktopSearchBtn).toHaveAttribute('title', searchBtnProps.title);
|
|
112
|
+
expect(mobileSearchBtn).toHaveTextContent(searchBtnProps.title);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('DataGridActions should be interactive', () => {
|
|
117
|
+
it('clicking on columns button opens show/hide columns popover', async () => {
|
|
118
|
+
const toggleHeader = { name: 'test', headline: 'Label' };
|
|
119
|
+
const { getAllByRole, findByLabelText } = createDataGridActions((params) => ({
|
|
120
|
+
...params,
|
|
121
|
+
enableColumnsBtn: true,
|
|
122
|
+
headers: [toggleHeader],
|
|
123
|
+
}));
|
|
124
|
+
|
|
125
|
+
userEvent.click(getAllByRole('button')[0]);
|
|
126
|
+
|
|
127
|
+
const toggle = await findByLabelText(toggleHeader.headline);
|
|
128
|
+
expect(toggle).toBeDefined();
|
|
129
|
+
expect(toggle).toBeChecked();
|
|
130
|
+
|
|
131
|
+
userEvent.click(toggle);
|
|
132
|
+
expect(defaultParams.onColumnToggled).toBeCalledWith(toggleHeader.name);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('clicking on add button runs callback', () => {
|
|
136
|
+
const onClick = jest.fn();
|
|
137
|
+
const { getAllByRole } = createDataGridActions((params) => ({
|
|
138
|
+
...params,
|
|
139
|
+
enableAddBtn: true,
|
|
140
|
+
addBtnProps: { onClick },
|
|
141
|
+
}));
|
|
142
|
+
|
|
143
|
+
userEvent.click(getAllByRole('button')[0]);
|
|
144
|
+
|
|
145
|
+
expect(onClick).toBeCalledTimes(1);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('clicking on search button runs callback', () => {
|
|
149
|
+
const onClick = jest.fn();
|
|
150
|
+
const { getAllByRole } = createDataGridActions((params) => ({
|
|
151
|
+
...params,
|
|
152
|
+
enableSearchBtn: true,
|
|
153
|
+
searchBtnProps: { onClick },
|
|
154
|
+
}));
|
|
155
|
+
|
|
156
|
+
userEvent.click(getAllByRole('button')[0]);
|
|
157
|
+
|
|
158
|
+
expect(onClick).toBeCalledTimes(1);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe('ref should work', () => {
|
|
163
|
+
it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
|
|
164
|
+
const ExampleComponent = ({
|
|
165
|
+
propagateRef,
|
|
166
|
+
}: {
|
|
167
|
+
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
168
|
+
}) => {
|
|
169
|
+
const ref = useRef(null);
|
|
170
|
+
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
propagateRef(ref);
|
|
173
|
+
}, [ref]);
|
|
174
|
+
|
|
175
|
+
return <DataGridActions {...defaultParams} data-ref="testing" enableAddBtn ref={ref} />;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
179
|
+
expect(ref.current).toHaveAttribute('data-ref', 'testing');
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
render(<ExampleComponent propagateRef={refCheck} />);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React, { ComponentPropsWithRef, Fragment, useRef, useState } from 'react';
|
|
2
|
+
import { Button, Props as ButtonProps } from '../../Button/Button';
|
|
3
|
+
import { IconButton } from '../../Button/IconButton';
|
|
4
|
+
import { Icon, Icons } from '../../Icon/Icon';
|
|
5
|
+
import { HeaderCell, ColumnName } from '../datagrid.interfaces';
|
|
6
|
+
import classes from './DataGridActions.module.scss';
|
|
7
|
+
import { DataGridColumnsToggle } from './DataGridColumnsToggle';
|
|
8
|
+
|
|
9
|
+
export interface Props extends ComponentPropsWithRef<'div'> {
|
|
10
|
+
enableAddBtn?: boolean;
|
|
11
|
+
enableColumnsBtn?: boolean;
|
|
12
|
+
enableSearchBtn?: boolean;
|
|
13
|
+
addBtnProps?: ButtonProps;
|
|
14
|
+
columnsBtnProps?: ButtonProps;
|
|
15
|
+
searchBtnProps?: ButtonProps;
|
|
16
|
+
headers: HeaderCell[];
|
|
17
|
+
onColumnToggled: (colName: ColumnName) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const DataGridActions = React.forwardRef<HTMLDivElement, Props>(
|
|
21
|
+
(
|
|
22
|
+
{
|
|
23
|
+
className,
|
|
24
|
+
enableAddBtn,
|
|
25
|
+
enableColumnsBtn,
|
|
26
|
+
enableSearchBtn,
|
|
27
|
+
addBtnProps = {},
|
|
28
|
+
columnsBtnProps = {},
|
|
29
|
+
searchBtnProps = {},
|
|
30
|
+
headers,
|
|
31
|
+
onColumnToggled,
|
|
32
|
+
...rest
|
|
33
|
+
}: Props,
|
|
34
|
+
ref
|
|
35
|
+
) => {
|
|
36
|
+
const isHidden = !(enableAddBtn || enableColumnsBtn || enableSearchBtn);
|
|
37
|
+
const [showColsPopover, setShowColsPopover] = useState(false);
|
|
38
|
+
const showColumnBtn = useRef<HTMLButtonElement>(null);
|
|
39
|
+
|
|
40
|
+
return isHidden ? null : (
|
|
41
|
+
<div {...rest} ref={ref} className={`${classes['actions']} ${className ?? ''}`}>
|
|
42
|
+
<div className={classes['left-actions']}>
|
|
43
|
+
{enableAddBtn && (
|
|
44
|
+
<Button
|
|
45
|
+
color="primary"
|
|
46
|
+
startIcon={<Icon icon={Icons.Plus} />}
|
|
47
|
+
title="Add item"
|
|
48
|
+
type="button"
|
|
49
|
+
variant="outline"
|
|
50
|
+
children="Add item"
|
|
51
|
+
{...addBtnProps}
|
|
52
|
+
/>
|
|
53
|
+
)}
|
|
54
|
+
</div>
|
|
55
|
+
<div className={classes['right-actions']}>
|
|
56
|
+
{enableColumnsBtn && (
|
|
57
|
+
<Fragment>
|
|
58
|
+
<Button
|
|
59
|
+
startIcon={<Icon icon={Icons.Change} />}
|
|
60
|
+
title="Show/hide columns"
|
|
61
|
+
variant="text"
|
|
62
|
+
children="Columns"
|
|
63
|
+
{...columnsBtnProps}
|
|
64
|
+
className={`${classes['desktop']} ${columnsBtnProps?.className ?? ''}`}
|
|
65
|
+
ref={showColumnBtn}
|
|
66
|
+
onClick={() => setShowColsPopover(true)}
|
|
67
|
+
/>
|
|
68
|
+
<IconButton
|
|
69
|
+
title="Show/hide columns"
|
|
70
|
+
{...columnsBtnProps}
|
|
71
|
+
onClick={() => setShowColsPopover(true)}
|
|
72
|
+
className={`${classes['mobile']} ${columnsBtnProps?.className ?? ''}`}
|
|
73
|
+
>
|
|
74
|
+
<Icon icon={Icons.Change} />
|
|
75
|
+
</IconButton>
|
|
76
|
+
<DataGridColumnsToggle
|
|
77
|
+
aria-hidden={!showColsPopover}
|
|
78
|
+
open={showColsPopover}
|
|
79
|
+
headers={headers}
|
|
80
|
+
onClose={() => setShowColsPopover(false)}
|
|
81
|
+
onToggleClicked={onColumnToggled}
|
|
82
|
+
anchorEl={showColumnBtn}
|
|
83
|
+
/>
|
|
84
|
+
</Fragment>
|
|
85
|
+
)}
|
|
86
|
+
{enableSearchBtn && (
|
|
87
|
+
<Fragment>
|
|
88
|
+
<Button
|
|
89
|
+
startIcon={<Icon icon={Icons.TableSearch} />}
|
|
90
|
+
title="Search"
|
|
91
|
+
variant="text"
|
|
92
|
+
children="Search"
|
|
93
|
+
{...searchBtnProps}
|
|
94
|
+
className={`${classes['desktop']} ${searchBtnProps?.className ?? ''}`}
|
|
95
|
+
/>
|
|
96
|
+
<IconButton
|
|
97
|
+
title="Search"
|
|
98
|
+
{...searchBtnProps}
|
|
99
|
+
className={`${classes['mobile']} ${columnsBtnProps?.className ?? ''}`}
|
|
100
|
+
>
|
|
101
|
+
<Icon icon={Icons.TableSearch} />
|
|
102
|
+
</IconButton>
|
|
103
|
+
</Fragment>
|
|
104
|
+
)}
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
.popover {
|
|
2
|
+
background-color: var(--modal-background-color);
|
|
3
|
+
z-index: 1;
|
|
4
|
+
min-width: 17.5rem;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.backdrop {
|
|
8
|
+
content: '';
|
|
9
|
+
position: absolute;
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 100%;
|
|
12
|
+
left: 0;
|
|
13
|
+
top: 0;
|
|
14
|
+
background-color: transparent;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.header {
|
|
18
|
+
min-width: 5rem;
|
|
19
|
+
padding: 1rem 0.5rem 1rem 1.5rem;
|
|
20
|
+
background-color: var(--modal-header-background-color);
|
|
21
|
+
border-top-left-radius: 0.5rem;
|
|
22
|
+
border-top-right-radius: 0.5rem;
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.title {
|
|
28
|
+
flex: 1;
|
|
29
|
+
margin: 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.close-btn {
|
|
33
|
+
margin-left: 0.5rem;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.content {
|
|
37
|
+
padding: 1.5rem;
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-direction: column;
|
|
40
|
+
gap: 1.25rem;
|
|
41
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { DataGridColumnsToggle, Props } from './DataGridColumnsToggle';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
5
|
+
|
|
6
|
+
const defaultParams: Props = {
|
|
7
|
+
open: true,
|
|
8
|
+
headers: [
|
|
9
|
+
{ headline: 'Name', name: 'name' },
|
|
10
|
+
{ headline: 'Date', name: 'date', hidden: true },
|
|
11
|
+
],
|
|
12
|
+
onClose: jest.fn(),
|
|
13
|
+
onToggleClicked: jest.fn(),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const createDataGridColumnsToggle = (params?: (defaultParams: Props) => Props) => {
|
|
17
|
+
let parameters: Props = defaultParams;
|
|
18
|
+
if (params) {
|
|
19
|
+
parameters = params(defaultParams);
|
|
20
|
+
}
|
|
21
|
+
const queries = render(
|
|
22
|
+
<DataGridColumnsToggle {...parameters} data-testid="dataGridColumnsToggle" />
|
|
23
|
+
);
|
|
24
|
+
const dataGridColumnsToggle = queries.getByTestId('dataGridColumnsToggle');
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
...queries,
|
|
28
|
+
dataGridColumnsToggle,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe('DataGridColumnsToggle should render', () => {
|
|
33
|
+
it('renders without crashing', () => {
|
|
34
|
+
const { dataGridColumnsToggle, getByLabelText, getByText } = createDataGridColumnsToggle();
|
|
35
|
+
|
|
36
|
+
expect(dataGridColumnsToggle).toBeDefined();
|
|
37
|
+
expect(getByText('Show columns')).toBeDefined();
|
|
38
|
+
expect(getByLabelText(defaultParams.headers[0].headline)).toBeChecked();
|
|
39
|
+
expect(getByLabelText(defaultParams.headers[1].headline)).not.toBeChecked();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('DataGridColumnsToggle should be interactive', () => {
|
|
44
|
+
it('clicking on close calls onClose callback', () => {
|
|
45
|
+
const { getByRole } = createDataGridColumnsToggle();
|
|
46
|
+
|
|
47
|
+
userEvent.click(getByRole('button'));
|
|
48
|
+
|
|
49
|
+
expect(defaultParams.onClose).toBeCalledTimes(1);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('clicking outside of container (on backdrop layer) calls onClose callback', () => {
|
|
53
|
+
createDataGridColumnsToggle();
|
|
54
|
+
|
|
55
|
+
userEvent.click(document.querySelector('.backdrop')!);
|
|
56
|
+
|
|
57
|
+
expect(defaultParams.onClose).toBeCalledTimes(1);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('ref should work', () => {
|
|
62
|
+
it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
|
|
63
|
+
const ExampleComponent = ({
|
|
64
|
+
propagateRef,
|
|
65
|
+
}: {
|
|
66
|
+
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
67
|
+
}) => {
|
|
68
|
+
const ref = useRef(null);
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
propagateRef(ref);
|
|
72
|
+
}, [ref]);
|
|
73
|
+
|
|
74
|
+
return <DataGridColumnsToggle {...defaultParams} data-ref="testing" ref={ref} />;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
78
|
+
expect(ref.current).toHaveAttribute('data-ref', 'testing');
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
render(<ExampleComponent propagateRef={refCheck} />);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React, { Fragment, useState } from 'react';
|
|
2
|
+
import { IconButton } from '../../Button/IconButton';
|
|
3
|
+
import { Toggle } from '../../Form/Toggle/Toggle';
|
|
4
|
+
import { Icon, Icons } from '../../Icon/Icon';
|
|
5
|
+
import { Popover, Props as PopoverProps } from '../../Popover/Popover';
|
|
6
|
+
import { Typography } from '../../Typography/Typography';
|
|
7
|
+
import { generateID } from '../../util/helper';
|
|
8
|
+
import { ColumnName, HeaderCell } from '../datagrid.interfaces';
|
|
9
|
+
import classes from './DataGridColumnsToggle.module.scss';
|
|
10
|
+
import { createPortal } from 'react-dom';
|
|
11
|
+
|
|
12
|
+
export interface Props extends PopoverProps {
|
|
13
|
+
open: boolean;
|
|
14
|
+
headers: HeaderCell[];
|
|
15
|
+
titleLabel?: string;
|
|
16
|
+
closeButtonTitle?: string;
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
onToggleClicked: (colName: ColumnName) => void;
|
|
19
|
+
domRoot?: HTMLElement;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const DataGridColumnsToggle = React.forwardRef<HTMLDivElement, Props>(
|
|
23
|
+
(
|
|
24
|
+
{
|
|
25
|
+
open,
|
|
26
|
+
headers,
|
|
27
|
+
titleLabel = 'Show columns',
|
|
28
|
+
closeButtonTitle = 'Close show columns dialog',
|
|
29
|
+
onClose,
|
|
30
|
+
onToggleClicked,
|
|
31
|
+
className,
|
|
32
|
+
domRoot = document.body,
|
|
33
|
+
...rest
|
|
34
|
+
}: Props,
|
|
35
|
+
ref
|
|
36
|
+
) => {
|
|
37
|
+
const [id] = useState(generateID());
|
|
38
|
+
const labelledId = id + '_header';
|
|
39
|
+
|
|
40
|
+
const toggles = headers.map((item) => (
|
|
41
|
+
<Toggle
|
|
42
|
+
key={item.name}
|
|
43
|
+
name={item.name}
|
|
44
|
+
checked={!item.hidden}
|
|
45
|
+
onChange={() => onToggleClicked(item.name)}
|
|
46
|
+
>
|
|
47
|
+
{item.headline}
|
|
48
|
+
</Toggle>
|
|
49
|
+
));
|
|
50
|
+
|
|
51
|
+
const handleBackdropClick = () => onClose();
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<Popover
|
|
55
|
+
{...rest}
|
|
56
|
+
ref={ref}
|
|
57
|
+
className={`${classes['popover']} ${className}`}
|
|
58
|
+
show={open}
|
|
59
|
+
role="dialog"
|
|
60
|
+
aria-modal="true"
|
|
61
|
+
aria-labelledby={labelledId}
|
|
62
|
+
>
|
|
63
|
+
{open &&
|
|
64
|
+
createPortal(
|
|
65
|
+
<div className={classes['backdrop']} onClick={handleBackdropClick}></div>,
|
|
66
|
+
domRoot
|
|
67
|
+
)}
|
|
68
|
+
{open && (
|
|
69
|
+
<Fragment>
|
|
70
|
+
<div className={classes['header']}>
|
|
71
|
+
<Typography id={labelledId} className={classes['title']} tag="span" variant="h4">
|
|
72
|
+
{titleLabel}
|
|
73
|
+
</Typography>
|
|
74
|
+
<IconButton
|
|
75
|
+
onClick={onClose}
|
|
76
|
+
className={`${classes['close-btn']}`}
|
|
77
|
+
title={closeButtonTitle}
|
|
78
|
+
>
|
|
79
|
+
<Icon icon={Icons.Times} />
|
|
80
|
+
</IconButton>
|
|
81
|
+
</div>
|
|
82
|
+
<div className={classes['content']}>{toggles}</div>
|
|
83
|
+
</Fragment>
|
|
84
|
+
)}
|
|
85
|
+
</Popover>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { DataGridBody, Props } from './DataGridBody';
|
|
3
|
+
import { render, getAllByRole } from '@testing-library/react';
|
|
4
|
+
import { DataGridRow } from './DataGridRow';
|
|
5
|
+
import { DataGridCell } from './DataGridCell';
|
|
6
|
+
import { ContextMenu } from '../../ContextMenu/ContextMenu';
|
|
7
|
+
import { IconButton } from '../../Button/IconButton';
|
|
8
|
+
import { Icon, Icons } from '../../Icon/Icon';
|
|
9
|
+
import { ContextMenuItem } from '../../ContextMenu/ContextMenuItem';
|
|
10
|
+
|
|
11
|
+
type DataType = { firstName: string; lastName: string; date: string };
|
|
12
|
+
|
|
13
|
+
const defaultParams: Props<DataType> = {
|
|
14
|
+
children: ({ item }) => (
|
|
15
|
+
<DataGridRow key={item.firstName}>
|
|
16
|
+
<DataGridCell>{item.firstName}</DataGridCell>
|
|
17
|
+
<DataGridCell>{item.lastName}</DataGridCell>
|
|
18
|
+
<DataGridCell>{item.date}</DataGridCell>
|
|
19
|
+
<DataGridCell>
|
|
20
|
+
<ContextMenu
|
|
21
|
+
id={`consent_menu_${item.firstName}`}
|
|
22
|
+
trigger={
|
|
23
|
+
<IconButton title={`Actions for ${item.firstName}`} color="default">
|
|
24
|
+
<Icon icon={Icons.EllipsisAlt} />
|
|
25
|
+
</IconButton>
|
|
26
|
+
}
|
|
27
|
+
>
|
|
28
|
+
<ContextMenuItem>Item 1</ContextMenuItem>
|
|
29
|
+
</ContextMenu>
|
|
30
|
+
</DataGridCell>
|
|
31
|
+
</DataGridRow>
|
|
32
|
+
),
|
|
33
|
+
headers: [
|
|
34
|
+
{ name: 'firstName', headline: 'First name' },
|
|
35
|
+
{ name: 'lastName', headline: 'Last name' },
|
|
36
|
+
{ name: 'date', headline: 'Date' },
|
|
37
|
+
],
|
|
38
|
+
data: [
|
|
39
|
+
{ firstName: 'Paweł', lastName: 'Napieracz', date: '12.12.1990' },
|
|
40
|
+
{ firstName: 'Michał', lastName: 'Górski', date: '12.12.1994' },
|
|
41
|
+
{ firstName: 'Daniel', lastName: 'Velden', date: '12.12.199x' },
|
|
42
|
+
{ firstName: 'Jasha', lastName: 'Joachimsthal', date: '12.12.198x' },
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const createDataGridBody = (params?: (defaultParams: Props<DataType>) => Props<DataType>) => {
|
|
47
|
+
let parameters = defaultParams;
|
|
48
|
+
if (params) {
|
|
49
|
+
parameters = params(defaultParams);
|
|
50
|
+
}
|
|
51
|
+
const container = document.createElement('table');
|
|
52
|
+
const queries = render(<DataGridBody {...parameters} data-testid="dataGridBody" />, {
|
|
53
|
+
container,
|
|
54
|
+
});
|
|
55
|
+
const dataGridBody = queries.getByTestId('dataGridBody');
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
...queries,
|
|
59
|
+
dataGridBody,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
describe('DataGridBody should render', () => {
|
|
64
|
+
it('renders without crashing', () => {
|
|
65
|
+
const { dataGridBody } = createDataGridBody();
|
|
66
|
+
|
|
67
|
+
expect(dataGridBody).toBeDefined();
|
|
68
|
+
const rows = getAllByRole(dataGridBody, 'row');
|
|
69
|
+
expect(rows).toMatchSnapshot();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('renders loading state with only visible columns', () => {
|
|
73
|
+
const headers = [...defaultParams.headers];
|
|
74
|
+
headers[0] = { ...headers[0], hidden: true };
|
|
75
|
+
const { dataGridBody } = createDataGridBody((params) => ({ ...params, headers }));
|
|
76
|
+
|
|
77
|
+
expect(dataGridBody).toBeDefined();
|
|
78
|
+
const rows = getAllByRole(dataGridBody, 'row');
|
|
79
|
+
const firstRowCells = getAllByRole(rows[0], 'cell');
|
|
80
|
+
expect(firstRowCells).toHaveLength(3);
|
|
81
|
+
expect(firstRowCells[0]).toHaveTextContent(defaultParams.data?.[0].lastName!);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('renders empty state', () => {
|
|
85
|
+
const emptyLabel = 'emptyLabel';
|
|
86
|
+
const { dataGridBody } = createDataGridBody((params) => ({
|
|
87
|
+
...params,
|
|
88
|
+
emptyLabel,
|
|
89
|
+
data: undefined,
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
const rows = getAllByRole(dataGridBody, 'row');
|
|
93
|
+
const firstRowCells = getAllByRole(rows[0], 'cell');
|
|
94
|
+
expect(firstRowCells).toHaveLength(1);
|
|
95
|
+
expect(firstRowCells[0]).toHaveAttribute('colspan', `${defaultParams.headers.length + 1}`);
|
|
96
|
+
expect(firstRowCells[0]).toHaveTextContent(emptyLabel);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('ref should work', () => {
|
|
101
|
+
it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
|
|
102
|
+
const ExampleComponent = ({
|
|
103
|
+
propagateRef,
|
|
104
|
+
}: {
|
|
105
|
+
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
106
|
+
}) => {
|
|
107
|
+
const ref = useRef(null);
|
|
108
|
+
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
propagateRef(ref);
|
|
111
|
+
}, [ref]);
|
|
112
|
+
|
|
113
|
+
return <DataGridBody {...defaultParams} data-ref="testing" ref={ref} />;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
117
|
+
expect(ref.current).toHaveAttribute('data-ref', 'testing');
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const container = document.createElement('table');
|
|
121
|
+
render(<ExampleComponent propagateRef={refCheck} />, { container });
|
|
122
|
+
});
|
|
123
|
+
});
|