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

중복선택 버튼 컴포넌트 (체크박스) 작성 #27

Merged
merged 10 commits into from
Jul 14, 2024

Conversation

leeminhee119
Copy link
Member

중복선택 버튼 컴포넌트 (체크박스) 작성


🏄🏼‍♂️‍ Summary (요약)

  • 중복 선택이 가능한 버튼그룹 (체크박스) 컴포넌트 개발
  • 중복 선택이 불가한 버튼그룹 (라디오버튼) 컴포넌트 리팩토링 (체크박스와 사용방식 통일)

🫨 Describe your Change (변경사항)

  • useRadioButton, useCheckBox 훅 작성
    • 각각 selectedValue, setSelectedValues (튜플의 세 번째 값) 값이 선택된 value 정보를 담고 있습니다.
  • 라디오버튼은 input의 name 속성에 들어가는 radioName props를 추가로 전달해야 한다는 점 외에는 라디오버튼, 체크박스 사용 방법이 같습니다.

🧐 Issue number and link (참고)

📚 Reference (참조)

  • Staging.tsx사용 예시를 참고해주세요!

@leeminhee119 leeminhee119 added 🚀 feature New feature or request 🧹 refactor 사용자에게는 드러나지 않는 코드 상의 변화 labels Jul 10, 2024
@leeminhee119 leeminhee119 self-assigned this Jul 10, 2024
@leeminhee119 leeminhee119 added this to the v1.0.0 milestone Jul 10, 2024
@leeminhee119 leeminhee119 mentioned this pull request Jul 10, 2024
14 tasks
@leeminhee119 leeminhee119 marked this pull request as draft July 10, 2024 14:43
@leeminhee119 leeminhee119 marked this pull request as ready for review July 10, 2024 15:14
Copy link
Collaborator

@sean2337 sean2337 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!!

Comment on lines +34 to +48
<RadioButtonGroup isChecked={isRadioChecked} onChange={onChange} radioName={"프로젝트 주기"}>
<Radio value={"0"}>주 1회</Radio>
<Radio value={"1"}>월 1회</Radio>
<Radio value={"2"}>분기별</Radio>
<Radio value={"3"}>프로젝트 끝난 후</Radio>
</RadioButtonGroup>

<br />
<h3>체크박스</h3>
<CheckBoxGroup isChecked={isCheckBoxChecked} onChange={toggle}>
<CheckBox value={"00"}>주 1회</CheckBox>
<CheckBox value={"10"}>월 1회</CheckBox>
<CheckBox value={"20"}>분기별</CheckBox>
<CheckBox value={"30"}>프로젝트 끝난 후</CheckBox>
</CheckBoxGroup>
Copy link
Collaborator

Choose a reason for hiding this comment

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

사용방법이 직관적이어서 좋네요!!

return (
<ListItemCard variant={checkboxContext?.isChecked(value) ? "theme" : "default"}>
<label
htmlFor={value}
Copy link
Collaborator

Choose a reason for hiding this comment

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

htmlFor이라는 속성도 있군요!! 하나 또 알아갑니다.

@leeminhee119 leeminhee119 changed the title Feature/#11/checkbox 중복선택 버튼 컴포넌트 (체크박스) 작성 Jul 13, 2024
Comment on lines 3 to 12
import { RadioContextState } from "@/store/context/RadioContext";

type UseRadioButtonReturn = [RadioContextState["isChecked"], RadioContextState["onChange"], string | undefined];

export const useRadioButton = (): UseRadioButtonReturn => {
const [selectedValue, setSelectedValue] = useState<string>();
const isChecked = (value: string) => selectedValue === value;
const onChange = (value: string) => setSelectedValue(value);

return [isChecked, onChange, selectedValue];
Copy link
Collaborator

@donghunee donghunee Jul 13, 2024

Choose a reason for hiding this comment

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

Suggested change
import { RadioContextState } from "@/store/context/RadioContext";
type UseRadioButtonReturn = [RadioContextState["isChecked"], RadioContextState["onChange"], string | undefined];
export const useRadioButton = (): UseRadioButtonReturn => {
const [selectedValue, setSelectedValue] = useState<string>();
const isChecked = (value: string) => selectedValue === value;
const onChange = (value: string) => setSelectedValue(value);
return [isChecked, onChange, selectedValue];
export const useRadioButton = () => {
const [selectedValue, setSelectedValue] = useState<string>();
const isChecked = (value: string) => selectedValue === value;
const onChange = (value: string) => setSelectedValue(value);
return [isChecked, onChange, selectedValue] as const;
}

저는 custom hook에서 배열로 반환 시 return type을 설정해줄 때 as const로 명시해주는게 깔끔하더라구요~!!

별개로 object return 이 아닌 array return을 채택하신 이유도 궁금해요~!!

Copy link
Member Author

Choose a reason for hiding this comment

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

아!! 맞네요 as const로 수정하겠습니다! 감사합니다 🙇‍♀️

+) Staging.tsx 파일에 예시 작성하면서 라디오버튼과 체크박스를 같이 사용할 때 useRadioButton, useCheckBox 훅이 같은 이름(isChecked)을 반환하다보니 충돌이 나더라구요! 저희 프로젝트에서는 아직까지 그럴 일은 없겠지만, 그래도 이름을 사용하는 쪽에서 바꿔서 사용하면 좋겠다는 생각으로 이렇게 작성했습니다!

Copy link
Collaborator

Choose a reason for hiding this comment

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

자세한 설명 감사합니다👍👍

@leeminhee119 leeminhee119 requested a review from donghunee July 13, 2024 15:05
Copy link
Collaborator

@donghunee donghunee left a comment

Choose a reason for hiding this comment

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

수고하셨습니다👏👏

@leeminhee119 leeminhee119 merged commit 217356e into develop Jul 14, 2024
1 check passed
@leeminhee119 leeminhee119 deleted the feature/#11/checkbox branch July 14, 2024 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 feature New feature or request 🧹 refactor 사용자에게는 드러나지 않는 코드 상의 변화
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants