@atlaskit/table 0.2.0 → 0.2.2
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/CHANGELOG.md +13 -0
- package/dist/cjs/body.js +16 -35
- package/dist/cjs/head-cell.js +6 -12
- package/dist/cjs/hooks/selection-provider.js +1 -9
- package/dist/cjs/hooks/use-row-id.js +2 -5
- package/dist/cjs/hooks/use-selectable.js +13 -29
- package/dist/cjs/hooks/use-sorting.js +6 -17
- package/dist/cjs/hooks/use-table-body.js +1 -7
- package/dist/cjs/hooks/use-table.js +4 -13
- package/dist/cjs/index.js +0 -8
- package/dist/cjs/row.js +8 -25
- package/dist/cjs/selectable-cell.js +6 -20
- package/dist/cjs/sortable-column.js +12 -26
- package/dist/cjs/table.js +8 -22
- package/dist/cjs/thead.js +10 -27
- package/dist/cjs/ui/base-cell.js +15 -21
- package/dist/cjs/ui/bulk-action-overlay.js +4 -7
- package/dist/cjs/ui/index.js +0 -9
- package/dist/cjs/ui/selectable-cell.js +4 -7
- package/dist/cjs/ui/sort-icon.js +2 -14
- package/dist/cjs/ui/table.js +2 -5
- package/dist/cjs/ui/tbody.js +2 -5
- package/dist/cjs/ui/td.js +3 -10
- package/dist/cjs/ui/th.js +5 -10
- package/dist/cjs/ui/thead.js +2 -4
- package/dist/cjs/ui/tr.js +6 -11
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/body.js +11 -8
- package/dist/es2019/head-cell.js +3 -4
- package/dist/es2019/hooks/selection-provider.js +1 -2
- package/dist/es2019/hooks/use-row-id.js +2 -2
- package/dist/es2019/hooks/use-selectable.js +4 -13
- package/dist/es2019/hooks/use-sorting.js +0 -4
- package/dist/es2019/hooks/use-table-body.js +1 -1
- package/dist/es2019/hooks/use-table.js +3 -4
- package/dist/es2019/row.js +2 -4
- package/dist/es2019/selectable-cell.js +0 -2
- package/dist/es2019/sortable-column.js +5 -10
- package/dist/es2019/table.js +0 -2
- package/dist/es2019/thead.js +3 -6
- package/dist/es2019/ui/base-cell.js +4 -5
- package/dist/es2019/ui/bulk-action-overlay.js +4 -3
- package/dist/es2019/ui/selectable-cell.js +2 -1
- package/dist/es2019/ui/sort-icon.js +1 -5
- package/dist/es2019/ui/table.js +1 -1
- package/dist/es2019/ui/tbody.js +2 -2
- package/dist/es2019/ui/td.js +4 -3
- package/dist/es2019/ui/th.js +0 -1
- package/dist/es2019/ui/thead.js +2 -1
- package/dist/es2019/ui/tr.js +2 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/body.js +16 -21
- package/dist/esm/head-cell.js +8 -9
- package/dist/esm/hooks/selection-provider.js +1 -2
- package/dist/esm/hooks/use-row-id.js +2 -2
- package/dist/esm/hooks/use-selectable.js +13 -25
- package/dist/esm/hooks/use-sorting.js +6 -12
- package/dist/esm/hooks/use-table-body.js +1 -1
- package/dist/esm/hooks/use-table.js +4 -5
- package/dist/esm/row.js +8 -13
- package/dist/esm/selectable-cell.js +5 -9
- package/dist/esm/sortable-column.js +12 -18
- package/dist/esm/table.js +8 -12
- package/dist/esm/thead.js +10 -16
- package/dist/esm/ui/base-cell.js +14 -15
- package/dist/esm/ui/bulk-action-overlay.js +4 -3
- package/dist/esm/ui/selectable-cell.js +4 -3
- package/dist/esm/ui/sort-icon.js +3 -8
- package/dist/esm/ui/table.js +3 -3
- package/dist/esm/ui/tbody.js +2 -2
- package/dist/esm/ui/td.js +5 -5
- package/dist/esm/ui/th.js +5 -6
- package/dist/esm/ui/thead.js +2 -1
- package/dist/esm/ui/tr.js +6 -6
- package/dist/esm/version.json +1 -1
- package/package.json +3 -3
package/dist/cjs/ui/thead.js
CHANGED
|
@@ -4,10 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.THead = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("@emotion/react");
|
|
9
|
-
|
|
10
8
|
/** @jsx jsx */
|
|
9
|
+
|
|
11
10
|
var baseStyles = (0, _react.css)({
|
|
12
11
|
position: 'sticky',
|
|
13
12
|
zIndex: 1,
|
|
@@ -17,6 +16,7 @@ var baseStyles = (0, _react.css)({
|
|
|
17
16
|
borderTop: '2px solid transparent',
|
|
18
17
|
inset: 0
|
|
19
18
|
});
|
|
19
|
+
|
|
20
20
|
/**
|
|
21
21
|
* __THead__
|
|
22
22
|
*
|
|
@@ -24,12 +24,10 @@ var baseStyles = (0, _react.css)({
|
|
|
24
24
|
*
|
|
25
25
|
* @primitive
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
27
|
var THead = function THead(_ref) {
|
|
29
28
|
var children = _ref.children;
|
|
30
29
|
return (0, _react.jsx)("thead", {
|
|
31
30
|
css: baseStyles
|
|
32
31
|
}, children);
|
|
33
32
|
};
|
|
34
|
-
|
|
35
33
|
exports.THead = THead;
|
package/dist/cjs/ui/tr.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.TR = void 0;
|
|
9
|
-
|
|
10
8
|
var _react = require("@emotion/react");
|
|
11
|
-
|
|
12
9
|
var _focusRing = _interopRequireDefault(require("@atlaskit/focus-ring"));
|
|
13
|
-
|
|
14
10
|
/** @jsx jsx */
|
|
11
|
+
|
|
15
12
|
var baseStyles = (0, _react.css)({
|
|
16
13
|
height: 48,
|
|
17
14
|
position: 'relative',
|
|
@@ -23,9 +20,9 @@ var selectedStyles = (0, _react.css)({
|
|
|
23
20
|
backgroundColor: "var(--ds-background-selected, #DEEBFF88)",
|
|
24
21
|
'&:hover': {
|
|
25
22
|
backgroundColor: "var(--ds-background-selected-hovered, #DEEBFF)" // B50
|
|
26
|
-
|
|
27
23
|
}
|
|
28
24
|
});
|
|
25
|
+
|
|
29
26
|
var bodyRowStyles = (0, _react.css)({
|
|
30
27
|
borderBottom: "1px solid ".concat("var(--ds-border, #eee)"),
|
|
31
28
|
'&:hover': {
|
|
@@ -35,7 +32,6 @@ var bodyRowStyles = (0, _react.css)({
|
|
|
35
32
|
boxShadow: 'none'
|
|
36
33
|
}
|
|
37
34
|
});
|
|
38
|
-
|
|
39
35
|
/**
|
|
40
36
|
* __Row__
|
|
41
37
|
*
|
|
@@ -45,10 +41,10 @@ var bodyRowStyles = (0, _react.css)({
|
|
|
45
41
|
*/
|
|
46
42
|
var TR = function TR(_ref) {
|
|
47
43
|
var children = _ref.children,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
testId = _ref.testId,
|
|
45
|
+
isSelected = _ref.isSelected,
|
|
46
|
+
_ref$isBodyRow = _ref.isBodyRow,
|
|
47
|
+
isBodyRow = _ref$isBodyRow === void 0 ? true : _ref$isBodyRow;
|
|
52
48
|
return (0, _react.jsx)(_focusRing.default, {
|
|
53
49
|
isInset: true
|
|
54
50
|
}, (0, _react.jsx)("tr", {
|
|
@@ -58,5 +54,4 @@ var TR = function TR(_ref) {
|
|
|
58
54
|
css: [baseStyles, isBodyRow && bodyRowStyles, isSelected && selectedStyles]
|
|
59
55
|
}, children));
|
|
60
56
|
};
|
|
61
|
-
|
|
62
57
|
exports.TR = TR;
|
package/dist/cjs/version.json
CHANGED
package/dist/es2019/body.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @repo/internal/react/no-clone-element */
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { Children, useEffect, useMemo } from 'react';
|
|
5
4
|
import { jsx } from '@emotion/react';
|
|
@@ -8,7 +7,6 @@ import { RowProvider } from './hooks/use-row-id';
|
|
|
8
7
|
import { useTable } from './hooks/use-table';
|
|
9
8
|
import { TableBodyProvider } from './hooks/use-table-body';
|
|
10
9
|
import * as Primitives from './ui';
|
|
11
|
-
|
|
12
10
|
/**
|
|
13
11
|
* __Table body__
|
|
14
12
|
*/
|
|
@@ -22,19 +20,24 @@ function TBody({
|
|
|
22
20
|
const [_state, {
|
|
23
21
|
removeAll,
|
|
24
22
|
setMax
|
|
25
|
-
}] = useSelection();
|
|
23
|
+
}] = useSelection();
|
|
26
24
|
|
|
25
|
+
// TODO: this seems like something the user should control or opt into.
|
|
27
26
|
useEffect(() => {
|
|
28
|
-
removeAll === null || removeAll === void 0 ? void 0 : removeAll();
|
|
27
|
+
removeAll === null || removeAll === void 0 ? void 0 : removeAll();
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- When the rows change, we [currently] want to call removeAll.
|
|
29
30
|
}, [rows]);
|
|
30
31
|
const childrenCount = Children.count(children);
|
|
31
|
-
const rowsLength = rows === null || rows === void 0 ? void 0 : rows.length;
|
|
32
|
+
const rowsLength = rows === null || rows === void 0 ? void 0 : rows.length;
|
|
32
33
|
|
|
34
|
+
// Set data length (via setMax) whenever data changes
|
|
33
35
|
useEffect(() => {
|
|
34
36
|
const numRows = rowsLength !== null && rowsLength !== void 0 ? rowsLength : childrenCount;
|
|
35
37
|
setMax === null || setMax === void 0 ? void 0 : setMax(numRows);
|
|
36
38
|
}, [rowsLength, childrenCount, setMax]);
|
|
37
|
-
const sortedRows = useMemo(() => rows === null || rows === void 0 ? void 0 : rows.map((row, idx) => ({
|
|
39
|
+
const sortedRows = useMemo(() => rows === null || rows === void 0 ? void 0 : rows.map((row, idx) => ({
|
|
40
|
+
...row,
|
|
38
41
|
idx
|
|
39
42
|
})).sort(sortFn), [rows, sortFn]);
|
|
40
43
|
return jsx(TableBodyProvider, {
|
|
@@ -45,11 +48,11 @@ function TBody({
|
|
|
45
48
|
}) => jsx(RowProvider, {
|
|
46
49
|
key: idx,
|
|
47
50
|
value: idx
|
|
48
|
-
},
|
|
51
|
+
},
|
|
52
|
+
// @ts-expect-error
|
|
49
53
|
children(row))) : Children.map(children, (row, idx) => jsx(RowProvider, {
|
|
50
54
|
key: idx,
|
|
51
55
|
value: idx
|
|
52
56
|
}, row))));
|
|
53
57
|
}
|
|
54
|
-
|
|
55
58
|
export default TBody;
|
package/dist/es2019/head-cell.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
3
|
+
|
|
4
4
|
import { jsx } from '@emotion/react';
|
|
5
5
|
import { UNSAFE_Text as Text } from '@atlaskit/ds-explorations';
|
|
6
6
|
import { TH } from './ui/th';
|
|
7
|
+
|
|
7
8
|
/**
|
|
8
9
|
* __HeadCell__
|
|
9
10
|
*
|
|
10
11
|
* HeadCell element
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
13
|
const Column = ({
|
|
14
14
|
children,
|
|
15
15
|
align,
|
|
@@ -24,8 +24,7 @@ const Column = ({
|
|
|
24
24
|
backgroundColor: backgroundColor
|
|
25
25
|
}, jsx(Text, {
|
|
26
26
|
color: "color.text",
|
|
27
|
-
fontWeight: "
|
|
27
|
+
fontWeight: "medium"
|
|
28
28
|
}, children));
|
|
29
29
|
};
|
|
30
|
-
|
|
31
30
|
export default Column;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { createContext, useContext } from 'react';
|
|
2
2
|
import useSelectionReducer, { defaultSelectableState } from './use-selectable';
|
|
3
3
|
const SelectionContext = /*#__PURE__*/createContext([defaultSelectableState, {}]);
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* __Selection provider__
|
|
6
7
|
*
|
|
@@ -10,7 +11,6 @@ const SelectionContext = /*#__PURE__*/createContext([defaultSelectableState, {}]
|
|
|
10
11
|
* - [Code](https://atlassian.design/components/{packageName}/code)
|
|
11
12
|
* - [Usage](https://atlassian.design/components/{packageName}/usage)
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
14
|
const SelectionProvider = ({
|
|
15
15
|
children
|
|
16
16
|
}) => {
|
|
@@ -19,7 +19,6 @@ const SelectionProvider = ({
|
|
|
19
19
|
value: reducer
|
|
20
20
|
}, children);
|
|
21
21
|
};
|
|
22
|
-
|
|
23
22
|
export const useSelection = () => {
|
|
24
23
|
return useContext(SelectionContext);
|
|
25
24
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
2
|
const RowContext = /*#__PURE__*/createContext(undefined);
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* @internal
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
7
|
export const useRowId = () => useContext(RowContext);
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* __Row provider__
|
|
10
11
|
* @internal
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
13
|
export const RowProvider = RowContext.Provider;
|
|
@@ -7,24 +7,21 @@ export const defaultSelectableState = {
|
|
|
7
7
|
selectionStart: -1,
|
|
8
8
|
previousSelection: []
|
|
9
9
|
};
|
|
10
|
-
|
|
11
10
|
const arrayFromRange = (from, to) => {
|
|
12
11
|
let startIdx = from;
|
|
13
12
|
let stopIdx = to;
|
|
14
13
|
let increment = 1;
|
|
15
|
-
|
|
16
14
|
if (from > to) {
|
|
17
15
|
startIdx = to;
|
|
18
16
|
stopIdx = from;
|
|
19
17
|
increment = 0;
|
|
20
|
-
}
|
|
21
|
-
|
|
18
|
+
}
|
|
22
19
|
|
|
20
|
+
// Create an array with values between `from` and `to` - either ascending or descending
|
|
23
21
|
return Array.from({
|
|
24
22
|
length: stopIdx - startIdx
|
|
25
23
|
}, (_, i) => startIdx + i + increment);
|
|
26
24
|
};
|
|
27
|
-
|
|
28
25
|
function reducer({
|
|
29
26
|
checked,
|
|
30
27
|
anyChecked,
|
|
@@ -44,17 +41,17 @@ function reducer({
|
|
|
44
41
|
let updated = checked.slice();
|
|
45
42
|
let newSelectionStart = selectionStart;
|
|
46
43
|
let newPreviousSelection = previousSelection.slice();
|
|
47
|
-
|
|
48
44
|
if (shiftHeld) {
|
|
49
45
|
if (checked.length > 0) {
|
|
50
46
|
const newIds = arrayFromRange(selectionStart, id); // create an array of the new ids
|
|
47
|
+
|
|
51
48
|
// Uncheck ids from the previous selection.
|
|
52
49
|
// This is done to maintain consistency with Shift-select behaviour elsewhere (e.g. macOS)
|
|
53
50
|
// TODO: Code could be improved to only remove ids that are not included in the new range, avoiding needing to re-add them below
|
|
54
|
-
|
|
55
51
|
updated = updated.filter(id => !previousSelection.includes(id));
|
|
56
52
|
newIds.forEach(id => updated.indexOf(id) === -1 && updated.push(id) // If the new id is not already checked, check it
|
|
57
53
|
);
|
|
54
|
+
|
|
58
55
|
newPreviousSelection = newIds; // Maintain an array of the previous selection to allow for consistent Shift-select behaviour
|
|
59
56
|
}
|
|
60
57
|
} else {
|
|
@@ -67,7 +64,6 @@ function reducer({
|
|
|
67
64
|
}
|
|
68
65
|
|
|
69
66
|
newSelectionStart = id; // Reset selection start id to this non-shift-selected id
|
|
70
|
-
|
|
71
67
|
newPreviousSelection = []; // Reset previous selection as it is no longer relevant once a new non-shift-selected id is added
|
|
72
68
|
}
|
|
73
69
|
|
|
@@ -81,7 +77,6 @@ function reducer({
|
|
|
81
77
|
previousSelection: newPreviousSelection
|
|
82
78
|
};
|
|
83
79
|
}
|
|
84
|
-
|
|
85
80
|
case 'set_root':
|
|
86
81
|
return {
|
|
87
82
|
checked: action.value ? Array.from(Array(maxChecked).keys()) : [],
|
|
@@ -91,7 +86,6 @@ function reducer({
|
|
|
91
86
|
selectionStart,
|
|
92
87
|
previousSelection
|
|
93
88
|
};
|
|
94
|
-
|
|
95
89
|
case 'set_max':
|
|
96
90
|
{
|
|
97
91
|
const {
|
|
@@ -106,12 +100,10 @@ function reducer({
|
|
|
106
100
|
previousSelection
|
|
107
101
|
};
|
|
108
102
|
}
|
|
109
|
-
|
|
110
103
|
default:
|
|
111
104
|
throw new Error();
|
|
112
105
|
}
|
|
113
106
|
}
|
|
114
|
-
|
|
115
107
|
function useSelectable() {
|
|
116
108
|
const [state, dispatch] = useReducer(reducer, defaultSelectableState);
|
|
117
109
|
const toggleSelection = useCallback((id, shiftHeld) => {
|
|
@@ -148,5 +140,4 @@ function useSelectable() {
|
|
|
148
140
|
setMax
|
|
149
141
|
}];
|
|
150
142
|
}
|
|
151
|
-
|
|
152
143
|
export default useSelectable;
|
|
@@ -7,10 +7,8 @@ export const useSorting = sortKey => {
|
|
|
7
7
|
switch (oldLocalSortDirection) {
|
|
8
8
|
case undefined:
|
|
9
9
|
return 'ascending';
|
|
10
|
-
|
|
11
10
|
case 'ascending':
|
|
12
11
|
return 'descending';
|
|
13
|
-
|
|
14
12
|
case 'descending':
|
|
15
13
|
return 'ascending';
|
|
16
14
|
}
|
|
@@ -25,7 +23,6 @@ export const useSorting = sortKey => {
|
|
|
25
23
|
} else {
|
|
26
24
|
toggleSortDirection();
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
return localSortKey;
|
|
30
27
|
});
|
|
31
28
|
}, [toggleSortDirection]);
|
|
@@ -33,7 +30,6 @@ export const useSorting = sortKey => {
|
|
|
33
30
|
if (localSortKey === 'unset') {
|
|
34
31
|
return 0;
|
|
35
32
|
}
|
|
36
|
-
|
|
37
33
|
const ascendingComparator = rowA[localSortKey] < rowB[localSortKey] ? -1 : 1;
|
|
38
34
|
return localSortDirection === 'ascending' ? ascendingComparator : -ascendingComparator;
|
|
39
35
|
}, [localSortDirection, localSortKey]);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
2
|
import invariant from 'tiny-invariant';
|
|
3
3
|
const TableBodyContext = /*#__PURE__*/createContext(false);
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* __Table body provider__
|
|
6
7
|
* Ensures correct nesting of table elements.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
export const TableBodyProvider = TableBodyContext.Provider;
|
|
10
10
|
export const useTableBody = () => {
|
|
11
11
|
const hasTableBody = useContext(TableBodyContext);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { createContext, useContext } from 'react';
|
|
2
2
|
import __noop from '@atlaskit/ds-lib/noop';
|
|
3
|
-
|
|
4
3
|
function generateContext() {
|
|
5
4
|
return /*#__PURE__*/createContext({
|
|
6
5
|
isSelectable: false,
|
|
@@ -9,8 +8,8 @@ function generateContext() {
|
|
|
9
8
|
sortFn: () => 0
|
|
10
9
|
});
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
const TableContext = generateContext();
|
|
12
|
+
|
|
14
13
|
/**
|
|
15
14
|
* __Table state provider__
|
|
16
15
|
*
|
|
@@ -18,7 +17,6 @@ const TableContext = generateContext();
|
|
|
18
17
|
*
|
|
19
18
|
* - [Examples](https://atlassian.design/components/table/examples)
|
|
20
19
|
*/
|
|
21
|
-
|
|
22
20
|
export function TableProvider({
|
|
23
21
|
children,
|
|
24
22
|
state
|
|
@@ -31,5 +29,6 @@ export function TableProvider({
|
|
|
31
29
|
}, children)
|
|
32
30
|
);
|
|
33
31
|
}
|
|
34
|
-
export const useTable = () =>
|
|
32
|
+
export const useTable = () =>
|
|
33
|
+
// @ts-expect-error
|
|
35
34
|
useContext(TableContext);
|
package/dist/es2019/row.js
CHANGED
|
@@ -7,7 +7,6 @@ import { useTable } from './hooks/use-table';
|
|
|
7
7
|
import { useTableBody } from './hooks/use-table-body';
|
|
8
8
|
import SelectableCell from './selectable-cell';
|
|
9
9
|
import * as Primitives from './ui';
|
|
10
|
-
|
|
11
10
|
/**
|
|
12
11
|
* __Row__
|
|
13
12
|
*
|
|
@@ -20,8 +19,8 @@ const Row = /*#__PURE__*/memo(({
|
|
|
20
19
|
testId
|
|
21
20
|
}) => {
|
|
22
21
|
// To ensure valid nesting
|
|
23
|
-
useTableBody();
|
|
24
|
-
|
|
22
|
+
useTableBody();
|
|
23
|
+
// to access table state
|
|
25
24
|
const {
|
|
26
25
|
isSelectable
|
|
27
26
|
} = useTable();
|
|
@@ -34,7 +33,6 @@ const Row = /*#__PURE__*/memo(({
|
|
|
34
33
|
if (!isSelectable) {
|
|
35
34
|
return undefined;
|
|
36
35
|
}
|
|
37
|
-
|
|
38
36
|
return allChecked || checked.includes(rowId);
|
|
39
37
|
}, [allChecked, checked, isSelectable, rowId]);
|
|
40
38
|
return jsx(Primitives.TR, {
|
|
@@ -5,7 +5,6 @@ import Checkbox from '@atlaskit/checkbox';
|
|
|
5
5
|
import { useSelection } from './hooks/selection-provider';
|
|
6
6
|
import { useRowId } from './hooks/use-row-id';
|
|
7
7
|
import * as Primitives from './ui';
|
|
8
|
-
|
|
9
8
|
const SelectableCell = () => {
|
|
10
9
|
const [{
|
|
11
10
|
allChecked,
|
|
@@ -23,5 +22,4 @@ const SelectableCell = () => {
|
|
|
23
22
|
onChange: onChange
|
|
24
23
|
}));
|
|
25
24
|
};
|
|
26
|
-
|
|
27
25
|
export default /*#__PURE__*/memo(SelectableCell);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
|
|
3
2
|
/* eslint-disable no-unused-vars */
|
|
4
|
-
|
|
5
3
|
/** @jsx jsx */
|
|
6
4
|
import { useCallback } from 'react';
|
|
7
5
|
import { css, jsx } from '@emotion/react';
|
|
@@ -9,7 +7,6 @@ import Button from '@atlaskit/button';
|
|
|
9
7
|
import Tooltip from '@atlaskit/tooltip';
|
|
10
8
|
import { useTable } from './hooks/use-table';
|
|
11
9
|
import { SortIcon, TH } from './ui';
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* TODO these need to be i18n supported
|
|
15
12
|
*/
|
|
@@ -34,12 +31,12 @@ const overrideStyles = css({
|
|
|
34
31
|
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage-spacing
|
|
35
32
|
paddingInline: `2px !important`
|
|
36
33
|
});
|
|
34
|
+
|
|
37
35
|
/**
|
|
38
36
|
* __SortableColumn__
|
|
39
37
|
*
|
|
40
38
|
* SortableColumn is used in place of the default Column when sorting is desired.
|
|
41
39
|
*/
|
|
42
|
-
|
|
43
40
|
const SortableColumn = ({
|
|
44
41
|
name,
|
|
45
42
|
testId,
|
|
@@ -52,19 +49,18 @@ const SortableColumn = ({
|
|
|
52
49
|
sortDirection,
|
|
53
50
|
setSortState
|
|
54
51
|
} = useTable();
|
|
55
|
-
|
|
56
52
|
const getSortMessage = () => {
|
|
57
53
|
if (sortKey === name) {
|
|
58
54
|
// TODO: Change message depending on data type (string/number)
|
|
59
55
|
return sortingMessages[sortDirection || 'unsorted'].string;
|
|
60
56
|
}
|
|
61
|
-
|
|
62
57
|
return sortingMessages.unsorted.string;
|
|
63
58
|
};
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
const updateSortState = useCallback(
|
|
60
|
+
// @ts-expect-error: TODO: Our `name` typing is off; refer to `SortKey`
|
|
66
61
|
() => setSortState(name), [setSortState, name]);
|
|
67
|
-
return (
|
|
62
|
+
return (
|
|
63
|
+
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
68
64
|
jsx(TH, _extends({
|
|
69
65
|
testId: testId
|
|
70
66
|
}, other), jsx(Tooltip, {
|
|
@@ -82,5 +78,4 @@ const SortableColumn = ({
|
|
|
82
78
|
}), children)))
|
|
83
79
|
);
|
|
84
80
|
};
|
|
85
|
-
|
|
86
81
|
export default SortableColumn;
|
package/dist/es2019/table.js
CHANGED
|
@@ -5,7 +5,6 @@ import SelectionProvider from './hooks/selection-provider';
|
|
|
5
5
|
import { useSorting } from './hooks/use-sorting';
|
|
6
6
|
import { TableProvider } from './hooks/use-table';
|
|
7
7
|
import * as Primitives from './ui';
|
|
8
|
-
|
|
9
8
|
/**
|
|
10
9
|
* __Table__
|
|
11
10
|
*
|
|
@@ -38,5 +37,4 @@ function Table({
|
|
|
38
37
|
testId: testId
|
|
39
38
|
}, isSelectable ? jsx(SelectionProvider, null, children) : children));
|
|
40
39
|
}
|
|
41
|
-
|
|
42
40
|
export default Table;
|
package/dist/es2019/thead.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
+
|
|
2
3
|
import { jsx } from '@emotion/react';
|
|
3
4
|
import Checkbox from '@atlaskit/checkbox';
|
|
4
5
|
import { UNSAFE_Inline as Inline, UNSAFE_Text as Text } from '@atlaskit/ds-explorations';
|
|
@@ -6,7 +7,6 @@ import VisuallyHidden from '@atlaskit/visually-hidden';
|
|
|
6
7
|
import { useSelection } from './hooks/selection-provider';
|
|
7
8
|
import { useTable } from './hooks/use-table';
|
|
8
9
|
import * as Primitives from './ui';
|
|
9
|
-
|
|
10
10
|
const THead = ({
|
|
11
11
|
actions,
|
|
12
12
|
children
|
|
@@ -18,13 +18,11 @@ const THead = ({
|
|
|
18
18
|
setAll,
|
|
19
19
|
removeAll
|
|
20
20
|
}] = useSelection();
|
|
21
|
-
|
|
22
21
|
if (!isSelectable) {
|
|
23
22
|
return jsx(Primitives.THead, null, jsx(Primitives.TR, {
|
|
24
23
|
isBodyRow: false
|
|
25
24
|
}, children));
|
|
26
25
|
}
|
|
27
|
-
|
|
28
26
|
const isChecked = state.allChecked || state.anyChecked;
|
|
29
27
|
return jsx(Primitives.THead, null, jsx(Primitives.TR, {
|
|
30
28
|
isBodyRow: false
|
|
@@ -39,10 +37,9 @@ const THead = ({
|
|
|
39
37
|
id: "select-all"
|
|
40
38
|
}, "Select all rows")), children, isChecked && jsx(Primitives.BulkActionOverlay, null, jsx(Text, {
|
|
41
39
|
color: "color.text",
|
|
42
|
-
fontWeight: "
|
|
40
|
+
fontWeight: "medium"
|
|
43
41
|
}, state.checked.length, " selected"), actions && jsx(Inline, {
|
|
44
|
-
gap: "
|
|
42
|
+
gap: "space.100"
|
|
45
43
|
}, actions(state.checked)))));
|
|
46
44
|
};
|
|
47
|
-
|
|
48
45
|
export default THead;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @atlassian/tangerine/import/entry-points */
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { forwardRef } from 'react';
|
|
5
4
|
import { css, jsx } from '@emotion/react';
|
|
@@ -20,6 +19,7 @@ const baseResetStyles = css({
|
|
|
20
19
|
paddingRight: "var(--ds-space-100, 8px)"
|
|
21
20
|
}
|
|
22
21
|
});
|
|
22
|
+
|
|
23
23
|
/**
|
|
24
24
|
* __BaseCell__
|
|
25
25
|
*
|
|
@@ -27,14 +27,13 @@ const baseResetStyles = css({
|
|
|
27
27
|
*
|
|
28
28
|
* Basic cell element.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
30
|
export const BaseCell = /*#__PURE__*/forwardRef(({
|
|
32
31
|
testId,
|
|
33
32
|
as,
|
|
34
33
|
children,
|
|
35
34
|
align = 'text',
|
|
36
|
-
paddingBlock = '
|
|
37
|
-
paddingInline = '
|
|
35
|
+
paddingBlock = 'space.100',
|
|
36
|
+
paddingInline = 'space.200',
|
|
38
37
|
backgroundColor,
|
|
39
38
|
scope,
|
|
40
39
|
width,
|
|
@@ -54,5 +53,5 @@ export const BaseCell = /*#__PURE__*/forwardRef(({
|
|
|
54
53
|
} : undefined
|
|
55
54
|
}, jsx(Inline, {
|
|
56
55
|
justifyContent: alignMap[align],
|
|
57
|
-
gap: "
|
|
56
|
+
gap: "space.0"
|
|
58
57
|
}, children)));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
+
|
|
2
3
|
import { css, jsx } from '@emotion/react';
|
|
3
4
|
import { UNSAFE_Box as Box, UNSAFE_Inline as Inline } from '@atlaskit/ds-explorations';
|
|
4
5
|
const overlayStyles = css({
|
|
@@ -7,21 +8,21 @@ const overlayStyles = css({
|
|
|
7
8
|
bottom: 0,
|
|
8
9
|
left: 32
|
|
9
10
|
});
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* __Bulk action overlay__
|
|
12
14
|
*
|
|
13
15
|
* A bulk action overlay is used to conditionally render when a user makes a row selection
|
|
14
16
|
*/
|
|
15
|
-
|
|
16
17
|
export const BulkActionOverlay = ({
|
|
17
18
|
children
|
|
18
19
|
}) => jsx(Box, {
|
|
19
20
|
as: "th",
|
|
20
21
|
position: "absolute",
|
|
21
|
-
paddingInline: "
|
|
22
|
+
paddingInline: "space.100",
|
|
22
23
|
backgroundColor: "elevation.surface",
|
|
23
24
|
css: overlayStyles
|
|
24
25
|
}, jsx(Inline, {
|
|
25
|
-
gap: "
|
|
26
|
+
gap: "space.300",
|
|
26
27
|
alignItems: "center"
|
|
27
28
|
}, children));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
+
|
|
2
3
|
import { css, jsx } from '@emotion/react';
|
|
3
4
|
import { BaseCell } from './base-cell';
|
|
4
5
|
const spacingStyles = css({
|
|
@@ -11,12 +12,12 @@ const spacingStyles = css({
|
|
|
11
12
|
paddingLeft: '8px !important'
|
|
12
13
|
}
|
|
13
14
|
});
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* __Selectable cell__
|
|
16
18
|
*
|
|
17
19
|
* A selectable cell primitive designed to be used for light weight composition.
|
|
18
20
|
*/
|
|
19
|
-
|
|
20
21
|
export const SelectableCell = ({
|
|
21
22
|
children,
|
|
22
23
|
as = 'td'
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { memo } from 'react';
|
|
5
4
|
import { jsx } from '@emotion/react';
|
|
6
5
|
import ArrowDownIcon from '@atlaskit/icon/glyph/arrow-down';
|
|
7
6
|
import ArrowUpIcon from '@atlaskit/icon/glyph/arrow-up';
|
|
8
7
|
import { useTable } from '../hooks/use-table';
|
|
8
|
+
|
|
9
9
|
/**
|
|
10
10
|
* __SortIcon__
|
|
11
11
|
*
|
|
12
12
|
* SortIcon is used to display the sort state in our SortableColumn.
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
14
|
export const SortIcon = /*#__PURE__*/memo(({
|
|
16
15
|
name
|
|
17
16
|
}) => {
|
|
@@ -19,7 +18,6 @@ export const SortIcon = /*#__PURE__*/memo(({
|
|
|
19
18
|
sortKey,
|
|
20
19
|
sortDirection
|
|
21
20
|
} = useTable();
|
|
22
|
-
|
|
23
21
|
if (sortKey === name) {
|
|
24
22
|
switch (sortDirection) {
|
|
25
23
|
case 'ascending':
|
|
@@ -28,7 +26,6 @@ export const SortIcon = /*#__PURE__*/memo(({
|
|
|
28
26
|
label: "",
|
|
29
27
|
primaryColor: "inherit"
|
|
30
28
|
});
|
|
31
|
-
|
|
32
29
|
case 'descending':
|
|
33
30
|
return jsx(ArrowDownIcon, {
|
|
34
31
|
size: "small",
|
|
@@ -37,6 +34,5 @@ export const SortIcon = /*#__PURE__*/memo(({
|
|
|
37
34
|
});
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
|
-
|
|
41
37
|
return null;
|
|
42
38
|
});
|