@instructure/ui-table 11.6.0 → 11.6.1-snapshot-129
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 +43 -308
- package/es/Table/{Body → v1/Body}/index.js +2 -2
- package/es/Table/{Cell → v1/Cell}/index.js +2 -2
- package/es/Table/{ColHeader → v1/ColHeader}/index.js +1 -1
- package/es/Table/{Head → v1/Head}/index.js +2 -2
- package/es/Table/{Row → v1/Row}/index.js +2 -2
- package/es/Table/{RowHeader → v1/RowHeader}/index.js +2 -2
- package/es/Table/{index.js → v1/index.js} +2 -2
- package/es/Table/v2/Body/index.js +73 -0
- package/es/Table/v2/Body/props.js +26 -0
- package/es/Table/v2/Body/styles.js +45 -0
- package/es/Table/v2/Cell/index.js +68 -0
- package/es/Table/v2/Cell/props.js +26 -0
- package/es/Table/v2/Cell/styles.js +54 -0
- package/es/Table/v2/ColHeader/index.js +117 -0
- package/es/Table/v2/ColHeader/props.js +26 -0
- package/es/Table/v2/ColHeader/styles.js +93 -0
- package/es/Table/v2/Head/index.js +173 -0
- package/es/Table/v2/Head/props.js +26 -0
- package/es/Table/v2/Head/styles.js +45 -0
- package/es/Table/v2/Row/index.js +82 -0
- package/es/Table/v2/Row/props.js +26 -0
- package/es/Table/v2/Row/styles.js +67 -0
- package/es/Table/v2/RowHeader/index.js +68 -0
- package/es/Table/v2/RowHeader/props.js +26 -0
- package/es/Table/v2/RowHeader/styles.js +54 -0
- package/es/Table/v2/TableContext.js +46 -0
- package/es/Table/v2/index.js +135 -0
- package/es/Table/v2/props.js +26 -0
- package/es/Table/v2/styles.js +58 -0
- package/es/exports/a.js +31 -0
- package/es/exports/b.js +31 -0
- package/lib/Table/{Body → v1/Body}/index.js +4 -4
- package/lib/Table/{Cell → v1/Cell}/index.js +4 -4
- package/lib/Table/{ColHeader → v1/ColHeader}/index.js +4 -4
- package/lib/Table/{Head → v1/Head}/index.js +5 -5
- package/lib/Table/{Row → v1/Row}/index.js +4 -4
- package/lib/Table/{RowHeader → v1/RowHeader}/index.js +4 -4
- package/lib/Table/{index.js → v1/index.js} +4 -4
- package/lib/Table/v2/Body/index.js +79 -0
- package/lib/Table/v2/Body/props.js +31 -0
- package/lib/Table/v2/Body/styles.js +51 -0
- package/lib/Table/v2/Cell/index.js +74 -0
- package/lib/Table/v2/Cell/props.js +31 -0
- package/lib/Table/v2/Cell/styles.js +60 -0
- package/lib/Table/v2/ColHeader/index.js +122 -0
- package/lib/Table/v2/ColHeader/props.js +31 -0
- package/lib/Table/v2/ColHeader/styles.js +99 -0
- package/lib/Table/v2/Head/index.js +179 -0
- package/lib/Table/v2/Head/props.js +31 -0
- package/lib/Table/v2/Head/styles.js +51 -0
- package/lib/Table/v2/Row/index.js +88 -0
- package/lib/Table/v2/Row/props.js +31 -0
- package/lib/Table/v2/Row/styles.js +73 -0
- package/lib/Table/v2/RowHeader/index.js +74 -0
- package/lib/Table/v2/RowHeader/props.js +31 -0
- package/lib/Table/v2/RowHeader/styles.js +60 -0
- package/lib/Table/v2/TableContext.js +51 -0
- package/lib/Table/v2/index.js +140 -0
- package/lib/Table/v2/props.js +31 -0
- package/lib/Table/v2/styles.js +64 -0
- package/lib/{index.js → exports/a.js} +9 -9
- package/lib/exports/b.js +61 -0
- package/package.json +43 -21
- package/src/Table/{Body → v1/Body}/index.tsx +2 -2
- package/src/Table/{Cell → v1/Cell}/index.tsx +2 -2
- package/src/Table/{ColHeader → v1/ColHeader}/index.tsx +1 -1
- package/src/Table/{Head → v1/Head}/index.tsx +3 -3
- package/src/Table/{README.md → v1/README.md} +1 -1
- package/src/Table/{Row → v1/Row}/index.tsx +2 -2
- package/src/Table/{RowHeader → v1/RowHeader}/index.tsx +2 -2
- package/src/Table/{index.tsx → v1/index.tsx} +2 -2
- package/src/Table/v2/Body/index.tsx +91 -0
- package/src/Table/v2/Body/props.ts +50 -0
- package/src/Table/v2/Body/styles.ts +51 -0
- package/src/Table/v2/Cell/index.tsx +83 -0
- package/src/Table/v2/Cell/props.ts +54 -0
- package/src/Table/v2/Cell/styles.ts +60 -0
- package/src/Table/v2/ColHeader/index.tsx +118 -0
- package/src/Table/v2/ColHeader/props.ts +93 -0
- package/src/Table/v2/ColHeader/styles.ts +95 -0
- package/src/Table/v2/Head/index.tsx +200 -0
- package/src/Table/v2/Head/props.ts +64 -0
- package/src/Table/v2/Head/styles.ts +51 -0
- package/src/Table/v2/README.md +1155 -0
- package/src/Table/v2/Row/index.tsx +105 -0
- package/src/Table/v2/Row/props.ts +67 -0
- package/src/Table/v2/Row/styles.ts +78 -0
- package/src/Table/v2/RowHeader/index.tsx +84 -0
- package/src/Table/v2/RowHeader/props.ts +48 -0
- package/src/Table/v2/RowHeader/styles.ts +60 -0
- package/src/Table/v2/TableContext.ts +66 -0
- package/src/Table/v2/index.tsx +160 -0
- package/src/Table/v2/props.ts +98 -0
- package/src/Table/v2/styles.ts +63 -0
- package/src/exports/a.ts +39 -0
- package/src/exports/b.ts +39 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Table/v1/Body/index.d.ts.map +1 -0
- package/types/Table/v1/Body/props.d.ts.map +1 -0
- package/types/Table/v1/Body/styles.d.ts.map +1 -0
- package/types/Table/v1/Body/theme.d.ts.map +1 -0
- package/types/Table/v1/Cell/index.d.ts.map +1 -0
- package/types/Table/v1/Cell/props.d.ts.map +1 -0
- package/types/Table/v1/Cell/styles.d.ts.map +1 -0
- package/types/Table/v1/Cell/theme.d.ts.map +1 -0
- package/types/Table/v1/ColHeader/index.d.ts.map +1 -0
- package/types/Table/v1/ColHeader/props.d.ts.map +1 -0
- package/types/Table/v1/ColHeader/styles.d.ts.map +1 -0
- package/types/Table/v1/ColHeader/theme.d.ts.map +1 -0
- package/types/Table/v1/Head/index.d.ts.map +1 -0
- package/types/Table/v1/Head/props.d.ts.map +1 -0
- package/types/Table/v1/Head/styles.d.ts.map +1 -0
- package/types/Table/v1/Head/theme.d.ts.map +1 -0
- package/types/Table/v1/Row/index.d.ts.map +1 -0
- package/types/Table/v1/Row/props.d.ts.map +1 -0
- package/types/Table/v1/Row/styles.d.ts.map +1 -0
- package/types/Table/v1/Row/theme.d.ts.map +1 -0
- package/types/Table/v1/RowHeader/index.d.ts.map +1 -0
- package/types/Table/v1/RowHeader/props.d.ts.map +1 -0
- package/types/Table/v1/RowHeader/styles.d.ts.map +1 -0
- package/types/Table/v1/RowHeader/theme.d.ts.map +1 -0
- package/types/Table/v1/TableContext.d.ts.map +1 -0
- package/types/Table/v1/index.d.ts.map +1 -0
- package/types/Table/v1/props.d.ts.map +1 -0
- package/types/Table/v1/styles.d.ts.map +1 -0
- package/types/Table/v1/theme.d.ts.map +1 -0
- package/types/Table/v2/Body/index.d.ts +24 -0
- package/types/Table/v2/Body/index.d.ts.map +1 -0
- package/types/Table/v2/Body/props.d.ts +20 -0
- package/types/Table/v2/Body/props.d.ts.map +1 -0
- package/types/Table/v2/Body/styles.d.ts +13 -0
- package/types/Table/v2/Body/styles.d.ts.map +1 -0
- package/types/Table/v2/Cell/index.d.ts +29 -0
- package/types/Table/v2/Cell/index.d.ts.map +1 -0
- package/types/Table/v2/Cell/props.d.ts +23 -0
- package/types/Table/v2/Cell/props.d.ts.map +1 -0
- package/types/Table/v2/Cell/styles.d.ts +14 -0
- package/types/Table/v2/Cell/styles.d.ts.map +1 -0
- package/types/Table/v2/ColHeader/index.d.ts +37 -0
- package/types/Table/v2/ColHeader/index.d.ts.map +1 -0
- package/types/Table/v2/ColHeader/props.d.ts +47 -0
- package/types/Table/v2/ColHeader/props.d.ts.map +1 -0
- package/types/Table/v2/ColHeader/styles.d.ts +15 -0
- package/types/Table/v2/ColHeader/styles.d.ts.map +1 -0
- package/types/Table/v2/Head/index.d.ts +38 -0
- package/types/Table/v2/Head/index.d.ts.map +1 -0
- package/types/Table/v2/Head/props.d.ts +34 -0
- package/types/Table/v2/Head/props.d.ts.map +1 -0
- package/types/Table/v2/Head/styles.d.ts +13 -0
- package/types/Table/v2/Head/styles.d.ts.map +1 -0
- package/types/Table/v2/Row/index.d.ts +27 -0
- package/types/Table/v2/Row/index.d.ts.map +1 -0
- package/types/Table/v2/Row/props.d.ts +29 -0
- package/types/Table/v2/Row/props.d.ts.map +1 -0
- package/types/Table/v2/Row/styles.d.ts +19 -0
- package/types/Table/v2/Row/styles.d.ts.map +1 -0
- package/types/Table/v2/RowHeader/index.d.ts +28 -0
- package/types/Table/v2/RowHeader/index.d.ts.map +1 -0
- package/types/Table/v2/RowHeader/props.d.ts +17 -0
- package/types/Table/v2/RowHeader/props.d.ts.map +1 -0
- package/types/Table/v2/RowHeader/styles.d.ts +14 -0
- package/types/Table/v2/RowHeader/styles.d.ts.map +1 -0
- package/types/Table/v2/TableContext.d.ts +36 -0
- package/types/Table/v2/TableContext.d.ts.map +1 -0
- package/types/Table/v2/index.d.ts +45 -0
- package/types/Table/v2/index.d.ts.map +1 -0
- package/types/Table/v2/props.d.ts +53 -0
- package/types/Table/v2/props.d.ts.map +1 -0
- package/types/Table/v2/styles.d.ts +15 -0
- package/types/Table/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +16 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +16 -0
- package/types/exports/b.d.ts.map +1 -0
- package/es/index.js +0 -31
- package/src/index.ts +0 -39
- package/types/Table/Body/index.d.ts.map +0 -1
- package/types/Table/Body/props.d.ts.map +0 -1
- package/types/Table/Body/styles.d.ts.map +0 -1
- package/types/Table/Body/theme.d.ts.map +0 -1
- package/types/Table/Cell/index.d.ts.map +0 -1
- package/types/Table/Cell/props.d.ts.map +0 -1
- package/types/Table/Cell/styles.d.ts.map +0 -1
- package/types/Table/Cell/theme.d.ts.map +0 -1
- package/types/Table/ColHeader/index.d.ts.map +0 -1
- package/types/Table/ColHeader/props.d.ts.map +0 -1
- package/types/Table/ColHeader/styles.d.ts.map +0 -1
- package/types/Table/ColHeader/theme.d.ts.map +0 -1
- package/types/Table/Head/index.d.ts.map +0 -1
- package/types/Table/Head/props.d.ts.map +0 -1
- package/types/Table/Head/styles.d.ts.map +0 -1
- package/types/Table/Head/theme.d.ts.map +0 -1
- package/types/Table/Row/index.d.ts.map +0 -1
- package/types/Table/Row/props.d.ts.map +0 -1
- package/types/Table/Row/styles.d.ts.map +0 -1
- package/types/Table/Row/theme.d.ts.map +0 -1
- package/types/Table/RowHeader/index.d.ts.map +0 -1
- package/types/Table/RowHeader/props.d.ts.map +0 -1
- package/types/Table/RowHeader/styles.d.ts.map +0 -1
- package/types/Table/RowHeader/theme.d.ts.map +0 -1
- package/types/Table/TableContext.d.ts.map +0 -1
- package/types/Table/index.d.ts.map +0 -1
- package/types/Table/props.d.ts.map +0 -1
- package/types/Table/styles.d.ts.map +0 -1
- package/types/Table/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -16
- package/types/index.d.ts.map +0 -1
- /package/es/Table/{Body → v1/Body}/props.js +0 -0
- /package/es/Table/{Body → v1/Body}/styles.js +0 -0
- /package/es/Table/{Body → v1/Body}/theme.js +0 -0
- /package/es/Table/{Cell → v1/Cell}/props.js +0 -0
- /package/es/Table/{Cell → v1/Cell}/styles.js +0 -0
- /package/es/Table/{Cell → v1/Cell}/theme.js +0 -0
- /package/es/Table/{ColHeader → v1/ColHeader}/props.js +0 -0
- /package/es/Table/{ColHeader → v1/ColHeader}/styles.js +0 -0
- /package/es/Table/{ColHeader → v1/ColHeader}/theme.js +0 -0
- /package/es/Table/{Head → v1/Head}/props.js +0 -0
- /package/es/Table/{Head → v1/Head}/styles.js +0 -0
- /package/es/Table/{Head → v1/Head}/theme.js +0 -0
- /package/es/Table/{Row → v1/Row}/props.js +0 -0
- /package/es/Table/{Row → v1/Row}/styles.js +0 -0
- /package/es/Table/{Row → v1/Row}/theme.js +0 -0
- /package/es/Table/{RowHeader → v1/RowHeader}/props.js +0 -0
- /package/es/Table/{RowHeader → v1/RowHeader}/styles.js +0 -0
- /package/es/Table/{RowHeader → v1/RowHeader}/theme.js +0 -0
- /package/es/Table/{TableContext.js → v1/TableContext.js} +0 -0
- /package/es/Table/{props.js → v1/props.js} +0 -0
- /package/es/Table/{styles.js → v1/styles.js} +0 -0
- /package/es/Table/{theme.js → v1/theme.js} +0 -0
- /package/lib/Table/{Body → v1/Body}/props.js +0 -0
- /package/lib/Table/{Body → v1/Body}/styles.js +0 -0
- /package/lib/Table/{Body → v1/Body}/theme.js +0 -0
- /package/lib/Table/{Cell → v1/Cell}/props.js +0 -0
- /package/lib/Table/{Cell → v1/Cell}/styles.js +0 -0
- /package/lib/Table/{Cell → v1/Cell}/theme.js +0 -0
- /package/lib/Table/{ColHeader → v1/ColHeader}/props.js +0 -0
- /package/lib/Table/{ColHeader → v1/ColHeader}/styles.js +0 -0
- /package/lib/Table/{ColHeader → v1/ColHeader}/theme.js +0 -0
- /package/lib/Table/{Head → v1/Head}/props.js +0 -0
- /package/lib/Table/{Head → v1/Head}/styles.js +0 -0
- /package/lib/Table/{Head → v1/Head}/theme.js +0 -0
- /package/lib/Table/{Row → v1/Row}/props.js +0 -0
- /package/lib/Table/{Row → v1/Row}/styles.js +0 -0
- /package/lib/Table/{Row → v1/Row}/theme.js +0 -0
- /package/lib/Table/{RowHeader → v1/RowHeader}/props.js +0 -0
- /package/lib/Table/{RowHeader → v1/RowHeader}/styles.js +0 -0
- /package/lib/Table/{RowHeader → v1/RowHeader}/theme.js +0 -0
- /package/lib/Table/{TableContext.js → v1/TableContext.js} +0 -0
- /package/lib/Table/{props.js → v1/props.js} +0 -0
- /package/lib/Table/{styles.js → v1/styles.js} +0 -0
- /package/lib/Table/{theme.js → v1/theme.js} +0 -0
- /package/src/Table/{Body → v1/Body}/props.ts +0 -0
- /package/src/Table/{Body → v1/Body}/styles.ts +0 -0
- /package/src/Table/{Body → v1/Body}/theme.ts +0 -0
- /package/src/Table/{Cell → v1/Cell}/props.ts +0 -0
- /package/src/Table/{Cell → v1/Cell}/styles.ts +0 -0
- /package/src/Table/{Cell → v1/Cell}/theme.ts +0 -0
- /package/src/Table/{ColHeader → v1/ColHeader}/props.ts +0 -0
- /package/src/Table/{ColHeader → v1/ColHeader}/styles.ts +0 -0
- /package/src/Table/{ColHeader → v1/ColHeader}/theme.ts +0 -0
- /package/src/Table/{Head → v1/Head}/props.ts +0 -0
- /package/src/Table/{Head → v1/Head}/styles.ts +0 -0
- /package/src/Table/{Head → v1/Head}/theme.ts +0 -0
- /package/src/Table/{Row → v1/Row}/props.ts +0 -0
- /package/src/Table/{Row → v1/Row}/styles.ts +0 -0
- /package/src/Table/{Row → v1/Row}/theme.ts +0 -0
- /package/src/Table/{RowHeader → v1/RowHeader}/props.ts +0 -0
- /package/src/Table/{RowHeader → v1/RowHeader}/styles.ts +0 -0
- /package/src/Table/{RowHeader → v1/RowHeader}/theme.ts +0 -0
- /package/src/Table/{TableContext.ts → v1/TableContext.ts} +0 -0
- /package/src/Table/{props.ts → v1/props.ts} +0 -0
- /package/src/Table/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Table/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Table/{Body → v1/Body}/index.d.ts +0 -0
- /package/types/Table/{Body → v1/Body}/props.d.ts +0 -0
- /package/types/Table/{Body → v1/Body}/styles.d.ts +0 -0
- /package/types/Table/{Body → v1/Body}/theme.d.ts +0 -0
- /package/types/Table/{Cell → v1/Cell}/index.d.ts +0 -0
- /package/types/Table/{Cell → v1/Cell}/props.d.ts +0 -0
- /package/types/Table/{Cell → v1/Cell}/styles.d.ts +0 -0
- /package/types/Table/{Cell → v1/Cell}/theme.d.ts +0 -0
- /package/types/Table/{ColHeader → v1/ColHeader}/index.d.ts +0 -0
- /package/types/Table/{ColHeader → v1/ColHeader}/props.d.ts +0 -0
- /package/types/Table/{ColHeader → v1/ColHeader}/styles.d.ts +0 -0
- /package/types/Table/{ColHeader → v1/ColHeader}/theme.d.ts +0 -0
- /package/types/Table/{Head → v1/Head}/index.d.ts +0 -0
- /package/types/Table/{Head → v1/Head}/props.d.ts +0 -0
- /package/types/Table/{Head → v1/Head}/styles.d.ts +0 -0
- /package/types/Table/{Head → v1/Head}/theme.d.ts +0 -0
- /package/types/Table/{Row → v1/Row}/index.d.ts +0 -0
- /package/types/Table/{Row → v1/Row}/props.d.ts +0 -0
- /package/types/Table/{Row → v1/Row}/styles.d.ts +0 -0
- /package/types/Table/{Row → v1/Row}/theme.d.ts +0 -0
- /package/types/Table/{RowHeader → v1/RowHeader}/index.d.ts +0 -0
- /package/types/Table/{RowHeader → v1/RowHeader}/props.d.ts +0 -0
- /package/types/Table/{RowHeader → v1/RowHeader}/styles.d.ts +0 -0
- /package/types/Table/{RowHeader → v1/RowHeader}/theme.d.ts +0 -0
- /package/types/Table/{TableContext.d.ts → v1/TableContext.d.ts} +0 -0
- /package/types/Table/{index.d.ts → v1/index.d.ts} +0 -0
- /package/types/Table/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/Table/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Table/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
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 {
|
|
26
|
+
Component,
|
|
27
|
+
Children,
|
|
28
|
+
ContextType,
|
|
29
|
+
isValidElement,
|
|
30
|
+
type ReactElement
|
|
31
|
+
} from 'react'
|
|
32
|
+
|
|
33
|
+
import { omitProps, safeCloneElement } from '@instructure/ui-react-utils'
|
|
34
|
+
import { View } from '@instructure/ui-view/latest'
|
|
35
|
+
|
|
36
|
+
import { withStyle } from '@instructure/emotion'
|
|
37
|
+
|
|
38
|
+
import generateStyle from './styles'
|
|
39
|
+
|
|
40
|
+
import type { TableRowProps } from './props'
|
|
41
|
+
import { allowedProps } from './props'
|
|
42
|
+
import TableContext from '../TableContext'
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
---
|
|
46
|
+
parent: Table
|
|
47
|
+
id: Table.Row
|
|
48
|
+
---
|
|
49
|
+
**/
|
|
50
|
+
@withStyle(generateStyle)
|
|
51
|
+
class Row extends Component<TableRowProps> {
|
|
52
|
+
static readonly componentId = 'Table.Row'
|
|
53
|
+
static contextType = TableContext
|
|
54
|
+
declare context: ContextType<typeof TableContext>
|
|
55
|
+
static allowedProps = allowedProps
|
|
56
|
+
|
|
57
|
+
static defaultProps = {
|
|
58
|
+
children: null
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
componentDidMount() {
|
|
62
|
+
this.props.makeStyles?.({
|
|
63
|
+
isStacked: this.context.isStacked,
|
|
64
|
+
hover: this.context.hover
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
componentDidUpdate() {
|
|
69
|
+
this.props.makeStyles?.({
|
|
70
|
+
isStacked: this.context.isStacked,
|
|
71
|
+
hover: this.context.hover
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
render() {
|
|
76
|
+
const { children, styles } = this.props
|
|
77
|
+
const isStacked = this.context.isStacked
|
|
78
|
+
const headers = this.context.headers
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<View
|
|
82
|
+
{...View.omitViewProps(omitProps(this.props, Row.allowedProps), Row)}
|
|
83
|
+
as={isStacked ? 'div' : 'tr'}
|
|
84
|
+
css={styles?.row}
|
|
85
|
+
role={isStacked ? 'row' : undefined}
|
|
86
|
+
>
|
|
87
|
+
{Children.toArray(children)
|
|
88
|
+
.filter(Boolean)
|
|
89
|
+
.map((child, index) => {
|
|
90
|
+
if (isValidElement(child)) {
|
|
91
|
+
return safeCloneElement(child, {
|
|
92
|
+
key: (child as ReactElement<any>).props.name,
|
|
93
|
+
// used by `Cell` to render its column title in `stacked` layout
|
|
94
|
+
header: headers && headers[index]
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
return child
|
|
98
|
+
})}
|
|
99
|
+
</View>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export default Row
|
|
105
|
+
export { Row }
|
|
@@ -0,0 +1,67 @@
|
|
|
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 type { OtherHTMLAttributes } from '@instructure/shared-types'
|
|
27
|
+
import type { ComponentStyle, WithStyleProps } from '@instructure/emotion'
|
|
28
|
+
|
|
29
|
+
type TableRowOwnProps = {
|
|
30
|
+
/**
|
|
31
|
+
* A row's children should be table cells. Its children should have the
|
|
32
|
+
* `header` prop to render the column header in `stacked` layout
|
|
33
|
+
*
|
|
34
|
+
* By default, `Table.ColHeader` or `Table.RowHeader` or `Table.Cell`.
|
|
35
|
+
*
|
|
36
|
+
* Falsy values are also allowed to be able to use syntax like
|
|
37
|
+
* `{condition && <Table.Cell>bla<Table.Cell>}`
|
|
38
|
+
*/
|
|
39
|
+
children?:
|
|
40
|
+
| React.ReactElement<any>
|
|
41
|
+
| null
|
|
42
|
+
| undefined
|
|
43
|
+
| boolean
|
|
44
|
+
| (React.ReactElement<any> | null | undefined | boolean)[]
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Controls the hover state of the row.
|
|
48
|
+
* When set to true, the row will appear highlighted even when not hovered.
|
|
49
|
+
* When set to false, the row will not highlight on hover even if the hover prop is set to true.
|
|
50
|
+
*/
|
|
51
|
+
setHoverStateTo?: boolean
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type PropKeys = keyof TableRowOwnProps
|
|
55
|
+
|
|
56
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
57
|
+
|
|
58
|
+
type TableRowProps = TableRowOwnProps &
|
|
59
|
+
WithStyleProps<null, TableRowStyle> &
|
|
60
|
+
OtherHTMLAttributes<TableRowOwnProps>
|
|
61
|
+
|
|
62
|
+
type TableRowStyle = ComponentStyle<'row'>
|
|
63
|
+
|
|
64
|
+
const allowedProps: AllowedPropKeys = ['children', 'setHoverStateTo']
|
|
65
|
+
|
|
66
|
+
export type { TableRowProps, TableRowStyle }
|
|
67
|
+
export { allowedProps }
|
|
@@ -0,0 +1,78 @@
|
|
|
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 type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
|
|
26
|
+
import type { TableRowProps, TableRowStyle } from './props'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* ---
|
|
30
|
+
* private: true
|
|
31
|
+
* ---
|
|
32
|
+
* Generates the style object from the theme and provided additional information
|
|
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} _sharedTokens Shared token object (not used in this component)
|
|
36
|
+
* @param {Object} extraArgs the state of the component, the style is applied to
|
|
37
|
+
* @return {Object} The final style object, which will be used in the component
|
|
38
|
+
*/
|
|
39
|
+
const generateStyle = (
|
|
40
|
+
componentTheme: NewComponentTypes['TableRow'],
|
|
41
|
+
props: TableRowProps,
|
|
42
|
+
_sharedTokens: SharedTokens,
|
|
43
|
+
extraArgs: { isStacked: boolean; hover: boolean }
|
|
44
|
+
): TableRowStyle => {
|
|
45
|
+
const { setHoverStateTo } = props
|
|
46
|
+
|
|
47
|
+
const hoverStyles = {
|
|
48
|
+
borderLeftColor: componentTheme.hoverBorderColor,
|
|
49
|
+
borderRightColor: componentTheme.hoverBorderColor
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
row: {
|
|
54
|
+
label: 'row',
|
|
55
|
+
fontSize: componentTheme.fontSize,
|
|
56
|
+
fontFamily: componentTheme.fontFamily,
|
|
57
|
+
fontWeight: componentTheme.fontWeight,
|
|
58
|
+
color: componentTheme.color,
|
|
59
|
+
background: componentTheme.background,
|
|
60
|
+
boxSizing: 'border-box',
|
|
61
|
+
borderBottomStyle: 'solid',
|
|
62
|
+
borderBottomWidth: '0.0625rem',
|
|
63
|
+
borderBottomColor: componentTheme.borderColor,
|
|
64
|
+
|
|
65
|
+
...((setHoverStateTo ?? extraArgs.hover) && {
|
|
66
|
+
borderLeft: '0.1875rem solid transparent',
|
|
67
|
+
borderRight: '0.1875rem solid transparent',
|
|
68
|
+
...(setHoverStateTo === true ? hoverStyles : { '&:hover': hoverStyles })
|
|
69
|
+
}),
|
|
70
|
+
|
|
71
|
+
...(extraArgs.isStacked && {
|
|
72
|
+
padding: `${componentTheme.paddingVertical} ${componentTheme.paddingHorizontal}`
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default generateStyle
|
|
@@ -0,0 +1,84 @@
|
|
|
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 { Component, ContextType } from 'react'
|
|
26
|
+
|
|
27
|
+
import { omitProps, callRenderProp } from '@instructure/ui-react-utils'
|
|
28
|
+
import { View } from '@instructure/ui-view/latest'
|
|
29
|
+
|
|
30
|
+
import { withStyle } from '@instructure/emotion'
|
|
31
|
+
|
|
32
|
+
import generateStyle from './styles'
|
|
33
|
+
import type { TableRowHeaderProps } from './props'
|
|
34
|
+
import { allowedProps } from './props'
|
|
35
|
+
import TableContext from '../TableContext'
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
---
|
|
39
|
+
parent: Table
|
|
40
|
+
id: Table.RowHeader
|
|
41
|
+
---
|
|
42
|
+
**/
|
|
43
|
+
@withStyle(generateStyle)
|
|
44
|
+
class RowHeader extends Component<TableRowHeaderProps> {
|
|
45
|
+
static readonly componentId = 'Table.RowHeader'
|
|
46
|
+
static contextType = TableContext
|
|
47
|
+
declare context: ContextType<typeof TableContext>
|
|
48
|
+
static allowedProps = allowedProps
|
|
49
|
+
|
|
50
|
+
static defaultProps = {
|
|
51
|
+
textAlign: 'start',
|
|
52
|
+
children: null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
componentDidMount() {
|
|
56
|
+
this.props.makeStyles?.()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
componentDidUpdate() {
|
|
60
|
+
this.props.makeStyles?.()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
render() {
|
|
64
|
+
const { children, styles } = this.props
|
|
65
|
+
const isStacked = this.context.isStacked
|
|
66
|
+
return (
|
|
67
|
+
<View
|
|
68
|
+
{...View.omitViewProps(
|
|
69
|
+
omitProps(this.props, RowHeader.allowedProps),
|
|
70
|
+
RowHeader
|
|
71
|
+
)}
|
|
72
|
+
as={isStacked ? 'div' : 'th'}
|
|
73
|
+
css={styles?.rowHeader}
|
|
74
|
+
scope="row"
|
|
75
|
+
role={isStacked ? 'rowheader' : undefined}
|
|
76
|
+
>
|
|
77
|
+
{callRenderProp(children)}
|
|
78
|
+
</View>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default RowHeader
|
|
84
|
+
export { RowHeader }
|
|
@@ -0,0 +1,48 @@
|
|
|
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 type { Renderable, OtherHTMLAttributes } from '@instructure/shared-types'
|
|
26
|
+
import type { ComponentStyle, WithStyleProps } from '@instructure/emotion'
|
|
27
|
+
|
|
28
|
+
type TableRowHeaderOwnProps = {
|
|
29
|
+
/**
|
|
30
|
+
* Control the text alignment in row header
|
|
31
|
+
*/
|
|
32
|
+
textAlign?: 'start' | 'center' | 'end'
|
|
33
|
+
children?: Renderable
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type PropKeys = keyof TableRowHeaderOwnProps
|
|
37
|
+
|
|
38
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
39
|
+
|
|
40
|
+
type TableRowHeaderProps = TableRowHeaderOwnProps &
|
|
41
|
+
WithStyleProps<null, TableRowHeaderStyle> &
|
|
42
|
+
OtherHTMLAttributes<TableRowHeaderOwnProps>
|
|
43
|
+
|
|
44
|
+
type TableRowHeaderStyle = ComponentStyle<'rowHeader'>
|
|
45
|
+
const allowedProps: AllowedPropKeys = ['children', 'textAlign']
|
|
46
|
+
|
|
47
|
+
export type { TableRowHeaderProps, TableRowHeaderStyle }
|
|
48
|
+
export { allowedProps }
|
|
@@ -0,0 +1,60 @@
|
|
|
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 type { NewComponentTypes } from '@instructure/ui-themes'
|
|
26
|
+
import type { TableRowHeaderProps, TableRowHeaderStyle } from './props'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* ---
|
|
30
|
+
* private: true
|
|
31
|
+
* ---
|
|
32
|
+
* Generates the style object from the theme and provided additional information
|
|
33
|
+
* @param {Object} componentTheme The theme variable object.
|
|
34
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
35
|
+
* @return {Object} The final style object, which will be used in the component
|
|
36
|
+
*/
|
|
37
|
+
const generateStyle = (
|
|
38
|
+
componentTheme: NewComponentTypes['TableRowHeader'],
|
|
39
|
+
props: TableRowHeaderProps
|
|
40
|
+
): TableRowHeaderStyle => {
|
|
41
|
+
const { textAlign } = props
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
rowHeader: {
|
|
45
|
+
label: 'rowHeader',
|
|
46
|
+
fontSize: componentTheme.fontSize,
|
|
47
|
+
fontFamily: componentTheme.fontFamily,
|
|
48
|
+
fontWeight: componentTheme.fontWeight,
|
|
49
|
+
color: componentTheme.color,
|
|
50
|
+
background: componentTheme.background,
|
|
51
|
+
boxSizing: 'border-box',
|
|
52
|
+
verticalAlign: 'middle',
|
|
53
|
+
lineHeight: componentTheme.lineHeight,
|
|
54
|
+
padding: `${componentTheme.paddingVertical} ${componentTheme.paddingHorizontal}`,
|
|
55
|
+
...(textAlign && { textAlign })
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default generateStyle
|
|
@@ -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
|
+
|
|
25
|
+
import { createContext } from 'react'
|
|
26
|
+
import { Renderable } from '@instructure/shared-types'
|
|
27
|
+
|
|
28
|
+
type TableContextType = {
|
|
29
|
+
/**
|
|
30
|
+
* If `true` the table gets rendered in one column to be more readable on
|
|
31
|
+
* narrow screens.
|
|
32
|
+
*/
|
|
33
|
+
isStacked: boolean
|
|
34
|
+
/**
|
|
35
|
+
* Highlight each row on hover.
|
|
36
|
+
*/
|
|
37
|
+
hover: boolean
|
|
38
|
+
/**
|
|
39
|
+
* Contents of the first row of cells. Has value if `isStacked` is `true`.
|
|
40
|
+
*/
|
|
41
|
+
headers?: Renderable[]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* ---
|
|
46
|
+
* category: components/contexts
|
|
47
|
+
* ---
|
|
48
|
+
* React context created by the `Table` component to hold its data which are
|
|
49
|
+
* read by its children. You can access these to make custom Table cells/rows.
|
|
50
|
+
*
|
|
51
|
+
* It stores the following parameters:
|
|
52
|
+
* - `isStacked`: Whether the `Table` is in `stacked` layout.
|
|
53
|
+
* - `hover`: Whether highlight rows on mouse hover
|
|
54
|
+
* - `headers`: in `stacked` layout the children of the first row of cells
|
|
55
|
+
* (e.g. the titles in a table). This is used in `stacked` layout to display
|
|
56
|
+
* the titles inline
|
|
57
|
+
* @module
|
|
58
|
+
*/
|
|
59
|
+
const TableContext = createContext<TableContextType>({
|
|
60
|
+
isStacked: false,
|
|
61
|
+
hover: false
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
export default TableContext
|
|
65
|
+
export { TableContext }
|
|
66
|
+
export type { TableContextType }
|
|
@@ -0,0 +1,160 @@
|
|
|
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 { Component, Children, isValidElement, ReactElement } from 'react'
|
|
26
|
+
|
|
27
|
+
import { safeCloneElement, omitProps } from '@instructure/ui-react-utils'
|
|
28
|
+
import { View } from '@instructure/ui-view/latest'
|
|
29
|
+
import { ScreenReaderContent } from '@instructure/ui-a11y-content'
|
|
30
|
+
|
|
31
|
+
import { withStyle } from '@instructure/emotion'
|
|
32
|
+
|
|
33
|
+
import generateStyle from './styles'
|
|
34
|
+
|
|
35
|
+
import { Head } from './Head'
|
|
36
|
+
import { Body } from './Body'
|
|
37
|
+
import { Row } from './Row'
|
|
38
|
+
import { ColHeader } from './ColHeader'
|
|
39
|
+
import { RowHeader } from './RowHeader'
|
|
40
|
+
import { Cell } from './Cell'
|
|
41
|
+
|
|
42
|
+
import type { TableProps } from './props'
|
|
43
|
+
|
|
44
|
+
import { allowedProps } from './props'
|
|
45
|
+
import TableContext from './TableContext'
|
|
46
|
+
import { error } from '@instructure/console'
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
---
|
|
50
|
+
category: components
|
|
51
|
+
---
|
|
52
|
+
**/
|
|
53
|
+
@withStyle(generateStyle)
|
|
54
|
+
class Table extends Component<TableProps> {
|
|
55
|
+
static readonly componentId = 'Table'
|
|
56
|
+
|
|
57
|
+
static allowedProps = allowedProps
|
|
58
|
+
|
|
59
|
+
static defaultProps = {
|
|
60
|
+
children: null,
|
|
61
|
+
hover: false,
|
|
62
|
+
layout: 'auto'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static Head = Head
|
|
66
|
+
static Body = Body
|
|
67
|
+
static Row = Row
|
|
68
|
+
static ColHeader = ColHeader
|
|
69
|
+
static RowHeader = RowHeader
|
|
70
|
+
static Cell = Cell
|
|
71
|
+
|
|
72
|
+
ref: Element | null = null
|
|
73
|
+
|
|
74
|
+
handleRef = (el: Element | null) => {
|
|
75
|
+
const { elementRef } = this.props
|
|
76
|
+
|
|
77
|
+
this.ref = el
|
|
78
|
+
|
|
79
|
+
if (typeof elementRef === 'function') {
|
|
80
|
+
elementRef(el)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
componentDidMount() {
|
|
85
|
+
this.props.makeStyles?.()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
componentDidUpdate() {
|
|
89
|
+
this.props.makeStyles?.()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getHeaders() {
|
|
93
|
+
const [headChild] = Children.toArray(this.props.children)
|
|
94
|
+
if (!headChild || !isValidElement(headChild)) return undefined
|
|
95
|
+
const [firstRow] = Children.toArray(
|
|
96
|
+
(headChild as ReactElement<any>).props.children
|
|
97
|
+
)
|
|
98
|
+
if (!firstRow || !isValidElement(firstRow)) return undefined
|
|
99
|
+
return Children.map(
|
|
100
|
+
(firstRow as ReactElement<any>).props.children,
|
|
101
|
+
(colHeader) => {
|
|
102
|
+
if (!isValidElement<{ children?: any }>(colHeader)) return undefined
|
|
103
|
+
return colHeader.props.children
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
render() {
|
|
109
|
+
const { margin, layout, caption, children, hover, styles, minWidth } =
|
|
110
|
+
this.props
|
|
111
|
+
const isStacked = layout === 'stacked'
|
|
112
|
+
const headers = isStacked ? this.getHeaders() : undefined
|
|
113
|
+
|
|
114
|
+
if (!caption) {
|
|
115
|
+
error(false, `[Table] required prop caption is not set.`)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<TableContext.Provider
|
|
120
|
+
value={{
|
|
121
|
+
isStacked: isStacked,
|
|
122
|
+
hover: hover!,
|
|
123
|
+
headers: headers
|
|
124
|
+
}}
|
|
125
|
+
>
|
|
126
|
+
<View
|
|
127
|
+
// All HTML props, except the ones accepted by `View` and `Table`
|
|
128
|
+
{...View.omitViewProps(
|
|
129
|
+
omitProps(this.props, Table.allowedProps),
|
|
130
|
+
Table
|
|
131
|
+
)}
|
|
132
|
+
minWidth={minWidth}
|
|
133
|
+
as={isStacked ? 'div' : 'table'}
|
|
134
|
+
margin={margin}
|
|
135
|
+
elementRef={this.handleRef}
|
|
136
|
+
css={styles?.table}
|
|
137
|
+
role={isStacked ? 'table' : undefined}
|
|
138
|
+
aria-label={isStacked ? (caption as string) : undefined}
|
|
139
|
+
>
|
|
140
|
+
{!isStacked && (
|
|
141
|
+
<caption>
|
|
142
|
+
<ScreenReaderContent>{caption}</ScreenReaderContent>
|
|
143
|
+
</caption>
|
|
144
|
+
)}
|
|
145
|
+
{Children.map(children, (child) => {
|
|
146
|
+
if (isValidElement(child)) {
|
|
147
|
+
return safeCloneElement(child, {
|
|
148
|
+
key: (child as ReactElement<any>).props.name
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
return child
|
|
152
|
+
})}
|
|
153
|
+
</View>
|
|
154
|
+
</TableContext.Provider>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export default Table
|
|
160
|
+
export { Table }
|