# Accordion

shadcn accordion where each item is a raised bevelled box, with beveled chevron toggles and no easing.

Source: https://www.ui95.dev/ui/accordion

## Examples

```tsx
import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from "@/components/ui/accordion"

import type { ShowcaseDemo } from "../types"

const ENTRIES = [
  { value: "hardware", title: "Hardware", body: "486DX2 66 MHz, 8 MB RAM, turbo button." },
  { value: "software", title: "Software", body: "DOS 6.22, a paint program, three games." },
  { value: "network", title: "Network", body: "None. The modem is in a drawer." },
] as const

function renderItems(disabledValue?: string) {
  return ENTRIES.map(({ value, title, body }) => (
    <AccordionItem key={value} value={value} disabled={value === disabledValue}>
      <AccordionTrigger>{title}</AccordionTrigger>
      <AccordionContent>{body}</AccordionContent>
    </AccordionItem>
  ))
}

export const demo: ShowcaseDemo = {
  span: "tall",
  variants: [
    {
      label: "single, collapsible",
      render: () => (
        <Accordion type="single" collapsible defaultValue="hardware">
          {renderItems()}
        </Accordion>
      ),
    },
    {
      label: "multiple, disabled item",
      render: () => (
        <Accordion type="multiple" defaultValue={["software"]}>
          {renderItems("network")}
        </Accordion>
      ),
    },
  ],
}
```

## Installation

```bash
npx shadcn@latest add https://www.ui95.dev/r/accordion.json
```

Run it in a Radix shadcn project that already has the UI95 theme.

Dependencies:

```bash
npm install cn radix-ui
```

Add these items first:

- [pixel-glyphs](https://www.ui95.dev/ui/pixel-glyphs)

`components/ui/accordion.tsx`

```tsx
"use client"

import { cn } from "cn"
import { Accordion as AccordionPrimitive } from "radix-ui"
import * as React from "react"

import { ChevronGlyph } from "@/components/ui/pixel-glyphs"

function Accordion({
  className,
  ...props
}: React.ComponentProps<typeof AccordionPrimitive.Root>) {
  return (
    <AccordionPrimitive.Root
      data-slot="accordion"
      className={cn("flex w-full flex-col gap-2", className)}
      {...props}
    />
  )
}

function AccordionItem({
  className,
  ...props
}: React.ComponentProps<typeof AccordionPrimitive.Item>) {
  return (
    <AccordionPrimitive.Item
      data-slot="accordion-item"
      className={cn("pixel-border border-border bg-card text-card-foreground bevel-raised offset-shadow-none", className)}
      {...props}
    />
  )
}

function AccordionTrigger({
  className,
  children,
  ...props
}: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
  return (
    <AccordionPrimitive.Header className="flex">
      <AccordionPrimitive.Trigger
        data-slot="accordion-trigger"
        className={cn(
          "group/accordion-trigger relative flex flex-1 items-center justify-between gap-3 px-3 py-3 text-left font-pixel text-[16px] leading-none uppercase hover:underline hover:decoration-(length:--pixel) hover:underline-offset-4 disabled:pointer-events-none disabled:text-muted-foreground **:data-[slot=accordion-trigger-icon]:ml-auto",
          className
        )}
        {...props}
      >
        {children}
        <span
          data-slot="accordion-trigger-icon"
          className="pointer-events-none grid size-5 shrink-0 place-items-center pixel-border border-border bg-secondary text-secondary-foreground bevel-raised offset-shadow-none group-aria-expanded/accordion-trigger:bevel-sunken"
        >
          <ChevronGlyph className="group-aria-expanded/accordion-trigger:hidden" />
          <ChevronGlyph direction="up" className="hidden group-aria-expanded/accordion-trigger:block" />
        </span>
      </AccordionPrimitive.Trigger>
    </AccordionPrimitive.Header>
  )
}

function AccordionContent({
  className,
  children,
  ...props
}: React.ComponentProps<typeof AccordionPrimitive.Content>) {
  return (
    <AccordionPrimitive.Content
      data-slot="accordion-content"
      className="overflow-hidden text-xl leading-tight"
      {...props}
    >
      <div
        className={cn(
          "px-3 pt-0 pb-3 [&_a]:underline [&_a]:decoration-(length:--pixel) [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4",
          className
        )}
      >
        {children}
      </div>
    </AccordionPrimitive.Content>
  )
}

export { Accordion, AccordionContent, AccordionItem, AccordionTrigger }
```

## API reference

### Accordion

No props of its own. It forwards the props of the element or primitive it wraps.

### AccordionContent

No props of its own. It forwards the props of the element or primitive it wraps.

### AccordionItem

No props of its own. It forwards the props of the element or primitive it wraps.

### AccordionTrigger

No props of its own. It forwards the props of the element or primitive it wraps.
