@instructure/ui-table 8.14.1-snapshot.7 → 8.15.1-snapshot.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 +4 -0
- package/es/Table/Body/index.js +2 -1
- package/es/Table/Body/props.js +0 -3
- package/es/Table/Cell/index.js +1 -0
- package/es/Table/Cell/props.js +0 -4
- package/es/Table/ColHeader/index.js +3 -2
- package/es/Table/ColHeader/props.js +0 -30
- package/es/Table/Head/index.js +19 -15
- package/es/Table/Head/props.js +0 -3
- package/es/Table/Row/index.js +1 -0
- package/es/Table/Row/props.js +0 -3
- package/es/Table/RowHeader/index.js +1 -0
- package/es/Table/RowHeader/props.js +0 -4
- package/es/Table/index.js +10 -9
- package/es/Table/props.js +0 -28
- package/lib/Table/Body/index.js +2 -1
- package/lib/Table/Body/props.js +0 -3
- package/lib/Table/Cell/index.js +1 -0
- package/lib/Table/Cell/props.js +0 -4
- package/lib/Table/ColHeader/index.js +5 -2
- package/lib/Table/ColHeader/props.js +0 -30
- package/lib/Table/Head/index.js +19 -15
- package/lib/Table/Head/props.js +0 -3
- package/lib/Table/Row/index.js +1 -0
- package/lib/Table/Row/props.js +0 -3
- package/lib/Table/RowHeader/index.js +1 -0
- package/lib/Table/RowHeader/props.js +0 -4
- package/lib/Table/index.js +10 -9
- package/lib/Table/props.js +0 -28
- package/package.json +17 -17
- package/src/Table/Body/index.tsx +6 -6
- package/src/Table/Body/props.ts +5 -4
- package/src/Table/Cell/index.tsx +1 -0
- package/src/Table/Cell/props.ts +5 -5
- package/src/Table/ColHeader/index.tsx +6 -15
- package/src/Table/ColHeader/props.ts +29 -26
- package/src/Table/Head/index.tsx +34 -29
- package/src/Table/Head/props.ts +4 -4
- package/src/Table/Row/index.tsx +15 -9
- package/src/Table/Row/props.ts +5 -4
- package/src/Table/RowHeader/index.tsx +1 -0
- package/src/Table/RowHeader/props.ts +4 -4
- package/src/Table/index.tsx +30 -20
- package/src/Table/props.ts +55 -28
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Table/Body/index.d.ts +4 -3
- package/types/Table/Body/index.d.ts.map +1 -1
- package/types/Table/Body/props.d.ts +5 -1
- package/types/Table/Body/props.d.ts.map +1 -1
- package/types/Table/Cell/index.d.ts +5 -4
- package/types/Table/Cell/index.d.ts.map +1 -1
- package/types/Table/Cell/props.d.ts +5 -2
- package/types/Table/Cell/props.d.ts.map +1 -1
- package/types/Table/ColHeader/index.d.ts +11 -6
- package/types/Table/ColHeader/index.d.ts.map +1 -1
- package/types/Table/ColHeader/props.d.ts +28 -2
- package/types/Table/ColHeader/props.d.ts.map +1 -1
- package/types/Table/Head/index.d.ts +3 -2
- package/types/Table/Head/index.d.ts.map +1 -1
- package/types/Table/Head/props.d.ts +4 -1
- package/types/Table/Head/props.d.ts.map +1 -1
- package/types/Table/Row/index.d.ts +3 -2
- package/types/Table/Row/index.d.ts.map +1 -1
- package/types/Table/Row/props.d.ts +5 -1
- package/types/Table/Row/props.d.ts.map +1 -1
- package/types/Table/RowHeader/index.d.ts +3 -2
- package/types/Table/RowHeader/index.d.ts.map +1 -1
- package/types/Table/RowHeader/props.d.ts +4 -1
- package/types/Table/RowHeader/props.d.ts.map +1 -1
- package/types/Table/index.d.ts +4 -3
- package/types/Table/index.d.ts.map +1 -1
- package/types/Table/props.d.ts +43 -2
- package/types/Table/props.d.ts.map +1 -1
package/lib/Table/props.js
CHANGED
@@ -41,39 +41,11 @@ var _Body = require("./Body");
|
|
41
41
|
* SOFTWARE.
|
42
42
|
*/
|
43
43
|
const propTypes = {
|
44
|
-
/**
|
45
|
-
* Provide a screen reader friendly description. Anything passed to this
|
46
|
-
* prop will be wrapped by `<ScreenReaderContent>` when it is rendered.
|
47
|
-
*/
|
48
44
|
caption: _propTypes.default.node.isRequired,
|
49
|
-
|
50
|
-
/**
|
51
|
-
* Build table via `Table.Head` and `Table.Body`
|
52
|
-
*/
|
53
45
|
children: _Children.Children.oneOf([_Head.Head, _Body.Body]),
|
54
|
-
|
55
|
-
/**
|
56
|
-
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
57
|
-
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
58
|
-
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
59
|
-
*/
|
60
46
|
margin: _emotion.ThemeablePropTypes.spacing,
|
61
|
-
|
62
|
-
/**
|
63
|
-
* Provide a reference to the underlying html element
|
64
|
-
*/
|
65
47
|
elementRef: _propTypes.default.func,
|
66
|
-
|
67
|
-
/**
|
68
|
-
* Highlight each row on hover
|
69
|
-
*/
|
70
48
|
hover: _propTypes.default.bool,
|
71
|
-
|
72
|
-
/**
|
73
|
-
* `auto` lets the browser determine table column widths based on cell content,
|
74
|
-
* while `fixed` forces columns of equal width. `stacked` renders table in one
|
75
|
-
* column to be more readable on narrow screens
|
76
|
-
*/
|
77
49
|
layout: _propTypes.default.oneOf(['auto', 'fixed', 'stacked'])
|
78
50
|
};
|
79
51
|
exports.propTypes = propTypes;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instructure/ui-table",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.15.1-snapshot.2+00f55c738",
|
4
4
|
"description": "A styled HTML table component",
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
6
6
|
"type": "commonjs",
|
@@ -24,24 +24,24 @@
|
|
24
24
|
},
|
25
25
|
"license": "MIT",
|
26
26
|
"devDependencies": {
|
27
|
-
"@instructure/ui-babel-preset": "8.
|
28
|
-
"@instructure/ui-color-utils": "8.
|
29
|
-
"@instructure/ui-test-utils": "8.
|
30
|
-
"@instructure/ui-themes": "8.
|
27
|
+
"@instructure/ui-babel-preset": "8.15.1-snapshot.2+00f55c738",
|
28
|
+
"@instructure/ui-color-utils": "8.15.1-snapshot.2+00f55c738",
|
29
|
+
"@instructure/ui-test-utils": "8.15.1-snapshot.2+00f55c738",
|
30
|
+
"@instructure/ui-themes": "8.15.1-snapshot.2+00f55c738"
|
31
31
|
},
|
32
32
|
"dependencies": {
|
33
33
|
"@babel/runtime": "^7.13.10",
|
34
|
-
"@instructure/console": "8.
|
35
|
-
"@instructure/emotion": "8.
|
36
|
-
"@instructure/shared-types": "8.
|
37
|
-
"@instructure/ui-a11y-content": "8.
|
38
|
-
"@instructure/ui-icons": "8.
|
39
|
-
"@instructure/ui-prop-types": "8.
|
40
|
-
"@instructure/ui-react-utils": "8.
|
41
|
-
"@instructure/ui-simple-select": "8.
|
42
|
-
"@instructure/ui-testable": "8.
|
43
|
-
"@instructure/ui-utils": "8.
|
44
|
-
"@instructure/ui-view": "8.
|
34
|
+
"@instructure/console": "8.15.1-snapshot.2+00f55c738",
|
35
|
+
"@instructure/emotion": "8.15.1-snapshot.2+00f55c738",
|
36
|
+
"@instructure/shared-types": "8.15.1-snapshot.2+00f55c738",
|
37
|
+
"@instructure/ui-a11y-content": "8.15.1-snapshot.2+00f55c738",
|
38
|
+
"@instructure/ui-icons": "8.15.1-snapshot.2+00f55c738",
|
39
|
+
"@instructure/ui-prop-types": "8.15.1-snapshot.2+00f55c738",
|
40
|
+
"@instructure/ui-react-utils": "8.15.1-snapshot.2+00f55c738",
|
41
|
+
"@instructure/ui-simple-select": "8.15.1-snapshot.2+00f55c738",
|
42
|
+
"@instructure/ui-testable": "8.15.1-snapshot.2+00f55c738",
|
43
|
+
"@instructure/ui-utils": "8.15.1-snapshot.2+00f55c738",
|
44
|
+
"@instructure/ui-view": "8.15.1-snapshot.2+00f55c738",
|
45
45
|
"prop-types": "^15"
|
46
46
|
},
|
47
47
|
"peerDependencies": {
|
@@ -51,5 +51,5 @@
|
|
51
51
|
"access": "public"
|
52
52
|
},
|
53
53
|
"sideEffects": false,
|
54
|
-
"gitHead": "
|
54
|
+
"gitHead": "00f55c7382e82209ea553c107951c4356ba202bf"
|
55
55
|
}
|
package/src/Table/Body/index.tsx
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
*/
|
24
24
|
|
25
25
|
/** @jsx jsx */
|
26
|
-
import { Component, Children
|
26
|
+
import { Component, Children } from 'react'
|
27
27
|
|
28
28
|
import {
|
29
29
|
matchComponentTypes,
|
@@ -37,6 +37,7 @@ import generateStyle from './styles'
|
|
37
37
|
import generateComponentTheme from './theme'
|
38
38
|
import { Row } from '../Row'
|
39
39
|
import type { TableBodyProps } from './props'
|
40
|
+
import type { RowChild } from '../props'
|
40
41
|
import { allowedProps, propTypes } from './props'
|
41
42
|
|
42
43
|
/**
|
@@ -44,6 +45,7 @@ import { allowedProps, propTypes } from './props'
|
|
44
45
|
parent: Table
|
45
46
|
id: Table.Body
|
46
47
|
---
|
48
|
+
@tsProps
|
47
49
|
**/
|
48
50
|
@withStyle(generateStyle, generateComponentTheme)
|
49
51
|
class Body extends Component<TableBodyProps> {
|
@@ -60,8 +62,7 @@ class Body extends Component<TableBodyProps> {
|
|
60
62
|
this.props.makeStyles?.()
|
61
63
|
}
|
62
64
|
|
63
|
-
|
64
|
-
componentDidUpdate(prevProps, prevState, snapshot) {
|
65
|
+
componentDidUpdate() {
|
65
66
|
this.props.makeStyles?.()
|
66
67
|
}
|
67
68
|
|
@@ -75,10 +76,9 @@ class Body extends Component<TableBodyProps> {
|
|
75
76
|
css={styles?.body}
|
76
77
|
role={isStacked ? 'rowgroup' : undefined}
|
77
78
|
>
|
78
|
-
{Children.map(children, (child) =>
|
79
|
+
{Children.map(children as RowChild[], (child) =>
|
79
80
|
matchComponentTypes(child, [Row])
|
80
|
-
? safeCloneElement(child
|
81
|
-
// @ts-expect-error ts-migrate(2533) FIXME: Object is possibly 'null' or 'undefined'.
|
81
|
+
? safeCloneElement(child, {
|
82
82
|
key: child.props.name,
|
83
83
|
hover,
|
84
84
|
isStacked,
|
package/src/Table/Body/props.ts
CHANGED
@@ -27,6 +27,7 @@ import PropTypes from 'prop-types'
|
|
27
27
|
import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types'
|
28
28
|
|
29
29
|
import { Row } from '../Row'
|
30
|
+
import type { TableRowProps } from '../Row/props'
|
30
31
|
|
31
32
|
import type {
|
32
33
|
OtherHTMLAttributes,
|
@@ -38,7 +39,10 @@ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
38
39
|
type TableBodyOwnProps = {
|
39
40
|
hover?: boolean
|
40
41
|
isStacked?: boolean
|
41
|
-
headers?:
|
42
|
+
headers?: TableRowProps['headers']
|
43
|
+
/**
|
44
|
+
* `Table.Row`
|
45
|
+
*/
|
42
46
|
children?: React.ReactNode
|
43
47
|
}
|
44
48
|
|
@@ -53,9 +57,6 @@ type TableBodyProps = TableBodyOwnProps &
|
|
53
57
|
type TableBodyStyle = ComponentStyle<'body'>
|
54
58
|
|
55
59
|
const propTypes: PropValidators<PropKeys> = {
|
56
|
-
/**
|
57
|
-
* `Table.Row`
|
58
|
-
*/
|
59
60
|
children: ChildrenPropTypes.oneOf([Row]),
|
60
61
|
hover: PropTypes.bool,
|
61
62
|
isStacked: PropTypes.bool,
|
package/src/Table/Cell/index.tsx
CHANGED
package/src/Table/Cell/props.ts
CHANGED
@@ -34,9 +34,12 @@ import type {
|
|
34
34
|
|
35
35
|
type TableCellOwnProps = {
|
36
36
|
isStacked?: boolean
|
37
|
-
header?: React.ReactNode | ((
|
37
|
+
header?: React.ReactNode | (() => React.ReactNode)
|
38
|
+
/**
|
39
|
+
* Control the text alignment in cell
|
40
|
+
*/
|
38
41
|
textAlign?: 'start' | 'center' | 'end'
|
39
|
-
children?: React.ReactNode | ((
|
42
|
+
children?: React.ReactNode | (() => React.ReactNode)
|
40
43
|
}
|
41
44
|
|
42
45
|
type PropKeys = keyof TableCellOwnProps
|
@@ -53,9 +56,6 @@ const propTypes: PropValidators<PropKeys> = {
|
|
53
56
|
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
54
57
|
isStacked: PropTypes.bool,
|
55
58
|
header: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
56
|
-
/**
|
57
|
-
* Control the text alignment in cell
|
58
|
-
*/
|
59
59
|
textAlign: PropTypes.oneOf(['start', 'center', 'end'])
|
60
60
|
}
|
61
61
|
|
@@ -23,7 +23,7 @@
|
|
23
23
|
*/
|
24
24
|
|
25
25
|
/** @jsx jsx */
|
26
|
-
import { Component } from 'react'
|
26
|
+
import React, { Component } from 'react'
|
27
27
|
|
28
28
|
import { omitProps, callRenderProp } from '@instructure/ui-react-utils'
|
29
29
|
import {
|
@@ -43,6 +43,7 @@ import { allowedProps, propTypes } from './props'
|
|
43
43
|
parent: Table
|
44
44
|
id: Table.ColHeader
|
45
45
|
---
|
46
|
+
@tsProps
|
46
47
|
**/
|
47
48
|
@withStyle(generateStyle, generateComponentTheme)
|
48
49
|
class ColHeader extends Component<TableColHeaderProps> {
|
@@ -66,14 +67,10 @@ class ColHeader extends Component<TableColHeaderProps> {
|
|
66
67
|
this.props.makeStyles?.()
|
67
68
|
}
|
68
69
|
|
69
|
-
|
70
|
-
handleClick = (event) => {
|
70
|
+
handleClick = (event: React.SyntheticEvent) => {
|
71
71
|
const { id, onRequestSort } = this.props
|
72
72
|
|
73
|
-
|
74
|
-
onRequestSort(event, {
|
75
|
-
id
|
76
|
-
})
|
73
|
+
onRequestSort && onRequestSort(event, { id })
|
77
74
|
}
|
78
75
|
|
79
76
|
renderSortArrow() {
|
@@ -93,14 +90,8 @@ class ColHeader extends Component<TableColHeaderProps> {
|
|
93
90
|
}
|
94
91
|
|
95
92
|
render() {
|
96
|
-
const {
|
97
|
-
|
98
|
-
width,
|
99
|
-
children,
|
100
|
-
sortDirection,
|
101
|
-
scope,
|
102
|
-
styles
|
103
|
-
} = this.props
|
93
|
+
const { onRequestSort, width, children, sortDirection, scope, styles } =
|
94
|
+
this.props
|
104
95
|
|
105
96
|
return (
|
106
97
|
<th
|
@@ -32,14 +32,41 @@ import type {
|
|
32
32
|
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
33
33
|
|
34
34
|
type TableColHeaderOwnProps = {
|
35
|
+
/**
|
36
|
+
* A unique id for this column. The `id` is also used as option in combobox,
|
37
|
+
* when sortable table is in stacked layout,
|
38
|
+
* and no `stackedSortByLabel` is provided.
|
39
|
+
*/
|
35
40
|
id: string
|
41
|
+
/**
|
42
|
+
* A custom string to display as option text in the combobox (instead of
|
43
|
+
* using the `id` prop), when sortable table is in stacked layout.
|
44
|
+
*/
|
36
45
|
stackedSortByLabel?: string
|
46
|
+
/**
|
47
|
+
* Control the width of column.
|
48
|
+
*/
|
37
49
|
width?: string | number
|
50
|
+
/**
|
51
|
+
* Control the text alignment in column header
|
52
|
+
*/
|
38
53
|
textAlign?: 'start' | 'center' | 'end'
|
54
|
+
/**
|
55
|
+
* The string of sorting direction
|
56
|
+
*/
|
39
57
|
sortDirection?: 'none' | 'ascending' | 'descending'
|
40
|
-
|
58
|
+
/**
|
59
|
+
* Callback fired when column header is clicked. Parameters: `(event, { id })`
|
60
|
+
*/
|
61
|
+
onRequestSort?: (
|
62
|
+
event: React.SyntheticEvent,
|
63
|
+
param: { id: TableColHeaderOwnProps['id'] }
|
64
|
+
) => void
|
65
|
+
/**
|
66
|
+
* The column header scope attribute. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th#attr-scope
|
67
|
+
*/
|
41
68
|
scope?: 'row' | 'col' | 'rowgroup' | 'colgroup' | 'auto'
|
42
|
-
children?: React.ReactNode | ((
|
69
|
+
children?: React.ReactNode | (() => React.ReactNode)
|
43
70
|
}
|
44
71
|
|
45
72
|
type PropKeys = keyof TableColHeaderOwnProps
|
@@ -56,37 +83,13 @@ type TableColHeaderProps = TableColHeaderOwnProps &
|
|
56
83
|
type TableColHeaderStyle = ComponentStyle<'colHeader' | 'button'>
|
57
84
|
|
58
85
|
const propTypes: PropValidators<PropKeys> = {
|
59
|
-
/**
|
60
|
-
* A unique id for this column. The `id` is also used as option in combobox,
|
61
|
-
* when sortable table is in stacked layout,
|
62
|
-
* and no `stackedSortByLabel` is provided.
|
63
|
-
*/
|
64
86
|
id: PropTypes.string.isRequired,
|
65
|
-
/**
|
66
|
-
* A custom string to display as option text in the combobox (instead of
|
67
|
-
* using the `id` prop), when sortable table is in stacked layout.
|
68
|
-
*/
|
69
87
|
stackedSortByLabel: PropTypes.string,
|
70
88
|
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
71
|
-
/**
|
72
|
-
* Control the width of column.
|
73
|
-
*/
|
74
89
|
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
75
|
-
/**
|
76
|
-
* Control the text alignment in column header
|
77
|
-
*/
|
78
90
|
textAlign: PropTypes.oneOf(['start', 'center', 'end']),
|
79
|
-
/**
|
80
|
-
* The string of sorting direction
|
81
|
-
*/
|
82
91
|
sortDirection: PropTypes.oneOf(['none', 'ascending', 'descending']),
|
83
|
-
/**
|
84
|
-
* Callback fired when column header is clicked. Parameters: `(event, { id })`
|
85
|
-
*/
|
86
92
|
onRequestSort: PropTypes.func,
|
87
|
-
/**
|
88
|
-
* The column header scope attribute. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th#attr-scope
|
89
|
-
*/
|
90
93
|
scope: PropTypes.oneOf(['row', 'col', 'rowgroup', 'colgroup', 'auto'])
|
91
94
|
}
|
92
95
|
|
package/src/Table/Head/index.tsx
CHANGED
@@ -31,6 +31,7 @@ import {
|
|
31
31
|
callRenderProp
|
32
32
|
} from '@instructure/ui-react-utils'
|
33
33
|
import { SimpleSelect } from '@instructure/ui-simple-select'
|
34
|
+
import type { SimpleSelectProps } from '@instructure/ui-simple-select'
|
34
35
|
import { ScreenReaderContent } from '@instructure/ui-a11y-content'
|
35
36
|
import { IconCheckLine } from '@instructure/ui-icons'
|
36
37
|
import { warn } from '@instructure/console'
|
@@ -42,7 +43,9 @@ import generateComponentTheme from './theme'
|
|
42
43
|
|
43
44
|
import { Row } from '../Row'
|
44
45
|
import { ColHeader } from '../ColHeader'
|
46
|
+
import type { TableColHeaderProps } from '../ColHeader/props'
|
45
47
|
import type { TableHeadProps } from './props'
|
48
|
+
import type { ColHeaderChild, RowChild } from '../props'
|
46
49
|
import { allowedProps, propTypes } from './props'
|
47
50
|
|
48
51
|
/**
|
@@ -50,6 +53,7 @@ import { allowedProps, propTypes } from './props'
|
|
50
53
|
parent: Table
|
51
54
|
id: Table.Head
|
52
55
|
---
|
56
|
+
@tsProps
|
53
57
|
**/
|
54
58
|
@withStyle(generateStyle, generateComponentTheme)
|
55
59
|
class Head extends Component<TableHeadProps> {
|
@@ -63,16 +67,18 @@ class Head extends Component<TableHeadProps> {
|
|
63
67
|
}
|
64
68
|
|
65
69
|
get isSortable() {
|
66
|
-
const [row] = Children.toArray(this.props.children)
|
70
|
+
const [row] = Children.toArray(this.props.children) as RowChild[]
|
67
71
|
let sortable = false
|
68
72
|
|
69
73
|
if (row) {
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
if (colHeader
|
74
|
+
Children.forEach(
|
75
|
+
row.props.children as ColHeaderChild[],
|
76
|
+
(colHeader) => {
|
77
|
+
if (matchComponentTypes<ColHeaderChild>(colHeader, [ColHeader])) {
|
78
|
+
if (colHeader.props.onRequestSort) sortable = true
|
79
|
+
}
|
74
80
|
}
|
75
|
-
|
81
|
+
)
|
76
82
|
}
|
77
83
|
|
78
84
|
return sortable
|
@@ -94,34 +100,35 @@ class Head extends Component<TableHeadProps> {
|
|
94
100
|
|
95
101
|
renderSelect() {
|
96
102
|
const { children, renderSortLabel } = this.props
|
97
|
-
const [row] = Children.toArray(children)
|
103
|
+
const [row] = Children.toArray(children) as RowChild[]
|
98
104
|
|
99
|
-
if (!matchComponentTypes(row, [Row])) {
|
105
|
+
if (!matchComponentTypes<RowChild>(row, [Row])) {
|
100
106
|
return null
|
101
107
|
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
108
|
+
const options: {
|
109
|
+
id: TableColHeaderProps['id']
|
110
|
+
label:
|
111
|
+
| TableColHeaderProps['stackedSortByLabel']
|
112
|
+
| TableColHeaderProps['id']
|
113
|
+
}[] = []
|
114
|
+
const clickHandlers: Record<
|
115
|
+
TableColHeaderProps['id'],
|
116
|
+
TableColHeaderProps['onRequestSort']
|
117
|
+
> = {}
|
118
|
+
let selectedOption: TableColHeaderProps['id'] | undefined
|
107
119
|
let count = 0
|
108
120
|
|
109
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type 'string | ... Remove this comment to see the full error message
|
110
121
|
Children.forEach(row.props.children, (colHeader) => {
|
111
122
|
count += 1
|
112
|
-
if (matchComponentTypes(colHeader, [ColHeader])) {
|
113
|
-
const {
|
114
|
-
|
115
|
-
|
116
|
-
sortDirection,
|
117
|
-
onRequestSort
|
118
|
-
} = colHeader.props
|
123
|
+
if (matchComponentTypes<ColHeaderChild>(colHeader, [ColHeader])) {
|
124
|
+
const { id, stackedSortByLabel, sortDirection, onRequestSort } = (
|
125
|
+
colHeader
|
126
|
+
).props
|
119
127
|
|
120
128
|
const label = stackedSortByLabel || id
|
121
129
|
|
122
130
|
if (onRequestSort) {
|
123
131
|
options.push({ id, label })
|
124
|
-
// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
125
132
|
clickHandlers[id] = onRequestSort
|
126
133
|
if (sortDirection !== 'none') {
|
127
134
|
selectedOption = id
|
@@ -132,10 +139,10 @@ class Head extends Component<TableHeadProps> {
|
|
132
139
|
if (!options.length) {
|
133
140
|
return null
|
134
141
|
}
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
142
|
+
const handleSelect: SimpleSelectProps['onChange'] = (event, { value }) => {
|
143
|
+
if (value && typeof clickHandlers[value] === 'function') {
|
144
|
+
clickHandlers[value]!(event, { id: `${value}` })
|
145
|
+
}
|
139
146
|
}
|
140
147
|
return (
|
141
148
|
<div role="rowgroup">
|
@@ -153,14 +160,12 @@ class Head extends Component<TableHeadProps> {
|
|
153
160
|
value={selectedOption}
|
154
161
|
onChange={handleSelect}
|
155
162
|
>
|
156
|
-
{/* @ts-expect-error ts-migrate(7005) FIXME: Variable 'options' implicitly has an 'any[]' type. */}
|
157
163
|
{options.map(({ id, label }) => (
|
158
164
|
<SimpleSelect.Option
|
159
165
|
id={id}
|
160
166
|
key={id}
|
161
167
|
value={id}
|
162
168
|
renderBeforeLabel={
|
163
|
-
// @ts-expect-error ts-migrate(7005) FIXME: Variable 'selectedOption' implicitly has an 'any' ... Remove this comment to see the full error message
|
164
169
|
id === selectedOption
|
165
170
|
? IconCheckLine
|
166
171
|
: () => <IconCheckLine style={{ color: 'transparent' }} />
|
@@ -184,7 +189,7 @@ class Head extends Component<TableHeadProps> {
|
|
184
189
|
) : (
|
185
190
|
<thead {...omitProps(this.props, Head.allowedProps)} css={styles?.head}>
|
186
191
|
{Children.map(children, (child) =>
|
187
|
-
matchComponentTypes(child, [Row]) ? child : null
|
192
|
+
matchComponentTypes<RowChild>(child, [Row]) ? child : null
|
188
193
|
)}
|
189
194
|
</thead>
|
190
195
|
)
|
package/src/Table/Head/props.ts
CHANGED
@@ -38,7 +38,10 @@ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
38
38
|
|
39
39
|
type TableHeadOwnProps = {
|
40
40
|
isStacked?: boolean
|
41
|
-
renderSortLabel?: React.ReactNode | ((
|
41
|
+
renderSortLabel?: React.ReactNode | (() => React.ReactNode)
|
42
|
+
/**
|
43
|
+
* `Table.Row`
|
44
|
+
*/
|
42
45
|
children?: React.ReactNode
|
43
46
|
}
|
44
47
|
type PropKeys = keyof TableHeadOwnProps
|
@@ -52,9 +55,6 @@ type TableHeadProps = TableHeadOwnProps &
|
|
52
55
|
type TableHeadStyle = ComponentStyle<'head'>
|
53
56
|
|
54
57
|
const propTypes: PropValidators<PropKeys> = {
|
55
|
-
/**
|
56
|
-
* `Table.Row`
|
57
|
-
*/
|
58
58
|
children: ChildrenPropTypes.oneOf([Row]),
|
59
59
|
isStacked: PropTypes.bool,
|
60
60
|
renderSortLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
package/src/Table/Row/index.tsx
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
*/
|
24
24
|
|
25
25
|
/** @jsx jsx */
|
26
|
-
import { Component, Children
|
26
|
+
import { Component, Children } from 'react'
|
27
27
|
|
28
28
|
import {
|
29
29
|
omitProps,
|
@@ -41,6 +41,7 @@ import { ColHeader } from '../ColHeader'
|
|
41
41
|
import { RowHeader } from '../RowHeader'
|
42
42
|
import { Cell } from '../Cell'
|
43
43
|
import type { TableRowProps } from './props'
|
44
|
+
import type { ColHeaderChild, RowHeaderChild, CellChild } from '../props'
|
44
45
|
import { allowedProps, propTypes } from './props'
|
45
46
|
|
46
47
|
/**
|
@@ -48,6 +49,7 @@ import { allowedProps, propTypes } from './props'
|
|
48
49
|
parent: Table
|
49
50
|
id: Table.Row
|
50
51
|
---
|
52
|
+
@tsProps
|
51
53
|
**/
|
52
54
|
@withStyle(generateStyle, generateComponentTheme)
|
53
55
|
class Row extends Component<TableRowProps> {
|
@@ -78,22 +80,26 @@ class Row extends Component<TableRowProps> {
|
|
78
80
|
css={styles?.row}
|
79
81
|
role={isStacked ? 'row' : undefined}
|
80
82
|
>
|
81
|
-
{
|
83
|
+
{(
|
84
|
+
Children.toArray(children) as (
|
85
|
+
| ColHeaderChild
|
86
|
+
| RowHeaderChild
|
87
|
+
| CellChild
|
88
|
+
)[]
|
89
|
+
)
|
82
90
|
.filter(Boolean)
|
83
91
|
.map((child, index) => {
|
84
|
-
if (matchComponentTypes(child, [ColHeader])) {
|
92
|
+
if (matchComponentTypes<ColHeaderChild>(child, [ColHeader])) {
|
85
93
|
return child
|
86
94
|
}
|
87
|
-
if (matchComponentTypes(child, [RowHeader])) {
|
88
|
-
return safeCloneElement(child
|
89
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type 'string | ... Remove this comment to see the full error message
|
95
|
+
if (matchComponentTypes<RowHeaderChild>(child, [RowHeader])) {
|
96
|
+
return safeCloneElement(child, {
|
90
97
|
key: child.props.name,
|
91
98
|
isStacked
|
92
99
|
})
|
93
100
|
}
|
94
|
-
if (matchComponentTypes(child, [Cell])) {
|
95
|
-
return safeCloneElement(child
|
96
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type 'string | ... Remove this comment to see the full error message
|
101
|
+
if (matchComponentTypes<CellChild>(child, [Cell])) {
|
102
|
+
return safeCloneElement(child, {
|
97
103
|
key: child.props.name,
|
98
104
|
isStacked,
|
99
105
|
header: headers && headers[index]
|
package/src/Table/Row/props.ts
CHANGED
@@ -30,6 +30,7 @@ import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types'
|
|
30
30
|
import { ColHeader } from '../ColHeader'
|
31
31
|
import { RowHeader } from '../RowHeader'
|
32
32
|
import { Cell } from '../Cell'
|
33
|
+
import type { TableCellProps } from '../Cell/props'
|
33
34
|
|
34
35
|
import type {
|
35
36
|
OtherHTMLAttributes,
|
@@ -41,7 +42,10 @@ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
41
42
|
type TableRowOwnProps = {
|
42
43
|
hover?: boolean
|
43
44
|
isStacked?: boolean
|
44
|
-
headers?:
|
45
|
+
headers?: TableCellProps['header'][]
|
46
|
+
/**
|
47
|
+
* `Table.ColHeader`, `Table.RowHeader` or `Table.Cell`
|
48
|
+
*/
|
45
49
|
children?: React.ReactNode
|
46
50
|
}
|
47
51
|
|
@@ -56,9 +60,6 @@ type TableRowProps = TableRowOwnProps &
|
|
56
60
|
type TableRowStyle = ComponentStyle<'row'>
|
57
61
|
|
58
62
|
const propTypes: PropValidators<PropKeys> = {
|
59
|
-
/**
|
60
|
-
* `Table.ColHeader`, `Table.RowHeader` or `Table.Cell`
|
61
|
-
*/
|
62
63
|
children: ChildrenPropTypes.oneOf([ColHeader, RowHeader, Cell]),
|
63
64
|
hover: PropTypes.bool,
|
64
65
|
isStacked: PropTypes.bool,
|
@@ -34,8 +34,11 @@ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
34
34
|
|
35
35
|
type TableRowHeaderOwnProps = {
|
36
36
|
isStacked?: boolean
|
37
|
+
/**
|
38
|
+
* Control the text alignment in row header
|
39
|
+
*/
|
37
40
|
textAlign?: 'start' | 'center' | 'end'
|
38
|
-
children?: React.ReactNode | ((
|
41
|
+
children?: React.ReactNode | (() => React.ReactNode)
|
39
42
|
}
|
40
43
|
|
41
44
|
type PropKeys = keyof TableRowHeaderOwnProps
|
@@ -51,9 +54,6 @@ type TableRowHeaderStyle = ComponentStyle<'rowHeader'>
|
|
51
54
|
const propTypes: PropValidators<PropKeys> = {
|
52
55
|
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
53
56
|
isStacked: PropTypes.bool,
|
54
|
-
/**
|
55
|
-
* Control the text alignment in row header
|
56
|
-
*/
|
57
57
|
textAlign: PropTypes.oneOf(['start', 'center', 'end'])
|
58
58
|
}
|
59
59
|
|