RadioCards
Unas pocas opciones dibujadas como tarjetas, cada una con un título y una frase, de las que se elige una. Para decisiones que merecen un momento de lectura, como un plan.
import { RadioCards, RadioCardsSkeleton } from '@sypnia/ui/react'
Elegir un plan
Toda la tarjeta es el objetivo. La pista dice lo que cuesta la opción.
No cost, and no card needed.
Código
import { useState } from 'react';
import { Field, RadioCards, type Option } from '@sypnia/ui/react';
const plans: Option[] = [
{ value: 'free', label: 'Free', description: 'One project, 500 MB, backups every week. Sleeps after 7 days without use.' },
{ value: 'pro', label: 'Pro', description: 'Unlimited projects, 20 GB each, backups every day, no sleeping.' },
{ value: 'team', label: 'Team', description: 'Everything in Pro, plus roles, audit log and support by chat.' },
];
const price: Record<string, string> = { free: 'No cost, and no card needed.', pro: 'USD 25 a month for each project.', team: 'USD 99 a month for each project.' };
export default function Basic() {
const [plan, setPlan] = useState('free');
return (
<Field label="Plan" hint={price[plan]}>
<RadioCards options={plans} value={plan} onChange={setPlan} />
</Field>
);
} Con iconos
Un icono al final de cada tarjeta ayuda a distinguirlas de un vistazo.
Código
import { Field, RadioCards, type Option } from '@sypnia/ui/react';
const kinds: Option[] = [
{ value: 'cloud', label: 'Sypnia Cloud', description: 'We run it. Ready in a minute.', icon: 'cloud' },
{ value: 'self', label: 'Your own server', description: 'You run it, with the open source engine.', icon: 'self-host' },
];
export default function WithIcons() {
return (
<Field label="Where will it run?">
<RadioCards options={kinds} defaultValue="cloud" />
</Field>
);
} Estados
Nada elegido con un error, una opción que no se puede elegir, y todas desactivadas.
Choose where the data will live: it cannot be moved later.
The region was chosen when the project was created.
Código
import { Field, RadioCards, type Option } from '@sypnia/ui/react';
const regions: Option[] = [
{ value: 'us-east-1', label: 'Virginia', description: 'Closest to North America.' },
{ value: 'sa-east-1', label: 'São Paulo', description: 'Closest to South America.' },
{ value: 'ap-southeast-1', label: 'Singapore', description: 'Opens in January.', disabled: true },
];
export default function States() {
return (
<div className="sy-stack">
<Field label="Region" error="Choose where the data will live: it cannot be moved later.">
<RadioCards options={regions} />
</Field>
<Field label="Region" hint="The region was chosen when the project was created.">
<RadioCards disabled options={regions.slice(0, 2)} defaultValue="sa-east-1" />
</Field>
</div>
);
} Skeleton
La pieza real y su skeleton: la misma caja, así nada se mueve cuando llegan los datos.
Código
import { RadioCards, RadioCardsSkeleton } from '@sypnia/ui/react';
// Plans whose prices are still loading. The skeleton has the same box as the real one, so nothing moves when the data arrives.
export default function Skeleton() {
return (
<div className="sy-stack">
<RadioCards aria-label="Plan" defaultValue="team" options={[{ value: 'starter', label: 'Starter', description: '3 people, 1 project.' }, { value: 'team', label: 'Team', description: '10 people, every project.' }]} />
<RadioCardsSkeleton items={2} />
</div>
);
} Cuándo usarlo
Úsalo cuando
- De dos a cuatro opciones que necesitan una frase cada una para entenderse: planes, regiones, tipos de proyecto.
- La elección es lo principal que pide la pantalla.
No lo uses cuando
- Las opciones son palabras cortas: RadioGroup ocupa menos espacio.
- Hay más de cuatro o cinco: Select.
- Se pueden elegir varias: un grupo de CheckboxCards.
Para todos
- Son radios nativos dentro de etiquetas: el grupo es una parada de Tab, las flechas mueven la elección, y se puede presionar toda la tarjeta.
- Se anuncia como
radiogroupcon la pregunta como nombre; cada tarjeta lee su título y luego su frase. - La tarjeta elegida se nota por su borde, su tinte y el radio lleno: nunca solo por el color.
- En el celular las tarjetas se apilan una debajo de otra; nada se desplaza de lado.
Props
| RadioCards | Tipo | Por defecto |
|---|---|---|
optionsobligatorio | Option[] | |
aria-describedby | string | |
aria-labelThe name for screen readers when there is no Field around it. | string | |
aria-labelledby | string | |
className | string | |
defaultValue | string | |
disabled | boolean | |
idInside a Field it comes from the Field. | string | |
invalidMarks the value as wrong. Inside a `<Field error>` it is set for you. | boolean | |
nameThe name of the value when it travels in a form. | string | |
onChange | ((value: string) => void) | |
value | string | null |
| RadioCardsSkeleton | Tipo | Por defecto |
|---|---|---|
items | number | 3 |