Skip to content

Commit

Permalink
♻️ refactor: 컴포넌트 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
myoungjinGo-FE committed Nov 20, 2024
1 parent 17fbaa9 commit b41a6c1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/components/global/ButtonGrid/ButtonGrid.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StoryObj, Meta } from "@storybook/react";
import { ButtonGrid, ButtonGridProps } from "./ButtonGrid";
import ButtonGrid, { ButtonGridProps } from "./ButtonGrid";

const meta: Meta<typeof ButtonGrid> = {
title: "Components/ButtonGrid",
Expand Down
25 changes: 25 additions & 0 deletions src/components/global/ButtonGrid/ButtonGrid.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import styled from "styled-components";

export const GridWrapper = styled.div`
display: grid;
grid-template-rows: repeat(auto-fit, minmax(40px, 1fr));
grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
gap: 8px;
margin: 0 auto;
width: fit-content;
`;

export const ButtonStyle = styled.button<{ selected: boolean }>`
font-size: 12px;
padding: 8px 16px;
border: 1px solid ${({ selected }) => (selected ? "#007bff" : "#ccc")};
background-color: ${({ selected }) => (selected ? "#e6f0ff" : "#fff")};
color: ${({ selected }) => (selected ? "#007bff" : "#000")};
border-radius: 4px;
cursor: pointer;
transition: all 0.3s;
&:hover {
background-color: ${({ selected }) => (selected ? "#cce4ff" : "#f5f5f5")};
}
`;
32 changes: 4 additions & 28 deletions src/components/global/ButtonGrid/ButtonGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from "react";
import styled from "styled-components";
import { useState } from "react";
import { GridWrapper, ButtonStyle } from "./ButtonGrid.styles";

export interface ButtonGridProps {
row: number;
Expand All @@ -9,31 +9,7 @@ export interface ButtonGridProps {
onSelect?: (indexes: number[]) => void; // 선택 이벤트
}

const GridWrapper = styled.div`
display: grid;
grid-template-rows: repeat(auto-fit, minmax(40px, 1fr));
grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
gap: 8px;
margin: 0 auto;
width: fit-content;
`;

const ButtonStyle = styled.button<{ selected: boolean }>`
font-size: 12px;
padding: 8px 16px;
border: 1px solid ${({ selected }) => (selected ? "#007bff" : "#ccc")};
background-color: ${({ selected }) => (selected ? "#e6f0ff" : "#fff")};
color: ${({ selected }) => (selected ? "#007bff" : "#000")};
border-radius: 4px;
cursor: pointer;
transition: all 0.3s;
&:hover {
background-color: ${({ selected }) => (selected ? "#cce4ff" : "#f5f5f5")};
}
`;

export function ButtonGrid({
export default function ButtonGrid({
row,
col,
buttonNames,
Expand Down Expand Up @@ -75,4 +51,4 @@ export function ButtonGrid({
))}
</GridWrapper>
);
}
}
1 change: 1 addition & 0 deletions src/components/global/ButtonGrid/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as ButtonGrid } from "./ButtonGrid";

0 comments on commit b41a6c1

Please sign in to comment.