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