@instructure/ui-table 9.7.2 → 9.8.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/es/Table/Body/index.js +13 -5
  3. package/es/Table/Body/props.js +2 -5
  4. package/es/Table/Body/styles.js +0 -2
  5. package/es/Table/Cell/index.js +3 -2
  6. package/es/Table/Cell/props.js +1 -2
  7. package/es/Table/ColHeader/props.js +2 -1
  8. package/es/Table/Head/index.js +40 -30
  9. package/es/Table/Head/props.js +1 -2
  10. package/es/Table/Head/styles.js +0 -2
  11. package/es/Table/Row/index.js +21 -18
  12. package/es/Table/Row/props.js +2 -5
  13. package/es/Table/Row/styles.js +4 -6
  14. package/es/Table/RowHeader/index.js +3 -2
  15. package/es/Table/RowHeader/props.js +1 -2
  16. package/es/Table/TableContext.js +34 -0
  17. package/es/Table/__new-tests__/Table.test.js +66 -2
  18. package/es/Table/index.js +10 -6
  19. package/es/index.js +2 -1
  20. package/lib/Table/Body/index.js +13 -5
  21. package/lib/Table/Body/props.js +2 -5
  22. package/lib/Table/Body/styles.js +0 -2
  23. package/lib/Table/Cell/index.js +3 -2
  24. package/lib/Table/Cell/props.js +1 -2
  25. package/lib/Table/ColHeader/props.js +2 -1
  26. package/lib/Table/Head/index.js +39 -30
  27. package/lib/Table/Head/props.js +1 -2
  28. package/lib/Table/Head/styles.js +0 -2
  29. package/lib/Table/Row/index.js +18 -17
  30. package/lib/Table/Row/props.js +2 -5
  31. package/lib/Table/Row/styles.js +4 -6
  32. package/lib/Table/RowHeader/index.js +3 -2
  33. package/lib/Table/RowHeader/props.js +1 -2
  34. package/lib/Table/TableContext.js +39 -0
  35. package/lib/Table/__new-tests__/Table.test.js +66 -2
  36. package/lib/Table/index.js +10 -6
  37. package/lib/index.js +8 -1
  38. package/package.json +17 -17
  39. package/src/Table/Body/index.tsx +14 -7
  40. package/src/Table/Body/props.ts +6 -18
  41. package/src/Table/Body/styles.ts +0 -2
  42. package/src/Table/Cell/index.tsx +6 -3
  43. package/src/Table/Cell/props.ts +7 -9
  44. package/src/Table/ColHeader/props.ts +9 -3
  45. package/src/Table/Head/index.tsx +40 -40
  46. package/src/Table/Head/props.ts +20 -10
  47. package/src/Table/Head/styles.ts +0 -2
  48. package/src/Table/README.md +1788 -546
  49. package/src/Table/Row/index.tsx +21 -23
  50. package/src/Table/Row/props.ts +7 -19
  51. package/src/Table/Row/styles.ts +5 -6
  52. package/src/Table/RowHeader/index.tsx +6 -4
  53. package/src/Table/RowHeader/props.ts +1 -3
  54. package/src/Table/TableContext.ts +54 -0
  55. package/src/Table/__new-tests__/Table.test.tsx +95 -2
  56. package/src/Table/index.tsx +32 -28
  57. package/src/Table/props.ts +8 -28
  58. package/src/index.ts +1 -0
  59. package/tsconfig.build.tsbuildinfo +1 -1
  60. package/types/Table/Body/index.d.ts +6 -13
  61. package/types/Table/Body/index.d.ts.map +1 -1
  62. package/types/Table/Body/props.d.ts +4 -5
  63. package/types/Table/Body/props.d.ts.map +1 -1
  64. package/types/Table/Body/styles.d.ts +0 -2
  65. package/types/Table/Body/styles.d.ts.map +1 -1
  66. package/types/Table/Cell/index.d.ts +4 -3
  67. package/types/Table/Cell/index.d.ts.map +1 -1
  68. package/types/Table/Cell/props.d.ts +6 -2
  69. package/types/Table/Cell/props.d.ts.map +1 -1
  70. package/types/Table/ColHeader/index.d.ts +2 -0
  71. package/types/Table/ColHeader/index.d.ts.map +1 -1
  72. package/types/Table/ColHeader/props.d.ts +7 -3
  73. package/types/Table/ColHeader/props.d.ts.map +1 -1
  74. package/types/Table/Head/index.d.ts +15 -5
  75. package/types/Table/Head/index.d.ts.map +1 -1
  76. package/types/Table/Head/props.d.ts +19 -4
  77. package/types/Table/Head/props.d.ts.map +1 -1
  78. package/types/Table/Head/styles.d.ts +0 -2
  79. package/types/Table/Head/styles.d.ts.map +1 -1
  80. package/types/Table/Row/index.d.ts +6 -13
  81. package/types/Table/Row/index.d.ts.map +1 -1
  82. package/types/Table/Row/props.d.ts +5 -6
  83. package/types/Table/Row/props.d.ts.map +1 -1
  84. package/types/Table/Row/styles.d.ts +5 -2
  85. package/types/Table/Row/styles.d.ts.map +1 -1
  86. package/types/Table/RowHeader/index.d.ts +4 -3
  87. package/types/Table/RowHeader/index.d.ts.map +1 -1
  88. package/types/Table/RowHeader/props.d.ts +0 -1
  89. package/types/Table/RowHeader/props.d.ts.map +1 -1
  90. package/types/Table/TableContext.d.ts +24 -0
  91. package/types/Table/TableContext.d.ts.map +1 -0
  92. package/types/Table/index.d.ts.map +1 -1
  93. package/types/Table/props.d.ts +10 -22
  94. package/types/Table/props.d.ts.map +1 -1
  95. package/types/index.d.ts +1 -0
  96. package/types/index.d.ts.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-table",
