About
Accordion whose items morph from pills into cards, inspired by Apple’s product pages. From chanhdai.com (ncdai), MIT.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Apple Accordion to your project and fits it to your theme.
Code
How Apple Accordion is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
"use client"
import { useState } from "react"
import { AppleAccordionClose, AppleAccordionContent, AppleAccordionItem, AppleAccordionList, AppleAccordionNext, AppleAccordionPrevious, AppleAccordionRoot, AppleAccordionTrigger, AppleAccordionTriggerIcon } from "@/components/ui/chanhdai-apple-accordion"
export default function AppleAccordionDemo() {
const [value, setValue] = useState<string | null>(null)
const image = ITEMS.find((item) => item.value === value)?.image ?? COVER
return (
<AppleAccordionRoot
value={value}
onValueChange={setValue}
className="mx-auto h-176 max-w-6xl overflow-hidden rounded-4xl bg-background"
>
{[COVER, ...ITEMS.map((item) => item.image)].map((src) => (
<img
key={src}
src={src}
alt=""
aria-hidden
data-current={src === image ? "" : undefined}
className="absolute inset-0 -z-10 size-full object-cover opacity-0 transition-opacity duration-500 ease-in-out data-current:opacity-100"
/>
))}
<div className="flex h-full items-center gap-4 px-4 sm:gap-8 sm:px-8">
<div className="flex flex-col gap-5">
<AppleAccordionPrevious aria-label="Previous place" />
<AppleAccordionNext aria-label="Next place" />
</div>
<AppleAccordionList aria-label="Places in Viet Nam">
{ITEMS.map((item) => (
<AppleAccordionItem key={item.value} value={item.value}>
<AppleAccordionTrigger>
<AppleAccordionTriggerIcon />
{item.title}
</AppleAccordionTrigger>
<AppleAccordionContent>
<p>
<span className="font-medium">{item.title}.</span>{" "}
{item.description}
</p>
</AppleAccordionContent>
</AppleAccordionItem>
))}
</AppleAccordionList>
</div>
<AppleAccordionClose className="absolute inset-e-4 top-4 sm:inset-e-6 sm:top-6" />
</AppleAccordionRoot>
)
}
const COVER =
"https://cdn.21st.dev/assets/mirror/86/86285c7b4acad6fc19168558cc4538e2605e1b4f56199983196c00bc3851685f.webp"
const ITEMS = [
{
value: "quang-ninh",
title: "Quang Ninh",
description:
"Home to Ha Long Bay, where nearly two thousand limestone islands rise from emerald water.",
image:
"https://cdn.21st.dev/assets/mirror/57/57efb3d570eaa9ae647f5887b968c8b0ce0f66e6fff5a6320307aefca66f1313.webp",
},
{
value: "an-giang",
title: "An Giang",
description:
"Rice fields, floating markets, and the Tra Su cajuput forest in the heart of the Mekong Delta.",
image:
"https://cdn.21st.dev/assets/mirror/b4/b4fb65e2e5c7ac593e9f79ceeae9d541ff859a2972ba4de74a250bfca60c867d.webp",
},
{
value: "ninh-binh",
title: "Ninh Binh",
description:
"Boats drift through limestone caves at Trang An, a UNESCO World Heritage site.",
image:
"https://cdn.21st.dev/assets/mirror/de/de60b04deb271175366bbe907a53cb240c7e80907e202521654813ee0eed1979.webp",
},
{
value: "hue",
title: "Hue",
description:
"The former imperial capital, with its Citadel and royal tombs along the Perfume River.",
image:
"https://cdn.21st.dev/assets/mirror/7d/7d37a67dd8421f1487d9da53dc3833ffa7d20c89f474e41fe17800d55ef5bdec.webp",
},
{
value: "ho-chi-minh-city",
title: "Ho Chi Minh City",
description:
"The country’s largest city, busy day and night, with street food on every corner.",
image:
"https://cdn.21st.dev/assets/mirror/08/08396b15719cd19a3538288753c83bb86caffa0abe59fd6a13751f04742d692b.webp",
},
{
value: "da-nang",
title: "Da Nang",
description:
"Long sandy beaches, the Dragon Bridge, and the Marble Mountains just south of the city.",
image:
"https://cdn.21st.dev/assets/mirror/68/6819739c0db23721ab9cff35b382a685d9e73f380da2c5f67c1ad88c0b107322.webp",
},
]







