@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.
Files changed (113) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/es/Table/Body/index.js +16 -28
  3. package/{src/Table/Cell/types.ts → es/Table/Body/props.js} +14 -8
  4. package/es/Table/Cell/index.js +16 -28
  5. package/{src/Table/types.ts → es/Table/Cell/props.js} +12 -11
  6. package/es/Table/ColHeader/index.js +22 -63
  7. package/es/Table/ColHeader/props.js +66 -0
  8. package/es/Table/Head/index.js +18 -29
  9. package/{src/Table/Body/types.ts → es/Table/Head/props.js} +13 -8
  10. package/es/Table/Row/index.js +16 -28
  11. package/{src/Table/ColHeader/types.ts → es/Table/Row/props.js} +16 -12
  12. package/es/Table/RowHeader/index.js +15 -26
  13. package/{src/Table/Head/types.ts → es/Table/RowHeader/props.js} +11 -6
  14. package/es/Table/index.js +21 -60
  15. package/es/Table/props.js +66 -0
  16. package/lib/Table/Body/index.js +16 -29
  17. package/lib/Table/Body/props.js +50 -0
  18. package/lib/Table/Cell/index.js +16 -28
  19. package/lib/Table/Cell/props.js +47 -0
  20. package/lib/Table/ColHeader/index.js +22 -63
  21. package/lib/Table/ColHeader/props.js +77 -0
  22. package/lib/Table/Head/index.js +18 -30
  23. package/lib/Table/Head/props.js +49 -0
  24. package/lib/Table/Row/index.js +16 -29
  25. package/lib/Table/Row/props.js +54 -0
  26. package/lib/Table/RowHeader/index.js +15 -26
  27. package/lib/Table/RowHeader/props.js +46 -0
  28. package/lib/Table/index.js +20 -60
  29. package/lib/Table/props.js +81 -0
  30. package/package.json +17 -18
  31. package/src/Table/Body/index.tsx +7 -25
  32. package/src/Table/{Row/types.ts → Body/props.ts} +39 -3
  33. package/src/Table/Cell/index.tsx +8 -24
  34. package/src/Table/Cell/props.ts +62 -0
  35. package/src/Table/Cell/styles.ts +1 -1
  36. package/src/Table/ColHeader/index.tsx +9 -51
  37. package/src/Table/ColHeader/props.ts +94 -0
  38. package/src/Table/ColHeader/styles.ts +1 -1
  39. package/src/Table/Head/index.tsx +8 -24
  40. package/src/Table/Head/props.ts +62 -0
  41. package/src/Table/Row/index.tsx +8 -27
  42. package/src/Table/Row/props.ts +70 -0
  43. package/src/Table/Row/styles.ts +1 -1
  44. package/src/Table/RowHeader/index.tsx +8 -23
  45. package/src/Table/RowHeader/{types.ts → props.ts} +28 -3
  46. package/src/Table/RowHeader/styles.ts +1 -1
  47. package/src/Table/index.tsx +10 -49
  48. package/src/Table/props.ts +93 -0
  49. package/src/Table/styles.ts +1 -1
  50. package/src/index.ts +7 -7
  51. package/types/Table/Body/index.d.ts +13 -16
  52. package/types/Table/Body/index.d.ts.map +1 -1
  53. package/types/Table/Body/props.d.ts +17 -0
  54. package/types/Table/Body/props.d.ts.map +1 -0
  55. package/types/Table/Cell/index.d.ts +14 -14
  56. package/types/Table/Cell/index.d.ts.map +1 -1
  57. package/types/Table/Cell/props.d.ts +17 -0
  58. package/types/Table/Cell/props.d.ts.map +1 -0
  59. package/types/Table/Cell/styles.d.ts +1 -1
  60. package/types/Table/ColHeader/index.d.ts +22 -40
  61. package/types/Table/ColHeader/index.d.ts.map +1 -1
  62. package/types/Table/ColHeader/props.d.ts +21 -0
  63. package/types/Table/ColHeader/props.d.ts.map +1 -0
  64. package/types/Table/ColHeader/styles.d.ts +1 -1
  65. package/types/Table/Head/index.d.ts +11 -15
  66. package/types/Table/Head/index.d.ts.map +1 -1
  67. package/types/Table/Head/props.d.ts +16 -0
  68. package/types/Table/Head/props.d.ts.map +1 -0
  69. package/types/Table/Row/index.d.ts +14 -17
  70. package/types/Table/Row/index.d.ts.map +1 -1
  71. package/types/Table/Row/props.d.ts +17 -0
  72. package/types/Table/Row/props.d.ts.map +1 -0
  73. package/types/Table/Row/styles.d.ts +1 -1
  74. package/types/Table/RowHeader/index.d.ts +12 -13
  75. package/types/Table/RowHeader/index.d.ts.map +1 -1
  76. package/types/Table/RowHeader/props.d.ts +16 -0
  77. package/types/Table/RowHeader/props.d.ts.map +1 -0
  78. package/types/Table/RowHeader/styles.d.ts +1 -1
  79. package/types/Table/index.d.ts +18 -41
  80. package/types/Table/index.d.ts.map +1 -1
  81. package/types/Table/props.d.ts +19 -0
  82. package/types/Table/props.d.ts.map +1 -0
  83. package/types/Table/styles.d.ts +1 -1
  84. package/types/index.d.ts +7 -7
  85. package/LICENSE.md +0 -27
  86. package/es/Table/Body/types.js +0 -1
  87. package/es/Table/Cell/types.js +0 -1
  88. package/es/Table/ColHeader/types.js +0 -1
  89. package/es/Table/Head/types.js +0 -1
  90. package/es/Table/Row/types.js +0 -1
  91. package/es/Table/RowHeader/types.js +0 -1
  92. package/es/Table/types.js +0 -1
  93. package/lib/Table/Body/types.js +0 -1
  94. package/lib/Table/Cell/types.js +0 -1
  95. package/lib/Table/ColHeader/types.js +0 -1
  96. package/lib/Table/Head/types.js +0 -1
  97. package/lib/Table/Row/types.js +0 -1
  98. package/lib/Table/RowHeader/types.js +0 -1
  99. package/lib/Table/types.js +0 -1
  100. package/types/Table/Body/types.d.ts +0 -9
  101. package/types/Table/Body/types.d.ts.map +0 -1
  102. package/types/Table/Cell/types.d.ts +0 -9
  103. package/types/Table/Cell/types.d.ts.map +0 -1
  104. package/types/Table/ColHeader/types.d.ts +0 -12
  105. package/types/Table/ColHeader/types.d.ts.map +0 -1
  106. package/types/Table/Head/types.d.ts +0 -8
  107. package/types/Table/Head/types.d.ts.map +0 -1
  108. package/types/Table/Row/types.d.ts +0 -9
  109. package/types/Table/Row/types.d.ts.map +0 -1
  110. package/types/Table/RowHeader/types.d.ts +0 -7
  111. package/types/Table/RowHeader/types.d.ts.map +0 -1
  112. package/types/Table/types.d.ts +0 -12
  113. package/types/Table/types.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [8.9.0](https://github.com/instructure/instructure-ui/compare/v8.8.0...v8.9.0) (2021-09-15)
7
+
8
+ ### Bug Fixes
9
+
10
+ - fix shared-types TS errors ([7b83164](https://github.com/instructure/instructure-ui/commit/7b83164f4c5872f3a217e010563f59bf584ae4fc))
11
+
6
12
  # [8.8.0](https://github.com/instructure/instructure-ui/compare/v8.7.0...v8.8.0) (2021-08-27)
7
13
 
8
14
  **Note:** Version bump only for package @instructure/ui-table
@@ -26,43 +26,43 @@ var _dec, _class, _class2, _temp;
26
26
 
27
27
  /** @jsx jsx */
28
28
  import { Component, Children } from 'react';
29
- import PropTypes from 'prop-types';
30
29
  import { matchComponentTypes, safeCloneElement, omitProps } from '@instructure/ui-react-utils';
31
- import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types';
32
30
  import { View } from '@instructure/ui-view';
33
31
  import { withStyle, jsx } from '@instructure/emotion';
34
32
  import generateStyle from './styles';
35
33
  import generateComponentTheme from './theme';
36
34
  import { Row } from '../Row';
37
-
35
+ import { allowedProps, propTypes } from './props';
38
36
  /**
39
37
  ---
40
38
  parent: Table
41
39
  id: Table.Body
42
40
  ---
43
41
  **/
44
- let Body = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_temp = _class2 = class Body extends Component {
45
- /* eslint-disable react/require-default-props */
46
42
 
47
- /* eslint-enable react/require-default-props */
43
+ let Body = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_temp = _class2 = class Body extends Component {
48
44
  componentDidMount() {
49
- this.props.makeStyles();
45
+ var _this$props$makeStyle, _this$props;
46
+
47
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
50
48
  }
51
49
 
52
50
  componentDidUpdate(prevProps, prevState, snapshot) {
53
- this.props.makeStyles();
51
+ var _this$props$makeStyle2, _this$props2;
52
+
53
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
54
54
  }
55
55
 
56
56
  render() {
57
- const _this$props = this.props,
58
- children = _this$props.children,
59
- hover = _this$props.hover,
60
- isStacked = _this$props.isStacked,
61
- headers = _this$props.headers,
62
- styles = _this$props.styles;
57
+ const _this$props3 = this.props,
58
+ children = _this$props3.children,
59
+ hover = _this$props3.hover,
60
+ isStacked = _this$props3.isStacked,
61
+ headers = _this$props3.headers,
62
+ styles = _this$props3.styles;
63
63
  return jsx(View, Object.assign({}, View.omitViewProps(omitProps(this.props, Body.propTypes), Body), {
64
64
  as: isStacked ? 'div' : 'tbody',
65
- css: styles.body,
65
+ css: styles === null || styles === void 0 ? void 0 : styles.body,
66
66
  role: isStacked ? 'rowgroup' : void 0
67
67
  }), Children.map(children, child => matchComponentTypes(child, [Row]) ? safeCloneElement(child, {
68
68
  key: child.props.name,
@@ -72,19 +72,7 @@ let Body = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class
72
72
  }) : null));
73
73
  }
74
74
 
75
- }, _class2.displayName = "Body", _class2.componentId = 'Table.Body', _class2.propTypes = {
76
- /**
77
- * `Table.Row`
78
- */
79
- // eslint-disable-next-line react/require-default-props
80
- makeStyles: PropTypes.func,
81
- // eslint-disable-next-line react/require-default-props
82
- styles: PropTypes.object,
83
- children: ChildrenPropTypes.oneOf([Row]),
84
- hover: PropTypes.bool,
85
- isStacked: PropTypes.bool,
86
- headers: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.node, PropTypes.func]))
87
- }, _class2.defaultProps = {
75
+ }, _class2.displayName = "Body", _class2.componentId = 'Table.Body', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
88
76
  children: null
89
77
  }, _temp)) || _class);
