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

Drawer 의 Transition 이벤트시 외부함수를 주입할수 있도록 변경했다 #44

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Changes from 1 commit
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
32 changes: 30 additions & 2 deletions packages/co-design-core/src/components/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ export interface DrawerProps extends CoComponentProps<DrawerStylesNames>, Omit<R

/** Drawer 컴포넌트가 닫힐 때 실행됩니다. */
onClose(): void;

/** Drawer 컴포넌트가 열리는 진입 트랜지션이 시작되면 실행됩니다. */
onEnter?(): void;

/** Drawer 컴포넌트가 열리는 진입 트랜지션이 끝나면 실행됩니다. */
onEntered?(): void;

/** Drawer 컴포넌트가 닫히는 종료 트랜지션이 시작되면 실행됩니다. */
onExit?(): void;

/** Drawer 컴포넌트가 닫히는 종료 트랜지션이 끝나면 실행됩니다. */
onExited?(): void;
}

const transitions: Record<DrawerPosition, CoTransition> = {
Expand Down Expand Up @@ -108,6 +120,10 @@ export const CoDrawer = ({
onClose,
className,
overrideStyles,
onEnter,
onEntered,
onExit,
onExited,
...props
}: DrawerProps) => {
const { classes, cx, theme } = useStyles({ size, position }, { overrideStyles, name: 'Drawer' });
Expand Down Expand Up @@ -135,8 +151,20 @@ export const CoDrawer = ({

return (
<GroupedTransition
onExited={() => lockScroll(false)}
onEntered={() => lockScroll(!noScrollLock && true)}
onExit={() => {
if (onExit) onExit();
}}
Copy link
Member

Choose a reason for hiding this comment

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

onExit={onExit}와 같은 형태로 넣으면 onExitundefined일 때 어차피 실행이 안될 것 같은데 if를 사용한 이유가 있을까요?

Copy link
Member Author

@healtheloper healtheloper Nov 13, 2023

Choose a reason for hiding this comment

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

@kciter undefiend 인 경우 내부 로직에서 undefiend 임에도 함수로 실행시키는 로직이 있다면 undefined is not function 타입 에러가 발생할 수 있을 것 같아 한번 조건문으로 감쌌는데, 내부 로직을 다시 파악해보니 typeof function 로 분기처리하고 있어서 말씀하신 코드로 변경하겠습니다

onExited={() => {
lockScroll(false);
if (onExited) onExited();
}}
onEnter={() => {
if (onEnter) onEnter();
}}
onEntered={() => {
lockScroll(!noScrollLock && true);
if (onEntered) onEntered();
}}
mounted={opened}
transitions={{
overlay: { duration: transitionDuration / 2, transition: 'fade', timingFunction: 'ease' },
Expand Down
Loading