3
- "version": "9.7.2",
3
+ "version": "9.8.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,11 +23,11 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-axe-check": "9.7.2",
27
- "@instructure/ui-babel-preset": "9.7.2",
28
- "@instructure/ui-color-utils": "9.7.2",
29
- "@instructure/ui-test-utils": "9.7.2",
30
- "@instructure/ui-themes": "9.7.2",
26
+ "@instructure/ui-axe-check": "9.8.0",
27
+ "@instructure/ui-babel-preset": "9.8.0",
28
+ "@instructure/ui-color-utils": "9.8.0",
29
+ "@instructure/ui-test-utils": "9.8.0",
30
+ "@instructure/ui-themes": "9.8.0",
31
31
  "@testing-library/jest-dom": "^6.4.6",
32
32
  "@testing-library/react": "^15.0.7",
33
33
  "@testing-library/user-event": "^14.5.2",
@@ -35,17 +35,17 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@babel/runtime": "^7.24.5",
38
- "@instructure/console": "9.7.2",
39
- "@instructure/emotion": "9.7.2",
40
- "@instructure/shared-types": "9.7.2",
41
- "@instructure/ui-a11y-content": "9.7.2",
42
- "@instructure/ui-icons": "9.7.2",
43
- "@instructure/ui-prop-types": "9.7.2",
44
- "@instructure/ui-react-utils": "9.7.2",
45
- "@instructure/ui-simple-select": "9.7.2",
46
- "@instructure/ui-testable": "9.7.2",
47
- "@instructure/ui-utils": "9.7.2",
48
- "@instructure/ui-view": "9.7.2",
38
+ "@instructure/console": "9.8.0",
39
+ "@instructure/emotion": "9.8.0",
40
+ "@instructure/shared-types": "9.8.0",
41
+ "@instructure/ui-a11y-content": "9.8.0",
42
+ "@instructure/ui-icons": "9.8.0",
43
+ "@instructure/ui-prop-types": "9.8.0",
44
+ "@instructure/ui-react-utils": "9.8.0",
45
+ "@instructure/ui-simple-select": "9.8.0",
46
+ "@instructure/ui-testable": "9.8.0",
47
+ "@instructure/ui-utils": "9.8.0",
48
+ "@instructure/ui-view": "9.8.0",
49
49
  "prop-types": "^15.8.1"
50
50
  },
