@instructure/ui-table 10.2.1-snapshot-3 → 10.2.1-snapshot-12
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 +1 -1
- package/es/Table/Body/index.js +24 -11
- package/es/Table/Body/props.js +2 -5
- package/es/Table/Body/styles.js +0 -2
- package/es/Table/Cell/index.js +3 -2
- package/es/Table/Cell/props.js +1 -2
- package/es/Table/ColHeader/styles.js +0 -1
- package/es/Table/Head/index.js +40 -30
- package/es/Table/Head/props.js +1 -3
- package/es/Table/Head/styles.js +0 -2
- package/es/Table/Row/index.js +25 -12
- package/es/Table/Row/props.js +2 -5
- package/es/Table/Row/styles.js +4 -6
- package/es/Table/RowHeader/index.js +3 -2
- package/es/Table/RowHeader/props.js +1 -2
- package/es/Table/TableContext.js +34 -0
- package/es/Table/__new-tests__/Table.test.js +74 -1
- package/es/Table/index.js +25 -17
- package/es/index.js +2 -1
- package/lib/Table/Body/index.js +23 -10
- package/lib/Table/Body/props.js +2 -5
- package/lib/Table/Body/styles.js +0 -2
- package/lib/Table/Cell/index.js +3 -2
- package/lib/Table/Cell/props.js +1 -2
- package/lib/Table/ColHeader/styles.js +0 -1
- package/lib/Table/Head/index.js +39 -30
- package/lib/Table/Head/props.js +1 -3
- package/lib/Table/Head/styles.js +0 -2
- package/lib/Table/Row/index.js +24 -11
- package/lib/Table/Row/props.js +2 -5
- package/lib/Table/Row/styles.js +4 -6
- package/lib/Table/RowHeader/index.js +3 -2
- package/lib/Table/RowHeader/props.js +1 -2
- package/lib/Table/TableContext.js +39 -0
- package/lib/Table/__new-tests__/Table.test.js +74 -1
- package/lib/Table/index.js +24 -16
- package/lib/index.js +8 -1
- package/package.json +17 -17
- package/src/Table/Body/index.tsx +23 -13
- package/src/Table/Body/props.ts +6 -18
- package/src/Table/Body/styles.ts +0 -2
- package/src/Table/Cell/index.tsx +6 -3
- package/src/Table/Cell/props.ts +7 -9
- package/src/Table/ColHeader/props.ts +7 -4
- package/src/Table/ColHeader/styles.ts +0 -1
- package/src/Table/Head/index.tsx +40 -40
- package/src/Table/Head/props.ts +20 -13
- package/src/Table/Head/styles.ts +0 -2
- package/src/Table/README.md +299 -2
- package/src/Table/Row/index.tsx +27 -11
- package/src/Table/Row/props.ts +7 -19
- package/src/Table/Row/styles.ts +5 -6
- package/src/Table/RowHeader/index.tsx +6 -4
- package/src/Table/RowHeader/props.ts +1 -3
- package/src/Table/TableContext.ts +54 -0
- package/src/Table/__new-tests__/Table.test.tsx +131 -2
- package/src/Table/index.tsx +42 -44
- package/src/Table/props.ts +8 -28
- package/src/index.ts +1 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Table/Body/index.d.ts +6 -13
- package/types/Table/Body/index.d.ts.map +1 -1
- package/types/Table/Body/props.d.ts +4 -5
- package/types/Table/Body/props.d.ts.map +1 -1
- package/types/Table/Body/styles.d.ts +0 -2
- package/types/Table/Body/styles.d.ts.map +1 -1
- package/types/Table/Cell/index.d.ts +4 -3
- package/types/Table/Cell/index.d.ts.map +1 -1
- package/types/Table/Cell/props.d.ts +6 -2
- package/types/Table/Cell/props.d.ts.map +1 -1
- package/types/Table/ColHeader/props.d.ts +6 -3
- package/types/Table/ColHeader/props.d.ts.map +1 -1
- package/types/Table/ColHeader/styles.d.ts +0 -1
- package/types/Table/ColHeader/styles.d.ts.map +1 -1
- package/types/Table/Head/index.d.ts +15 -7
- package/types/Table/Head/index.d.ts.map +1 -1
- package/types/Table/Head/props.d.ts +19 -5
- package/types/Table/Head/props.d.ts.map +1 -1
- package/types/Table/Head/styles.d.ts +0 -2
- package/types/Table/Head/styles.d.ts.map +1 -1
- package/types/Table/Row/index.d.ts +6 -13
- package/types/Table/Row/index.d.ts.map +1 -1
- package/types/Table/Row/props.d.ts +5 -6
- package/types/Table/Row/props.d.ts.map +1 -1
- package/types/Table/Row/styles.d.ts +5 -2
- package/types/Table/Row/styles.d.ts.map +1 -1
- package/types/Table/RowHeader/index.d.ts +4 -3
- package/types/Table/RowHeader/index.d.ts.map +1 -1
- package/types/Table/RowHeader/props.d.ts +0 -1
- package/types/Table/RowHeader/props.d.ts.map +1 -1
- package/types/Table/TableContext.d.ts +24 -0
- package/types/Table/TableContext.d.ts.map +1 -0
- package/types/Table/index.d.ts +1 -1
- package/types/Table/index.d.ts.map +1 -1
- package/types/Table/props.d.ts +10 -22
- package/types/Table/props.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
package/lib/Table/index.js
CHANGED
@@ -21,6 +21,7 @@ var _ColHeader = require("./ColHeader");
|
|
21
21
|
var _RowHeader = require("./RowHeader");
|
22
22
|
var _Cell = require("./Cell");
|
23
23
|
var _props = require("./props");
|
24
|
+
var _TableContext = _interopRequireDefault(require("./TableContext"));
|
24
25
|
var _dec, _class, _Table;
|
25
26
|
/*
|
26
27
|
* The MIT License (MIT)
|
@@ -72,15 +73,16 @@ let Table = exports.Table = (_dec = (0, _emotion.withStyle)(_styles.default, _th
|
|
72
73
|
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
73
74
|
}
|
74
75
|
getHeaders() {
|
75
|
-
const
|
76
|
-
const _ref = _react.Children.toArray(children),
|
77
|
-
_ref2 = (0, _slicedToArray2.default)(_ref, 1),
|
78
|
-
head = _ref2[0];
|
79
|
-
const _Children$toArray = _react.Children.toArray(head.props.children),
|
76
|
+
const _Children$toArray = _react.Children.toArray(this.props.children),
|
80
77
|
_Children$toArray2 = (0, _slicedToArray2.default)(_Children$toArray, 1),
|
81
|
-
|
82
|
-
if (!
|
83
|
-
|
78
|
+
headChild = _Children$toArray2[0];
|
79
|
+
if (!headChild || ! /*#__PURE__*/(0, _react.isValidElement)(headChild)) return void 0;
|
80
|
+
const _Children$toArray3 = _react.Children.toArray(headChild.props.children),
|
81
|
+
_Children$toArray4 = (0, _slicedToArray2.default)(_Children$toArray3, 1),
|
82
|
+
firstRow = _Children$toArray4[0];
|
83
|
+
if (!firstRow || ! /*#__PURE__*/(0, _react.isValidElement)(firstRow)) return void 0;
|
84
|
+
return _react.Children.map(firstRow.props.children, colHeader => {
|
85
|
+
if (! /*#__PURE__*/(0, _react.isValidElement)(colHeader)) return void 0;
|
84
86
|
return colHeader.props.children;
|
85
87
|
});
|
86
88
|
}
|
@@ -94,7 +96,13 @@ let Table = exports.Table = (_dec = (0, _emotion.withStyle)(_styles.default, _th
|
|
94
96
|
styles = _this$props3.styles;
|
95
97
|
const isStacked = layout === 'stacked';
|
96
98
|
const headers = isStacked ? this.getHeaders() : void 0;
|
97
|
-
return (0, _emotion.jsx)(
|
99
|
+
return (0, _emotion.jsx)(_TableContext.default.Provider, {
|
100
|
+
value: {
|
101
|
+
isStacked: isStacked,
|
102
|
+
hover: hover,
|
103
|
+
headers: headers
|
104
|
+
}
|
105
|
+
}, (0, _emotion.jsx)(_View.View, Object.assign({}, _View.View.omitViewProps((0, _omitProps.omitProps)(this.props, Table.allowedProps), Table), {
|
98
106
|
as: isStacked ? 'div' : 'table',
|
99
107
|
margin: margin,
|
100
108
|
elementRef: this.handleRef,
|
@@ -102,13 +110,13 @@ let Table = exports.Table = (_dec = (0, _emotion.withStyle)(_styles.default, _th
|
|
102
110
|
role: isStacked ? 'table' : void 0,
|
103
111
|
"aria-label": isStacked ? caption : void 0
|
104
112
|
}), !isStacked && (0, _emotion.jsx)("caption", null, (0, _emotion.jsx)(_ScreenReaderContent.ScreenReaderContent, null, caption)), _react.Children.map(children, child => {
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
}));
|
113
|
+
if ( /*#__PURE__*/(0, _react.isValidElement)(child)) {
|
114
|
+
return (0, _safeCloneElement.safeCloneElement)(child, {
|
115
|
+
key: child.props.name
|
116
|
+
});
|
117
|
+
}
|
118
|
+
return child;
|
119
|
+
})));
|
112
120
|
}
|
113
121
|
}, _Table.displayName = "Table", _Table.componentId = 'Table', _Table.allowedProps = _props.allowedProps, _Table.propTypes = _props.propTypes, _Table.defaultProps = {
|
114
122
|
children: null,
|
package/lib/index.js
CHANGED
@@ -9,4 +9,11 @@ Object.defineProperty(exports, "Table", {
|
|
9
9
|
return _Table.Table;
|
10
10
|
}
|
11
11
|
});
|
12
|
-
|
12
|
+
Object.defineProperty(exports, "TableContext", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _TableContext.TableContext;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
var _Table = require("./Table");
|
19
|
+
var _TableContext = require("./Table/TableContext");
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instructure/ui-table",
|
3
|
-
"version": "10.2.1-snapshot-
|
3
|
+
"version": "10.2.1-snapshot-12",
|
4
4
|
"description": "A styled HTML table component",
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
6
6
|
"module": "./es/index.js",
|
@@ -23,11 +23,11 @@
|
|
23
23
|
},
|
24
24
|
"license": "MIT",
|
25
25
|
"devDependencies": {
|
26
|
-
"@instructure/ui-axe-check": "10.2.1-snapshot-
|
27
|
-
"@instructure/ui-babel-preset": "10.2.1-snapshot-
|
28
|
-
"@instructure/ui-color-utils": "10.2.1-snapshot-
|
29
|
-
"@instructure/ui-test-utils": "10.2.1-snapshot-
|
30
|
-
"@instructure/ui-themes": "10.2.1-snapshot-
|
26
|
+
"@instructure/ui-axe-check": "10.2.1-snapshot-12",
|
27
|
+
"@instructure/ui-babel-preset": "10.2.1-snapshot-12",
|
28
|
+
"@instructure/ui-color-utils": "10.2.1-snapshot-12",
|
29
|
+
"@instructure/ui-test-utils": "10.2.1-snapshot-12",
|
30
|
+
"@instructure/ui-themes": "10.2.1-snapshot-12",
|
31
31
|
"@testing-library/jest-dom": "^6.4.6",
|
32
32
|
"@testing-library/react": "^15.0.7",
|
33
33
|
"@testing-library/user-event": "^14.5.2",
|
@@ -35,17 +35,17 @@
|
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
37
|
"@babel/runtime": "^7.24.5",
|
38
|
-
"@instructure/console": "10.2.1-snapshot-
|
39
|
-
"@instructure/emotion": "10.2.1-snapshot-
|
40
|
-
"@instructure/shared-types": "10.2.1-snapshot-
|
41
|
-
"@instructure/ui-a11y-content": "10.2.1-snapshot-
|
42
|
-
"@instructure/ui-icons": "10.2.1-snapshot-
|
43
|
-
"@instructure/ui-prop-types": "10.2.1-snapshot-
|
44
|
-
"@instructure/ui-react-utils": "10.2.1-snapshot-
|
45
|
-
"@instructure/ui-simple-select": "10.2.1-snapshot-
|
46
|
-
"@instructure/ui-testable": "10.2.1-snapshot-
|
47
|
-
"@instructure/ui-utils": "10.2.1-snapshot-
|
48
|
-
"@instructure/ui-view": "10.2.1-snapshot-
|
38
|
+
"@instructure/console": "10.2.1-snapshot-12",
|
39
|
+
"@instructure/emotion": "10.2.1-snapshot-12",
|
40
|
+
"@instructure/shared-types": "10.2.1-snapshot-12",
|
41
|
+
"@instructure/ui-a11y-content": "10.2.1-snapshot-12",
|
42
|
+
"@instructure/ui-icons": "10.2.1-snapshot-12",
|
43
|
+
"@instructure/ui-prop-types": "10.2.1-snapshot-12",
|
44
|
+
"@instructure/ui-react-utils": "10.2.1-snapshot-12",
|
45
|
+
"@instructure/ui-simple-select": "10.2.1-snapshot-12",
|
46
|
+
"@instructure/ui-testable": "10.2.1-snapshot-12",
|
47
|
+
"@instructure/ui-utils": "10.2.1-snapshot-12",
|
48
|
+
"@instructure/ui-view": "10.2.1-snapshot-12",
|
49
49
|
"prop-types": "^15.8.1"
|
50
50
|
},
|
51
51
|
"peerDependencies": {
|
package/src/Table/Body/index.tsx
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
*/
|
24
24
|
|
25
25
|
/** @jsx jsx */
|
26
|
-
import { Component, Children } from 'react'
|
26
|
+
import { Component, Children, ContextType, isValidElement } from 'react'
|
27
27
|
|
28
28
|
import { safeCloneElement, omitProps } from '@instructure/ui-react-utils'
|
29
29
|
import { View } from '@instructure/ui-view'
|
@@ -32,8 +32,8 @@ import { withStyle, jsx } from '@instructure/emotion'
|
|
32
32
|
import generateStyle from './styles'
|
33
33
|
import generateComponentTheme from './theme'
|
34
34
|
import type { TableBodyProps } from './props'
|
35
|
-
import type { RowChild } from '../props'
|
36
35
|
import { allowedProps, propTypes } from './props'
|
36
|
+
import TableContext from '../TableContext'
|
37
37
|
|
38
38
|
/**
|
39
39
|
---
|
@@ -44,10 +44,10 @@ id: Table.Body
|
|
44
44
|
@withStyle(generateStyle, generateComponentTheme)
|
45
45
|
class Body extends Component<TableBodyProps> {
|
46
46
|
static readonly componentId = 'Table.Body'
|
47
|
-
|
47
|
+
static contextType = TableContext
|
48
|
+
declare context: ContextType<typeof TableContext>
|
48
49
|
static allowedProps = allowedProps
|
49
50
|
static propTypes = propTypes
|
50
|
-
|
51
51
|
static defaultProps = {
|
52
52
|
children: null
|
53
53
|
}
|
@@ -61,7 +61,8 @@ class Body extends Component<TableBodyProps> {
|
|
61
61
|
}
|
62
62
|
|
63
63
|
render() {
|
64
|
-
const { children,
|
64
|
+
const { children, styles } = this.props
|
65
|
+
const { isStacked, hover, headers } = this.context
|
65
66
|
|
66
67
|
return (
|
67
68
|
<View
|
@@ -70,14 +71,23 @@ class Body extends Component<TableBodyProps> {
|
|
70
71
|
css={styles?.body}
|
71
72
|
role={isStacked ? 'rowgroup' : undefined}
|
72
73
|
>
|
73
|
-
{Children.map(children
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
{Children.map(children, (child) => {
|
75
|
+
if (isValidElement(child)) {
|
76
|
+
return safeCloneElement(child, {
|
77
|
+
key: child.props.name,
|
78
|
+
// Sent down for compatibility with custom components
|
79
|
+
// TODO DEPRECATED, remove in v11
|
80
|
+
hover,
|
81
|
+
// Sent down for compatibility with custom components
|
82
|
+
// TODO DEPRECATED, remove in v11
|
83
|
+
isStacked,
|
84
|
+
// Sent down for compatibility with custom components
|
85
|
+
// TODO DEPRECATED, remove in v11
|
86
|
+
headers
|
87
|
+
})
|
88
|
+
}
|
89
|
+
return child
|
90
|
+
})}
|
81
91
|
</View>
|
82
92
|
)
|
83
93
|
}
|
package/src/Table/Body/props.ts
CHANGED
@@ -24,8 +24,6 @@
|
|
24
24
|
import React from 'react'
|
25
25
|
import PropTypes from 'prop-types'
|
26
26
|
|
27
|
-
import type { TableRowProps } from '../Row/props'
|
28
|
-
|
29
27
|
import type {
|
30
28
|
OtherHTMLAttributes,
|
31
29
|
PropValidators,
|
@@ -34,11 +32,11 @@ import type {
|
|
34
32
|
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
35
33
|
|
36
34
|
type TableBodyOwnProps = {
|
37
|
-
hover?: boolean
|
38
|
-
isStacked?: boolean
|
39
|
-
headers?: TableRowProps['headers']
|
40
35
|
/**
|
41
|
-
*
|
36
|
+
* Body's children should be a container component where each child represents
|
37
|
+
* a row.
|
38
|
+
*
|
39
|
+
* `Table.Row` by default
|
42
40
|
*/
|
43
41
|
children?: React.ReactNode
|
44
42
|
}
|
@@ -54,20 +52,10 @@ type TableBodyProps = TableBodyOwnProps &
|
|
54
52
|
type TableBodyStyle = ComponentStyle<'body'>
|
55
53
|
|
56
54
|
const propTypes: PropValidators<PropKeys> = {
|
57
|
-
children: PropTypes.node
|
58
|
-
hover: PropTypes.bool,
|
59
|
-
isStacked: PropTypes.bool,
|
60
|
-
headers: PropTypes.arrayOf(
|
61
|
-
PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
62
|
-
)
|
55
|
+
children: PropTypes.node
|
63
56
|
}
|
64
57
|
|
65
|
-
const allowedProps: AllowedPropKeys = [
|
66
|
-
'children',
|
67
|
-
'hover',
|
68
|
-
'isStacked',
|
69
|
-
'headers'
|
70
|
-
]
|
58
|
+
const allowedProps: AllowedPropKeys = ['children']
|
71
59
|
|
72
60
|
export type { TableBodyProps, TableBodyStyle }
|
73
61
|
export { propTypes, allowedProps }
|
package/src/Table/Body/styles.ts
CHANGED
@@ -31,8 +31,6 @@ import type { TableBodyStyle } from './props'
|
|
31
31
|
* ---
|
32
32
|
* Generates the style object from the theme and provided additional information
|
33
33
|
* @param {Object} componentTheme The theme variable object.
|
34
|
-
* @param {Object} props the props of the component, the style is applied to
|
35
|
-
* @param {Object} state the state of the component, the style is applied to
|
36
34
|
* @return {Object} The final style object, which will be used in the component
|
37
35
|
*/
|
38
36
|
const generateStyle = (componentTheme: TableBodyTheme): TableBodyStyle => {
|
package/src/Table/Cell/index.tsx
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
*/
|
24
24
|
|
25
25
|
/** @jsx jsx */
|
26
|
-
import { Component } from 'react'
|
26
|
+
import { Component, ContextType } from 'react'
|
27
27
|
|
28
28
|
import { omitProps, callRenderProp } from '@instructure/ui-react-utils'
|
29
29
|
import { View } from '@instructure/ui-view'
|
@@ -34,6 +34,7 @@ import generateStyle from './styles'
|
|
34
34
|
import generateComponentTheme from './theme'
|
35
35
|
import type { TableCellProps } from './props'
|
36
36
|
import { allowedProps, propTypes } from './props'
|
37
|
+
import TableContext from '../TableContext'
|
37
38
|
|
38
39
|
/**
|
39
40
|
---
|
@@ -44,7 +45,8 @@ id: Table.Cell
|
|
44
45
|
@withStyle(generateStyle, generateComponentTheme)
|
45
46
|
class Cell extends Component<TableCellProps> {
|
46
47
|
static readonly componentId = 'Table.Cell'
|
47
|
-
|
48
|
+
static contextType = TableContext
|
49
|
+
declare context: ContextType<typeof TableContext>
|
48
50
|
static allowedProps = allowedProps
|
49
51
|
static propTypes = propTypes
|
50
52
|
|
@@ -62,7 +64,8 @@ class Cell extends Component<TableCellProps> {
|
|
62
64
|
}
|
63
65
|
|
64
66
|
render() {
|
65
|
-
const { children, styles,
|
67
|
+
const { children, styles, header } = this.props
|
68
|
+
const isStacked = this.context.isStacked
|
66
69
|
|
67
70
|
return (
|
68
71
|
<View
|
package/src/Table/Cell/props.ts
CHANGED
@@ -33,10 +33,14 @@ import type {
|
|
33
33
|
} from '@instructure/shared-types'
|
34
34
|
|
35
35
|
type TableCellOwnProps = {
|
36
|
-
|
36
|
+
/**
|
37
|
+
* Contains the column header for this cell.
|
38
|
+
* This gets rendered in `stacked` layout to identify the column the data
|
39
|
+
* belongs to.
|
40
|
+
*/
|
37
41
|
header?: Renderable
|
38
42
|
/**
|
39
|
-
*
|
43
|
+
* Controls the text alignment in cell.
|
40
44
|
*/
|
41
45
|
textAlign?: 'start' | 'center' | 'end'
|
42
46
|
children?: Renderable
|
@@ -54,17 +58,11 @@ type TableCellStyle = ComponentStyle<'cell'>
|
|
54
58
|
|
55
59
|
const propTypes: PropValidators<PropKeys> = {
|
56
60
|
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
57
|
-
isStacked: PropTypes.bool,
|
58
61
|
header: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
59
62
|
textAlign: PropTypes.oneOf(['start', 'center', 'end'])
|
60
63
|
}
|
61
64
|
|
62
|
-
const allowedProps: AllowedPropKeys = [
|
63
|
-
'children',
|
64
|
-
'isStacked',
|
65
|
-
'header',
|
66
|
-
'textAlign'
|
67
|
-
]
|
65
|
+
const allowedProps: AllowedPropKeys = ['children', 'header', 'textAlign']
|
68
66
|
|
69
67
|
export type { TableCellProps, TableCellStyle }
|
70
68
|
export { propTypes, allowedProps }
|
@@ -32,7 +32,10 @@ import type {
|
|
32
32
|
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
33
33
|
|
34
34
|
type TableColHeaderOwnProps = {
|
35
|
-
|
35
|
+
/**
|
36
|
+
* DEPRECATED. Use `TableContext` to read this value
|
37
|
+
*/
|
38
|
+
isStacked?: boolean
|
36
39
|
/**
|
37
40
|
* A unique id for this column. The `id` is also used as option in combobox,
|
38
41
|
* when sortable table is in stacked layout,
|
@@ -53,18 +56,18 @@ type TableColHeaderOwnProps = {
|
|
53
56
|
*/
|
54
57
|
textAlign?: 'start' | 'center' | 'end'
|
55
58
|
/**
|
56
|
-
* The
|
59
|
+
* The sorting direction
|
57
60
|
*/
|
58
61
|
sortDirection?: 'none' | 'ascending' | 'descending'
|
59
62
|
/**
|
60
|
-
* Callback fired when column header is clicked.
|
63
|
+
* Callback fired when column header is clicked.
|
61
64
|
*/
|
62
65
|
onRequestSort?: (
|
63
66
|
event: React.SyntheticEvent,
|
64
67
|
param: { id: TableColHeaderOwnProps['id'] }
|
65
68
|
) => void
|
66
69
|
/**
|
67
|
-
* The column header scope attribute. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th#
|
70
|
+
* The column header scope attribute. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th#scope
|
68
71
|
*/
|
69
72
|
scope?: 'row' | 'col' | 'rowgroup' | 'colgroup' | 'auto'
|
70
73
|
children?: React.ReactNode
|
@@ -32,7 +32,6 @@ import type { TableColHeaderProps, TableColHeaderStyle } from './props'
|
|
32
32
|
* Generates the style object from the theme and provided additional information
|
33
33
|
* @param {Object} componentTheme The theme variable object.
|
34
34
|
* @param {Object} props the props of the component, the style is applied to
|
35
|
-
* @param {Object} state the state of the component, the style is applied to
|
36
35
|
* @return {Object} The final style object, which will be used in the component
|
37
36
|
*/
|
38
37
|
const generateStyle = (
|
package/src/Table/Head/index.tsx
CHANGED
@@ -23,13 +23,9 @@
|
|
23
23
|
*/
|
24
24
|
|
25
25
|
/** @jsx jsx */
|
26
|
-
import { Component, Children } from 'react'
|
26
|
+
import { Component, Children, ContextType } from 'react'
|
27
27
|
|
28
|
-
import {
|
29
|
-
omitProps,
|
30
|
-
matchComponentTypes,
|
31
|
-
callRenderProp
|
32
|
-
} from '@instructure/ui-react-utils'
|
28
|
+
import { omitProps, callRenderProp } from '@instructure/ui-react-utils'
|
33
29
|
import { SimpleSelect } from '@instructure/ui-simple-select'
|
34
30
|
import type { SimpleSelectProps } from '@instructure/ui-simple-select'
|
35
31
|
import { ScreenReaderContent } from '@instructure/ui-a11y-content'
|
@@ -41,12 +37,11 @@ import { withStyle, jsx } from '@instructure/emotion'
|
|
41
37
|
import generateStyle from './styles'
|
42
38
|
import generateComponentTheme from './theme'
|
43
39
|
|
44
|
-
import { Row } from '../Row'
|
45
|
-
import { ColHeader } from '../ColHeader'
|
46
40
|
import type { TableColHeaderProps } from '../ColHeader/props'
|
47
41
|
import type { TableHeadProps } from './props'
|
48
|
-
import type {
|
42
|
+
import type { RowChild } from '../props'
|
49
43
|
import { allowedProps, propTypes } from './props'
|
44
|
+
import TableContext from '../TableContext'
|
50
45
|
|
51
46
|
/**
|
52
47
|
---
|
@@ -57,26 +52,28 @@ id: Table.Head
|
|
57
52
|
@withStyle(generateStyle, generateComponentTheme)
|
58
53
|
class Head extends Component<TableHeadProps> {
|
59
54
|
static readonly componentId = 'Table.Head'
|
60
|
-
|
55
|
+
static contextType = TableContext
|
56
|
+
declare context: ContextType<typeof TableContext>
|
61
57
|
static allowedProps = allowedProps
|
62
58
|
static propTypes = propTypes
|
63
|
-
|
64
59
|
static defaultProps = {
|
65
60
|
children: null
|
66
61
|
}
|
67
62
|
|
63
|
+
/**
|
64
|
+
* Returns `true` if the first child's children have a `onRequestSort` prop
|
65
|
+
*/
|
68
66
|
get isSortable() {
|
69
|
-
const [
|
67
|
+
const [firstRow] = Children.toArray(this.props.children) as RowChild[]
|
70
68
|
let sortable = false
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
69
|
+
if (firstRow && firstRow.props && firstRow.props.children) {
|
70
|
+
Children.forEach(firstRow.props.children, (grandchild) => {
|
71
|
+
if (grandchild.props.onRequestSort) {
|
72
|
+
sortable = true
|
73
|
+
return
|
76
74
|
}
|
77
75
|
})
|
78
76
|
}
|
79
|
-
|
80
77
|
return sortable
|
81
78
|
}
|
82
79
|
|
@@ -94,13 +91,19 @@ class Head extends Component<TableHeadProps> {
|
|
94
91
|
this.props.makeStyles?.()
|
95
92
|
}
|
96
93
|
|
94
|
+
/**
|
95
|
+
* This `Select` is used in `stacked` layout. It's populated by iterating
|
96
|
+
* through the first child's children (by default `ColHeader`) and reading
|
97
|
+
* there the `id`, `stackedSortByLabel`, `sortDirection`, `onRequestSort` props
|
98
|
+
*/
|
97
99
|
renderSelect() {
|
98
100
|
const { children, renderSortLabel } = this.props
|
99
|
-
const [
|
101
|
+
const [firstRow] = Children.toArray(children) as RowChild[]
|
100
102
|
|
101
|
-
if (!
|
103
|
+
if (!firstRow?.props?.children) {
|
102
104
|
return null
|
103
105
|
}
|
106
|
+
|
104
107
|
const options: {
|
105
108
|
id: TableColHeaderProps['id']
|
106
109
|
label:
|
@@ -113,21 +116,17 @@ class Head extends Component<TableHeadProps> {
|
|
113
116
|
> = {}
|
114
117
|
let selectedOption: TableColHeaderProps['id'] | undefined
|
115
118
|
let count = 0
|
116
|
-
|
117
|
-
Children.forEach(row.props.children, (colHeader) => {
|
119
|
+
Children.forEach(firstRow.props.children, (grandchild) => {
|
118
120
|
count += 1
|
119
|
-
if (
|
120
|
-
|
121
|
-
|
122
|
-
|
121
|
+
if (!grandchild.props) return
|
122
|
+
const { id, stackedSortByLabel, sortDirection, onRequestSort } =
|
123
|
+
grandchild.props
|
124
|
+
if (id && onRequestSort) {
|
123
125
|
const label = stackedSortByLabel || id
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
if (sortDirection !== 'none') {
|
129
|
-
selectedOption = id
|
130
|
-
}
|
126
|
+
options.push({ id, label })
|
127
|
+
clickHandlers[id] = onRequestSort
|
128
|
+
if (sortDirection !== 'none') {
|
129
|
+
selectedOption = id
|
131
130
|
}
|
132
131
|
}
|
133
132
|
})
|
@@ -177,15 +176,16 @@ class Head extends Component<TableHeadProps> {
|
|
177
176
|
}
|
178
177
|
|
179
178
|
render() {
|
180
|
-
const { children,
|
181
|
-
|
182
|
-
return isStacked ? (
|
179
|
+
const { children, styles } = this.props
|
180
|
+
return this.context.isStacked ? (
|
183
181
|
this.renderSelect()
|
184
182
|
) : (
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
183
|
+
// TODO remove 'hover' exclude in v11, its passed down for compatibility with custom components
|
184
|
+
<thead
|
185
|
+
{...omitProps(this.props, Head.allowedProps, ['hover'])}
|
186
|
+
css={styles?.head}
|
187
|
+
>
|
188
|
+
{children}
|
189
189
|
</thead>
|
190
190
|
)
|
191
191
|
}
|
package/src/Table/Head/props.ts
CHANGED
@@ -22,7 +22,6 @@
|
|
22
22
|
* SOFTWARE.
|
23
23
|
*/
|
24
24
|
|
25
|
-
import React from 'react'
|
26
25
|
import PropTypes from 'prop-types'
|
27
26
|
|
28
27
|
import type {
|
@@ -32,15 +31,30 @@ import type {
|
|
32
31
|
TableHeadTheme
|
33
32
|
} from '@instructure/shared-types'
|
34
33
|
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
34
|
+
import { RowChild } from '../props'
|
35
35
|
|
36
36
|
type TableHeadOwnProps = {
|
37
|
-
|
38
|
-
|
37
|
+
/**
|
38
|
+
* The sort `Select`'s label when using `stacked` layout and the table is
|
39
|
+
* sortable.
|
40
|
+
* If you don't want to display anything you should use `ScreenReaderContent`
|
41
|
+
* so screen readers can read the `Select`'s purpose
|
42
|
+
*/
|
39
43
|
renderSortLabel?: Renderable
|
40
44
|
/**
|
41
|
-
*
|
45
|
+
* The header row(s).
|
46
|
+
* Default type: `Table.Row`
|
47
|
+
*
|
48
|
+
* Its first child is treated specially if the table is sortable and has
|
49
|
+
* `stacked` layout:
|
50
|
+
*
|
51
|
+
* A `Select` is created which reads options from the first child's
|
52
|
+
* children, that tries to read the following props: `id`,
|
53
|
+
* `stackedSortByLabel`,`sortDirection`, `onRequestSort` (Available on
|
54
|
+
* `Table.ColHeader`).
|
55
|
+
* These are used to sort the table in this layout.
|
42
56
|
*/
|
43
|
-
children?:
|
57
|
+
children?: RowChild
|
44
58
|
}
|
45
59
|
type PropKeys = keyof TableHeadOwnProps
|
46
60
|
|
@@ -54,17 +68,10 @@ type TableHeadStyle = ComponentStyle<'head'>
|
|
54
68
|
|
55
69
|
const propTypes: PropValidators<PropKeys> = {
|
56
70
|
children: PropTypes.node,
|
57
|
-
hover: PropTypes.bool,
|
58
|
-
isStacked: PropTypes.bool,
|
59
71
|
renderSortLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
60
72
|
}
|
61
73
|
|
62
|
-
const allowedProps: AllowedPropKeys = [
|
63
|
-
'children',
|
64
|
-
'hover',
|
65
|
-
'isStacked',
|
66
|
-
'renderSortLabel'
|
67
|
-
]
|
74
|
+
const allowedProps: AllowedPropKeys = ['children', 'renderSortLabel']
|
68
75
|
|
69
76
|
export type { TableHeadProps, TableHeadStyle }
|
70
77
|
export { propTypes, allowedProps }
|
package/src/Table/Head/styles.ts
CHANGED
@@ -31,8 +31,6 @@ import type { TableHeadStyle } from './props'
|
|
31
31
|
* ---
|
32
32
|
* Generates the style object from the theme and provided additional information
|
33
33
|
* @param {Object} componentTheme The theme variable object.
|
34
|
-
* @param {Object} props the props of the component, the style is applied to
|
35
|
-
* @param {Object} state the state of the component, the style is applied to
|
36
34
|
* @return {Object} The final style object, which will be used in the component
|
37
35
|
*/
|
38
36
|
const generateStyle = (componentTheme: TableHeadTheme): TableHeadStyle => {
|