5.0.0-bate-6 • Published 3 years ago

@uiw/react-input v5.0.0-bate-6

Weekly downloads
324
License
MIT
Repository
github
Last release
3 years ago

Input 输入框

Open in unpkg NPM Downloads npm version

通过鼠标或键盘输入内容,是最基础的表单域的包装。

import { Input } from 'uiw';
// or
import Input from '@uiw/react-input';

基础用法

import React from 'react';
import { Input } from 'uiw';

const Demo = () => (
  <div>
    <Input placeholder="请输入内容" style={{ maxWidth: 200 }} />
  </div>
);
export default Demo

数字输入框

import React from 'react';
import { InputNumber,Row,Col, Icon, } from 'uiw';

const Demo = () => {

  return(
    <div>
      <Row gutter={10}>
        <Col fixed>
          <InputNumber
            placeholder="请输入内容"
            style={{ width: 200 }}
          />
        </Col>
        <Col fixed style={{ lineHeight: '30px' }}>限制大小</Col>
        <Col fixed>
          <InputNumber
            placeholder="请输入内容"
            style={{ width: 200 }}
            min={1}
            max={10}
          />
        </Col>
        <Col fixed style={{ lineHeight: '30px' }}>超出限界警告</Col>
        <Col fixed>
          <InputNumber
            placeholder="请输入内容"
            style={{ width: 200 }}
            min={1}
            max={10}
            overLimitColor={'red'}
          />
        </Col>
        <Col fixed style={{ lineHeight: '30px' }}>设置步涨值</Col>
        <Col fixed>
          <InputNumber
            placeholder="请输入内容"
            style={{ width: 200 }}
            step={5}
          />
        </Col>
      </Row>
    </div>
  )
};
export default Demo

Form 中使用 Input

import React from 'react';
import { Form, Input, Row, Col, Button, Notify ,InputNumber, Icon,} from 'uiw';

const Demo = () => (
  <Form
    onChange={({ initial, current }) => { }}
    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: <Input placeholder="请输入内容" style={{ maxWidth: 200 }} />,
      },
      inputNumber: {
        value: 'www',
        label: '请输入内容',
        help: '必须长度超过 3 个字符!',
        validator: (value = '') => value.length < 4 ? '必填选项!' : null,
        children: <InputNumber placeholder="请输入内容" style={{ maxWidth: 200 }} />,
      },
    }}
  >
    {({ fields, state, canSubmit }) => {
      return (
        <div>
          <Row>
            <Col>{fields.input}</Col>
          </Row>
          <Row>
            <Col>{fields.inputNumber}</Col>
          </Row>
          <Row>
            <Col>
              <Button disabled={!canSubmit()} type="primary" htmlType="submit">提交</Button>
            </Col>
          </Row>
          <Row>
            <Col>
              <pre style={{ padding: 10, marginTop: 10 }}>
                {JSON.stringify(state.current, null, 2)}
              </pre>
            </Col>
          </Row>
        </div>
      );
    }}
  </Form>
);

export default Demo

插入图标

import React from 'react';
import { Input, Row, Col,Icon } from 'uiw';

const stylItem = { margin: 20 };
const Demo = () => (
  <div>
    <Row gutter={10}>
      <Col fixed>
        <Input  preIcon= {<Icon type='delete' />} placeholder="请输入内容" />
      </Col>
      <Col fixed>
        <Input  preIcon= {<Icon type='tag' />}  placeholder="请输入内容" />
      </Col>
      <Col fixed>
        <Input  preIcon= {<Icon type='picasa' />} placeholder="请输入内容" />
      </Col>
      <Col fixed>
        <Input  preIcon= {<Icon type='like-o' />} placeholder="请输入内容" />
      </Col>
    </Row>
  </div>
)
export default Demo

后面插入内容

向后面插入 Button 或者 Tag

import React from 'react';
import { Input, Row, Col, Button, Tag,Icon } from 'uiw';

