@instructure/ui-table 8.19.0 → 8.19.1-snapshot.16
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/LICENSE.md +27 -0
- package/es/Table/ColHeader/index.js +7 -6
- package/es/Table/ColHeader/styles.js +5 -0
- package/lib/Table/ColHeader/index.js +8 -5
- package/lib/Table/ColHeader/styles.js +5 -0
- package/package.json +18 -17
- package/src/Table/ColHeader/index.tsx +4 -4
- package/src/Table/ColHeader/props.ts +3 -1
- package/src/Table/ColHeader/styles.ts +5 -0
- package/src/Table/README.md +138 -15
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Table/ColHeader/index.d.ts.map +1 -1
- package/types/Table/ColHeader/props.d.ts +1 -1
- package/types/Table/ColHeader/props.d.ts.map +1 -1
- package/types/Table/ColHeader/styles.d.ts.map +1 -1
package/LICENSE.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
title: The MIT License (MIT)
|
3
|
+
category: Getting Started
|
4
|
+
order: 9
|
5
|
+
---
|
6
|
+
|
7
|
+
# The MIT License (MIT)
|
8
|
+
|
9
|
+
Copyright (c) 2015 Instructure, Inc.
|
10
|
+
|
11
|
+
**Permission is hereby granted, free of charge, to any person obtaining a copy
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
13
|
+
in the Software without restriction, including without limitation the rights
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
16
|
+
furnished to do so, subject to the following conditions.**
|
17
|
+
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
19
|
+
copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
27
|
+
SOFTWARE.
|
@@ -27,7 +27,7 @@ var _dec, _class, _class2, _temp, _IconMiniArrowUpLine, _IconMiniArrowDownLin;
|
|
27
27
|
/** @jsx jsx */
|
28
28
|
import React, { Component } from 'react';
|
29
29
|
import { omitProps, callRenderProp } from '@instructure/ui-react-utils';
|
30
|
-
import { IconMiniArrowUpLine, IconMiniArrowDownLine } from '@instructure/ui-icons';
|
30
|
+
import { IconMiniArrowUpLine, IconMiniArrowDownLine, IconMiniArrowDoubleLine } from '@instructure/ui-icons';
|
31
31
|
import { withStyle, jsx } from '@instructure/emotion';
|
32
32
|
import generateStyle from './styles';
|
33
33
|
import generateComponentTheme from './theme';
|
@@ -80,10 +80,9 @@ let ColHeader = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_
|
|
80
80
|
}
|
81
81
|
|
82
82
|
if (onRequestSort) {
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
color: 'transparent'
|
83
|
+
return jsx(IconMiniArrowDoubleLine, {
|
84
|
+
css: {
|
85
|
+
opacity: '30%'
|
87
86
|
}
|
88
87
|
});
|
89
88
|
}
|
@@ -109,7 +108,9 @@ let ColHeader = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_
|
|
109
108
|
}), onRequestSort && jsx("button", {
|
110
109
|
onClick: this.handleClick,
|
111
110
|
css: styles === null || styles === void 0 ? void 0 : styles.button
|
112
|
-
}, jsx("div",
|
111
|
+
}, jsx("div", {
|
112
|
+
css: styles === null || styles === void 0 ? void 0 : styles.buttonContent
|
113
|
+
}, callRenderProp(children), this.renderSortArrow())), !onRequestSort && children, !onRequestSort && this.renderSortArrow());
|
113
114
|
}
|
114
115
|
|
115
116
|
}, _class2.displayName = "ColHeader", _class2.componentId = 'Table.ColHeader', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
|
@@ -82,6 +82,11 @@ const generateStyle = (componentTheme, props) => {
|
|
82
82
|
outline: `${componentTheme.focusOutlineWidth} ${componentTheme.focusOutlineStyle} ${componentTheme.focusOutlineColor}`
|
83
83
|
},
|
84
84
|
...buttonTextAlignVariants[textAlign]
|
85
|
+
},
|
86
|
+
buttonContent: {
|
87
|
+
label: 'colHeader__buttonContent',
|
88
|
+
display: 'flex',
|
89
|
+
alignItems: 'center'
|
85
90
|
}
|
86
91
|
};
|
87
92
|
};
|
@@ -19,6 +19,8 @@ var _IconMiniArrowUpLine2 = require("@instructure/ui-icons/lib/IconMiniArrowUpLi
|
|
19
19
|
|
20
20
|
var _IconMiniArrowDownLine = require("@instructure/ui-icons/lib/IconMiniArrowDownLine.js");
|
21
21
|
|
22
|
+
var _IconMiniArrowDoubleLine = require("@instructure/ui-icons/lib/IconMiniArrowDoubleLine.js");
|
23
|
+
|
22
24
|
var _emotion = require("@instructure/emotion");
|
23
25
|
|
24
26
|
var _styles = _interopRequireDefault(require("./styles"));
|
@@ -76,10 +78,9 @@ let ColHeader = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default)
|
|
76
78
|
}
|
77
79
|
|
78
80
|
if (onRequestSort) {
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
color: 'transparent'
|
81
|
+
return (0, _emotion.jsx)(_IconMiniArrowDoubleLine.IconMiniArrowDoubleLine, {
|
82
|
+
css: {
|
83
|
+
opacity: '30%'
|
83
84
|
}
|
84
85
|
});
|
85
86
|
}
|
@@ -105,7 +106,9 @@ let ColHeader = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default)
|
|
105
106
|
}), onRequestSort && (0, _emotion.jsx)("button", {
|
106
107
|
onClick: this.handleClick,
|
107
108
|
css: styles === null || styles === void 0 ? void 0 : styles.button
|
108
|
-
}, (0, _emotion.jsx)("div",
|
109
|
+
}, (0, _emotion.jsx)("div", {
|
110
|
+
css: styles === null || styles === void 0 ? void 0 : styles.buttonContent
|
111
|
+
}, (0, _callRenderProp.callRenderProp)(children), this.renderSortArrow())), !onRequestSort && children, !onRequestSort && this.renderSortArrow());
|
109
112
|
}
|
110
113
|
|
111
114
|
}, _class2.displayName = "ColHeader", _class2.componentId = 'Table.ColHeader', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
|
@@ -89,6 +89,11 @@ const generateStyle = (componentTheme, props) => {
|
|
89
89
|
outline: `${componentTheme.focusOutlineWidth} ${componentTheme.focusOutlineStyle} ${componentTheme.focusOutlineColor}`
|
90
90
|
},
|
91
91
|
...buttonTextAlignVariants[textAlign]
|
92
|
+
},
|
93
|
+
buttonContent: {
|
94
|
+
label: 'colHeader__buttonContent',
|
95
|
+
display: 'flex',
|
96
|
+
alignItems: 'center'
|
92
97
|
}
|
93
98
|
};
|
94
99
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instructure/ui-table",
|
3
|
-
"version": "8.19.
|
3
|
+
"version": "8.19.1-snapshot.16+e6d596014",
|
4
4
|
"description": "A styled HTML table component",
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
6
6
|
"module": "./es/index.js",
|
@@ -23,24 +23,24 @@
|
|
23
23
|
},
|
24
24
|
"license": "MIT",
|
25
25
|
"devDependencies": {
|
26
|
-
"@instructure/ui-babel-preset": "8.19.
|
27
|
-
"@instructure/ui-color-utils": "8.19.
|
28
|
-
"@instructure/ui-test-utils": "8.19.
|
29
|
-
"@instructure/ui-themes": "8.19.
|
26
|
+
"@instructure/ui-babel-preset": "8.19.1-snapshot.16+e6d596014",
|
27
|
+
"@instructure/ui-color-utils": "8.19.1-snapshot.16+e6d596014",
|
28
|
+
"@instructure/ui-test-utils": "8.19.1-snapshot.16+e6d596014",
|
29
|
+
"@instructure/ui-themes": "8.19.1-snapshot.16+e6d596014"
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
32
|
"@babel/runtime": "^7.13.10",
|
33
|
-
"@instructure/console": "8.19.
|
34
|
-
"@instructure/emotion": "8.19.
|
35
|
-
"@instructure/shared-types": "8.19.
|
36
|
-
"@instructure/ui-a11y-content": "8.19.
|
37
|
-
"@instructure/ui-icons": "8.19.
|
38
|
-
"@instructure/ui-prop-types": "8.19.
|
39
|
-
"@instructure/ui-react-utils": "8.19.
|
40
|
-
"@instructure/ui-simple-select": "8.19.
|
41
|
-
"@instructure/ui-testable": "8.19.
|
42
|
-
"@instructure/ui-utils": "8.19.
|
43
|
-
"@instructure/ui-view": "8.19.
|
33
|
+
"@instructure/console": "8.19.1-snapshot.16+e6d596014",
|
34
|
+
"@instructure/emotion": "8.19.1-snapshot.16+e6d596014",
|
35
|
+
"@instructure/shared-types": "8.19.1-snapshot.16+e6d596014",
|
36
|
+
"@instructure/ui-a11y-content": "8.19.1-snapshot.16+e6d596014",
|
37
|
+
"@instructure/ui-icons": "8.19.1-snapshot.16+e6d596014",
|
38
|
+
"@instructure/ui-prop-types": "8.19.1-snapshot.16+e6d596014",
|
39
|
+
"@instructure/ui-react-utils": "8.19.1-snapshot.16+e6d596014",
|
40
|
+
"@instructure/ui-simple-select": "8.19.1-snapshot.16+e6d596014",
|
41
|
+
"@instructure/ui-testable": "8.19.1-snapshot.16+e6d596014",
|
42
|
+
"@instructure/ui-utils": "8.19.1-snapshot.16+e6d596014",
|
43
|
+
"@instructure/ui-view": "8.19.1-snapshot.16+e6d596014",
|
44
44
|
"prop-types": "^15"
|
45
45
|
},
|
46
46
|
"peerDependencies": {
|
@@ -49,5 +49,6 @@
|
|
49
49
|
"publishConfig": {
|
50
50
|
"access": "public"
|
51
51
|
},
|
52
|
-
"sideEffects": false
|
52
|
+
"sideEffects": false,
|
53
|
+
"gitHead": "e6d5960140f65290f1f80fd9e90f291d3b284ae7"
|
53
54
|
}
|
@@ -28,7 +28,8 @@ import React, { Component } from 'react'
|
|
28
28
|
import { omitProps, callRenderProp } from '@instructure/ui-react-utils'
|
29
29
|
import {
|
30
30
|
IconMiniArrowUpLine,
|
31
|
-
IconMiniArrowDownLine
|
31
|
+
IconMiniArrowDownLine,
|
32
|
+
IconMiniArrowDoubleLine
|
32
33
|
} from '@instructure/ui-icons'
|
33
34
|
|
34
35
|
import { withStyle, jsx } from '@instructure/emotion'
|
@@ -83,8 +84,7 @@ class ColHeader extends Component<TableColHeaderProps> {
|
|
83
84
|
return <IconMiniArrowDownLine />
|
84
85
|
}
|
85
86
|
if (onRequestSort) {
|
86
|
-
|
87
|
-
return <IconMiniArrowUpLine style={{ color: 'transparent' }} />
|
87
|
+
return <IconMiniArrowDoubleLine css={{ opacity: '30%' }} />
|
88
88
|
}
|
89
89
|
return null
|
90
90
|
}
|
@@ -105,7 +105,7 @@ class ColHeader extends Component<TableColHeaderProps> {
|
|
105
105
|
>
|
106
106
|
{onRequestSort && (
|
107
107
|
<button onClick={this.handleClick} css={styles?.button}>
|
108
|
-
<div>
|
108
|
+
<div css={styles?.buttonContent}>
|
109
109
|
{callRenderProp(children)}
|
110
110
|
{this.renderSortArrow()}
|
111
111
|
</div>
|
@@ -80,7 +80,9 @@ type TableColHeaderProps = TableColHeaderOwnProps &
|
|
80
80
|
ThHTMLAttributes<TableColHeaderOwnProps>
|
81
81
|
>
|
82
82
|
|
83
|
-
type TableColHeaderStyle = ComponentStyle<
|
83
|
+
type TableColHeaderStyle = ComponentStyle<
|
84
|
+
'colHeader' | 'button' | 'buttonContent'
|
85
|
+
>
|
84
86
|
|
85
87
|
const propTypes: PropValidators<PropKeys> = {
|
86
88
|
id: PropTypes.string.isRequired,
|
@@ -82,6 +82,11 @@ const generateStyle = (
|
|
82
82
|
outline: `${componentTheme.focusOutlineWidth} ${componentTheme.focusOutlineStyle} ${componentTheme.focusOutlineColor}`
|
83
83
|
},
|
84
84
|
...buttonTextAlignVariants[textAlign!]
|
85
|
+
},
|
86
|
+
buttonContent: {
|
87
|
+
label: 'colHeader__buttonContent',
|
88
|
+
display: 'flex',
|
89
|
+
alignItems: 'center'
|
85
90
|
}
|
86
91
|
}
|
87
92
|
}
|
package/src/Table/README.md
CHANGED
@@ -254,9 +254,15 @@ class SortableTable extends React.Component {
|
|
254
254
|
super(props)
|
255
255
|
const { headers } = props
|
256
256
|
|
257
|
+
const initialColWidth = {}
|
258
|
+
headers.forEach((header) => {
|
259
|
+
initialColWidth[header.id] = 'start'
|
260
|
+
})
|
261
|
+
|
257
262
|
this.state = {
|
258
263
|
sortBy: headers && headers[0] && headers[0].id,
|
259
264
|
ascending: true,
|
265
|
+
colTextAligns: initialColWidth
|
260
266
|
}
|
261
267
|
}
|
262
268
|
|
@@ -275,9 +281,128 @@ class SortableTable extends React.Component {
|
|
275
281
|
}
|
276
282
|
}
|
277
283
|
|
284
|
+
handleColTextAlignChange(id, value) {
|
285
|
+
this.setState(state => ({
|
286
|
+
colTextAligns: {
|
287
|
+
...state.colTextAligns,
|
288
|
+
[id]: value
|
289
|
+
}
|
290
|
+
}))
|
291
|
+
}
|
292
|
+
|
293
|
+
renderHeaderRow(direction) {
|
294
|
+
const { headers } = this.props
|
295
|
+
const { colTextAligns , sortBy } = this.state
|
296
|
+
|
297
|
+
return (
|
298
|
+
<Table.Row>
|
299
|
+
{(headers || []).map(({ id, text, width }) => (
|
300
|
+
<Table.ColHeader
|
301
|
+
key={id}
|
302
|
+
id={id}
|
303
|
+
width={width}
|
304
|
+
{...(direction && {
|
305
|
+
textAlign: colTextAligns[id],
|
306
|
+
stackedSortByLabel: text,
|
307
|
+
onRequestSort: this.handleSort,
|
308
|
+
sortDirection: id === sortBy ? direction : 'none'
|
309
|
+
})}
|
310
|
+
>
|
311
|
+
{text}
|
312
|
+
</Table.ColHeader>
|
313
|
+
))}
|
314
|
+
</Table.Row>
|
315
|
+
)
|
316
|
+
}
|
317
|
+
|
318
|
+
renderOptions () {
|
319
|
+
const { headers } = this.props
|
320
|
+
const { colTextAligns } = this.state
|
321
|
+
|
322
|
+
return (
|
323
|
+
<ToggleGroup
|
324
|
+
size="small"
|
325
|
+
toggleLabel="Set text-align for columns"
|
326
|
+
summary="Set text-align for columns"
|
327
|
+
background="default"
|
328
|
+
>
|
329
|
+
<Table caption='Set text-align for columns'>
|
330
|
+
<Table.Head>
|
331
|
+
{this.renderHeaderRow()}
|
332
|
+
</Table.Head>
|
333
|
+
<Table.Body>
|
334
|
+
<Table.Row>
|
335
|
+
{Object.entries(colTextAligns).map(([headerId, textAlign]) => {
|
336
|
+
return (
|
337
|
+
<Table.Cell
|
338
|
+
key={headerId}
|
339
|
+
width={headers.find(header => header.id === headerId).width}
|
340
|
+
>
|
341
|
+
<RadioInputGroup
|
342
|
+
description={
|
343
|
+
<ScreenReaderContent>
|
344
|
+
Set text-align for column: {headerId}
|
345
|
+
</ScreenReaderContent>
|
346
|
+
}
|
347
|
+
name={`columnTextAlign_${headerId}`}
|
348
|
+
value={textAlign}
|
349
|
+
margin="0 0 small"
|
350
|
+
size="small"
|
351
|
+
onChange={
|
352
|
+
(e, value) => this.handleColTextAlignChange(headerId, value)
|
353
|
+
}
|
354
|
+
>
|
355
|
+
<RadioInput label="start" value="start" />
|
356
|
+
<RadioInput label="center" value="center" />
|
357
|
+
<RadioInput label="end" value="end" />
|
358
|
+
</RadioInputGroup>
|
359
|
+
</Table.Cell>
|
360
|
+
)
|
361
|
+
})}
|
362
|
+
</Table.Row>
|
363
|
+
</Table.Body>
|
364
|
+
</Table>
|
365
|
+
</ToggleGroup>
|
366
|
+
)
|
367
|
+
|
368
|
+
return (
|
369
|
+
<FormField id="columnTextAlign" label="Set column text-align">
|
370
|
+
<Flex margin="0 0 medium">
|
371
|
+
{Object.entries(colTextAligns).map(([headerId, textAlign]) => {
|
372
|
+
return (
|
373
|
+
<Flex.Item
|
374
|
+
key={headerId}
|
375
|
+
width={headers.find(header => header.id === headerId).width}
|
376
|
+
>
|
377
|
+
<RadioInputGroup
|
378
|
+
description={
|
379
|
+
<ScreenReaderContent>
|
380
|
+
Column {headerId}textAlign
|
381
|
+
</ScreenReaderContent>
|
382
|
+
}
|
383
|
+
name={`Column "${headerId}" textAlign`}
|
384
|
+
value={textAlign}
|
385
|
+
margin="0 0 small"
|
386
|
+
size="small"
|
387
|
+
onChange={
|
388
|
+
(e, value) => this.handleColTextAlignChange(headerId, value)
|
389
|
+
}
|
390
|
+
>
|
391
|
+
<RadioInput label="start" value="start" />
|
392
|
+
<RadioInput label="center" value="center" />
|
393
|
+
<RadioInput label="end" value="end" />
|
394
|
+
</RadioInputGroup>
|
395
|
+
</Flex.Item>
|
396
|
+
)
|
397
|
+
})}
|
398
|
+
</Flex>
|
399
|
+
</FormField>
|
400
|
+
)
|
401
|
+
}
|
402
|
+
|
278
403
|
render() {
|
279
404
|
const { caption, headers, rows } = this.props
|
280
|
-
const { sortBy, ascending } = this.state
|
405
|
+
const { sortBy, ascending, colTextAligns } = this.state
|
281
406
|
const direction = ascending ? 'ascending' : 'descending'
|
282
407
|
const sortedRows = [...(rows || [])].sort((a, b) => {
|
283
408
|
if (a[sortBy] < b[sortBy]) {
|
@@ -305,30 +430,24 @@ class SortableTable extends React.Component {
|
|
305
430
|
>
|
306
431
|
{(props) => (
|
307
432
|
<div>
|
433
|
+
{props.layout !== 'stacked' && (
|
434
|
+
<View display="block" margin="0 0 medium">
|
435
|
+
{this.renderOptions()}
|
436
|
+
</View>
|
437
|
+
)}
|
438
|
+
|
308
439
|
<Table
|
309
440
|
caption={`${caption}: sorted by ${sortBy} in ${direction} order`}
|
310
441
|
{...props}
|
311
442
|
>
|
312
443
|
<Table.Head renderSortLabel="Sort by">
|
313
|
-
|
314
|
-
{(headers || []).map(({ id, text }) => (
|
315
|
-
<Table.ColHeader
|
316
|
-
key={id}
|
317
|
-
id={id}
|
318
|
-
stackedSortByLabel={text}
|
319
|
-
onRequestSort={this.handleSort}
|
320
|
-
sortDirection={id === sortBy ? direction : 'none'}
|
321
|
-
>
|
322
|
-
{text}
|
323
|
-
</Table.ColHeader>
|
324
|
-
))}
|
325
|
-
</Table.Row>
|
444
|
+
{this.renderHeaderRow(direction)}
|
326
445
|
</Table.Head>
|
327
446
|
<Table.Body>
|
328
447
|
{sortedRows.map((row) => (
|
329
448
|
<Table.Row key={row.id}>
|
330
449
|
{headers.map(({ id, renderCell }) => (
|
331
|
-
<Table.Cell key={id}>
|
450
|
+
<Table.Cell key={id} textAlign={colTextAligns[id]}>
|
332
451
|
{renderCell ? renderCell(row[id]) : row[id]}
|
333
452
|
</Table.Cell>
|
334
453
|
))}
|
@@ -357,18 +476,22 @@ render(
|
|
357
476
|
{
|
358
477
|
id: 'rank',
|
359
478
|
text: 'Rank',
|
479
|
+
width: '15%',
|
360
480
|
},
|
361
481
|
{
|
362
482
|
id: 'title',
|
363
483
|
text: 'Title',
|
484
|
+
width: '55%',
|
364
485
|
},
|
365
486
|
{
|
366
487
|
id: 'year',
|
367
488
|
text: 'Year',
|
489
|
+
width: '15%',
|
368
490
|
},
|
369
491
|
{
|
370
492
|
id: 'rating',
|
371
493
|
text: 'Rating',
|
494
|
+
width: '15%',
|
372
495
|
renderCell: (rating) => rating.toFixed(1),
|
373
496
|
},
|
374
497
|
]}
|