@onewelcome/react-lib-components 0.1.5-alpha → 0.1.8-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.
Files changed (105) hide show
  1. package/dist/Button/IconButton.d.ts +2 -1
  2. package/dist/ContextMenu/ContextMenu.d.ts +2 -3
  3. package/dist/ContextMenu/ContextMenuItem.d.ts +10 -3
  4. package/dist/DataGrid/DataGrid.d.ts +30 -0
  5. package/dist/DataGrid/DataGridActions/DataGridActions.d.ts +14 -0
  6. package/dist/DataGrid/DataGridActions/DataGridColumnsToggle.d.ts +13 -0
  7. package/dist/DataGrid/DataGridBody/DataGridBody.d.ts +16 -0
  8. package/dist/DataGrid/DataGridBody/DataGridCell.d.ts +6 -0
  9. package/dist/DataGrid/DataGridBody/DataGridRow.d.ts +7 -0
  10. package/dist/DataGrid/DataGridHeader/DataGridHeader.d.ts +10 -0
  11. package/dist/DataGrid/DataGridHeader/DataGridHeaderCell.d.ts +10 -0
  12. package/dist/DataGrid/datagrid.interfaces.d.ts +13 -0
  13. package/dist/Form/Checkbox/Checkbox.d.ts +2 -2
  14. package/dist/Form/Select/Option.d.ts +9 -4
  15. package/dist/Form/Select/Select.d.ts +8 -2
  16. package/dist/Form/Toggle/Toggle.d.ts +1 -1
  17. package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +1 -1
  18. package/dist/Icon/Icon.d.ts +1 -0
  19. package/dist/Link/Link.d.ts +4 -3
  20. package/dist/Notifications/BaseModal/BaseModal.d.ts +4 -2
  21. package/dist/Notifications/SlideInModal/SlideInModal.d.ts +4 -0
  22. package/dist/StatusIndicator/StatusIndicator.d.ts +9 -0
  23. package/dist/_BaseStyling_/BaseStyling.d.ts +4 -0
  24. package/dist/hooks/useSpacing.d.ts +1 -1
  25. package/dist/hooks/useWrapper.d.ts +1 -1
  26. package/dist/index.d.ts +48 -43
  27. package/dist/react-lib-components.cjs.development.js +2900 -2049
  28. package/dist/react-lib-components.cjs.development.js.map +1 -1
  29. package/dist/react-lib-components.cjs.production.min.js +1 -1
  30. package/dist/react-lib-components.cjs.production.min.js.map +1 -1
  31. package/dist/react-lib-components.esm.js +2897 -2050
  32. package/dist/react-lib-components.esm.js.map +1 -1
  33. package/dist/util/helper.d.ts +1 -1
  34. package/package.json +11 -11
  35. package/src/Button/BaseButton.module.scss +3 -18
  36. package/src/Button/Button.module.scss +4 -311
  37. package/src/Button/IconButton.module.scss +21 -128
  38. package/src/Button/IconButton.test.tsx +24 -0
  39. package/src/Button/IconButton.tsx +6 -1
  40. package/src/ContextMenu/ContextMenu.test.tsx +121 -6
  41. package/src/ContextMenu/ContextMenu.tsx +99 -6
  42. package/src/ContextMenu/ContextMenuItem.tsx +57 -9
  43. package/src/DataGrid/DataGrid.module.scss +21 -0
  44. package/src/DataGrid/DataGrid.test.tsx +276 -0
  45. package/src/DataGrid/DataGrid.tsx +101 -0
  46. package/src/DataGrid/DataGridActions/DataGridActions.module.scss +35 -0
  47. package/src/DataGrid/DataGridActions/DataGridActions.test.tsx +184 -0
  48. package/src/DataGrid/DataGridActions/DataGridActions.tsx +109 -0
  49. package/src/DataGrid/DataGridActions/DataGridColumnsToggle.module.scss +41 -0
  50. package/src/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +83 -0
  51. package/src/DataGrid/DataGridActions/DataGridColumnsToggle.tsx +88 -0
  52. package/src/DataGrid/DataGridBody/DataGridBody.module.scss +10 -0
  53. package/src/DataGrid/DataGridBody/DataGridBody.test.tsx +123 -0
  54. package/src/DataGrid/DataGridBody/DataGridBody.tsx +64 -0
  55. package/src/DataGrid/DataGridBody/DataGridCell.module.scss +33 -0
  56. package/src/DataGrid/DataGridBody/DataGridCell.test.tsx +74 -0
  57. package/src/DataGrid/DataGridBody/DataGridCell.tsx +25 -0
  58. package/src/DataGrid/DataGridBody/DataGridRow.module.scss +7 -0
  59. package/src/DataGrid/DataGridBody/DataGridRow.test.tsx +101 -0
  60. package/src/DataGrid/DataGridBody/DataGridRow.tsx +27 -0
  61. package/src/DataGrid/DataGridBody/__snapshots__/DataGridBody.test.tsx.snap +258 -0
  62. package/src/DataGrid/DataGridHeader/DataGridHeader.module.scss +26 -0
  63. package/src/DataGrid/DataGridHeader/DataGridHeader.test.tsx +255 -0
  64. package/src/DataGrid/DataGridHeader/DataGridHeader.tsx +80 -0
  65. package/src/DataGrid/DataGridHeader/DataGridHeaderCell.module.scss +68 -0
  66. package/src/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +128 -0
  67. package/src/DataGrid/DataGridHeader/DataGridHeaderCell.tsx +72 -0
  68. package/src/DataGrid/datagrid.interfaces.ts +14 -0
  69. package/src/Form/Checkbox/Checkbox.test.tsx +144 -8
  70. package/src/Form/Checkbox/Checkbox.tsx +8 -8
  71. package/src/Form/Select/Option.tsx +39 -21
  72. package/src/Form/Select/Select.module.scss +1 -1
  73. package/src/Form/Select/Select.test.tsx +235 -56
  74. package/src/Form/Select/Select.tsx +194 -34
  75. package/src/Form/Toggle/Toggle.module.scss +1 -0
  76. package/src/Form/Toggle/Toggle.test.tsx +45 -19
  77. package/src/Form/Toggle/Toggle.tsx +3 -3
  78. package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +1 -1
  79. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +44 -0
  80. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +4 -2
  81. package/src/Icon/Icon.module.scss +4 -0
  82. package/src/Icon/Icon.tsx +1 -0
  83. package/src/Link/Link.module.scss +20 -0
  84. package/src/Link/Link.test.tsx +33 -0
  85. package/src/Link/Link.tsx +8 -2
  86. package/src/Notifications/BaseModal/BaseModal.module.scss +1 -1
  87. package/src/Notifications/BaseModal/BaseModal.test.tsx +77 -12
  88. package/src/Notifications/BaseModal/BaseModal.tsx +27 -6
  89. package/src/Notifications/Dialog/Dialog.module.scss +1 -1
  90. package/src/Notifications/Dialog/Dialog.tsx +1 -1
  91. package/src/Notifications/SlideInModal/SlideInModal.module.scss +36 -0
  92. package/src/Notifications/SlideInModal/SlideInModal.test.tsx +69 -0
  93. package/src/Notifications/SlideInModal/SlideInModal.tsx +31 -0
  94. package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.module.scss +1 -1
  95. package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.scss +1 -1
  96. package/src/Pagination/Pagination.module.scss +74 -74
  97. package/src/StatusIndicator/StatusIndicator.module.scss +27 -0
  98. package/src/StatusIndicator/StatusIndicator.test.tsx +127 -0
  99. package/src/StatusIndicator/StatusIndicator.tsx +25 -0
  100. package/src/Tiles/Tile.module.scss +1 -1
  101. package/src/Tiles/Tile.test.tsx +4 -4
  102. package/src/_BaseStyling_/BaseStyling.tsx +14 -6
  103. package/src/index.ts +85 -48
  104. package/src/mixins.module.scss +171 -0
  105. package/src/readyclasses.module.scss +0 -30
