@atlaskit/table 0.2.1 → 0.2.3
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 +12 -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 +9 -21
- package/dist/cjs/sortable-column.js +33 -44
- package/dist/cjs/table.js +8 -22
- package/dist/cjs/thead.js +12 -29
- package/dist/cjs/ui/base-cell.js +17 -21
- 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 +8 -11
- 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 +3 -3
- package/dist/es2019/sortable-column.js +24 -26
- package/dist/es2019/table.js +0 -2
- package/dist/es2019/thead.js +5 -8
- package/dist/es2019/ui/base-cell.js +5 -4
- 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 +4 -3
- 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 +8 -10
- package/dist/esm/sortable-column.js +33 -36
- package/dist/esm/table.js +8 -12
- package/dist/esm/thead.js +12 -18
- package/dist/esm/ui/base-cell.js +16 -15
- 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 +8 -7
- package/dist/esm/ui/thead.js +2 -1
- package/dist/esm/ui/tr.js +6 -6
- package/dist/esm/version.json +1 -1
- package/dist/types/ui/base-cell.d.ts +7 -1
- package/dist/types/ui/th.d.ts +6 -2
- package/package.json +9 -6
- package/constellation/index/examples.mdx +0 -19
- package/constellation/index/props.mdx +0 -17
|
@@ -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,12 +8,12 @@ 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, {
|
|
@@ -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
|
});
|
package/dist/es2019/ui/table.js
CHANGED
package/dist/es2019/ui/tbody.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @repo/internal/react/no-clone-element */
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
3
|
+
|
|
4
4
|
import { css, jsx } from '@emotion/react';
|
|
5
5
|
const bodyStyles = css({
|
|
6
6
|
position: 'relative',
|
|
@@ -13,11 +13,11 @@ const bodyStyles = css({
|
|
|
13
13
|
pointerEvents: 'none'
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
+
|
|
16
17
|
/**
|
|
17
18
|
* __TBody__
|
|
18
19
|
* @primitive
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
21
|
export const TBody = ({
|
|
22
22
|
children
|
|
23
23
|
}) => jsx("tbody", {
|
package/dist/es2019/ui/td.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
3
|
+
|
|
4
4
|
import { jsx } from '@emotion/react';
|
|
5
5
|
import { BaseCell } from './base-cell';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* __Cell__
|
|
8
9
|
*
|
|
@@ -10,11 +11,11 @@ import { BaseCell } from './base-cell';
|
|
|
10
11
|
*
|
|
11
12
|
* @primitive
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
14
|
export const TD = ({
|
|
15
15
|
testId,
|
|
16
16
|
...props
|
|
17
|
-
}) =>
|
|
17
|
+
}) =>
|
|
18
|
+
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
18
19
|
jsx(BaseCell, _extends({
|
|
19
20
|
as: "td",
|
|
20
21
|
testId: testId
|
package/dist/es2019/ui/th.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { BaseCell } from './base-cell';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* __Head cell__
|
|
6
5
|
*
|
|
@@ -14,7 +13,8 @@ export const TH = ({
|
|
|
14
13
|
align,
|
|
15
14
|
scope,
|
|
16
15
|
backgroundColor,
|
|
17
|
-
width
|
|
16
|
+
width,
|
|
17
|
+
sortDirection
|
|
18
18
|
}) =>
|
|
19
19
|
/*#__PURE__*/
|
|
20
20
|
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
@@ -24,5 +24,6 @@ React.createElement(BaseCell, {
|
|
|
24
24
|
align: align,
|
|
25
25
|
scope: scope,
|
|
26
26
|
width: width,
|
|
27
|
-
backgroundColor: backgroundColor
|
|
27
|
+
backgroundColor: backgroundColor,
|
|
28
|
+
sortDirection: sortDirection
|
|
28
29
|
}, children);
|
package/dist/es2019/ui/thead.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
+
|
|
2
3
|
import { css, jsx } from '@emotion/react';
|
|
3
4
|
const baseStyles = css({
|
|
4
5
|
position: 'sticky',
|
|
@@ -9,6 +10,7 @@ const baseStyles = css({
|
|
|
9
10
|
borderTop: '2px solid transparent',
|
|
10
11
|
inset: 0
|
|
11
12
|
});
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* __THead__
|
|
14
16
|
*
|
|
@@ -16,7 +18,6 @@ const baseStyles = css({
|
|
|
16
18
|
*
|
|
17
19
|
* @primitive
|
|
18
20
|
*/
|
|
19
|
-
|
|
20
21
|
export const THead = ({
|
|
21
22
|
children
|
|
22
23
|
}) => {
|
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, {
|