Files
twenty/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsRadioSettingsCard.tsx
gitstart-app[bot] fc8c9d9167 Migrate to twenty-ui - input components (#7914)
### Description

Migrate Input components: 

- CardPicker
- Radio
- RadioGroup
- Checkbox
- Toggle
- IconListViewGrip

### Demo

Radio Component on Storybook


![](https://assets-service.gitstart.com/4814/2d0c7436-9fab-4f3d-a5c4-be874e885789.png)

Checkbox component on Storybook


![](https://assets-service.gitstart.com/4814/07bcc040-cc92-4c7e-9be8-ca1a5f454993.png)

###### Fixes twentyhq/private-issues#92

Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
2024-10-28 15:36:58 +01:00

75 lines
1.8 KiB
TypeScript

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