react-challengers / Codefolio

부트캠프 수강생들이 작업한 프로젝트를 체계적으로 정리하여 채용과 연계할 수 있는 포트폴리오 공유 서비스
https://code-folio.vercel.app/
1 stars 2 forks source link

프라이머리 버튼 컬러 변경 #371

Closed yunjunhojj closed 1 year ago

arch-spatula commented 1 year ago
import { MouseEventHandler } from "react";
import styled from "styled-components";

type PrimaryButtonType = "default" | "line";
type PrimaryButtonSize = "s" | "m";

interface PrimaryButtonProps {
  text: string;
  buttonType: PrimaryButtonType;
  size: PrimaryButtonSize;
  onClick: MouseEventHandler<HTMLButtonElement>;
  disabled?: boolean;
}

const PrimaryButton = ({
  text,
  buttonType,
  size,
  onClick,
  disabled = false,
}: PrimaryButtonProps) => {
  return (
    <PrimaryButtonContainer
      buttonType={buttonType}
      size={size}
      onClick={onClick}
      disabled={disabled}
    >
      {text}
    </PrimaryButtonContainer>
  );
};

const PrimaryButtonContainer = styled.button<{
  buttonType: PrimaryButtonType;
  size: PrimaryButtonSize;
  onClick: MouseEventHandler<HTMLButtonElement>;
}>`
  all: unset;
  cursor: pointer;
  border-radius: 0.25rem;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  /* default & line */
  ${({ theme, buttonType, size }) => {
    if (buttonType === "default" && size === "m")
      return theme.fonts.subtitle18Bold;
    if (buttonType === "default" && size === "s")
      return theme.fonts.body14Medium;
    if (buttonType === "line" && size === "m") return theme.fonts.subtitle18;
    if (buttonType === "default" && size === "s") return theme.fonts.body14;
    return "";
  }}
  color: ${({ buttonType, theme }) =>
    buttonType === "default" ? theme.colors.gray11 : theme.colors.primary6};
  background-color: ${({ buttonType, theme }) =>
    buttonType === "default" ? theme.colors.primary4 : `none`};
  border: 1px solid
    ${({ theme, buttonType }) =>
      buttonType === "default" ? `none` : theme.colors.primary6};

  :hover {
    background-color: ${({ buttonType, theme }) =>
      buttonType === "default" ? theme.colors.primary6 : theme.colors.gray8};
  }

  :disabled {
    ${(props) => props.theme.fonts.subtitle18}
    color: ${({ buttonType, theme }) =>
      buttonType === "default" ? theme.colors.gray3 : theme.colors.gray4};
    background-color: ${({ theme, buttonType }) =>
      buttonType === "default" ? theme.colors.gray7 : theme.colors.primary2};
  }

  /* "s" | "m": */
  width: ${({ size }) => (size === "m" ? `7.75rem` : `5rem`)};
  height: ${({ size }) => (size === "m" ? "3.375rem" : "2.5rem")};
`;

export default PrimaryButton;
arch-spatula commented 1 year ago

스크린샷 2023-03-09 오전 10 15 18

스크린샷 2023-03-09 오전 10 15 40