Skip to content

Commit 559bbf0

Browse files
committed
feat(web): checkmark-animation
1 parent f931560 commit 559bbf0

File tree

1 file changed

+50
-14
lines changed

1 file changed

+50
-14
lines changed

src/lib/form/checkbox.tsx

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { InputHTMLAttributes } from "react";
2-
import styled, { css } from "styled-components";
2+
import styled, { css, keyframes } from "styled-components";
33
import CheckmarkIcon from "../../assets/svgs/form/checkmark.svg";
44
import { borderBox, svg } from "../../styles/common-style";
55

@@ -35,42 +35,76 @@ const HiddenInput = styled.input.attrs({ type: "checkbox" })`
3535
width: 0;
3636
`;
3737

38-
const StyledCheckmark = styled(CheckmarkIcon)<
39-
CheckboxBaseProps & { $small?: boolean }
40-
>`
41-
${svg}
38+
const CheckmarkContainer = styled.div<CheckboxBaseProps & { $small?: boolean }>`
4239
position: absolute;
4340
top: 0;
4441
left: 0;
4542
border-radius: 3px;
4643
border: 1px solid ${({ theme }) => theme.klerosUIComponentsStroke};
44+
overflow: hidden;
4745
${({ $small }) =>
4846
$small
4947
? css`
50-
padding: 0 3px;
5148
width: 16px;
5249
height: 16px;
5350
`
5451
: css`
55-
padding: 0 4px;
5652
width: 24px;
5753
height: 24px;
5854
`}
5955
56+
${({ theme, checked }) =>
57+
checked &&
58+
css`
59+
background: ${theme.klerosUIComponentsPrimaryBlue};
60+
border: none;
61+
:after {
62+
display: block;
63+
}
64+
`}
65+
`;
66+
67+
const bouncedIn = keyframes`
68+
0%{
69+
transform: translateY(100%);
70+
}
71+
50%{
72+
transform: translateY(-5px);
73+
}
74+
100%{
75+
transform: translateY(0);
76+
}
77+
`;
78+
79+
const StyledCheckmark = styled(CheckmarkIcon)<
80+
CheckboxBaseProps & { $small?: boolean }
81+
>`
82+
${svg}
83+
84+
position: absolute;
85+
top: 1px;
86+
width: 100%;
87+
height: 100%;
88+
6089
${({ theme, checked }) =>
6190
checked
6291
? css`
63-
fill: ${({ theme }) => theme.klerosUIComponentsWhiteBackground};
92+
fill: ${theme.klerosUIComponentsWhiteBackground};
6493
background: ${theme.klerosUIComponentsPrimaryBlue};
65-
border: none;
66-
67-
:after {
68-
display: block;
69-
}
94+
animation: ${bouncedIn} 200ms ease-out;
7095
`
7196
: css`
7297
fill: transparent;
7398
`}
99+
100+
${({ $small }) =>
101+
$small
102+
? css`
103+
padding: 0 3px;
104+
`
105+
: css`
106+
padding: 0 4px;
107+
`}
74108
`;
75109

76110
interface CheckboxProps
@@ -89,7 +123,9 @@ const Checkbox: React.FC<CheckboxProps> = ({
89123
<Wrapper {...{ small, className }}>
90124
{label}
91125
<HiddenInput checked={checked} {...props} />
92-
<StyledCheckmark $small={small} checked={checked} />
126+
<CheckmarkContainer $small={small} checked={checked}>
127+
<StyledCheckmark $small={small} checked={checked} />
128+
</CheckmarkContainer>
93129
</Wrapper>
94130
);
95131

0 commit comments

Comments
 (0)