{"id":13450314,"url":"https://github.com/upmostly/modali","last_synced_at":"2025-04-05T21:07:06.650Z","repository":{"id":34530300,"uuid":"179479002","full_name":"upmostly/modali","owner":"upmostly","description":"A delightful modal dialog component for React, built from the ground up to support React Hooks.","archived":false,"fork":false,"pushed_at":"2022-12-09T18:41:20.000Z","size":925,"stargazers_count":214,"open_issues_count":42,"forks_count":21,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T20:08:14.197Z","etag":null,"topics":["dialog","modal","react","react-components","react-modal","reacthooks","reactjs","reactmodal"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/upmostly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-04T10:50:27.000Z","updated_at":"2024-10-15T17:12:24.000Z","dependencies_parsed_at":"2023-01-15T07:36:25.600Z","dependency_job_id":null,"html_url":"https://github.com/upmostly/modali","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upmostly%2Fmodali","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upmostly%2Fmodali/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upmostly%2Fmodali/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upmostly%2Fmodali/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/upmostly","download_url":"https://codeload.github.com/upmostly/modali/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399874,"owners_count":20932876,"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":["dialog","modal","react","react-components","react-modal","reacthooks","reactjs","reactmodal"],"created_at":"2024-07-31T07:00:33.541Z","updated_at":"2025-04-05T21:07:06.630Z","avatar_url":"https://github.com/upmostly.png","language":"JavaScript","readme":"# 🦞 modali\nA delightful modal dialog library for React, built from the ground up to support React Hooks. Modali provides a simple interface to build beautiful modals in minutes.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"../assets/modali-logo.png\" alt=\"drawing\" width=\"400\"/\u003e\n\u003c/p\u003e\n\nA full tutorial on [Modal Components in React Using Custom Hooks](https://upmostly.com/tutorials/modal-components-react-custom-hooks/) can be found over at https://upmostly.com\n\n## Live Demo\n\nhttps://upmostly.github.io/modali/\n\n## Installation\nInstall Modali in your project using npm:\n\n```\nnpm install --save modali\n```\n\n**⚠️ Modali uses React Hooks, therefore you are required to use React v16.8 or above when using Modali.**\n\n## Usage\n\nImport the `Modali` component and `useModali` Hook in your React components, like so:\n```javascript\nimport Modali, { useModali } from 'modali';\n```\n\nAfter you've imported the Modali component and useModali Hook, you're ready to start using Modali inside your components! 🎉\n\n### Basic Modal\n\n```jsx\nimport React from 'react';\nimport Modali, { useModali } from 'modali';\n\nconst App = () =\u003e {\n  const [exampleModal, toggleExampleModal] = useModali();\n\n  return (\n    \u003cdiv className=\"app\"\u003e\n      \u003cbutton onClick={toggleExampleModal}\u003e\n        Click me to open the modal\n      \u003c/button\u003e\n      \u003cModali.Modal {...exampleModal}\u003e\n        Hi, I'm a Modali!\n      \u003c/Modali.Modal\u003e\n    \u003c/div\u003e\n  );\n};\n\nexport default App;\n\n```\n\n### Title, Message, and Buttons\n\nModali provides everything you need to build beautiful modals in minutes. Use the title, message and buttons props to customize your modal as quick as a flash! ⚡️\n\n```jsx\nimport React from 'react';\nimport Modali, { useModali } from 'modali';\n\nconst App = () =\u003e {\n  const [completeExample, toggleCompleteModal] = useModali({\n    animated: true,\n    title: 'Are you sure?',\n    message: 'Deleting this user will be permanent.',\n    buttons: [\n      \u003cModali.Button\n        label=\"Cancel\"\n        isStyleCancel\n        onClick={() =\u003e toggleCompleteModal()}\n      /\u003e,\n      \u003cModali.Button\n        label=\"Delete\"\n        isStyleDestructive\n        onClick={() =\u003e deleteUserWithId('123')}\n      /\u003e,\n    ],\n  });\n\n  return (\n    \u003cdiv className=\"app\"\u003e\n      \u003cbutton onClick={toggleCompleteModal}\u003e\n        Click me to open the modal\n      \u003c/button\u003e\n      \u003cModali.Modal {...completeExample} /\u003e\n    \u003c/div\u003e\n  );\n};\n\nexport default App;\n\n```\n\n### useModali Hook\n\nMuch like the useState Hook, the `useModali` Hook returns two values which can be named whatever you'd like:\n\n- An object containing props which must be passed into the Modali component.\n- A function to toggle the Modali component.\n\nThis is demonstrated in the example above, from the following line:\n\u003cbr /\u003e\n`const [exampleModal, toggleExampleModal] = useModali();`\n- `exampleModal` is the props object. Again, this must be passed into the Modali component.\n- `toggleExampleModal` is the function to show/hide Modali.\n\n### \u003cModali.Modal /\u003e Component\n\nThe `\u003cModali.Modal /\u003e` component provides a beautiful, WAI-ARIA accessible modal dialog out of the box. Import it, add it to your component tree, pass in the props object that you get from the useModali Hook and you're all set.\n\n```jsx\n...\n\nconst [exampleModal, toggleExampleModal] = useModali();\n\nreturn (\n  \u003cModali.Modal {...exampleModal}\u003e\n    Hi, I'm a Modali\n  \u003c/Modali.Modal\u003e\n);\n\n...\n\n```\n\n### \u003cModali.Button /\u003e Component\n\nThe `\u003cModali.Button /\u003e` component provides a ready-to-go button component that includes three separate styles of button: default, cancel, and destructive.\n\n```jsx\n...\n\nconst [completeExample, toggleCompleteModal] = useModali({\n  buttons: [\n    \u003cModali.Button\n      label=\"Done\"\n      isStyleDefault\n      onClick={() =\u003e handleDoneClicked()}\n    /\u003e,\n    \u003cModali.Button\n      label=\"Cancel\"\n      isStyleCancel\n      onClick={() =\u003e toggleCompleteModal()}\n    /\u003e,\n    \u003cModali.Button\n      label=\"Delete\"\n      isStyleDestructive\n      onClick={() =\u003e deleteUserWithId('123')}\n    /\u003e,\n  ],\n});\n\nreturn (\n  \u003cModali.Modal {...exampleModal}\u003e\n    Hi, I'm a Modali\n  \u003c/Modali.Modal\u003e\n);\n\n...\n\n```\n### \u003cModali.Button/\u003e Props\n| Prop | Description |\n| --- | --- |\n| `label` | String that is shown on the button |\n| `isStyleDefault` | Pass in this prop as true to show the default button |\n| `isStyleCancel` | Pass in this prop as true to show a cancel button |\n| `isStyleDestructive` | Pass in this prop as true to show a delete button |\n| `onClick` | Called when the button is clicked |\n\n## More Examples\n\n### Multiple Modals\nThis flexibility of being able to name the props object and toggle function allows us to use multiple Modalis in the same component:\n\n```jsx\nimport React from 'react';\nimport Modali, { useModali } from 'modali';\n\nconst App = () =\u003e {\n  const [firstModal, toggleFirstModal] = useModali();\n  const [secondModal, toggleSecondModal] = useModali();\n  \n  return (\n    \u003cdiv className=\"app\"\u003e\n      \u003cbutton onClick={toggleFirstModal}\u003e\n        Click me to open the first modal!\n      \u003c/button\u003e\n      \u003cbutton onClick={toggleSecondModal}\u003e\n        Click me to open the second modal!\n      \u003c/button\u003e\n      \u003cModali.Modal {...firstModal}\u003e\n        Hi, I'm the first Modali\n      \u003c/Modali.Modal\u003e\n      \u003cModali.Modal {...secondModal}\u003e\n        And I'm the second Modali\n      \u003c/Modali.Modal\u003e\n    \u003c/div\u003e\n  );\n};\n\nexport default App;\n\n```\n\n## Modali Options\n\nModali provides an easy to use interface for accessing useful events, such as when the modal shows and hides.\n\n### Events\n\n| Event | Description |\n| --- | --- |\n| `onShow` | Called when the component finishes mounting to the DOM |\n| `onHide` | Called when the component is removed from the DOM |\n| `onEscapeKeyDown` | Called when the escape key is pressed while the component is mounted to the DOM |\n| `onOverlayClicked` | Called when the modal overlay back is clicked while the component is mounted to the DOM |\n\nExample\n\n```javascript\nconst [exampleModal, toggleExampleModal] = useModali({\n  onShow: () =\u003e console.log('Modali is shown'),\n  onHide: () =\u003e console.log('Modali is hidden')\n});\n\n```\n\nModali can be easily customized by passing in an object of key/value pairs to the useModali Hook's initializer:\n\n### Props\n\n| Option | Default Value | Description |\n| --- | --- | --- |\n| `title` | string | The text displayed in the upper left corner |\n| `message` | string | The text displayed in the body of the modal |\n| `buttons` | array | Displays whatever is passed in in the footer |\n| `closeButton` | true | Controls the visibility of the close button |\n| `animated` | false | Fades in the modal when it mounts to the DOM |\n| `centered` | false | Positions the modal in the center of the screen |\n| `large` | false | Changes the size of the modal to be 800px wide |\n| `overlayClose` | true | Disables clicking the modal overlay to hide it |\n| `keyboardClose` | true | Disables the ESC key hiding the modal |\n\nExample\n\n```javascript\nconst [exampleModal, toggleExampleModal] = useModali({\n  animated: true,\n  large: true,\n  closeButton: false,\n});\n\n```\n\nOf course, props and events can be combined when passing the options to the useModali Hook:\n\n```javascript\n\nfunction handleModalOnHide() {\n  // do something when the modal hides\n}\n\nconst [exampleModal, toggleExampleModal] = useModali({\n  onHide: handleModalOnHide,\n  large: true,\n  closeButton: false,\n});\n\n```\n","funding_links":[],"categories":["Packages","UI Components"],"sub_categories":["Overlay"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupmostly%2Fmodali","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fupmostly%2Fmodali","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupmostly%2Fmodali/lists"}