icns-frontend/components/primary-button/index.tsx

113 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-12-18 08:59:29 +00:00
import { ButtonHTMLAttributes, FunctionComponent } from "react";
2022-12-18 09:38:56 +00:00
import styled, { keyframes } from "styled-components";
2022-12-06 10:41:38 +00:00
import color from "../../styles/color";
2022-12-18 09:38:56 +00:00
interface PrimaryButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
isLoading?: boolean;
}
export const PrimaryButton: FunctionComponent<PrimaryButtonProps> = ({
children,
isLoading,
disabled,
2022-12-18 09:38:56 +00:00
...props
}) => {
2022-12-18 08:59:29 +00:00
return (
<StyledPrimaryButton {...props} disabled={disabled || isLoading}>
2022-12-18 09:38:56 +00:00
{isLoading ? (
<SpinnerWrapper>
<Spinner />
<Spinner />
<Spinner />
<Spinner />
</SpinnerWrapper>
) : (
<span>{children}</span>
)}
2022-12-18 08:59:29 +00:00
</StyledPrimaryButton>
);
};
const StyledPrimaryButton = styled.button`
2022-12-18 09:38:56 +00:00
display: flex;
align-items center;
justify-content: center;
2022-12-06 10:41:38 +00:00
width: 100%;
height: 100%;
border: none;
padding: 11px 30px;
font-family: "Inter", serif;
font-style: normal;
font-weight: 600;
2022-12-16 06:55:31 +00:00
font-size: 1.25rem;
line-height: 1.25rem;
letter-spacing: 0.07em;
text-transform: uppercase;
2022-12-06 10:41:38 +00:00
2022-12-15 15:43:18 +00:00
background-color: ${color.orange["100"]};
cursor: pointer;
2022-12-09 11:59:52 +00:00
&:hover {
transition-duration: 0.5s;
background-color: ${color.orange["200"]};
2022-12-18 08:59:29 +00:00
span {
opacity: 0.5;
}
2022-12-09 11:59:52 +00:00
}
&:disabled {
2022-12-15 15:43:18 +00:00
background-color: ${color.orange["300"]};
cursor: not-allowed;
2022-12-18 08:59:29 +00:00
span {
opacity: 0.5;
}
}
span {
transition-duration: 0.5s;
color: ${color.orange["50"]};
2022-12-09 11:59:52 +00:00
}
2022-12-06 10:41:38 +00:00
`;
2022-12-18 09:38:56 +00:00
const SpinnerWrapper = styled.div`
display: flex;
position: relative;
width: 20px;
height: 20px;
`;
const spinAnimation = keyframes`
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
`;
const Spinner = styled.div<{ animationDelay?: string }>`
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
animation: ${spinAnimation} 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
${({ animationDelay }) =>
animationDelay ? `animation-delay: ${animationDelay};` : ""}
border-radius: 100%;
border-style: solid;
border-width: 3px;
border-color: white transparent transparent transparent;
`;