const Demo = () => (
  <div>
    <Row gutter={10}>
      <Col fixed>
        <Input
          preIcon= {<Icon type='like-o' />}
          placeholder="请输入密码"
          addonAfter={<Button icon={ <Icon type="lock" />} size="small" basic type="light" />}
        />
      </Col>
      <Col fixed>
        <Input
          preIcon= {<Icon type='tag' />}
          placeholder="请输入内容"
          addonAfter={<Tag title="1000" color="#28a745" />}
        />
      </Col>
      <Col fixed>
        <Input
          preIcon= {<Icon type='search' />}
          placeholder="请输入内容"
          addonAfter={<Button icon="apple" size="small" type="primary">按钮</Button>}
        />
      </Col>
      <Col fixed>
        <Input
          preIcon= { <Icon type='tag' />}
          placeholder="请输入内容"
          addonAfter={<Button size="small" type="primary">按钮</Button>}
        />
      </Col>
    </Row>
  </div>
)
export default Demo

输入框尺寸

import React from 'react';
import { Input, Row, Col, Tag, Button ,Icon} from 'uiw';

const Demo = () => (
  <div>
    <Row gutter={10} style={{ marginBottom: 10 }}>
      <Col fixed>
        <Input
          preIcon= {<Icon type='like-o' />}
          size="large"
          placeholder="请输入密码"
          addonAfter={<Button icon={<Icon type='lock' />} basic type="light" />}
        />
      </Col>
      <Col fixed>
        <Input
          preIcon= {<Icon type='search' />}
          placeholder="请输入内容"
          addonAfter={<Button icon={<Icon type='arrow-right' />} basic size="small" type="light" />}
        />
      </Col>
      <Col fixed>
        <Input
          size="small"
          preIcon= {<Icon type='tag' />}
          placeholder="请输入内容"
          addonAfter={<Button size="small" type="primary">按钮</Button>}
        />
      </Col>
    </Row>
    <Row gutter={10} style={{ marginBottom: 10 }}>
      <Col fixed>
        <Input
          size="large"
          preIcon= {<Icon type='like-o' />}
          placeholder="请输入密码"
          addonAfter={<Tag title="1000" color="#28a745" />}
        />
      </Col>
      <Col fixed>
        <Input
          preIcon= {<Icon type='tag' />}
          placeholder="请输入内容"
          addonAfter={<Tag title="药丸" color="#1C7CEB" color="#40bf16">丸</Tag>}
        />
      </Col>
      <Col fixed>
        <Input
          preIcon= {<Icon type='tag' />}
          size="small"
          placeholder="请输入内容"
          addonAfter={<Tag title="1000" color="#28a745" />}
        />
      </Col>
    </Row>
    <Row gutter={10} style={{ marginBottom: 10 }}>
      <Col fixed>
        <Input
          preIcon= {<Icon type='like-o' />}
          size="large"
          placeholder="请输入密码"
          addonAfter={<Button  icon={<Icon type='apple' />}  type="primary">按钮</Button>}
        />
      </Col>
      <Col fixed>
        <Input
          preIcon= {<Icon type='search' />}
          placeholder="请输入内容"
          addonAfter={<Button size="small" type="primary">搜索</Button>}
        />
      </Col>
      <Col fixed>
        <Input
          preIcon= {<Icon type='tag' />}
          size="small"
          placeholder="请输入内容"
          addonAfter={<Button size="small" type="primary">按钮</Button>}
        />
      </Col>
    </Row>
    <Row gutter={10} style={{ marginBottom: 10 }}>
      <Col fixed>
        <Input
           preIcon= {<Icon type='like-o' />}
          placeholder="请输入密码"
          addonAfter={<Button size="small" type="light">亮按钮</Button>}
        />
      </Col>
      <Col fixed>
        <Input
          placeholder="请输入内容"
          addonAfter={<Button size="small" type="danger">按钮</Button>}
        />
      </Col>
      <Col fixed>
        <Input
          placeholder="请输入内容"
          addonAfter={<Button size="small" type="warning">按钮</Button>}
        />
      </Col>
    </Row>
    <Row gutter={10}>
      <Col fixed>
        <Input size="small" preIcon={<Icon type='like-o' />} placeholder="请输入密码" />
      </Col>
      <Col fixed>
        <Input size="small" placeholder="请输入内容" />
      </Col>
      <Col fixed>
        <Input
          size="small"
          preIcon= { <Icon type='like-o' />}
          placeholder="请输入内容"
          addonAfter={<Button size="small" type="warning">按钮</Button>}
        />
      </Col>
    </Row>
  </div>
)
export default Demo

