Socket
Socket
Sign inDemoInstall

@lani.ground/react-modal

Package Overview
Dependencies
0
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @lani.ground/react-modal

Modal components used in reactjs


Version published
Weekly downloads
25
decreased by-68.35%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

react-modal

npm

Modal components used in reactjs.

Demo

Example

Modal Example

Installation

npm install @lani.ground/react-modal

// or

yarn add @lani.ground/react-modal

Usage

// Components to be shown

interface PopupProps {
  closeModal: () => Promise<void>;
}

function Popup({closeModal}: PopupProps) {
  return (
    <div className="sample-modal-inner">
      <button
        type="button"
        onClick={closeModal}
      >
        Close Modal
      </button>
      <div>
        {/* content here */}
        {/*
          If you want to implement nested modals
          <Modal name="[unique name]"
            ...
          />
        */}
      </div>
    </div>
  );
}
  )
}
// using modal
import { Modal } from '@lani.ground/react-modal';
import '@lani.ground/react-modal/css';


export default function Component({
  closeModal,
}: {
  closeModal: () => Promise<void>;
}) {
  const [isOpen, setIsOpen] = useState<boolean>(false);
  return (
    <>
      <button type="button" onClick={() => setIsOpen(true)}>Click Me!</button>
      <Modal
        name="modal"
        component={(closeModal) => <Popup closeModal={closeModal} />}
        onClose={() => {
          // callback here
          setIsOpen(false);
        }}
        dim="rgba(0, 0, 0, 0.8)"
        animation={{
          duration: 1000, // Modals cannot be re-opened or closed for the specified time.(ms)
          className: 'sample',
        }}
        centerMode
        isOpen={isOpen}
      />
    </>
  );
}
/* Examples of effects when modals appear and disappear */
.react-modal__container__enter.sample,
.react-modal__container__exit.sample {
  transition-duration: 1s;
}

.react-modal__container__enter {
  opacity: 1;
  transition-property: all;
  filter: blur(0);
}

.react-modal__container__enter .sample-modal-inner {
  transform: scale(1);
  opacity: 1;
  filter: blur(0);
  transition: all 1s;
}

.react-modal__container__exit {
  opacity: 0;
  transition-property: all;
  filter: blur(1rem);
}

.react-modal__container__exit .sample-modal-inner {
  transform: scale(0);
  opacity: 0;
  transition: all 1s;
  filter: blur(1rem);
}

Isolating components by state

const [isVaild, setIsValid] = useState<boolean>(false);

<Modal
  component={(closeModal) => {
    if (isVaild) return <div>Vaild!</div>;
    return <div>Not vaild!</div>;
  }}
/>

If you want to show the modal as soon as the screen is rendered

<Modal
  {/* ... */}
  isOpen={true}
/>

// or

const [isOpen, setIsOpen] = useState<boolean>(true);

<Modal
  onClose={() => {
    setIsOpen(false);
  }}
  isOpen={isOpen}
/>

Props

Nametypedescription
name(optional)string (default: 'modal')If there are nested modals, it should be used and requires a unique value.
고유한 값으로 중첩 모달을 사용시에 필요합니다.
component(closeModal: () => Promise) => JSX.ElementModal Component
화면에 표시될 모달 컴포넌트
onClose(optional)() => unknownCallback called when the modal closes.
모달이 닫힐 때 호출되는 콜백
dim(optional)stringPlease enter the color to be used for dim.
Dim 배경 색상
isOpen(optional)boolean (default: false)Modal Open Status
모달 오픈 상태
centerMode(optional)boolean (default: false)Whether to use the center mode
중앙 정렬 모드 사용 여부
animation(optional){
className?: string
(default: react-modal__container),
duration: number(ms)
}
You can set the animation option to add effects when a modal is displayed
모달이 표시될 때 효과를 추가하려면 애니메이션 옵션을 설정할 수 있습니다.
className: You can inject a specific class so that you can control the animation.
애니메이션을 제어하기 위해 특정 클래스를 삽입할 수 있습니다.
duration: Modals cannot be re-opened or closed for the specified time.
모달은 지정된 시간 동안 다시 열거나 닫을 수 없습니다.
isUnlockScroll(optional)boolean (default: false)Whether to allow scrolling in the background
뒷 배경의 스크롤을 허용할지 여부
containerPadding(optional)stringYou can apply the padding value of the container.
컨테이너의 패딩 값을 적용할 수 있습니다.

Keywords

FAQs

Last updated on 26 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc