FAQ Block (Astro)
contentbit/astro-faqFreeComponent
Accordion of question/answer pairs.
Install it
npx shadcn@latest add https://contentbit.dev/r/astro-faq.jsonSource
1---2import type { FaqData, FaqItemData } from '@contentbit/blocks'3import type { ValidatedBlockNode } from '@contentbit/core'4import type { AstroBlockContext } from '@contentbit/astro'56import { isValidatedBlock } from '@contentbit/core'78interface Props {9 node: ValidatedBlockNode<unknown>10 ctx: AstroBlockContext11}1213const { node, ctx } = Astro.props14const data = node.data as FaqData15const items = await Promise.all(16 data.blocks.map(async (item) => ({17 question: String(item.props.question),18 html: await ctx.renderMarkdown(isValidatedBlock(item) ? (item.data as FaqItemData).markdown : item.body),19 })),20)2122// Inline lucide path: chevron-down.23const CHEVRON = '<path d="m6 9 6 6 6-6"/>'2425// Native <details> means items open independently (the React pack's accordion26// is single-open). Add name="faq" to the <details> elements for exclusivity.27---2829<div data-cb-styled class="bg-card my-6 rounded-lg border px-4">30 {31 items.map((item, i) => (32 <details class:list={['group', i < items.length - 1 && 'border-b']}>33 <summary class="flex cursor-pointer list-none items-center justify-between gap-4 py-4 text-left text-sm font-medium [&::-webkit-details-marker]:hidden">34 {item.question}35 <svg36 xmlns="http://www.w3.org/2000/svg"37 viewBox="0 0 24 24"38 fill="none"39 stroke="currentColor"40 stroke-width="2"41 stroke-linecap="round"42 stroke-linejoin="round"43 class="text-muted-foreground size-4 shrink-0 transition-transform group-open:rotate-180"44 aria-hidden="true"45 set:html={CHEVRON}46 />47 </summary>48 <div class="text-muted-foreground pb-4 text-sm leading-relaxed" set:html={item.html} />49 </details>50 ))51 }52</div>
What it pulls in
npm packages
Files it writes
More from contentbit
All 20 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Callout Block (Astro)astro-callout | contentbit | Components | Free | 3 deps | |
| Comparison Block (Astro)astro-comparison | contentbit | Components | Free | 3 deps | |
| Content Renderer (Astro)astro-content-renderer | contentbit | Components | Free | 3 deps | |
| Key Metrics Block (Astro)astro-key-metrics | contentbit | Components | Free | 3 deps | |
| Pros & Cons Block (Astro)astro-pros-cons | contentbit | Components | Free | 3 deps | |
| Quick Reference Block (Astro)astro-quick-ref | contentbit | Components | Free | 3 deps | |
| Steps Block (Astro)astro-steps | contentbit | Components | Free | 3 deps | |
| Tabs Block (Astro)astro-tabs | contentbit | Components | Free | 3 deps |