密码输入框

import React from 'react';
import { Input, Row, Col, Button ,Icon} from 'uiw';

class Demo extends React.Component {
  constructor() {
    super();
    this.state = {
      btnIcon: 'lock',
    }
  }
  onClick() {
    this.setState({
      btnIcon: this.state.btnIcon === 'lock' ? 'unlock' : 'lock',
    })
  }
  render() {
    return (
      <Row gutter={10}>
        <Col fixed>
          <Input
            ref={(instance) => {
              if (instance) {
                console.log('instance:', instance);
              }
            }}
            preIcon= { <Icon type='like-o' />}
            type={this.state.btnIcon === 'lock' ? 'password' : 'text'}
            placeholder="请输入密码"
            addonAfter={<Button
             icon={<Icon type={this.state.btnIcon} />}
             onClick={this.onClick.bind(this)}
             size="small"
             basic 
             type="light" />}
          />
        </Col>
      </Row>
    )
  }
}
export default Demo

输入框被禁用

import React from 'react';
import { Icon, Input, Row, Col,Button} from 'uiw';

const stylItem = { margin: 20 };
const Demo = () => (
  <>
    <Row gutter={10}>
      <Col fixed>
        <Input disabled preIcon={<Icon type="delete" />} placeholder="请输入内容" />
      </Col>
      <Col fixed>
        <Input disabled preIcon={<Icon type="tag" />} placeholder="请输入内容" />
      </Col>
      <Col fixed>
        <Input
          disabled
          preIcon={<Icon type="picasa" />}
          placeholder="请输入内容"
          addonAfter={
            <Button icon={<Icon type="close" />} disabled size="small" basic type="light" />
          }
        />
      </Col>
      <Col fixed>
        <Input disabled  preIcon={<Icon type="like-o" />}  placeholder="请输入内容" />
      </Col>
    </Row>
  </>
);
export default Demo

Input

参数说明类型默认值版本
value绑定值String-
disabled禁用输入框Booleanfalse
preIcon输入框面放置图标ReactNode-
addonAfter带标签的 input,设置后置标签String/ReactNode-
size指定输入框的尺寸,除了默认的大小外,还提供了 largesmalldefault 三种尺寸。String-
inputStyle传递给input的样式,在需要动态设置样式场景下使用Object-v4.18.2

InputNumber

在v4.18.2中增加

参数说明类型默认值版本
min最小值Number-
max最大值Number-
step设置步长值Number-
overLimitColor允许超出min,max限制, 使用该警告色显示String-

更多属性文档请参考 Input。

4.22.0

2 years ago

4.22.1

2 years ago

4.22.2

2 years ago

4.22.3

2 years ago

4.21.26

3 years ago

4.21.25

3 years ago

4.21.28

3 years ago

4.21.27

3 years ago

5.0.0-bate.2.1

3 years ago

5.0.0-bate.2.0

3 years ago

4.21.24

3 years ago

5.0.0-bate-19

3 years ago

4.21.22

3 years ago

4.21.21

3 years ago

4.21.23

3 years ago

5.0.0-bate-18

3 years ago

5.0.0-bate-14

3 years ago

5.0.0-bate-17

3 years ago

5.0.0-bate-10

3 years ago

5.0.0-bate-11

3 years ago

5.0.0-bate-12

3 years ago

5.0.0-bate-9

3 years ago

5.0.0-bate-7

3 years ago

5.0.0-bate-8

3 years ago

5.0.0-bate-6

3 years ago

4.21.20

3 years ago

4.21.19

3 years ago

4.21.18

3 years ago

4.21.15

3 years ago

4.21.17

3 years ago

4.21.16

3 years ago

5.0.0-bate-5

3 years ago

5.0.0-bate-3

3 years ago

5.0.0-bate-4

3 years ago

5.0.0-bate-1

3 years ago

5.0.0-bate-2

3 years ago

5.0.0-bate-0

3 years ago

4.21.13

4 years ago

