Gathering detailed insights and metrics for next-modal
Gathering detailed insights and metrics for next-modal
Gathering detailed insights and metrics for next-modal
Gathering detailed insights and metrics for next-modal
@nextui-org/modal
Displays a dialog with a custom content that requires attention or provides additional information.
@faceless-ui/modal
America's next top modal
vf-modal
  
Shell (3.03%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Stars
27 Commits
1 Watchers
1 Branches
2 Contributors
Updated on Jul 22, 2022
Latest Version
1.3.2
Package Id
next-modal@1.3.2
Unpacked Size
24.86 kB
Size
7.17 kB
File Count
5
NPM Version
8.15.0
Node Version
16.16.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
20
This is a sustainable React modal component project based on greenCSS, which works with plain React, as well as with SSR - such as Next.js. Animations and the basic design were realised with greenCSS. greenCSS is an animated, responsive, lightweight and sustainable CSS library. It is recommended that you also use greenCSS in your project. If you don't want to, just style your modal with your own classes.
fade-in animation-duration-500ms animation-forwards
. If you want to animate the Modal.Header
or Modal.Body
, just add your greenCSS or your custom animation as a class to the className
. Here can find all greenCSS animations. p.e. <Modal.Body className='clip-circle-in-left animation-duration-800ms animation-forwards'>
closeIcon
with your own (svg-) component. <Modal toggle={toggleModal} setToggle={setToggleModal} closeIcon={<div>X</div>}>
The recommended size for an svg is 20x20px.prefers-reduced-motion: reduce
First, install the Modal dependency:
1npm i next-modal
In the pages directory, add _document.js
. It is important to add <div id='modal-portal' />
below the <Main />
component. Otherwise your SSR Modal will not work. Learn more about the custom document.
1// pages/_document.js 2import Document, { Html, Head, Main, NextScript } from 'next/document' 3 4class MyDocument extends Document { 5 static async getInitialProps(ctx) { 6 const initialProps = await Document.getInitialProps(ctx) 7 return { ...initialProps } 8 } 9 10 render() { 11 return ( 12 <Html> 13 <Head /> 14 <body> 15 <Main /> 16 <div id='modal-portal' /> 17 <NextScript /> 18 </body> 19 </Html> 20 ) 21 } 22} 23export default MyDocument
The following jsx file below is based on greenCSS. If you don't want to use it, you can add your own classNames
.
1import React, { useState } from 'react' 2import { Modal } from 'next-modal' 3 4export default function Home() { 5 const [toggleModal, setToggleModal] = useState(false) 6 return ( 7 <div className='min-h-100vh bg-gray-9'> 8 {/* Modal Toggle Button */} 9 <button onClick={() => setToggleModal((prev) => !prev)} className='bg-red-9 px-20px py-10px rounded-10px hover:bg-red-7'> 10 Toggle Modal 11 </button> 12 13 {/* Modal */} 14 <Modal toggle={toggleModal} setToggle={setToggleModal}> 15 <Modal.Header className='sans font-900 text-30px fade-in-left animation-duration-500ms animation-forwards'> 16 <h3>👋 Hi, I'm your modal</h3> 17 </Modal.Header> 18 <Modal.Body className='sans font-400 text-15px text-gray fade-in animation-duration-800ms animation-forwards'> 19 <p> 20 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna 21 aliqua. Viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor. Quis vel eros donec ac. Mauris 22 pellentesque pulvinar pellentesque habitant morbi tristique senectus. 23 </p> 24 <p> 25 Nunc non blandit massa enim nec dui nunc. Sed elementum tempus egestas sed sed risus. Senectus et netus et malesuada 26 fames ac turpis egestas maecenas. Urna nec tincidunt praesent semper feugiat. Est ante in nibh mauris cursus mattis 27 molestie. Vel elit scelerisque mauris pellentesque pulvinar pellentesque habitant. 28 </p> 29 </Modal.Body> 30 <Modal.Footer className='sans font-400 text-10px'> 31 <h3>copyright</h3> 32 </Modal.Footer> 33 </Modal> 34 </div> 35 ) 36}
Do you want to use your style within the modal? No problem - you can add any JSX inside.
1import React, { useState } from 'react' 2import { Modal } from 'next-modal' 3 4export default function Home() { 5 const [toggleModal, setToggleModal] = useState(false) 6 return ( 7 <div className='min-h-100vh bg-gray-9'> 8 {/* Modal Toggle Button */} 9 <button onClick={() => setToggleModal((prev) => !prev)} className='bg-red-9 px-20px py-10px rounded-10px hover:bg-red-7'> 10 Toggle Modal 11 </button> 12 13 {/* Modal */} 14 <Modal toggle={toggleModal} setToggle={setToggleModal}> 15 <h3>👋 Hi, I'm your independent modal</h3> 16 <p> 17 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna 18 aliqua. Viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor. Quis vel eros donec ac. Mauris pellentesque 19 pulvinar pellentesque habitant morbi tristique senectus. 20 </p> 21 </Modal> 22 </div> 23 ) 24}
You can also use next-modal in your create-react-app. Head to your public/index.html
file and add <div id="modal-portal" />
below the <div id="root"></div>
.
1<!DOCTYPE html> 2<html lang="en"> 3 <head> 4 <meta charset="utf-8" /> 5 <link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> 6 <meta name="viewport" content="width=device-width, initial-scale=1" /> 7 <meta name="theme-color" content="#000000" /> 8 <meta name="description" content="Web site created using create-react-app" /> 9 <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> 10 <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> 11 <title>React App</title> 12 </head> 13 <body> 14 <noscript>You need to enable JavaScript to run this app.</noscript> 15 <div id="root"></div> 16 <div id="modal-portal" /> 17 </body> 18</html>
Within a page or a component, you can now add and use the Modal.
1import React, { useState } from 'react' 2import { Modal } from 'next-modal' 3 4function App() { 5 const [toggleModal, setToggleModal] = useState(false) 6 return ( 7 <div className='App'> 8 {/* Modal Toggle Button */} 9 <button onClick={() => setToggleModal((prev) => !prev)} className='bg-red-9 px-20px py-10px rounded-10px hover:bg-red-7'> 10 Toggle Modal 11 </button> 12 13 {/* Modal */} 14 <Modal toggle={toggleModal} setToggle={setToggleModal}> 15 <Modal.Header className='sans font-900 text-30px fade-in-left animation-duration-500ms animation-forwards'> 16 <h3>👋 Hi, I'm your modal</h3> 17 </Modal.Header> 18 <Modal.Body className='sans font-400 text-15px text-gray fade-in animation-duration-800ms animation-forwards'> 19 <p> 20 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna 21 aliqua. Viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor. Quis vel eros donec ac. Mauris 22 pellentesque pulvinar pellentesque habitant morbi tristique senectus. 23 </p> 24 </Modal.Body> 25 <Modal.Footer className='sans font-400 text-10px'> 26 <h3>copyright</h3> 27 </Modal.Footer> 28 </Modal> 29 </div> 30 ) 31} 32 33export default App
Name | Default Value | Description |
---|---|---|
toggle | - | useState toggle state |
setToggle | - | useState toggle setToggle |
className | "" | Use your own className to style the modal content |
backgroundAnimation | 'fade-in animation-duration-500ms animation-forwards' | Add your custom animation className in order to overwrite the default fade in animation for the background |
modalContentAnimation | 'fade-in animation-duration-500ms animation-forwards' | Add your custom animation className in order to overwrite the default fade in animation for the modal content component |
closeIcon | <CloseIcon /> | Add your own close icon on the top right, may be an svg or your custom component |
useKeyInput | true | Use the default key inputs "CTRL + k" to open the modal and "ESC" to close the modal |
<Modal> | <Modal>{children}</Modal> | This is the Modal component. Add your own child element(s) or use the <Modal.Header> and <Modal.Body> inside. |
<Modal.Header> | <Modal.Header>{children}</Modal.Header> | Add a header text |
<Modal.Body> | <Modal.Body>{children}</Modal.Body> | Add body elements |
<Modal.Footer> | <Modal.Footer>{children}</Modal.Footer> | Add footer elements |
We use semantic versioning for commit messages.
For commit messages, use semantig writing:
Commit | Usage | Version |
---|---|---|
fix(your-change): a small change, maybe just a fix | Fix Release | v.0.0.1 |
feat(your-change): a new feature, a medium change | Feature Release | v.0.1.0 |
perf(your-change): a breaking change or hotfix | Breaking Release | v.1.0.0 |
No vulnerabilities found.
No security vulnerabilities found.