|
1 | | -import React from "react"; |
2 | | - |
3 | | -export function Accordion() { |
4 | | - return ( |
5 | | - <div className="space-y-4 mx-auto"> |
6 | | - <details className="border-2 border-black shadow-md hover:shadow-sm transition-all overflow-hidden"> |
7 | | - <summary className="px-4 py-2 font-head text-black cursor-pointer focus:outline-none"> |
8 | | - Accordion Item 1 |
9 | | - </summary> |
10 | | - <div className="px-4 py-2 font-body bg-white text-gray-700"> |
11 | | - This is the content of the first accordion item. It is styled with |
12 | | - Tailwind CSS. |
13 | | - </div> |
14 | | - </details> |
15 | | - |
16 | | - <details className="border-2 border-black shadow-md hover:shadow-sm transition-all overflow-hidden"> |
17 | | - <summary className="px-4 py-2 font-head text-black cursor-pointer focus:outline-none"> |
18 | | - Accordion Item 2 |
19 | | - </summary> |
20 | | - <div className="px-4 py-2 font-body bg-white text-gray-700"> |
21 | | - This is the content of the second accordion item. It has a similar |
22 | | - style to maintain consistency. |
23 | | - </div> |
24 | | - </details> |
25 | | - |
26 | | - <details className="border-2 border-black shadow-md hover:shadow-sm transition-all overflow-hidden"> |
27 | | - <summary className="px-4 py-2 font-head text-black cursor-pointer focus:outline-none"> |
28 | | - Accordion Item 3 |
29 | | - </summary> |
30 | | - <div className="px-4 py-2 font-body bg-white text-gray-700"> |
31 | | - This is the content of the third accordion item. The details element |
32 | | - handles the toggle behavior. |
33 | | - </div> |
34 | | - </details> |
35 | | - </div> |
36 | | - ); |
37 | | -} |
| 1 | +"use client"; |
| 2 | + |
| 3 | +import * as React from "react"; |
| 4 | +import * as AccordionPrimitive from "@radix-ui/react-accordion"; |
| 5 | +import { ChevronDown } from "lucide-react"; |
| 6 | + |
| 7 | +import { cn } from "@/lib/utils"; |
| 8 | + |
| 9 | +const Accordion = AccordionPrimitive.Root; |
| 10 | + |
| 11 | +const AccordionItem = React.forwardRef< |
| 12 | + React.ElementRef<typeof AccordionPrimitive.Item>, |
| 13 | + React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item> |
| 14 | +>(({ className, ...props }, ref) => ( |
| 15 | + <AccordionPrimitive.Item |
| 16 | + ref={ref} |
| 17 | + className={cn( |
| 18 | + "border-2 border-black shadow-md hover:shadow-sm data-[state=open]:shadow-sm transition-all overflow-hidden", |
| 19 | + className |
| 20 | + )} |
| 21 | + {...props} |
| 22 | + /> |
| 23 | +)); |
| 24 | +AccordionItem.displayName = AccordionPrimitive.Item.displayName; |
| 25 | + |
| 26 | +const AccordionHeader = React.forwardRef< |
| 27 | + React.ElementRef<typeof AccordionPrimitive.Trigger>, |
| 28 | + React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger> |
| 29 | +>(({ className, children, ...props }, ref) => ( |
| 30 | + <AccordionPrimitive.Header className="flex"> |
| 31 | + <AccordionPrimitive.Trigger |
| 32 | + ref={ref} |
| 33 | + className={cn( |
| 34 | + "flex flex-1 items-start justify-between px-4 py-2 font-head text-black cursor-pointer focus:outline-none", |
| 35 | + className |
| 36 | + )} |
| 37 | + {...props} |
| 38 | + > |
| 39 | + {children} |
| 40 | + <ChevronDown className="h-4 w-4 shrink-0 transition-transform duration-200" /> |
| 41 | + </AccordionPrimitive.Trigger> |
| 42 | + </AccordionPrimitive.Header> |
| 43 | +)); |
| 44 | +AccordionHeader.displayName = AccordionPrimitive.Header.displayName; |
| 45 | + |
| 46 | +const AccordionContent = React.forwardRef< |
| 47 | + React.ElementRef<typeof AccordionPrimitive.Content>, |
| 48 | + React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content> |
| 49 | +>(({ className, children, ...props }, ref) => ( |
| 50 | + <AccordionPrimitive.Content |
| 51 | + ref={ref} |
| 52 | + className="overflow-hidden px-4 py-2 font-body bg-white text-gray-700 transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down" |
| 53 | + {...props} |
| 54 | + > |
| 55 | + <div className={cn("pb-4 pt-0", className)}>{children}</div> |
| 56 | + </AccordionPrimitive.Content> |
| 57 | +)); |
| 58 | + |
| 59 | +AccordionContent.displayName = AccordionPrimitive.Content.displayName; |
| 60 | + |
| 61 | +const AccordionComponent = Object.assign(Accordion, { |
| 62 | + Item: AccordionItem, |
| 63 | + Header: AccordionHeader, |
| 64 | + Content: AccordionContent, |
| 65 | +}); |
| 66 | + |
| 67 | +export { AccordionComponent as Accordion }; |
0 commit comments