Skip to content

ChoiceCards ​

One of a few options, each a card with a description, for a choice where the description helps decide.

tsx
import { ChoiceCards } from '@adecore/ui';
tsx
import { ChoiceCards } from '@adecore/ui';
import { Cloud, HardDrive } from 'lucide-react';
import { useState } from 'react';

type Storage = 'local' | 'cloud';

export default function ChoiceCardsDemo() {
    const [storage, setStorage] = useState<Storage>('local');

    return (
        <ChoiceCards<Storage>
            label="Where to keep the project"
            className="w-full max-w-xl"
            value={storage}
            onValueChange={setStorage}
            choices={[
                { value: 'local', title: 'On this computer', description: 'Fast, and only here.', icon: HardDrive },
                { value: 'cloud', title: 'In your account', description: 'On every device you sign in on.', icon: Cloud }
            ]}
        />
    );
}

Vertical, with a detail ​

orientation="vertical" stacks the cards, for long descriptions. A vertical group can show a detail under the checked card, for what that choice still needs, such as a folder. radio="start" moves the dot before the title.

tsx
import { ChoiceCards, Field, Input } from '@adecore/ui';
import { useState } from 'react';

type Source = 'empty' | 'clone';

export default function ChoiceCardsVertical() {
    const [source, setSource] = useState<Source>('clone');

    return (
        <ChoiceCards<Source>
            label="How to start"
            orientation="vertical"
            radio="start"
            className="w-full max-w-md"
            value={source}
            onValueChange={setSource}
            choices={[
                { value: 'empty', title: 'An empty folder', description: 'Nothing in it yet.' },
                { value: 'clone', title: 'Clone a repository', description: 'Copy one from a remote.' }
            ]}
            detail={
                <Field label="Repository URL" className="px-1 pb-1">
                    <Input mono placeholder="git@github.com:owner/repo.git" />
                </Field>
            }
        />
    );
}

Columns ​

columns lays the cards out in that many columns. It replaces orientation and shows no detail.

tsx
import { ChoiceCards } from '@adecore/ui';
import { FileText, Image, Music, Video } from 'lucide-react';
import { useState } from 'react';

type Kind = 'document' | 'image' | 'audio' | 'video';

export default function ChoiceCardsColumns() {
    const [kind, setKind] = useState<Kind>('document');

    return (
        <ChoiceCards<Kind>
            label="What to create"
            columns={2}
            className="w-full max-w-xl"
            value={kind}
            onValueChange={setKind}
            choices={[
                { value: 'document', title: 'Document', description: 'Text with headings, lists and tables.', icon: FileText },
                { value: 'image', title: 'Image', description: 'A picture to draw on or crop.', icon: Image },
                { value: 'audio', title: 'Audio', description: 'A recording to trim and mix.', icon: Music },
                { value: 'video', title: 'Video', description: 'Clips on a timeline, cut to length.', icon: Video }
            ]}
        />
    );
}

Keyboard ​

The cards are a Base UI radio group. Tab lands on the checked card, and the arrow keys move and check.

Props ​

ChoiceCards is generic over the value, a string or a number.

PropTypeDefault
valueValueRequired.
onValueChange(value: Value) => voidRequired.
choicesreadonly Choice<Value>[]Required.
labelstringRequired. The group's accessible name.
orientation'horizontal' | 'vertical''horizontal'
columnsnumberReplaces orientation.
radio'start' | 'end''end'
detailReactNodeVertical groups without columns only.
disabledboolean
classNamestring
refRef<HTMLDivElement>

A Choice<Value> is { value, title, description, icon?, disabled? }. ChoiceCardsProps and Choice are exported types.

Licenses and third-party notices are listed in each package.