๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
React

[React] ์„ธ์ƒ ์‰ฌ์šด ๋ฆฌ์•กํŠธ ๋ชจ๋‹ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

by LasBe 2024. 5. 7.
๋ฐ˜์‘ํ˜•

๐Ÿ“’ ๋„ˆ๋ฌด๋‚˜ ์‰ฌ์šด ๋ฆฌ์•กํŠธ ๋ชจ๋‹ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ


  • ์ €์—๊ฒŒ ๋”ฑ ๋งž๋Š” ์Šคํƒ€์ผ์˜ ๋ชจ๋‹ฌ ์ปดํฌ๋„ŒํŠธ, ์žฌ์‚ฌ์šฉํ•˜๋ ค๊ณ  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.
  • 6๊ฐœ์›” ์ „ ๋Œ€์ถฉ ๋งŒ๋“ค๋‹ค ๋ง์•˜๋˜ ์ฝ”๋“œ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ตฌ์กฐ ๋‹ค์‹œ ์งœ๋Š๋ผ ํ† ํ•  ๋ป” ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ๋‹ค๋ฅธ ์ข…์†์„ฑ ์—†์ด react context๋ฅผ ์ด์šฉํ•ด ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.
  • ๋ชจ๋‹ฌ ์กฐ์ž‘์— ๊ด€๋ จ๋œ ๋กœ์ง๋งŒ ์ถ”์ƒํ™”ํ•˜๊ณ , ์Šคํƒ€์ผ๊ณผ UI ๋ Œ๋” ๊ด€๋ จ ๋กœ์ง์€ ์ตœ๋Œ€ํ•œ headless ํ•˜๊ฒŒ ๋งŒ๋“ค์–ด ์–ด๋Š ํ”„๋กœ์ ํŠธ์—์„œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.
  • ๋‹ค์ค‘ ๋ชจ๋‹ฌ ๊ธฐ๋Šฅ์€ UX์ ์œผ๋กœ ๊ทธ๋‹ฅ์ด๋ผ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.
  • ์ „์ฒด ์ ์šฉ ๊ธฐ๋ณธ ์Šคํƒ€์ผ์€ provider์—๊ฒŒ, ๊ฐœ๋ณ„ ์ ์šฉํ•  ์Šคํƒ€์ผ์€ openModal() ํ•จ์ˆ˜์—๊ฒŒ.
  • ์ง„์งœ ์‰ฝ๊ณ  ๊ฐ„ํŽธํ•˜๋‹ˆ๊นŒ ํ•œ๋ฒˆ๋งŒ ์จ์ฃผ์„ธ์š”

๐Ÿ“Œ @lasbe/react-modal

 

@lasbe/react-modal

๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฆฌ์•กํŠธ ๋ชจ๋‹ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค.. Latest version: 1.0.1, last published: 3 hours ago. Start using @lasbe/react-modal in your project by running `npm i @lasbe/react-modal`. There are no other projects in the n

www.npmjs.com

 

GitHub - LasBe-code/react-modal: ์‰ฝ๊ณ  ๊ฐ„๋‹จํ•œ React Modal ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

์‰ฝ๊ณ  ๊ฐ„๋‹จํ•œ React Modal ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ. Contribute to LasBe-code/react-modal development by creating an account on GitHub.

github.com

์„ ์–ธ์ ์œผ๋กœ ๋ชจ๋‹ฌ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํŒจํ‚ค์ง€์ž…๋‹ˆ๋‹ค.
๊ตฌ์„ฑ๊ณผ ๋””์ž์ธ์„ ์ตœ๋Œ€ํ•œ ์ž์œ ๋กญ๊ฒŒ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจ๋‹ฌ์˜ ๋ฐฐ๊ฒฝ์ธ dimmer์™€ ์Šคํฌ๋กค ๋ฐฉ์ง€ ๊ธฐ๋Šฅ์ด ํฌํ•จ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ”Ž install

$ npm i @lasbe/react-modal

๐Ÿ”Ž example

  1. ModalProvider๋ฅผ ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ์— ๊ฐ์•„์ค๋‹ˆ๋‹ค.
root.render(
  <ModalProvider>
    <App />
  </ModalProvider>,
);
  1. useModal() ํ›…์„ ์ด์šฉํ•ด ๋ชจ๋‹ฌ์„ ์—ฌ๋‹ซ๋Š” ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.
    ModalStyle์„ import ํ•˜์—ฌ ๊ธฐ๋ณธ ์Šคํƒ€์ผ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
import React from 'react';
import { useModal, ModalStyle } from '@lasbe/react-modal';

function App() {
  const { openModal, closeModal } = useModal();
  return (
    <button
      onClick={() =>
        openModal({
          content: (
            <>
              <ModalStyle.Header>
                <ModalStyle.Title>Header</ModalStyle.Title>
              </ModalStyle.Header>
              <ModalStyle.Body>Body</ModalStyle.Body>
              <ModalStyle.Footer>
                <ModalStyle.Button color="gray" onClick={closeModal}>
                  Close
                </ModalStyle.Button>
                <ModalStyle.Button onClick={closeModal}>Submit</ModalStyle.Button>
              </ModalStyle.Footer>
            </>
          ),
        })
      }
    >
      OPEN MODAL
    </button>
  );
}

export default App;

๐Ÿ”Ž props

  1. <ModalProvider />
type ModalProvidertype = {
  children: React.ReactElement;
  options?: {
    // ๋ชจ๋‹ฌ ๋ฐฐ๊ฒฝ ์Šคํƒ€์ผ ์ง€์ •
    dimmer?: React.CSSProperties;
    // ๋ชจ๋‹ฌ body ์Šคํƒ€์ผ ์ง€์ •
    body?: React.CSSProperties;
    // ๋ชจ๋‹ฌ ์—ฌ๋‹ซ์„ ๋•Œ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ ์šฉ ์—ฌ๋ถ€
    useAnimation?: boolean;
  };
};
  1. openModal()
type OpenModalType = {
  // Modal์— ๋„์šธ ์š”์†Œ
  content: React.ReactNode;
  options?: {
    // ๋ชจ๋‹ฌ ๋ฐฐ๊ฒฝ ์Šคํƒ€์ผ ์ง€์ •
    dimmer?: React.CSSProperties;
    // ๋ชจ๋‹ฌ body ์Šคํƒ€์ผ ์ง€์ •
    body?: React.CSSProperties;
    // ๋ชจ๋‹ฌ ์—ฌ๋‹ซ์„ ๋•Œ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ ์šฉ ์—ฌ๋ถ€
    useAnimation?: boolean;
  };
};
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€


์˜คํ”ˆ ์ฑ„ํŒ