-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathindex.tsx
140 lines (117 loc) · 2.95 KB
/
index.tsx
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*--------------------------------------------------------------------------
* Copyright (c) 2019-2021, Postgres.ai, Nikolay Samokhvalov nik@postgres.ai
* All Rights Reserved. Proprietary and confidential.
* Unauthorized copying of this file, via any medium is strictly prohibited
*--------------------------------------------------------------------------
*/
import React from 'react'
import {
Table as TableBase,
TableProps as TableBaseProps,
TableHead,
TableRow,
TableCell as TableCellBase,
TableCellProps as TableCellBaseProps,
TableBody,
makeStyles,
} from '@material-ui/core'
import clsx from 'clsx'
import { colors } from '@postgres.ai/shared/styles/colors'
import { RowMenu, Props as RowMenuProps } from './RowMenu'
const cellStyles = {
paddingLeft: '8px',
paddingRight: '8px',
borderColor: colors.consoleStroke,
}
// Table.
type TableProps = TableBaseProps
const useTableStyles = makeStyles(
{
root: {
whiteSpace: 'nowrap',
'& .MuiTableCell-root': {
lineHeight: 'normal',
},
},
},
{ index: 1 },
)
const Table = (props: TableProps) => {
const classes = useTableStyles()
return (
<TableBase {...props} className={clsx(props.className, classes.root)} />
)
}
// TableHeaderCell.
type TableHeaderCellProps = TableCellBaseProps
const useTableHeaderCellStyles = makeStyles(
{
root: {
...cellStyles,
color: colors.pgaiDarkGray,
paddingTop: '12px',
paddingBottom: '12px',
},
},
{ index: 1 },
)
const TableHeaderCell = (props: TableHeaderCellProps) => {
const classes = useTableHeaderCellStyles()
return (
<TableCellBase {...props} className={clsx(props.className, classes.root)} />
)
}
// TableBodyCell.
type TableBodyCellProps = TableCellBaseProps
const useTableBodyCellStyles = makeStyles(
{
root: {
...cellStyles,
fontSize: '12px',
paddingTop: '8px',
paddingBottom: '8px',
},
},
{ index: 1 },
)
const TableBodyCell = (props: TableBodyCellProps) => {
const classes = useTableBodyCellStyles()
return (
<TableCellBase {...props} className={clsx(props.className, classes.root)} />
)
}
// TableBodyCellMenu.
type TableBodyCellMenuProps = TableBodyCellProps & RowMenuProps
const useTableBodyCellMenuStyles = makeStyles(
{
root: {
padding: 0,
},
},
{ index: 1 },
)
const TableBodyCellMenu = (props: TableBodyCellMenuProps) => {
const classes = useTableBodyCellMenuStyles()
const { isLoading, isDisabled, children, ...hiddenProps } = props
const handleClick: React.MouseEventHandler<HTMLTableDataCellElement> = (e) =>
e.stopPropagation()
return (
<TableBodyCell
{...hiddenProps}
className={classes.root}
onClick={handleClick}
>
<RowMenu {...hiddenProps} isLoading={isLoading} isDisabled={isDisabled} />
{children}
</TableBodyCell>
)
}
export {
Table,
TableHead,
TableRow,
TableBody,
TableHeaderCell,
TableBodyCell,
TableBodyCellMenu,
}