@instructure/ui-table 8.8.1-snapshot.8 → 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 +16 -28
- package/{src/Table/Cell/types.ts → es/Table/Body/props.js} +14 -8
- package/es/Table/Cell/index.js +16 -28
- 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 +16 -28
- package/{src/Table/ColHeader/types.ts → es/Table/Row/props.js} +16 -12
- package/es/Table/RowHeader/index.js +15 -26
- package/{src/Table/Head/types.ts → es/Table/RowHeader/props.js} +11 -6
- package/es/Table/index.js +21 -60
- package/es/Table/props.js +66 -0
- package/lib/Table/Body/index.js +16 -29
- package/lib/Table/Body/props.js +50 -0
- package/lib/Table/Cell/index.js +16 -28
- 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 +16 -29
- package/lib/Table/Row/props.js +54 -0
- package/lib/Table/RowHeader/index.js +15 -26
- package/lib/Table/RowHeader/props.js +46 -0
- package/lib/Table/index.js +20 -60
- package/lib/Table/props.js +81 -0
- package/package.json +17 -18
- package/src/Table/Body/index.tsx +7 -25
- package/src/Table/{Row/types.ts → Body/props.ts} +39 -3
- package/src/Table/Cell/index.tsx +8 -24
- 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 +8 -27
- package/src/Table/Row/props.ts +70 -0
- package/src/Table/Row/styles.ts +1 -1
- package/src/Table/RowHeader/index.tsx +8 -23
- package/src/Table/RowHeader/{types.ts → props.ts} +28 -3
- package/src/Table/RowHeader/styles.ts +1 -1
- package/src/Table/index.tsx +10 -49
- 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
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instructure/ui-table",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.9.0",
|
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.9.0",
|
28
|
+
"@instructure/ui-color-utils": "8.9.0",
|
29
|
+
"@instructure/ui-test-utils": "8.9.0",
|
30
|
+
"@instructure/ui-themes": "8.9.0"
|
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.9.0",
|
35
|
+
"@instructure/emotion": "8.9.0",
|
36
|
+
"@instructure/shared-types": "8.9.0",
|
37
|
+
"@instructure/ui-a11y-content": "8.9.0",
|
38
|
+
"@instructure/ui-icons": "8.9.0",
|
39
|
+
"@instructure/ui-prop-types": "8.9.0",
|
40
|
+
"@instructure/ui-react-utils": "8.9.0",
|
41
|
+
"@instructure/ui-simple-select": "8.9.0",
|
42
|
+
"@instructure/ui-testable": "8.9.0",
|
43
|
+
"@instructure/ui-utils": "8.9.0",
|
44
|
+
"@instructure/ui-view": "8.9.0",
|
45
45
|
"prop-types": "^15"
|
46
46
|
},
|
47
47
|
"peerDependencies": {
|
@@ -50,6 +50,5 @@
|
|
50
50
|
"publishConfig": {
|
51
51
|
"access": "public"
|
52
52
|
},
|
53
|
-
"sideEffects": false
|
54
|
-
"gitHead": "7b83164f4c5872f3a217e010563f59bf584ae4fc"
|
53
|
+
"sideEffects": false
|
55
54
|
}
|
package/src/Table/Body/index.tsx
CHANGED
@@ -24,21 +24,20 @@
|
|
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
|
matchComponentTypes,
|
31
30
|
safeCloneElement,
|
32
31
|
omitProps
|
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
|
import { withStyle, jsx } from '@instructure/emotion'
|
37
35
|
|
38
36
|
import generateStyle from './styles'
|
39
37
|
import generateComponentTheme from './theme'
|
40
38
|
import { Row } from '../Row'
|
41
|
-
import { TableBodyProps } from './
|
39
|
+
import type { TableBodyProps } from './props'
|
40
|
+
import { allowedProps, propTypes } from './props'
|
42
41
|
|
43
42
|
/**
|
44
43
|
---
|
@@ -50,37 +49,20 @@ id: Table.Body
|
|
50
49
|
class Body extends Component<TableBodyProps> {
|
51
50
|
static readonly componentId = 'Table.Body'
|
52
51
|
|
53
|
-
|
54
|
-
static propTypes =
|
55
|
-
/**
|
56
|
-
* `Table.Row`
|
57
|
-
*/
|
58
|
-
// eslint-disable-next-line react/require-default-props
|
59
|
-
makeStyles: PropTypes.func,
|
60
|
-
// eslint-disable-next-line react/require-default-props
|
61
|
-
styles: PropTypes.object,
|
62
|
-
children: ChildrenPropTypes.oneOf([Row]),
|
63
|
-
hover: PropTypes.bool,
|
64
|
-
isStacked: PropTypes.bool,
|
65
|
-
headers: PropTypes.arrayOf(
|
66
|
-
PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
67
|
-
)
|
68
|
-
}
|
69
|
-
/* eslint-enable react/require-default-props */
|
52
|
+
static allowedProps = allowedProps
|
53
|
+
static propTypes = propTypes
|
70
54
|
|
71
55
|
static defaultProps = {
|
72
56
|
children: null
|
73
57
|
}
|
74
58
|
|
75
59
|
componentDidMount() {
|
76
|
-
|
77
|
-
this.props.makeStyles()
|
60
|
+
this.props.makeStyles?.()
|
78
61
|
}
|
79
62
|
|
80
63
|
// @ts-expect-error ts-migrate(6133) FIXME: 'prevProps' is declared but its value is never rea... Remove this comment to see the full error message
|
81
64
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
82
|
-
|
83
|
-
this.props.makeStyles()
|
65
|
+
this.props.makeStyles?.()
|
84
66
|
}
|
85
67
|
|
86
68
|
render() {
|
@@ -90,7 +72,7 @@ class Body extends Component<TableBodyProps> {
|
|
90
72
|
<View
|
91
73
|
{...View.omitViewProps(omitProps(this.props, Body.propTypes), Body)}
|
92
74
|
as={isStacked ? 'div' : 'tbody'}
|
93
|
-
css={styles
|
75
|
+
css={styles?.body}
|
94
76
|
role={isStacked ? 'rowgroup' : undefined}
|
95
77
|
>
|
96
78
|
{Children.map(children, (child) =>
|
@@ -21,11 +21,47 @@
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
22
|
* SOFTWARE.
|
23
23
|
*/
|
24
|
+
import React from 'react'
|
25
|
+
import PropTypes from 'prop-types'
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types'
|
28
|
+
|
29
|
+
import { Row } from '../Row'
|
30
|
+
|
31
|
+
import type { PropValidators } from '@instructure/shared-types'
|
32
|
+
import type { WithStyleProps } from '@instructure/emotion'
|
33
|
+
|
34
|
+
type TableBodyOwnProps = {
|
28
35
|
hover?: boolean
|
29
36
|
isStacked?: boolean
|
30
37
|
headers?: (React.ReactNode | ((...args: any[]) => any))[]
|
38
|
+
children?: React.ReactNode
|
39
|
+
}
|
40
|
+
|
41
|
+
type PropKeys = keyof TableBodyOwnProps
|
42
|
+
|
43
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
44
|
+
|
45
|
+
type TableBodyProps = TableBodyOwnProps & WithStyleProps
|
46
|
+
|
47
|
+
const propTypes: PropValidators<PropKeys> = {
|
48
|
+
/**
|
49
|
+
* `Table.Row`
|
50
|
+
*/
|
51
|
+
children: ChildrenPropTypes.oneOf([Row]),
|
52
|
+
hover: PropTypes.bool,
|
53
|
+
isStacked: PropTypes.bool,
|
54
|
+
headers: PropTypes.arrayOf(
|
55
|
+
PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
56
|
+
)
|
31
57
|
}
|
58
|
+
|
59
|
+
const allowedProps: AllowedPropKeys = [
|
60
|
+
'children',
|
61
|
+
'hover',
|
62
|
+
'isStacked',
|
63
|
+
'headers'
|
64
|
+
]
|
65
|
+
|
66
|
+
export type { TableBodyProps }
|
67
|
+
export { propTypes, allowedProps }
|
package/src/Table/Cell/index.tsx
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 { TableCellProps } from './
|
35
|
+
import type { TableCellProps } from './props'
|
36
|
+
import { allowedProps, propTypes } from './props'
|
37
37
|
|
38
38
|
/**
|
39
39
|
---
|
@@ -45,21 +45,8 @@ id: Table.Cell
|
|
45
45
|
class Cell extends Component<TableCellProps> {
|
46
46
|
static readonly componentId = 'Table.Cell'
|
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
|
-
header: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
57
|
-
/**
|
58
|
-
* Control the text alignment in cell
|
59
|
-
*/
|
60
|
-
textAlign: PropTypes.oneOf(['start', 'center', 'end'])
|
61
|
-
}
|
62
|
-
/* eslint-enable react/require-default-props */
|
48
|
+
static allowedProps = allowedProps
|
49
|
+
static propTypes = propTypes
|
63
50
|
|
64
51
|
static defaultProps = {
|
65
52
|
textAlign: 'start',
|
@@ -67,14 +54,11 @@ class Cell extends Component<TableCellProps> {
|
|
67
54
|
}
|
68
55
|
|
69
56
|
componentDidMount() {
|
70
|
-
|
71
|
-
this.props.makeStyles()
|
57
|
+
this.props.makeStyles?.()
|
72
58
|
}
|
73
59
|
|
74
|
-
|
75
|
-
|
76
|
-
// @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
|
77
|
-
this.props.makeStyles()
|
60
|
+
componentDidUpdate() {
|
61
|
+
this.props.makeStyles?.()
|
78
62
|
}
|
79
63
|
|
80
64
|
render() {
|
@@ -84,7 +68,7 @@ class Cell extends Component<TableCellProps> {
|
|
84
68
|
<View
|
85
69
|
{...View.omitViewProps(omitProps(this.props, Cell.propTypes), Cell)}
|
86
70
|
as={isStacked ? 'div' : 'td'}
|
87
|
-
css={styles
|
71
|
+
css={styles?.cell}
|
88
72
|
role={isStacked ? 'cell' : undefined}
|
89
73
|
>
|
90
74
|
{header && callRenderProp(header)}
|
@@ -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 type { WithStyleProps } from '@instructure/emotion'
|
29
|
+
import type { PropValidators } from '@instructure/shared-types'
|
30
|
+
|
31
|
+
type TableCellOwnProps = {
|
32
|
+
isStacked?: boolean
|
33
|
+
header?: React.ReactNode | ((...args: any[]) => any)
|
34
|
+
textAlign?: 'start' | 'center' | 'end'
|
35
|
+
children?: React.ReactNode | ((...args: any[]) => React.ReactNode)
|
36
|
+
}
|
37
|
+
|
38
|
+
type PropKeys = keyof TableCellOwnProps
|
39
|
+
|
40
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
41
|
+
|
42
|
+
type TableCellProps = TableCellOwnProps & WithStyleProps
|
43
|
+
|
44
|
+
const propTypes: PropValidators<PropKeys> = {
|
45
|
+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
46
|
+
isStacked: PropTypes.bool,
|
47
|
+
header: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
48
|
+
/**
|
49
|
+
* Control the text alignment in cell
|
50
|
+
*/
|
51
|
+
textAlign: PropTypes.oneOf(['start', 'center', 'end'])
|
52
|
+
}
|
53
|
+
|
54
|
+
const allowedProps: AllowedPropKeys = [
|
55
|
+
'children',
|
56
|
+
'isStacked',
|
57
|
+
'header',
|
58
|
+
'textAlign'
|
59
|
+
]
|
60
|
+
|
61
|
+
export type { TableCellProps }
|
62
|
+
export { propTypes, allowedProps }
|
package/src/Table/Cell/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 {
|
@@ -36,7 +35,8 @@ import { withStyle, jsx } from '@instructure/emotion'
|
|
36
35
|
|
37
36
|
import generateStyle from './styles'
|
38
37
|
import generateComponentTheme from './theme'
|
39
|
-
import { TableColHeaderProps } from './
|
38
|
+
import type { TableColHeaderProps } from './props'
|
39
|
+
import { allowedProps, propTypes } from './props'
|
40
40
|
|
41
41
|
/**
|
42
42
|
---
|
@@ -48,64 +48,22 @@ id: Table.ColHeader
|
|
48
48
|
class ColHeader extends Component<TableColHeaderProps> {
|
49
49
|
static readonly componentId = 'Table.ColHeader'
|
50
50
|
|
51
|
-
|
52
|
-
static propTypes =
|
53
|
-
// eslint-disable-next-line react/require-default-props
|
54
|
-
makeStyles: PropTypes.func,
|
55
|
-
// eslint-disable-next-line react/require-default-props
|
56
|
-
styles: PropTypes.object,
|
57
|
-
/**
|
58
|
-
* A unique id for this column. The `id` is also used as option in combobox,
|
59
|
-
* when sortable table is in stacked layout,
|
60
|
-
* and no `stackedSortByLabel` is provided.
|
61
|
-
*/
|
62
|
-
id: PropTypes.string.isRequired,
|
63
|
-
/**
|
64
|
-
* A custom string to display as option text in the combobox (instead of
|
65
|
-
* using the `id` prop), when sortable table is in stacked layout.
|
66
|
-
*/
|
67
|
-
stackedSortByLabel: PropTypes.string,
|
68
|
-
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
69
|
-
/**
|
70
|
-
* Control the width of column.
|
71
|
-
*/
|
72
|
-
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
73
|
-
/**
|
74
|
-
* Control the text alignment in column header
|
75
|
-
*/
|
76
|
-
textAlign: PropTypes.oneOf(['start', 'center', 'end']),
|
77
|
-
/**
|
78
|
-
* The string of sorting direction
|
79
|
-
*/
|
80
|
-
sortDirection: PropTypes.oneOf(['none', 'ascending', 'descending']),
|
81
|
-
/**
|
82
|
-
* Callback fired when column header is clicked. Parameters: `(event, { id })`
|
83
|
-
*/
|
84
|
-
onRequestSort: PropTypes.func,
|
85
|
-
/**
|
86
|
-
* The column header scope attribute. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th#attr-scope
|
87
|
-
*/
|
88
|
-
scope: PropTypes.oneOf(['row', 'col', 'rowgroup', 'colgroup', 'auto'])
|
89
|
-
}
|
90
|
-
/* eslint-enable react/require-default-props */
|
51
|
+
static allowedProps = allowedProps
|
52
|
+
static propTypes = propTypes
|
91
53
|
|
92
54
|
static defaultProps = {
|
93
55
|
textAlign: 'start',
|
94
56
|
sortDirection: 'none',
|
95
|
-
stackedSortByLabel: undefined,
|
96
57
|
children: null,
|
97
58
|
scope: 'col'
|
98
59
|
}
|
99
60
|
|
100
61
|
componentDidMount() {
|
101
|
-
|
102
|
-
this.props.makeStyles()
|
62
|
+
this.props.makeStyles?.()
|
103
63
|
}
|
104
64
|
|
105
|
-
|
106
|
-
|
107
|
-
// @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
|
108
|
-
this.props.makeStyles()
|
65
|
+
componentDidUpdate() {
|
66
|
+
this.props.makeStyles?.()
|
109
67
|
}
|
110
68
|
|
111
69
|
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
|
@@ -147,7 +105,7 @@ class ColHeader extends Component<TableColHeaderProps> {
|
|
147
105
|
return (
|
148
106
|
<th
|
149
107
|
{...omitProps(this.props, ColHeader.propTypes)}
|
150
|
-
css={styles
|
108
|
+
css={styles?.colHeader}
|
151
109
|
style={{
|
152
110
|
width
|
153
111
|
}}
|
@@ -155,7 +113,7 @@ class ColHeader extends Component<TableColHeaderProps> {
|
|
155
113
|
aria-sort={sortDirection}
|
156
114
|
>
|
157
115
|
{onRequestSort && (
|
158
|
-
<button onClick={this.handleClick} css={styles
|
116
|
+
<button onClick={this.handleClick} css={styles?.button}>
|
159
117
|
<div>
|
160
118
|
{callRenderProp(children)}
|
161
119
|
{this.renderSortArrow()}
|
@@ -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 }
|