Radio Card

A radio button laid out as a card, with room for a title, a description, and an icon.

Select framework

Usage

Code
import { RadioCard } from '@leverui/components';
Code
<RadioCard.Root>
  <RadioCard.Label />
  <RadioCard.Item>
    <RadioCard.ItemHiddenInput />
    <RadioCard.ItemControl>
      <RadioCard.ItemContent>
        <RadioCard.ItemText />
        <RadioCard.ItemDescription />
      </RadioCard.ItemContent>
      <RadioCard.ItemIndicator />
    </RadioCard.ItemControl>
  </RadioCard.Item>
</RadioCard.Root>

For one component with props, see the snippet below.

Examples

Description

Here's an example of how to add some further description to the radio card.

Select framework

Sizes

Pass the size prop to the RadioCard.Root component to change the size of the radio card.

size = (sm)
size = (md)
size = (lg)

Colors

Pass the colorPalette prop to the RadioCard.Root component to change the color of the radio card.

Select framework
Select framework
Select framework
Select framework
Select framework
Select framework
Select framework
Select framework
Select framework
Select framework

Variants

Pass the variant prop to the RadioCard.Root component to change the visual style of the radio card.

variant = (surface)
variant = (subtle)
variant = (outline)
variant = (solid)

Icon

Render a custom icon inside the radio card by placing it within RadioCard.ItemContent.

Select permission

Controlled

Pass the value and onValueChange props to the RadioCard.Root component to control the selected radio card.

Select framework

No Indicator

Here's an example of how to use the radio card without an indicator.

Payment method

No Indicator (Vertical)

Here's an example of a radio card with no indicator and content aligned vertically.

Payment method

Responsive Orientation

Use useBreakpointValue for responsive orientation — the orientation prop doesn't support responsive object notation.

Alternatively, render two RadioCard.Root instances (one horizontal, one vertical) and show or hide them by breakpoint using CSS display.

Payment method

Centered

Here's an example of a radio card with centered text.

Select contract type

Composition

Here's an example of composing the RadioCard with the Group component.

How well do you know SolidJS?

Addon

Use the RadioCard.ItemAddon component to add metadata to the radio card.

Select framework

Closed Component

Code
import { Show, omit } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { RadioCard, type RadioCardItemProps } from '@leverui/components';

export type ClosedRadioCardItemProps = RadioCardItemProps & {
  icon?: JSX.Element;
  label?: JSX.Element;
  description?: JSX.Element;
  addon?: JSX.Element;
  indicator?: JSX.Element | null;
  indicatorPlacement?: 'start' | 'end' | 'inside' | undefined;
  inputProps?: JSX.InputHTMLAttributes<HTMLInputElement>;
};

export function RadioCardItem(props: ClosedRadioCardItemProps) {
  const item = omit(
    props,
    'icon',
    'label',
    'description',
    'addon',
    'indicator',
    'indicatorPlacement',
    'inputProps',
  );
  const placement = () => props.indicatorPlacement ?? 'end';
  const indicator = () =>
    props.indicator === null ? null : (props.indicator ?? <RadioCard.ItemIndicator />);

  return (
    <RadioCard.Item {...item}>
      <RadioCard.ItemHiddenInput {...props.inputProps} />
      <RadioCard.ItemControl>
        <Show when={placement() === 'start'}>{indicator()}</Show>
        <Show when={props.label || props.description || props.icon}>
          <RadioCard.ItemContent>
            {props.icon}
            <Show when={props.label}>
              <RadioCard.ItemText>{props.label}</RadioCard.ItemText>
            </Show>
            <Show when={props.description}>
              <RadioCard.ItemDescription>{props.description}</RadioCard.ItemDescription>
            </Show>
            <Show when={placement() === 'inside'}>{indicator()}</Show>
          </RadioCard.ItemContent>
        </Show>
        <Show when={placement() === 'end'}>{indicator()}</Show>
      </RadioCard.ItemControl>
      <Show when={props.addon}>
        <RadioCard.ItemAddon>{props.addon}</RadioCard.ItemAddon>
      </Show>
    </RadioCard.Item>
  );
}

export const RadioCardRoot = RadioCard.Root;
export const RadioCardLabel = RadioCard.Label;
export const RadioCardItemIndicator = RadioCard.ItemIndicator;
Code
<RadioCardRoot>
  <RadioCardLabel />
  <RadioCardItem />
</RadioCardRoot>

Guides

State and forms

Give each item its own value and an ItemHiddenInput. Set name on the root for forms. ItemText names the native input. A click anywhere on the item's label selects it.

defaultValue sets the first selection. Use value and onValueChange when a signal holds the value. disabled goes on the root or on one item. required, invalid, and readOnly work as in a radio group. Context and ItemContext give the reactive state.

To own the state machine, call useRadioCardGroup() in a component and pass its accessor to RootProvider. PropsProvider takes default props as an object or an accessor. A prop on a component wins. RootProvider takes presentation defaults from PropsProvider and keeps your machine.

Custom selected indicator

ItemIndicator takes a checked render function. It puts the indicator classes, attributes, and ref on your own element. getProps takes attributes that HTML and SVG share. Put SVG-only ones such as viewBox on the SVG itself.

children does not replace the default radio dot. With checked, you cannot use as or asChild.

Code
<RadioCard.ItemIndicator checked={(getProps) => <CheckIcon {...getProps()} />} />

Props

Root

PropDefaultTypeDescription
orientationhorizontal'vertical' | 'horizontal'Layout and arrow-key direction. One value, not responsive.
colorPalettegraystringColor palette, built-in or your own.
sizemd'sm' | 'md' | 'lg'Card size. Responsive.
variantoutline'surface' | 'subtle' | 'outline' | 'solid'Card style. Responsive.
alignstart'start' | 'end' | 'center'Content alignment. Responsive.
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the root's props.
unstyledfalsebooleanTurn off the Lever UI styles.
defaultValue—stringValue selected at first, when you do not control it.
disabled—booleanDisable the radio group.
form—stringId of the form the inputs belong to.
id—stringUnique id of the state machine.
ids—Element ID mapYour own ids for the elements.
invalid—booleanMark the radio group as invalid.
name—stringInput name sent with the form.
onValueChange—(details) => voidCalled when a radio is checked.
readOnly—booleanMake the radio group read-only.
required—booleanMark the radio group as required.
value—stringSelected value, when you control it.
justify—'start' | 'end' | 'center'Content justification. Responsive.

Customize with CSS

Import @leverui/components/styles.css, then override the --leverui-* tokens or style the part classes. The class names are stable.

Code
.leverui-radio-card__itemControl {
  border-radius: 0.75rem;
}

The root and items have data-size and data-variant, plus a version of each for every breakpoint. The indicator also has .leverui-radiomark.

Variables for one group: --leverui-radio-card-root-gap, --leverui-radio-card-radius, --leverui-radio-card-control-padding, --leverui-radio-card-control-gap.

Every public part takes class, style, and unstyled.

Explorer

Click a part name to highlight it in the preview.

Component Anatomy

Hover to highlight, click to select parts