90
78
  export default Body;
@@ -21,11 +21,17 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
-
25
- export type TableCellProps = {
26
- makeStyles?: (...args: any[]) => any
27
- styles?: any
28
- isStacked?: boolean
29
- header?: React.ReactNode | ((...args: any[]) => any)
30
- textAlign?: 'start' | 'center' | 'end'
31
- }
24
+ import PropTypes from 'prop-types';
25
+ import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types';
26
+ import { Row } from '../Row';
27
+ const propTypes = {
28
+ /**
29
+ * `Table.Row`
30
+ */
31
+ children: ChildrenPropTypes.oneOf([Row]),
32
+ hover: PropTypes.bool,
33
+ isStacked: PropTypes.bool,
34
+ headers: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.node, PropTypes.func]))
35
+ };
36
+ const allowedProps = ['children', 'hover', 'isStacked', 'headers'];
37
+ export { propTypes, allowedProps };
@@ -26,58 +26,46 @@ var _dec, _class, _class2, _temp;
26
26
 
27
27
  /** @jsx jsx */
28
28
  import { Component } from 'react';
29
- import PropTypes from 'prop-types';
30
29
  import { omitProps, callRenderProp } from '@instructure/ui-react-utils';
31
30
  import { View } from '@instructure/ui-view';
32
31
  import { withStyle, jsx } from '@instructure/emotion';
