{"id":20447621,"url":"https://github.com/acrool/acrool-react-modal","last_synced_at":"2025-07-16T16:39:03.076Z","repository":{"id":248483910,"uuid":"828721027","full_name":"acrool/acrool-react-modal","owner":"acrool","description":"react create modal method","archived":false,"fork":false,"pushed_at":"2025-05-27T13:25:15.000Z","size":1861,"stargazers_count":8,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-08T10:56:00.121Z","etag":null,"topics":["model","react-model","react-portal","reactjs","route-hash-modal","typescript"],"latest_commit_sha":null,"homepage":"https://acrool-react-modal.pages.dev/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/acrool.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-15T01:43:52.000Z","updated_at":"2025-06-03T04:30:40.000Z","dependencies_parsed_at":"2024-08-07T17:27:36.928Z","dependency_job_id":"391d7dea-f6b1-462a-b68c-fe37315f20ac","html_url":"https://github.com/acrool/acrool-react-modal","commit_stats":null,"previous_names":["acrool/acrool-react-modal"],"tags_count":49,"template":false,"template_full_name":null,"purl":"pkg:github/acrool/acrool-react-modal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acrool%2Facrool-react-modal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acrool%2Facrool-react-modal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acrool%2Facrool-react-modal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acrool%2Facrool-react-modal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acrool","download_url":"https://codeload.github.com/acrool/acrool-react-modal/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acrool%2Facrool-react-modal/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265524907,"owners_count":23782057,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["model","react-model","react-portal","reactjs","route-hash-modal","typescript"],"created_at":"2024-11-15T10:28:04.947Z","updated_at":"2025-07-16T16:39:03.068Z","avatar_url":"https://github.com/acrool.png","language":"TypeScript","funding_links":[],"categories":["React underlying structure"],"sub_categories":[],"readme":"# Acrool React Modal\n\n\u003ca href=\"https://acrool-react-modal.pages.dev/\" title=\"Acrool React Modal - This is a modal function for React development loading modal\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/acrool/acrool-react-modal/main/example/public/og.webp\" alt=\"Acrool React Modal Logo\"/\u003e\n\u003c/a\u003e\n\n\u003cp align=\"center\"\u003e\n    This is a toast message function for React development notifications\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![NPM](https://img.shields.io/npm/v/@acrool/react-modal.svg?style=for-the-badge)](https://www.npmjs.com/package/@acrool/react-modal)\n[![npm](https://img.shields.io/bundlejs/size/@acrool/react-modal?style=for-the-badge)](https://github.com/acrool/@acrool/react-modal/blob/main/LICENSE)\n[![npm](https://img.shields.io/npm/l/@acrool/react-modal?style=for-the-badge)](https://github.com/acrool/react-modal/blob/main/LICENSE)\n\n[![npm downloads](https://img.shields.io/npm/dm/@acrool/react-modal.svg?style=for-the-badge)](https://www.npmjs.com/package/@acrool/react-modal)\n[![npm](https://img.shields.io/npm/dt/@acrool/react-modal.svg?style=for-the-badge)](https://www.npmjs.com/package/@acrool/react-modal)\n\n\u003c/div\u003e\n\n\n`^1.1.0 support react \u003e=19.0.0 \u003c20.0.0, framer-motion@12`\n\n\n## Features\n\n- Supports queue modal list\n- Plug and unplug using `@acrool/react-portal` and `framer-motion`\n- Quickly create light box effects and send them to the outside to avoid hierarchical problems\n- Support [@acrool/react-router-hash](https://github.com/acrool/acrool-react-router-hash) lightbox (using createControlledModal)\n- Modal open auto add `acrool_model-open` body overflow style class\n- export BodyScroll utils (state control)\n\n## Install\n\n```bash\nyarn add @acrool/react-modal framer-motion@12\n```\n\nin your packages.\n\n```json\n{\n    \"resolutions\": {\n        \"framer-motion\": \"^12.x\"\n    }\n}\n```\n\n\u003e ⚠️ If you do not rely on the project's internal `framer-motion`, the internal self-implemented AnimatePresence will be affected and produce unexpected results.\n\n\n## Usage\n\nadd in your index.tsx\n```tst\nimport \"@acrool/react-modal/dist/index.css\";\n```\n\nadd in your App.tsx\n\n\u003e 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.\n\n\n```tsx\nimport {ModalPortal} from \"@acrool/react-modal\";\n\nconst App = () =\u003e {\n    return (\n        \u003cdiv\u003e\n            \u003cBaseUsed/\u003e\n            \u003cModalPortal/\u003e\n        \u003c/div\u003e\n    );\n};\n```\n\n- Here are two ways to use it\n  - [A. Custom modal component](#a-custom-modal-component)\n  - [B. Custom state modal component](#b-custom-state-modal-component)\n\n\n## A. Custom modal component\n\nAdd the lightbox to the display column list by throwing the Show method\n\n***Defined Modal***\n\n```tsx\nimport {animation, createModal, IModalOptions, useModal} from '@acrool/react-modal';\n\ninterface IProps {\n    myVar: string\n}\n\nconst PromotionModal = (args: IProps) =\u003e {\n    const {hide} = useModal();\n\n    return \u003cdiv\u003e\n        \u003cdiv\u003eTest2 content\u003c/div\u003e\n        \u003cbutton type=\"button\" onClick={hide}\u003eX \u003c/button\u003e\n    \u003c/div\u003e;\n}\n\nexport default createModal(\n    PromotionModal,\n    animation.generateFadeInFromTop(),\n);\n```\n\n***Use Modal***\n\nthen in your page\n\n```tsx\nconst ExamplePage = () =\u003e {\n    return \u003cdiv\u003e\n        \u003cbutton type=\"button\" onClick={() =\u003e PromotionModal.show({myVar: 'Imageine'})}\u003eShow Modal\u003c/button\u003e\n    \u003c/div\u003e\n}\n```\n\n\n\n\n\n\n\n\n\n## B. Custom state modal component\n\nThe inside of the light box is controlled by its own state, which is displayed through rendering, such as using HashRouter.\n\n***Defined Modal***\n\n```tsx\nimport {animation, createStateModal, IModalOptions, useModal} from '@acrool/react-modal';\nimport {useHashParams} from '@acrool/react-router-hash';\n\n\nconst PromotionHashModal = () =\u003e {\n      const {hide} = useModal();\n      const navigate = useNavigate();\n      const {id} = useHashParams\u003c{id: string}\u003e();\n\n      useEffect(() =\u003e {\n        return () =\u003e {\n          navigate({...location, hash: undefined});\n        };\n      }, []);\n\n      const handleOnHide = () =\u003e {\n        hide();\n      };\n      \n      // const handleOnClose = () =\u003e {\n      //     hide().then(() =\u003e {\n      //         navigate({hash: undefined});\n      //     })\n      // }\n\n  return \u003cdiv\u003e\n          \u003cdiv\u003eTest2 content\u003c/div\u003e\n          \u003cbutton type=\"button\" onClick={handleOnClose}\u003eClose Modal\u003c/button\u003e\n      \u003c/div\u003e;\n}\n\nexport default createStateModal(\n    PromotionHashModal,\n    {\n      ...animation.generateFadeInFromTop(),\n      isHideWithMaskClick: true,\n    },\n);\n```\n\n\n***Defined Hash Route***\n\n\u003e 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.\n\n```tsx\nimport {HashRoute,HashRoutes} from '@acrool/react-router-hash';\nimport {createBrowserHistory} from 'history';\nimport {BrowserRouter as Router,Route, Routes} from 'react-router-dom';\n\nconst history = createBrowserHistory({window});\n\nconst RouterSetting = () =\u003e {\n    return \u003cRouter\u003e\n\n        \u003cRoutes\u003e\n            \u003cRoute path=\"/\" element={\u003cExample/\u003e} /\u003e\n        \u003c/Routes\u003e\n\n        \u003cHashRoutes\u003e\n            \u003cHashRoute path=\"promotion/:id\" element={\u003cPromotionHashModal/\u003e}/\u003e\n        \u003c/HashRoutes\u003e\n\n        {/* Add this */}\n        \u003cModalPortal/\u003e\n\n    \u003c/Router\u003e;\n};\n```\n\n\n\n***Use Modal***\n\nthen in your page\n\n```tsx\nimport {useNavigate} from 'react-router-dom';\n\nconst ExamplePage = () =\u003e {\n    const navigate = useNavigate();\n    return \u003cdiv\u003e\n        \u003cbutton type=\"button\" onClick={() =\u003e navigate({hash: '/promotion/1'})}\u003eShow Modal\u003c/button\u003e\n        \u003cbutton type=\"button\" onClick={() =\u003e navigate({hash: '/promotion/2'})}\u003eShow Modal\u003c/button\u003e\n    \u003c/div\u003e\n}\n```\n\n\n\n- 😁 [Animation Sample](src/animation.ts)\n  - fadeInDown: (default), ex Base modal style\n  - zoomInDown\n  - slideInLeft: ex Drawer slider\n  - slideInRight: ex Drawer slider\n  - slideInUp: ex Dropdown\n  - custom (ref; https://www.framer.com/motion/animate-presence/#usage)\n   ```tsx\n  variants = {\n     initial: {opacity: 0, y: -20, transition: {type:'spring'}},\n     animate: {opacity: 1, y: 0},\n     exit: {opacity: 0, y: -40}\n  }\n  ```\n\n\nThere is also a example that you can play with it:\n\n[![Play react-editext-example](https://raw.githubusercontent.com/acrool/acrool-react-modal/main/play-in-example-button.svg)](https://acrool-react-modal.pages.dev)\n\n\n## License\n\nMIT © [Acrool](https://github.com/acrool) \u0026 [Imagine](https://github.com/imagine10255)\n\n\n## Refer to\n\n- [https://github.com/ebay/nice-modal-react](https://github.com/ebay/nice-modal-react)\n- [https://animate.style](https://animate.style)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facrool%2Facrool-react-modal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facrool%2Facrool-react-modal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facrool%2Facrool-react-modal/lists"}