@instructure/ui-table 8.8.1-snapshot.3 → 8.9.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 +6 -0
- package/es/Table/Body/index.js +17 -29
- package/{src/Table/Cell/types.ts → es/Table/Body/props.js} +14 -8
- package/es/Table/Cell/index.js +17 -29
- package/{src/Table/types.ts → es/Table/Cell/props.js} +12 -11
- package/es/Table/ColHeader/index.js +22 -63
- package/es/Table/ColHeader/props.js +66 -0
- package/es/Table/Head/index.js +18 -29
- package/{src/Table/Body/types.ts → es/Table/Head/props.js} +13 -8
- package/es/Table/Row/index.js +17 -29
- package/{src/Table/ColHeader/types.ts → es/Table/Row/props.js} +16 -12
- package/es/Table/RowHeader/index.js +16 -27
- package/{src/Table/Head/types.ts → es/Table/RowHeader/props.js} +11 -6
- package/es/Table/index.js +23 -62
- package/es/Table/props.js +66 -0
- package/lib/Table/Body/index.js +17 -30
- package/lib/Table/Body/props.js +50 -0
- package/lib/Table/Cell/index.js +17 -29
- package/lib/Table/Cell/props.js +47 -0
- package/lib/Table/ColHeader/index.js +22 -63
- package/lib/Table/ColHeader/props.js +77 -0
- package/lib/Table/Head/index.js +18 -30
- package/lib/Table/Head/props.js +49 -0
- package/lib/Table/Row/index.js +17 -30
- package/lib/Table/Row/props.js +54 -0
- package/lib/Table/RowHeader/index.js +16 -27
- package/lib/Table/RowHeader/props.js +46 -0
- package/lib/Table/index.js +22 -62
- package/lib/Table/props.js +81 -0
- package/package.json +17 -18
- package/src/Table/Body/index.tsx +8 -26
- package/src/Table/{Row/types.ts → Body/props.ts} +39 -3
- package/src/Table/Cell/index.tsx +9 -25
- package/src/Table/Cell/props.ts +62 -0
- package/src/Table/Cell/styles.ts +1 -1
- package/src/Table/ColHeader/index.tsx +9 -51
- package/src/Table/ColHeader/props.ts +94 -0
- package/src/Table/ColHeader/styles.ts +1 -1
- package/src/Table/Head/index.tsx +8 -24
- package/src/Table/Head/props.ts +62 -0
- package/src/Table/Row/index.tsx +9 -28
- package/src/Table/Row/props.ts +70 -0
- package/src/Table/Row/styles.ts +1 -1
- package/src/Table/RowHeader/index.tsx +9 -24
- package/src/Table/RowHeader/{types.ts → props.ts} +28 -3
- package/src/Table/RowHeader/styles.ts +1 -1
- package/src/Table/index.tsx +12 -51
- package/src/Table/props.ts +93 -0
- package/src/Table/styles.ts +1 -1
- package/src/index.ts +7 -7
- package/types/Table/Body/index.d.ts +13 -16
- package/types/Table/Body/index.d.ts.map +1 -1
- package/types/Table/Body/props.d.ts +17 -0
- package/types/Table/Body/props.d.ts.map +1 -0
- package/types/Table/Cell/index.d.ts +14 -14
- package/types/Table/Cell/index.d.ts.map +1 -1
- package/types/Table/Cell/props.d.ts +17 -0
- package/types/Table/Cell/props.d.ts.map +1 -0
- package/types/Table/Cell/styles.d.ts +1 -1
- package/types/Table/ColHeader/index.d.ts +22 -40
- package/types/Table/ColHeader/index.d.ts.map +1 -1
- package/types/Table/ColHeader/props.d.ts +21 -0
- package/types/Table/ColHeader/props.d.ts.map +1 -0
- package/types/Table/ColHeader/styles.d.ts +1 -1
- package/types/Table/Head/index.d.ts +11 -15
- package/types/Table/Head/index.d.ts.map +1 -1
- package/types/Table/Head/props.d.ts +16 -0
- package/types/Table/Head/props.d.ts.map +1 -0
- package/types/Table/Row/index.d.ts +14 -17
- package/types/Table/Row/index.d.ts.map +1 -1
- package/types/Table/Row/props.d.ts +17 -0
- package/types/Table/Row/props.d.ts.map +1 -0
- package/types/Table/Row/styles.d.ts +1 -1
- package/types/Table/RowHeader/index.d.ts +12 -13
- package/types/Table/RowHeader/index.d.ts.map +1 -1
- package/types/Table/RowHeader/props.d.ts +16 -0
- package/types/Table/RowHeader/props.d.ts.map +1 -0
- package/types/Table/RowHeader/styles.d.ts +1 -1
- package/types/Table/index.d.ts +18 -41
- package/types/Table/index.d.ts.map +1 -1
- package/types/Table/props.d.ts +19 -0
- package/types/Table/props.d.ts.map +1 -0
- package/types/Table/styles.d.ts +1 -1
- package/types/index.d.ts +7 -7
- package/LICENSE.md +0 -27
- package/es/Table/Body/types.js +0 -1
- package/es/Table/Cell/types.js +0 -1
- package/es/Table/ColHeader/types.js +0 -1
- package/es/Table/Head/types.js +0 -1
- package/es/Table/Row/types.js +0 -1
- package/es/Table/RowHeader/types.js +0 -1
- package/es/Table/types.js +0 -1
- package/lib/Table/Body/types.js +0 -1
- package/lib/Table/Cell/types.js +0 -1
- package/lib/Table/ColHeader/types.js +0 -1
- package/lib/Table/Head/types.js +0 -1
- package/lib/Table/Row/types.js +0 -1
- package/lib/Table/RowHeader/types.js +0 -1
- package/lib/Table/types.js +0 -1
- package/types/Table/Body/types.d.ts +0 -9
- package/types/Table/Body/types.d.ts.map +0 -1
- package/types/Table/Cell/types.d.ts +0 -9
- package/types/Table/Cell/types.d.ts.map +0 -1
- package/types/Table/ColHeader/types.d.ts +0 -12
- package/types/Table/ColHeader/types.d.ts.map +0 -1
- package/types/Table/Head/types.d.ts +0 -8
- package/types/Table/Head/types.d.ts.map +0 -1
- package/types/Table/Row/types.d.ts +0 -9
- package/types/Table/Row/types.d.ts.map +0 -1
- package/types/Table/RowHeader/types.d.ts +0 -7
- package/types/Table/RowHeader/types.d.ts.map +0 -1
- package/types/Table/types.d.ts +0 -12
- package/types/Table/types.d.ts.map +0 -1
@@ -0,0 +1,94 @@
|
|
1
|
+
/*
|
2
|
+
* The MIT License (MIT)
|
3
|
+
*
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
11
|
+
* furnished to do so, subject to the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
14
|
+
* copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
* SOFTWARE.
|
23
|
+
*/
|
24
|
+
import React from 'react'
|
25
|
+
import PropTypes from 'prop-types'
|
26
|
+
|
27
|
+
import type { PropValidators } from '@instructure/shared-types'
|
28
|
+
import type { WithStyleProps } from '@instructure/emotion'
|
29
|
+
|
30
|
+
type TableColHeaderOwnProps = {
|
31
|
+
id: string
|
32
|
+
stackedSortByLabel?: string
|
33
|
+
width?: string | number
|
34
|
+
textAlign?: 'start' | 'center' | 'end'
|
35
|
+
sortDirection?: 'none' | 'ascending' | 'descending'
|
36
|
+
onRequestSort?: (...args: any[]) => any
|
37
|
+
scope?: 'row' | 'col' | 'rowgroup' | 'colgroup' | 'auto'
|
38
|
+
children?: React.ReactNode | ((...args: any[]) => React.ReactNode)
|
39
|
+
}
|
40
|
+
|
41
|
+
type PropKeys = keyof TableColHeaderOwnProps
|
42
|
+
|
43
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
44
|
+
|
45
|
+
type TableColHeaderProps = TableColHeaderOwnProps & WithStyleProps
|
46
|
+
|
47
|
+
const propTypes: PropValidators<PropKeys> = {
|
48
|
+
/**
|
49
|
+
* A unique id for this column. The `id` is also used as option in combobox,
|
50
|
+
* when sortable table is in stacked layout,
|
51
|
+
* and no `stackedSortByLabel` is provided.
|
52
|
+
*/
|
53
|
+
id: PropTypes.string.isRequired,
|
54
|
+
/**
|
55
|
+
* A custom string to display as option text in the combobox (instead of
|
56
|
+
* using the `id` prop), when sortable table is in stacked layout.
|
57
|
+
*/
|
58
|
+
stackedSortByLabel: PropTypes.string,
|
59
|
+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
60
|
+
/**
|
61
|
+
* Control the width of column.
|
62
|
+
*/
|
63
|
+
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
64
|
+
/**
|
65
|
+
* Control the text alignment in column header
|
66
|
+
*/
|
67
|
+
textAlign: PropTypes.oneOf(['start', 'center', 'end']),
|
68
|
+
/**
|
69
|
+
* The string of sorting direction
|
70
|
+
*/
|
71
|
+
sortDirection: PropTypes.oneOf(['none', 'ascending', 'descending']),
|
72
|
+
/**
|
73
|
+
* Callback fired when column header is clicked. Parameters: `(event, { id })`
|
74
|
+
*/
|
75
|
+
onRequestSort: PropTypes.func,
|
76
|
+
/**
|
77
|
+
* The column header scope attribute. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th#attr-scope
|
78
|
+
*/
|
79
|
+
scope: PropTypes.oneOf(['row', 'col', 'rowgroup', 'colgroup', 'auto'])
|
80
|
+
}
|
81
|
+
|
82
|
+
const allowedProps: AllowedPropKeys = [
|
83
|
+
'id',
|
84
|
+
'stackedSortByLabel',
|
85
|
+
'children',
|
86
|
+
'width',
|
87
|
+
'textAlign',
|
88
|
+
'sortDirection',
|
89
|
+
'onRequestSort',
|
90
|
+
'scope'
|
91
|
+
]
|
92
|
+
|
93
|
+
export type { TableColHeaderProps }
|
94
|
+
export { propTypes, allowedProps }
|
package/src/Table/Head/index.tsx
CHANGED
@@ -24,14 +24,12 @@
|
|
24
24
|
|
25
25
|
/** @jsx jsx */
|
26
26
|
import { Component, Children } from 'react'
|
27
|
-
import PropTypes from 'prop-types'
|
28
27
|
|
29
28
|
import {
|
30
29
|
omitProps,
|
31
30
|
matchComponentTypes,
|
32
31
|
callRenderProp
|
33
32
|
} from '@instructure/ui-react-utils'
|
34
|
-
import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types'
|
35
33
|
import { SimpleSelect } from '@instructure/ui-simple-select'
|
36
34
|
import { ScreenReaderContent } from '@instructure/ui-a11y-content'
|
37
35
|
import { IconCheckLine } from '@instructure/ui-icons'
|
@@ -44,7 +42,8 @@ import generateComponentTheme from './theme'
|
|
44
42
|
|
45
43
|
import { Row } from '../Row'
|
46
44
|
import { ColHeader } from '../ColHeader'
|
47
|
-
import { TableHeadProps } from './
|
45
|
+
import type { TableHeadProps } from './props'
|
46
|
+
import { allowedProps, propTypes } from './props'
|
48
47
|
|
49
48
|
/**
|
50
49
|
---
|
@@ -56,20 +55,8 @@ id: Table.Head
|
|
56
55
|
class Head extends Component<TableHeadProps> {
|
57
56
|
static readonly componentId = 'Table.Head'
|
58
57
|
|
59
|
-
|
60
|
-
static propTypes =
|
61
|
-
/**
|
62
|
-
* `Table.Row`
|
63
|
-
*/
|
64
|
-
// eslint-disable-next-line react/require-default-props
|
65
|
-
makeStyles: PropTypes.func,
|
66
|
-
// eslint-disable-next-line react/require-default-props
|
67
|
-
styles: PropTypes.object,
|
68
|
-
children: ChildrenPropTypes.oneOf([Row]),
|
69
|
-
isStacked: PropTypes.bool,
|
70
|
-
renderSortLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
71
|
-
}
|
72
|
-
/* eslint-enable react/require-default-props */
|
58
|
+
static allowedProps = allowedProps
|
59
|
+
static propTypes = propTypes
|
73
60
|
|
74
61
|
static defaultProps = {
|
75
62
|
children: null
|
@@ -92,8 +79,7 @@ class Head extends Component<TableHeadProps> {
|
|
92
79
|
}
|
93
80
|
|
94
81
|
componentDidMount() {
|
95
|
-
|
96
|
-
this.props.makeStyles()
|
82
|
+
this.props.makeStyles?.()
|
97
83
|
}
|
98
84
|
|
99
85
|
componentDidUpdate() {
|
@@ -103,8 +89,7 @@ class Head extends Component<TableHeadProps> {
|
|
103
89
|
'[Table.Head] The `renderSortLabel` prop should be provided when Table is sortable.'
|
104
90
|
)
|
105
91
|
}
|
106
|
-
|
107
|
-
this.props.makeStyles()
|
92
|
+
this.props.makeStyles?.()
|
108
93
|
}
|
109
94
|
|
110
95
|
renderSelect() {
|
@@ -118,7 +103,7 @@ class Head extends Component<TableHeadProps> {
|
|
118
103
|
const options = []
|
119
104
|
const clickHandlers = {}
|
120
105
|
// @ts-expect-error ts-migrate(7034) FIXME: Variable 'selectedOption' implicitly has type 'any... Remove this comment to see the full error message
|
121
|
-
let selectedOption =
|
106
|
+
let selectedOption = undefined
|
122
107
|
let count = 0
|
123
108
|
|
124
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
|
@@ -165,7 +150,6 @@ class Head extends Component<TableHeadProps> {
|
|
165
150
|
)
|
166
151
|
}
|
167
152
|
renderBeforeInput={selectedOption && IconCheckLine}
|
168
|
-
// @ts-expect-error FIXME: Type 'null' is not assignable to type 'string | number | undefined'.ts(2322)
|
169
153
|
value={selectedOption}
|
170
154
|
onChange={handleSelect}
|
171
155
|
>
|
@@ -198,7 +182,7 @@ class Head extends Component<TableHeadProps> {
|
|
198
182
|
return isStacked ? (
|
199
183
|
this.renderSelect()
|
200
184
|
) : (
|
201
|
-
<thead {...omitProps(this.props, Head.propTypes)} css={styles
|
185
|
+
<thead {...omitProps(this.props, Head.propTypes)} css={styles?.head}>
|
202
186
|
{Children.map(children, (child) =>
|
203
187
|
matchComponentTypes(child, [Row]) ? child : null
|
204
188
|
)}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
/*
|
2
|
+
* The MIT License (MIT)
|
3
|
+
*
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
11
|
+
* furnished to do so, subject to the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
14
|
+
* copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
* SOFTWARE.
|
23
|
+
*/
|
24
|
+
|
25
|
+
import React from 'react'
|
26
|
+
import PropTypes from 'prop-types'
|
27
|
+
|
28
|
+
import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types'
|
29
|
+
|
30
|
+
import { Row } from '../Row'
|
31
|
+
|
32
|
+
import type { PropValidators } from '@instructure/shared-types'
|
33
|
+
import type { WithStyleProps } from '@instructure/emotion'
|
34
|
+
|
35
|
+
type TableHeadOwnProps = {
|
36
|
+
isStacked?: boolean
|
37
|
+
renderSortLabel?: React.ReactNode | ((...args: any[]) => any)
|
38
|
+
children?: React.ReactNode
|
39
|
+
}
|
40
|
+
type PropKeys = keyof TableHeadOwnProps
|
41
|
+
|
42
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
43
|
+
|
44
|
+
type TableHeadProps = TableHeadOwnProps & WithStyleProps
|
45
|
+
|
46
|
+
const propTypes: PropValidators<PropKeys> = {
|
47
|
+
/**
|
48
|
+
* `Table.Row`
|
49
|
+
*/
|
50
|
+
children: ChildrenPropTypes.oneOf([Row]),
|
51
|
+
isStacked: PropTypes.bool,
|
52
|
+
renderSortLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
53
|
+
}
|
54
|
+
|
55
|
+
const allowedProps: AllowedPropKeys = [
|
56
|
+
'children',
|
57
|
+
'isStacked',
|
58
|
+
'renderSortLabel'
|
59
|
+
]
|
60
|
+
|
61
|
+
export type { TableHeadProps }
|
62
|
+
export { propTypes, allowedProps }
|
package/src/Table/Row/index.tsx
CHANGED
@@ -24,14 +24,12 @@
|
|
24
24
|
|
25
25
|
/** @jsx jsx */
|
26
26
|
import { Component, Children, ReactElement } from 'react'
|
27
|
-
import PropTypes from 'prop-types'
|
28
27
|
|
29
28
|
import {
|
30
29
|
omitProps,
|
31
30
|
matchComponentTypes,
|
32
31
|
safeCloneElement
|
33
32
|
} from '@instructure/ui-react-utils'
|
34
|
-
import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types'
|
35
33
|
import { View } from '@instructure/ui-view'
|
36
34
|
|
37
35
|
import { withStyle, jsx } from '@instructure/emotion'
|
@@ -42,7 +40,8 @@ import generateComponentTheme from './theme'
|
|
42
40
|
import { ColHeader } from '../ColHeader'
|
43
41
|
import { RowHeader } from '../RowHeader'
|
44
42
|
import { Cell } from '../Cell'
|
45
|
-
import { TableRowProps } from './
|
43
|
+
import type { TableRowProps } from './props'
|
44
|
+
import { allowedProps, propTypes } from './props'
|
46
45
|
|
47
46
|
/**
|
48
47
|
---
|
@@ -54,37 +53,19 @@ id: Table.Row
|
|
54
53
|
class Row extends Component<TableRowProps> {
|
55
54
|
static readonly componentId = 'Table.Row'
|
56
55
|
|
57
|
-
|
58
|
-
static propTypes =
|
59
|
-
/**
|
60
|
-
* `Table.ColHeader`, `Table.RowHeader` or `Table.Cell`
|
61
|
-
*/
|
62
|
-
// eslint-disable-next-line react/require-default-props
|
63
|
-
makeStyles: PropTypes.func,
|
64
|
-
// eslint-disable-next-line react/require-default-props
|
65
|
-
styles: PropTypes.object,
|
66
|
-
children: ChildrenPropTypes.oneOf([ColHeader, RowHeader, Cell]),
|
67
|
-
hover: PropTypes.bool,
|
68
|
-
isStacked: PropTypes.bool,
|
69
|
-
headers: PropTypes.arrayOf(
|
70
|
-
PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
71
|
-
)
|
72
|
-
}
|
73
|
-
/* eslint-enable react/require-default-props */
|
56
|
+
static allowedProps = allowedProps
|
57
|
+
static propTypes = propTypes
|
74
58
|
|
75
59
|
static defaultProps = {
|
76
60
|
children: null
|
77
61
|
}
|
78
62
|
|
79
63
|
componentDidMount() {
|
80
|
-
|
81
|
-
this.props.makeStyles()
|
64
|
+
this.props.makeStyles?.()
|
82
65
|
}
|
83
66
|
|
84
|
-
|
85
|
-
|
86
|
-
// @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
|
87
|
-
this.props.makeStyles()
|
67
|
+
componentDidUpdate() {
|
68
|
+
this.props.makeStyles?.()
|
88
69
|
}
|
89
70
|
|
90
71
|
render() {
|
@@ -94,8 +75,8 @@ class Row extends Component<TableRowProps> {
|
|
94
75
|
<View
|
95
76
|
{...View.omitViewProps(omitProps(this.props, Row.propTypes), Row)}
|
96
77
|
as={isStacked ? 'div' : 'tr'}
|
97
|
-
css={styles
|
98
|
-
role={isStacked ? 'row' :
|
78
|
+
css={styles?.row}
|
79
|
+
role={isStacked ? 'row' : undefined}
|
99
80
|
>
|
100
81
|
{Children.toArray(children)
|
101
82
|
.filter(Boolean)
|
@@ -0,0 +1,70 @@
|
|
1
|
+
/*
|
2
|
+
* The MIT License (MIT)
|
3
|
+
*
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
11
|
+
* furnished to do so, subject to the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
14
|
+
* copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
* SOFTWARE.
|
23
|
+
*/
|
24
|
+
|
25
|
+
import React from 'react'
|
26
|
+
import PropTypes from 'prop-types'
|
27
|
+
|
28
|
+
import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types'
|
29
|
+
|
30
|
+
import { ColHeader } from '../ColHeader'
|
31
|
+
import { RowHeader } from '../RowHeader'
|
32
|
+
import { Cell } from '../Cell'
|
33
|
+
|
34
|
+
import type { PropValidators } from '@instructure/shared-types'
|
35
|
+
import type { WithStyleProps } from '@instructure/emotion'
|
36
|
+
|
37
|
+
type TableRowOwnProps = {
|
38
|
+
hover?: boolean
|
39
|
+
isStacked?: boolean
|
40
|
+
headers?: (React.ReactNode | ((...args: any[]) => any))[]
|
41
|
+
children?: React.ReactNode
|
42
|
+
}
|
43
|
+
|
44
|
+
type PropKeys = keyof TableRowOwnProps
|
45
|
+
|
46
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
47
|
+
|
48
|
+
type TableRowProps = TableRowOwnProps & WithStyleProps
|
49
|
+
|
50
|
+
const propTypes: PropValidators<PropKeys> = {
|
51
|
+
/**
|
52
|
+
* `Table.ColHeader`, `Table.RowHeader` or `Table.Cell`
|
53
|
+
*/
|
54
|
+
children: ChildrenPropTypes.oneOf([ColHeader, RowHeader, Cell]),
|
55
|
+
hover: PropTypes.bool,
|
56
|
+
isStacked: PropTypes.bool,
|
57
|
+
headers: PropTypes.arrayOf(
|
58
|
+
PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
59
|
+
)
|
60
|
+
}
|
61
|
+
|
62
|
+
const allowedProps: AllowedPropKeys = [
|
63
|
+
'children',
|
64
|
+
'hover',
|
65
|
+
'isStacked',
|
66
|
+
'headers'
|
67
|
+
]
|
68
|
+
|
69
|
+
export type { TableRowProps }
|
70
|
+
export { propTypes, allowedProps }
|
package/src/Table/Row/styles.ts
CHANGED
@@ -24,7 +24,6 @@
|
|
24
24
|
|
25
25
|
/** @jsx jsx */
|
26
26
|
import { Component } from 'react'
|
27
|
-
import PropTypes from 'prop-types'
|
28
27
|
|
29
28
|
import { omitProps, callRenderProp } from '@instructure/ui-react-utils'
|
30
29
|
import { View } from '@instructure/ui-view'
|
@@ -33,7 +32,8 @@ import { withStyle, jsx } from '@instructure/emotion'
|
|
33
32
|
|
34
33
|
import generateStyle from './styles'
|
35
34
|
import generateComponentTheme from './theme'
|
36
|
-
import { TableRowHeaderProps } from './
|
35
|
+
import type { TableRowHeaderProps } from './props'
|
36
|
+
import { allowedProps, propTypes } from './props'
|
37
37
|
|
38
38
|
/**
|
39
39
|
---
|
@@ -45,20 +45,8 @@ id: Table.RowHeader
|
|
45
45
|
class RowHeader extends Component<TableRowHeaderProps> {
|
46
46
|
static readonly componentId = 'Table.RowHeader'
|
47
47
|
|
48
|
-
|
49
|
-
static propTypes =
|
50
|
-
// eslint-disable-next-line react/require-default-props
|
51
|
-
makeStyles: PropTypes.func,
|
52
|
-
// eslint-disable-next-line react/require-default-props
|
53
|
-
styles: PropTypes.object,
|
54
|
-
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
55
|
-
isStacked: PropTypes.bool,
|
56
|
-
/**
|
57
|
-
* Control the text alignment in row header
|
58
|
-
*/
|
59
|
-
textAlign: PropTypes.oneOf(['start', 'center', 'end'])
|
60
|
-
}
|
61
|
-
/* eslint-enable react/require-default-props */
|
48
|
+
static allowedProps = allowedProps
|
49
|
+
static propTypes = propTypes
|
62
50
|
|
63
51
|
static defaultProps = {
|
64
52
|
textAlign: 'start',
|
@@ -66,14 +54,11 @@ class RowHeader extends Component<TableRowHeaderProps> {
|
|
66
54
|
}
|
67
55
|
|
68
56
|
componentDidMount() {
|
69
|
-
|
70
|
-
this.props.makeStyles()
|
57
|
+
this.props.makeStyles?.()
|
71
58
|
}
|
72
59
|
|
73
|
-
|
74
|
-
|
75
|
-
// @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
|
76
|
-
this.props.makeStyles()
|
60
|
+
componentDidUpdate() {
|
61
|
+
this.props.makeStyles?.()
|
77
62
|
}
|
78
63
|
|
79
64
|
render() {
|
@@ -86,9 +71,9 @@ class RowHeader extends Component<TableRowHeaderProps> {
|
|
86
71
|
RowHeader
|
87
72
|
)}
|
88
73
|
as={isStacked ? 'div' : 'th'}
|
89
|
-
css={styles
|
74
|
+
css={styles?.rowHeader}
|
90
75
|
scope="row"
|
91
|
-
role={isStacked ? 'rowheader' :
|
76
|
+
role={isStacked ? 'rowheader' : undefined}
|
92
77
|
>
|
93
78
|
{callRenderProp(children)}
|
94
79
|
</View>
|