33
32
  import generateStyle from './styles';
34
33
  import generateComponentTheme from './theme';
35
-
34
+ import { allowedProps, propTypes } from './props';
36
35
  /**
37
36
  ---
38
37
  parent: Table
39
38
  id: Table.Cell
40
39
  ---
41
40
  **/
42
- let Cell = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_temp = _class2 = class Cell extends Component {
43
- /* eslint-disable react/require-default-props */
44
41
 
45
- /* eslint-enable react/require-default-props */
42
+ let Cell = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_temp = _class2 = class Cell extends Component {
46
43
  componentDidMount() {
47
- this.props.makeStyles();
44
+ var _this$props$makeStyle, _this$props;
45
+
46
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
48
47
  }
49
48
 
50
- componentDidUpdate(prevProps, prevState, snapshot) {
51
- this.props.makeStyles();
49
+ componentDidUpdate() {
50
+ var _this$props$makeStyle2, _this$props2;
51
+
52
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
52
53
  }
53
54
 
54
55
  render() {
55
- const _this$props = this.props,
56
- children = _this$props.children,
57
- styles = _this$props.styles,
58
- isStacked = _this$props.isStacked,
59
- header = _this$props.header;
56
+ const _this$props3 = this.props,
57
+ children = _this$props3.children,
58
+ styles = _this$props3.styles,
59
+ isStacked = _this$props3.isStacked,
60
+ header = _this$props3.header;
60
61
  return jsx(View, Object.assign({}, View.omitViewProps(omitProps(this.props, Cell.propTypes), Cell), {
61
62
  as: isStacked ? 'div' : 'td',
62
- css: styles.cell,
63
+ css: styles === null || styles === void 0 ? void 0 : styles.cell,
63
64
  role: isStacked ? 'cell' : void 0
64
65
  }), header && callRenderProp(header), header && ': ', callRenderProp(children));
65
66
  }
66
67
 
67
- }, _class2.displayName = "Cell", _class2.componentId = 'Table.Cell', _class2.propTypes = {
68
- // eslint-disable-next-line react/require-default-props
69
- makeStyles: PropTypes.func,
70
- // eslint-disable-next-line react/require-default-props
71
- styles: PropTypes.object,
72
- children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
73
- isStacked: PropTypes.bool,
74
- header: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
75
-
76
- /**
77
- * Control the text alignment in cell
78
- */
79
- textAlign: PropTypes.oneOf(['start', 'center', 'end'])
80
- }, _class2.defaultProps = {
68
+ }, _class2.displayName = "Cell", _class2.componentId = 'Table.Cell', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
81
69
  textAlign: 'start',
82
70
  children: null
83
71
  }, _temp)) || _class);
