{"id":16791340,"url":"https://github.com/jsun969/react-hook-dialog","last_synced_at":"2025-03-17T03:30:35.210Z","repository":{"id":45782049,"uuid":"513118718","full_name":"jsun969/react-hook-dialog","owner":"jsun969","description":"💬 React hooks for master your dialog(modal) component","archived":false,"fork":false,"pushed_at":"2023-03-03T18:03:51.000Z","size":286,"stargazers_count":49,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-14T08:34:36.526Z","etag":null,"topics":["dialog","hook","modal","popup","react","react-hooks"],"latest_commit_sha":null,"homepage":"https://npm.im/react-hook-dialog","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/jsun969.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-12T11:41:22.000Z","updated_at":"2024-03-13T15:26:02.000Z","dependencies_parsed_at":"2024-06-21T05:56:24.697Z","dependency_job_id":null,"html_url":"https://github.com/jsun969/react-hook-dialog","commit_stats":{"total_commits":89,"total_committers":1,"mean_commits":89.0,"dds":0.0,"last_synced_commit":"cccf8e522b35cea580da7d426e40ec45eb513758"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsun969%2Freact-hook-dialog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsun969%2Freact-hook-dialog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsun969%2Freact-hook-dialog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsun969%2Freact-hook-dialog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsun969","download_url":"https://codeload.github.com/jsun969/react-hook-dialog/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221671268,"owners_count":16861227,"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","hook","modal","popup","react","react-hooks"],"created_at":"2024-10-13T08:34:36.490Z","updated_at":"2024-10-27T11:50:46.977Z","avatar_url":"https://github.com/jsun969.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# 💬 React Hook Dialog\n\nReact hooks for master your dialog(modal) component\n\n[![version](https://img.shields.io/npm/v/react-hook-dialog?style=for-the-badge)](https://www.npmjs.com/package/react-hook-dialog)\n[![license](https://img.shields.io/npm/l/react-hook-dialog?style=for-the-badge)](https://github.com/jsun969/react-hook-dialog/blob/main/LICENSE)\n[![size](https://img.shields.io/bundlephobia/minzip/react-hook-dialog?style=for-the-badge)](https://bundlephobia.com/result?p=react-hook-dialog)\n\nEnglish | [简体中文](./README_zh-CN.md)\n\n\u003c/div\u003e\n\n## ✨ Features\n\n- 🧙‍♂️ TYPE SAFE\n- 🐎 Awesome DX\n- 🍃 Super light\n\n## 🕶 Example\n\n- [Material UI](https://codesandbox.io/s/rhd-mui-example-etwz20)\n- [Ant Design](https://codesandbox.io/s/rhd-antd-example-qhj7zy)\n\n## 📦 Installation\n\n```bash\nnpm install react-hook-dialog\n```\n\n## 🎯 Quickstart\n\n`lib/dialog.ts`\n\n```tsx\nimport { createDialogs, createDialogHooks } from 'react-hook-dialog';\n\nexport const dialogs = createDialogs({\n  customDialog: { title: '', content: '' },\n});\n\nexport const dialog = createDialogHooks(dialogs);\n```\n\n`components/CustomDialog.tsx`\n\n```tsx\nimport { Dialog } from 'your-ui-lib';\n\nimport { dialog } from '../lib/dialog';\n\nconst CustomDialog = () =\u003e {\n  const { isOpen, handleClose, props } =\n    dialog.useDialogController('customDialog');\n\n  return (\n    \u003cDialog open={isOpen} onClose={handleClose}\u003e\n      \u003ch3\u003e{props.title}\u003c/h3\u003e\n      \u003cp\u003e{props.content}\u003c/p\u003e\n    \u003c/Dialog\u003e\n  );\n};\n\nexport default CustomDialog;\n```\n\n`main.tsx`\n\n```tsx\nimport React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport { DialogProvider } from 'react-hook-dialog';\n\nimport App from './App';\nimport CustomDialog from './components/CustomDialog';\nimport { dialogs } from './lib/dialog';\n\nReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(\n  \u003cReact.StrictMode\u003e\n    \u003cDialogProvider dialogs={dialogs}\u003e\n      \u003cApp /\u003e\n      \u003cCustomDialog /\u003e\n    \u003c/DialogProvider\u003e\n  \u003c/React.StrictMode\u003e,\n);\n```\n\n`anywhere`\n\n```tsx\nimport { dialog } from 'dir to lib/dialog';\n\nconst YourComponent = () =\u003e {\n  const { open, close, isOpen } = dialog.useDialog('customDialog', {\n    title: 'Some Title',\n    content: 'some content',\n  });\n\n  return (\n    \u003c\u003e\n      \u003cdiv\u003eDialog Status: {isOpen ? 'open' : 'closed'}\u003c/div\u003e\n      \u003cbutton onClick={() =\u003e open()}\u003eOpen Dialog\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e close()}\u003eClose Dialog\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e open({ title: 'Another Title' })}\u003e\n        Open Another Dialog\n        {/* { title: 'Another Title', content: 'some content' } */}\n      \u003c/button\u003e\n    \u003c/\u003e\n  );\n};\n\nexport default YourComponent;\n```\n\n## 🕹 API\n\n### 🔗 `createDialogs`\n\nInitialize your dialogs name and props\n\n```ts\nconst dialogs = createDialogs({\n  firstDialogName: {\n    title: '',\n    content: '',\n  },\n  secondDialogName: {\n    lol: '',\n    olo: '',\n  },\n});\n```\n\n### 🔗 `DialogProvider`\n\n```tsx\n\u003cDialogProvider dialogs={dialogs}\u003e\n  \u003cApp /\u003e\n  \u003cFirstDialog /\u003e\n  \u003cSecondDialog /\u003e\n\u003c/DialogProvider\u003e\n```\n\n### 🔗 `createDialogHooks`\n\nCreate type-safe dialog hooks\n\n```ts\nconst dialog = createDialogHooks(dialogs);\n```\n\n### 🔗 `useDialogController`\n\nA hook to control your dialog component\n\n```tsx\nconst { isOpen, handleClose, props } = dialog.useDialogController('dialogName');\n\nreturn \u003cDialog open={isOpen} onClose={handleClose} {...props}\u003e\n```\n\n### 🔗 `useDialog`\n\nA hook to use any dialogs anywhere!\n\n\u003e **Note**  \n\u003e You may have found that the dialog props can be defined in 3 places  \n\u003e Priority: `open` \u003e `useDialog` \u003e `createDialogs`\n\n```tsx\nconst { open, close, isOpen } = dialog.useDialog(\n  'dialogName',\n  { title: 'New Title' }, // Dialog props\n);\n```\n\n```tsx\n\u003c\u003e\n  \u003cdiv\u003eDialog Status: {isOpen ? 'open' : 'closed'}\u003c/div\u003e\n  \u003cbutton onClick={() =\u003e open({ title: 'New New Title' })}\u003eOpen\u003c/button\u003e\n  \u003cbutton onClick={() =\u003e close()}\u003eClose\u003c/button\u003e\n\u003c/\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsun969%2Freact-hook-dialog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsun969%2Freact-hook-dialog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsun969%2Freact-hook-dialog/lists"}