Zubra UI
Code for
GitHub

faq-list

Frequently asked questions, each opening to its answer, on native <details>: the browser does the keyboard, find-in-page opens the right answer, and with single only one is open at a time. items is [{ question, answer }].

This one has no events: it shows what it's given.

Source: faq-list.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/faq-list.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/faq-list.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/faq-list.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/faq-list.json
One file, no dependencies (4.3 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/faq-list.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/faq-list.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/faq-list.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/faq-list.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/faq-list.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/faq-list.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/faq-list.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/faq-list.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/faq-list.js"></script>

The compiled install writes src/components/zubra/faq-list.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
<faq-list heading="Questions"></faq-list>

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

  const element = document.querySelector('faq-list');
  element.single = true;
  element.items = [
    {
      question: 'Do I need my own starter?',
      answer: 'No. Every class gives you a starter to take home, with a feeding schedule.',
    },
    {
      question: 'Can I cancel?',
      answer: 'Yes, up to 48 hours before the class, for a full refund.',
    },
    {
      question: 'Are classes accessible?',
      answer: 'The kitchen is step-free, and benches can be lowered.',
    },
  ];
</script>
Example.jsx
import './components/zubra/faq-list.js';

const single = true;
const items = [
  {
    question: 'Do I need my own starter?',
    answer: 'No. Every class gives you a starter to take home, with a feeding schedule.',
  },
  {
    question: 'Can I cancel?',
    answer: 'Yes, up to 48 hours before the class, for a full refund.',
  },
  {
    question: 'Are classes accessible?',
    answer: 'The kitchen is step-free, and benches can be lowered.',
  },
];

export function FaqListExample() {
  return (
    <faq-list heading="Questions" single={single} items={items}></faq-list>
  );
}
Example.vue
<script setup>
import './components/zubra/faq-list.js';
const single = true;
const items = [
  {
    question: 'Do I need my own starter?',
    answer: 'No. Every class gives you a starter to take home, with a feeding schedule.',
  },
  {
    question: 'Can I cancel?',
    answer: 'Yes, up to 48 hours before the class, for a full refund.',
  },
  {
    question: 'Are classes accessible?',
    answer: 'The kitchen is step-free, and benches can be lowered.',
  },
];
</script>

<template>
  <faq-list heading="Questions" :single.prop="single" :items.prop="items"></faq-list>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/faq-list.js';
  const single = true;
  const items = [
    {
      question: 'Do I need my own starter?',
      answer: 'No. Every class gives you a starter to take home, with a feeding schedule.',
    },
    {
      question: 'Can I cancel?',
      answer: 'Yes, up to 48 hours before the class, for a full refund.',
    },
    {
      question: 'Are classes accessible?',
      answer: 'The kitchen is step-free, and benches can be lowered.',
    },
  ];
</script>

<faq-list heading="Questions" {single} {items}></faq-list>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/faq-list.js';

@Component({
  selector: 'app-faq-list-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <faq-list heading="Questions" [single]="single" [items]="items"></faq-list>
  `,
})
export class FaqListExample {
  single = true;

  items = [
    {
      question: 'Do I need my own starter?',
      answer: 'No. Every class gives you a starter to take home, with a feeding schedule.',
    },
    {
      question: 'Can I cancel?',
      answer: 'Yes, up to 48 hours before the class, for a full refund.',
    },
    {
      question: 'Are classes accessible?',
      answer: 'The kitchen is step-free, and benches can be lowered.',
    },
  ];
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
items
property only
{ question, answer }[][]
headingstring""
singlebooleanfalse
Slots
SlotFor
headingA heading above the list (defaults to heading, shown only when set).

Size

1.1 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 17.3 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