|
1 | | -# @rc-component/dialog |
| 1 | +<div align="center"> |
| 2 | + <h1>@rc-component/dialog</h1> |
| 3 | + <p>💬 A composable dialog component for React.</p> |
2 | 4 |
|
3 | | -react dialog component. |
| 5 | + <a href="https://ant.design"> |
| 6 | + <img width="32" height="32" src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg" alt="Ant Design" /> |
| 7 | + </a> |
| 8 | + |
| 9 | + <p>Part of the Ant Design ecosystem.</p> |
4 | 10 |
|
5 | 11 | [![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url] [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![bundle size][bundlephobia-image]][bundlephobia-url] [![dumi][dumi-image]][dumi-url] |
6 | 12 |
|
| 13 | +</div> |
| 14 | + |
7 | 15 | [npm-image]: https://img.shields.io/npm/v/@rc-component/dialog.svg?style=flat-square |
8 | 16 | [npm-url]: https://npmjs.org/package/@rc-component/dialog |
9 | | -[travis-image]: https://img.shields.io/travis/react-component/dialog/master?style=flat-square |
10 | | -[travis-url]: https://travis-ci.com/react-component/dialog |
11 | 17 | [github-actions-image]: https://github.com/react-component/dialog/actions/workflows/react-component-ci.yml/badge.svg |
12 | 18 | [github-actions-url]: https://github.com/react-component/dialog/actions/workflows/react-component-ci.yml |
13 | 19 | [codecov-image]: https://img.shields.io/codecov/c/github/react-component/dialog/master.svg?style=flat-square |
14 | 20 | [codecov-url]: https://app.codecov.io/gh/react-component/dialog |
15 | | -[david-url]: https://david-dm.org/react-component/dialog |
16 | | -[david-image]: https://david-dm.org/react-component/dialog/status.svg?style=flat-square |
17 | | -[david-dev-url]: https://david-dm.org/react-component/dialog?type=dev |
18 | | -[david-dev-image]: https://david-dm.org/react-component/dialog/dev-status.svg?style=flat-square |
19 | 21 | [download-image]: https://img.shields.io/npm/dm/@rc-component/dialog.svg?style=flat-square |
20 | 22 | [download-url]: https://npmjs.org/package/@rc-component/dialog |
| 23 | +[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/%40rc-component%2Fdialog?style=flat-square |
21 | 24 | [bundlephobia-url]: https://bundlephobia.com/package/@rc-component/dialog |
22 | | -[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/dialog |
23 | | -[dumi-url]: https://github.com/umijs/dumi |
24 | 25 | [dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square |
| 26 | +[dumi-url]: https://github.com/umijs/dumi |
25 | 27 |
|
| 28 | +## Highlights |
26 | 29 |
|
27 | | -## Screenshot |
28 | | - |
29 | | -<img src="http://gtms04.alicdn.com/tps/i4/TB1dp5lHXXXXXbmXpXXyVug.FXX-664-480.png" /> |
30 | | - |
31 | | -## Example |
32 | | - |
33 | | -http://localhost:8007/examples/ |
34 | | - |
35 | | -online example: https://dialog.react-component.vercel.app/ |
| 30 | +- Supports controlled visibility, mask, keyboard close, and focus restoration. |
| 31 | +- Allows custom title, footer, close icon, container, motion, and modal content rendering. |
| 32 | +- Provides semantic `classNames` and `styles` hooks for the dialog structure. |
| 33 | +- Ships compiled JavaScript, TypeScript definitions, and CSS assets. |
36 | 34 |
|
37 | 35 | ## Install |
38 | 36 |
|
39 | | -[](https://npmjs.org/package/@rc-component/dialog) |
| 37 | +```bash |
| 38 | +npm install @rc-component/dialog |
| 39 | +``` |
40 | 40 |
|
41 | 41 | ## Usage |
42 | 42 |
|
43 | | -```js |
44 | | -var Dialog = require('@rc-component/dialog'); |
| 43 | +```tsx | pure |
| 44 | +import Dialog from '@rc-component/dialog'; |
| 45 | +import '@rc-component/dialog/assets/index.css'; |
| 46 | + |
| 47 | +export default function App() { |
| 48 | + return ( |
| 49 | + <Dialog title="Dialog" visible onClose={() => {}}> |
| 50 | + <p>Dialog content</p> |
| 51 | + </Dialog> |
| 52 | + ); |
| 53 | +} |
| 54 | +``` |
45 | 55 |
|
46 | | -ReactDOM.render( |
47 | | - <Dialog title={title} onClose={callback1} visible> |
48 | | - <p>first dialog</p> |
49 | | - </Dialog> |
50 | | -), document.getElementById('t1')); |
| 56 | +## Examples |
51 | 57 |
|
52 | | -// use dialog |
| 58 | +```bash |
| 59 | +npm install |
| 60 | +npm start |
53 | 61 | ``` |
54 | 62 |
|
| 63 | +Then open `http://localhost:8000`. |
| 64 | + |
| 65 | +Online demo: https://dialog.react-component.vercel.app/ |
| 66 | + |
55 | 67 | ## API |
56 | 68 |
|
57 | | -### @rc-component/dialog |
58 | | - |
59 | | -| Name | Type | Default | Description | Version | |
60 | | -| --- | --- | --- | --- | --- | |
61 | | -| prefixCls | String | rc-dialog | The dialog dom node's prefixCls | | |
62 | | -| className | String | | additional className for dialog | | |
63 | | -| classNames | { header?: string; body?: string; footer?: string; mask?: string; content?: string; wrapper?: string; } | | pass className to target area | | |
64 | | -| styles | { header?: CSSProperties; body?: CSSProperties; footer?: CSSProperties; mask?: CSSProperties; content?: CSSProperties; wrapper?: CSSProperties; } | | pass styles to target area | | |
65 | | -| style | Object | {} | Root style for dialog element.Such as width, height | | |
66 | | -| zIndex | Number | | | | |
67 | | -| visible | Boolean | false | current dialog's visible status | | |
68 | | -| animation | String | | part of dialog animation css class name | | |
69 | | -| maskAnimation | String | | part of dialog's mask animation css class name | | |
70 | | -| transitionName | String | | dialog animation css class name | | |
71 | | -| maskTransitionName | String | | mask animation css class name | | |
72 | | -| title | String\|React.Element | | Title of the dialog | | |
73 | | -| footer | React.Element | | footer of the dialog | | |
74 | | -| closable | Boolean \| ({ closeIcon?: React.ReactNode; disabled?: boolean, afterClose:function } & React.AriaAttributes) | true | whether show close button | | |
75 | | -| mask | Boolean | true | whether show mask | | |
76 | | -| maskClosable | Boolean | true | whether click mask to close | | |
77 | | -| keyboard | Boolean | true | whether support press esc to close | | |
78 | | -| mousePosition | {x:number,y:number} | | set pageX and pageY of current mouse(it will cause transform origin to be set). | | |
79 | | -| onClose | function() | | called when click close button or mask | | |
80 | | -| afterClose | function() | | called when close animation end | | |
81 | | -| getContainer | function(): HTMLElement | | to determine where Dialog will be mounted | | |
82 | | -| destroyOnHidden | Boolean | false | to unmount child compenents on onClose | | |
83 | | -| closeIcon | ReactNode | | specific the close icon. | | |
84 | | -| forceRender | Boolean | false | Create dialog dom node before dialog first show | | |
85 | | -| focusTriggerAfterClose | Boolean | true | focus trigger element when dialog closed | | |
86 | | -| scrollLock | Boolean | true | Control whether to lock body scroll when dialog opens | | |
87 | | -| modalRender | (node: ReactNode) => ReactNode | | Custom modal content render | 8.3.0 | |
| 69 | +| Property | Description | Type | Default | |
| 70 | +| --- | --- | --- | --- | |
| 71 | +| afterClose | Callback after close animation ends | `() => void` | - | |
| 72 | +| animation | Dialog animation name | string | - | |
| 73 | +| className | Additional dialog class name | string | - | |
| 74 | +| classNames | Semantic class names | `{ header?: string; body?: string; footer?: string; mask?: string; content?: string; wrapper?: string }` | - | |
| 75 | +| closable | Whether to show close button, or close button props | boolean \| object | true | |
| 76 | +| closeIcon | Custom close icon | `React.ReactNode` | - | |
| 77 | +| destroyOnHidden | Unmount children after dialog closes | boolean | false | |
| 78 | +| focusTriggerAfterClose | Focus trigger element after close | boolean | true | |
| 79 | +| footer | Dialog footer | `React.ReactNode` | - | |
| 80 | +| forceRender | Render dialog before it is first shown | boolean | false | |
| 81 | +| getContainer | Container where dialog is mounted | `() => HTMLElement` | - | |
| 82 | +| keyboard | Whether pressing Esc closes the dialog | boolean | true | |
| 83 | +| mask | Whether to show mask | boolean | true | |
| 84 | +| maskAnimation | Mask animation name | string | - | |
| 85 | +| maskClosable | Whether clicking mask closes the dialog | boolean | true | |
| 86 | +| maskTransitionName | Mask transition class name | string | - | |
| 87 | +| modalRender | Custom modal content renderer | `(node: React.ReactNode) => React.ReactNode` | - | |
| 88 | +| mousePosition | Mouse position used for transform origin | `{ x: number; y: number }` | - | |
| 89 | +| prefixCls | Component class name prefix | string | `rc-dialog` | |
| 90 | +| scrollLock | Whether to lock body scroll when open | boolean | true | |
| 91 | +| style | Root dialog style | `React.CSSProperties` | - | |
| 92 | +| styles | Semantic styles | `{ header?: CSSProperties; body?: CSSProperties; footer?: CSSProperties; mask?: CSSProperties; content?: CSSProperties; wrapper?: CSSProperties }` | - | |
| 93 | +| title | Dialog title | `React.ReactNode` | - | |
| 94 | +| transitionName | Dialog transition class name | string | - | |
| 95 | +| visible | Whether the dialog is visible | boolean | false | |
| 96 | +| zIndex | Dialog z-index | number | - | |
| 97 | +| onClose | Callback when close button or mask is clicked | `(event: React.SyntheticEvent) => void` | - | |
88 | 98 |
|
89 | 99 | ## Development |
90 | 100 |
|
91 | | -``` |
| 101 | +```bash |
92 | 102 | npm install |
93 | 103 | npm start |
94 | 104 | ``` |
95 | 105 |
|
96 | | -## Test Case |
97 | | - |
98 | | -``` |
| 106 | +```bash |
99 | 107 | npm test |
100 | | -npm run chrome-test |
| 108 | +npm run tsc |
| 109 | +npm run lint |
| 110 | +npm run compile |
| 111 | +npm run build |
101 | 112 | ``` |
102 | 113 |
|
103 | | -## Coverage |
| 114 | +## Release |
104 | 115 |
|
105 | | -``` |
106 | | -npm run coverage |
| 116 | +```bash |
| 117 | +npm run prepublishOnly |
107 | 118 | ``` |
108 | 119 |
|
109 | | -open coverage/ dir |
| 120 | +The release script compiles the package and runs `rc-np`. |
110 | 121 |
|
111 | 122 | ## License |
112 | 123 |
|
113 | | -@rc-component/dialog is released under the MIT license. |
114 | | - |
115 | | - |
116 | | -## 🤝 Contributing |
117 | | - |
118 | | -<a href="https://openomy.app/github/react-component/dialog" target="_blank" style="display: block; width: 100%;" align="center"> |
119 | | - <img src="https://www.openomy.app/svg?repo=react-component/dialog&chart=bubble&latestMonth=24" target="_blank" alt="Contribution Leaderboard" style="display: block; width: 100%;" /> |
120 | | -</a> |
| 124 | +`@rc-component/dialog` is released under the MIT license. |
0 commit comments