@atlaskit/table 0.2.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/cjs/body.js +0 -2
- package/dist/cjs/expandable-cell.js +45 -0
- package/dist/cjs/expandable-row-content.js +21 -0
- package/dist/cjs/expandable-row.js +25 -0
- package/dist/cjs/head-cell.js +3 -3
- package/dist/cjs/hooks/selection-provider.js +0 -4
- package/dist/cjs/hooks/use-expand-content.js +33 -0
- package/dist/cjs/hooks/use-expand.js +50 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/row.js +19 -3
- package/dist/cjs/thead.js +2 -7
- package/dist/cjs/ui/base-cell.js +21 -14
- package/dist/cjs/ui/expand-icon.js +41 -0
- package/dist/cjs/ui/expandable-cell.js +28 -0
- package/dist/cjs/ui/index.js +14 -0
- package/dist/cjs/ui/selectable-cell.js +2 -9
- package/dist/cjs/ui/th.js +9 -13
- package/dist/cjs/ui/tr.js +6 -2
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/body.js +0 -2
- package/dist/es2019/expandable-cell.js +35 -0
- package/dist/es2019/expandable-row-content.js +14 -0
- package/dist/es2019/expandable-row.js +18 -0
- package/dist/es2019/head-cell.js +3 -3
- package/dist/es2019/hooks/selection-provider.js +0 -4
- package/dist/es2019/hooks/use-expand-content.js +23 -0
- package/dist/es2019/hooks/use-expand.js +32 -0
- package/dist/es2019/index.js +3 -0
- package/dist/es2019/row.js +21 -3
- package/dist/es2019/thead.js +2 -7
- package/dist/es2019/ui/base-cell.js +21 -14
- package/dist/es2019/ui/expand-icon.js +34 -0
- package/dist/es2019/ui/expandable-cell.js +22 -0
- package/dist/es2019/ui/index.js +2 -0
- package/dist/es2019/ui/selectable-cell.js +2 -8
- package/dist/es2019/ui/th.js +1 -4
- package/dist/es2019/ui/tr.js +6 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/body.js +0 -2
- package/dist/esm/expandable-cell.js +34 -0
- package/dist/esm/expandable-row-content.js +13 -0
- package/dist/esm/expandable-row.js +17 -0
- package/dist/esm/head-cell.js +3 -3
- package/dist/esm/hooks/selection-provider.js +0 -4
- package/dist/esm/hooks/use-expand-content.js +22 -0
- package/dist/esm/hooks/use-expand.js +38 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/row.js +19 -3
- package/dist/esm/thead.js +2 -7
- package/dist/esm/ui/base-cell.js +21 -14
- package/dist/esm/ui/expand-icon.js +33 -0
- package/dist/esm/ui/expandable-cell.js +21 -0
- package/dist/esm/ui/index.js +2 -0
- package/dist/esm/ui/selectable-cell.js +2 -9
- package/dist/esm/ui/th.js +9 -13
- package/dist/esm/ui/tr.js +6 -2
- package/dist/esm/version.json +1 -1
- package/dist/types/expandable-cell.d.ts +10 -0
- package/dist/types/expandable-row-content.d.ts +12 -0
- package/dist/types/expandable-row.d.ts +19 -0
- package/dist/types/head-cell.d.ts +3 -3
- package/dist/types/hooks/selection-provider.d.ts +0 -4
- package/dist/types/hooks/use-expand-content.d.ts +15 -0
- package/dist/types/hooks/use-expand.d.ts +17 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/ui/base-cell.d.ts +11 -3
- package/dist/types/ui/expand-icon.d.ts +10 -0
- package/dist/types/ui/expandable-cell.d.ts +14 -0
- package/dist/types/ui/index.d.ts +2 -0
- package/dist/types/ui/selectable-cell.d.ts +3 -2
- package/dist/types/ui/td.d.ts +1 -1
- package/dist/types/ui/thead.d.ts +1 -1
- package/dist/types/ui/tr.d.ts +5 -1
- package/package.json +2 -1
- package/report.api.md +36 -3
- package/tmp/api-report-tmp.d.ts +30 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ExpandContentContextProvider } from './hooks/use-expand-content';
|
|
3
|
+
/**
|
|
4
|
+
* __Expandable row content__
|
|
5
|
+
*
|
|
6
|
+
* Contains expandable content. Uses a context provider to allow children
|
|
7
|
+
* to identify if they are expandable content.
|
|
8
|
+
*/
|
|
9
|
+
const ExpandableRowContent = ({
|
|
10
|
+
children
|
|
11
|
+
}) => {
|
|
12
|
+
return /*#__PURE__*/React.createElement(ExpandContentContextProvider, null, children);
|
|
13
|
+
};
|
|
14
|
+
export default ExpandableRowContent;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ExpandContextProvider } from './hooks/use-expand';
|
|
3
|
+
/**
|
|
4
|
+
* __Expandable row__
|
|
5
|
+
*
|
|
6
|
+
* A context provider for `<Row>` to support expandable content.
|
|
7
|
+
*/
|
|
8
|
+
const ExpandableRow = ({
|
|
9
|
+
children,
|
|
10
|
+
isExpanded,
|
|
11
|
+
isDefaultExpanded
|
|
12
|
+
}) => {
|
|
13
|
+
return /*#__PURE__*/React.createElement(ExpandContextProvider, {
|
|
14
|
+
isExpanded: isExpanded,
|
|
15
|
+
isDefaultExpanded: isDefaultExpanded
|
|
16
|
+
}, children);
|
|
17
|
+
};
|
|
18
|
+
export default ExpandableRow;
|
package/dist/es2019/head-cell.js
CHANGED
|
@@ -10,7 +10,7 @@ import { TH } from './ui/th';
|
|
|
10
10
|
*
|
|
11
11
|
* HeadCell element
|
|
12
12
|
*/
|
|
13
|
-
const
|
|
13
|
+
const HeadCell = ({
|
|
14
14
|
children,
|
|
15
15
|
align,
|
|
16
16
|
testId,
|
|
@@ -22,9 +22,9 @@ const Column = ({
|
|
|
22
22
|
align: align,
|
|
23
23
|
testId: testId,
|
|
24
24
|
backgroundColor: backgroundColor
|
|
25
|
-
}, jsx(Text, {
|
|
25
|
+
}, children && jsx(Text, {
|
|
26
26
|
color: "color.text",
|
|
27
27
|
fontWeight: "medium"
|
|
28
28
|
}, children));
|
|
29
29
|
};
|
|
30
|
-
export default
|
|
30
|
+
export default HeadCell;
|
|
@@ -6,10 +6,6 @@ const SelectionContext = /*#__PURE__*/createContext([defaultSelectableState, {}]
|
|
|
6
6
|
* __Selection provider__
|
|
7
7
|
*
|
|
8
8
|
* A selection provider injects selection specific state into the table.
|
|
9
|
-
*
|
|
10
|
-
* - [Examples](https://atlassian.design/components/{packageName}/examples)
|
|
11
|
-
* - [Code](https://atlassian.design/components/{packageName}/code)
|
|
12
|
-
* - [Usage](https://atlassian.design/components/{packageName}/usage)
|
|
13
9
|
*/
|
|
14
10
|
const SelectionProvider = ({
|
|
15
11
|
children
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { createContext, useContext } from 'react';
|
|
2
|
+
const ExpandContentContext = /*#__PURE__*/createContext({
|
|
3
|
+
isExpandableContent: false
|
|
4
|
+
});
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* __Expand content provider__
|
|
8
|
+
*
|
|
9
|
+
* An expand content provider allows `<Row>` to determine if it is a subitem.
|
|
10
|
+
*/
|
|
11
|
+
export const ExpandContentContextProvider = ({
|
|
12
|
+
children
|
|
13
|
+
}) => {
|
|
14
|
+
return /*#__PURE__*/React.createElement(ExpandContentContext.Provider, {
|
|
15
|
+
value: {
|
|
16
|
+
isExpandableContent: true
|
|
17
|
+
}
|
|
18
|
+
}, children);
|
|
19
|
+
};
|
|
20
|
+
const useExpandContent = () => {
|
|
21
|
+
return useContext(ExpandContentContext);
|
|
22
|
+
};
|
|
23
|
+
export default useExpandContent;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { createContext, useCallback, useContext, useState } from 'react';
|
|
2
|
+
import __noop from '@atlaskit/ds-lib/noop';
|
|
3
|
+
const ExpandContext = /*#__PURE__*/createContext({
|
|
4
|
+
isExpanded: false,
|
|
5
|
+
toggleExpanded: __noop
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* __Expand context provider__
|
|
10
|
+
*
|
|
11
|
+
* An expand context provider.
|
|
12
|
+
*/
|
|
13
|
+
export const ExpandContextProvider = ({
|
|
14
|
+
children,
|
|
15
|
+
isExpanded: isExpandedProp,
|
|
16
|
+
isDefaultExpanded = false
|
|
17
|
+
}) => {
|
|
18
|
+
const [isExpanded, setIsExpanded] = useState(isDefaultExpanded);
|
|
19
|
+
const toggleExpanded = useCallback(() => {
|
|
20
|
+
setIsExpanded(v => !v);
|
|
21
|
+
}, []);
|
|
22
|
+
return /*#__PURE__*/React.createElement(ExpandContext.Provider, {
|
|
23
|
+
value: {
|
|
24
|
+
isExpanded: isExpandedProp || isExpanded,
|
|
25
|
+
toggleExpanded
|
|
26
|
+
}
|
|
27
|
+
}, children);
|
|
28
|
+
};
|
|
29
|
+
const useExpand = () => {
|
|
30
|
+
return useContext(ExpandContext);
|
|
31
|
+
};
|
|
32
|
+
export default useExpand;
|
package/dist/es2019/index.js
CHANGED
|
@@ -2,6 +2,9 @@ export { default } from './table';
|
|
|
2
2
|
export { default as TBody } from './body';
|
|
3
3
|
export { default as Row } from './row';
|
|
4
4
|
export { TD as Cell } from './ui';
|
|
5
|
+
export { default as ExpandableCell } from './expandable-cell';
|
|
6
|
+
export { default as ExpandableRow } from './expandable-row';
|
|
7
|
+
export { default as ExpandableRowContent } from './expandable-row-content';
|
|
5
8
|
export { default as HeadCell } from './head-cell';
|
|
6
9
|
export { default as SortableColumn } from './sortable-column';
|
|
7
10
|
export { default as THead } from './thead';
|
package/dist/es2019/row.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { memo, useMemo } from 'react';
|
|
3
3
|
import { jsx } from '@emotion/react';
|
|
4
4
|
import { useSelection } from './hooks/selection-provider';
|
|
5
|
+
import useExpand from './hooks/use-expand';
|
|
6
|
+
import useExpandContent from './hooks/use-expand-content';
|
|
5
7
|
import { useRowId } from './hooks/use-row-id';
|
|
6
8
|
import { useTable } from './hooks/use-table';
|
|
7
9
|
import { useTableBody } from './hooks/use-table-body';
|
|
@@ -28,16 +30,32 @@ const Row = /*#__PURE__*/memo(({
|
|
|
28
30
|
allChecked,
|
|
29
31
|
checked
|
|
30
32
|
}] = useSelection();
|
|
33
|
+
const {
|
|
34
|
+
isExpanded
|
|
35
|
+
} = useExpand();
|
|
36
|
+
const {
|
|
37
|
+
isExpandableContent
|
|
38
|
+
} = useExpandContent();
|
|
31
39
|
const rowId = useRowId();
|
|
32
40
|
const isSelected = useMemo(() => {
|
|
33
|
-
if (!isSelectable) {
|
|
41
|
+
if (!isSelectable || rowId === undefined) {
|
|
34
42
|
return undefined;
|
|
35
43
|
}
|
|
36
44
|
return allChecked || checked.includes(rowId);
|
|
37
45
|
}, [allChecked, checked, isSelectable, rowId]);
|
|
46
|
+
if (isExpanded === false && isExpandableContent) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
let selectableCell = isSelectable && jsx(SelectableCell, null);
|
|
50
|
+
if (isSelectable && isExpandableContent) {
|
|
51
|
+
selectableCell = jsx(Primitives.SelectableCell, {
|
|
52
|
+
as: "td"
|
|
53
|
+
});
|
|
54
|
+
}
|
|
38
55
|
return jsx(Primitives.TR, {
|
|
39
56
|
isSelected: isSelected,
|
|
40
|
-
testId: testId
|
|
41
|
-
|
|
57
|
+
testId: testId,
|
|
58
|
+
isSubitem: isExpandableContent
|
|
59
|
+
}, selectableCell, children);
|
|
42
60
|
});
|
|
43
61
|
export default Row;
|
package/dist/es2019/thead.js
CHANGED
|
@@ -19,15 +19,10 @@ const THead = ({
|
|
|
19
19
|
setAll,
|
|
20
20
|
removeAll
|
|
21
21
|
}] = useSelection();
|
|
22
|
-
if (!isSelectable) {
|
|
23
|
-
return jsx(Primitives.THead, null, jsx(Primitives.TR, {
|
|
24
|
-
isBodyRow: false
|
|
25
|
-
}, children));
|
|
26
|
-
}
|
|
27
22
|
const isChecked = state.allChecked || state.anyChecked;
|
|
28
23
|
return jsx(Primitives.THead, null, jsx(Primitives.TR, {
|
|
29
24
|
isBodyRow: false
|
|
30
|
-
}, jsx(Primitives.SelectableCell, {
|
|
25
|
+
}, isSelectable && jsx(Primitives.SelectableCell, {
|
|
31
26
|
as: "th"
|
|
32
27
|
}, jsx(Checkbox, {
|
|
33
28
|
label: jsx(VisuallyHidden, {
|
|
@@ -36,7 +31,7 @@ const THead = ({
|
|
|
36
31
|
onChange: isChecked ? removeAll : setAll,
|
|
37
32
|
isChecked: isChecked,
|
|
38
33
|
isIndeterminate: state.anyChecked && !state.allChecked
|
|
39
|
-
})), children, isChecked && jsx(Primitives.BulkActionOverlay, null, jsx(Text, {
|
|
34
|
+
})), children, isSelectable && isChecked && jsx(Primitives.BulkActionOverlay, null, jsx(Text, {
|
|
40
35
|
color: "color.text",
|
|
41
36
|
fontWeight: "medium"
|
|
42
37
|
}, state.checked.length, " selected"), actions && jsx(Inline, {
|
|
@@ -3,12 +3,6 @@
|
|
|
3
3
|
import { forwardRef } from 'react';
|
|
4
4
|
import { css, jsx } from '@emotion/react';
|
|
5
5
|
import Box from '@atlaskit/ds-explorations/box';
|
|
6
|
-
import Inline from '@atlaskit/primitives/inline';
|
|
7
|
-
const alignMap = {
|
|
8
|
-
text: 'start',
|
|
9
|
-
number: 'end',
|
|
10
|
-
icon: 'center'
|
|
11
|
-
};
|
|
12
6
|
const baseResetStyles = css({
|
|
13
7
|
display: 'table-cell',
|
|
14
8
|
verticalAlign: 'middle',
|
|
@@ -19,6 +13,20 @@ const baseResetStyles = css({
|
|
|
19
13
|
paddingRight: "var(--ds-space-100, 8px)"
|
|
20
14
|
}
|
|
21
15
|
});
|
|
16
|
+
const alignLeftStyles = css({
|
|
17
|
+
textAlign: 'left'
|
|
18
|
+
});
|
|
19
|
+
const alignCenterStyles = css({
|
|
20
|
+
textAlign: 'center'
|
|
21
|
+
});
|
|
22
|
+
const alignRightStyles = css({
|
|
23
|
+
textAlign: 'right'
|
|
24
|
+
});
|
|
25
|
+
const alignMap = {
|
|
26
|
+
text: alignLeftStyles,
|
|
27
|
+
number: alignRightStyles,
|
|
28
|
+
icon: alignCenterStyles
|
|
29
|
+
};
|
|
22
30
|
|
|
23
31
|
/**
|
|
24
32
|
* __BaseCell__
|
|
@@ -33,14 +41,15 @@ export const BaseCell = /*#__PURE__*/forwardRef(({
|
|
|
33
41
|
children,
|
|
34
42
|
align = 'text',
|
|
35
43
|
paddingBlock = 'space.100',
|
|
36
|
-
paddingInline = 'space.
|
|
44
|
+
paddingInline = 'space.100',
|
|
37
45
|
backgroundColor,
|
|
38
46
|
scope,
|
|
39
47
|
width,
|
|
40
48
|
className,
|
|
41
|
-
sortDirection
|
|
49
|
+
sortDirection,
|
|
50
|
+
colSpan
|
|
42
51
|
}, ref) => jsx(Box, {
|
|
43
|
-
css: baseResetStyles,
|
|
52
|
+
css: [baseResetStyles, alignMap[align]],
|
|
44
53
|
ref: ref,
|
|
45
54
|
scope: scope,
|
|
46
55
|
backgroundColor: backgroundColor,
|
|
@@ -52,8 +61,6 @@ export const BaseCell = /*#__PURE__*/forwardRef(({
|
|
|
52
61
|
UNSAFE_style: width ? {
|
|
53
62
|
width
|
|
54
63
|
} : undefined,
|
|
55
|
-
"aria-sort": sortDirection
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
space: "0"
|
|
59
|
-
}, children)));
|
|
64
|
+
"aria-sort": sortDirection,
|
|
65
|
+
colSpan: colSpan
|
|
66
|
+
}, children));
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
/** @jsx jsx */
|
|
3
|
+
import { memo } from 'react';
|
|
4
|
+
import { jsx } from '@emotion/react';
|
|
5
|
+
|
|
6
|
+
// TODO: Using HipChat icons as the standard icon set is missing large
|
|
7
|
+
// versions of `chevron-up` and `chevron-down`, despite already including
|
|
8
|
+
// `chevron-left-large` and `chevron-right-large`...
|
|
9
|
+
import ChevronDownIcon from '@atlaskit/icon/glyph/hipchat/chevron-down';
|
|
10
|
+
import ChevronUpIcon from '@atlaskit/icon/glyph/hipchat/chevron-up';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* __Expand icon__
|
|
14
|
+
*
|
|
15
|
+
* An icon used to display the expanded state in an `<ExpandableCell>`.
|
|
16
|
+
*/
|
|
17
|
+
export const ExpandIcon = /*#__PURE__*/memo(({
|
|
18
|
+
isExpanded
|
|
19
|
+
}) => {
|
|
20
|
+
switch (isExpanded) {
|
|
21
|
+
case true:
|
|
22
|
+
return jsx(ChevronUpIcon, {
|
|
23
|
+
size: "small",
|
|
24
|
+
label: "",
|
|
25
|
+
primaryColor: "inherit"
|
|
26
|
+
});
|
|
27
|
+
case false:
|
|
28
|
+
return jsx(ChevronDownIcon, {
|
|
29
|
+
size: "small",
|
|
30
|
+
label: "",
|
|
31
|
+
primaryColor: "inherit"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
|
|
3
|
+
import { css, jsx } from '@emotion/react';
|
|
4
|
+
import { BaseCell } from './base-cell';
|
|
5
|
+
const spacingStyles = css({
|
|
6
|
+
width: 24,
|
|
7
|
+
padding: "var(--ds-space-0, 0px)"
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* __Expandable cell__
|
|
11
|
+
*
|
|
12
|
+
* An expandable cell primitive designed to be used for light weight composition.
|
|
13
|
+
*/
|
|
14
|
+
export const ExpandableCell = ({
|
|
15
|
+
children,
|
|
16
|
+
as
|
|
17
|
+
}) => {
|
|
18
|
+
return jsx(BaseCell, {
|
|
19
|
+
as: as,
|
|
20
|
+
css: spacingStyles
|
|
21
|
+
}, children);
|
|
22
|
+
};
|
package/dist/es2019/ui/index.js
CHANGED
|
@@ -7,6 +7,8 @@ export { TR } from './tr';
|
|
|
7
7
|
export { TD } from './td';
|
|
8
8
|
export { TH } from './th';
|
|
9
9
|
export { SelectableCell } from './selectable-cell';
|
|
10
|
+
export { ExpandableCell } from './expandable-cell';
|
|
11
|
+
export { ExpandIcon } from './expand-icon';
|
|
10
12
|
export { THead } from './thead';
|
|
11
13
|
export { BulkActionOverlay } from './bulk-action-overlay';
|
|
12
14
|
export { SortIcon } from './sort-icon';
|
|
@@ -4,13 +4,7 @@ import { css, jsx } from '@emotion/react';
|
|
|
4
4
|
import { BaseCell } from './base-cell';
|
|
5
5
|
const spacingStyles = css({
|
|
6
6
|
width: 32,
|
|
7
|
-
padding: "var(--ds-space-0, 0px)"
|
|
8
|
-
paddingLeft: "var(--ds-space-100, 8px)",
|
|
9
|
-
// eslint-disable-next-line @repo/internal/styles/no-nested-styles
|
|
10
|
-
'& + *': {
|
|
11
|
-
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage-spacing
|
|
12
|
-
paddingLeft: '8px !important'
|
|
13
|
-
}
|
|
7
|
+
padding: "var(--ds-space-0, 0px)"
|
|
14
8
|
});
|
|
15
9
|
/**
|
|
16
10
|
* __Selectable cell__
|
|
@@ -19,7 +13,7 @@ const spacingStyles = css({
|
|
|
19
13
|
*/
|
|
20
14
|
export const SelectableCell = ({
|
|
21
15
|
children,
|
|
22
|
-
as
|
|
16
|
+
as
|
|
23
17
|
}) => {
|
|
24
18
|
return jsx(BaseCell, {
|
|
25
19
|
as: as,
|
package/dist/es2019/ui/th.js
CHANGED
|
@@ -15,10 +15,7 @@ export const TH = ({
|
|
|
15
15
|
backgroundColor,
|
|
16
16
|
width,
|
|
17
17
|
sortDirection
|
|
18
|
-
}) =>
|
|
19
|
-
/*#__PURE__*/
|
|
20
|
-
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
21
|
-
React.createElement(BaseCell, {
|
|
18
|
+
}) => /*#__PURE__*/React.createElement(BaseCell, {
|
|
22
19
|
as: "th",
|
|
23
20
|
testId: testId,
|
|
24
21
|
align: align,
|
package/dist/es2019/ui/tr.js
CHANGED
|
@@ -16,6 +16,9 @@ const selectedStyles = css({
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
+
const subitemStyles = css({
|
|
20
|
+
backgroundColor: "var(--ds-background-neutral, #091E420F)"
|
|
21
|
+
});
|
|
19
22
|
const bodyRowStyles = css({
|
|
20
23
|
borderBottom: `1px solid ${"var(--ds-border, #eee)"}`,
|
|
21
24
|
'&:hover': {
|
|
@@ -36,7 +39,8 @@ export const TR = ({
|
|
|
36
39
|
children,
|
|
37
40
|
testId,
|
|
38
41
|
isSelected,
|
|
39
|
-
isBodyRow = true
|
|
42
|
+
isBodyRow = true,
|
|
43
|
+
isSubitem
|
|
40
44
|
}) => {
|
|
41
45
|
return jsx(FocusRing, {
|
|
42
46
|
isInset: true
|
|
@@ -44,6 +48,6 @@ export const TR = ({
|
|
|
44
48
|
tabIndex: -1,
|
|
45
49
|
"aria-selected": isSelected,
|
|
46
50
|
"data-testid": testId,
|
|
47
|
-
css: [baseStyles, isBodyRow && bodyRowStyles, isSelected && selectedStyles]
|
|
51
|
+
css: [baseStyles, isBodyRow && bodyRowStyles, isSelected && selectedStyles, isSubitem && subitemStyles]
|
|
48
52
|
}, children));
|
|
49
53
|
};
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/body.js
CHANGED
|
@@ -27,11 +27,9 @@ function TBody(_ref) {
|
|
|
27
27
|
_useSelection2$ = _useSelection2[1],
|
|
28
28
|
removeAll = _useSelection2$.removeAll,
|
|
29
29
|
setMax = _useSelection2$.setMax;
|
|
30
|
-
|
|
31
30
|
// TODO: this seems like something the user should control or opt into.
|
|
32
31
|
useEffect(function () {
|
|
33
32
|
removeAll === null || removeAll === void 0 ? void 0 : removeAll();
|
|
34
|
-
|
|
35
33
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- When the rows change, we [currently] want to call removeAll.
|
|
36
34
|
}, [rows]);
|
|
37
35
|
var childrenCount = Children.count(children);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { memo, useCallback } from 'react';
|
|
3
|
+
import { jsx } from '@emotion/react';
|
|
4
|
+
import Button from '@atlaskit/button';
|
|
5
|
+
import useExpand from './hooks/use-expand';
|
|
6
|
+
import * as Primitives from './ui';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* __Expandable cell__
|
|
10
|
+
*
|
|
11
|
+
* A cell with an expand button that controls the expanded state
|
|
12
|
+
* of the `<ExpandableRow>`.
|
|
13
|
+
*/
|
|
14
|
+
var ExpandableCell = /*#__PURE__*/memo(function () {
|
|
15
|
+
var _useExpand = useExpand(),
|
|
16
|
+
isExpanded = _useExpand.isExpanded,
|
|
17
|
+
toggleExpanded = _useExpand.toggleExpanded;
|
|
18
|
+
var handleClick = useCallback(function () {
|
|
19
|
+
toggleExpanded();
|
|
20
|
+
}, [toggleExpanded]);
|
|
21
|
+
return jsx(Primitives.ExpandableCell, {
|
|
22
|
+
as: "td"
|
|
23
|
+
}, jsx(Button, {
|
|
24
|
+
spacing: "compact",
|
|
25
|
+
appearance: "subtle",
|
|
26
|
+
iconAfter: jsx(Primitives.ExpandIcon, {
|
|
27
|
+
isExpanded: isExpanded
|
|
28
|
+
}),
|
|
29
|
+
onClick: handleClick,
|
|
30
|
+
"aria-pressed": isExpanded,
|
|
31
|
+
"aria-label": "Expand row"
|
|
32
|
+
}));
|
|
33
|
+
});
|
|
34
|
+
export default ExpandableCell;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ExpandContentContextProvider } from './hooks/use-expand-content';
|
|
3
|
+
/**
|
|
4
|
+
* __Expandable row content__
|
|
5
|
+
*
|
|
6
|
+
* Contains expandable content. Uses a context provider to allow children
|
|
7
|
+
* to identify if they are expandable content.
|
|
8
|
+
*/
|
|
9
|
+
var ExpandableRowContent = function ExpandableRowContent(_ref) {
|
|
10
|
+
var children = _ref.children;
|
|
11
|
+
return /*#__PURE__*/React.createElement(ExpandContentContextProvider, null, children);
|
|
12
|
+
};
|
|
13
|
+
export default ExpandableRowContent;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ExpandContextProvider } from './hooks/use-expand';
|
|
3
|
+
/**
|
|
4
|
+
* __Expandable row__
|
|
5
|
+
*
|
|
6
|
+
* A context provider for `<Row>` to support expandable content.
|
|
7
|
+
*/
|
|
8
|
+
var ExpandableRow = function ExpandableRow(_ref) {
|
|
9
|
+
var children = _ref.children,
|
|
10
|
+
isExpanded = _ref.isExpanded,
|
|
11
|
+
isDefaultExpanded = _ref.isDefaultExpanded;
|
|
12
|
+
return /*#__PURE__*/React.createElement(ExpandContextProvider, {
|
|
13
|
+
isExpanded: isExpanded,
|
|
14
|
+
isDefaultExpanded: isDefaultExpanded
|
|
15
|
+
}, children);
|
|
16
|
+
};
|
|
17
|
+
export default ExpandableRow;
|
package/dist/esm/head-cell.js
CHANGED
|
@@ -10,7 +10,7 @@ import { TH } from './ui/th';
|
|
|
10
10
|
*
|
|
11
11
|
* HeadCell element
|
|
12
12
|
*/
|
|
13
|
-
var
|
|
13
|
+
var HeadCell = function HeadCell(_ref) {
|
|
14
14
|
var children = _ref.children,
|
|
15
15
|
align = _ref.align,
|
|
16
16
|
testId = _ref.testId,
|
|
@@ -22,9 +22,9 @@ var Column = function Column(_ref) {
|
|
|
22
22
|
align: align,
|
|
23
23
|
testId: testId,
|
|
24
24
|
backgroundColor: backgroundColor
|
|
25
|
-
}, jsx(Text, {
|
|
25
|
+
}, children && jsx(Text, {
|
|
26
26
|
color: "color.text",
|
|
27
27
|
fontWeight: "medium"
|
|
28
28
|
}, children));
|
|
29
29
|
};
|
|
30
|
-
export default
|
|
30
|
+
export default HeadCell;
|
|
@@ -6,10 +6,6 @@ var SelectionContext = /*#__PURE__*/createContext([defaultSelectableState, {}]);
|
|
|
6
6
|
* __Selection provider__
|
|
7
7
|
*
|
|
8
8
|
* A selection provider injects selection specific state into the table.
|
|
9
|
-
*
|
|
10
|
-
* - [Examples](https://atlassian.design/components/{packageName}/examples)
|
|
11
|
-
* - [Code](https://atlassian.design/components/{packageName}/code)
|
|
12
|
-
* - [Usage](https://atlassian.design/components/{packageName}/usage)
|
|
13
9
|
*/
|
|
14
10
|
var SelectionProvider = function SelectionProvider(_ref) {
|
|
15
11
|
var children = _ref.children;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { createContext, useContext } from 'react';
|
|
2
|
+
var ExpandContentContext = /*#__PURE__*/createContext({
|
|
3
|
+
isExpandableContent: false
|
|
4
|
+
});
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* __Expand content provider__
|
|
8
|
+
*
|
|
9
|
+
* An expand content provider allows `<Row>` to determine if it is a subitem.
|
|
10
|
+
*/
|
|
11
|
+
export var ExpandContentContextProvider = function ExpandContentContextProvider(_ref) {
|
|
12
|
+
var children = _ref.children;
|
|
13
|
+
return /*#__PURE__*/React.createElement(ExpandContentContext.Provider, {
|
|
14
|
+
value: {
|
|
15
|
+
isExpandableContent: true
|
|
16
|
+
}
|
|
17
|
+
}, children);
|
|
18
|
+
};
|
|
19
|
+
var useExpandContent = function useExpandContent() {
|
|
20
|
+
return useContext(ExpandContentContext);
|
|
21
|
+
};
|
|
22
|
+
export default useExpandContent;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { createContext, useCallback, useContext, useState } from 'react';
|
|
3
|
+
import __noop from '@atlaskit/ds-lib/noop';
|
|
4
|
+
var ExpandContext = /*#__PURE__*/createContext({
|
|
5
|
+
isExpanded: false,
|
|
6
|
+
toggleExpanded: __noop
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* __Expand context provider__
|
|
11
|
+
*
|
|
12
|
+
* An expand context provider.
|
|
13
|
+
*/
|
|
14
|
+
export var ExpandContextProvider = function ExpandContextProvider(_ref) {
|
|
15
|
+
var children = _ref.children,
|
|
16
|
+
isExpandedProp = _ref.isExpanded,
|
|
17
|
+
_ref$isDefaultExpande = _ref.isDefaultExpanded,
|
|
18
|
+
isDefaultExpanded = _ref$isDefaultExpande === void 0 ? false : _ref$isDefaultExpande;
|
|
19
|
+
var _useState = useState(isDefaultExpanded),
|
|
20
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
21
|
+
isExpanded = _useState2[0],
|
|
22
|
+
setIsExpanded = _useState2[1];
|
|
23
|
+
var toggleExpanded = useCallback(function () {
|
|
24
|
+
setIsExpanded(function (v) {
|
|
25
|
+
return !v;
|
|
26
|
+
});
|
|
27
|
+
}, []);
|
|
28
|
+
return /*#__PURE__*/React.createElement(ExpandContext.Provider, {
|
|
29
|
+
value: {
|
|
30
|
+
isExpanded: isExpandedProp || isExpanded,
|
|
31
|
+
toggleExpanded: toggleExpanded
|
|
32
|
+
}
|
|
33
|
+
}, children);
|
|
34
|
+
};
|
|
35
|
+
var useExpand = function useExpand() {
|
|
36
|
+
return useContext(ExpandContext);
|
|
37
|
+
};
|
|
38
|
+
export default useExpand;
|
package/dist/esm/index.js
CHANGED
|
@@ -2,6 +2,9 @@ export { default } from './table';
|
|
|
2
2
|
export { default as TBody } from './body';
|
|
3
3
|
export { default as Row } from './row';
|
|
4
4
|
export { TD as Cell } from './ui';
|
|
5
|
+
export { default as ExpandableCell } from './expandable-cell';
|
|
6
|
+
export { default as ExpandableRow } from './expandable-row';
|
|
7
|
+
export { default as ExpandableRowContent } from './expandable-row-content';
|
|
5
8
|
export { default as HeadCell } from './head-cell';
|
|
6
9
|
export { default as SortableColumn } from './sortable-column';
|
|
7
10
|
export { default as THead } from './thead';
|
package/dist/esm/row.js
CHANGED
|
@@ -3,6 +3,8 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
3
3
|
import { memo, useMemo } from 'react';
|
|
4
4
|
import { jsx } from '@emotion/react';
|
|
5
5
|
import { useSelection } from './hooks/selection-provider';
|
|
6
|
+
import useExpand from './hooks/use-expand';
|
|
7
|
+
import useExpandContent from './hooks/use-expand-content';
|
|
6
8
|
import { useRowId } from './hooks/use-row-id';
|
|
7
9
|
import { useTable } from './hooks/use-table';
|
|
8
10
|
import { useTableBody } from './hooks/use-table-body';
|
|
@@ -28,16 +30,30 @@ var Row = /*#__PURE__*/memo(function (_ref) {
|
|
|
28
30
|
_useSelection2$ = _useSelection2[0],
|
|
29
31
|
allChecked = _useSelection2$.allChecked,
|
|
30
32
|
checked = _useSelection2$.checked;
|
|
33
|
+
var _useExpand = useExpand(),
|
|
34
|
+
isExpanded = _useExpand.isExpanded;
|
|
35
|
+
var _useExpandContent = useExpandContent(),
|
|
36
|
+
isExpandableContent = _useExpandContent.isExpandableContent;
|
|
31
37
|
var rowId = useRowId();
|
|
32
38
|
var isSelected = useMemo(function () {
|
|
33
|
-
if (!isSelectable) {
|
|
39
|
+
if (!isSelectable || rowId === undefined) {
|
|
34
40
|
return undefined;
|
|
35
41
|
}
|
|
36
42
|
return allChecked || checked.includes(rowId);
|
|
37
43
|
}, [allChecked, checked, isSelectable, rowId]);
|
|
44
|
+
if (isExpanded === false && isExpandableContent) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
var selectableCell = isSelectable && jsx(SelectableCell, null);
|
|
48
|
+
if (isSelectable && isExpandableContent) {
|
|
49
|
+
selectableCell = jsx(Primitives.SelectableCell, {
|
|
50
|
+
as: "td"
|
|
51
|
+
});
|
|
52
|
+
}
|
|
38
53
|
return jsx(Primitives.TR, {
|
|
39
54
|
isSelected: isSelected,
|
|
40
|
-
testId: testId
|
|
41
|
-
|
|
55
|
+
testId: testId,
|
|
56
|
+
isSubitem: isExpandableContent
|
|
57
|
+
}, selectableCell, children);
|
|
42
58
|
});
|
|
43
59
|
export default Row;
|
package/dist/esm/thead.js
CHANGED
|
@@ -20,15 +20,10 @@ var THead = function THead(_ref) {
|
|
|
20
20
|
_useSelection2$ = _useSelection2[1],
|
|
21
21
|
setAll = _useSelection2$.setAll,
|
|
22
22
|
removeAll = _useSelection2$.removeAll;
|
|
23
|
-
if (!isSelectable) {
|
|
24
|
-
return jsx(Primitives.THead, null, jsx(Primitives.TR, {
|
|
25
|
-
isBodyRow: false
|
|
26
|
-
}, children));
|
|
27
|
-
}
|
|
28
23
|
var isChecked = state.allChecked || state.anyChecked;
|
|
29
24
|
return jsx(Primitives.THead, null, jsx(Primitives.TR, {
|
|
30
25
|
isBodyRow: false
|
|
31
|
-
}, jsx(Primitives.SelectableCell, {
|
|
26
|
+
}, isSelectable && jsx(Primitives.SelectableCell, {
|
|
32
27
|
as: "th"
|
|
33
28
|
}, jsx(Checkbox, {
|
|
34
29
|
label: jsx(VisuallyHidden, {
|
|
@@ -37,7 +32,7 @@ var THead = function THead(_ref) {
|
|
|
37
32
|
onChange: isChecked ? removeAll : setAll,
|
|
38
33
|
isChecked: isChecked,
|
|
39
34
|
isIndeterminate: state.anyChecked && !state.allChecked
|
|
40
|
-
})), children, isChecked && jsx(Primitives.BulkActionOverlay, null, jsx(Text, {
|
|
35
|
+
})), children, isSelectable && isChecked && jsx(Primitives.BulkActionOverlay, null, jsx(Text, {
|
|
41
36
|
color: "color.text",
|
|
42
37
|
fontWeight: "medium"
|
|
43
38
|
}, state.checked.length, " selected"), actions && jsx(Inline, {
|