@workday/canvas-kit-react 11.0.0-alpha.707-next.0 → 11.0.0-alpha.708-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/table/index.d.ts +0 -1
- package/dist/commonjs/table/index.d.ts.map +1 -1
- package/dist/commonjs/table/index.js +0 -1
- package/dist/commonjs/table/lib/Table.d.ts +204 -8
- package/dist/commonjs/table/lib/Table.d.ts.map +1 -1
- package/dist/commonjs/table/lib/Table.js +226 -43
- package/dist/commonjs/table/lib/TableBody.d.ts +2 -0
- package/dist/commonjs/table/lib/TableBody.d.ts.map +1 -0
- package/dist/commonjs/table/lib/TableBody.js +19 -0
- package/dist/commonjs/table/lib/TableCaption.d.ts +2 -0
- package/dist/commonjs/table/lib/TableCaption.d.ts.map +1 -0
- package/dist/commonjs/table/lib/TableCaption.js +20 -0
- package/dist/commonjs/table/lib/TableCell.d.ts +2 -0
- package/dist/commonjs/table/lib/TableCell.d.ts.map +1 -0
- package/dist/commonjs/table/lib/TableCell.js +20 -0
- package/dist/commonjs/table/lib/TableFooter.d.ts +2 -0
- package/dist/commonjs/table/lib/TableFooter.d.ts.map +1 -0
- package/dist/commonjs/table/lib/TableFooter.js +19 -0
- package/dist/commonjs/table/lib/TableHead.d.ts +2 -0
- package/dist/commonjs/table/lib/TableHead.d.ts.map +1 -0
- package/dist/commonjs/table/lib/TableHead.js +20 -0
- package/dist/commonjs/table/lib/TableHeader.d.ts +2 -0
- package/dist/commonjs/table/lib/TableHeader.d.ts.map +1 -0
- package/dist/commonjs/table/lib/TableHeader.js +20 -0
- package/dist/commonjs/table/lib/TableRow.d.ts +1 -33
- package/dist/commonjs/table/lib/TableRow.d.ts.map +1 -1
- package/dist/commonjs/table/lib/TableRow.js +20 -197
- package/dist/es6/table/index.d.ts +0 -1
- package/dist/es6/table/index.d.ts.map +1 -1
- package/dist/es6/table/index.js +0 -1
- package/dist/es6/table/lib/Table.d.ts +204 -8
- package/dist/es6/table/lib/Table.d.ts.map +1 -1
- package/dist/es6/table/lib/Table.js +225 -22
- package/dist/es6/table/lib/TableBody.d.ts +2 -0
- package/dist/es6/table/lib/TableBody.d.ts.map +1 -0
- package/dist/es6/table/lib/TableBody.js +13 -0
- package/dist/es6/table/lib/TableCaption.d.ts +2 -0
- package/dist/es6/table/lib/TableCaption.d.ts.map +1 -0
- package/dist/es6/table/lib/TableCaption.js +14 -0
- package/dist/es6/table/lib/TableCell.d.ts +2 -0
- package/dist/es6/table/lib/TableCell.d.ts.map +1 -0
- package/dist/es6/table/lib/TableCell.js +14 -0
- package/dist/es6/table/lib/TableFooter.d.ts +2 -0
- package/dist/es6/table/lib/TableFooter.d.ts.map +1 -0
- package/dist/es6/table/lib/TableFooter.js +13 -0
- package/dist/es6/table/lib/TableHead.d.ts +2 -0
- package/dist/es6/table/lib/TableHead.d.ts.map +1 -0
- package/dist/es6/table/lib/TableHead.js +14 -0
- package/dist/es6/table/lib/TableHeader.d.ts +2 -0
- package/dist/es6/table/lib/TableHeader.d.ts.map +1 -0
- package/dist/es6/table/lib/TableHeader.js +14 -0
- package/dist/es6/table/lib/TableRow.d.ts +1 -33
- package/dist/es6/table/lib/TableRow.d.ts.map +1 -1
- package/dist/es6/table/lib/TableRow.js +19 -177
- package/package.json +4 -5
- package/table/LICENSE +51 -0
- package/table/index.ts +0 -1
- package/table/lib/Table.tsx +235 -22
- package/table/lib/TableBody.tsx +42 -0
- package/table/lib/TableCaption.tsx +25 -0
- package/table/lib/TableCell.tsx +31 -0
- package/table/lib/TableFooter.tsx +22 -0
- package/table/lib/TableHead.tsx +33 -0
- package/table/lib/TableHeader.tsx +31 -0
- package/table/lib/TableRow.tsx +33 -212
package/table/lib/TableRow.tsx
CHANGED
|
@@ -1,220 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
InputAlert,
|
|
16
|
-
Hover,
|
|
17
|
-
Selected,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @deprecated ⚠️ `Table` has been deprecated and will be removed in a future major version. Please use [`Table`](https://workday.github.io/canvas-kit/?path=/docs/preview-table--basic) in Preview instead.
|
|
22
|
-
*/
|
|
23
|
-
export interface TableRowProps extends React.HTMLAttributes<HTMLTableRowElement> {
|
|
24
|
-
/**
|
|
25
|
-
* The state of the TableRow. Accepts `Error`, `Alert`, `InputError`, `InputAlert`, `Hover`, or `Selected`.
|
|
26
|
-
*/
|
|
27
|
-
state?: TableRowState;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* If true, render the TableRow with header elements.
|
|
31
|
-
* @default false
|
|
32
|
-
*/
|
|
33
|
-
header?: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const errorColor = statusColors.error;
|
|
37
|
-
const errorColorLight = colors.cinnamon200;
|
|
38
|
-
const alertColor = statusColors.warning;
|
|
39
|
-
const alertColorLight = colors.cantaloupe200;
|
|
40
|
-
|
|
41
|
-
function makeColoredRow(_bgColor: string, _borderColor: string): CSSObject {
|
|
42
|
-
return {
|
|
43
|
-
backgroundColor: _bgColor,
|
|
44
|
-
position: 'relative',
|
|
45
|
-
|
|
46
|
-
// Bottom border
|
|
47
|
-
'&:before, &:after': {
|
|
48
|
-
position: 'absolute',
|
|
49
|
-
left: 0,
|
|
50
|
-
top: -borderWidth,
|
|
51
|
-
content: '""',
|
|
52
|
-
width: `calc(100% + ${borderWidth}px)`,
|
|
53
|
-
height: borderWidth,
|
|
54
|
-
backgroundColor: _borderColor,
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
'&:after': {
|
|
58
|
-
top: 'auto',
|
|
59
|
-
bottom: -borderWidth,
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
'&:first-of-type': {
|
|
63
|
-
boxShadow: `inset ${borderWidth}px 0 0 ${_borderColor}`,
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
'&:last-child': {
|
|
67
|
-
boxShadow: `inset -${borderWidth}px 0 0 ${_borderColor}`,
|
|
68
|
-
'&:before, &:after': {
|
|
69
|
-
width: '100%',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function makeColoredRowStyle(_bgColor: string, _borderColor: string): CSSObject {
|
|
76
|
-
const lightenedBg = rgba(_bgColor, 0.2);
|
|
77
|
-
return {
|
|
78
|
-
'th, td': [
|
|
79
|
-
makeColoredRow(lightenedBg, _bgColor),
|
|
80
|
-
{
|
|
81
|
-
borderLeftColor: _borderColor,
|
|
82
|
-
borderRightColor: _borderColor,
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
'&:hover': {
|
|
86
|
-
'th, td': {
|
|
87
|
-
backgroundColor: lightenedBg,
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function makeBorderlessStyle(_bgColor: string): CSSObject {
|
|
94
|
-
return {
|
|
95
|
-
'th, td': {
|
|
96
|
-
backgroundColor: rgba(_bgColor, 0.2),
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const StyledTableRow = styled('tr')<TableRowProps>(
|
|
102
|
-
{
|
|
103
|
-
'th, td': {
|
|
104
|
-
backgroundColor: colors.frenchVanilla100,
|
|
105
|
-
padding: `${space.xs} ${space.xxs}`,
|
|
106
|
-
fontSize: 13,
|
|
107
|
-
borderRight: cellBorder,
|
|
108
|
-
borderBottom: cellBorder,
|
|
109
|
-
height: `calc(${space.xl} + ${space.xxs})`,
|
|
110
|
-
boxSizing: 'border-box',
|
|
111
|
-
transition: 'background-color 0.2s',
|
|
112
|
-
},
|
|
113
|
-
td: {
|
|
114
|
-
'&:last-child': {
|
|
115
|
-
borderRight: 'none',
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
th: {
|
|
119
|
-
height: space.xxl,
|
|
120
|
-
'&:last-child': {
|
|
121
|
-
borderRight: 'none',
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
'&:last-child': {
|
|
125
|
-
'th, td': {
|
|
126
|
-
borderBottom: 'none',
|
|
127
|
-
},
|
|
128
|
-
},
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {GridProps, mergeStyles} from '@workday/canvas-kit-react/layout';
|
|
3
|
+
import {createComponent} from '@workday/canvas-kit-react/common';
|
|
4
|
+
import {createStencil, createVars} from '@workday/canvas-kit-styling';
|
|
5
|
+
|
|
6
|
+
const childrenVars = createVars('cellNumber');
|
|
7
|
+
|
|
8
|
+
// Styles for rows including dynamic sizing for amount of cells within a row
|
|
9
|
+
const tableRowStencil = createStencil({
|
|
10
|
+
base: {
|
|
11
|
+
display: 'grid',
|
|
12
|
+
gridAutoFlow: 'column',
|
|
13
|
+
gridTemplateColumns: `repeat(${childrenVars.cellNumber}, minmax(10rem, 1fr))`,
|
|
14
|
+
boxSizing: 'border-box',
|
|
129
15
|
},
|
|
130
|
-
|
|
131
|
-
header && {
|
|
132
|
-
'&:last-child': {
|
|
133
|
-
'th, td': {
|
|
134
|
-
borderBottom: '1px solid transparent',
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
'th, td': {
|
|
138
|
-
position: 'relative',
|
|
139
|
-
backgroundColor: colors.frenchVanilla100,
|
|
140
|
-
verticalAlign: 'middle', // Bottom border
|
|
141
|
-
'&:after': {
|
|
142
|
-
position: 'absolute',
|
|
143
|
-
left: 0,
|
|
144
|
-
bottom: -borderWidth,
|
|
145
|
-
content: '""',
|
|
146
|
-
width: `calc(100% + ${borderWidth}px)`,
|
|
147
|
-
height: borderWidth,
|
|
148
|
-
backgroundColor: borderColor,
|
|
149
|
-
},
|
|
150
|
-
'&:last-child': {
|
|
151
|
-
'&:after': {
|
|
152
|
-
width: '100%',
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
({state}) => {
|
|
158
|
-
switch (state) {
|
|
159
|
-
case TableRowState.InputError:
|
|
160
|
-
return makeBorderlessStyle(errorColor);
|
|
161
|
-
case TableRowState.Error:
|
|
162
|
-
return makeColoredRowStyle(errorColor, errorColorLight);
|
|
163
|
-
case TableRowState.InputAlert:
|
|
164
|
-
return makeBorderlessStyle(alertColor);
|
|
165
|
-
case TableRowState.Alert:
|
|
166
|
-
return makeColoredRowStyle(alertColor, alertColorLight);
|
|
167
|
-
case TableRowState.Selected:
|
|
168
|
-
return {
|
|
169
|
-
'th, td': [
|
|
170
|
-
makeColoredRow(colors.blueberry100, colors.blueberry500),
|
|
171
|
-
{
|
|
172
|
-
'&:after': {
|
|
173
|
-
zIndex: 2,
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
],
|
|
177
|
-
};
|
|
178
|
-
default:
|
|
179
|
-
return {
|
|
180
|
-
'&:hover': {
|
|
181
|
-
'th, td': {
|
|
182
|
-
backgroundColor: colors.soap300,
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
'&:focus': {
|
|
186
|
-
outline: 'none',
|
|
187
|
-
'th, td': [
|
|
188
|
-
makeColoredRow(colors.blueberry100, colors.blueberry500),
|
|
189
|
-
{
|
|
190
|
-
'&:after': {
|
|
191
|
-
zIndex: 2,
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
],
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
);
|
|
16
|
+
});
|
|
200
17
|
|
|
201
|
-
/**
|
|
202
|
-
* @deprecated ⚠️ `Table` has been deprecated and will be removed in a future major version. Please use [`Table`](https://workday.github.io/canvas-kit/?path=/docs/preview-table--basic) in Preview instead.
|
|
203
|
-
*/
|
|
204
18
|
export const TableRow = createComponent('tr')({
|
|
205
|
-
displayName: '
|
|
206
|
-
Component: (
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
19
|
+
displayName: 'Table.Row',
|
|
20
|
+
Component: ({children, ...elemProps}: GridProps, ref, Element) => {
|
|
21
|
+
// This calculates the amount of valid React children cells within the row and will update the gridTemplateColumns style property with that amount of cells within the row
|
|
22
|
+
const validChildren = (children: React.ReactNode) => {
|
|
23
|
+
return React.Children.toArray(children).filter(child =>
|
|
24
|
+
React.isValidElement(child)
|
|
25
|
+
) as React.ReactElement[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* This is the calculated amount of valid React children
|
|
29
|
+
*/
|
|
30
|
+
const childrenArray = validChildren(children).length;
|
|
31
|
+
|
|
211
32
|
return (
|
|
212
|
-
<
|
|
33
|
+
<Element
|
|
34
|
+
ref={ref}
|
|
35
|
+
{...mergeStyles(elemProps, [tableRowStencil(), {[childrenVars.cellNumber]: childrenArray}])}
|
|
36
|
+
>
|
|
213
37
|
{children}
|
|
214
|
-
</
|
|
38
|
+
</Element>
|
|
215
39
|
);
|
|
216
40
|
},
|
|
217
|
-
subComponents: {
|
|
218
|
-
State: TableRowState,
|
|
219
|
-
},
|
|
220
41
|
});
|