@@ -21,15 +21,16 @@
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 PropTypes from 'prop-types';
25
+ const propTypes = {
26
+ children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
27
+ isStacked: PropTypes.bool,
28
+ header: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
24
29
 
25
- import type { Spacing } from '@instructure/emotion'
26
-
27
- export type TableProps = {
28
- makeStyles?: (...args: any[]) => any
29
- styles?: any
30
- caption: React.ReactNode
31
- margin?: Spacing
32
- elementRef?: (...args: any[]) => any
33
- hover?: boolean
34
- layout?: 'auto' | 'fixed' | 'stacked'
35
- }
30
+ /**
31
+ * Control the text alignment in cell
32
+ */
33
+ textAlign: PropTypes.oneOf(['start', 'center', 'end'])
34
+ };
35
+ const allowedProps = ['children', 'isStacked', 'header', 'textAlign'];
36
+ export { propTypes, allowedProps };
@@ -26,19 +26,19 @@ var _dec, _class, _class2, _temp, _IconMiniArrowUpLine, _IconMiniArrowDownLin;
26
26
 
27
27
  /** @jsx jsx */
28
28
  import { Component } from 'react';
29
- import PropTypes from 'prop-types';
30
29
  import { omitProps, callRenderProp } from '@instructure/ui-react-utils';
