Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/#53] Stepper 공통 컴포넌트 추가 #56

Merged
merged 5 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions public/svgs/icon_minus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/svgs/icon_plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/assets/svgs/IconMinus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { SVGProps } from "react";
const SvgIconMinus = (props: SVGProps<SVGSVGElement>) => (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" {...props}>
<path stroke="currentColor" strokeMiterlimit={10} strokeWidth={1.2} d="M17 12H7" />
</svg>
);
export default SvgIconMinus;
8 changes: 8 additions & 0 deletions src/assets/svgs/IconPlus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as React from "react";
import type { SVGProps } from "react";
const SvgIconPlus = (props: SVGProps<SVGSVGElement>) => (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" {...props}>
<path stroke="currentColor" strokeMiterlimit={10} strokeWidth={1.2} d="M12 7v10M17 12H7" />
</svg>
);
export default SvgIconPlus;
2 changes: 2 additions & 0 deletions src/assets/svgs/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { default as IconMinus } from "./IconMinus";
export { default as IconPlus } from "./IconPlus";
export { default as IconTextfiedlDelete } from "./IconTextfiedlDelete";
25 changes: 25 additions & 0 deletions src/components/commons/stepper/Stepper.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Meta, StoryFn, StoryObj } from "@storybook/react";
import Stepper, { StepperProps } from "./Stepper";
import { useState } from "react";

const meta = {
title: "Stepper",
component: Stepper,
parameters: {
layout: "centered",
},
argTypes: {},
args: { max: 3, round: 1 },
} satisfies Meta<typeof Stepper>;

export default meta;
type Story = StoryObj<StepperProps>;

const Template: StoryFn<StepperProps> = (args) => {
const [round, setRound] = useState(args.round);

return <Stepper {...args} round={round} setRound={setRound} />;
};

export const Default: Story = Template.bind({});
Default.args = {};
41 changes: 41 additions & 0 deletions src/components/commons/stepper/Stepper.styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Generators } from "@styles/generator";
import styled from "styled-components";

export const StepperWrapper = styled.div`
${Generators.flexGenerator()};
gap: 0.6rem;
width: 11.5rem;
height: 4rem;
padding: 0.8rem 1rem;

background: ${({ theme }) => theme.colors.gray_900};
border: 1px solid ${({ theme }) => theme.colors.gray_700};
border-radius: 6px;
`;

export const StepperBtn = styled.button`
${Generators.flexGenerator()};
width: 2.4rem;
height: 2.4rem;

color: ${({ theme }) => theme.colors.white};

cursor: pointer;

&:disabled {
color: ${({ theme }) => theme.colors.gray_500};

cursor: not-allowed;
}
`;

export const StepperNum = styled.p`
${Generators.flexGenerator()};

width: 3.5rem;
height: 1.3rem;

color: ${({ theme }) => theme.colors.white};

${({ theme }) => theme.fonts.heading4}
`;
34 changes: 34 additions & 0 deletions src/components/commons/stepper/Stepper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as S from "./Stepper.styled";
import { IconMinus, IconPlus } from "@assets/svgs";

export interface StepperProps {
max: number;
round: number;
setRound: (round: number) => void;
}

const Stepper = ({ round, max, setRound }: StepperProps) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3) setState 자체를 props로 넘기면 안된다? 와 관련해서 화랑이가 적은 아티클이 있어서 링크 남겨놓겠습니다!
props로 onMinusClick, onPlusClick 이렇게 넘기는 방식은 어떨까요!?

https://velog.io/@thisishwarang/React-setState-%EC%9E%90%EC%B2%B4%EB%A5%BC-props%EB%A1%9C-%EC%A0%84%EB%8B%AC%ED%95%98%EC%A7%80-%EB%A7%90%EC%95%84%EC%95%BC-%ED%95%98%EB%8A%94-%EC%9D%B4%EC%9C%A0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵!! onMinusClick, onPlusClick으로 prop 넘기는 방향으로 수정했습니다!!

return (
<S.StepperWrapper>
<S.StepperBtn
disabled={round === 1}
onClick={() => {
setRound(round - 1);
}}
>
<IconMinus />
</S.StepperBtn>
<S.StepperNum>{round}</S.StepperNum>
<S.StepperBtn
disabled={max === round}
onClick={() => {
setRound(round + 1);
}}
>
<IconPlus />
</S.StepperBtn>
</S.StepperWrapper>
);
};

export default Stepper;
3 changes: 3 additions & 0 deletions src/pages/test/TestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { IconTextfiedlDelete } from "@assets/svgs";
import Chip from "@components/commons/chip/Chip";
import TextArea from "@components/commons/input/textArea/TextArea";
import TextField from "@components/commons/input/textField/TextField";
import Stepper from "@components/commons/stepper/Stepper";
import { useState } from "react";

const TestPage = () => {
const [inputValue, setInputValue] = useState("");
const [inputAreaValue, setInputAreaValue] = useState("");
const [round, setRound] = useState(1);

const handleChangeInput = (value: string) => {
setInputValue(value);
Expand Down Expand Up @@ -39,6 +41,7 @@ const TestPage = () => {
/>
<Chip label="테스트" />
</div>
<Stepper max={3} round={round} setRound={setRound} />
</div>
);
};
Expand Down
Loading