@telus-uds/components-community.data-grid 0.1.0
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/.eslintrc.cjs +21 -0
- package/CHANGELOG.md +17 -0
- package/__mocks__/styleMock.js +7 -0
- package/babel.config.cjs +4 -0
- package/jest.config.cjs +19 -0
- package/lib/DataGrid.js +368 -0
- package/lib/DataGridBody.js +20 -0
- package/lib/DataGridCell.js +184 -0
- package/lib/DataGridHead.js +20 -0
- package/lib/DataGridRow.js +103 -0
- package/lib/DataGridTable.js +70 -0
- package/lib/dictionary.js +18 -0
- package/lib/index.js +12 -0
- package/lib/utility.js +75 -0
- package/package.json +48 -0
- package/src/DataGrid.jsx +465 -0
- package/src/DataGridBody.jsx +17 -0
- package/src/DataGridCell.jsx +200 -0
- package/src/DataGridHead.jsx +15 -0
- package/src/DataGridRow.jsx +110 -0
- package/src/DataGridTable.jsx +68 -0
- package/src/dictionary.js +18 -0
- package/src/index.js +14 -0
- package/src/utility.jsx +76 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { styledComponents } from '@telus-uds/components-web';
|
|
4
|
+
import { ROW_TYPE } from './utility';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
const {
|
|
7
|
+
styled,
|
|
8
|
+
css
|
|
9
|
+
} = styledComponents;
|
|
10
|
+
const StyledExpandedRow = styled.tr`
|
|
11
|
+
${props => {
|
|
12
|
+
return css`
|
|
13
|
+
background-color: ${props.rowBackgroundColorOnHover};
|
|
14
|
+
`;
|
|
15
|
+
}}
|
|
16
|
+
transition: 0.3s ease;
|
|
17
|
+
`;
|
|
18
|
+
const StyledRow = styled.tr`
|
|
19
|
+
${props => {
|
|
20
|
+
if (props.isExpandedRowOpen) {
|
|
21
|
+
return css`
|
|
22
|
+
background-color: ${props.rowBackgroundColorOnHover};
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
`;
|
|
25
|
+
}
|
|
26
|
+
return css`
|
|
27
|
+
cursor: ${props.hasExpandedContent ? `pointer` : `arrow`};
|
|
28
|
+
background-color: ${props.rowBackgroundColor};
|
|
29
|
+
padding: ${props.rowPadding}px;
|
|
30
|
+
&:hover {
|
|
31
|
+
background-color: ${props.rowBackgroundColorOnHover};
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
}}
|
|
35
|
+
transition: 0.3s ease;
|
|
36
|
+
`;
|
|
37
|
+
const DataGridRow = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
38
|
+
let {
|
|
39
|
+
children,
|
|
40
|
+
tokens,
|
|
41
|
+
type,
|
|
42
|
+
rowId,
|
|
43
|
+
isExpandedRowOpen = false,
|
|
44
|
+
hasExpandedContent = false,
|
|
45
|
+
onClick
|
|
46
|
+
} = _ref;
|
|
47
|
+
const onClickHandler = () => {
|
|
48
|
+
onClick(rowId);
|
|
49
|
+
};
|
|
50
|
+
if (type === ROW_TYPE.HEADING) {
|
|
51
|
+
return /*#__PURE__*/_jsx("tr", {
|
|
52
|
+
ref: ref,
|
|
53
|
+
children: children
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (type === ROW_TYPE.EXPANDEDROW) {
|
|
57
|
+
return /*#__PURE__*/_jsx(StyledExpandedRow, {
|
|
58
|
+
...tokens,
|
|
59
|
+
ref: ref,
|
|
60
|
+
children: children
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return /*#__PURE__*/_jsx(StyledRow, {
|
|
64
|
+
...tokens,
|
|
65
|
+
isExpandedRowOpen: isExpandedRowOpen,
|
|
66
|
+
hasExpandedContent: hasExpandedContent,
|
|
67
|
+
onClick: hasExpandedContent ? onClickHandler : null,
|
|
68
|
+
ref: ref,
|
|
69
|
+
children: children
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
DataGridRow.displayName = 'DataGridRow';
|
|
73
|
+
DataGridRow.propTypes = {
|
|
74
|
+
/**
|
|
75
|
+
Row type
|
|
76
|
+
*/
|
|
77
|
+
type: PropTypes.oneOf(['heading', 'subHeading', 'expandedRow']),
|
|
78
|
+
/**
|
|
79
|
+
* Accepts any React or HTML node
|
|
80
|
+
*/
|
|
81
|
+
children: PropTypes.node.isRequired,
|
|
82
|
+
/**
|
|
83
|
+
* data-id passed from the data to the row passed to the component
|
|
84
|
+
*/
|
|
85
|
+
rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
86
|
+
/**
|
|
87
|
+
* Tokens passed to the component
|
|
88
|
+
*/
|
|
89
|
+
tokens: PropTypes.object,
|
|
90
|
+
/**
|
|
91
|
+
* isExpandedRowOpen determines component's behavior to additonal available data
|
|
92
|
+
*/
|
|
93
|
+
isExpandedRowOpen: PropTypes.bool,
|
|
94
|
+
/**
|
|
95
|
+
* hasExpandedContent determines component's behavior to additional available data
|
|
96
|
+
*/
|
|
97
|
+
hasExpandedContent: PropTypes.bool,
|
|
98
|
+
/**
|
|
99
|
+
* onClick is a function to open/close a row with expanded content
|
|
100
|
+
*/
|
|
101
|
+
onClick: PropTypes.func
|
|
102
|
+
};
|
|
103
|
+
export default DataGridRow;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { styledComponents } from '@telus-uds/components-web';
|
|
4
|
+
import { Scrollbar } from 'smooth-scrollbar-react';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
const {
|
|
7
|
+
styled,
|
|
8
|
+
css
|
|
9
|
+
} = styledComponents;
|
|
10
|
+
const StyledWrapper = styled.div`
|
|
11
|
+
display: flex;
|
|
12
|
+
width: 100%;
|
|
13
|
+
margin: 0px;
|
|
14
|
+
padding: 8px;
|
|
15
|
+
${props => props.tokens.maxHeight && css`
|
|
16
|
+
max-height: ${props.tokens.maxHeight}px;
|
|
17
|
+
`}
|
|
18
|
+
box-sizing: border-box;
|
|
19
|
+
border: 0px solid #000000;
|
|
20
|
+
overflow-y: auto;
|
|
21
|
+
`;
|
|
22
|
+
const StyledTable = styled.table`
|
|
23
|
+
width: 100%;
|
|
24
|
+
border-spacing: 0;
|
|
25
|
+
`;
|
|
26
|
+
const WrappedScrollbar = styled(Scrollbar)`
|
|
27
|
+
width: 100%;
|
|
28
|
+
`;
|
|
29
|
+
const DataGridTable = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
30
|
+
let {
|
|
31
|
+
children,
|
|
32
|
+
tokens,
|
|
33
|
+
makeScrollBarAlwaysVisible,
|
|
34
|
+
testID
|
|
35
|
+
} = _ref;
|
|
36
|
+
return /*#__PURE__*/_jsx(StyledWrapper, {
|
|
37
|
+
tokens: tokens,
|
|
38
|
+
ref: ref,
|
|
39
|
+
testID: testID,
|
|
40
|
+
children: /*#__PURE__*/_jsx(WrappedScrollbar, {
|
|
41
|
+
alwaysShowTracks: makeScrollBarAlwaysVisible,
|
|
42
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
43
|
+
children: /*#__PURE__*/_jsx(StyledTable, {
|
|
44
|
+
children: children
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
DataGridTable.displayName = 'DataGridTable';
|
|
51
|
+
DataGridTable.propTypes = {
|
|
52
|
+
/**
|
|
53
|
+
* Accepts any React or HTML node
|
|
54
|
+
*/
|
|
55
|
+
children: PropTypes.node.isRequired,
|
|
56
|
+
/**
|
|
57
|
+
* Tokens passed to the component
|
|
58
|
+
*/
|
|
59
|
+
tokens: PropTypes.object,
|
|
60
|
+
/**
|
|
61
|
+
* Set this to true to make scrollbar always visible when content is larger than the grid
|
|
62
|
+
*/
|
|
63
|
+
makeScrollBarAlwaysVisible: PropTypes.bool,
|
|
64
|
+
/**
|
|
65
|
+
/**
|
|
66
|
+
* Use in tests if the datagrid test cases need to find the element with the id.
|
|
67
|
+
*/
|
|
68
|
+
testID: PropTypes.string
|
|
69
|
+
};
|
|
70
|
+
export default DataGridTable;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
en: {
|
|
3
|
+
all: 'All',
|
|
4
|
+
hideRow: 'Hide Row',
|
|
5
|
+
expandRow: 'Expand Row',
|
|
6
|
+
sortAsc: 'Sort Ascending',
|
|
7
|
+
sortDesc: 'Sort Descending',
|
|
8
|
+
button: 'Button'
|
|
9
|
+
},
|
|
10
|
+
fr: {
|
|
11
|
+
all: 'Tout',
|
|
12
|
+
hideRow: 'Masquer la ligne',
|
|
13
|
+
expandRow: 'Développer la ligne',
|
|
14
|
+
sortAsc: 'Tri croissant',
|
|
15
|
+
sortDesc: 'Tri décroissant',
|
|
16
|
+
button: 'Bouton'
|
|
17
|
+
}
|
|
18
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import DataGrid from './DataGrid';
|
|
2
|
+
import DataGridBody from './DataGridBody';
|
|
3
|
+
import DataGridCell from './DataGridCell';
|
|
4
|
+
import DataGridHead from './DataGridHead';
|
|
5
|
+
import DataGridRow from './DataGridRow';
|
|
6
|
+
import DataGridTable from './DataGridTable';
|
|
7
|
+
DataGrid.Body = DataGridBody;
|
|
8
|
+
DataGrid.Cell = DataGridCell;
|
|
9
|
+
DataGrid.Head = DataGridHead;
|
|
10
|
+
DataGrid.Row = DataGridRow;
|
|
11
|
+
DataGrid.Table = DataGridTable;
|
|
12
|
+
export default DataGrid;
|
package/lib/utility.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export const ROW_TYPE = {
|
|
2
|
+
HEADING: 'heading',
|
|
3
|
+
SUBHEADING: 'subHeading',
|
|
4
|
+
EXPANDEDROW: 'expandedRow'
|
|
5
|
+
};
|
|
6
|
+
export const CELL_TYPE = {
|
|
7
|
+
HEADING: 'heading',
|
|
8
|
+
SUBHEADING: 'subHeading',
|
|
9
|
+
EXPANDEDROWCELL: 'expandedRowCell'
|
|
10
|
+
};
|
|
11
|
+
export const SORT_DIRECTION = {
|
|
12
|
+
ASC: 'asc',
|
|
13
|
+
DESC: 'desc'
|
|
14
|
+
};
|
|
15
|
+
export const DATA_TYPE = {
|
|
16
|
+
STRING: 'string',
|
|
17
|
+
NUMBER: 'number'
|
|
18
|
+
};
|
|
19
|
+
const mappedData = array => {
|
|
20
|
+
return array.map(element => {
|
|
21
|
+
const eachRow = {
|
|
22
|
+
...element,
|
|
23
|
+
isSelected: false
|
|
24
|
+
};
|
|
25
|
+
if (eachRow.expandedRowChildComponent) {
|
|
26
|
+
eachRow.hasExpandedRow = true;
|
|
27
|
+
eachRow.isExpandedRowOpen = element.expandedRowChildComponent.displayOnLoad;
|
|
28
|
+
}
|
|
29
|
+
return eachRow;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
export const isAtLeastOneRowUnselected = array => {
|
|
33
|
+
return array.some(each => each.isSelected === false);
|
|
34
|
+
};
|
|
35
|
+
export const resetColumnsData = data => {
|
|
36
|
+
return data.map(element => ({
|
|
37
|
+
...element,
|
|
38
|
+
currentSort: false,
|
|
39
|
+
sortDirection: SORT_DIRECTION.DESC
|
|
40
|
+
}));
|
|
41
|
+
};
|
|
42
|
+
export const resetRowData = function (data) {
|
|
43
|
+
let isGrouped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
44
|
+
if (isGrouped) {
|
|
45
|
+
const result = {};
|
|
46
|
+
data.forEach(el => {
|
|
47
|
+
result[el.key] = {
|
|
48
|
+
...el,
|
|
49
|
+
data: mappedData(el.data)
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
return mappedData(data);
|
|
55
|
+
};
|
|
56
|
+
export const toggleAllCheckBoxes = (array, headerCheckBoxState) => {
|
|
57
|
+
return array.map(element => {
|
|
58
|
+
return {
|
|
59
|
+
...element,
|
|
60
|
+
isSelected: !headerCheckBoxState
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
export const toggleRowCheckbox = (array, rowId) => {
|
|
65
|
+
return array.map(el => ({
|
|
66
|
+
...el,
|
|
67
|
+
isSelected: el.id === rowId ? !el.isSelected : el.isSelected
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
export const toggleExpandedRow = (array, rowId) => {
|
|
71
|
+
return array.map(el => ({
|
|
72
|
+
...el,
|
|
73
|
+
isExpandedRowOpen: el.id === rowId ? !el.isExpandedRowOpen : el.isExpandedRowOpen
|
|
74
|
+
}));
|
|
75
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "TELUS Digital",
|
|
3
|
+
"browserslist": [
|
|
4
|
+
"extends @telus-uds/browserslist-config"
|
|
5
|
+
],
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"prop-types": "^15.7.2",
|
|
8
|
+
"@telus-uds/components-web": "^3.2.1",
|
|
9
|
+
"@telus-uds/components-base": "^2.3.0",
|
|
10
|
+
"@telus-uds/system-theme-tokens": "^3.2.0",
|
|
11
|
+
"styled-components": "6.1.13",
|
|
12
|
+
"smooth-scrollbar": "8.8.4",
|
|
13
|
+
"smooth-scrollbar-react": "2.4.1"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@telus-uds/browserslist-config": "^1.0.4",
|
|
17
|
+
"babel-plugin-styled-components": "^2.0.6",
|
|
18
|
+
"jest-styled-components": "^7.0.8",
|
|
19
|
+
"@testing-library/jest-dom": "^5.16.1",
|
|
20
|
+
"@testing-library/react": "^13.3.0",
|
|
21
|
+
"jest-axe": "^6.0.0"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/telus/universal-design-system#readme",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"name": "@telus-uds/components-community.data-grid",
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": "^17.0.2 || ^18.0.0",
|
|
28
|
+
"react-dom": "^17.0.2 || ^18.0.0"
|
|
29
|
+
},
|
|
30
|
+
"main": "lib/index.js",
|
|
31
|
+
"module": "lib/index.js",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/telus/universal-design-system.git"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"format": "prettier --write .",
|
|
38
|
+
"lint": "telus-standard",
|
|
39
|
+
"lint:fix": "telus-standard --fix",
|
|
40
|
+
"test": "jest",
|
|
41
|
+
"build": "babel src -d lib --env-name module"
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": false,
|
|
44
|
+
"standard-engine": {
|
|
45
|
+
"skip": true
|
|
46
|
+
},
|
|
47
|
+
"version": "0.1.0"
|
|
48
|
+
}
|