Skip to content

Commit

Permalink
Merge pull request #91 from pknu-wap/refactor/#89/use-portal
Browse files Browse the repository at this point in the history
Refactor/#89/use portal
  • Loading branch information
alstn113 authored May 14, 2023
2 parents 4404f50 + d3315c3 commit 6d047d2
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 231 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
yarn.lock
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plgin:react-hooks/recommended",
"plugin:react-hooks/recommended",
"plugin:storybook/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
yarn.lock
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ To use WAP UI, Install the `@wap-ui/react` package and its peer dependencies.
(`@emotion/react`, `@emotion/styled`, `framer-motion`)

```sh
pnpm add @wap-ui/react @emotion/react @emotion/styled framer-motion
# or
yarn add @wap-ui/react @emotion/react @emotion/styled framer-motion
# or
npm i @wap-ui/react @emotion/react @emotion/styled framer-motion
Expand Down
32 changes: 0 additions & 32 deletions docs/components/Portal.md

This file was deleted.

4 changes: 3 additions & 1 deletion packages/react/.storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<div id="modal"></div>
<script>
window.global = window;
</script>
8 changes: 5 additions & 3 deletions packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
</tr>
<tr>
<td width="50%">
<img src="https://user-images.githubusercontent.com/75781414/209562230-7f3e9d0d-fa5f-452c-be92-dfeebb251e48.gif" />
<img src="https://user-images.githubusercontent.com/75781414/209572114-dfa9b08a-052b-446e-afd5-388545d09c6b.gif" />
</td>
<td width="50%">
<img src="https://user-images.githubusercontent.com/75781414/209560781-9994d09d-6768-4555-833d-35d6ebe16a11.gif" />
<img src="https://user-images.githubusercontent.com/75781414/209572876-2720e0ef-94bb-441d-b24e-b282fefc683d.gif" />
</td>
</tr>
</tr>
Expand All @@ -45,6 +45,8 @@ To use WAP UI, Install the `@wap-ui/react` package and its peer dependencies.
(`@emotion/react`, `@emotion/styled`, `framer-motion`)

```sh
pnpm add @wap-ui/react @emotion/react @emotion/styled framer-motion
# or
yarn add @wap-ui/react @emotion/react @emotion/styled framer-motion
# or
npm i @wap-ui/react @emotion/react @emotion/styled framer-motion
Expand Down Expand Up @@ -141,7 +143,7 @@ export default Home;
## `Links`

- #### [Documents](https://github.com/pknu-wap/wap-ui/tree/main/docs)
- #### [NPM](https://www.npmjs.com/package/wap-ui)
- #### [NPM](https://www.npmjs.com/package/@wap-ui/react)
- #### [Playground](https://wap-ui.vercel.app/)
- #### [Presentations](https://github.com/pknu-wap/wap-ui/tree/main/ppt)
- #### [Example](https://github.com/pknu-wap/wap-ui/tree/main/example)
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wap-ui/react",
"version": "1.3.3",
"version": "1.4.0",
"description": "WAP UI / React UI Components Library",
"repository": "https://github.com/pknu-wap/2022_2_WAP_WEB_TEAM1.git",
"author": "neko113 <alstn113@gmail.com>",
Expand Down
9 changes: 6 additions & 3 deletions packages/react/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useRef, useState } from 'react';
import useOnClickOutside from '../../hooks/useOnClickOutside';
import { DropdownMenu } from './DropdownMenu';
import { DropdownMenuItem } from './DropdownMenuItem';
import { DropdownButton } from './DropdownButton/DropdownButton';
import { DropdownContext } from './DropdownContext';
import { Portal } from '../Portal';
import { usePortal, useOnClickOutside } from '../../hooks';
import { createPortal } from 'react-dom';

export interface DropdownProps {
children: React.ReactNode[];
Expand All @@ -27,6 +27,7 @@ export interface DropdownProps {
* ```
*/
export const Dropdown = ({ children }: DropdownProps) => {
const el = usePortal('dropdown');
/** triggerRef은 Context를 타고 DropdownButton으로 전달됨 */
const triggerRef = useRef<HTMLButtonElement>(null);
const contentRef = useRef<HTMLDivElement>(null);
Expand All @@ -42,6 +43,8 @@ export const Dropdown = ({ children }: DropdownProps) => {
}
});

if (!el) return null;

return (
<DropdownContext.Provider
value={{
Expand All @@ -54,7 +57,7 @@ export const Dropdown = ({ children }: DropdownProps) => {
{/* tirgger button <Dropdown.Button>Actions</Dropdown.Button> */}
{trigger}
{/* content menu <Dropdown.Menu>...</Dropdown.Menu> */}
<Portal>{content}</Portal>
{createPortal(content, el)}
</DropdownContext.Provider>
);
};
Expand Down
57 changes: 30 additions & 27 deletions packages/react/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { AnimatePresence, useWillChange, type Variants } from 'framer-motion';
import React, { useLayoutEffect } from 'react';
import { Portal } from '../Portal';
import * as S from './Modal.styles';
import { ModalBody } from './ModalBody/ModalBody';
import { ModalFooter } from './ModalFooter/ModalFooter';
import { ModalHeader } from './ModalHeader/ModalHeader';
import { usePortal } from '../../hooks';
import { createPortal } from 'react-dom';

export interface ModalProps {
/**
Expand Down Expand Up @@ -52,6 +53,7 @@ export const Modal = ({
children,
}: ModalProps) => {
const willChange = useWillChange();
const el = usePortal('modal');

useLayoutEffect(() => {
if (isOpen) {
Expand Down Expand Up @@ -88,37 +90,38 @@ export const Modal = ({
},
};

return (
<Portal target="modal">
<AnimatePresence>
{isOpen && (
<>
<S.Overlay
variants={overlayVariants}
if (!el) return null;

return createPortal(
<AnimatePresence>
{isOpen && (
<>
<S.Overlay
variants={overlayVariants}
initial="initial"
animate="animate"
exit="exit"
transition={{ duration: 0.3 }}
blur={blur.toString()}
onClick={onClose}
style={{ willChange }}
/>
<S.Positioner>
<S.ModalContainer
variants={modalVariants}
initial="initial"
animate="animate"
exit="exit"
transition={{ duration: 0.3 }}
blur={blur.toString()}
onClick={onClose}
style={{ willChange }}
/>
<S.Positioner>
<S.ModalContainer
variants={modalVariants}
initial="initial"
animate="animate"
exit="exit"
transition={{ duration: 0.3 }}
style={{ willChange }}
>
{children}
</S.ModalContainer>
</S.Positioner>
</>
)}
</AnimatePresence>
</Portal>
>
{children}
</S.ModalContainer>
</S.Positioner>
</>
)}
</AnimatePresence>,
el,
);
};

Expand Down
60 changes: 0 additions & 60 deletions packages/react/src/components/Portal/Portal.stories.tsx

This file was deleted.

82 changes: 0 additions & 82 deletions packages/react/src/components/Portal/Portal.tsx

This file was deleted.

1 change: 0 additions & 1 deletion packages/react/src/components/Portal/index.ts

This file was deleted.

Loading

0 comments on commit 6d047d2

Please sign in to comment.