51
51
  "peerDependencies": {
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  /** @jsx jsx */
26
- import { Component, Children, isValidElement } from 'react'
26
+ import { Component, Children, ContextType, isValidElement } from 'react'
27
27
 
28
28
  import { safeCloneElement, omitProps } from '@instructure/ui-react-utils'
29
29
  import { View } from '@instructure/ui-view'
@@ -32,8 +32,8 @@ import { withStyle, jsx } from '@instructure/emotion'
32
32
  import generateStyle from './styles'
33
33
  import generateComponentTheme from './theme'
34
34
  import type { TableBodyProps } from './props'
35
- import type { RowChild } from '../props'
36
35
  import { allowedProps, propTypes } from './props'
36
+ import TableContext from '../TableContext'
37
37
 
38
38
  /**
39
39
  ---
@@ -44,10 +44,10 @@ id: Table.Body
44
44
  @withStyle(generateStyle, generateComponentTheme)
45
45
  class Body extends Component<TableBodyProps> {
46
46
  static readonly componentId = 'Table.Body'
47
-
47
+ static contextType = TableContext
48
+ declare context: ContextType<typeof TableContext>
48
49
  static allowedProps = allowedProps
49
50
  static propTypes = propTypes
50
-
51
51
  static defaultProps = {
52
52
  children: null
53
53
  }
@@ -61,7 +61,8 @@ class Body extends Component<TableBodyProps> {
61
61
  }
62
62
 
63
63
  render() {
64
- const { children, hover, isStacked, headers, styles } = this.props
64
+ const { children, styles } = this.props
65
+ const { isStacked, hover, headers } = this.context
65
66
 
66
67
  return (
67
68
  <View
@@ -70,12 +71,18 @@ class Body extends Component<TableBodyProps> {
70
71
  css={styles?.body}
71
72
  role={isStacked ? 'rowgroup' : undefined}
72
73
  >
73
- {Children.map(children as RowChild[], (child) => {
74
+ {Children.map(children, (child) => {
74
75
  if (isValidElement(child)) {
75
76
  return safeCloneElement(child, {
76
77
  key: child.props.name,
77
- isStacked,
78
+ // Sent down for compatibility with custom components
79
+ // TODO DEPRECATED, remove in v11
78
80
  hover,
81
+ // Sent down for compatibility with custom components
82
+ // TODO DEPRECATED, remove in v11
83
+ isStacked,
84
+ // Sent down for compatibility with custom components
85
+ // TODO DEPRECATED, remove in v11
79
86
  headers
80
87
  })
81
88
  }
@@ -24,8 +24,6 @@
24
24
  import React from 'react'
25
25
  import PropTypes from 'prop-types'
26
26
 
27
- import type { TableRowProps } from '../Row/props'
28
-
29
27
  import type {
30
28
  OtherHTMLAttributes,
31
29
  PropValidators,
@@ -34,11 +32,11 @@ import type {
34
32
  import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
35
33
 
36
34
  type TableBodyOwnProps = {
37
- hover?: boolean
38
- isStacked?: boolean
39
- headers?: TableRowProps['headers']
40
35
  /**
41
- * `Table.Row`
36
+ * Body's children should be a container component where each child represents
37
+ * a row.
38
+ *
39
+ * `Table.Row` by default
42
40
  */
43
41
  children?: React.ReactNode
44
42
  }
@@ -54,20 +52,10 @@ type TableBodyProps = TableBodyOwnProps &
54
52
  type TableBodyStyle = ComponentStyle<'body'>
55
53
 
56
54
  const propTypes: PropValidators<PropKeys> = {
57
- children: PropTypes.node,
58
- hover: PropTypes.bool,
59
- isStacked: PropTypes.bool,
60
- headers: PropTypes.arrayOf(
61
- PropTypes.oneOfType([PropTypes.node, PropTypes.func])
62
- )
55
+ children: PropTypes.node
63
56
  }
64
57
 
65
- const allowedProps: AllowedPropKeys = [
66
- 'children',
67
- 'hover',
68
- 'isStacked',
69
- 'headers'
70
- ]
58
+ const allowedProps: AllowedPropKeys = ['children']
71
59
 
72
60
  export type { TableBodyProps, TableBodyStyle }
73
61
  export { propTypes, allowedProps }
@@ -31,8 +31,6 @@ import type { TableBodyStyle } from './props'
31
31
  * ---
32
32
  * Generates the style object from the theme and provided additional information
33
33
  * @param {Object} componentTheme The theme variable object.
34
- * @param {Object} props the props of the component, the style is applied to
35
- * @param {Object} state the state of the component, the style is applied to
36
34
  * @return {Object} The final style object, which will be used in the component
37
35
  */
