tasko/components/ui/accordion.tsx

59 lines
2 KiB
TypeScript
Raw Permalink Normal View History

2024-02-16 01:49:19 +00:00
'use client';
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
import * as React from 'react';
import * as AccordionPrimitive from '@radix-ui/react-accordion';
import { ChevronDown } from 'lucide-react';
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
import { cn } from '@/lib/utils';
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
const Accordion = AccordionPrimitive.Root;
2024-02-15 02:30:10 +00:00
const AccordionItem = React.forwardRef<
2024-11-01 01:58:40 +00:00
React.ComponentRef<typeof AccordionPrimitive.Item>,
2024-02-15 02:30:10 +00:00
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
>(({ className, ...props }, ref) => (
<AccordionPrimitive.Item
ref={ref}
2024-02-16 01:49:19 +00:00
className={cn('border-b', className)}
2024-02-15 02:30:10 +00:00
{...props}
/>
2024-02-16 01:49:19 +00:00
));
AccordionItem.displayName = 'AccordionItem';
2024-02-15 02:30:10 +00:00
const AccordionTrigger = React.forwardRef<
2024-11-01 01:58:40 +00:00
React.ComponentRef<typeof AccordionPrimitive.Trigger>,
2024-02-15 02:30:10 +00:00
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
2024-02-16 01:49:19 +00:00
<AccordionPrimitive.Header className='flex'>
2024-02-15 02:30:10 +00:00
<AccordionPrimitive.Trigger
ref={ref}
className={cn(
2024-02-16 01:49:19 +00:00
'flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180',
2024-02-15 02:30:10 +00:00
className
)}
{...props}
>
{children}
2024-02-16 01:49:19 +00:00
<ChevronDown className='h-4 w-4 shrink-0 transition-transform duration-200' />
2024-02-15 02:30:10 +00:00
</AccordionPrimitive.Trigger>
</AccordionPrimitive.Header>
2024-02-16 01:49:19 +00:00
));
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName;
2024-02-15 02:30:10 +00:00
const AccordionContent = React.forwardRef<
2024-11-01 01:58:40 +00:00
React.ComponentRef<typeof AccordionPrimitive.Content>,
2024-02-15 02:30:10 +00:00
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<AccordionPrimitive.Content
ref={ref}
2024-02-16 01:49:19 +00:00
className='overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down'
2024-02-15 02:30:10 +00:00
{...props}
>
2024-02-16 01:49:19 +00:00
<div className={cn('pb-4 pt-0', className)}>{children}</div>
2024-02-15 02:30:10 +00:00
</AccordionPrimitive.Content>
2024-02-16 01:49:19 +00:00
));
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
AccordionContent.displayName = AccordionPrimitive.Content.displayName;
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };