feishin/src/renderer/components/virtual-table/cells/generic-cell.tsx

78 lines
2 KiB
TypeScript
Raw Normal View History

2022-12-19 15:59:14 -08:00
import type { ICellRendererParams } from '@ag-grid-community/core';
2022-12-19 15:59:14 -08:00
import { Link } from 'react-router-dom';
import styled from 'styled-components';
import { Skeleton } from '/@/renderer/components/skeleton';
2022-12-19 15:59:14 -08:00
import { Text } from '/@/renderer/components/text';
export const CellContainer = styled.div<{ $position?: 'center' | 'left' | 'right' }>`
2023-07-01 19:10:05 -07:00
display: flex;
align-items: center;
justify-content: ${(props) =>
props.$position === 'right'
2023-07-01 19:10:05 -07:00
? 'flex-end'
: props.$position === 'center'
2024-08-23 08:19:27 -07:00
? 'center'
: 'flex-start'};
2023-07-01 19:10:05 -07:00
width: 100%;
height: 100%;
letter-spacing: 0.5px;
2022-12-19 15:59:14 -08:00
`;
type Options = {
2023-07-01 19:10:05 -07:00
array?: boolean;
isArray?: boolean;
isLink?: boolean;
position?: 'center' | 'left' | 'right';
2023-07-01 19:10:05 -07:00
primary?: boolean;
2022-12-19 15:59:14 -08:00
};
export const GenericCell = (
2023-07-01 19:10:05 -07:00
{ value, valueFormatted }: ICellRendererParams,
{ isLink, position, primary }: Options,
2022-12-19 15:59:14 -08:00
) => {
2023-07-01 19:10:05 -07:00
const displayedValue = valueFormatted || value;
if (value === undefined) {
return (
<CellContainer $position={position || 'left'}>
2023-07-01 19:10:05 -07:00
<Skeleton
height="1rem"
width="80%"
/>
</CellContainer>
);
}
2022-12-19 15:59:14 -08:00
return (
<CellContainer $position={position || 'left'}>
2023-07-01 19:10:05 -07:00
{isLink ? (
<Text
$link={isLink}
$secondary={!primary}
component={Link}
overflow="hidden"
size="md"
to={displayedValue.link}
>
{isLink ? displayedValue.value : displayedValue}
</Text>
) : (
<Text
$noSelect={false}
2023-07-01 19:10:05 -07:00
$secondary={!primary}
overflow="hidden"
size="md"
>
{displayedValue}
</Text>
)}
</CellContainer>
);
2022-12-19 15:59:14 -08:00
};
GenericCell.defaultProps = {
2023-07-01 19:10:05 -07:00
position: undefined,
2022-12-19 15:59:14 -08:00
};