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

컨벤션 반영 #41

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
8 changes: 3 additions & 5 deletions src/app/test/Staging.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { useEffect } from "react";

import Button from "@/component/Button/Button.tsx";
import { ButtonProvider } from "@/component/Button/ButtonProvider.tsx";
import CheckBox from "@/component/common/CheckBox/CheckBox";
import CheckBoxGroup from "@/component/common/CheckBox/CheckBoxGroup";
import { Input, InputLabelContainer, Label } from "@/component/common/Input";
import Radio from "@/component/common/RadioButton/Radio";
import RadioButtonGroup from "@/component/common/RadioButton/RadioButtonGroup";
import { CheckBox, CheckBoxGroup } from "@/component/common/checkBox";
import { Input, InputLabelContainer, Label } from "@/component/common/input";
import { Radio, RadioButtonGroup } from "@/component/common/radioButton";
import { useCheckBox } from "@/hooks/useCheckBox";
import { useInput } from "@/hooks/useInput";
import { useRadioButton } from "@/hooks/useRadioButton";
Expand Down
6 changes: 2 additions & 4 deletions src/component/common/CheckBox/CheckBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type CheckBoxProps = {
children: React.ReactNode;
};

const CheckBox = ({ value, children }: CheckBoxProps) => {
export function CheckBox({ value, children }: CheckBoxProps) {
const checkboxContext = useContext(CheckBoxContext);
return (
<ListItemCard variant={checkboxContext?.isChecked(value) ? "theme" : "default"}>
Expand Down Expand Up @@ -41,6 +41,4 @@ const CheckBox = ({ value, children }: CheckBoxProps) => {
/>
</ListItemCard>
);
};

export default CheckBox;
}
8 changes: 3 additions & 5 deletions src/component/common/CheckBox/CheckBoxGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export type CheckBoxContextState = {

export const CheckBoxContext = createContext<CheckBoxContextState | undefined>(undefined);

type CheckBoxGroupProps = {
type CheckBoxProps = {
children: React.ReactNode;
} & CheckBoxContextState;

const CheckBoxGroup = ({ children, ...props }: CheckBoxGroupProps) => {
export function CheckBoxGroup({ children, ...props }: CheckBoxProps) {
return (
<div
css={css`
Expand All @@ -24,6 +24,4 @@ const CheckBoxGroup = ({ children, ...props }: CheckBoxGroupProps) => {
<CheckBoxContext.Provider value={props}>{children}</CheckBoxContext.Provider>
</div>
);
};

export default CheckBoxGroup;
}
2 changes: 2 additions & 0 deletions src/component/common/CheckBox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { CheckBox } from "./CheckBox";
export { CheckBoxGroup } from "./CheckBoxGroup";
6 changes: 2 additions & 4 deletions src/component/common/RadioButton/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type RadioProps = {
children: React.ReactNode;
};

const Radio = ({ value, children }: RadioProps) => {
export function Radio({ value, children }: RadioProps) {
const radioContext = useContext(RadioContext);
return (
<ListItemCard variant={radioContext?.isChecked(value) ? "theme" : "default"}>
Expand Down Expand Up @@ -42,6 +42,4 @@ const Radio = ({ value, children }: RadioProps) => {
/>
</ListItemCard>
);
};

export default Radio;
}
6 changes: 2 additions & 4 deletions src/component/common/RadioButton/RadioButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type RadioButtonGroupProps = {
children: React.ReactNode;
} & RadioContextState;

const RadioButtonGroup = ({ children, ...props }: RadioButtonGroupProps) => {
export function RadioButtonGroup({ children, ...props }: RadioButtonGroupProps) {
return (
<div
css={css`
Expand All @@ -25,6 +25,4 @@ const RadioButtonGroup = ({ children, ...props }: RadioButtonGroupProps) => {
<RadioContext.Provider value={props}>{children}</RadioContext.Provider>
</div>
);
};

export default RadioButtonGroup;
}
2 changes: 2 additions & 0 deletions src/component/common/RadioButton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Radio } from "./Radio";
export { RadioButtonGroup } from "./RadioButtonGroup";
44 changes: 44 additions & 0 deletions src/component/common/checkBox/CheckBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { css } from "@emotion/react";
import { useContext } from "react";

import { CheckBoxContext } from "./CheckBoxGroup";

import ListItemCard from "@/component/common/Card/ListItemCard";

type CheckBoxProps = {
value: string;
children: React.ReactNode;
};

export function CheckBox({ value, children }: CheckBoxProps) {
const checkboxContext = useContext(CheckBoxContext);
return (
<ListItemCard variant={checkboxContext?.isChecked(value) ? "theme" : "default"}>
<label
htmlFor={value}
css={css`
font-weight: 600;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
cursor: pointer;
`}
>
{children}
</label>
<input
type="checkbox"
id={value}
value={value}
onChange={(e) => {
checkboxContext?.onChange && checkboxContext.onChange(e.target.value);
}}
css={css`
display: none;
`}
/>
</ListItemCard>
);
}
27 changes: 27 additions & 0 deletions src/component/common/checkBox/CheckBoxGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { css } from "@emotion/react";
import { createContext } from "react";

export type CheckBoxContextState = {
isChecked: (value: string) => boolean;
onChange: (value: string) => void;
};

export const CheckBoxContext = createContext<CheckBoxContextState | undefined>(undefined);

type CheckBoxProps = {
children: React.ReactNode;
} & CheckBoxContextState;

export function CheckBoxGroup({ children, ...props }: CheckBoxProps) {
return (
<div
css={css`
display: flex;
flex-direction: column;
gap: 1rem;
`}
>
<CheckBoxContext.Provider value={props}>{children}</CheckBoxContext.Provider>
</div>
);
}
2 changes: 2 additions & 0 deletions src/component/common/checkBox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { CheckBox } from "./CheckBox";
export { CheckBoxGroup } from "./CheckBoxGroup";
34 changes: 34 additions & 0 deletions src/component/common/input/Input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { css } from "@emotion/react";
import { forwardRef, useContext } from "react";

import { InputContext } from "./InputLabelContainer";

type InputProps = {
width?: string;
} & React.InputHTMLAttributes<HTMLInputElement>;

export const Input = forwardRef(function ({ id, width = "100%", ...props }: InputProps) {
const inputContext = useContext(InputContext);
return (
<div>
<div
css={css`
width: ${width};
border: 1px solid #e3e6ea; // FIXME: 디자인 토큰 적용하기
border-radius: 0.8rem;
padding: 1.6rem;
`}
>
<input
id={id || inputContext?.id}
css={css`
width: 100%;
`}
{...props}
/>
</div>
</div>
);
});

Input.displayName = "Input";
27 changes: 27 additions & 0 deletions src/component/common/input/InputLabelContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { css } from "@emotion/react";
import { createContext } from "react";

type InputLabelContainerProps = {
id: string;
children: React.ReactNode;
};

export const InputContext = createContext<{ id: string } | undefined>(undefined);

export function InputLabelContainer({ id, children }: InputLabelContainerProps) {
return (
<InputContext.Provider value={{ id }}>
<div
css={[
css`
display: flex;
flex-direction: column;
gap: 2rem;
`,
]}
>
{children}
</div>
</InputContext.Provider>
);
}
63 changes: 63 additions & 0 deletions src/component/common/input/Label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { css, Interpolation, Theme } from "@emotion/react";
import { useContext } from "react";

import { InputContext } from "./InputLabelContainer";

type LabelProps = {
order?: number;
styles?: Interpolation<Theme>;
} & React.LabelHTMLAttributes<HTMLLabelElement>;

export function Label({ id, children, order, styles }: LabelProps) {
const inputContext = useContext(InputContext);

return (
<label
htmlFor={id || inputContext?.id}
css={
order
? css`
display: flex;
align-items: center;
gap: 0.8rem;
`
: null
}
>
{order && (
<div
css={[
css`
background-color: #212529; // FIXME: 디자인 토큰 적용하기
width: 2rem;
height: 2rem;
border-radius: 0.4rem;
vertical-align: middle;
text-align: center;
`,
styles,
]}
>
{/* FIXME text 컴포넌트 적용하기 */}
<span
css={css`
color: #fff;
font-size: 1rem;
font-weight: 600;
`}
>
{order}
</span>
</div>
)}
<span
css={css`
font-size: 1.4rem;
font-weight: 600;
`}
>
{children}
</span>
</label>
);
}
3 changes: 3 additions & 0 deletions src/component/common/input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { Input } from "./Input";
export { Label } from "./Label";
export { InputLabelContainer } from "./InputLabelContainer";
45 changes: 45 additions & 0 deletions src/component/common/radioButton/Radio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { css } from "@emotion/react";
import { useContext } from "react";

import { RadioContext } from "./RadioButtonGroup";

import ListItemCard from "@/component/common/Card/ListItemCard";

type RadioProps = {
value: string;
children: React.ReactNode;
};

export function Radio({ value, children }: RadioProps) {
const radioContext = useContext(RadioContext);
return (
<ListItemCard variant={radioContext?.isChecked(value) ? "theme" : "default"}>
<label
htmlFor={value}
css={css`
font-weight: 600;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
cursor: pointer;
`}
>
{children}
</label>
<input
type="radio"
name={radioContext?.radioName}
id={value}
value={value}
onChange={(e) => {
radioContext?.onChange && radioContext.onChange(e.target.value);
}}
css={css`
display: none;
`}
/>
</ListItemCard>
);
}
28 changes: 28 additions & 0 deletions src/component/common/radioButton/RadioButtonGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { css } from "@emotion/react";
import { createContext } from "react";

export type RadioContextState = {
radioName: string;
isChecked: (value: string) => boolean;
onChange: (value: string) => void;
};

export const RadioContext = createContext<RadioContextState | undefined>(undefined);

type RadioButtonGroupProps = {
children: React.ReactNode;
} & RadioContextState;

export function RadioButtonGroup({ children, ...props }: RadioButtonGroupProps) {
return (
<div
css={css`
display: flex;
flex-direction: column;
gap: 1rem;
`}
>
<RadioContext.Provider value={props}>{children}</RadioContext.Provider>
</div>
);
}
2 changes: 2 additions & 0 deletions src/component/common/radioButton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Radio } from "./Radio";
export { RadioButtonGroup } from "./RadioButtonGroup";
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"forceConsistentCasingInFileNames": true,
Copy link
Member

Choose a reason for hiding this comment

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

엇 이거 넣으면 파일 명에 변화가 생기는건가?!

Copy link
Member Author

Choose a reason for hiding this comment

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

아 요게 계속 폴더 대소문자를 구분 못해서 넣어봤는데 파일명 한정어서인지 해도 안되네
근데 이게 내 깃이 대소문자를 구분 못하고 있어서 그랬던 거 같아서 깃 설정하고 새로 브랜치 파서 다시 pr 올릴게!


/* Linting */
"strict": true,
Expand Down
Loading