ui icon indicating copy to clipboard operation
ui copied to clipboard

Can you add animation to the Collapsible component like you to do the accordion component?

Open 684efs3 opened this issue 2 years ago • 2 comments

Can you add animation to the Collapsible component like you to do the accordion component? Thank you!

684efs3 avatar Dec 05 '23 16:12 684efs3

@684efs3

Update the files with the changes to have a animated collapsible like accordion

Api reference: https://www.radix-ui.com/primitives/docs/components/collapsible#animating-content-size

tailwind.config.ts

keyframes: {
	'collapsible-down': {
		from: { height: '0' },
		to: { height: 'var(--radix-collapsible-content-height)' },
	},
	'collapsible-up': {
		from: { height: 'var(--radix-collapsible-content-height)' },
		to: { height: '0' },
	},
},
animation: {
	'collapsible-down': 'collapsible-down 0.2s ease-out',
	'collapsible-up': 'collapsible-up 0.2s ease-out',
},

collapsible.tsx - Inside the dir components/ui/collapsible.tsx

'use client';

import { cn } from '@/lib/utils';
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';
import * as React from 'react';

const Collapsible = CollapsiblePrimitive.Root;

const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger;

const CollapsibleContent = React.forwardRef<
	React.ElementRef<typeof CollapsiblePrimitive.CollapsibleContent>,
	React.ComponentPropsWithoutRef<typeof CollapsiblePrimitive.CollapsibleContent>
>(({ className, ...props }, ref) => (
	<CollapsiblePrimitive.CollapsibleContent
		ref={ref}
		className={cn('overflow-hidden data-[state=open]:animate-collapsible-down data-[state=closed]:animate-collapsible-up', className)}
		{...props}
	/>
));

export { Collapsible, CollapsibleContent, CollapsibleTrigger };

imopbuilder avatar Jan 21 '24 07:01 imopbuilder

@shadcn

You can close this issue 🌟

imopbuilder avatar Jan 21 '24 07:01 imopbuilder

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Feb 12 '24 23:02 shadcn