Skip to content

Commit

Permalink
Improve Accordion Animations (#23)
Browse files Browse the repository at this point in the history
* Improve Accordion Animations

* Fix Initial Content Opacity
  • Loading branch information
timoclsn authored Sep 2, 2023
1 parent 5256f8e commit 04df185
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
28 changes: 14 additions & 14 deletions apps/website/src/components/Accordion/Accordion.module.css
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
.AccordionContent[data-state="open"] {
animation: slideDown 300ms linear;
opacity: 1;
}
.AccordionContent[data-state="closed"] {
animation: slideUp 300ms linear;
opacity: 0;
}

@media (min-width: 1024px) {
.AccordionContent[data-state="open"] {
animation: openHorizontal 600ms linear;
opacity: 1;
animation:
openHorizontal 300ms linear,
fadeIn 600ms linear;
}
.AccordionContent[data-state="closed"] {
animation: closeHorizontal 300ms linear;
opacity: 0;
animation: closeHorizontal 300ms linear;
}
}

@keyframes openHorizontal {
@keyframes fadeIn {
0% {
width: 0;
opacity: 0;
}
50% {
width: var(--radix-accordion-content-width);
}
75% {
opacity: 0;
}
100% {
opacity: 1;
}
}

@keyframes openHorizontal {
from {
width: 0;
}
to {
width: var(--radix-accordion-content-width);
}
}

@keyframes closeHorizontal {
0% {
width: var(--radix-accordion-content-width);
Expand All @@ -46,21 +50,17 @@
@keyframes slideDown {
from {
height: 0;
opacity: 0;
}
to {
height: var(--radix-accordion-content-height);
opacity: 1;
}
}

@keyframes slideUp {
from {
height: var(--radix-accordion-content-height);
opacity: 1;
}
to {
height: 0;
opacity: 0;
}
}
10 changes: 5 additions & 5 deletions apps/website/src/components/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const itemVariants = cva(
...backgroundColorsMap,
},
},
}
},
);

const triggerVariants = cva(
Expand All @@ -40,10 +40,10 @@ const triggerVariants = cva(
large: "data-[state=open]:hidden",
},
},
}
},
);

const contentVariants = cva("overflow-hidden p-6 sm:p-10", {
const contentVariants = cva("overflow-hidden", {
variants: {
size: {
medium: "lg:pl-0",
Expand Down Expand Up @@ -101,10 +101,10 @@ export const Accordion = ({
className={cx(
"w-full",
styles.AccordionContent,
contentVariants({ size })
contentVariants({ size }),
)}
>
<div className="flex h-full flex-col items-start overflow-auto">
<div className="flex h-full flex-col items-start overflow-auto p-6 sm:p-10">
{size === "large" && (
<>
<div className="flex w-full justify-center">
Expand Down

2 comments on commit 04df185

@vercel
Copy link

@vercel vercel bot commented on 04df185 Sep 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 04df185 Sep 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.