index.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. width: fit-content;
  24. :disabled {
  25. cursor: not-allowed;
  26. opacity: 0.5;
  27. }
  28. @media only screen and (max-width: 768px) {
  29. font-size: 18px;
  30. }
  31. `;
  32. const StyledButtonContent = styled.div`
  33. display: flex;
  34. justify-content: center;
  35. align-items: center;
  36. gap: 8px;
  37. `;
  38. export const Button: React.FC<ButtonProps> = ({
  39. children,
  40. status,
  41. ...props
  42. }) => {
  43. return (
  44. <StyledButton type="button" status={status ?? "PRIMARY"} {...props}>
  45. <StyledButtonContent>{children}</StyledButtonContent>
  46. </StyledButton>
  47. );
  48. };