|
1 | 1 | import React, { ReactElement, useCallback, useState } from "react";
|
2 | 2 | import { css } from "emotion";
|
| 3 | +import styled from "@emotion/styled"; |
3 | 4 | import classNames from "classnames";
|
4 | 5 | import { Typography } from "@webiny/ui/Typography";
|
5 | 6 |
|
@@ -69,23 +70,34 @@ const classes = {
|
69 | 70 | transform: "translateY(3px) rotate(90deg)"
|
70 | 71 | }
|
71 | 72 | }
|
72 |
| - }), |
73 |
| - accordionItem: css({ |
74 |
| - overflow: "hidden", |
75 |
| - transition: "max-height 0.3s cubic-bezier(1, 0, 1, 0)", |
76 |
| - height: "auto", |
77 |
| - maxHeight: "9999px", |
78 |
| - |
79 |
| - "&.collapsed": { |
80 |
| - maxHeight: 0, |
81 |
| - transition: "max-height 0.35s cubic-bezier(0, 1, 0, 1)" |
82 |
| - }, |
83 |
| - ".accordion-content": { |
84 |
| - paddingBottom: 10 |
85 |
| - } |
86 | 73 | })
|
87 | 74 | };
|
88 | 75 |
|
| 76 | +const AccordionItem = styled.div` |
| 77 | + @keyframes show-overflow { |
| 78 | + to { |
| 79 | + overflow: visible; |
| 80 | + } |
| 81 | + } |
| 82 | + overflow: hidden; |
| 83 | + transition: max-height 0.35s cubic-bezier(0, 1, 0, 1); |
| 84 | + height: auto; |
| 85 | + max-height: 0; |
| 86 | +
|
| 87 | + &.expanded { |
| 88 | + max-height: 9999px; |
| 89 | + transition: max-height 0.3s cubic-bezier(1, 0, 1, 0); |
| 90 | + animation-name: show-overflow; |
| 91 | + animation-fill-mode: forwards; |
| 92 | + animation-duration: 20ms; |
| 93 | + animation-delay: 0.3s; |
| 94 | + } |
| 95 | +`; |
| 96 | + |
| 97 | +const AccordionContent = styled.div` |
| 98 | + padding-bottom: 10; |
| 99 | +`; |
| 100 | + |
89 | 101 | interface AccordionProps {
|
90 | 102 | title: string;
|
91 | 103 | action?: ReactElement | null;
|
@@ -116,9 +128,9 @@ const Accordion = ({ title, children, action, icon, defaultValue = false }: Acco
|
116 | 128 | <div className={"icon-container"}>{icon}</div>
|
117 | 129 | </div>
|
118 | 130 | </div>
|
119 |
| - <div className={classNames(classes.accordionItem, { collapsed: !isOpen })}> |
120 |
| - <div className="accordion-content">{children}</div> |
121 |
| - </div> |
| 131 | + <AccordionItem className={classNames({ expanded: isOpen })}> |
| 132 | + <AccordionContent>{children}</AccordionContent> |
| 133 | + </AccordionItem> |
122 | 134 | </div>
|
123 | 135 | );
|
124 | 136 | };
|
|
0 commit comments