The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { styled } from '@linaria/react';
import { Fragment, type ReactNode } from 'react';
import { type IconComponent } from 'twenty-ui/icon';
import { useTheme, themeCssVariables } from 'twenty-ui/theme';
export type SettingsStatRow = {
Icon: IconComponent;
label: string;
value: ReactNode;
hasSeparatorAfter?: boolean;
};
type SettingsStatsGridProps = {
columns: SettingsStatRow[][];
};
const StyledContainer = styled.div`
background: ${themeCssVariables.background.secondary};
border: 1px solid ${themeCssVariables.border.color.medium};
border-radius: ${themeCssVariables.border.radius.md};
display: flex;
gap: ${themeCssVariables.spacing[3]};
padding: ${themeCssVariables.spacing[2]};
`;
const StyledColumn = styled.div`
display: flex;
flex: 1 1 0;
flex-direction: column;
gap: ${themeCssVariables.spacing[1]};
min-width: 0;
`;
const StyledDivider = styled.div`
align-self: stretch;
background: ${themeCssVariables.border.color.light};
width: 1px;
`;
const StyledRow = styled.div`
align-items: center;
display: flex;
gap: ${themeCssVariables.spacing[2]};
height: ${themeCssVariables.spacing[6]};
`;
const StyledRowSeparator = styled.div`
background: ${themeCssVariables.border.color.light};
height: 1px;
`;
const StyledLabel = styled.div`
color: ${themeCssVariables.font.color.tertiary};
flex: 1 1 0;
font-size: ${themeCssVariables.font.size.sm};
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;
const StyledValue = styled.div`
color: ${themeCssVariables.font.color.primary};
max-width: 50%;
min-width: 0;
padding: 0 ${themeCssVariables.spacing[1]};
`;
type StatRowProps = SettingsStatRow;
const StatRow = ({ Icon, label, value }: StatRowProps) => {
const theme = useTheme();
return (
<StyledRow>
<Icon size={theme.icon.size.md} color={theme.font.color.tertiary} />
<StyledLabel>{label}</StyledLabel>
<StyledValue>{value}</StyledValue>
</StyledRow>
);
};
export const SettingsStatsGrid = ({ columns }: SettingsStatsGridProps) => (
<StyledContainer>
{columns.map((column, index) => (
<Fragment key={index}>
{index > 0 && <StyledDivider />}
<StyledColumn>
{column.map((stat, rowIndex) => (
<Fragment key={`${rowIndex}-${stat.label}`}>
<StatRow Icon={stat.Icon} label={stat.label} value={stat.value} />
{stat.hasSeparatorAfter && <StyledRowSeparator />}
</Fragment>
))}
</StyledColumn>
</Fragment>
))}
</StyledContainer>
);