Hairline FAQ Accordion
A serif 'Questions' heading above rows of medium-weight sans questions separated by thin hairline rules. A small grey chevron sits on the right edge.
Rebuilt from arc.net in the Obsidian Farewell Editorial style.
npx shadcn@latest add https://justyoink.it/r/obsidian-farewell-editorial/blocks/hairline-faq-accordion.json
Looks exactly like arc.net: brings its fonts and colours, namespaced so your own theme stays untouched.
npx shadcn@latest add https://justyoink.it/r/obsidian-farewell-editorial/mine/hairline-faq-accordion.json
Restyled to your project: uses your shadcn colours, fonts and radius, so it matches the rest of your app. Layout, type sizes and motion stay as designed.
Usage
Pass `heading` and an `items` array of {q, a} to customize. Click a row to expand it; only one panel is open at a time.
components/hairline-faq-accordion.tsx
"use client"; import { useEffect, useLayoutEffect, useRef, type CSSProperties, type ElementType, type ReactNode, type RefObject } from "react"; import { useState } from "react"; type Item = { q: string; a: string }; const DEFAULT_ITEMS: Item[] = [ { q: "How long will the old planner stay available?", a: "The legacy planner keeps working through the end of the transition period. We will email every account well before any change takes effect." }, { q: "Which app takes its place?", a: "Our new workspace app covers everything the planner did, with a faster editor and shared boards for teams." }, { q: "Can my notes move over automatically?", a: "Yes. Open settings, choose Import, and your notes and folders are copied across in a few minutes." }, { q: "Is it possible to download my boards?", a: "Every board can be exported as plain files from the board menu at any time." }, { q: "What becomes of my saved files?", a: "Your files stay stored securely until you choose to delete them, and you can request removal whenever you like." }, { q: "Does the pocket edition keep working?", a: "The pocket edition continues to sync until the transition ends, then moves into the new app." }, { q: "Who can I contact with something unusual?", a: "Our support team replies within one business day through the help center or by email." }, { q: "Why should I switch to the new workspace?", a: "It is quicker, simpler to share, and built to keep growing with the way you plan your work." }, ]; export default function HairlineFaqAccordion({ heading = "Questions", items = DEFAULT_ITEMS }: { heading?: string; items?: Item[] }) { const [open, setOpen] = useState<number | null>(null); return ( <section className="bg-canvas px-6 py-24 md:px-12"> <div className="mx-auto max-w-[1070px]"> <Reveal from="up"> <h2 className="font-display text-display text-ink-soft mb-16">{heading}</h2> </Reveal> <ul className="border-b border-hairline"> {items.map((it, i) => { const isOpen = open === i; return ( <li key={i} className="border-t border-hairline first:border-t-0"> <h3> <button type="button" aria-expanded={isOpen} aria-controls={`faq-panel-${i}`} onClick={() => setOpen(isOpen ? null : i)} className="flex w-full items-center justify-between gap-6 py-6 text-left font-sans text-body-lg font-medium text-ink focus-visible:outline-2 focus-visible:outline-focus-ring" > <span>{it.q}</span> <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" className={`shrink-0 text-faint transition-transform duration-[250ms] ease-[cubic-bezier(0.16,1,0.3,1)] ${isOpen ? "rotate-180" : ""}`} > <path d="M2 5l5 5 5-5" /> </svg> </button> </h3> <div id={`faq-panel-${i}`} role="region" className={`grid transition-[grid-template-rows] duration-[280ms] ease-[cubic-bezier(0.16,1,0.3,1)] ${isOpen ? "grid-rows-[1fr]" : "grid-rows-[0fr]"}`} > <div className="overflow-hidden"> <p className="max-w-2xl pb-6 font-sans text-body text-muted">{it.a}</p> </div> </div> </li> ); })} </ul> </div> </section> ); } // ---- Yoink motion (inlined, no dependencies): Reveal ---- const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)"; const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect; function ykReducedMotion(): boolean { return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches; } // "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance. // Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed, // and there is a box to watch), and a safety net reveals anything on screen that is still hidden. type YkRevealState = "idle" | "hidden" | "shown"; function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState { const [state, setState] = useState<YkRevealState>("idle"); useYkLayoutEffect(() => { const el = ref.current; if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return; // watch the element's own box, or its children when it has none (display: contents) const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]); const onScreen = (t: Element) => { const r = t.getBoundingClientRect(); return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth; }; if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible let shown = false; const show = (v: boolean) => { if (v !== shown) (shown = v), setState(v ? "shown" : "hidden"); }; setState("hidden"); const inView = new Set<Element>(); const io = new IntersectionObserver((entries) => { for (const e of entries) { if (e.isIntersecting) inView.add(e.target); else inView.delete(e.target); } if (inView.size) { show(true); if (once) io.disconnect(); } else if (!once) show(false); }); const watched = new Set<Element>(); const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t))); watch(); // safety net: styles that land after mount (display: contents) get watched too, and nothing // stays hidden for more than a moment while it is actually on screen const start = Date.now(); const net = setInterval(() => { if (shown) return once && clearInterval(net); watch(); if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true); }, 600); return () => { io.disconnect(); clearInterval(net); }; }, [once]); return state; } type YkRevealFrom = "up" | "down" | "left" | "right" | "scale" | "blur" | "none"; /** Fades content in as it scrolls into view. */ function Reveal({ children, from = "up", delay = 0, duration = 700, distance = 24, once = true, as = "div", className, style, }: { children?: ReactNode; from?: YkRevealFrom; delay?: number; duration?: number; distance?: number; once?: boolean; as?: ElementType; className?: string; style?: CSSProperties; }) { const Tag = as; const ref = useRef<HTMLElement>(null); const state = useYkReveal(ref, once); const hidden = state === "hidden"; const offset = { up: `translate3d(0, ${distance}px, 0)`, down: `translate3d(0, ${-distance}px, 0)`, left: `translate3d(${-distance}px, 0, 0)`, right: `translate3d(${distance}px, 0, 0)`, scale: "scale(0.94)", blur: `translate3d(0, ${distance / 2}px, 0)`, none: "none", }[from]; const t = `${duration}ms ${YK_EASE} ${delay}ms`; return ( <Tag ref={ref} className={className} style={{ ...style, ...(hidden && { opacity: 0, transform: offset, filter: from === "blur" ? "blur(12px)" : undefined }), ...(state === "shown" && { transition: `opacity ${t}, transform ${t}, filter ${t}` }), }} > {children} </Tag> ); }"use client"; import { useEffect, useLayoutEffect, useRef, type CSSProperties, type ElementType, type ReactNode, type RefObject } from "react"; import { useState } from "react"; type Item = { q: string; a: string }; const DEFAULT_ITEMS: Item[] = [ { q: "How long will the old planner stay available?", a: "The legacy planner keeps working through the end of the transition period. We will email every account well before any change takes effect." }, { q: "Which app takes its place?", a: "Our new workspace app covers everything the planner did, with a faster editor and shared boards for teams." }, { q: "Can my notes move over automatically?", a: "Yes. Open settings, choose Import, and your notes and folders are copied across in a few minutes." }, { q: "Is it possible to download my boards?", a: "Every board can be exported as plain files from the board menu at any time." }, { q: "What becomes of my saved files?", a: "Your files stay stored securely until you choose to delete them, and you can request removal whenever you like." }, { q: "Does the pocket edition keep working?", a: "The pocket edition continues to sync until the transition ends, then moves into the new app." }, { q: "Who can I contact with something unusual?", a: "Our support team replies within one business day through the help center or by email." }, { q: "Why should I switch to the new workspace?", a: "It is quicker, simpler to share, and built to keep growing with the way you plan your work." }, ]; export default function HairlineFaqAccordion({ heading = "Questions", items = DEFAULT_ITEMS }: { heading?: string; items?: Item[] }) { const [open, setOpen] = useState<number | null>(null); return ( <section className="bg-background px-6 py-24 md:px-12"> <div className="mx-auto max-w-[1070px]"> <Reveal from="up"> <h2 className="font-sans text-obsidian-display text-muted-foreground mb-16">{heading}</h2> </Reveal> <ul className="border-b border-border"> {items.map((it, i) => { const isOpen = open === i; return ( <li key={i} className="border-t border-border first:border-t-0"> <h3> <button type="button" aria-expanded={isOpen} aria-controls={`faq-panel-${i}`} onClick={() => setOpen(isOpen ? null : i)} className="flex w-full items-center justify-between gap-6 py-6 text-left font-sans text-obsidian-body-lg font-medium text-foreground focus-visible:outline-2 focus-visible:outline-ring" > <span>{it.q}</span> <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" className={`shrink-0 text-muted-foreground transition-transform duration-[250ms] ease-[cubic-bezier(0.16,1,0.3,1)] ${isOpen ? "rotate-180" : ""}`} > <path d="M2 5l5 5 5-5" /> </svg> </button> </h3> <div id={`faq-panel-${i}`} role="region" className={`grid transition-[grid-template-rows] duration-[280ms] ease-[cubic-bezier(0.16,1,0.3,1)] ${isOpen ? "grid-rows-[1fr]" : "grid-rows-[0fr]"}`} > <div className="overflow-hidden"> <p className="max-w-2xl pb-6 font-sans text-obsidian-body text-muted-foreground">{it.a}</p> </div> </div> </li> ); })} </ul> </div> </section> ); } // ---- Yoink motion (inlined, no dependencies): Reveal ---- const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)"; const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect; function ykReducedMotion(): boolean { return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches; } // "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance. // Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed, // and there is a box to watch), and a safety net reveals anything on screen that is still hidden. type YkRevealState = "idle" | "hidden" | "shown"; function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState { const [state, setState] = useState<YkRevealState>("idle"); useYkLayoutEffect(() => { const el = ref.current; if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return; // watch the element's own box, or its children when it has none (display: contents) const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]); const onScreen = (t: Element) => { const r = t.getBoundingClientRect(); return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth; }; if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible let shown = false; const show = (v: boolean) => { if (v !== shown) (shown = v), setState(v ? "shown" : "hidden"); }; setState("hidden"); const inView = new Set<Element>(); const io = new IntersectionObserver((entries) => { for (const e of entries) { if (e.isIntersecting) inView.add(e.target); else inView.delete(e.target); } if (inView.size) { show(true); if (once) io.disconnect(); } else if (!once) show(false); }); const watched = new Set<Element>(); const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t))); watch(); // safety net: styles that land after mount (display: contents) get watched too, and nothing // stays hidden for more than a moment while it is actually on screen const start = Date.now(); const net = setInterval(() => { if (shown) return once && clearInterval(net); watch(); if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true); }, 600); return () => { io.disconnect(); clearInterval(net); }; }, [once]); return state; } type YkRevealFrom = "up" | "down" | "left" | "right" | "scale" | "blur" | "none"; /** Fades content in as it scrolls into view. */ function Reveal({ children, from = "up", delay = 0, duration = 700, distance = 24, once = true, as = "div", className, style, }: { children?: ReactNode; from?: YkRevealFrom; delay?: number; duration?: number; distance?: number; once?: boolean; as?: ElementType; className?: string; style?: CSSProperties; }) { const Tag = as; const ref = useRef<HTMLElement>(null); const state = useYkReveal(ref, once); const hidden = state === "hidden"; const offset = { up: `translate3d(0, ${distance}px, 0)`, down: `translate3d(0, ${-distance}px, 0)`, left: `translate3d(${-distance}px, 0, 0)`, right: `translate3d(${distance}px, 0, 0)`, scale: "scale(0.94)", blur: `translate3d(0, ${distance / 2}px, 0)`, none: "none", }[from]; const t = `${duration}ms ${YK_EASE} ${delay}ms`; return ( <Tag ref={ref} className={className} style={{ ...style, ...(hidden && { opacity: 0, transform: offset, filter: from === "blur" ? "blur(12px)" : undefined }), ...(state === "shown" && { transition: `opacity ${t}, transform ${t}, filter ${t}` }), }} > {children} </Tag> ); }
Quality checks
Automated, in a real browser · 4d ago- Accessible: passedNo serious accessibility problems (axe-core): readable contrast, labelled buttons and images.
- Responsive: passedRenders at phone (390px), tablet (768px) and desktop width without sideways scrolling.
- Dark mode: passedStill readable when installed in your theme and switched to dark mode.
- Themeable: passedUses design tokens rather than hard-coded colours, so it follows your theme cleanly.
- Animates cleanly: passedIts animation plays and finishes with everything visible, and it stays still for people who turn on reduced motion.