4.21.14

4 years ago

4.21.11

4 years ago

4.21.12

4 years ago

4.21.10

4 years ago

4.21.1

4 years ago

4.21.2

4 years ago

4.21.3

4 years ago

4.21.4

4 years ago

4.21.0

4 years ago

4.20.0

4 years ago

4.21.9

4 years ago

4.21.5

4 years ago

4.21.6

4 years ago

4.21.7

4 years ago

4.21.8

4 years ago

4.18.1

4 years ago

4.18.0

4 years ago

4.17.0

4 years ago

4.16.0

4 years ago

4.16.1

4 years ago

4.16.2

4 years ago

4.19.0

4 years ago

4.15.1

4 years ago

4.14.1

4 years ago

4.14.2

4 years ago

4.14.0

4 years ago

4.13.7

4 years ago

4.13.8

4 years ago

4.13.9

4 years ago

4.13.11

4 years ago

4.13.12

4 years ago

4.13.10

4 years ago

4.15.0

4 years ago

4.10.5

4 years ago

4.10.6

4 years ago

4.10.7

4 years ago

4.9.9

4 years ago

4.10.1

4 years ago

4.10.2

4 years ago

4.10.3

4 years ago

4.10.4

4 years ago

4.10.0

4 years ago

4.13.6

4 years ago

4.13.2

4 years ago

4.13.3

4 years ago

4.13.4

4 years ago

4.13.5

4 years ago

4.13.0

4 years ago

4.13.1

4 years ago

4.12.0

4 years ago

4.12.1

4 years ago

4.12.2

4 years ago

4.11.4

4 years ago

4.11.5

4 years ago

4.11.6

4 years ago

4.9.11

4 years ago

4.9.10

4 years ago

4.11.0

4 years ago

4.11.1

4 years ago

4.11.2

4 years ago

4.11.3

4 years ago

4.9.7

4 years ago

4.9.6

4 years ago

4.9.4

4 years ago

4.9.3

4 years ago

4.9.2

4 years ago

4.9.1

5 years ago

4.9.0

5 years ago

4.8.9

5 years ago

4.8.8

5 years ago

4.7.16

5 years ago

4.8.5

5 years ago

4.8.4

5 years ago

4.8.7

5 years ago

4.8.6

5 years ago

4.8.1

5 years ago

4.8.0

5 years ago

4.8.3

5 years ago

4.8.2

5 years ago

4.7.13

5 years ago

4.7.14

5 years ago

4.7.15

5 years ago

4.7.12

5 years ago

4.7.10

5 years ago

4.7.11

5 years ago

4.7.9

5 years ago

4.7.8

5 years ago

4.7.7

5 years ago

4.7.6

5 years ago

4.7.5

5 years ago

4.7.4

5 years ago

4.7.3

5 years ago

4.7.2

5 years ago

4.7.0

5 years ago

4.6.19

5 years ago

4.6.15

5 years ago

4.6.16

5 years ago

4.6.17

5 years ago

4.6.18

5 years ago

4.6.14

5 years ago

4.6.13

5 years ago

4.6.12

5 years ago

4.6.11

5 years ago

4.6.10

5 years ago

4.6.9

5 years ago

4.6.8

5 years ago

4.6.7

5 years ago

4.6.6

5 years ago

4.6.3

6 years ago

4.6.4

6 years ago

4.6.2

6 years ago

4.6.1

6 years ago

4.6.0

6 years ago

4.5.0

6 years ago

4.4.1

6 years ago

4.4.0

6 years ago

4.3.1

6 years ago

4.2.3

6 years ago

4.2.5

6 years ago

4.3.0

6 years ago

4.2.14

6 years ago

4.2.1

6 years ago

4.2.0

6 years ago

4.1.0

6 years ago

4.1.2

6 years ago

4.1.1

6 years ago

4.0.0

6 years ago

4.0.0-alpha.7

6 years ago

4.0.0-alpha.8

6 years ago

4.0.0-alpha.6

6 years ago

4.0.0-alpha.3

6 years ago

4.0.0-alpha.2

6 years ago

4.0.0-alpha.1

6 years ago

4.0.0-alpha.0

6 years ago