31
30
  import { IconMiniArrowUpLine, IconMiniArrowDownLine } from '@instructure/ui-icons';
32
31
  import { withStyle, jsx } from '@instructure/emotion';
33
32
  import generateStyle from './styles';
34
33
  import generateComponentTheme from './theme';
35
-
34
+ import { allowedProps, propTypes } from './props';
36
35
  /**
37
36
  ---
38
37
  parent: Table
39
38
  id: Table.ColHeader
40
39
  ---
41
40
  **/
41
+
42
42
  let ColHeader = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_temp = _class2 = class ColHeader extends Component {
43
43
  constructor(...args) {
44
44
  super(...args);
@@ -54,17 +54,21 @@ let ColHeader = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_
54
54
  }
55
55
 
56
56
  componentDidMount() {
57
- this.props.makeStyles();
57
+ var _this$props$makeStyle, _this$props2;
58
+
59
+ (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
58
60
  }
59
61
 
60
- componentDidUpdate(prevProps, prevState, snapshot) {
61
- this.props.makeStyles();
62
+ componentDidUpdate() {
63
+ var _this$props$makeStyle2, _this$props3;
64
+
65
+ (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
62
66
  }
63
67
 
64
68
  renderSortArrow() {
65
- const _this$props2 = this.props,
66
- sortDirection = _this$props2.sortDirection,
67
- onRequestSort = _this$props2.onRequestSort;
69
+ const _this$props4 = this.props,
70
+ sortDirection = _this$props4.sortDirection,
71
+ onRequestSort = _this$props4.onRequestSort;
68
72
 
69
73
  if (sortDirection === 'ascending') {
70
74
  return _IconMiniArrowUpLine || (_IconMiniArrowUpLine = jsx(IconMiniArrowUpLine, null));
@@ -87,15 +91,15 @@ let ColHeader = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_
87
91
  }
88
92
 
89
93
  render() {
90
- const _this$props3 = this.props,
91
- onRequestSort = _this$props3.onRequestSort,
92
- width = _this$props3.width,
93
- children = _this$props3.children,
94
- sortDirection = _this$props3.sortDirection,
95
- scope = _this$props3.scope,
96
- styles = _this$props3.styles;
94
+ const _this$props5 = this.props,
95
+ onRequestSort = _this$props5.onRequestSort,
96
+ width = _this$props5.width,
97
+ children = _this$props5.children,
98
+ sortDirection = _this$props5.sortDirection,
99
+ scope = _this$props5.scope,
100
+ styles = _this$props5.styles;
97
101
  return jsx("th", Object.assign({}, omitProps(this.props, ColHeader.propTypes), {
98
- css: styles.colHeader,
102
+ css: styles === null || styles === void 0 ? void 0 : styles.colHeader,
99
103
  style: {
100
104
  width
101
105
  },
@@ -103,58 +107,13 @@ let ColHeader = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_
103
107
  "aria-sort": sortDirection
104
108
  }), onRequestSort && jsx("button", {
105
109
  onClick: this.handleClick,
106
- css: styles.button
110
+ css: styles === null || styles === void 0 ? void 0 : styles.button
107
111
  }, jsx("div", null, callRenderProp(children), this.renderSortArrow())), !onRequestSort && children, !onRequestSort && this.renderSortArrow());
108
112
  }
109
113
 
110
- }, _class2.displayName = "ColHeader", _class2.componentId = 'Table.ColHeader', _class2.propTypes = {
111
- // eslint-disable-next-line react/require-default-props
112
- makeStyles: PropTypes.func,
113
- // eslint-disable-next-line react/require-default-props
114
- styles: PropTypes.object,
115
-
116
- /**
117
- * A unique id for this column. The `id` is also used as option in combobox,
118
- * when sortable table is in stacked layout,
119
- * and no `stackedSortByLabel` is provided.
120
- */
121
- id: PropTypes.string.isRequired,
122
-
123
- /**
124
- * A custom string to display as option text in the combobox (instead of
125
- * using the `id` prop), when sortable table is in stacked layout.
126
- */
127
- stackedSortByLabel: PropTypes.string,
128
- children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
129
-
130
- /**
131
- * Control the width of column.
132
- */
133
- width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
134
-
135
- /**
136
- * Control the text alignment in column header
137
- */
138
- textAlign: PropTypes.oneOf(['start', 'center', 'end']),
139
-
140
- /**
141
- * The string of sorting direction
142
- */
143
- sortDirection: PropTypes.oneOf(['none', 'ascending', 'descending']),
144
-
145
- /**
146
- * Callback fired when column header is clicked. Parameters: `(event, { id })`
147
- */
148
- onRequestSort: PropTypes.func,
149
-
150
- /**
151
- * The column header scope attribute. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th#attr-scope
152
- */
153
- scope: PropTypes.oneOf(['row', 'col', 'rowgroup', 'colgroup', 'auto'])
154
- }, _class2.defaultProps = {
114
+ }, _class2.displayName = "ColHeader", _class2.componentId = 'Table.ColHeader', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
155
115
  textAlign: 'start',
156
116
  sortDirection: 'none',
157
- stackedSortByLabel: void 0,
158
117
  children: null,
159
118
  scope: 'col'
160
119
  }, _temp)) || _class);
