Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 3700fb8

Browse files
committed
feat: add animation and update styles
1 parent de1e01f commit 3700fb8

File tree

2 files changed

+56
-17
lines changed

2 files changed

+56
-17
lines changed

src/components/Accordion/Accordion.minors.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
Content,
55
ChevronUp,
66
CircleWarningIcon,
7-
Header,
7+
HeaderContainer,
88
StyledChevronDown,
99
Subcopy,
1010
Title,
@@ -60,14 +60,18 @@ export function Item({
6060
aria-controls={`accordion-${index}-content`}
6161
id={`accordion-${index}-trigger`}
6262
>
63-
<Header>
63+
<HeaderContainer>
6464
{hasError && <CircleWarningIcon />}
6565
{!hasError && icon && icon}
6666
<TitleContainer>
67-
<Title>{title}</Title>
68-
{subcopy && <Subcopy>{subcopy}</Subcopy>}
67+
<Title size="4">{title}</Title>
68+
{subcopy && (
69+
<Subcopy size="6" variant="thin">
70+
{subcopy}
71+
</Subcopy>
72+
)}
6973
</TitleContainer>
70-
</Header>
74+
</HeaderContainer>
7175
{isActive ? (
7276
<ChevronUp width="24" />
7377
) : (

src/components/Accordion/Accordion.style.ts

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { rem } from 'polished';
2-
import styled, { css } from 'styled-components';
2+
import styled, { css, keyframes } from 'styled-components';
33

44
import { ChevronDown, CircleWarning } from '../../icons';
5-
import { Paragraph } from '../../typography';
5+
import { Header } from '../../typography';
66

77
import { grayscale } from '../../color';
88
import { core } from '../../tokens';
@@ -72,7 +72,7 @@ export const TriggerContainer = styled.button<{
7272
}
7373
`;
7474

75-
export const Header = styled.div`
75+
export const HeaderContainer = styled.div`
7676
display: flex;
7777
margin-right: ${rem(10)};
7878
`;
@@ -81,17 +81,14 @@ export const TitleContainer = styled.div`
8181
display: flex;
8282
flex-direction: column;
8383
text-align: left;
84+
gap: ${rem(4)};
8485
`;
8586

86-
export const Title = styled(Paragraph)`
87-
font-size: ${rem(16)};
88-
font-weight: 700;
89-
margin-bottom: 0;
87+
export const Title = styled(Header)`
88+
margin-bottom: ${rem(0)};
9089
`;
9190

92-
export const Subcopy = styled(Paragraph)`
93-
font-size: ${rem(14)};
94-
font-weight: 400;
91+
export const Subcopy = styled(Header)`
9592
margin-bottom: -${rem(0.2)};
9693
`;
9794

@@ -103,18 +100,56 @@ export const CircleWarningIcon = styled(CircleWarning)`
103100
}
104101
`;
105102

103+
const rotateUp = keyframes`
104+
from {
105+
transform: rotate(0deg);
106+
}
107+
to {
108+
transform: rotate(-180deg);
109+
}
110+
`;
111+
112+
const rotateDown = keyframes`
113+
from {
114+
transform: rotate(-180deg);
115+
}
116+
to {
117+
transform: rotate(0deg);
118+
}
119+
`;
120+
106121
export const StyledChevronDown = styled(ChevronDown)`
122+
animation: ${rotateDown} 120ms ease-in-out both;
107123
path {
108124
fill: ${core.color.text.primary};
109125
}
110126
`;
111127

112128
export const ChevronUp = styled(StyledChevronDown)`
113-
transform: rotate(180deg);
129+
animation: ${rotateUp} 120ms ease-in-out both;
130+
`;
131+
132+
const fadeAndExpand = keyframes`
133+
from {
134+
transform: translateY(-50%);
135+
opacity: 0;
136+
}
137+
to {
138+
transform: translateY(0);
139+
opacity: 1;
140+
}
114141
`;
115142

116143
export const Content = styled.div<{ active: boolean }>`
117-
padding: ${rem(0)} ${rem(15)} ${rem(20)};
144+
padding: ${rem(0)} ${rem(15)} ${rem(20)} ${rem(20)};
118145
max-height: ${({ active }) => (active ? '100%' : '0')};
119146
overflow: hidden;
147+
transform: translateY(-50%);
148+
opacity: 0;
149+
${({ active }) =>
150+
active &&
151+
css`
152+
animation: ${fadeAndExpand} 150ms ease-in-out both;
153+
opacity: 1;
154+
`};
120155
`;

0 commit comments

Comments
 (0)