使用 我的应用 也是一种 支持 我的方式:
DockLift: 点击 Dock 应用窗口回到当前屏幕 Zipora: Zip/RAR/7Z 解压工具 Scap: Screenshot & Markup Edit Screen Test Deskmark Keyzer Vidwall Hub VidCrop Vidwall Mousio Hint Mousio Musicer Audioer FileSentinel FocusCursor Videoer KeyClicker DayBar Iconed Menuist Quick RSS Quick RSS Web Serve Copybook Generator DevTutor for SwiftUI RegexMate Time Passage Iconize Folder Textsound Saver Create Custom Symbols DevHub Resume Revise Palette Genius Symbol Scribe

Modal 模态对话框 === [![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor) [![Telegram Channel](https://img.shields.io/badge/%20-Telegram-00618f.svg?logo=Telegram)](https://t.me/s/AwesomeMacApps) [![Follow On X](https://img.shields.io/badge/Follow%20on%20X-333333?logo=x&logoColor=white)](https://x.com/jaywcjlove) [![Open in unpkg](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/@uiw/react-modal/file/README.md) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/react-modal.svg?style=flat)](https://www.npmjs.com/package/@uiw/react-modal) [![npm version](https://img.shields.io/npm/v/@uiw/react-modal.svg?label=@uiw/react-modal)](https://npmjs.com/@uiw/react-modal) 模态对话框。 ```jsx import { Modal } from 'uiw'; // or import Modal from '@uiw/react-modal'; ``` ### 基本用法 ```jsx mdx:preview&bg=#fff import React from 'react'; import { Modal, ButtonGroup, Button } from 'uiw'; class Demo extends React.Component { constructor() { super(); this.state = { visible: false, } } onClick() { this.setState({ visible: !this.state.visible }); } onClosed() { this.setState({ visible: false }); } render() { return (
console.log('您点击了确定按钮!')} onCancel={() => console.log('您点击了取消按钮!')} onClosed={this.onClosed.bind(this)} > React 可以非常轻松地创建用户交互界面。为你应用的每一个状态设计简洁的视图,在数据改变时 React 也可以高效地更新渲染界面。

以声明式编写UI,可以让你的代码更加可靠,且方便调试。

创建好拥有各自状态的组件,再由组件构成更加复杂的界面。

无需再用模版代码,通过使用JavaScript编写的组件你可以更好地传递数据,将应用状态和DOM拆分开来。

无论你现在正在使用什么技术栈,你都可以随时引入 React 开发新特性。

组件

React 组件使用一个名为 render() 的方法, 接收数据作为输入,输出页面中对应展示的内容。 下面这个示例中类似XML的写法被称为JSX. 输入的数据通过 this.props 传入 render() 方法。

使用 React 的时候也可以不使用 JSX 语法 你可以在 Babel REPL 查看 JSX 是如何被渲染成原生 JavaScript 代码的。
) } } export default Demo; ``` ### 延迟关闭对话框 这里是利用 `Promise` 等它执行完成再去关闭窗口 ```jsx mdx:preview&bg=#fff import React from 'react'; import { Modal, ButtonGroup, Button } from 'uiw'; class Demo extends React.Component { constructor() { super(); this.state = { visible: false, } this.time = null } onClick() { this.setState({ visible: !this.state.visible }); } onClosed() { this.setState({ visible: false }); } render() { return (
{ clearTimeout(this.time) console.log('您点击了取消按钮!') }} onClosed={this.onClosed.bind(this)} onConfirm={() => { console.log('确定回调!, 这里是利用Promise等执行完成再去关闭窗口'); return new Promise((resolve, reject) => { const random = Math.random(); console.log('测试,随机值大于 0.5 执行 resolve 事件,否则 执行 reject 触发 catch 错误', random, random > 0.5) this.time = setTimeout(random > 0.5 ? resolve : reject, 3000); }).catch(() => { // 可以通过下面方式,阻止弹框消失 // throw new Error(); }); }} > 这是一个单击 “确定按钮” 延迟关闭对话框的实例,关闭对话框触发 “onConfirm” 或 “onCancel” 事件。

这里是利用 Promise 的特性,等它执行完成后,再去关闭窗口,达到延迟关闭的效果。

这个测试例子,生成随机值判断是否大于 0.5 执行 resolve 事件,否则 执行 reject 触发 catch 错误。
) } } export default Demo; ``` ### 表单应用 这里是利用 `Promise` 等它执行完成再去关闭窗口 ```jsx mdx:preview&bg=#fff import React from 'react'; import { Modal, ButtonGroup, Button, Form, Input, Textarea, Notify, Row, Col } from 'uiw'; class Demo extends React.Component { constructor() { super(); this.state = { visible: false, loading: false, } } onClick() { this.setState({ visible: !this.state.visible }); } onClosed() { this.setState({ visible: false }); } onSubmit({ initial, current }) { const errorObj = {}; if (current.userName.startsWith('u')) { errorObj.userName = `姓名 ${current.userName} 不能以 ‘u’ 开头`; } if (!current.age || current.age < 18 || current.age > 30) { errorObj.age = '年龄必须在18 ~ 30岁之间。'; } if (!current.textarea) { errorObj.textarea = '请输入描述内容'; } if(Object.keys(errorObj).length > 0) { const err = new Error(); err.filed = errorObj; throw err; } this.setState({ loading: true }); setTimeout(() => { this.setState({ loading: false, visible: false }); Notify.success({ title: '提交成功通知!', description: '提交内容,。' }); }, 2000); } render() { return (
{ if (error.filed) { return { ...error.filed }; } return null; }} fields={{ userName: { initialValue: 'uiw', label: '姓名', help: '以“u”开头的名字将在此处显示错误信息', children: }, age: { initialValue: 9, label: '年龄', children: }, textarea: { initialValue: '', label: '描述说明', children: