@onewelcome/react-lib-components 0.1.6-alpha → 0.1.9-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/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/Checkbox/Checkbox.d.ts +2 -2
- package/dist/Form/Select/Option.d.ts +9 -4
- package/dist/Form/Select/Select.d.ts +8 -2
- package/dist/Form/Toggle/Toggle.d.ts +1 -1
- package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +1 -1
- package/dist/Icon/Icon.d.ts +1 -0
- 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/_BaseStyling_/BaseStyling.d.ts +4 -0
- package/dist/index.d.ts +48 -43
- package/dist/react-lib-components.cjs.development.js +3097 -2157
- 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 +3094 -2158
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +11 -13
- 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 +99 -6
- package/src/ContextMenu/ContextMenuItem.tsx +57 -9
- 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/Checkbox/Checkbox.test.tsx +144 -8
- package/src/Form/Checkbox/Checkbox.tsx +8 -8
- 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/Toggle/Toggle.tsx +1 -1
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +1 -1
- 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/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.module.scss +1 -1
- package/src/Notifications/BaseModal/BaseModal.test.tsx +77 -12
- package/src/Notifications/BaseModal/BaseModal.tsx +27 -6
- package/src/Notifications/Dialog/Dialog.module.scss +1 -1
- 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/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/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/_BaseStyling_/BaseStyling.tsx +14 -6
- package/src/index.ts +85 -48
- package/src/mixins.module.scss +171 -0
- package/src/readyclasses.module.scss +0 -30
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React, { ComponentPropsWithRef, ReactElement, Ref } from 'react';
|
|
2
|
+
import { HeaderCell } from '../datagrid.interfaces';
|
|
3
|
+
import { DataGridCell } from './DataGridCell';
|
|
4
|
+
import { DataGridRow } from './DataGridRow';
|
|
5
|
+
import classes from './DataGridBody.module.scss';
|
|
6
|
+
import { Typography } from '../../Typography/Typography';
|
|
7
|
+
|
|
8
|
+
export interface Props<T> extends ComponentPropsWithRef<'tbody'> {
|
|
9
|
+
children: ({ item, index }: { item: T; index: number }) => ReactElement;
|
|
10
|
+
data?: T[];
|
|
11
|
+
headers: HeaderCell[];
|
|
12
|
+
isLoading?: boolean;
|
|
13
|
+
disableContextMenuColumn?: boolean;
|
|
14
|
+
emptyLabel?: string;
|
|
15
|
+
spacing?: React.CSSProperties;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const skeletonLoadingRows = 9;
|
|
19
|
+
|
|
20
|
+
const DataGridBodyInner = <T extends {}>(
|
|
21
|
+
{
|
|
22
|
+
children,
|
|
23
|
+
data,
|
|
24
|
+
headers,
|
|
25
|
+
isLoading,
|
|
26
|
+
disableContextMenuColumn,
|
|
27
|
+
emptyLabel,
|
|
28
|
+
spacing,
|
|
29
|
+
...rest
|
|
30
|
+
}: Props<T>,
|
|
31
|
+
ref: Ref<HTMLTableSectionElement>
|
|
32
|
+
) => {
|
|
33
|
+
const renderContent = () => {
|
|
34
|
+
const visibleColumns = headers.filter((header) => !header.hidden).length;
|
|
35
|
+
if (isLoading) {
|
|
36
|
+
return Array.from(Array(skeletonLoadingRows)).map((_, rowIdx) => (
|
|
37
|
+
<DataGridRow key={rowIdx} isLoading>
|
|
38
|
+
{Array.from(Array(visibleColumns)).map((__, colIdx) => (
|
|
39
|
+
<DataGridCell key={colIdx} isLoading></DataGridCell>
|
|
40
|
+
))}
|
|
41
|
+
{!disableContextMenuColumn && <DataGridCell></DataGridCell>}
|
|
42
|
+
</DataGridRow>
|
|
43
|
+
));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const emptyData = !data || data.length === 0;
|
|
47
|
+
if (emptyData) {
|
|
48
|
+
return (
|
|
49
|
+
<tr>
|
|
50
|
+
<td
|
|
51
|
+
className={classes['empty']}
|
|
52
|
+
colSpan={visibleColumns + (disableContextMenuColumn ? 0 : 1)}
|
|
53
|
+
>
|
|
54
|
+
<Typography variant="body" spacing={{ margin: 0 }}>
|
|
55
|
+
{emptyLabel}
|
|
56
|
+
</Typography>
|
|
57
|
+
</td>
|
|
58
|
+
</tr>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return data?.map((item, index) => {
|
|
63
|
+
return React.cloneElement(children({ item, index }), {
|
|
64
|
+
headers,
|
|
65
|
+
spacing,
|
|
66
|
+
disableContextMenuColumn,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<tbody {...rest} ref={ref}>
|
|
73
|
+
{renderContent()}
|
|
74
|
+
</tbody>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const DataGridBody = React.forwardRef(DataGridBodyInner) as <T extends {}>(
|
|
79
|
+
p: Props<T> & { ref?: Ref<HTMLTableSectionElement> }
|
|
80
|
+
) => ReactElement;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
@import '../../mixins.module.scss';
|
|
2
|
+
|
|
3
|
+
.cell {
|
|
4
|
+
min-height: 3.5rem;
|
|
5
|
+
padding: 0.5rem 0.625rem;
|
|
6
|
+
|
|
7
|
+
&:first-child {
|
|
8
|
+
padding-left: 1rem;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&:last-child {
|
|
12
|
+
padding-right: 1rem;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.loading {
|
|
16
|
+
@include skeletonLoading();
|
|
17
|
+
border-radius: 0.5rem;
|
|
18
|
+
height: 1.25rem;
|
|
19
|
+
margin: 0.625rem 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@media only screen and (min-width: 50em) {
|
|
24
|
+
.cell {
|
|
25
|
+
&:first-child {
|
|
26
|
+
padding-left: 1.25rem;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&:last-child {
|
|
30
|
+
padding-right: 1.25rem;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { DataGridCell, Props } from './DataGridCell';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
const defaultParams: Props = {
|
|
6
|
+
children: 'cell',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const createDataGridCell = (params?: (defaultParams: Props) => Props) => {
|
|
10
|
+
let parameters: Props = defaultParams;
|
|
11
|
+
if (params) {
|
|
12
|
+
parameters = params(defaultParams);
|
|
13
|
+
}
|
|
14
|
+
const container = document.createElement('tr');
|
|
15
|
+
const queries = render(<DataGridCell {...parameters} data-testid="dataGridCell" />, {
|
|
16
|
+
container,
|
|
17
|
+
});
|
|
18
|
+
const dataGridCell = queries.getByTestId('dataGridCell');
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
...queries,
|
|
22
|
+
dataGridCell,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('DataGridCell should render', () => {
|
|
27
|
+
it('renders without crashing', () => {
|
|
28
|
+
const { dataGridCell } = createDataGridCell();
|
|
29
|
+
|
|
30
|
+
expect(dataGridCell).toBeDefined();
|
|
31
|
+
expect(dataGridCell).toHaveClass('cell');
|
|
32
|
+
expect(dataGridCell).toHaveTextContent(defaultParams.children as string);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('renders with additional class', () => {
|
|
36
|
+
const { dataGridCell } = createDataGridCell((params) => ({ ...params, className: 'test' }));
|
|
37
|
+
|
|
38
|
+
expect(dataGridCell).toHaveClass('cell', 'test');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('renders loading state', () => {
|
|
42
|
+
const { dataGridCell } = createDataGridCell((params) => ({ ...params, isLoading: true }));
|
|
43
|
+
|
|
44
|
+
const skeletonLoadingEl = dataGridCell.querySelector('div');
|
|
45
|
+
expect(skeletonLoadingEl).toHaveClass('loading');
|
|
46
|
+
expect(skeletonLoadingEl).toHaveAttribute('aria-busy', 'true');
|
|
47
|
+
expect(skeletonLoadingEl).toHaveAttribute('aria-live', 'polite');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('ref should work', () => {
|
|
52
|
+
it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
|
|
53
|
+
const ExampleComponent = ({
|
|
54
|
+
propagateRef,
|
|
55
|
+
}: {
|
|
56
|
+
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
57
|
+
}) => {
|
|
58
|
+
const ref = useRef(null);
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
propagateRef(ref);
|
|
62
|
+
}, [ref]);
|
|
63
|
+
|
|
64
|
+
return <DataGridCell {...defaultParams} data-ref="testing" ref={ref} />;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
68
|
+
expect(ref.current).toHaveAttribute('data-ref', 'testing');
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const container = document.createElement('tr');
|
|
72
|
+
render(<ExampleComponent propagateRef={refCheck} />, { container });
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React, { ComponentPropsWithRef, ReactChild } from 'react';
|
|
2
|
+
import { Typography } from '../../Typography/Typography';
|
|
3
|
+
import classes from './DataGridCell.module.scss';
|
|
4
|
+
|
|
5
|
+
export interface Props extends ComponentPropsWithRef<'td'> {
|
|
6
|
+
children?: ReactChild;
|
|
7
|
+
isLoading?: boolean;
|
|
8
|
+
spacing?: React.CSSProperties;
|
|
9
|
+
cellIndex?: number;
|
|
10
|
+
columnLength?: number;
|
|
11
|
+
disableContextMenuColumn?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const DataGridCell = React.forwardRef<HTMLTableCellElement, Props>(
|
|
15
|
+
(
|
|
16
|
+
{
|
|
17
|
+
children,
|
|
18
|
+
className,
|
|
19
|
+
isLoading,
|
|
20
|
+
spacing,
|
|
21
|
+
cellIndex,
|
|
22
|
+
columnLength,
|
|
23
|
+
disableContextMenuColumn,
|
|
24
|
+
...rest
|
|
25
|
+
}: Props,
|
|
26
|
+
ref
|
|
27
|
+
) => {
|
|
28
|
+
let cellStyle: React.CSSProperties = {};
|
|
29
|
+
|
|
30
|
+
if (cellIndex === 0) {
|
|
31
|
+
cellStyle.paddingLeft = spacing?.paddingLeft;
|
|
32
|
+
}
|
|
33
|
+
if (
|
|
34
|
+
(cellIndex === columnLength && !disableContextMenuColumn) ||
|
|
35
|
+
(columnLength && cellIndex === columnLength - 1 && disableContextMenuColumn)
|
|
36
|
+
) {
|
|
37
|
+
cellStyle.paddingRight = spacing?.paddingRight;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<td
|
|
42
|
+
{...rest}
|
|
43
|
+
ref={ref}
|
|
44
|
+
style={{ ...rest.style, ...cellStyle }}
|
|
45
|
+
className={`${classes['cell']} ${className ?? ''}`}
|
|
46
|
+
>
|
|
47
|
+
{isLoading && (
|
|
48
|
+
<div className={classes['loading']} aria-busy="true" aria-live="polite"></div>
|
|
49
|
+
)}
|
|
50
|
+
{!isLoading && (
|
|
51
|
+
<Typography variant="body" tag="span">
|
|
52
|
+
{children}
|
|
53
|
+
</Typography>
|
|
54
|
+
)}
|
|
55
|
+
</td>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
);
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { DataGridRow, Props } from './DataGridRow';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import { DataGridCell } from './DataGridCell';
|
|
5
|
+
|
|
6
|
+
const defaultParams: Props = {
|
|
7
|
+
children: [<DataGridCell>1</DataGridCell>, <DataGridCell>2</DataGridCell>],
|
|
8
|
+
headers: [
|
|
9
|
+
{ name: 'firstName', headline: 'first name' },
|
|
10
|
+
{ name: 'lastName', headline: 'last name' },
|
|
11
|
+
],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const createDataGridRow = (params?: (defaultParams: Props) => Props) => {
|
|
15
|
+
let parameters: Props = defaultParams;
|
|
16
|
+
if (params) {
|
|
17
|
+
parameters = params(defaultParams);
|
|
18
|
+
}
|
|
19
|
+
const container = document.createElement('tbody');
|
|
20
|
+
const queries = render(<DataGridRow {...parameters} data-testid="dataGridRow" />, { container });
|
|
21
|
+
const dataGridRow = queries.getByTestId('dataGridRow');
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
...queries,
|
|
25
|
+
dataGridRow,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
describe('DataGridRow should render', () => {
|
|
30
|
+
it('renders without crashing', () => {
|
|
31
|
+
const { dataGridRow, getAllByRole } = createDataGridRow();
|
|
32
|
+
|
|
33
|
+
expect(dataGridRow).toBeDefined();
|
|
34
|
+
expect(dataGridRow).toHaveClass('row', { exact: true });
|
|
35
|
+
const cells = getAllByRole('cell');
|
|
36
|
+
expect(cells).toHaveLength(2);
|
|
37
|
+
expect(cells[0]).toHaveTextContent('1');
|
|
38
|
+
expect(cells[1]).toHaveTextContent('2');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('renders with additional class', () => {
|
|
42
|
+
const { dataGridRow } = createDataGridRow((params) => ({ ...params, className: 'test' }));
|
|
43
|
+
|
|
44
|
+
expect(dataGridRow).toHaveClass('row test', { exact: true });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('renders loading state', () => {
|
|
48
|
+
const { dataGridRow } = createDataGridRow((params) => ({ ...params, isLoading: true }));
|
|
49
|
+
|
|
50
|
+
expect(dataGridRow).toHaveClass('row loading', { exact: true });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('renders only visible columns', () => {
|
|
54
|
+
const { dataGridRow, getAllByRole } = createDataGridRow((params) => ({
|
|
55
|
+
...params,
|
|
56
|
+
headers: [
|
|
57
|
+
{ name: 'firstName', headline: 'first name', hidden: true },
|
|
58
|
+
{ name: 'lastName', headline: 'last name', hidden: true },
|
|
59
|
+
{ name: 'date', headline: 'date' },
|
|
60
|
+
{ name: 'status', headline: 'status' },
|
|
61
|
+
],
|
|
62
|
+
children: [
|
|
63
|
+
<DataGridCell>1</DataGridCell>,
|
|
64
|
+
<DataGridCell>2</DataGridCell>,
|
|
65
|
+
<DataGridCell>3</DataGridCell>,
|
|
66
|
+
<DataGridCell>4</DataGridCell>,
|
|
67
|
+
],
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
expect(dataGridRow).toBeDefined();
|
|
71
|
+
const cells = getAllByRole('cell');
|
|
72
|
+
expect(cells).toHaveLength(2);
|
|
73
|
+
expect(cells[0]).toHaveTextContent('3');
|
|
74
|
+
expect(cells[1]).toHaveTextContent('4');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('ref should work', () => {
|
|
79
|
+
it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
|
|
80
|
+
const ExampleComponent = ({
|
|
81
|
+
propagateRef,
|
|
82
|
+
}: {
|
|
83
|
+
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
84
|
+
}) => {
|
|
85
|
+
const ref = useRef(null);
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
propagateRef(ref);
|
|
89
|
+
}, [ref]);
|
|
90
|
+
|
|
91
|
+
return <DataGridRow {...defaultParams} data-ref="testing" ref={ref} />;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
95
|
+
expect(ref.current).toHaveAttribute('data-ref', 'testing');
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const container = document.createElement('tbody');
|
|
99
|
+
render(<ExampleComponent propagateRef={refCheck} />, { container });
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { ComponentPropsWithRef } from 'react';
|
|
2
|
+
import { HeaderCell } from '../datagrid.interfaces';
|
|
3
|
+
import classes from './DataGridRow.module.scss';
|
|
4
|
+
|
|
5
|
+
export interface Props extends ComponentPropsWithRef<'tr'> {
|
|
6
|
+
headers?: HeaderCell[];
|
|
7
|
+
isLoading?: boolean;
|
|
8
|
+
spacing?: React.CSSProperties;
|
|
9
|
+
disableContextMenuColumn?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const DataGridRow = React.forwardRef<HTMLTableRowElement, Props>(
|
|
13
|
+
(
|
|
14
|
+
{ children, className, headers, isLoading, spacing, disableContextMenuColumn, ...rest }: Props,
|
|
15
|
+
ref
|
|
16
|
+
) => {
|
|
17
|
+
const visibleCells = React.Children.map(children as React.ReactElement[], (child, index) => {
|
|
18
|
+
if (child) {
|
|
19
|
+
const cellWithSpacing = React.cloneElement(child, {
|
|
20
|
+
spacing: spacing,
|
|
21
|
+
cellIndex: index,
|
|
22
|
+
columnLength: headers?.length,
|
|
23
|
+
disableContextMenuColumn,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const visible = headers?.length! > index ? !headers![index].hidden : true;
|
|
27
|
+
return visible && cellWithSpacing;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const classNames = [classes['row']];
|
|
33
|
+
className && classNames.push(className);
|
|
34
|
+
isLoading && classNames.push(classes['loading']);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<tr {...rest} ref={ref} className={classNames.join(' ')}>
|
|
38
|
+
{visibleCells}
|
|
39
|
+
</tr>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
);
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`DataGridBody should render renders without crashing 1`] = `
|
|
4
|
+
Array [
|
|
5
|
+
<tr
|
|
6
|
+
class="row"
|
|
7
|
+
>
|
|
8
|
+
<td
|
|
9
|
+
class="cell "
|
|
10
|
+
>
|
|
11
|
+
<span
|
|
12
|
+
class="typography_style_body "
|
|
13
|
+
>
|
|
14
|
+
Paweł
|
|
15
|
+
</span>
|
|
16
|
+
</td>
|
|
17
|
+
<td
|
|
18
|
+
class="cell "
|
|
19
|
+
>
|
|
20
|
+
<span
|
|
21
|
+
class="typography_style_body "
|
|
22
|
+
>
|
|
23
|
+
Napieracz
|
|
24
|
+
</span>
|
|
25
|
+
</td>
|
|
26
|
+
<td
|
|
27
|
+
class="cell "
|
|
28
|
+
>
|
|
29
|
+
<span
|
|
30
|
+
class="typography_style_body "
|
|
31
|
+
>
|
|
32
|
+
12.12.1990
|
|
33
|
+
</span>
|
|
34
|
+
</td>
|
|
35
|
+
<td
|
|
36
|
+
class="cell "
|
|
37
|
+
>
|
|
38
|
+
<span
|
|
39
|
+
class="typography_style_body "
|
|
40
|
+
>
|
|
41
|
+
<div
|
|
42
|
+
class="context-menu"
|
|
43
|
+
>
|
|
44
|
+
<button
|
|
45
|
+
aria-controls="consent_menu_Paweł-menu"
|
|
46
|
+
aria-expanded="false"
|
|
47
|
+
aria-haspopup="true"
|
|
48
|
+
class="button icon-button text default button-m"
|
|
49
|
+
id="consent_menu_Paweł"
|
|
50
|
+
tabindex="0"
|
|
51
|
+
type="button"
|
|
52
|
+
>
|
|
53
|
+
<span
|
|
54
|
+
aria-hidden="true"
|
|
55
|
+
class="icon icon-ellipsis-alt "
|
|
56
|
+
data-icon="true"
|
|
57
|
+
/>
|
|
58
|
+
<span
|
|
59
|
+
class="sr-only"
|
|
60
|
+
>
|
|
61
|
+
Actions for Paweł
|
|
62
|
+
</span>
|
|
63
|
+
</button>
|
|
64
|
+
</div>
|
|
65
|
+
</span>
|
|
66
|
+
</td>
|
|
67
|
+
</tr>,
|
|
68
|
+
<tr
|
|
69
|
+
class="row"
|
|
70
|
+
>
|
|
71
|
+
<td
|
|
72
|
+
class="cell "
|
|
73
|
+
>
|
|
74
|
+
<span
|
|
75
|
+
class="typography_style_body "
|
|
76
|
+
>
|
|
77
|
+
Michał
|
|
78
|
+
</span>
|
|
79
|
+
</td>
|
|
80
|
+
<td
|
|
81
|
+
class="cell "
|
|
82
|
+
>
|
|
83
|
+
<span
|
|
84
|
+
class="typography_style_body "
|
|
85
|
+
>
|
|
86
|
+
Górski
|
|
87
|
+
</span>
|
|
88
|
+
</td>
|
|
89
|
+
<td
|
|
90
|
+
class="cell "
|
|
91
|
+
>
|
|
92
|
+
<span
|
|
93
|
+
class="typography_style_body "
|
|
94
|
+
>
|
|
95
|
+
12.12.1994
|
|
96
|
+
</span>
|
|
97
|
+
</td>
|
|
98
|
+
<td
|
|
99
|
+
class="cell "
|
|
100
|
+
>
|
|
101
|
+
<span
|
|
102
|
+
class="typography_style_body "
|
|
103
|
+
>
|
|
104
|
+
<div
|
|
105
|
+
class="context-menu"
|
|
106
|
+
>
|
|
107
|
+
<button
|
|
108
|
+
aria-controls="consent_menu_Michał-menu"
|
|
109
|
+
aria-expanded="false"
|
|
110
|
+
aria-haspopup="true"
|
|
111
|
+
class="button icon-button text default button-m"
|
|
112
|
+
id="consent_menu_Michał"
|
|
113
|
+
tabindex="0"
|
|
114
|
+
type="button"
|
|
115
|
+
>
|
|
116
|
+
<span
|
|
117
|
+
aria-hidden="true"
|
|
118
|
+
class="icon icon-ellipsis-alt "
|
|
119
|
+
data-icon="true"
|
|
120
|
+
/>
|
|
121
|
+
<span
|
|
122
|
+
class="sr-only"
|
|
123
|
+
>
|
|
124
|
+
Actions for Michał
|
|
125
|
+
</span>
|
|
126
|
+
</button>
|
|
127
|
+
</div>
|
|
128
|
+
</span>
|
|
129
|
+
</td>
|
|
130
|
+
</tr>,
|
|
131
|
+
<tr
|
|
132
|
+
class="row"
|
|
133
|
+
>
|
|
134
|
+
<td
|
|
135
|
+
class="cell "
|
|
136
|
+
>
|
|
137
|
+
<span
|
|
138
|
+
class="typography_style_body "
|
|
139
|
+
>
|
|
140
|
+
Daniel
|
|
141
|
+
</span>
|
|
142
|
+
</td>
|
|
143
|
+
<td
|
|
144
|
+
class="cell "
|
|
145
|
+
>
|
|
146
|
+
<span
|
|
147
|
+
class="typography_style_body "
|
|
148
|
+
>
|
|
149
|
+
Velden
|
|
150
|
+
</span>
|
|
151
|
+
</td>
|
|
152
|
+
<td
|
|
153
|
+
class="cell "
|
|
154
|
+
>
|
|
155
|
+
<span
|
|
156
|
+
class="typography_style_body "
|
|
157
|
+
>
|
|
158
|
+
12.12.199x
|
|
159
|
+
</span>
|
|
160
|
+
</td>
|
|
161
|
+
<td
|
|
162
|
+
class="cell "
|
|
163
|
+
>
|
|
164
|
+
<span
|
|
165
|
+
class="typography_style_body "
|
|
166
|
+
>
|
|
167
|
+
<div
|
|
168
|
+
class="context-menu"
|
|
169
|
+
>
|
|
170
|
+
<button
|
|
171
|
+
aria-controls="consent_menu_Daniel-menu"
|
|
172
|
+
aria-expanded="false"
|
|
173
|
+
aria-haspopup="true"
|
|
174
|
+
class="button icon-button text default button-m"
|
|
175
|
+
id="consent_menu_Daniel"
|
|
176
|
+
tabindex="0"
|
|
177
|
+
type="button"
|
|
178
|
+
>
|
|
179
|
+
<span
|
|
180
|
+
aria-hidden="true"
|
|
181
|
+
class="icon icon-ellipsis-alt "
|
|
182
|
+
data-icon="true"
|
|
183
|
+
/>
|
|
184
|
+
<span
|
|
185
|
+
class="sr-only"
|
|
186
|
+
>
|
|
187
|
+
Actions for Daniel
|
|
188
|
+
</span>
|
|
189
|
+
</button>
|
|
190
|
+
</div>
|
|
191
|
+
</span>
|
|
192
|
+
</td>
|
|
193
|
+
</tr>,
|
|
194
|
+
<tr
|
|
195
|
+
class="row"
|
|
196
|
+
>
|
|
197
|
+
<td
|
|
198
|
+
class="cell "
|
|
199
|
+
>
|
|
200
|
+
<span
|
|
201
|
+
class="typography_style_body "
|
|
202
|
+
>
|
|
203
|
+
Jasha
|
|
204
|
+
</span>
|
|
205
|
+
</td>
|
|
206
|
+
<td
|
|
207
|
+
class="cell "
|
|
208
|
+
>
|
|
209
|
+
<span
|
|
210
|
+
class="typography_style_body "
|
|
211
|
+
>
|
|
212
|
+
Joachimsthal
|
|
213
|
+
</span>
|
|
214
|
+
</td>
|
|
215
|
+
<td
|
|
216
|
+
class="cell "
|
|
217
|
+
>
|
|
218
|
+
<span
|
|
219
|
+
class="typography_style_body "
|
|
220
|
+
>
|
|
221
|
+
12.12.198x
|
|
222
|
+
</span>
|
|
223
|
+
</td>
|
|
224
|
+
<td
|
|
225
|
+
class="cell "
|
|
226
|
+
>
|
|
227
|
+
<span
|
|
228
|
+
class="typography_style_body "
|
|
229
|
+
>
|
|
230
|
+
<div
|
|
231
|
+
class="context-menu"
|
|
232
|
+
>
|
|
233
|
+
<button
|
|
234
|
+
aria-controls="consent_menu_Jasha-menu"
|
|
235
|
+
aria-expanded="false"
|
|
236
|
+
aria-haspopup="true"
|
|
237
|
+
class="button icon-button text default button-m"
|
|
238
|
+
id="consent_menu_Jasha"
|
|
239
|
+
tabindex="0"
|
|
240
|
+
type="button"
|
|
241
|
+
>
|
|
242
|
+
<span
|
|
243
|
+
aria-hidden="true"
|
|
244
|
+
class="icon icon-ellipsis-alt "
|
|
245
|
+
data-icon="true"
|
|
246
|
+
/>
|
|
247
|
+
<span
|
|
248
|
+
class="sr-only"
|
|
249
|
+
>
|
|
250
|
+
Actions for Jasha
|
|
251
|
+
</span>
|
|
252
|
+
</button>
|
|
253
|
+
</div>
|
|
254
|
+
</span>
|
|
255
|
+
</td>
|
|
256
|
+
</tr>,
|
|
257
|
+
]
|
|
258
|
+
`;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.thead {
|
|
2
|
+
&::after {
|
|
3
|
+
content: '';
|
|
4
|
+
position: absolute;
|
|
5
|
+
top: 2.5rem;
|
|
6
|
+
width: calc(100% - 2rem);
|
|
7
|
+
left: 1rem;
|
|
8
|
+
border-bottom: 1px solid #c3c3c7;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.row {
|
|
13
|
+
height: 2.5rem;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.context-menu {
|
|
17
|
+
width: 4.125rem;
|
|
18
|
+
box-sizing: border-box;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@media only screen and (min-width: 50em) {
|
|
22
|
+
.thead::after {
|
|
23
|
+
width: calc(100% - 2.5rem);
|
|
24
|
+
left: 1.25rem;
|
|
25
|
+
}
|
|
26
|
+
}
|