@spaced-out/ui-design-system 0.0.37 → 0.0.39
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/.cspell/custom-words.txt +2 -0
- package/CHANGELOG.md +14 -0
- package/design-tokens/size/base-size.json +6 -0
- package/lib/components/Checkbox/Checkbox.js.flow +5 -0
- package/lib/components/Checkbox/Checkbox.module.css +1 -1
- package/lib/components/Menu/Menu.js.flow +1 -1
- package/lib/components/Menu/MenuOptionButton.js +3 -2
- package/lib/components/Menu/MenuOptionButton.js.flow +15 -10
- package/lib/components/Table/Cell.js +114 -0
- package/lib/components/Table/Cell.js.flow +123 -0
- package/lib/components/Table/Row.js +96 -0
- package/lib/components/Table/Row.js.flow +145 -0
- package/lib/components/Table/StaticTable.js +124 -0
- package/lib/components/Table/StaticTable.js.flow +170 -0
- package/lib/components/Table/Table.js +61 -0
- package/lib/components/Table/Table.js.flow +101 -0
- package/lib/components/Table/Table.module.css +252 -0
- package/lib/components/Table/TableHeader.js +146 -0
- package/lib/components/Table/TableHeader.js.flow +236 -0
- package/lib/components/Table/hooks.js +68 -0
- package/lib/components/Table/hooks.js.flow +91 -0
- package/lib/components/Table/index.js +63 -0
- package/lib/components/Table/index.js.flow +14 -0
- package/lib/styles/variables/_size.css +4 -0
- package/lib/styles/variables/_size.js +6 -2
- package/lib/styles/variables/_size.js.flow +4 -0
- package/lib/utils/makeClassNameComponent.js +1 -1
- package/lib/utils/makeClassNameComponent.js.flow +1 -1
- package/package.json +4 -3
package/.cspell/custom-words.txt
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.0.39](https://github.com/spaced-out/ui-design-system/compare/v0.0.38...v0.0.39) (2023-03-03)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* (GDS-145) table component ([#70](https://github.com/spaced-out/ui-design-system/issues/70)) ([5d4ccf8](https://github.com/spaced-out/ui-design-system/commit/5d4ccf8c8097cdb545ad9b1086569146b072d761))
|
|
11
|
+
|
|
12
|
+
### [0.0.38](https://github.com/spaced-out/ui-design-system/compare/v0.0.37...v0.0.38) (2023-03-03)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* exposed a classname for each option in a menu ([ef5feab](https://github.com/spaced-out/ui-design-system/commit/ef5feab4f4cc39b1d479641906a141250481dd95))
|
|
18
|
+
|
|
5
19
|
### [0.0.37](https://github.com/spaced-out/ui-design-system/compare/v0.0.36...v0.0.37) (2023-03-03)
|
|
6
20
|
|
|
7
21
|
|
|
@@ -51,6 +51,9 @@
|
|
|
51
51
|
"42": {
|
|
52
52
|
"value": "42px"
|
|
53
53
|
},
|
|
54
|
+
"48": {
|
|
55
|
+
"value": "48px"
|
|
56
|
+
},
|
|
54
57
|
"58": {
|
|
55
58
|
"value": "58px"
|
|
56
59
|
},
|
|
@@ -110,6 +113,9 @@
|
|
|
110
113
|
},
|
|
111
114
|
"fullViewportHeight": {
|
|
112
115
|
"value": "100vh"
|
|
116
|
+
},
|
|
117
|
+
"fullViewportWidth": {
|
|
118
|
+
"value": "100vw"
|
|
113
119
|
}
|
|
114
120
|
}
|
|
115
121
|
}
|
|
@@ -12,6 +12,11 @@ import css from './Checkbox.module.css';
|
|
|
12
12
|
|
|
13
13
|
type ClassNames = $ReadOnly<{wrapper?: string, label?: string}>;
|
|
14
14
|
|
|
15
|
+
/*
|
|
16
|
+
Note: An indeterminate state has a higher priority.
|
|
17
|
+
If true checkbox would be in an indeterminate state. If indeterminate is false, it will owner checked value.
|
|
18
|
+
*/
|
|
19
|
+
|
|
15
20
|
export type CheckboxProps = {
|
|
16
21
|
name?: string,
|
|
17
22
|
value?: string,
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
|
|
67
67
|
.checkboxSquare .disabled {
|
|
68
68
|
cursor: not-allowed;
|
|
69
|
+
border: borderWidthTertiary solid colorFillDisabled;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
.inputCheckbox {
|
|
@@ -124,7 +125,6 @@ input[type='checkbox']:disabled {
|
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
.disabled {
|
|
127
|
-
border: borderWidthTertiary solid colorFillDisabled;
|
|
128
128
|
pointer-events: none;
|
|
129
129
|
cursor: not-allowed;
|
|
130
130
|
}
|
|
@@ -9,7 +9,7 @@ import {MenuOptionButton} from './MenuOptionButton.js';
|
|
|
9
9
|
import css from './Menu.module.css';
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
type ClassNames = $ReadOnly<{wrapper?: string}>;
|
|
12
|
+
type ClassNames = $ReadOnly<{wrapper?: string, option?: string}>;
|
|
13
13
|
|
|
14
14
|
export type MenuOption = {
|
|
15
15
|
key?: string,
|
|
@@ -20,7 +20,8 @@ const MenuOptionButton = props => {
|
|
|
20
20
|
size,
|
|
21
21
|
onSelect,
|
|
22
22
|
selectedOption,
|
|
23
|
-
menuDisabled
|
|
23
|
+
menuDisabled,
|
|
24
|
+
classNames
|
|
24
25
|
} = props;
|
|
25
26
|
const {
|
|
26
27
|
key,
|
|
@@ -46,7 +47,7 @@ const MenuOptionButton = props => {
|
|
|
46
47
|
[_MenuModule.default.disabled]: menuDisabled || disabled,
|
|
47
48
|
[_MenuModule.default.withIconLeft]: !!iconLeft,
|
|
48
49
|
[_MenuModule.default.withIconRight]: !!iconRight
|
|
49
|
-
}),
|
|
50
|
+
}, classNames?.option),
|
|
50
51
|
disabled: menuDisabled || disabled,
|
|
51
52
|
onClick: () => onSelect && onSelect(option),
|
|
52
53
|
autoFocus: selectedOption?.key === key
|
|
@@ -11,7 +11,7 @@ import type {MenuOption} from './Menu.js';
|
|
|
11
11
|
import css from './Menu.module.css';
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
type ClassNames = $ReadOnly<{wrapper?: string}>;
|
|
14
|
+
type ClassNames = $ReadOnly<{wrapper?: string, option?: string}>;
|
|
15
15
|
|
|
16
16
|
export type MenuOptionProps = {
|
|
17
17
|
option: MenuOption,
|
|
@@ -25,7 +25,8 @@ export type MenuOptionProps = {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export const MenuOptionButton = (props: MenuOptionProps): React.Node => {
|
|
28
|
-
const {option, size, onSelect, selectedOption, menuDisabled} =
|
|
28
|
+
const {option, size, onSelect, selectedOption, menuDisabled, classNames} =
|
|
29
|
+
props;
|
|
29
30
|
const {
|
|
30
31
|
key,
|
|
31
32
|
label,
|
|
@@ -46,14 +47,18 @@ export const MenuOptionButton = (props: MenuOptionProps): React.Node => {
|
|
|
46
47
|
|
|
47
48
|
return (
|
|
48
49
|
<UnstyledButton
|
|
49
|
-
className={classify(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
className={classify(
|
|
51
|
+
css.option,
|
|
52
|
+
{
|
|
53
|
+
[css.selected]: key === selectedOption?.key,
|
|
54
|
+
[css.optionSmall]: buttonSize === 'small',
|
|
55
|
+
[css.optionMedium]: buttonSize === 'medium',
|
|
56
|
+
[css.disabled]: menuDisabled || disabled,
|
|
57
|
+
[css.withIconLeft]: !!iconLeft,
|
|
58
|
+
[css.withIconRight]: !!iconRight,
|
|
59
|
+
},
|
|
60
|
+
classNames?.option,
|
|
61
|
+
)}
|
|
57
62
|
disabled={menuDisabled || disabled}
|
|
58
63
|
onClick={() => onSelect && onSelect(option)}
|
|
59
64
|
autoFocus={selectedOption?.key === key}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SingleCell = exports.Row = exports.PaddedDoubleContentCell = exports.PaddedContentCell = exports.MonogramCell = exports.Monogram = exports.DoubleCell = exports.DateCell = exports.Cells = exports.Cell = exports.BasicSingleCell = exports.BasicDoubleCell = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _formatDistance = _interopRequireDefault(require("date-fns/formatDistance"));
|
|
9
|
+
var _parseISO = _interopRequireDefault(require("date-fns/parseISO"));
|
|
10
|
+
var _classify = require("../../utils/classify");
|
|
11
|
+
var _makeClassNameComponent = require("../../utils/makeClassNameComponent");
|
|
12
|
+
var _Avatar = require("../Avatar");
|
|
13
|
+
var _Text = require("../Text");
|
|
14
|
+
var _TableModule = _interopRequireDefault(require("./Table.module.css"));
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
18
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
19
|
+
const Cells = _ref => {
|
|
20
|
+
let {
|
|
21
|
+
children,
|
|
22
|
+
className,
|
|
23
|
+
...rest
|
|
24
|
+
} = _ref;
|
|
25
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
26
|
+
className: (0, _classify.classify)(_TableModule.default.row, className)
|
|
27
|
+
}, rest), children);
|
|
28
|
+
};
|
|
29
|
+
exports.Cells = Cells;
|
|
30
|
+
const Row = Cells;
|
|
31
|
+
exports.Row = Row;
|
|
32
|
+
const Cell = _ref2 => {
|
|
33
|
+
let {
|
|
34
|
+
children,
|
|
35
|
+
className
|
|
36
|
+
} = _ref2;
|
|
37
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
38
|
+
className: (0, _classify.classify)(_TableModule.default.cell, className)
|
|
39
|
+
}, children);
|
|
40
|
+
};
|
|
41
|
+
exports.Cell = Cell;
|
|
42
|
+
const BasicSingleCell = (0, _makeClassNameComponent.makeClassNameComponent)(_TableModule.default.defaultSingleCell, 'td');
|
|
43
|
+
exports.BasicSingleCell = BasicSingleCell;
|
|
44
|
+
const BasicDoubleCell = (0, _makeClassNameComponent.makeClassNameComponent)(_TableModule.default.defaultDoubleCell, 'td');
|
|
45
|
+
exports.BasicDoubleCell = BasicDoubleCell;
|
|
46
|
+
const PaddedContentCell = (0, _makeClassNameComponent.makeClassNameComponent)(_TableModule.default.singleContentCell, 'td');
|
|
47
|
+
exports.PaddedContentCell = PaddedContentCell;
|
|
48
|
+
const PaddedDoubleContentCell = (0, _makeClassNameComponent.makeClassNameComponent)(_TableModule.default.doubleContentCell, 'td');
|
|
49
|
+
exports.PaddedDoubleContentCell = PaddedDoubleContentCell;
|
|
50
|
+
const SingleCell = _ref3 => {
|
|
51
|
+
let {
|
|
52
|
+
title,
|
|
53
|
+
className
|
|
54
|
+
} = _ref3;
|
|
55
|
+
return /*#__PURE__*/React.createElement(PaddedContentCell, {
|
|
56
|
+
className: className
|
|
57
|
+
}, /*#__PURE__*/React.createElement(_Text.BodyMedium, {
|
|
58
|
+
className: _TableModule.default.paddedTitleBlock
|
|
59
|
+
}, title));
|
|
60
|
+
};
|
|
61
|
+
exports.SingleCell = SingleCell;
|
|
62
|
+
const DoubleCell = _ref4 => {
|
|
63
|
+
let {
|
|
64
|
+
title,
|
|
65
|
+
subtitle,
|
|
66
|
+
className
|
|
67
|
+
} = _ref4;
|
|
68
|
+
return /*#__PURE__*/React.createElement(PaddedDoubleContentCell, {
|
|
69
|
+
className: className
|
|
70
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
71
|
+
className: _TableModule.default.paddedTitleBlock
|
|
72
|
+
}, /*#__PURE__*/React.createElement(_Text.BodyMedium, {
|
|
73
|
+
className: _TableModule.default.doubleTitle
|
|
74
|
+
}, title), /*#__PURE__*/React.createElement(_Text.BodySmall, {
|
|
75
|
+
color: _Text.TEXT_COLORS.tertiary,
|
|
76
|
+
className: _TableModule.default.doubleSubtitle
|
|
77
|
+
}, subtitle ?? '')));
|
|
78
|
+
};
|
|
79
|
+
exports.DoubleCell = DoubleCell;
|
|
80
|
+
const DateCell = _ref5 => {
|
|
81
|
+
let {
|
|
82
|
+
date,
|
|
83
|
+
className
|
|
84
|
+
} = _ref5;
|
|
85
|
+
const parsedDate = typeof date === 'object' ? date : (0, _parseISO.default)(date);
|
|
86
|
+
return /*#__PURE__*/React.createElement(DoubleCell, {
|
|
87
|
+
title: `${parsedDate.getMonth() + 1} / ${parsedDate.getDate() + 1} / ${parsedDate.getFullYear()}`,
|
|
88
|
+
subtitle: `${(0, _formatDistance.default)(parsedDate, new Date())} ago`,
|
|
89
|
+
className: className
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
exports.DateCell = DateCell;
|
|
93
|
+
const Monogram = _ref6 => {
|
|
94
|
+
let {
|
|
95
|
+
initials
|
|
96
|
+
} = _ref6;
|
|
97
|
+
return /*#__PURE__*/React.createElement(_Avatar.Avatar, {
|
|
98
|
+
size: "small",
|
|
99
|
+
text: initials
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
exports.Monogram = Monogram;
|
|
103
|
+
const MonogramCell = _ref7 => {
|
|
104
|
+
let {
|
|
105
|
+
initials,
|
|
106
|
+
className
|
|
107
|
+
} = _ref7;
|
|
108
|
+
return /*#__PURE__*/React.createElement(PaddedContentCell, {
|
|
109
|
+
className: className
|
|
110
|
+
}, /*#__PURE__*/React.createElement(Monogram, {
|
|
111
|
+
initials: initials
|
|
112
|
+
}));
|
|
113
|
+
};
|
|
114
|
+
exports.MonogramCell = MonogramCell;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
// $FlowIssue[nonstrict-import] date-fns
|
|
5
|
+
import formatDistance from 'date-fns/formatDistance';
|
|
6
|
+
// $FlowIssue[nonstrict-import] date-fns
|
|
7
|
+
import parseISO from 'date-fns/parseISO';
|
|
8
|
+
|
|
9
|
+
import {classify} from '../../utils/classify';
|
|
10
|
+
import type {ClassNameComponent} from '../../utils/makeClassNameComponent';
|
|
11
|
+
import {makeClassNameComponent} from '../../utils/makeClassNameComponent';
|
|
12
|
+
import {Avatar} from '../Avatar';
|
|
13
|
+
import {BodyMedium, BodySmall, TEXT_COLORS} from '../Text';
|
|
14
|
+
|
|
15
|
+
import css from './Table.module.css';
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
type CellsProps = {
|
|
19
|
+
children?: React.Node,
|
|
20
|
+
className?: ?string,
|
|
21
|
+
truncatedText?: React.Node,
|
|
22
|
+
onClick?: ?(SyntheticEvent<HTMLElement>) => mixed,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const Cells = ({
|
|
26
|
+
children,
|
|
27
|
+
className,
|
|
28
|
+
...rest
|
|
29
|
+
}: CellsProps): React.Element<'div'> => (
|
|
30
|
+
<div className={classify(css.row, className)} {...rest}>
|
|
31
|
+
{children}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
export const Row = Cells;
|
|
35
|
+
|
|
36
|
+
export const Cell = ({
|
|
37
|
+
children,
|
|
38
|
+
className,
|
|
39
|
+
}: CellsProps): React.Element<'div'> => (
|
|
40
|
+
<div className={classify(css.cell, className)}>{children}</div>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export const BasicSingleCell: ClassNameComponent<'td'> = makeClassNameComponent(
|
|
44
|
+
css.defaultSingleCell,
|
|
45
|
+
'td',
|
|
46
|
+
);
|
|
47
|
+
export const BasicDoubleCell: ClassNameComponent<'td'> = makeClassNameComponent(
|
|
48
|
+
css.defaultDoubleCell,
|
|
49
|
+
'td',
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
export const PaddedContentCell: ClassNameComponent<'td'> =
|
|
53
|
+
makeClassNameComponent(css.singleContentCell, 'td');
|
|
54
|
+
|
|
55
|
+
export const PaddedDoubleContentCell: ClassNameComponent<'td'> =
|
|
56
|
+
makeClassNameComponent(css.doubleContentCell, 'td');
|
|
57
|
+
|
|
58
|
+
export const SingleCell = ({
|
|
59
|
+
title,
|
|
60
|
+
className,
|
|
61
|
+
}: {
|
|
62
|
+
title: string,
|
|
63
|
+
icon?: React.Node,
|
|
64
|
+
className?: string,
|
|
65
|
+
}): React.Node => (
|
|
66
|
+
<PaddedContentCell className={className}>
|
|
67
|
+
<BodyMedium className={css.paddedTitleBlock}>{title}</BodyMedium>
|
|
68
|
+
</PaddedContentCell>
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
export const DoubleCell = ({
|
|
72
|
+
title,
|
|
73
|
+
subtitle,
|
|
74
|
+
className,
|
|
75
|
+
}: {
|
|
76
|
+
title: React.Node,
|
|
77
|
+
subtitle?: React.Node,
|
|
78
|
+
className?: string,
|
|
79
|
+
}): React.Node => (
|
|
80
|
+
<PaddedDoubleContentCell className={className}>
|
|
81
|
+
<div className={css.paddedTitleBlock}>
|
|
82
|
+
<BodyMedium className={css.doubleTitle}>{title}</BodyMedium>
|
|
83
|
+
<BodySmall color={TEXT_COLORS.tertiary} className={css.doubleSubtitle}>
|
|
84
|
+
{subtitle ?? ''}
|
|
85
|
+
</BodySmall>
|
|
86
|
+
</div>
|
|
87
|
+
</PaddedDoubleContentCell>
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
export const DateCell = ({
|
|
91
|
+
date,
|
|
92
|
+
className,
|
|
93
|
+
}: {
|
|
94
|
+
date: string | Date,
|
|
95
|
+
className?: string,
|
|
96
|
+
}): React.Node => {
|
|
97
|
+
const parsedDate: Date = typeof date === 'object' ? date : parseISO(date);
|
|
98
|
+
return (
|
|
99
|
+
<DoubleCell
|
|
100
|
+
title={`${parsedDate.getMonth() + 1} / ${
|
|
101
|
+
parsedDate.getDate() + 1
|
|
102
|
+
} / ${parsedDate.getFullYear()}`}
|
|
103
|
+
subtitle={`${formatDistance(parsedDate, new Date())} ago`}
|
|
104
|
+
className={className}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const Monogram = ({initials}: {initials: string}): React.Node => (
|
|
110
|
+
<Avatar size="small" text={initials} />
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
export const MonogramCell = ({
|
|
114
|
+
initials,
|
|
115
|
+
className,
|
|
116
|
+
}: {
|
|
117
|
+
initials: string,
|
|
118
|
+
className?: string,
|
|
119
|
+
}): React.Node => (
|
|
120
|
+
<PaddedContentCell className={className}>
|
|
121
|
+
<Monogram initials={initials} />
|
|
122
|
+
</PaddedContentCell>
|
|
123
|
+
);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BasicRow = void 0;
|
|
7
|
+
exports.DefaultRow = DefaultRow;
|
|
8
|
+
exports.EmptyRow = void 0;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
11
|
+
var _makeClassNameComponent = require("../../utils/makeClassNameComponent");
|
|
12
|
+
var _Checkbox = require("../Checkbox");
|
|
13
|
+
var _CircularLoader = require("../CircularLoader");
|
|
14
|
+
var _Text = require("../Text");
|
|
15
|
+
var _Cell = require("./Cell");
|
|
16
|
+
var _TableModule = _interopRequireDefault(require("./Table.module.css"));
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
+
|
|
21
|
+
const BasicRow = (0, _makeClassNameComponent.makeClassNameComponent)(_TableModule.default.defaultRow, 'tr');
|
|
22
|
+
exports.BasicRow = BasicRow;
|
|
23
|
+
const EmptyRow = _ref => {
|
|
24
|
+
let {
|
|
25
|
+
isLoading,
|
|
26
|
+
emptyText,
|
|
27
|
+
headersLength = 0,
|
|
28
|
+
customLoader
|
|
29
|
+
} = _ref;
|
|
30
|
+
return /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", {
|
|
31
|
+
colSpan: headersLength
|
|
32
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
33
|
+
className: _TableModule.default.emptyRow
|
|
34
|
+
}, isLoading ? customLoader ? customLoader : /*#__PURE__*/React.createElement("div", {
|
|
35
|
+
className: _TableModule.default.defaultLoader
|
|
36
|
+
}, ' ', /*#__PURE__*/React.createElement(_CircularLoader.CircularLoader, {
|
|
37
|
+
colorToken: "colorFillPrimary",
|
|
38
|
+
size: "large"
|
|
39
|
+
})) : emptyText || /*#__PURE__*/React.createElement(_Text.BodyLarge, {
|
|
40
|
+
color: _Text.TEXT_COLORS.secondary,
|
|
41
|
+
className: _TableModule.default.defaultEmptyText
|
|
42
|
+
}, "Nothing to display here."))));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// This is a fallback row we use to render a table when
|
|
46
|
+
// initially stubbing out a design, the idea is you just avoid
|
|
47
|
+
// passing in a Row component and instead let this render out
|
|
48
|
+
// all the fields in the header in the short term
|
|
49
|
+
//
|
|
50
|
+
// Using the default row has the benefit that mismatches between
|
|
51
|
+
// header and entries _will_ error out even though there are the
|
|
52
|
+
// suppressions below
|
|
53
|
+
exports.EmptyRow = EmptyRow;
|
|
54
|
+
function DefaultRow(_ref2) {
|
|
55
|
+
let {
|
|
56
|
+
data,
|
|
57
|
+
extras,
|
|
58
|
+
headers,
|
|
59
|
+
selected,
|
|
60
|
+
onSelect,
|
|
61
|
+
className,
|
|
62
|
+
disabled
|
|
63
|
+
} = _ref2;
|
|
64
|
+
return /*#__PURE__*/React.createElement(BasicRow, {
|
|
65
|
+
className: (0, _classify.default)(className, selected ? _TableModule.default.defaultSelectedBodyRow : _TableModule.default.defaultBodyRow)
|
|
66
|
+
}, selected != null && /*#__PURE__*/React.createElement(_Cell.PaddedContentCell, null, /*#__PURE__*/React.createElement("div", {
|
|
67
|
+
className: _TableModule.default.checkbox
|
|
68
|
+
}, /*#__PURE__*/React.createElement(_Checkbox.Checkbox, {
|
|
69
|
+
checked: selected ? true : false,
|
|
70
|
+
onChange: onSelect,
|
|
71
|
+
disabled: disabled
|
|
72
|
+
}))), headers.map((item, index) => {
|
|
73
|
+
const {
|
|
74
|
+
key,
|
|
75
|
+
render: Renderer,
|
|
76
|
+
className: cellClassName,
|
|
77
|
+
sticky
|
|
78
|
+
} = item;
|
|
79
|
+
const value = data[key];
|
|
80
|
+
return Renderer ? /*#__PURE__*/React.createElement(Renderer, {
|
|
81
|
+
key: index,
|
|
82
|
+
data: data,
|
|
83
|
+
extras: extras,
|
|
84
|
+
selected: selected,
|
|
85
|
+
className: (0, _classify.default)({
|
|
86
|
+
[_TableModule.default.stickyCell]: sticky
|
|
87
|
+
})
|
|
88
|
+
}) : /*#__PURE__*/React.createElement(_Cell.SingleCell, {
|
|
89
|
+
key: index,
|
|
90
|
+
title: String(value),
|
|
91
|
+
className: (0, _classify.default)(cellClassName, {
|
|
92
|
+
[_TableModule.default.stickyCell]: sticky
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
import classify from '../../utils/classify';
|
|
6
|
+
import type {ClassNameComponent} from '../../utils/makeClassNameComponent';
|
|
7
|
+
import {makeClassNameComponent} from '../../utils/makeClassNameComponent';
|
|
8
|
+
import {Checkbox} from '../Checkbox';
|
|
9
|
+
import {CircularLoader} from '../CircularLoader';
|
|
10
|
+
import {BodyLarge, TEXT_COLORS} from '../Text';
|
|
11
|
+
|
|
12
|
+
import {PaddedContentCell, SingleCell} from './Cell';
|
|
13
|
+
import type {GenericObject} from './Table';
|
|
14
|
+
import type {GenericHeaderItems} from './TableHeader';
|
|
15
|
+
|
|
16
|
+
import css from './Table.module.css';
|
|
17
|
+
|
|
18
|
+
// When using a custom Row prop, you need to create a component that looks like
|
|
19
|
+
// MyRow = (props: TableRowProps<Entries, Extras>): React.Node => {...}
|
|
20
|
+
// otherwise flow will complain.
|
|
21
|
+
// Note that b/c extras is often optional, you will need to explicitly include
|
|
22
|
+
// `invariant(extras, 'extras exists');` in order to pull values out of
|
|
23
|
+
// extras (flow will remind you that it is of type `U | void`)
|
|
24
|
+
export type TableRowProps<T, U> = {
|
|
25
|
+
data: T,
|
|
26
|
+
extras?: U,
|
|
27
|
+
sortedKeys?: string[],
|
|
28
|
+
headers?: GenericHeaderItems<T, U>,
|
|
29
|
+
selected?: boolean,
|
|
30
|
+
disabled?: boolean,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type TableRow<T, U> = React.ComponentType<TableRowProps<T, U>>;
|
|
34
|
+
|
|
35
|
+
export const BasicRow: ClassNameComponent<'tr'> = makeClassNameComponent(
|
|
36
|
+
css.defaultRow,
|
|
37
|
+
'tr',
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
type EmptyRowProps = {
|
|
41
|
+
emptyText?: React.Node,
|
|
42
|
+
isLoading?: boolean,
|
|
43
|
+
headersLength: number,
|
|
44
|
+
customLoader?: React.Node,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const EmptyRow = ({
|
|
48
|
+
isLoading,
|
|
49
|
+
emptyText,
|
|
50
|
+
headersLength = 0,
|
|
51
|
+
customLoader,
|
|
52
|
+
}: EmptyRowProps): React.Element<'tr'> => (
|
|
53
|
+
<tr>
|
|
54
|
+
<td colSpan={headersLength}>
|
|
55
|
+
<div className={css.emptyRow}>
|
|
56
|
+
{isLoading ? (
|
|
57
|
+
customLoader ? (
|
|
58
|
+
customLoader
|
|
59
|
+
) : (
|
|
60
|
+
<div className={css.defaultLoader}>
|
|
61
|
+
{' '}
|
|
62
|
+
<CircularLoader colorToken="colorFillPrimary" size="large" />
|
|
63
|
+
</div>
|
|
64
|
+
)
|
|
65
|
+
) : (
|
|
66
|
+
emptyText || (
|
|
67
|
+
<BodyLarge
|
|
68
|
+
color={TEXT_COLORS.secondary}
|
|
69
|
+
className={css.defaultEmptyText}
|
|
70
|
+
>
|
|
71
|
+
Nothing to display here.
|
|
72
|
+
</BodyLarge>
|
|
73
|
+
)
|
|
74
|
+
)}
|
|
75
|
+
</div>
|
|
76
|
+
</td>
|
|
77
|
+
</tr>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// This is a fallback row we use to render a table when
|
|
81
|
+
// initially stubbing out a design, the idea is you just avoid
|
|
82
|
+
// passing in a Row component and instead let this render out
|
|
83
|
+
// all the fields in the header in the short term
|
|
84
|
+
//
|
|
85
|
+
// Using the default row has the benefit that mismatches between
|
|
86
|
+
// header and entries _will_ error out even though there are the
|
|
87
|
+
// suppressions below
|
|
88
|
+
export function DefaultRow<T: GenericObject, U: GenericObject>({
|
|
89
|
+
data,
|
|
90
|
+
extras,
|
|
91
|
+
headers,
|
|
92
|
+
selected,
|
|
93
|
+
onSelect,
|
|
94
|
+
className,
|
|
95
|
+
disabled,
|
|
96
|
+
}: {
|
|
97
|
+
data: T,
|
|
98
|
+
extras?: U,
|
|
99
|
+
headers: GenericHeaderItems<T, U>,
|
|
100
|
+
selected?: boolean,
|
|
101
|
+
// value dependent on checkbox checked value
|
|
102
|
+
onSelect?: ({value: string, checked: boolean}) => mixed,
|
|
103
|
+
className?: string,
|
|
104
|
+
disabled?: boolean,
|
|
105
|
+
}): React.Node {
|
|
106
|
+
return (
|
|
107
|
+
<BasicRow
|
|
108
|
+
className={classify(
|
|
109
|
+
className,
|
|
110
|
+
selected ? css.defaultSelectedBodyRow : css.defaultBodyRow,
|
|
111
|
+
)}
|
|
112
|
+
>
|
|
113
|
+
{selected != null && (
|
|
114
|
+
<PaddedContentCell>
|
|
115
|
+
<div className={css.checkbox}>
|
|
116
|
+
<Checkbox
|
|
117
|
+
checked={selected ? true : false}
|
|
118
|
+
onChange={onSelect}
|
|
119
|
+
disabled={disabled}
|
|
120
|
+
/>
|
|
121
|
+
</div>
|
|
122
|
+
</PaddedContentCell>
|
|
123
|
+
)}
|
|
124
|
+
{headers.map((item, index) => {
|
|
125
|
+
const {key, render: Renderer, className: cellClassName, sticky} = item;
|
|
126
|
+
const value = data[key];
|
|
127
|
+
return Renderer ? (
|
|
128
|
+
<Renderer
|
|
129
|
+
key={index}
|
|
130
|
+
data={data}
|
|
131
|
+
extras={extras}
|
|
132
|
+
selected={selected}
|
|
133
|
+
className={classify({[css.stickyCell]: sticky})}
|
|
134
|
+
/>
|
|
135
|
+
) : (
|
|
136
|
+
<SingleCell
|
|
137
|
+
key={index}
|
|
138
|
+
title={String(value)}
|
|
139
|
+
className={classify(cellClassName, {[css.stickyCell]: sticky})}
|
|
140
|
+
/>
|
|
141
|
+
);
|
|
142
|
+
})}
|
|
143
|
+
</BasicRow>
|
|
144
|
+
);
|
|
145
|
+
}
|