Zubra UI
Code for
GitHub

choice-cards

Pick one of several cards: a radio group. A form control; arrow keys move the choice. Each item is { id, title, detail, price, note } (note and price optional).

Try it: events appear here (valuechange).

Source: choice-cards.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/choice-cards.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/choice-cards.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/choice-cards.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/choice-cards.json
One file, no dependencies (4.2 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/choice-cards.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/choice-cards.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/choice-cards.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/choice-cards.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/choice-cards.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/choice-cards.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/choice-cards.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/choice-cards.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/choice-cards.js"></script>

The compiled install writes src/components/zubra/choice-cards.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<choice-cards label="Plan" name="plan"></choice-cards>

<script type="module">
  import './components/zubra/choice-cards.js';

  const element = document.querySelector('choice-cards');
  element.value = 'team';
  element.items = [
    {
      id: 'solo',
      title: 'Solo',
      detail: 'One project, community support',
      price: 'Free',
    },
    {
      id: 'team',
      title: 'Team',
      detail: 'Unlimited projects, five seats',
      price: '$12 / month',
      note: 'Most popular',
    },
    {
      id: 'org',
      title: 'Organisation',
      detail: 'SSO, audit log, priority support',
      price: '$49 / month',
    },
  ];
  element.addEventListener('valuechange', (event) => console.log('valuechange', event.detail));
</script>
Example.jsx
import './components/zubra/choice-cards.js';

const value = 'team';
const items = [
  {
    id: 'solo',
    title: 'Solo',
    detail: 'One project, community support',
    price: 'Free',
  },
  {
    id: 'team',
    title: 'Team',
    detail: 'Unlimited projects, five seats',
    price: '$12 / month',
    note: 'Most popular',
  },
  {
    id: 'org',
    title: 'Organisation',
    detail: 'SSO, audit log, priority support',
    price: '$49 / month',
  },
];

export function ChoiceCardsExample() {
  return (
    <choice-cards
      label="Plan"
      name="plan"
      value={value}
      items={items}
      onvaluechange={(event) => console.log('valuechange', event.detail)}
    ></choice-cards>
  );
}
Example.vue
<script setup>
import './components/zubra/choice-cards.js';
const value = 'team';
const items = [
  {
    id: 'solo',
    title: 'Solo',
    detail: 'One project, community support',
    price: 'Free',
  },
  {
    id: 'team',
    title: 'Team',
    detail: 'Unlimited projects, five seats',
    price: '$12 / month',
    note: 'Most popular',
  },
  {
    id: 'org',
    title: 'Organisation',
    detail: 'SSO, audit log, priority support',
    price: '$49 / month',
  },
];
const onValuechange = (event) => console.log('valuechange', event.detail);
</script>

<template>
  <choice-cards
    label="Plan"
    name="plan"
    :value.prop="value"
    :items.prop="items"
    @valuechange="onValuechange"
  ></choice-cards>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/choice-cards.js';
  const value = 'team';
  const items = [
    {
      id: 'solo',
      title: 'Solo',
      detail: 'One project, community support',
      price: 'Free',
    },
    {
      id: 'team',
      title: 'Team',
      detail: 'Unlimited projects, five seats',
      price: '$12 / month',
      note: 'Most popular',
    },
    {
      id: 'org',
      title: 'Organisation',
      detail: 'SSO, audit log, priority support',
      price: '$49 / month',
    },
  ];
</script>

<choice-cards
  label="Plan"
  name="plan"
  {value}
  {items}
  onvaluechange={(event) => console.log('valuechange', event.detail)}
></choice-cards>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/choice-cards.js';

@Component({
  selector: 'app-choice-cards-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <choice-cards
      label="Plan"
      name="plan"
      [value]="value"
      [items]="items"
      (valuechange)="onValuechange($event)"
    ></choice-cards>
  `,
})
export class ChoiceCardsExample {
  value = 'team';

  items = [
    {
      id: 'solo',
      title: 'Solo',
      detail: 'One project, community support',
      price: 'Free',
    },
    {
      id: 'team',
      title: 'Team',
      detail: 'Unlimited projects, five seats',
      price: '$12 / month',
      note: 'Most popular',
    },
    {
      id: 'org',
      title: 'Organisation',
      detail: 'SSO, audit log, priority support',
      price: '$49 / month',
    },
  ];

  onValuechange(event: Event) {
    console.log('valuechange', (event as CustomEvent).detail);
  }
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
valuestring""
items
property only
{ id, title, detail, price }[][]
requiredbooleanfalse
disabledbooleanfalse
labelstring""
Events
EventWhen
valuechangeThe choice changed; detail is the chosen id.

Size

1.6 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.4 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour