2022-07-01 18:13:34 +02:00
|
|
|
import { chakra, Fade, Button } from '@chakra-ui/react'
|
2022-08-08 08:21:36 +02:00
|
|
|
import { Cell as CellProps, flexRender } from '@tanstack/react-table'
|
2022-07-01 18:13:34 +02:00
|
|
|
import { ExpandIcon } from 'assets/icons'
|
|
|
|
import { memo } from 'react'
|
2022-08-08 08:21:36 +02:00
|
|
|
import { TableData } from 'services/typebots/results'
|
2022-07-01 18:13:34 +02:00
|
|
|
|
|
|
|
type Props = {
|
2022-08-08 08:21:36 +02:00
|
|
|
cell: CellProps<TableData, unknown>
|
2022-07-01 18:13:34 +02:00
|
|
|
size: number
|
|
|
|
isExpandButtonVisible: boolean
|
|
|
|
cellIndex: number
|
|
|
|
onExpandButtonClick: () => void
|
|
|
|
}
|
|
|
|
|
|
|
|
const Cell = ({
|
|
|
|
cell,
|
|
|
|
size,
|
|
|
|
isExpandButtonVisible,
|
|
|
|
cellIndex,
|
|
|
|
onExpandButtonClick,
|
|
|
|
}: Props) => {
|
|
|
|
return (
|
|
|
|
<chakra.td
|
|
|
|
key={cell.id}
|
|
|
|
px="4"
|
|
|
|
py="2"
|
|
|
|
border="1px"
|
|
|
|
borderColor="gray.200"
|
|
|
|
whiteSpace="nowrap"
|
|
|
|
wordBreak="normal"
|
|
|
|
overflow="hidden"
|
|
|
|
pos="relative"
|
|
|
|
style={{
|
|
|
|
minWidth: size,
|
|
|
|
maxWidth: size,
|
|
|
|
}}
|
|
|
|
>
|
2022-08-08 08:21:36 +02:00
|
|
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
2022-07-01 18:13:34 +02:00
|
|
|
<chakra.span
|
|
|
|
pos="absolute"
|
|
|
|
top="0"
|
|
|
|
right={2}
|
|
|
|
h="full"
|
|
|
|
display="inline-flex"
|
|
|
|
alignItems="center"
|
|
|
|
>
|
|
|
|
<Fade unmountOnExit in={isExpandButtonVisible && cellIndex === 1}>
|
|
|
|
<Button
|
|
|
|
leftIcon={<ExpandIcon />}
|
|
|
|
shadow="lg"
|
|
|
|
size="xs"
|
|
|
|
onClick={onExpandButtonClick}
|
|
|
|
>
|
|
|
|
Open
|
|
|
|
</Button>
|
|
|
|
</Fade>
|
|
|
|
</chakra.span>
|
|
|
|
</chakra.td>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(
|
|
|
|
Cell,
|
|
|
|
(prev, next) =>
|
|
|
|
prev.size === next.size &&
|
|
|
|
prev.isExpandButtonVisible === next.isExpandButtonVisible
|
|
|
|
)
|