38
36
  const generateStyle = (componentTheme: TableBodyTheme): TableBodyStyle => {
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  /** @jsx jsx */
26
- import { Component } from 'react'
26
+ import { Component, ContextType } from 'react'
27
27
 
28
28
  import { omitProps, callRenderProp } from '@instructure/ui-react-utils'
29
29
  import { View } from '@instructure/ui-view'
@@ -34,6 +34,7 @@ import generateStyle from './styles'
34
34
  import generateComponentTheme from './theme'
35
35
  import type { TableCellProps } from './props'
36
36
  import { allowedProps, propTypes } from './props'
37
+ import TableContext from '../TableContext'
37
38
 
38
39
  /**
39
40
  ---
@@ -44,7 +45,8 @@ id: Table.Cell
44
45
  @withStyle(generateStyle, generateComponentTheme)
45
46
  class Cell extends Component<TableCellProps> {
46
47
  static readonly componentId = 'Table.Cell'
47
-
48
+ static contextType = TableContext
49
+ declare context: ContextType<typeof TableContext>
48
50
  static allowedProps = allowedProps
49
51
  static propTypes = propTypes
50
52
 
@@ -62,7 +64,8 @@ class Cell extends Component<TableCellProps> {
62
64
  }
63
65
 
64
66
  render() {
65
- const { children, styles, isStacked, header } = this.props
67
+ const { children, styles, header } = this.props
68
+ const isStacked = this.context.isStacked
66
69
 
67
70
  return (
68
71
  <View
@@ -33,10 +33,14 @@ import type {
33
33
  } from '@instructure/shared-types'
34
34
 
35
35
  type TableCellOwnProps = {
36
- isStacked?: boolean
36
+ /**
37
+ * Contains the column header for this cell.
38
+ * This gets rendered in `stacked` layout to identify the column the data
39
+ * belongs to.
40
+ */
37
41
  header?: Renderable
38
42
  /**
39
- * Control the text alignment in cell
43
+ * Controls the text alignment in cell.
40
44
  */
41
45
  textAlign?: 'start' | 'center' | 'end'
42
46
  children?: Renderable
@@ -54,17 +58,11 @@ type TableCellStyle = ComponentStyle<'cell'>
54
58
 
55
59
  const propTypes: PropValidators<PropKeys> = {
56
60
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
57
- isStacked: PropTypes.bool,
58
61
  header: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
59
62
  textAlign: PropTypes.oneOf(['start', 'center', 'end'])
60
63
  }
61
64
 
62
- const allowedProps: AllowedPropKeys = [
63
- 'children',
64
- 'isStacked',
65
- 'header',
66
- 'textAlign'
67
- ]
65
+ const allowedProps: AllowedPropKeys = ['children', 'header', 'textAlign']
68
66
 
69
67
  export type { TableCellProps, TableCellStyle }
70
68
  export { propTypes, allowedProps }
@@ -32,6 +32,10 @@ import type {
32
32
  import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
33
33
 
34
34
  type TableColHeaderOwnProps = {
35
+ /**
36
+ * DEPRECATED. Use `TableContext` to read this value
37
+ */
38
+ isStacked?: boolean
35
39
  /**
36
40
  * A unique id for this column. The `id` is also used as option in combobox,
37
41
  * when sortable table is in stacked layout,
@@ -52,18 +56,18 @@ type TableColHeaderOwnProps = {
52
56
  */
53
57
  textAlign?: 'start' | 'center' | 'end'
54
58
  /**
55
- * The string of sorting direction
59
+ * The sorting direction
56
60
  */
57
61
  sortDirection?: 'none' | 'ascending' | 'descending'
58
62
  /**
59
- * Callback fired when column header is clicked. Parameters: `(event, { id })`
63
+ * Callback fired when column header is clicked.
60
64
  */
61
65
  onRequestSort?: (
62
66
  event: React.SyntheticEvent,
63
67
  param: { id: TableColHeaderOwnProps['id'] }
64
68
  ) => void
65
69
  /**
66
- * The column header scope attribute. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th#attr-scope
70
+ * The column header scope attribute. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th#scope
67
71
  */
68
72
  scope?: 'row' | 'col' | 'rowgroup' | 'colgroup' | 'auto'
69
73
  children?: React.ReactNode
@@ -85,6 +89,7 @@ type TableColHeaderStyle = ComponentStyle<
85
89
  >
86
90
 
87
91
  const propTypes: PropValidators<PropKeys> = {
92
+ isStacked: PropTypes.bool,
88
93
  id: PropTypes.string.isRequired,
89
94
  stackedSortByLabel: PropTypes.string,
90
95
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
@@ -97,6 +102,7 @@ const propTypes: PropValidators<PropKeys> = {
97
102
 
98
103
  const allowedProps: AllowedPropKeys = [
99
104
  'id',
105
+ 'isStacked',
100
106
  'stackedSortByLabel',
101
107
  'children',
102
108
  'width',
@@ -23,13 +23,9 @@
23
23
  */
24
24
 
25
25
  /** @jsx jsx */
26
- import { Component, Children } from 'react'
26
+ import { Component, Children, ContextType } from 'react'
27
27
 
28
- import {
29
- omitProps,
30
- matchComponentTypes,
31
- callRenderProp
32
- } from '@instructure/ui-react-utils'
28
+ import { omitProps, callRenderProp } from '@instructure/ui-react-utils'
33
29
  import { SimpleSelect } from '@instructure/ui-simple-select'
34
30
  import type { SimpleSelectProps } from '@instructure/ui-simple-select'
35
31
  import { ScreenReaderContent } from '@instructure/ui-a11y-content'
@@ -41,12 +37,11 @@ import { withStyle, jsx } from '@instructure/emotion'
41
37
  import generateStyle from './styles'
42
38
  import generateComponentTheme from './theme'
43
39
 
44
- import { Row } from '../Row'
45
- import { ColHeader } from '../ColHeader'
46
40
  import type { TableColHeaderProps } from '../ColHeader/props'
47
41
  import type { TableHeadProps } from './props'
48
- import type { ColHeaderChild, RowChild } from '../props'
42
+ import type { RowChild } from '../props'
49
43
  import { allowedProps, propTypes } from './props'
44
+ import TableContext from '../TableContext'
50
45
 
51
46
  /**
52
47
  ---
@@ -57,26 +52,28 @@ id: Table.Head
57
52
  @withStyle(generateStyle, generateComponentTheme)
58
53
  class Head extends Component<TableHeadProps> {
59
54
  static readonly componentId = 'Table.Head'
60
-
55
+ static contextType = TableContext
56
+ declare context: ContextType<typeof TableContext>
61
57
  static allowedProps = allowedProps
62
58
  static propTypes = propTypes
63
-
64
59
  static defaultProps = {
65
60
  children: null
66
61
  }
67
62
 
63
+ /**
64
+ * Returns `true` if the first child's children have a `onRequestSort` prop
65
+ */
68
66
  get isSortable() {
69
- const [row] = Children.toArray(this.props.children) as RowChild[]
67
+ const [firstRow] = Children.toArray(this.props.children) as RowChild[]
70
68
  let sortable = false
71
-
72
- if (row) {
73
- Children.forEach(row.props.children as ColHeaderChild[], (colHeader) => {
74
- if (matchComponentTypes<ColHeaderChild>(colHeader, [ColHeader])) {
75
- if (colHeader.props.onRequestSort) sortable = true
69
+ if (firstRow && firstRow.props && firstRow.props.children) {
70
+ Children.forEach(firstRow.props.children, (grandchild) => {
71
+ if (grandchild.props.onRequestSort) {
72
+ sortable = true
73
+ return
76
74
  }
77
75
  })
78
76
  }
79
-
80
77
  return sortable
81
78
  }
82
79
 
@@ -94,13 +91,19 @@ class Head extends Component<TableHeadProps> {
94
91
  this.props.makeStyles?.()
95
92
  }
96
93
 
94
+ /**
95
+ * This `Select` is used in `stacked` layout. It's populated by iterating
96
+ * through the first child's children (by default `ColHeader`) and reading
97
+ * there the `id`, `stackedSortByLabel`, `sortDirection`, `onRequestSort` props
98
+ */
97
99
  renderSelect() {
98
100
  const { children, renderSortLabel } = this.props
99
- const [row] = Children.toArray(children) as RowChild[]
101
+ const [firstRow] = Children.toArray(children) as RowChild[]
100
102
 
101
- if (!matchComponentTypes<RowChild>(row, [Row])) {
103
+ if (!firstRow?.props?.children) {
102
104
  return null
103
105
  }
106
+
104
107
  const options: {
105
108
  id: TableColHeaderProps['id']
106
109
  label:
@@ -113,21 +116,17 @@ class Head extends Component<TableHeadProps> {
113
116
  > = {}
114
117
  let selectedOption: TableColHeaderProps['id'] | undefined
115
118
  let count = 0
116
-
117
- Children.forEach(row.props.children, (colHeader) => {
119
+ Children.forEach(firstRow.props.children, (grandchild) => {
118
120
  count += 1
119
- if (matchComponentTypes<ColHeaderChild>(colHeader, [ColHeader])) {
120
- const { id, stackedSortByLabel, sortDirection, onRequestSort } =
121
- colHeader.props
122
-
121
+ if (!grandchild.props) return
122
+ const { id, stackedSortByLabel, sortDirection, onRequestSort } =
123
+ grandchild.props
124
+ if (id && onRequestSort) {
123
125
  const label = stackedSortByLabel || id
124
-
125
- if (onRequestSort) {
126
- options.push({ id, label })
127
- clickHandlers[id] = onRequestSort
128
- if (sortDirection !== 'none') {
129
- selectedOption = id
130
- }
126
+ options.push({ id, label })
127
+ clickHandlers[id] = onRequestSort
128
+ if (sortDirection !== 'none') {
129
+ selectedOption = id
131
130
  }
132
131
  }
133
132
  })
@@ -177,15 +176,16 @@ class Head extends Component<TableHeadProps> {
177
176
  }
178
177
 
179
178
  render() {
180
- const { children, isStacked, styles } = this.props
181
-
182
- return isStacked ? (
179
+ const { children, styles } = this.props
180
+ return this.context.isStacked ? (
183
181
  this.renderSelect()
184
182
  ) : (
185
- <thead {...omitProps(this.props, Head.allowedProps)} css={styles?.head}>
186
- {Children.map(children, (child) =>
187
- matchComponentTypes<RowChild>(child, [Row]) ? child : null
188
- )}
183
+ // TODO remove 'hover' exclude in v11, its passed down for compatibility with custom components
184
+ <thead
185
+ {...omitProps(this.props, Head.allowedProps, ['hover'])}
186
+ css={styles?.head}
187
+ >
188
+ {children}
189
189
  </thead>
190
190
  )
191
191
  }
@@ -22,7 +22,6 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- import React from 'react'
26
25
  import PropTypes from 'prop-types'
27
26
 
28
27
  import type {
@@ -32,14 +31,30 @@ import type {
32
31
  TableHeadTheme
33
32
  } from '@instructure/shared-types'
34
33
  import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
34
+ import { RowChild } from '../props'
35
35
 
36
36
  type TableHeadOwnProps = {
37
- isStacked?: boolean
37
+ /**
38
+ * The sort `Select`'s label when using `stacked` layout and the table is
39
+ * sortable.
40
+ * If you don't want to display anything you should use `ScreenReaderContent`
41
+ * so screen readers can read the `Select`'s purpose
42
+ */
38
43
  renderSortLabel?: Renderable
39
44
  /**
40
- * `Table.Row`
45
+ * The header row(s).
46
+ * Default type: `Table.Row`
47
+ *
48
+ * Its first child is treated specially if the table is sortable and has
49
+ * `stacked` layout:
50
+ *
51
+ * A `Select` is created which reads options from the first child's
52
+ * children, that tries to read the following props: `id`,
53
+ * `stackedSortByLabel`,`sortDirection`, `onRequestSort` (Available on
54
+ * `Table.ColHeader`).
55
+ * These are used to sort the table in this layout.
41
56
  */
42
- children?: React.ReactNode
57
+ children?: RowChild
43
58
  }
44
59
  type PropKeys = keyof TableHeadOwnProps
45
60
 
@@ -53,15 +68,10 @@ type TableHeadStyle = ComponentStyle<'head'>
53
68
 
54
69
  const propTypes: PropValidators<PropKeys> = {
55
70
  children: PropTypes.node,
56
- isStacked: PropTypes.bool,
57
71
  renderSortLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
58
72
  }
59
73
 
60
- const allowedProps: AllowedPropKeys = [
61
- 'children',
62
- 'isStacked',
63
- 'renderSortLabel'
64
- ]
74
+ const allowedProps: AllowedPropKeys = ['children', 'renderSortLabel']
65
75
 
66
76
  export type { TableHeadProps, TableHeadStyle }
67
77
  export { propTypes, allowedProps }
@@ -31,8 +31,6 @@ import type { TableHeadStyle } from './props'
31
31
  * ---
32
32
  * Generates the style object from the theme and provided additional information
33
33
  * @param {Object} componentTheme The theme variable object.
34
- * @param {Object} props the props of the component, the style is applied to
35
- * @param {Object} state the state of the component, the style is applied to
36
34
  * @return {Object} The final style object, which will be used in the component
37
35
  */
38
36
  const generateStyle = (componentTheme: TableHeadTheme): TableHeadStyle => {