@@ -0,0 +1,66 @@
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 PropTypes from 'prop-types';
25
+ const propTypes = {
26
+ /**
27
+ * A unique id for this column. The `id` is also used as option in combobox,
28
+ * when sortable table is in stacked layout,
29
+ * and no `stackedSortByLabel` is provided.
30
+ */
31
+ id: PropTypes.string.isRequired,
32
+
33
+ /**
34
+ * A custom string to display as option text in the combobox (instead of
35
+ * using the `id` prop), when sortable table is in stacked layout.
36
+ */
37
+ stackedSortByLabel: PropTypes.string,
38
+ children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
39
+
40
+ /**
41
+ * Control the width of column.
42
+ */
43
+ width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
44
+
45
+ /**
46
+ * Control the text alignment in column header
47
+ */
48
+ textAlign: PropTypes.oneOf(['start', 'center', 'end']),
49
+
50
+ /**
51
+ * The string of sorting direction
52
+ */
53
+ sortDirection: PropTypes.oneOf(['none', 'ascending', 'descending']),
54
+
55
+ /**
56
+ * Callback fired when column header is clicked. Parameters: `(event, { id })`
57
+ */
58
+ onRequestSort: PropTypes.func,
59
+
60
+ /**
61
+ * The column header scope attribute. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th#attr-scope
62
+ */
63
+ scope: PropTypes.oneOf(['row', 'col', 'rowgroup', 'colgroup', 'auto'])
64
+ };
65
+ const allowedProps = ['id', 'stackedSortByLabel', 'children', 'width', 'textAlign', 'sortDirection', 'onRequestSort', 'scope'];
66
+ export { propTypes, allowedProps };
@@ -28,9 +28,7 @@ var _dec, _class, _class2, _temp, _ScreenReaderContent;
28
28
 
29
29
  /** @jsx jsx */
30
30
  import { Component, Children } from 'react';
31
- import PropTypes from 'prop-types';
32
31
  import { omitProps, matchComponentTypes, callRenderProp } from '@instructure/ui-react-utils';
33
- import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types';
34
32
  import { SimpleSelect } from '@instructure/ui-simple-select';
35
33
  import { ScreenReaderContent } from '@instructure/ui-a11y-content';
