diff --git a/packages/react-input/README.md b/packages/react-input/README.md index 852fcf1338..af4bda09e4 100644 --- a/packages/react-input/README.md +++ b/packages/react-input/README.md @@ -12,7 +12,7 @@ import Input from '@uiw/react-input'; ### 基础用法 -```js +```jsx import { Input } from 'uiw'; const Demo = () => ( @@ -24,10 +24,80 @@ ReactDOM.render(, _mount_); ``` +### Form 中使用 Input + + +```jsx +import { Form, Input, Row, Col, Button, Notify } from 'uiw'; + +const Demo = () => ( +
{ }} + onSubmitError={(error) => { + console.log('error:', error) + return error && error.filed ? { ...error.filed } : null; + }} + onSubmit={({initial, current}) => { + if (current.input && current.input.length > 3) { + Notify.success({ + title: '提交成功!', + description: `填写:【${current.input.toString()}】!` + }); + } else { + Notify.error({ title: '提交失败!', description: '必须长度超过 3 个字符!' }); + } + const ErrObj = {}; + if (current.input && current.input.length < 4) { + ErrObj.input = '😆 必须长度超过 3 个字符!'; + } + if(Object.keys(ErrObj).length > 0) { + const err = new Error(); + err.filed = ErrObj; + throw err; + } + }} + fields={{ + input: { + value: 'www', + label: '请输入内容', + help: '必须长度超过 3 个字符!', + validator: (value = '') => value.length < 4 ? '必填选项!' : null, + children: , + }, + }} + > + {({ fields, state, canSubmit }) => { + return ( +
+ + {fields.input} + + + + + + + + +
+                {JSON.stringify(state.current, null, 2)}
+              
+ +
+
+ ); + }} +
+); + +ReactDOM.render(, _mount_); +``` + + ### 插入图标 -```js +```jsx import { Input, Row, Col } from 'uiw'; const stylItem = { margin: 20 }; @@ -58,7 +128,7 @@ ReactDOM.render(, _mount_); 向后面插入 [`Button`](#/components/button) 或者 [`Tag`](#/components/tag) -```js +```jsx import { Input, Row, Col, Button, Tag } from 'uiw'; const Demo = () => ( @@ -99,11 +169,10 @@ ReactDOM.render(, _mount_); ``` - ### 输入框尺寸 -```js +```jsx import { Input, Row, Col, Tag, Button } from 'uiw'; const Demo = () => ( @@ -226,7 +295,6 @@ ReactDOM.render(, _mount_); ``` - ### 密码输入框