Files
twenty/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsRadioSettingsCard.tsx
T
Charles Bochet c53a13417e Remove all styled(Component) patterns in favor of parent wrappers and props (#18430)
## Summary

Eliminates all ~350 `styled(Component)` usages across `twenty-front` and
`twenty-ui` (212 files changed). Each was replaced following these
rules:

- **Margin/layout CSS** (margin, padding, flex, align-self, width) →
wrapped in a `styled.div`/`styled.span` parent container
- **Third-party components** (Link, TextareaAutosize,
ReactPhoneNumberInput, Handle, etc.) → parent container with child CSS
selectors (`> a`, `> textarea`, `> input`, etc.)
- **Intrinsic behavior via existing props** (TableRow
`gridTemplateColumns`, TableCell `color`/`align`) → replaced
`styled(TableRow)` / `styled(TableCell)` with direct prop usage
- **Other visual overrides on twenty-ui components** (Card, Section,
TabList, Button, MenuItem, ScrollWrapper, etc.) → parent wrappers with
`> div` / `> *` child selectors
- **Extending styled.div/span** → merged all CSS into a single
`styled.div`/`styled.span`

Also adds `overflow: hidden` to parent containers wrapping
`ScrollWrapper` so scroll activates correctly with the new wrapper
structure.

### Migration patterns

| Before | After |
|--------|-------|
| `styled(Avatar)` with `margin-right` | `<StyledAvatarContainer><Avatar
/></StyledAvatarContainer>` |
| `styled(Link)` with `text-decoration: none` |
`<StyledLinkContainer><Link /></StyledLinkContainer>` with `> a { ... }`
|
| `styled(TableRow)` with `grid-template-columns` | `<TableRow
gridTemplateColumns="..." />` |
| `styled(TableCell)` with `color` / `align` | `<TableCell color={...}
align="right" />` |
| `styled(Card)` with `margin-top` | `<StyledCardContainer><Card
/></StyledCardContainer>` |
| `styled(TabList)` with `background` |
`<StyledTabListContainer><TabList /></StyledTabListContainer>` with `>
div { ... }` |
| `styled(StyledBase)` extending a `styled.div` | Single merged
`styled.div` with all styles inlined |
2026-03-05 18:16:25 +01:00

104 lines
2.8 KiB
TypeScript

import { styled } from '@linaria/react';
import { type MessageDescriptor } from '@lingui/core';
import { Trans } from '@lingui/react';
import { type ReactNode } from 'react';
import { Radio } from 'twenty-ui/input';
import { Card, CardContent } from 'twenty-ui/layout';
import { themeCssVariables } from 'twenty-ui/theme-constants';
type SettingsAccountsRadioSettingsCardProps<Option extends { value: string }> =
{
onChange: (nextValue: Option['value']) => void;
options: Option[];
value: Option['value'];
name: string;
};
const StyledCardContentContainer = styled.div`
> * {
cursor: pointer;
&:hover {
background: ${themeCssVariables.background.transparent.lighter};
}
}
`;
const StyledOptionHeader = styled.div`
align-items: center;
display: flex;
gap: ${themeCssVariables.spacing[4]};
`;
const StyledTitle = styled.div`
color: ${themeCssVariables.font.color.primary};
font-weight: ${themeCssVariables.font.weight.medium};
margin-bottom: ${themeCssVariables.spacing[2]};
`;
const StyledDescription = styled.div`
color: ${themeCssVariables.font.color.tertiary};
font-size: ${themeCssVariables.font.size.sm};
`;
const StyledRadioContainer = styled.span`
margin-left: auto;
display: flex;
align-items: center;
`;
const StyledExpandedContent = styled.div`
margin-top: ${themeCssVariables.spacing[4]};
`;
export const SettingsAccountsRadioSettingsCard = <
Option extends {
cardMedia: ReactNode;
description: MessageDescriptor;
title: MessageDescriptor;
value: string;
cardContentExpanded?: ReactNode;
},
>({
onChange,
options,
value,
name,
}: SettingsAccountsRadioSettingsCardProps<Option>) => (
<Card rounded>
{options.map((option, index) => (
<StyledCardContentContainer key={option.value}>
<CardContent
divider={index < options.length - 1}
onClick={() => onChange(option.value)}
>
<StyledOptionHeader>
{option.cardMedia}
<div>
<StyledTitle>
<Trans id={option.title.id} />
</StyledTitle>
<StyledDescription>
<Trans id={option.description.id} />
</StyledDescription>
</div>
<StyledRadioContainer>
<Radio
name={name}
value={option.value}
onCheckedChange={() => onChange(option.value)}
checked={value === option.value}
/>
</StyledRadioContainer>
</StyledOptionHeader>
{option.cardContentExpanded && value === option.value && (
<StyledExpandedContent>
{option.cardContentExpanded}
</StyledExpandedContent>
)}
</CardContent>
</StyledCardContentContainer>
))}
</Card>
);