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

[Refactor/BAR-233] Dropdown 컴포넌트 수정 #58

Merged
merged 13 commits into from
Feb 13, 2024
Merged

Conversation

dmswl98
Copy link
Member

@dmswl98 dmswl98 commented Feb 12, 2024

Summary

구현 내용 및 작업한 내역을 요약해서 적어주세요

To Reviewers

PR을 볼 때 주의깊게 봐야하거나 말하고 싶은 점을 적어주세요

  • 기존에 직접 CSS로 Dropdown 컴포넌트 위치를 직접 조정했다면, 리팩토링을 통해 trigger 요소와 결합해 작성 가능하도록 구현했어요.
<Dropdown {...args}>
  <Dropdown.Trigger>버튼</Dropdown.Trigger>
  <Dropdown.List>
    <Dropdown.Item onClick={}>수정하기</Dropdown.Item>
    <Dropdown.Item onClick={}>삭제하기</Dropdown.Item>
  </Dropdown.List>
</Dropdown>

useDisclosure

boolean 상태를 관리하는 hook

const { isOpen, onOpen, onClose, onToggle } = useDisclosure();

useClickAway

ref 객체 외부를 클릭했을 때 실행해야할 이벤트를 설정할 수 있어요.

const ref = useClickAway({
  onClickAway: onClose,
});

usePosition

triggerRef를 기준으로 targetRef 요소를 위치시킬 position: { top, left } 위치값을 반환해요.

type Placement = "bottom-left" | "bottom-center" | "bottom-right" | "top-left" | "top-center" | "top-right"
const { triggerRef, targetRef, position } = usePosition({
  isOpen,
  placement,
});
const { targetRef, position } = usePosition<HTMLDivElement, HTMLUListElement>(
  {
    defaultTriggerRef: triggerRef,
    isOpen,
    placement,
    fixed,
  },
);
  • 제네릭을 이용해 ref 요소를 특정 태그로 설정할 수 있어요.
  • usePosition hook 내부에서 ref(triggerRef)를 생성하지 않고, 기존 ref를 사용하고 싶다면 defaultTriggerRef prop을 사용하면 돼요.

How To Test

PR의 기능을 확인하는 방법을 상세하게 적어주세요

Copy link

@@ -0,0 +1,68 @@
import { type RefObject, useEffect, useRef, useState } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

@dmswl98
어떤 기준으로 위치를 결정하는걸까요?

Copy link
Member Author

Choose a reason for hiding this comment

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

triggerRef 요소를 기준으로 targetRef 요소를 위치시킵니다!

Copy link
Contributor

@miro-ring miro-ring left a comment

Choose a reason for hiding this comment

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

수고하셧습니다!!!
그 디자인 시스템에 Dialog로 되어 있는 부분만 Dropdown으로 변경 요청 드려도 좋을 것 같아요!

@dmswl98 dmswl98 merged commit a9af233 into main Feb 13, 2024
@dmswl98 dmswl98 deleted the refactor/BAR-233 branch February 13, 2024 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants