shadcn.io is not affiliated with official shadcn/ui
Code Snippet FAQ Block for React
An SDK FAQ for a webhook service: five questions whose answers are code windows with curl, Node and Python tabs and a copy button, in a band of hairline rows.
Installation
Overview
An FAQ for React with Base UI whose answers hold code. A start-aligned header sits over a band of five questions that run from rail to rail under a rule with + marks; each answer is a sentence and a code window with curl, Node and Python tabs and a copy button. The language you pick follows you through every answer, and every window keeps the height of its tallest snippet, so switching never moves the page. The code follows your theme: keywords are bold, calls medium, comments muted, and nothing is coloured. It's built from Accordion, Tabs, Syntax Text, Copy Button and Guides, with CSS for the entrance. For SDK pages, API docs and developer onboarding where each answer is half prose and half code.
FAQ
How do I change the snippets?
Edit QUESTIONS at the top of the file: each entry has an id, the question, an answer sentence and a code object with one string per language. LANGUAGES lists the tabs and the words each language's highlighter sets in bold; add a language there and give every question a snippet for it. The window's minimum height is worked out from the longest snippet of each question.
How does the language choice work?
All the code windows share one useState, so choosing Node in one answer shows Node in every other, open or not. Each window is its own set of tabs with a named tab list, and the arrow keys move between languages.
Base UI's tabs select on focus here, the same as the other bases, so an arrow key both moves and chooses.
Is the code highlighted?
Yes, by weight and tone instead of colour. Syntax Text finds the keywords, calls, strings, numbers and comments, and the block sets keywords in semibold, calls in medium and comments in muted italic, all in the theme's foreground colours, so the code reads the same in every preset, light or dark. The per-token fade-in is turned off: a code answer should be there when it opens.
What does the copy button copy?
The snippet for the language that's showing, as plain text: no line numbers and no prompt. After it copies, the icon becomes a check and a polite status says "Copied" to screen readers.
Related
- Pro
API Error Codes FAQ
Code and mediaAn error-code FAQ for a geocoding API: seven status codes as accordion rows with a mono chip, a cause, a fix, the header to look for and a retry verdict, beside a retry-rules note.
- Pro
Schema Inspector FAQ
Code and mediaA headless-CMS FAQ with a live schema inspector: six questions beside a sticky JSON tree of the FAQPage data that expands and highlights the open question, a button to copy the JSON and one JSON-LD script.
- Pro
Copy Reply FAQ
Reading and sharingA support playbook FAQ for a help desk: each situation opens on the team's advice and a reply to send, with its length in characters and a Copy reply button.
- Pro
Install Command Snippet Hero
Code and terminalA compact centred hero for a web framework: an install command with a copy button, two calls to action and a band of three stats.
- Pro
Inset Code Snippet Copy CTA
Code and commandsA card-in-card call to action for a data SDK, split by a hairline: the headline, one sentence and a Shine Button at the start, and a three-line quickstart snippet with a copy button on every line and a Copy all button at the end.
- Pro
JSON-LD FAQ
Code and mediaA gift-shop FAQ that shows what its structured data is for: six questions beside a mock search result with an FAQ rich result, and one FAQPage JSON-LD script built from the same list.