@@ -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
+ });
@@ -0,0 +1,64 @@
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
+ }
16
+
17
+ const skeletonLoadingRows = 9;
18
+
19
+ const DataGridBodyInner = <T extends {}>(
20
+ { children, data, headers, isLoading, disableContextMenuColumn, emptyLabel, ...rest }: Props<T>,
21
+ ref: Ref<HTMLTableSectionElement>
22
+ ) => {
23
+ const renderContent = () => {
24
+ const visibleColumns = headers.filter((header) => !header.hidden).length;
25
+ if (isLoading) {
26
+ return Array.from(Array(skeletonLoadingRows)).map((_, rowIdx) => (
27
+ <DataGridRow key={rowIdx} isLoading>
28
+ {Array.from(Array(visibleColumns)).map((__, colIdx) => (
29
+ <DataGridCell key={colIdx} isLoading></DataGridCell>
30
+ ))}
31
+ {!disableContextMenuColumn && <DataGridCell></DataGridCell>}
32
+ </DataGridRow>
33
+ ));
34
+ }
35
+
36
+ const emptyData = !data || data.length === 0;
37
+ if (emptyData) {
38
+ return (
39
+ <tr>
40
+ <td
41
+ className={classes['empty']}
42
+ colSpan={visibleColumns + (disableContextMenuColumn ? 0 : 1)}
43
+ >
44
+ <Typography variant="body" spacing={{ margin: 0 }}>
45
+ {emptyLabel}
46
+ </Typography>
47
+ </td>
48
+ </tr>
49
+ );
50
+ }
51
+
52
+ return data?.map((item, index) => React.cloneElement(children({ item, index }), { headers }));
53
+ };
54
+
55
+ return (
56
+ <tbody {...rest} ref={ref}>
57
+ {renderContent()}
58
+ </tbody>
59
+ );
60
+ };
61
+
62
+ export const DataGridBody = React.forwardRef(DataGridBodyInner) as <T extends {}>(
63
+ p: Props<T> & { ref?: Ref<HTMLTableSectionElement> }
64
+ ) => 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,25 @@
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
+ }
9
+
10
+ export const DataGridCell = React.forwardRef<HTMLTableCellElement, Props>(
11
+ ({ children, className, isLoading, ...rest }: Props, ref) => {
12
+ return (
13
+ <td {...rest} ref={ref} className={`${classes['cell']} ${className ?? ''}`}>
14
+ {isLoading && (
15
+ <div className={classes['loading']} aria-busy="true" aria-live="polite"></div>
16
+ )}
17
+ {!isLoading && (
18
+ <Typography variant="body" tag="span">
19
+ {children}
20
+ </Typography>
21
+ )}
22
+ </td>
23
+ );
24
+ }
25
+ );
@@ -0,0 +1,7 @@
1
+ .row {
2
+ background-color: var(--data-grid-row-background-color);
3
+
4
+ &:not(.loading):hover {
5
+ background-color: var(--data-grid-row-hover-background-color);
6
+ }
7
+ }
@@ -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,27 @@
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
+ }
9
+
10
+ export const DataGridRow = React.forwardRef<HTMLTableRowElement, Props>(
11
+ ({ children, className, headers, isLoading, ...rest }: Props, ref) => {
12
+ const visibleCells = React.Children.map(children, (child, index) => {
13
+ const visible = headers?.length! > index ? !headers![index].hidden : true;
14
+ return visible && child;
15
+ });
16
+
17
+ const classNames = [classes['row']];
18
+ className && classNames.push(className);
19
+ isLoading && classNames.push(classes['loading']);
20
+
21
+ return (
22
+ <tr {...rest} ref={ref} className={classNames.join(' ')}>
23
+ {visibleCells}
24
+ </tr>
25
+ );
26
+ }
27
+ );