Skip to content

The open alternative to Salesforce, designed for AI.

1.9 KB
Raw Blame
import { Table } from '@/ui/layout/table/components/Table';
import { TableCell } from '@/ui/layout/table/components/TableCell';
import { TableRow } from '@/ui/layout/table/components/TableRow';
import { isDefined } from 'twenty-shared/utils';
import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
import { type IconComponent } from 'twenty-ui/icon';
import { Card } from 'twenty-ui/primitives/surfaces';
import { useTheme, themeCssVariables } from 'twenty-ui/theme';

export type TableItem = {
  Icon?: IconComponent;
  label: string;
  value: string | number | React.ReactNode;
  onClick?: () => void;
};

type SettingsTableCardProps = {
  items: TableItem[];
  gridAutoColumns?: string;
  labelAlign?: 'left' | 'center' | 'right';
  valueAlign?: 'left' | 'center' | 'right';
  className?: string;
};

export const SettingsTableCard = ({
  items,
  gridAutoColumns,
  labelAlign = 'left',
  valueAlign = 'left',
  className,
}: SettingsTableCardProps) => {
  const theme = useTheme();
  return (
    <Card.Root
      className={className}
      backgroundColor={themeCssVariables.background.secondary}
    >
      <Table>
        {items.map((item, index) => (
          <TableRow key={index + item.label} gridAutoColumns={gridAutoColumns}>
            <TableCell
              align={labelAlign}
              color={themeCssVariables.font.color.tertiary}
              gap={themeCssVariables.spacing[2]}
              overflow="hidden"
            >
              {item.Icon && <item.Icon size={theme.icon.size.md} />}
              <OverflowingTextWithTooltip text={item.label} />
            </TableCell>
            <TableCell
              align={valueAlign}
              color={themeCssVariables.font.color.primary}
              onClick={item.onClick}
              clickable={isDefined(item.onClick)}
            >
              {item.value}
            </TableCell>
          </TableRow>
        ))}
      </Table>
    </Card.Root>
  );
};