@atlaskit/table 0.2.1 → 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 +6 -0
- package/dist/cjs/body.js +16 -35
- package/dist/cjs/head-cell.js +5 -11
- 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 +8 -25
- package/dist/cjs/ui/base-cell.js +14 -20
- package/dist/cjs/ui/bulk-action-overlay.js +2 -5
- 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 +2 -3
- 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 +1 -4
- package/dist/es2019/ui/base-cell.js +1 -2
- package/dist/es2019/ui/bulk-action-overlay.js +2 -1
- 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 +7 -8
- 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 +8 -14
- package/dist/esm/ui/base-cell.js +13 -14
- package/dist/esm/ui/bulk-action-overlay.js +2 -1
- 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 +2 -2
package/dist/es2019/ui/tr.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
+
|
|
2
3
|
import { css, jsx } from '@emotion/react';
|
|
3
4
|
import FocusRing from '@atlaskit/focus-ring';
|
|
4
5
|
const baseStyles = css({
|
|
@@ -12,9 +13,9 @@ const selectedStyles = css({
|
|
|
12
13
|
backgroundColor: "var(--ds-background-selected, #DEEBFF88)",
|
|
13
14
|
'&:hover': {
|
|
14
15
|
backgroundColor: "var(--ds-background-selected-hovered, #DEEBFF)" // B50
|
|
15
|
-
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
|
|
18
19
|
const bodyRowStyles = css({
|
|
19
20
|
borderBottom: `1px solid ${"var(--ds-border, #eee)"}`,
|
|
20
21
|
'&:hover': {
|
|
@@ -24,7 +25,6 @@ const bodyRowStyles = css({
|
|
|
24
25
|
boxShadow: 'none'
|
|
25
26
|
}
|
|
26
27
|
});
|
|
27
|
-
|
|
28
28
|
/**
|
|
29
29
|
* __Row__
|
|
30
30
|
*
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/body.js
CHANGED
|
@@ -2,13 +2,9 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
|
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
4
|
var _excluded = ["idx"];
|
|
5
|
-
|
|
6
5
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
-
|
|
8
6
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
9
|
-
|
|
10
7
|
/* eslint-disable @repo/internal/react/no-clone-element */
|
|
11
|
-
|
|
12
8
|
/** @jsx jsx */
|
|
13
9
|
import { Children, useEffect, useMemo } from 'react';
|
|
14
10
|
import { jsx } from '@emotion/react';
|
|
@@ -17,31 +13,31 @@ import { RowProvider } from './hooks/use-row-id';
|
|
|
17
13
|
import { useTable } from './hooks/use-table';
|
|
18
14
|
import { TableBodyProvider } from './hooks/use-table-body';
|
|
19
15
|
import * as Primitives from './ui';
|
|
20
|
-
|
|
21
16
|
/**
|
|
22
17
|
* __Table body__
|
|
23
18
|
*/
|
|
24
19
|
function TBody(_ref) {
|
|
25
20
|
var rows = _ref.rows,
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
children = _ref.children;
|
|
28
22
|
var _useTable = useTable(),
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
sortFn = _useTable.sortFn;
|
|
31
24
|
var _useSelection = useSelection(),
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
_useSelection2 = _slicedToArray(_useSelection, 2),
|
|
26
|
+
_state = _useSelection2[0],
|
|
27
|
+
_useSelection2$ = _useSelection2[1],
|
|
28
|
+
removeAll = _useSelection2$.removeAll,
|
|
29
|
+
setMax = _useSelection2$.setMax;
|
|
38
30
|
|
|
31
|
+
// TODO: this seems like something the user should control or opt into.
|
|
39
32
|
useEffect(function () {
|
|
40
|
-
removeAll === null || removeAll === void 0 ? void 0 : removeAll();
|
|
33
|
+
removeAll === null || removeAll === void 0 ? void 0 : removeAll();
|
|
34
|
+
|
|
35
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- When the rows change, we [currently] want to call removeAll.
|
|
41
36
|
}, [rows]);
|
|
42
37
|
var childrenCount = Children.count(children);
|
|
43
|
-
var rowsLength = rows === null || rows === void 0 ? void 0 : rows.length;
|
|
38
|
+
var rowsLength = rows === null || rows === void 0 ? void 0 : rows.length;
|
|
44
39
|
|
|
40
|
+
// Set data length (via setMax) whenever data changes
|
|
45
41
|
useEffect(function () {
|
|
46
42
|
var numRows = rowsLength !== null && rowsLength !== void 0 ? rowsLength : childrenCount;
|
|
47
43
|
setMax === null || setMax === void 0 ? void 0 : setMax(numRows);
|
|
@@ -57,12 +53,12 @@ function TBody(_ref) {
|
|
|
57
53
|
value: true
|
|
58
54
|
}, jsx(Primitives.TBody, null, typeof children === 'function' && sortedRows ? sortedRows.map(function (_ref2) {
|
|
59
55
|
var idx = _ref2.idx,
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
row = _objectWithoutProperties(_ref2, _excluded);
|
|
62
57
|
return jsx(RowProvider, {
|
|
63
58
|
key: idx,
|
|
64
59
|
value: idx
|
|
65
|
-
},
|
|
60
|
+
},
|
|
61
|
+
// @ts-expect-error
|
|
66
62
|
children(row));
|
|
67
63
|
}) : Children.map(children, function (row, idx) {
|
|
68
64
|
return jsx(RowProvider, {
|
|
@@ -71,5 +67,4 @@ function TBody(_ref) {
|
|
|
71
67
|
}, row);
|
|
72
68
|
})));
|
|
73
69
|
}
|
|
74
|
-
|
|
75
70
|
export default TBody;
|
package/dist/esm/head-cell.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
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
|
var Column = function Column(_ref) {
|
|
14
14
|
var children = _ref.children,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
align = _ref.align,
|
|
16
|
+
testId = _ref.testId,
|
|
17
|
+
backgroundColor = _ref.backgroundColor,
|
|
18
|
+
_ref$scope = _ref.scope,
|
|
19
|
+
scope = _ref$scope === void 0 ? 'col' : _ref$scope;
|
|
20
20
|
return jsx(TH, {
|
|
21
21
|
scope: scope,
|
|
22
22
|
align: align,
|
|
@@ -27,5 +27,4 @@ var Column = function Column(_ref) {
|
|
|
27
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
|
var SelectionContext = /*#__PURE__*/createContext([defaultSelectableState, {}]);
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* __Selection provider__
|
|
6
7
|
*
|
|
@@ -10,7 +11,6 @@ var 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
|
var SelectionProvider = function SelectionProvider(_ref) {
|
|
15
15
|
var children = _ref.children;
|
|
16
16
|
var reducer = useSelectionReducer();
|
|
@@ -18,7 +18,6 @@ var SelectionProvider = function SelectionProvider(_ref) {
|
|
|
18
18
|
value: reducer
|
|
19
19
|
}, children);
|
|
20
20
|
};
|
|
21
|
-
|
|
22
21
|
export var useSelection = function useSelection() {
|
|
23
22
|
return useContext(SelectionContext);
|
|
24
23
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
2
|
var RowContext = /*#__PURE__*/createContext(undefined);
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* @internal
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
7
|
export var useRowId = function useRowId() {
|
|
8
8
|
return useContext(RowContext);
|
|
9
9
|
};
|
|
10
|
+
|
|
10
11
|
/**
|
|
11
12
|
* __Row provider__
|
|
12
13
|
* @internal
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
15
|
export var RowProvider = RowContext.Provider;
|
|
@@ -8,50 +8,45 @@ export var defaultSelectableState = {
|
|
|
8
8
|
selectionStart: -1,
|
|
9
9
|
previousSelection: []
|
|
10
10
|
};
|
|
11
|
-
|
|
12
11
|
var arrayFromRange = function arrayFromRange(from, to) {
|
|
13
12
|
var startIdx = from;
|
|
14
13
|
var stopIdx = to;
|
|
15
14
|
var increment = 1;
|
|
16
|
-
|
|
17
15
|
if (from > to) {
|
|
18
16
|
startIdx = to;
|
|
19
17
|
stopIdx = from;
|
|
20
18
|
increment = 0;
|
|
21
|
-
}
|
|
22
|
-
|
|
19
|
+
}
|
|
23
20
|
|
|
21
|
+
// Create an array with values between `from` and `to` - either ascending or descending
|
|
24
22
|
return Array.from({
|
|
25
23
|
length: stopIdx - startIdx
|
|
26
24
|
}, function (_, i) {
|
|
27
25
|
return startIdx + i + increment;
|
|
28
26
|
});
|
|
29
27
|
};
|
|
30
|
-
|
|
31
28
|
function reducer(_ref, action) {
|
|
32
29
|
var checked = _ref.checked,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
anyChecked = _ref.anyChecked,
|
|
31
|
+
maxChecked = _ref.maxChecked,
|
|
32
|
+
selectionStart = _ref.selectionStart,
|
|
33
|
+
previousSelection = _ref.previousSelection;
|
|
38
34
|
switch (action.type) {
|
|
39
35
|
case 'toggle_selection':
|
|
40
36
|
{
|
|
41
37
|
var _action$value = action.value,
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
_id = _action$value.id,
|
|
39
|
+
_shiftHeld = _action$value.shiftHeld;
|
|
44
40
|
var updated = checked.slice();
|
|
45
41
|
var newSelectionStart = selectionStart;
|
|
46
42
|
var newPreviousSelection = previousSelection.slice();
|
|
47
|
-
|
|
48
43
|
if (_shiftHeld) {
|
|
49
44
|
if (checked.length > 0) {
|
|
50
45
|
var newIds = arrayFromRange(selectionStart, _id); // create an array of the new ids
|
|
46
|
+
|
|
51
47
|
// Uncheck ids from the previous selection.
|
|
52
48
|
// This is done to maintain consistency with Shift-select behaviour elsewhere (e.g. macOS)
|
|
53
49
|
// 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
50
|
updated = updated.filter(function (id) {
|
|
56
51
|
return !previousSelection.includes(id);
|
|
57
52
|
});
|
|
@@ -59,6 +54,7 @@ function reducer(_ref, action) {
|
|
|
59
54
|
return updated.indexOf(id) === -1 && updated.push(id);
|
|
60
55
|
} // If the new id is not already checked, check it
|
|
61
56
|
);
|
|
57
|
+
|
|
62
58
|
newPreviousSelection = newIds; // Maintain an array of the previous selection to allow for consistent Shift-select behaviour
|
|
63
59
|
}
|
|
64
60
|
} else {
|
|
@@ -71,12 +67,10 @@ function reducer(_ref, action) {
|
|
|
71
67
|
}
|
|
72
68
|
|
|
73
69
|
newSelectionStart = _id; // Reset selection start id to this non-shift-selected id
|
|
74
|
-
|
|
75
70
|
newPreviousSelection = []; // Reset previous selection as it is no longer relevant once a new non-shift-selected id is added
|
|
76
71
|
}
|
|
77
72
|
|
|
78
73
|
var _anyChecked = updated.length > 0;
|
|
79
|
-
|
|
80
74
|
return {
|
|
81
75
|
checked: updated,
|
|
82
76
|
allChecked: updated.length === maxChecked,
|
|
@@ -86,7 +80,6 @@ function reducer(_ref, action) {
|
|
|
86
80
|
previousSelection: newPreviousSelection
|
|
87
81
|
};
|
|
88
82
|
}
|
|
89
|
-
|
|
90
83
|
case 'set_root':
|
|
91
84
|
return {
|
|
92
85
|
checked: action.value ? Array.from(Array(maxChecked).keys()) : [],
|
|
@@ -96,7 +89,6 @@ function reducer(_ref, action) {
|
|
|
96
89
|
selectionStart: selectionStart,
|
|
97
90
|
previousSelection: previousSelection
|
|
98
91
|
};
|
|
99
|
-
|
|
100
92
|
case 'set_max':
|
|
101
93
|
{
|
|
102
94
|
var _max = action.value;
|
|
@@ -109,18 +101,15 @@ function reducer(_ref, action) {
|
|
|
109
101
|
previousSelection: previousSelection
|
|
110
102
|
};
|
|
111
103
|
}
|
|
112
|
-
|
|
113
104
|
default:
|
|
114
105
|
throw new Error();
|
|
115
106
|
}
|
|
116
107
|
}
|
|
117
|
-
|
|
118
108
|
function useSelectable() {
|
|
119
109
|
var _useReducer = useReducer(reducer, defaultSelectableState),
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
110
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
111
|
+
state = _useReducer2[0],
|
|
112
|
+
dispatch = _useReducer2[1];
|
|
124
113
|
var toggleSelection = useCallback(function (id, shiftHeld) {
|
|
125
114
|
dispatch({
|
|
126
115
|
type: 'toggle_selection',
|
|
@@ -155,5 +144,4 @@ function useSelectable() {
|
|
|
155
144
|
setMax: setMax
|
|
156
145
|
}];
|
|
157
146
|
}
|
|
158
|
-
|
|
159
147
|
export default useSelectable;
|
|
@@ -2,24 +2,20 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import { useCallback, useState } from 'react';
|
|
3
3
|
export var useSorting = function useSorting(sortKey) {
|
|
4
4
|
var _useState = useState(sortKey),
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
6
|
+
localSortKey = _useState2[0],
|
|
7
|
+
setLocalSortKey = _useState2[1];
|
|
9
8
|
var _useState3 = useState(),
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
10
|
+
localSortDirection = _useState4[0],
|
|
11
|
+
setLocalSortDirection = _useState4[1];
|
|
14
12
|
var toggleSortDirection = useCallback(function () {
|
|
15
13
|
setLocalSortDirection(function (oldLocalSortDirection) {
|
|
16
14
|
switch (oldLocalSortDirection) {
|
|
17
15
|
case undefined:
|
|
18
16
|
return 'ascending';
|
|
19
|
-
|
|
20
17
|
case 'ascending':
|
|
21
18
|
return 'descending';
|
|
22
|
-
|
|
23
19
|
case 'descending':
|
|
24
20
|
return 'ascending';
|
|
25
21
|
}
|
|
@@ -34,7 +30,6 @@ export var useSorting = function useSorting(sortKey) {
|
|
|
34
30
|
} else {
|
|
35
31
|
toggleSortDirection();
|
|
36
32
|
}
|
|
37
|
-
|
|
38
33
|
return localSortKey;
|
|
39
34
|
});
|
|
40
35
|
}, [toggleSortDirection]);
|
|
@@ -42,7 +37,6 @@ export var useSorting = function useSorting(sortKey) {
|
|
|
42
37
|
if (localSortKey === 'unset') {
|
|
43
38
|
return 0;
|
|
44
39
|
}
|
|
45
|
-
|
|
46
40
|
var ascendingComparator = rowA[localSortKey] < rowB[localSortKey] ? -1 : 1;
|
|
47
41
|
return localSortDirection === 'ascending' ? ascendingComparator : -ascendingComparator;
|
|
48
42
|
}, [localSortDirection, localSortKey]);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
2
|
import invariant from 'tiny-invariant';
|
|
3
3
|
var 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 var TableBodyProvider = TableBodyContext.Provider;
|
|
10
10
|
export var useTableBody = function useTableBody() {
|
|
11
11
|
var 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,
|
|
@@ -11,8 +10,8 @@ function generateContext() {
|
|
|
11
10
|
}
|
|
12
11
|
});
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
var TableContext = generateContext();
|
|
14
|
+
|
|
16
15
|
/**
|
|
17
16
|
* __Table state provider__
|
|
18
17
|
*
|
|
@@ -20,10 +19,9 @@ var TableContext = generateContext();
|
|
|
20
19
|
*
|
|
21
20
|
* - [Examples](https://atlassian.design/components/table/examples)
|
|
22
21
|
*/
|
|
23
|
-
|
|
24
22
|
export function TableProvider(_ref) {
|
|
25
23
|
var children = _ref.children,
|
|
26
|
-
|
|
24
|
+
state = _ref.state;
|
|
27
25
|
return (
|
|
28
26
|
/*#__PURE__*/
|
|
29
27
|
// @ts-expect-error
|
|
@@ -33,7 +31,8 @@ export function TableProvider(_ref) {
|
|
|
33
31
|
);
|
|
34
32
|
}
|
|
35
33
|
export var useTable = function useTable() {
|
|
36
|
-
return (
|
|
34
|
+
return (
|
|
35
|
+
// @ts-expect-error
|
|
37
36
|
useContext(TableContext)
|
|
38
37
|
);
|
|
39
38
|
};
|
package/dist/esm/row.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { memo, useMemo } from 'react';
|
|
5
4
|
import { jsx } from '@emotion/react';
|
|
@@ -9,7 +8,6 @@ import { useTable } from './hooks/use-table';
|
|
|
9
8
|
import { useTableBody } from './hooks/use-table-body';
|
|
10
9
|
import SelectableCell from './selectable-cell';
|
|
11
10
|
import * as Primitives from './ui';
|
|
12
|
-
|
|
13
11
|
/**
|
|
14
12
|
* __Row__
|
|
15
13
|
*
|
|
@@ -19,25 +17,22 @@ import * as Primitives from './ui';
|
|
|
19
17
|
*/
|
|
20
18
|
var Row = /*#__PURE__*/memo(function (_ref) {
|
|
21
19
|
var children = _ref.children,
|
|
22
|
-
|
|
20
|
+
testId = _ref.testId;
|
|
23
21
|
// To ensure valid nesting
|
|
24
|
-
useTableBody();
|
|
25
|
-
|
|
22
|
+
useTableBody();
|
|
23
|
+
// to access table state
|
|
26
24
|
var _useTable = useTable(),
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
isSelectable = _useTable.isSelectable;
|
|
29
26
|
var _useSelection = useSelection(),
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
_useSelection2 = _slicedToArray(_useSelection, 1),
|
|
28
|
+
_useSelection2$ = _useSelection2[0],
|
|
29
|
+
allChecked = _useSelection2$.allChecked,
|
|
30
|
+
checked = _useSelection2$.checked;
|
|
35
31
|
var rowId = useRowId();
|
|
36
32
|
var isSelected = useMemo(function () {
|
|
37
33
|
if (!isSelectable) {
|
|
38
34
|
return undefined;
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
return allChecked || checked.includes(rowId);
|
|
42
37
|
}, [allChecked, checked, isSelectable, rowId]);
|
|
43
38
|
return jsx(Primitives.TR, {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { memo, useCallback, useMemo } from 'react';
|
|
5
4
|
import { jsx } from '@emotion/react';
|
|
@@ -7,15 +6,13 @@ import Checkbox from '@atlaskit/checkbox';
|
|
|
7
6
|
import { useSelection } from './hooks/selection-provider';
|
|
8
7
|
import { useRowId } from './hooks/use-row-id';
|
|
9
8
|
import * as Primitives from './ui';
|
|
10
|
-
|
|
11
9
|
var SelectableCell = function SelectableCell() {
|
|
12
10
|
var _useSelection = useSelection(),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
_useSelection2 = _slicedToArray(_useSelection, 2),
|
|
12
|
+
_useSelection2$ = _useSelection2[0],
|
|
13
|
+
allChecked = _useSelection2$.allChecked,
|
|
14
|
+
checked = _useSelection2$.checked,
|
|
15
|
+
toggleSelection = _useSelection2[1].toggleSelection;
|
|
19
16
|
var idx = useRowId();
|
|
20
17
|
var isChecked = useMemo(function () {
|
|
21
18
|
return allChecked || checked.includes(idx);
|
|
@@ -30,5 +27,4 @@ var SelectableCell = function SelectableCell() {
|
|
|
30
27
|
onChange: onChange
|
|
31
28
|
}));
|
|
32
29
|
};
|
|
33
|
-
|
|
34
30
|
export default /*#__PURE__*/memo(SelectableCell);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["name", "testId", "onClick", "children"];
|
|
4
|
-
|
|
5
4
|
/* eslint-disable no-unused-vars */
|
|
6
|
-
|
|
7
5
|
/** @jsx jsx */
|
|
8
6
|
import { useCallback } from 'react';
|
|
9
7
|
import { css, jsx } from '@emotion/react';
|
|
@@ -11,7 +9,6 @@ import Button from '@atlaskit/button';
|
|
|
11
9
|
import Tooltip from '@atlaskit/tooltip';
|
|
12
10
|
import { useTable } from './hooks/use-table';
|
|
13
11
|
import { SortIcon, TH } from './ui';
|
|
14
|
-
|
|
15
12
|
/**
|
|
16
13
|
* TODO these need to be i18n supported
|
|
17
14
|
*/
|
|
@@ -36,38 +33,36 @@ var overrideStyles = css({
|
|
|
36
33
|
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage-spacing
|
|
37
34
|
paddingInline: "2px !important"
|
|
38
35
|
});
|
|
36
|
+
|
|
39
37
|
/**
|
|
40
38
|
* __SortableColumn__
|
|
41
39
|
*
|
|
42
40
|
* SortableColumn is used in place of the default Column when sorting is desired.
|
|
43
41
|
*/
|
|
44
|
-
|
|
45
42
|
var SortableColumn = function SortableColumn(_ref) {
|
|
46
43
|
var name = _ref.name,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
testId = _ref.testId,
|
|
45
|
+
onClick = _ref.onClick,
|
|
46
|
+
children = _ref.children,
|
|
47
|
+
other = _objectWithoutProperties(_ref, _excluded);
|
|
52
48
|
var _useTable = useTable(),
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
sortKey = _useTable.sortKey,
|
|
50
|
+
sortDirection = _useTable.sortDirection,
|
|
51
|
+
setSortState = _useTable.setSortState;
|
|
57
52
|
var getSortMessage = function getSortMessage() {
|
|
58
53
|
if (sortKey === name) {
|
|
59
54
|
// TODO: Change message depending on data type (string/number)
|
|
60
55
|
return sortingMessages[sortDirection || 'unsorted'].string;
|
|
61
56
|
}
|
|
62
|
-
|
|
63
57
|
return sortingMessages.unsorted.string;
|
|
64
58
|
};
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
var updateSortState = useCallback(
|
|
60
|
+
// @ts-expect-error: TODO: Our `name` typing is off; refer to `SortKey`
|
|
67
61
|
function () {
|
|
68
62
|
return setSortState(name);
|
|
69
63
|
}, [setSortState, name]);
|
|
70
|
-
return (
|
|
64
|
+
return (
|
|
65
|
+
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
71
66
|
jsx(TH, _extends({
|
|
72
67
|
testId: testId
|
|
73
68
|
}, other), jsx(Tooltip, {
|
|
@@ -87,5 +82,4 @@ var SortableColumn = function SortableColumn(_ref) {
|
|
|
87
82
|
}))
|
|
88
83
|
);
|
|
89
84
|
};
|
|
90
|
-
|
|
91
85
|
export default SortableColumn;
|
package/dist/esm/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
|
*
|
|
@@ -15,17 +14,15 @@ import * as Primitives from './ui';
|
|
|
15
14
|
*/
|
|
16
15
|
function Table(_ref) {
|
|
17
16
|
var children = _ref.children,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
isSelectable = _ref.isSelectable,
|
|
18
|
+
_ref$sortKey = _ref.sortKey,
|
|
19
|
+
sortKey = _ref$sortKey === void 0 ? 'unset' : _ref$sortKey,
|
|
20
|
+
testId = _ref.testId;
|
|
23
21
|
var _useSorting = useSorting(sortKey),
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
localSortKey = _useSorting.sortKey,
|
|
23
|
+
sortDirection = _useSorting.sortDirection,
|
|
24
|
+
setSortState = _useSorting.setSortState,
|
|
25
|
+
sortFn = _useSorting.sortFn;
|
|
29
26
|
var tableProviderState = useMemo(function () {
|
|
30
27
|
return {
|
|
31
28
|
isSelectable: isSelectable,
|
|
@@ -41,5 +38,4 @@ function Table(_ref) {
|
|
|
41
38
|
testId: testId
|
|
42
39
|
}, isSelectable ? jsx(SelectionProvider, null, children) : children));
|
|
43
40
|
}
|
|
44
|
-
|
|
45
41
|
export default Table;
|
package/dist/esm/thead.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
3
|
+
|
|
4
4
|
import { jsx } from '@emotion/react';
|
|
5
5
|
import Checkbox from '@atlaskit/checkbox';
|
|
6
6
|
import { UNSAFE_Inline as Inline, UNSAFE_Text as Text } from '@atlaskit/ds-explorations';
|
|
@@ -8,27 +8,22 @@ import VisuallyHidden from '@atlaskit/visually-hidden';
|
|
|
8
8
|
import { useSelection } from './hooks/selection-provider';
|
|
9
9
|
import { useTable } from './hooks/use-table';
|
|
10
10
|
import * as Primitives from './ui';
|
|
11
|
-
|
|
12
11
|
var THead = function THead(_ref) {
|
|
13
12
|
var actions = _ref.actions,
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
children = _ref.children;
|
|
16
14
|
var _useTable = useTable(),
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
isSelectable = _useTable.isSelectable;
|
|
19
16
|
var _useSelection = useSelection(),
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
_useSelection2 = _slicedToArray(_useSelection, 2),
|
|
18
|
+
state = _useSelection2[0],
|
|
19
|
+
_useSelection2$ = _useSelection2[1],
|
|
20
|
+
setAll = _useSelection2$.setAll,
|
|
21
|
+
removeAll = _useSelection2$.removeAll;
|
|
26
22
|
if (!isSelectable) {
|
|
27
23
|
return jsx(Primitives.THead, null, jsx(Primitives.TR, {
|
|
28
24
|
isBodyRow: false
|
|
29
25
|
}, children));
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
var isChecked = state.allChecked || state.anyChecked;
|
|
33
28
|
return jsx(Primitives.THead, null, jsx(Primitives.TR, {
|
|
34
29
|
isBodyRow: false
|
|
@@ -48,5 +43,4 @@ var THead = function THead(_ref) {
|
|
|
48
43
|
gap: "space.100"
|
|
49
44
|
}, actions(state.checked)))));
|
|
50
45
|
};
|
|
51
|
-
|
|
52
46
|
export default THead;
|