npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lani.ground/react-modal

v2.1.5

Published

Modal components used in reactjs

Downloads

209

Readme

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

| Name | type | description | | ---------------------- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | name(optional) | string (default: 'modal') | If there are nested modals, it should be used and requires a unique value. 고유한 값으로 중첩 모달을 사용시에 필요합니다. | | | component | (closeModal: () => Promise) => JSX.Element | Modal Component 화면에 표시될 모달 컴포넌트 | | onClose(optional) | () => unknown | Callback called when the modal closes.모달이 닫힐 때 호출되는 콜백 | | dim(optional) | string | Please 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) | string | You can apply the padding value of the container. 컨테이너의 패딩 값을 적용할 수 있습니다. |