@instructure/ui-table 10.26.1 → 11.0.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 +23 -2
- package/es/Table/Body/index.js +4 -16
- package/es/Table/Body/props.js +1 -5
- package/es/Table/Cell/index.js +2 -2
- package/es/Table/Cell/props.js +1 -7
- package/es/Table/ColHeader/index.js +2 -2
- package/es/Table/ColHeader/props.js +2 -14
- package/es/Table/Head/index.js +4 -6
- package/es/Table/Head/props.js +1 -6
- package/es/Table/Row/index.js +2 -5
- package/es/Table/Row/props.js +1 -6
- package/es/Table/RowHeader/index.js +2 -2
- package/es/Table/RowHeader/props.js +1 -6
- package/es/Table/index.js +6 -2
- package/es/Table/props.js +1 -10
- package/lib/Table/Body/index.js +3 -15
- package/lib/Table/Body/props.js +1 -6
- package/lib/Table/Cell/index.js +1 -1
- package/lib/Table/Cell/props.js +1 -8
- package/lib/Table/ColHeader/index.js +1 -1
- package/lib/Table/ColHeader/props.js +2 -15
- package/lib/Table/Head/index.js +3 -5
- package/lib/Table/Head/props.js +1 -7
- package/lib/Table/Row/index.js +1 -4
- package/lib/Table/Row/props.js +1 -7
- package/lib/Table/RowHeader/index.js +1 -1
- package/lib/Table/RowHeader/props.js +1 -7
- package/lib/Table/index.js +5 -1
- package/lib/Table/props.js +1 -11
- package/package.json +16 -19
- package/src/Table/Body/index.tsx +10 -14
- package/src/Table/Body/props.ts +1 -9
- package/src/Table/Cell/index.tsx +1 -2
- package/src/Table/Cell/props.ts +1 -11
- package/src/Table/ColHeader/index.tsx +1 -2
- package/src/Table/ColHeader/props.ts +1 -21
- package/src/Table/Head/index.tsx +26 -25
- package/src/Table/Head/props.ts +1 -10
- package/src/Table/Row/index.tsx +9 -7
- package/src/Table/Row/props.ts +3 -11
- package/src/Table/RowHeader/index.tsx +1 -2
- package/src/Table/RowHeader/props.ts +1 -10
- package/src/Table/index.tsx +20 -9
- package/src/Table/props.ts +3 -19
- package/tsconfig.build.json +0 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Table/Body/index.d.ts +0 -1
- package/types/Table/Body/index.d.ts.map +1 -1
- package/types/Table/Body/props.d.ts +2 -3
- package/types/Table/Body/props.d.ts.map +1 -1
- package/types/Table/Cell/index.d.ts +0 -5
- package/types/Table/Cell/index.d.ts.map +1 -1
- package/types/Table/Cell/props.d.ts +2 -3
- package/types/Table/Cell/props.d.ts.map +1 -1
- package/types/Table/ColHeader/index.d.ts +0 -14
- package/types/Table/ColHeader/index.d.ts.map +1 -1
- package/types/Table/ColHeader/props.d.ts +2 -7
- package/types/Table/ColHeader/props.d.ts.map +1 -1
- package/types/Table/Head/index.d.ts +0 -4
- package/types/Table/Head/index.d.ts.map +1 -1
- package/types/Table/Head/props.d.ts +2 -3
- package/types/Table/Head/props.d.ts.map +1 -1
- package/types/Table/Row/index.d.ts +1 -5
- package/types/Table/Row/index.d.ts.map +1 -1
- package/types/Table/Row/props.d.ts +3 -4
- package/types/Table/Row/props.d.ts.map +1 -1
- package/types/Table/RowHeader/index.d.ts +0 -4
- package/types/Table/RowHeader/index.d.ts.map +1 -1
- package/types/Table/RowHeader/props.d.ts +2 -3
- package/types/Table/RowHeader/props.d.ts.map +1 -1
- package/types/Table/index.d.ts +1 -9
- package/types/Table/index.d.ts.map +1 -1
- package/types/Table/props.d.ts +3 -4
- package/types/Table/props.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-table",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "A styled HTML table component",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,32 +23,29 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-axe-check": "
|
|
27
|
-
"@instructure/ui-babel-preset": "
|
|
28
|
-
"@instructure/ui-color-utils": "
|
|
29
|
-
"@instructure/ui-themes": "
|
|
26
|
+
"@instructure/ui-axe-check": "11.0.0",
|
|
27
|
+
"@instructure/ui-babel-preset": "11.0.0",
|
|
28
|
+
"@instructure/ui-color-utils": "11.0.0",
|
|
29
|
+
"@instructure/ui-themes": "11.0.0",
|
|
30
30
|
"@testing-library/jest-dom": "^6.6.3",
|
|
31
|
-
"@testing-library/react": "
|
|
31
|
+
"@testing-library/react": "15.0.7",
|
|
32
32
|
"@testing-library/user-event": "^14.6.1",
|
|
33
33
|
"vitest": "^3.2.2"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/runtime": "^7.27.6",
|
|
37
|
-
"@instructure/console": "
|
|
38
|
-
"@instructure/emotion": "
|
|
39
|
-
"@instructure/shared-types": "
|
|
40
|
-
"@instructure/ui-a11y-content": "
|
|
41
|
-
"@instructure/ui-icons": "
|
|
42
|
-
"@instructure/ui-
|
|
43
|
-
"@instructure/ui-
|
|
44
|
-
"@instructure/ui-
|
|
45
|
-
"@instructure/ui-
|
|
46
|
-
"@instructure/ui-utils": "10.26.1",
|
|
47
|
-
"@instructure/ui-view": "10.26.1",
|
|
48
|
-
"prop-types": "^15.8.1"
|
|
37
|
+
"@instructure/console": "11.0.0",
|
|
38
|
+
"@instructure/emotion": "11.0.0",
|
|
39
|
+
"@instructure/shared-types": "11.0.0",
|
|
40
|
+
"@instructure/ui-a11y-content": "11.0.0",
|
|
41
|
+
"@instructure/ui-icons": "11.0.0",
|
|
42
|
+
"@instructure/ui-react-utils": "11.0.0",
|
|
43
|
+
"@instructure/ui-simple-select": "11.0.0",
|
|
44
|
+
"@instructure/ui-utils": "11.0.0",
|
|
45
|
+
"@instructure/ui-view": "11.0.0"
|
|
49
46
|
},
|
|
50
47
|
"peerDependencies": {
|
|
51
|
-
"react": ">=
|
|
48
|
+
"react": ">=18 <=19"
|
|
52
49
|
},
|
|
53
50
|
"publishConfig": {
|
|
54
51
|
"access": "public"
|
package/src/Table/Body/index.tsx
CHANGED
|
@@ -22,7 +22,13 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
Component,
|
|
27
|
+
Children,
|
|
28
|
+
ContextType,
|
|
29
|
+
isValidElement,
|
|
30
|
+
type ReactElement
|
|
31
|
+
} from 'react'
|
|
26
32
|
|
|
27
33
|
import { safeCloneElement, omitProps } from '@instructure/ui-react-utils'
|
|
28
34
|
import { View } from '@instructure/ui-view'
|
|
@@ -31,7 +37,7 @@ import { withStyle } from '@instructure/emotion'
|
|
|
31
37
|
import generateStyle from './styles'
|
|
32
38
|
import generateComponentTheme from './theme'
|
|
33
39
|
import type { TableBodyProps } from './props'
|
|
34
|
-
import { allowedProps
|
|
40
|
+
import { allowedProps } from './props'
|
|
35
41
|
import TableContext from '../TableContext'
|
|
36
42
|
|
|
37
43
|
/**
|
|
@@ -46,7 +52,6 @@ class Body extends Component<TableBodyProps> {
|
|
|
46
52
|
static contextType = TableContext
|
|
47
53
|
declare context: ContextType<typeof TableContext>
|
|
48
54
|
static allowedProps = allowedProps
|
|
49
|
-
static propTypes = propTypes
|
|
50
55
|
static defaultProps = {
|
|
51
56
|
children: null
|
|
52
57
|
}
|
|
@@ -61,7 +66,7 @@ class Body extends Component<TableBodyProps> {
|
|
|
61
66
|
|
|
62
67
|
render() {
|
|
63
68
|
const { children, styles } = this.props
|
|
64
|
-
const { isStacked
|
|
69
|
+
const { isStacked } = this.context
|
|
65
70
|
|
|
66
71
|
return (
|
|
67
72
|
<View
|
|
@@ -73,16 +78,7 @@ class Body extends Component<TableBodyProps> {
|
|
|
73
78
|
{Children.map(children, (child) => {
|
|
74
79
|
if (isValidElement(child)) {
|
|
75
80
|
return safeCloneElement(child, {
|
|
76
|
-
key: child.props.name
|
|
77
|
-
// Sent down for compatibility with custom components
|
|
78
|
-
// TODO DEPRECATED, remove in v11
|
|
79
|
-
hover,
|
|
80
|
-
// Sent down for compatibility with custom components
|
|
81
|
-
// TODO DEPRECATED, remove in v11
|
|
82
|
-
isStacked,
|
|
83
|
-
// Sent down for compatibility with custom components
|
|
84
|
-
// TODO DEPRECATED, remove in v11
|
|
85
|
-
headers
|
|
81
|
+
key: (child as ReactElement<any>).props.name
|
|
86
82
|
})
|
|
87
83
|
}
|
|
88
84
|
return child
|
package/src/Table/Body/props.ts
CHANGED
|
@@ -22,11 +22,8 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
import React from 'react'
|
|
25
|
-
import PropTypes from 'prop-types'
|
|
26
|
-
|
|
27
25
|
import type {
|
|
28
26
|
OtherHTMLAttributes,
|
|
29
|
-
PropValidators,
|
|
30
27
|
TableBodyTheme
|
|
31
28
|
} from '@instructure/shared-types'
|
|
32
29
|
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
@@ -50,12 +47,7 @@ type TableBodyProps = TableBodyOwnProps &
|
|
|
50
47
|
OtherHTMLAttributes<TableBodyOwnProps>
|
|
51
48
|
|
|
52
49
|
type TableBodyStyle = ComponentStyle<'body'>
|
|
53
|
-
|
|
54
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
55
|
-
children: PropTypes.node
|
|
56
|
-
}
|
|
57
|
-
|
|
58
50
|
const allowedProps: AllowedPropKeys = ['children']
|
|
59
51
|
|
|
60
52
|
export type { TableBodyProps, TableBodyStyle }
|
|
61
|
-
export {
|
|
53
|
+
export { allowedProps }
|
package/src/Table/Cell/index.tsx
CHANGED
|
@@ -32,7 +32,7 @@ import { withStyle } from '@instructure/emotion'
|
|
|
32
32
|
import generateStyle from './styles'
|
|
33
33
|
import generateComponentTheme from './theme'
|
|
34
34
|
import type { TableCellProps } from './props'
|
|
35
|
-
import { allowedProps
|
|
35
|
+
import { allowedProps } from './props'
|
|
36
36
|
import TableContext from '../TableContext'
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -47,7 +47,6 @@ class Cell extends Component<TableCellProps> {
|
|
|
47
47
|
static contextType = TableContext
|
|
48
48
|
declare context: ContextType<typeof TableContext>
|
|
49
49
|
static allowedProps = allowedProps
|
|
50
|
-
static propTypes = propTypes
|
|
51
50
|
|
|
52
51
|
static defaultProps = {
|
|
53
52
|
textAlign: 'start',
|
package/src/Table/Cell/props.ts
CHANGED
|
@@ -22,12 +22,9 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import PropTypes from 'prop-types'
|
|
26
|
-
|
|
27
25
|
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
28
26
|
import type {
|
|
29
27
|
OtherHTMLAttributes,
|
|
30
|
-
PropValidators,
|
|
31
28
|
Renderable,
|
|
32
29
|
TableCellTheme
|
|
33
30
|
} from '@instructure/shared-types'
|
|
@@ -55,14 +52,7 @@ type TableCellProps = TableCellOwnProps &
|
|
|
55
52
|
OtherHTMLAttributes<TableCellOwnProps>
|
|
56
53
|
|
|
57
54
|
type TableCellStyle = ComponentStyle<'cell'>
|
|
58
|
-
|
|
59
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
60
|
-
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
61
|
-
header: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
62
|
-
textAlign: PropTypes.oneOf(['start', 'center', 'end'])
|
|
63
|
-
}
|
|
64
|
-
|
|
65
55
|
const allowedProps: AllowedPropKeys = ['children', 'header', 'textAlign']
|
|
66
56
|
|
|
67
57
|
export type { TableCellProps, TableCellStyle }
|
|
68
|
-
export {
|
|
58
|
+
export { allowedProps }
|
|
@@ -36,7 +36,7 @@ import { withStyle } from '@instructure/emotion'
|
|
|
36
36
|
import generateStyle from './styles'
|
|
37
37
|
import generateComponentTheme from './theme'
|
|
38
38
|
import type { TableColHeaderProps } from './props'
|
|
39
|
-
import { allowedProps
|
|
39
|
+
import { allowedProps } from './props'
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
---
|
|
@@ -49,7 +49,6 @@ class ColHeader extends Component<TableColHeaderProps> {
|
|
|
49
49
|
static readonly componentId = 'Table.ColHeader'
|
|
50
50
|
|
|
51
51
|
static allowedProps = allowedProps
|
|
52
|
-
static propTypes = propTypes
|
|
53
52
|
|
|
54
53
|
static defaultProps = {
|
|
55
54
|
textAlign: 'start',
|
|
@@ -22,20 +22,14 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
import { ThHTMLAttributes } from 'react'
|
|
25
|
-
import PropTypes from 'prop-types'
|
|
26
25
|
|
|
27
26
|
import type {
|
|
28
27
|
OtherHTMLAttributes,
|
|
29
|
-
PropValidators,
|
|
30
28
|
TableColHeaderTheme
|
|
31
29
|
} from '@instructure/shared-types'
|
|
32
30
|
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
33
31
|
|
|
34
32
|
type TableColHeaderOwnProps = {
|
|
35
|
-
/**
|
|
36
|
-
* DEPRECATED. Use `TableContext` to read this value
|
|
37
|
-
*/
|
|
38
|
-
isStacked?: boolean
|
|
39
33
|
/**
|
|
40
34
|
* A unique id for this column. The `id` is also used as option in combobox,
|
|
41
35
|
* when sortable table is in stacked layout,
|
|
@@ -91,22 +85,8 @@ type TableColHeaderStyle = ComponentStyle<
|
|
|
91
85
|
| 'unSortedIconColor'
|
|
92
86
|
| 'sortedIconColor'
|
|
93
87
|
>
|
|
94
|
-
|
|
95
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
96
|
-
isStacked: PropTypes.bool,
|
|
97
|
-
id: PropTypes.string.isRequired,
|
|
98
|
-
stackedSortByLabel: PropTypes.string,
|
|
99
|
-
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
100
|
-
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
101
|
-
textAlign: PropTypes.oneOf(['start', 'center', 'end']),
|
|
102
|
-
sortDirection: PropTypes.oneOf(['none', 'ascending', 'descending']),
|
|
103
|
-
onRequestSort: PropTypes.func,
|
|
104
|
-
scope: PropTypes.oneOf(['row', 'col', 'rowgroup', 'colgroup', 'auto'])
|
|
105
|
-
}
|
|
106
|
-
|
|
107
88
|
const allowedProps: AllowedPropKeys = [
|
|
108
89
|
'id',
|
|
109
|
-
'isStacked',
|
|
110
90
|
'stackedSortByLabel',
|
|
111
91
|
'children',
|
|
112
92
|
'width',
|
|
@@ -117,4 +97,4 @@ const allowedProps: AllowedPropKeys = [
|
|
|
117
97
|
]
|
|
118
98
|
|
|
119
99
|
export type { TableColHeaderProps, TableColHeaderStyle }
|
|
120
|
-
export {
|
|
100
|
+
export { allowedProps }
|
package/src/Table/Head/index.tsx
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import { Component, Children, ContextType } from 'react'
|
|
25
|
+
import { Component, Children, ContextType, type ReactElement } from 'react'
|
|
26
26
|
|
|
27
27
|
import { omitProps, callRenderProp } from '@instructure/ui-react-utils'
|
|
28
28
|
import { SimpleSelect } from '@instructure/ui-simple-select'
|
|
@@ -39,7 +39,7 @@ import generateComponentTheme from './theme'
|
|
|
39
39
|
import type { TableColHeaderProps } from '../ColHeader/props'
|
|
40
40
|
import type { TableHeadProps } from './props'
|
|
41
41
|
import type { RowChild } from '../props'
|
|
42
|
-
import { allowedProps
|
|
42
|
+
import { allowedProps } from './props'
|
|
43
43
|
import TableContext from '../TableContext'
|
|
44
44
|
|
|
45
45
|
/**
|
|
@@ -54,7 +54,6 @@ class Head extends Component<TableHeadProps> {
|
|
|
54
54
|
static contextType = TableContext
|
|
55
55
|
declare context: ContextType<typeof TableContext>
|
|
56
56
|
static allowedProps = allowedProps
|
|
57
|
-
static propTypes = propTypes
|
|
58
57
|
static defaultProps = {
|
|
59
58
|
children: null
|
|
60
59
|
}
|
|
@@ -66,12 +65,15 @@ class Head extends Component<TableHeadProps> {
|
|
|
66
65
|
const [firstRow] = Children.toArray(this.props.children) as RowChild[]
|
|
67
66
|
let sortable = false
|
|
68
67
|
if (firstRow && firstRow.props && firstRow.props.children) {
|
|
69
|
-
Children.forEach(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
Children.forEach(
|
|
69
|
+
firstRow.props.children,
|
|
70
|
+
(grandchild: ReactElement<any>) => {
|
|
71
|
+
if (grandchild?.props?.onRequestSort) {
|
|
72
|
+
sortable = true
|
|
73
|
+
return
|
|
74
|
+
}
|
|
73
75
|
}
|
|
74
|
-
|
|
76
|
+
)
|
|
75
77
|
}
|
|
76
78
|
return sortable
|
|
77
79
|
}
|
|
@@ -115,20 +117,23 @@ class Head extends Component<TableHeadProps> {
|
|
|
115
117
|
> = {}
|
|
116
118
|
let selectedOption: TableColHeaderProps['id'] | undefined
|
|
117
119
|
let count = 0
|
|
118
|
-
Children.forEach(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
grandchild
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
120
|
+
Children.forEach(
|
|
121
|
+
firstRow.props.children,
|
|
122
|
+
(grandchild: ReactElement<any>) => {
|
|
123
|
+
count += 1
|
|
124
|
+
if (!grandchild?.props) return // grandchild can be false
|
|
125
|
+
const { id, stackedSortByLabel, sortDirection, onRequestSort } =
|
|
126
|
+
grandchild.props
|
|
127
|
+
if (id && onRequestSort) {
|
|
128
|
+
const label = stackedSortByLabel || id
|
|
129
|
+
options.push({ id, label })
|
|
130
|
+
clickHandlers[id] = onRequestSort
|
|
131
|
+
if (sortDirection !== 'none') {
|
|
132
|
+
selectedOption = id
|
|
133
|
+
}
|
|
129
134
|
}
|
|
130
135
|
}
|
|
131
|
-
|
|
136
|
+
)
|
|
132
137
|
if (!options.length) {
|
|
133
138
|
return null
|
|
134
139
|
}
|
|
@@ -179,11 +184,7 @@ class Head extends Component<TableHeadProps> {
|
|
|
179
184
|
return this.context.isStacked ? (
|
|
180
185
|
this.renderSelect()
|
|
181
186
|
) : (
|
|
182
|
-
|
|
183
|
-
<thead
|
|
184
|
-
{...omitProps(this.props, Head.allowedProps, ['hover'])}
|
|
185
|
-
css={styles?.head}
|
|
186
|
-
>
|
|
187
|
+
<thead {...omitProps(this.props, Head.allowedProps)} css={styles?.head}>
|
|
187
188
|
{children}
|
|
188
189
|
</thead>
|
|
189
190
|
)
|
package/src/Table/Head/props.ts
CHANGED
|
@@ -22,11 +22,8 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import PropTypes from 'prop-types'
|
|
26
|
-
|
|
27
25
|
import type {
|
|
28
26
|
OtherHTMLAttributes,
|
|
29
|
-
PropValidators,
|
|
30
27
|
Renderable,
|
|
31
28
|
TableHeadTheme
|
|
32
29
|
} from '@instructure/shared-types'
|
|
@@ -65,13 +62,7 @@ type TableHeadProps = TableHeadOwnProps &
|
|
|
65
62
|
OtherHTMLAttributes<TableHeadOwnProps>
|
|
66
63
|
|
|
67
64
|
type TableHeadStyle = ComponentStyle<'head'>
|
|
68
|
-
|
|
69
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
70
|
-
children: PropTypes.node,
|
|
71
|
-
renderSortLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
|
72
|
-
}
|
|
73
|
-
|
|
74
65
|
const allowedProps: AllowedPropKeys = ['children', 'renderSortLabel']
|
|
75
66
|
|
|
76
67
|
export type { TableHeadProps, TableHeadStyle }
|
|
77
|
-
export {
|
|
68
|
+
export { allowedProps }
|
package/src/Table/Row/index.tsx
CHANGED
|
@@ -22,7 +22,13 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
Component,
|
|
27
|
+
Children,
|
|
28
|
+
ContextType,
|
|
29
|
+
isValidElement,
|
|
30
|
+
type ReactElement
|
|
31
|
+
} from 'react'
|
|
26
32
|
|
|
27
33
|
import { omitProps, safeCloneElement } from '@instructure/ui-react-utils'
|
|
28
34
|
import { View } from '@instructure/ui-view'
|
|
@@ -33,7 +39,7 @@ import generateStyle from './styles'
|
|
|
33
39
|
import generateComponentTheme from './theme'
|
|
34
40
|
|
|
35
41
|
import type { TableRowProps } from './props'
|
|
36
|
-
import { allowedProps
|
|
42
|
+
import { allowedProps } from './props'
|
|
37
43
|
import TableContext from '../TableContext'
|
|
38
44
|
|
|
39
45
|
/**
|
|
@@ -48,7 +54,6 @@ class Row extends Component<TableRowProps> {
|
|
|
48
54
|
static contextType = TableContext
|
|
49
55
|
declare context: ContextType<typeof TableContext>
|
|
50
56
|
static allowedProps = allowedProps
|
|
51
|
-
static propTypes = propTypes
|
|
52
57
|
|
|
53
58
|
static defaultProps = {
|
|
54
59
|
children: null
|
|
@@ -85,10 +90,7 @@ class Row extends Component<TableRowProps> {
|
|
|
85
90
|
.map((child, index) => {
|
|
86
91
|
if (isValidElement(child)) {
|
|
87
92
|
return safeCloneElement(child, {
|
|
88
|
-
key: child.props.name,
|
|
89
|
-
// Sent down for compatibility with custom components
|
|
90
|
-
// TODO DEPRECATED, remove in v11
|
|
91
|
-
isStacked,
|
|
93
|
+
key: (child as ReactElement<any>).props.name,
|
|
92
94
|
// used by `Cell` to render its column title in `stacked` layout
|
|
93
95
|
header: headers && headers[index]
|
|
94
96
|
})
|
package/src/Table/Row/props.ts
CHANGED
|
@@ -23,11 +23,8 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import React from 'react'
|
|
26
|
-
import PropTypes from 'prop-types'
|
|
27
|
-
|
|
28
26
|
import type {
|
|
29
27
|
OtherHTMLAttributes,
|
|
30
|
-
PropValidators,
|
|
31
28
|
TableRowTheme
|
|
32
29
|
} from '@instructure/shared-types'
|
|
33
30
|
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
@@ -43,11 +40,11 @@ type TableRowOwnProps = {
|
|
|
43
40
|
* `{condition && <Table.Cell>bla<Table.Cell>}`
|
|
44
41
|
*/
|
|
45
42
|
children?:
|
|
46
|
-
| React.ReactElement
|
|
43
|
+
| React.ReactElement<any>
|
|
47
44
|
| null
|
|
48
45
|
| undefined
|
|
49
46
|
| boolean
|
|
50
|
-
| (React.ReactElement | null | undefined | boolean)[]
|
|
47
|
+
| (React.ReactElement<any> | null | undefined | boolean)[]
|
|
51
48
|
|
|
52
49
|
/**
|
|
53
50
|
* Controls the hover state of the row.
|
|
@@ -67,12 +64,7 @@ type TableRowProps = TableRowOwnProps &
|
|
|
67
64
|
|
|
68
65
|
type TableRowStyle = ComponentStyle<'row'>
|
|
69
66
|
|
|
70
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
71
|
-
children: PropTypes.node,
|
|
72
|
-
setHoverStateTo: PropTypes.bool
|
|
73
|
-
}
|
|
74
|
-
|
|
75
67
|
const allowedProps: AllowedPropKeys = ['children', 'setHoverStateTo']
|
|
76
68
|
|
|
77
69
|
export type { TableRowProps, TableRowStyle }
|
|
78
|
-
export {
|
|
70
|
+
export { allowedProps }
|
|
@@ -32,7 +32,7 @@ import { withStyle } from '@instructure/emotion'
|
|
|
32
32
|
import generateStyle from './styles'
|
|
33
33
|
import generateComponentTheme from './theme'
|
|
34
34
|
import type { TableRowHeaderProps } from './props'
|
|
35
|
-
import { allowedProps
|
|
35
|
+
import { allowedProps } from './props'
|
|
36
36
|
import TableContext from '../TableContext'
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -47,7 +47,6 @@ class RowHeader extends Component<TableRowHeaderProps> {
|
|
|
47
47
|
static contextType = TableContext
|
|
48
48
|
declare context: ContextType<typeof TableContext>
|
|
49
49
|
static allowedProps = allowedProps
|
|
50
|
-
static propTypes = propTypes
|
|
51
50
|
|
|
52
51
|
static defaultProps = {
|
|
53
52
|
textAlign: 'start',
|
|
@@ -22,11 +22,8 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import PropTypes from 'prop-types'
|
|
26
|
-
|
|
27
25
|
import type {
|
|
28
26
|
OtherHTMLAttributes,
|
|
29
|
-
PropValidators,
|
|
30
27
|
Renderable,
|
|
31
28
|
TableRowHeaderTheme
|
|
32
29
|
} from '@instructure/shared-types'
|
|
@@ -49,13 +46,7 @@ type TableRowHeaderProps = TableRowHeaderOwnProps &
|
|
|
49
46
|
OtherHTMLAttributes<TableRowHeaderOwnProps>
|
|
50
47
|
|
|
51
48
|
type TableRowHeaderStyle = ComponentStyle<'rowHeader'>
|
|
52
|
-
|
|
53
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
54
|
-
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
55
|
-
textAlign: PropTypes.oneOf(['start', 'center', 'end'])
|
|
56
|
-
}
|
|
57
|
-
|
|
58
49
|
const allowedProps: AllowedPropKeys = ['children', 'textAlign']
|
|
59
50
|
|
|
60
51
|
export type { TableRowHeaderProps, TableRowHeaderStyle }
|
|
61
|
-
export {
|
|
52
|
+
export { allowedProps }
|
package/src/Table/index.tsx
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import { Component, Children, isValidElement } from 'react'
|
|
25
|
+
import { Component, Children, isValidElement, ReactElement } from 'react'
|
|
26
26
|
|
|
27
27
|
import { safeCloneElement, omitProps } from '@instructure/ui-react-utils'
|
|
28
28
|
import { View } from '@instructure/ui-view'
|
|
@@ -42,8 +42,9 @@ import { Cell } from './Cell'
|
|
|
42
42
|
|
|
43
43
|
import type { TableProps } from './props'
|
|
44
44
|
|
|
45
|
-
import { allowedProps
|
|
45
|
+
import { allowedProps } from './props'
|
|
46
46
|
import TableContext from './TableContext'
|
|
47
|
+
import { error } from '@instructure/console'
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
50
|
---
|
|
@@ -55,7 +56,6 @@ class Table extends Component<TableProps> {
|
|
|
55
56
|
static readonly componentId = 'Table'
|
|
56
57
|
|
|
57
58
|
static allowedProps = allowedProps
|
|
58
|
-
static propTypes = propTypes
|
|
59
59
|
|
|
60
60
|
static defaultProps = {
|
|
61
61
|
children: null,
|
|
@@ -93,12 +93,17 @@ class Table extends Component<TableProps> {
|
|
|
93
93
|
getHeaders() {
|
|
94
94
|
const [headChild] = Children.toArray(this.props.children)
|
|
95
95
|
if (!headChild || !isValidElement(headChild)) return undefined
|
|
96
|
-
const [firstRow] = Children.toArray(
|
|
96
|
+
const [firstRow] = Children.toArray(
|
|
97
|
+
(headChild as ReactElement<any>).props.children
|
|
98
|
+
)
|
|
97
99
|
if (!firstRow || !isValidElement(firstRow)) return undefined
|
|
98
|
-
return Children.map(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
return Children.map(
|
|
101
|
+
(firstRow as ReactElement<any>).props.children,
|
|
102
|
+
(colHeader) => {
|
|
103
|
+
if (!isValidElement<{ children?: any }>(colHeader)) return undefined
|
|
104
|
+
return colHeader.props.children
|
|
105
|
+
}
|
|
106
|
+
)
|
|
102
107
|
}
|
|
103
108
|
|
|
104
109
|
render() {
|
|
@@ -106,6 +111,10 @@ class Table extends Component<TableProps> {
|
|
|
106
111
|
const isStacked = layout === 'stacked'
|
|
107
112
|
const headers = isStacked ? this.getHeaders() : undefined
|
|
108
113
|
|
|
114
|
+
if (!caption) {
|
|
115
|
+
error(false, `[Table] required prop caption is not set.`)
|
|
116
|
+
}
|
|
117
|
+
|
|
109
118
|
return (
|
|
110
119
|
<TableContext.Provider
|
|
111
120
|
value={{
|
|
@@ -133,7 +142,9 @@ class Table extends Component<TableProps> {
|
|
|
133
142
|
)}
|
|
134
143
|
{Children.map(children, (child) => {
|
|
135
144
|
if (isValidElement(child)) {
|
|
136
|
-
return safeCloneElement(child, {
|
|
145
|
+
return safeCloneElement(child, {
|
|
146
|
+
key: (child as ReactElement<any>).props.name
|
|
147
|
+
})
|
|
137
148
|
}
|
|
138
149
|
return child
|
|
139
150
|
})}
|
package/src/Table/props.ts
CHANGED
|
@@ -22,18 +22,12 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
import React from 'react'
|
|
25
|
-
import PropTypes from 'prop-types'
|
|
26
|
-
|
|
27
25
|
import type {
|
|
28
26
|
Spacing,
|
|
29
27
|
WithStyleProps,
|
|
30
28
|
ComponentStyle
|
|
31
29
|
} from '@instructure/emotion'
|
|
32
|
-
import type {
|
|
33
|
-
OtherHTMLAttributes,
|
|
34
|
-
PropValidators,
|
|
35
|
-
TableTheme
|
|
36
|
-
} from '@instructure/shared-types'
|
|
30
|
+
import type { OtherHTMLAttributes, TableTheme } from '@instructure/shared-types'
|
|
37
31
|
|
|
38
32
|
type RowChild = React.ReactElement<{ children: React.ReactElement }>
|
|
39
33
|
|
|
@@ -42,7 +36,7 @@ type TableOwnProps = {
|
|
|
42
36
|
* Provide a screen reader friendly description. Anything passed to this
|
|
43
37
|
* prop will be wrapped by `<ScreenReaderContent>` when it is rendered.
|
|
44
38
|
*/
|
|
45
|
-
caption
|
|
39
|
+
caption: React.ReactNode
|
|
46
40
|
/**
|
|
47
41
|
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
48
42
|
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
@@ -81,16 +75,6 @@ type TableProps = TableOwnProps &
|
|
|
81
75
|
OtherHTMLAttributes<TableOwnProps>
|
|
82
76
|
|
|
83
77
|
type TableStyle = ComponentStyle<'table'>
|
|
84
|
-
|
|
85
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
86
|
-
caption: PropTypes.node.isRequired,
|
|
87
|
-
children: PropTypes.node,
|
|
88
|
-
margin: PropTypes.string,
|
|
89
|
-
elementRef: PropTypes.func,
|
|
90
|
-
hover: PropTypes.bool,
|
|
91
|
-
layout: PropTypes.oneOf(['auto', 'fixed', 'stacked'])
|
|
92
|
-
}
|
|
93
|
-
|
|
94
78
|
const allowedProps: AllowedPropKeys = [
|
|
95
79
|
'caption',
|
|
96
80
|
'children',
|
|
@@ -106,4 +90,4 @@ export type {
|
|
|
106
90
|
// children
|
|
107
91
|
RowChild
|
|
108
92
|
}
|
|
109
|
-
export {
|
|
93
|
+
export { allowedProps }
|
package/tsconfig.build.json
CHANGED
|
@@ -16,10 +16,8 @@
|
|
|
16
16
|
{ "path": "../shared-types/tsconfig.build.json" },
|
|
17
17
|
{ "path": "../ui-a11y-content/tsconfig.build.json" },
|
|
18
18
|
{ "path": "../ui-icons/tsconfig.build.json" },
|
|
19
|
-
{ "path": "../ui-prop-types/tsconfig.build.json" },
|
|
20
19
|
{ "path": "../ui-react-utils/tsconfig.build.json" },
|
|
21
20
|
{ "path": "../ui-simple-select/tsconfig.build.json" },
|
|
22
|
-
{ "path": "../ui-testable/tsconfig.build.json" },
|
|
23
21
|
{ "path": "../ui-utils/tsconfig.build.json" },
|
|
24
22
|
{ "path": "../ui-view/tsconfig.build.json" }
|
|
25
23
|
]
|