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
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
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
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
<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
<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>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>
);
}<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('-') } } }) --><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>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
| Property | Type | Default |
|---|---|---|
value | string | "" |
itemsproperty only | { id, title, detail, price }[] | [] |
required | boolean | false |
disabled | boolean | false |
label | string | "" |
| Event | When |
|---|---|
valuechange | The 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.