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(web-domains): 공통 모달 컴포넌트 #71

Merged
merged 5 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions apps/web/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { FirstDomainExampleScreen } from '@sambad/web-domains/first-domain';

export default FirstDomainExampleScreen;
export default function Second() {
return <div></div>;
}
8 changes: 1 addition & 7 deletions apps/web/app/second/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { SecondDomainExampleScreen } from '@sambad/web-domains/second-domain';

import styles from '../page.module.css';

export default function Second() {
return (
<main className={styles.main}>
<SecondDomainExampleScreen />
</main>
);
return <main className={styles.main}></main>;
}

This file was deleted.

5 changes: 3 additions & 2 deletions packages/core/sds/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ButtonHTMLAttributes, forwardRef, HTMLAttributes } from 'react';
import { ButtonSize, ButtonVariant } from './types';
import { ButtonHTMLAttributes, forwardRef } from 'react';

import { buttonCss, buttonDisabledVariants, buttonSizeVariants, buttonVariantVariants } from './styles';
import { ButtonSize, ButtonVariant } from './types';

export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
size?: ButtonSize;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/sds/src/components/Button/styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from '@emotion/react';

import { borderRadiusVariants, colors } from '../../theme';

import { ButtonSize, ButtonVariant } from './types';

const buttonHeightVar = '--sambad-button-height';
Expand Down
8 changes: 5 additions & 3 deletions packages/core/sds/src/components/TextButton/TextButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ButtonHTMLAttributes, Children, forwardRef } from 'react';
import { TextButtonVariant } from './types';
import { ButtonHTMLAttributes, forwardRef } from 'react';

import { colors } from '../../theme';
import { Icon } from '../Icon';

import { arrowIconCss, textButtonCss } from './styles';
import { colors } from '../../theme';
import { TextButtonVariant } from './types';

export interface TextButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: TextButtonVariant;
Expand Down
1 change: 0 additions & 1 deletion packages/core/sds/src/components/TextButton/styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { css } from '@emotion/react';
import { colors } from '../../theme';

export const textButtonCss = css({
display: 'inline-flex',
Expand Down
80 changes: 80 additions & 0 deletions packages/web-domains/src/common/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use client';

import { borderRadiusVariants, colors } from '@sambad/sds/theme';
import { HTMLAttributes, PropsWithChildren, ReactNode, useEffect, useState } from 'react';
import { createPortal } from 'react-dom';

export interface ModalProps extends HTMLAttributes<HTMLDivElement> {
isOpen: boolean;
width?: number;
footer?: ReactNode;
onClose?: () => void;
}

export const Modal = ({ isOpen, width, onClose, children, footer, ...rest }: PropsWithChildren<ModalProps>) => {
const [modalState, setIsModalState] = useState<boolean>(isOpen);
const [element, setElement] = useState<HTMLElement | null>(null);

const modalWidth = width ? `${width}px` : '100%';
Copy link
Member

Choose a reason for hiding this comment

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

모바일 뷰라서 너비를 만질 일이 많이 없을 것 같은데
prop에서 width 제거하고, 내부에서는 제일 많이 사용하는 너비로 width 고정적으로 스타일링하는 것 어떠신가용 ? (maxWidth === 기본 width로..?)

진짜 만약 필요하면 사용처에서 스타일 오버라이드 하라고 하죠 ~!


const handleClose = () => {
setIsModalState(false);
onClose?.();
};

useEffect(() => {
setElement(document.body);
}, []);

useEffect(() => {
if (modalState) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = 'auto';
}

return () => {
document.body.style.overflow = 'auto';
};
}, [modalState]);

if (typeof window === 'undefined') {
return <></>;
}

if (!element) {
return <></>;
}

if (!modalState) {
return null;
}

return createPortal(
<div
css={{ width: '100%', height: '100%', background: '#00000066', position: 'fixed', top: 0 }}
onClick={handleClose}
>
<div
id="modal"
css={{
padding: '20px',
width: modalWidth,
maxWidth: '335px',
position: 'fixed',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
backgroundColor: colors.white,
borderRadius: borderRadiusVariants.medium,
zIndex: '10000',
Copy link
Member

Choose a reason for hiding this comment

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

음 createPortal 사용하면 zIndex 필요 없지 않나요? 🤔

}}
{...rest}
>
{children}
<div id="modal-footer">{footer}</div>
</div>
</div>,
element,
);
};
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions packages/web-domains/src/first-domain/index.ts

This file was deleted.

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion packages/web-domains/src/second-domain/index.ts

This file was deleted.

Loading
Loading