-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathCell.tsx
72 lines (66 loc) · 1.81 KB
/
Cell.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
import * as React from 'react';
import cs from 'clsx';
/** @jsxRuntime classic */
/** @jsx jsx */
import { css, jsx } from '@emotion/react';
import { CellContainer } from '@table-library/react-table-library/common/components/Cell';
import { ThemeContext } from '@table-library/react-table-library/common/context/Theme';
import { CellProps } from '@table-library/react-table-library/types/table';
export const Cell: React.FC<CellProps> = ({
index,
className,
hide,
pinLeft,
pinRight,
stiff,
includePreviousColSpan,
previousColSpans,
gridColumnStart,
gridColumnEnd,
onClick,
children,
style,
...rest
}: CellProps) => {
const theme = React.useContext(ThemeContext);
const hasColSpan = gridColumnStart && gridColumnEnd;
const colSpan = hasColSpan ? gridColumnEnd - gridColumnStart - 1 : 0;
const computedGridColumnStart = includePreviousColSpan
? gridColumnStart + previousColSpans
: gridColumnStart;
const computedGridColumnEnd = includePreviousColSpan
? gridColumnEnd + previousColSpans
: gridColumnEnd;
return (
<>
<CellContainer
role="gridcell"
data-table-library_td=""
style={{
...(hasColSpan
? { gridColumnStart: computedGridColumnStart, gridColumnEnd: computedGridColumnEnd }
: {}),
...style,
}}
css={css`
${theme?.BaseCell}
${theme?.Cell}
`}
className={cs('td', className, {
stiff,
hide,
'pin-left': pinLeft,
'pin-right': pinRight,
})}
onClick={onClick}
{...rest}
>
<div>{children}</div>
</CellContainer>
{/* column grouping */}
{Array.from({ length: colSpan }, () => (
<CellContainer className={cs('td', 'hide', 'colspan')} />
))}
</>
);
};