index.tsx 1007 B

123456789101112131415161718192021222324252627282930313233343536
  1. import React from "react";
  2. import styled, { DefaultTheme } from "styled-components";
  3. enum ButtonType {
  4. DEFAULT = "BLURPLE",
  5. DANGER = "DANGER",
  6. SUCCESS = "SEAGREEN",
  7. WARNING = "ORANGE",
  8. }
  9. export interface ButtonProps
  10. extends React.ButtonHTMLAttributes<HTMLButtonElement> {
  11. status?: keyof typeof ButtonType;
  12. }
  13. function getButtonStatus(status: keyof typeof ButtonType, theme: DefaultTheme) {
  14. return theme[ButtonType[status]];
  15. }
  16. const StyledButton = styled.button<{ status: keyof typeof ButtonType }>`
  17. background: ${({ status, theme }) => getButtonStatus(status, theme)};
  18. color: ${({ theme }) => theme.FULL_WHITE};
  19. cursor: pointer;
  20. `;
  21. const StyledButtonContent = styled.div``;
  22. const Button: React.FC<ButtonProps> = ({ children, status, ...props }) => {
  23. return (
  24. <StyledButton type="button" status={status ?? "DEFAULT"} {...props}>
  25. <StyledButtonContent>{children}</StyledButtonContent>
  26. </StyledButton>
  27. );
  28. };
  29. export default Button;