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

@acrool/react-modal

v1.0.2

Published

Modal library based for Reactjs

Downloads

329

Readme

Acrool React Modal

NPM npm npm

npm downloads npm

Features

  • Supports queue modal list
  • Plug and unplug using @acrool/react-portal and framer-motion
  • Quickly create light box effects and send them to the outside to avoid hierarchical problems
  • Support @acrool/react-router-hash lightbox (using createControlledModal)
  • Modal open auto add acrool_model-open body overflow style class
  • export BodyScroll utils (state control)

Install

yarn add framer-motion @acrool/react-modal

in your packages. (Make the version of styled-component you use match the version of styled-component used in acrool-react-gird)

"resolutions": {
    "framer-motion": "^11.x"
}

Usage

add in your index.tsx

import "@acrool/react-modal/dist/index.css";

add in your App.tsx

It should be noted that it must be within the scope of Router Provider. Another way is to place it in Layout and Outlet middle layer.

import {ModalPortal} from "@acrool/react-modal";

const App = () => {
    return (
        <div>
            <BaseUsed/>
            <ModalPortal/>
        </div>
    );
};

A. Custom modal component

Add the lightbox to the display column list by throwing the Show method

Defined Modal

import {animation, createModal, IModalOptions, useModal} from '@acrool/react-modal';

interface IProps {
    myVar: string
}

const PromotionModal = (args: IProps) => {
    const {hide} = useModal();

    return <div>
        <div>Test2 content</div>
        <button type="button" onClick={hide}>X </button>
    </div>;
}

export default createModal(
    PromotionModal,
    animation.generateFadeIn(),
);

Use Modal

then in your page

const ExamplePage = () => {
    return <div>
        <button type="button" onClick={() => PromotionModal.show({myVar: 'Imageine'})}>Show Modal</button>
    </div>
}

B. Custom state modal component

The inside of the light box is controlled by its own state, which is displayed through rendering, such as using HashRouter.

Defined Modal

import {animation, createStateModal, IModalOptions, useModal} from '@acrool/react-modal';
import {useHashParams} from '@acrool/react-router-hash';


const PromotionHashModal = () => {
      const {hide} = useModal();
      const navigate = useNavigate();
      const {id} = useHashParams<{id: string}>();

      useEffect(() => {
        return () => {
          navigate({...location, hash: undefined});
        };
      }, []);

      const handleOnHide = () => {
        hide();
      };
      
      // const handleOnClose = () => {
      //     hide().then(() => {
      //         navigate({hash: undefined});
      //     })
      // }

  return <div>
          <div>Test2 content</div>
          <button type="button" onClick={handleOnClose}>Close Modal</button>
      </div>;
}

export default createStateModal(
    PromotionHashModal,
    {
      ...animation.generateFadeIn(),
      isEnableHideWithClickMask: true,
    },
);

Defined Hash Route

It should be noted that it must be within the scope of Router Provider. Another way is to place it in Layout and Outlet middle layer.

import {HashRoute,HashRoutes} from '@acrool/react-router-hash';
import {createBrowserHistory} from 'history';
import {BrowserRouter as Router,Route, Routes} from 'react-router-dom';

const history = createBrowserHistory({window});

const RouterSetting = () => {
    return <Router>

        <Routes>
            <Route path="/" element={<Example/>} />
        </Routes>

        <HashRoutes>
            <HashRoute path="promotion/:id" element={<PromotionHashModal/>}/>
        </HashRoutes>

        {/* Add this */}
        <ModalPortal/>

    </Router>;
};

Use Modal

then in your page

import {useNavigate} from 'react-router-dom';

const ExamplePage = () => {
    const navigate = useNavigate();
    return <div>
        <button type="button" onClick={() => navigate({hash: '/promotion/1'})}>Show Modal</button>
        <button type="button" onClick={() => navigate({hash: '/promotion/2'})}>Show Modal</button>
    </div>
}
  • animation
    • fadeInDown: (default), ex Base modal style
    • zoomInDown
    • slideInLeft: ex Drawer slider
    • slideInRight: ex Drawer slider
    • slideInUp: ex Dropdown
    • custom (ref; https://www.framer.com/motion/animate-presence/#usage)
    variants = {
      initial: {opacity: 0, y: -20, transition: {type:'spring'}},
      animate: {opacity: 1, y: 0},
      exit: {opacity: 0, y: -40}
    }

There is also a example that you can play with it:

Play react-editext-example

License

MIT © Acrool & Imagine

Refer to