ai2
componentaccordion-accentsource: ok · hit
Accent accordion
Styled accordion: the Accent set. 5 decorative accordion variations (BarAccordion, GrowAccordion, GlowAccordion, LeftAccordion, FullAccordion) on the ai2 token system, powered by framer-motion, reduced-motion aware and sized sm to xl. Part of the free styled layer.
npx shadcn add "https://ai2.design/r/accordion-accent.json"free
Interaction
accordion
Tags auto-generated by rules on 9/24/2026 — empty means no evidence, not lack of support.
Dependencies
Bundle weight · lightmotion@^12.42.2lucide-react@^1.23.0
Registry dependencies
@ai2/tokens
Files1 · source cached 10/8/2026, 6:00:37 PM
registry/ai2/styled/accordion-accent.tsx
"use client"
import * as React from "react"
import { ChevronDown } from "lucide-react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Accent accordion family: 5 left-bar accordions. When a row opens, a primary
bar on the left edge grows or glows; the variants change how the bar behaves.
Every export is a complete accordion: internal single-open state, a button
header with aria-expanded, framer height auto animation. Colour comes ONLY
from tokens. Alpha via color-mix. Under reduced-motion the bar appears
instantly instead of transforming and the panel opens instantly. Size =
padding + text scale. Renders without props too. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
export interface StyledAccordionItem {
value: string
title: React.ReactNode
content: React.ReactNode
}
interface StyledAccordionProps {
className?: string
size?: StyledSize
items?: StyledAccordionItem[]
defaultOpen?: string
}
const headerPad: Record<StyledSize, string> = {
sm: "px-3 py-2.5 text-sm",
md: "px-4 py-3 text-sm",
lg: "px-5 py-4 text-base",
xl: "px-6 py-5 text-lg",
}
const bodyPad: Record<StyledSize, string> = {
sm: "px-3 pb-2.5 text-sm",
md: "px-4 pb-3 text-sm",
lg: "px-5 pb-4 text-base",
xl: "px-6 pb-5 text-base",
}
const iconSize: Record<StyledSize, string> = {
sm: "size-4",
md: "size-4",
lg: "size-5",
xl: "size-5",
}
const defaultItems: StyledAccordionItem[] = [
{
value: "item-1",
title: "What is included?",
content:
"Every plan ships the full component library, semantic tokens, and lifetime updates for the tier you own.",
},
{
value: "item-2",
title: "How does installation work?",
content:
"Add any component with a single CLI command. Files land in your project and stay fully editable.",
},
{
value: "item-3",
title: "Can I use it in production?",
content:
"Yes. The system is framework agnostic, self contained, and safe to ship to any number of projects.",
},
]
function useSingleOpen(defaultOpen?: string) {
const [open, setOpen] = React.useState<string | null>(defaultOpen ?? null)
const toggle = React.useCallback(
(value: string) => setOpen((cur) => (cur === value ? null : value)),
[]
)
return { open, toggle }
}
const headerBase =
"flex w-full items-center justify-between gap-3 text-left font-medium outline-none transition-colors focus-visible:ring-[3px] focus-visible:ring-ring/50"
function Panel({
isOpen,
size,
children,
}: {
isOpen: boolean
size: StyledSize
children: React.ReactNode
}) {
const reduce = useReducedMotion()
return (
<AnimatePresence initial={false}>
{isOpen && (
<motion.div
key="panel"
initial={reduce ? false : { height: 0, opacity: 0 }}
animate={{ height: "auto", opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={
reduce ? { duration: 0 } : { duration: 0.25, ease: [0.4, 0, 0.2, 1] }
}
className="overflow-hidden"
>
<div className={cn(bodyPad[size], "text-muted-foreground")}>
{children}
</div>
</motion.div>
)}
</AnimatePresence>
)
}
function Chevron({ isOpen, size }: { isOpen: boolean; size: StyledSize }) {
const reduce = useReducedMotion()
return (
<motion.span
aria-hidden
className="shrink-0 text-muted-foreground"
animate={{ rotate: isOpen ? 180 : 0 }}
transition={reduce ? { duration: 0 } : { duration: 0.2 }}
>
<ChevronDown className={iconSize[size]} />
</motion.span>
)
}
interface BarStyle {
/* the width of the bar */
width: string
/* acikken satira uygulanan ek arka plan */
openBg?: string
/* acikken bar'a uygulanan ek his (or. glow) */
openBar?: string
/* origin: dikey buyume mi yoksa yatay kayma mi */
mode: "grow" | "slide" | "fade"
}
/* Shared accent shell: an animated primary bar on the left of every row. The
bar grows, slides or glows on open and returns on close. barStyle is each
variant's behaviour. */
function AccentShell({
props,
barStyle,
}: {
props: StyledAccordionProps
barStyle: BarStyle
}) {
const { className, size = "md", items = defaultItems, defaultOpen } = props
const { open, toggle } = useSingleOpen(defaultOpen)
const reduce = useReducedMotion()
return (
<div
data-slot="styled-accordion"
className={cn(
"overflow-hidden rounded-xl border border-border bg-background",
className
)}
>
{items.map((item, i) => {
const isOpen = open === item.value
const barAnim =
barStyle.mode === "grow"
? { scaleY: isOpen ? 1 : 0 }
: barStyle.mode === "slide"
? { x: isOpen ? 0 : -4, opacity: isOpen ? 1 : 0 }
: { opacity: isOpen ? 1 : 0 }
return (
<div
key={item.value}
className={cn(
"relative transition-colors",
i > 0 && "border-t border-border",
isOpen && barStyle.openBg
)}
>
<motion.span
aria-hidden
className={cn(
"absolute left-0 top-0 bottom-0 origin-top rounded-full bg-primary",
barStyle.width,
isOpen && barStyle.openBar
)}
initial={false}
animate={reduce ? { opacity: isOpen ? 1 : 0 } : barAnim}
transition={
reduce
? { duration: 0 }
: { type: "spring" as const, stiffness: 320, damping: 30 }
}
/>
<button
type="button"
aria-expanded={isOpen}
onClick={() => toggle(item.value)}
className={cn(
headerBase,
headerPad[size],
"hover:bg-[color-mix(in_oklab,var(--color-foreground)_5%,transparent)]"
)}
>
{item.title}
<Chevron isOpen={isOpen} size={size} />
</button>
<Panel isOpen={isOpen} size={size}>
{item.content}
</Panel>
</div>
)
})}
</div>
)
}
/* Bar: klasik ince sol bar, acikken dikey buyur. */
export function BarAccordion(props: StyledAccordionProps) {
return <AccentShell props={props} barStyle={{ width: "w-1", mode: "grow" }} />
}
/* Grow: a thicker bar, growing vertically when open plus a soft row fill. */
export function GrowAccordion(props: StyledAccordionProps) {
return (
<AccentShell
props={props}
barStyle={{
width: "w-1.5",
mode: "grow",
openBg: "bg-[color-mix(in_oklab,var(--color-primary)_8%,transparent)]",
}}
/>
)
}
/* Glow: bar acikken parlar (primary tonlu golge). */
export function GlowAccordion(props: StyledAccordionProps) {
return (
<AccentShell
props={props}
barStyle={{
width: "w-1",
mode: "grow",
openBar:
"shadow-[0_0_10px_2px_color-mix(in_oklab,var(--color-primary)_55%,transparent)]",
}}
/>
)
}
/* Left: bar soldan kayarak girer (slide-in). */
export function LeftAccordion(props: StyledAccordionProps) {
return <AccentShell props={props} barStyle={{ width: "w-1", mode: "slide" }} />
}
/* Full: a thick bar appearing with a fade plus a pronounced row fill. */
export function FullAccordion(props: StyledAccordionProps) {
return (
<AccentShell
props={props}
barStyle={{
width: "w-2",
mode: "fade",
openBg: "bg-[color-mix(in_oklab,var(--color-primary)_12%,transparent)]",
}}
/>
)
}