index.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React from "react";
  2. import styled, { DefaultTheme } from "styled-components";
  3. enum ButtonType {
  4. PRIMARY = "PRIMARY",
  5. SECONDARY = "BLURPLE",
  6. DANGER = "DANGER",
  7. SUCCESS = "SEAGREEN",
  8. WARNING = "ORANGE",
  9. }
  10. export interface ButtonProps
  11. extends React.ButtonHTMLAttributes<HTMLButtonElement> {
  12. status?: keyof typeof ButtonType;
  13. }
  14. function getButtonStatus(status: keyof typeof ButtonType, theme: DefaultTheme) {
  15. return theme[ButtonType[status]];
  16. }
  17. const StyledButton = styled.button<{ status: keyof typeof ButtonType }>`
  18. display: block;
  19. background: ${({ status, theme }) => getButtonStatus(status, theme)};
  20. color: #ffffff;
  21. padding: 8px 16px;
  22. min-width: 60px;
  23. :disabled {
  24. cursor: not-allowed;
  25. opacity: 0.5;
  26. }
  27. @media only screen and (max-width: 768px) {
  28. font-size: 18px;
  29. }
  30. `;
  31. const StyledButtonContent = styled.div`
  32. display: flex;
  33. justify-content: center;
  34. align-items: center;
  35. gap: 8px;
  36. `;
  37. export const Button: React.FC<ButtonProps> = ({
  38. children,
  39. status,
  40. ...props
  41. }) => {
  42. return (
  43. <StyledButton type="button" status={status ?? "PRIMARY"} {...props}>
  44. <StyledButtonContent>{children}</StyledButtonContent>
  45. </StyledButton>
  46. );
  47. };