36
34
  import { IconCheckLine } from '@instructure/ui-icons';
@@ -40,17 +38,15 @@ import generateStyle from './styles';
40
38
  import generateComponentTheme from './theme';
41
39
  import { Row } from '../Row';
42
40
  import { ColHeader } from '../ColHeader';
43
-
41
+ import { allowedProps, propTypes } from './props';
44
42
  /**
45
43
  ---
46
44
  parent: Table
47
45
  id: Table.Head
48
46
  ---
49
47
  **/
50
- let Head = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_temp = _class2 = class Head extends Component {
51
- /* eslint-disable react/require-default-props */
52
48
 
53
- /* eslint-enable react/require-default-props */
49
+ let Head = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_temp = _class2 = class Head extends Component {
54
50
  get isSortable() {
55
51
  const _Children$toArray = Children.toArray(this.props.children),
56
52
  _Children$toArray2 = _slicedToArray(_Children$toArray, 1),
@@ -70,21 +66,25 @@ let Head = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class
70
66
  }
71
67
 
72
68
  componentDidMount() {
73
- this.props.makeStyles();
69
+ var _this$props$makeStyle, _this$props;
70
+
71
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
74
72
  }
75
73
 
76
74
  componentDidUpdate() {
75
+ var _this$props$makeStyle2, _this$props2;
76
+
77
77
  if (this.isSortable && typeof this.props.renderSortLabel === 'undefined') {
78
78
  warn(false, '[Table.Head] The `renderSortLabel` prop should be provided when Table is sortable.');
79
79
  }
80
80
 
81
- this.props.makeStyles();
81
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
82
82
  }
83
83
 
84
84
  renderSelect() {
85
- const _this$props = this.props,
86
- children = _this$props.children,
87
- renderSortLabel = _this$props.renderSortLabel;
85
+ const _this$props3 = this.props,
86
+ children = _this$props3.children,
87
+ renderSortLabel = _this$props3.renderSortLabel;
88
88
 
89
89
  const _Children$toArray3 = Children.toArray(children),
90
90
  _Children$toArray4 = _slicedToArray(_Children$toArray3, 1),
@@ -96,7 +96,7 @@ let Head = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class
96
96
 
97
97
  const options = [];
98
98
  const clickHandlers = {};
99
- let selectedOption = null;
99
+ let selectedOption = void 0;
100
100
  let count = 0;
101
101
  Children.forEach(row.props.children, colHeader => {
102
102
  count += 1;
@@ -163,27 +163,16 @@ let Head = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class
163
163
  }
164
164
 
165
165
  render() {
166
- const _this$props2 = this.props,
167
- children = _this$props2.children,
168
- isStacked = _this$props2.isStacked,
169
- styles = _this$props2.styles;
166
+ const _this$props4 = this.props,
167
+ children = _this$props4.children,
168
+ isStacked = _this$props4.isStacked,
169
+ styles = _this$props4.styles;
170
170
  return isStacked ? this.renderSelect() : jsx("thead", Object.assign({}, omitProps(this.props, Head.propTypes), {
171
- css: styles.head
171
+ css: styles === null || styles === void 0 ? void 0 : styles.head
172
172
  }), Children.map(children, child => matchComponentTypes(child, [Row]) ? child : null));
173
173
  }
174
174
 
175
- }, _class2.displayName = "Head", _class2.componentId = 'Table.Head', _class2.propTypes = {
176
- /**
177
- * `Table.Row`
178
- */
179
- // eslint-disable-next-line react/require-default-props
180
- makeStyles: PropTypes.func,
181
- // eslint-disable-next-line react/require-default-props
182
- styles: PropTypes.object,
183
- children: ChildrenPropTypes.oneOf([Row]),
184
- isStacked: PropTypes.bool,
185
- renderSortLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
186
- }, _class2.defaultProps = {
175
+ }, _class2.displayName = "Head", _class2.componentId = 'Table.Head', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
187
176
  children: null
188
177
  }, _temp)) || _class);
189
178
  export default Head;