forked from uber/baseweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyled-components.tsx
More file actions
85 lines (78 loc) · 2.22 KB
/
styled-components.tsx
File metadata and controls
85 lines (78 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';
import { withStyle, withWrapper } from '../styles';
import {
StyledTable as FlexStyledTable,
StyledHeadCell as FlexStyledHeadCell,
StyledCell as FlexStyledBodyCell,
} from '../table';
const StyledTableElement = withStyle<
typeof FlexStyledTable,
{
$gridTemplateColumns: string;
}
>(FlexStyledTable, (props) => {
return {
display: 'grid',
gridTemplateColumns: props.$gridTemplateColumns,
flexDirection: 'unset',
// Creates a stacking context so we can use z-index on the StyledHeadCell
// without affecting anything outside of this component.
transform: 'scale(1)',
};
});
StyledTableElement.displayName = 'StyledTableElement';
export const StyledTable = withWrapper(
StyledTableElement,
(StyledComponent) =>
function StyledTable(props) {
return <StyledComponent data-baseweb="table-grid" {...props} />;
}
);
export const StyledHeadCell = withStyle<
typeof FlexStyledHeadCell,
{
$sticky?: boolean;
$isFocusVisible?: boolean;
}
// @ts-ignore
>(FlexStyledHeadCell, ({ $sticky = true, $isFocusVisible, $theme }) => {
return {
backgroundColor: $theme.colors.tableHeadBackgroundColor,
boxShadow: $theme.lighting.shadow400,
position: $sticky ? 'sticky' : null,
top: $sticky ? 0 : null,
width: 'unset',
':focus': {
outline: $isFocusVisible ? `3px solid ${$theme.colors.borderAccent}` : 'none',
outlineOffset: '-3px',
},
zIndex: $sticky ? 1 : 'auto',
};
});
StyledHeadCell.displayName = 'StyledHeadCell';
export const StyledBodyCell = withStyle<
typeof FlexStyledBodyCell,
{
$gridColumn?: string;
$gridRow?: string;
$isFocusVisible?: boolean;
}
// @ts-ignore
>(FlexStyledBodyCell, (props) => {
return {
display: 'block',
flex: 'unset',
gridColumn: props.$gridColumn || null,
gridRow: props.$gridRow || null,
':focus': {
outline: props.$isFocusVisible ? `3px solid ${props.$theme.colors.borderAccent}` : 'none',
outlineOffset: '-3px',
},
};
});
StyledBodyCell.displayName = 'StyledBodyCell';