4.22.3 • Published 5 months ago

@uiw/react-date-input v4.22.3

Weekly downloads
308
License
MIT
Repository
github
Last release
5 months ago

DateInput 日期输入框

Buy me a coffee Open in unpkg NPM Downloads npm version

显示一个月的日历,并允许用户选择单个日期。

import { DateInput, DateInputRange } from 'uiw';
// or
import DateInput,{ DateInputRange } from '@uiw/react-date-input';
// 在 `v4.13.0` 版本中增加 DateInputRange 组件

基本使用

import React from 'react';
import { DateInput, DateInputRange, Row, Col } from 'uiw';

export default function Demo () {
  const [dataRange,dataRangeSet] =React.useState(['2022/02/25 15:06:24','2022/02/27 14:47:32'])

  function onChange(selectedDate,dataRange) {
    console.log('selectedDate',selectedDate,dataRange)
  }

  return (
    <div>
      <Row style={{ marginBottom:10 }}>
        <Col style={{ width: 200 }} fixed>
          <DateInput
            value={new Date()}
            datePickerProps={{ todayButton: '今天' }}
            onChange={onChange}
          />
        </Col>
        <Col style={{ width: 200, marginLeft: 10 }} fixed>
          <DateInput
            value={new Date()}
            disabled
            onChange={onChange}
          />
        </Col>
        <Col style={{ width: 400, marginLeft: 10 }} fixed>
          <DateInputRange
            bodyStyle={{ width: 400 }}
            format="YYYY/MM/DD HH:mm:ss"
            value={dataRange}
            datePickerProps={{ todayButton: '今天',showTime:true }}
            onChange={onChange}
          />
        </Col>
      </Row>
    </div>
  )
}

在表单中使用

<Form /> 表单中应用 <DateInput /> 组件。

import React from 'react';
import { DateInput,DateInputRange, Notify, Button, Form, Row, Col } from 'uiw';

export default function Demo() {
  const form = React.useRef(null)

  const resetDateRange = () => {
    form.current.resetForm()
  }

  const setDateRange = () => {
    form.current.setFields({dateRange:[new Date(),new Date()]})
  }

  return (
    <Form
      ref={form}
      onSubmit={({ initial, current }) => {
        if (current.date) {
          Notify.success({
            title: '提交成功!',
            description: `表单提交时间成功,时间为:${current.date} range:${current.dateRange}`,
          });
        } else {
          Notify.error({
            title: '提交失败!',
            description: `表单提交时间成功,时间为:${current.date} range:${current.dateRange},将自动填充初始化值!`,
          });
        }
      }}
      fields={{
        date: {
          initialValue: '2019/02/17',
          labelClassName: 'fieldLabel',
          labelFor: 'date-inline',
          children: <DateInput datePickerProps={{ todayButton: '今天' }} id="date-inline" />
        },
        dateRange: {
          initialValue: ['2019/02/17', '2019/02/20'],
          labelClassName: 'fieldLabel',
          labelFor: 'date-inline',
          children: <DateInputRange datePickerProps={{ todayButton: '今天' }} id="date-inline" />
        },
      }}
    >
      {({ fields, state, canSubmit }) => {
        return (
          <div>
            <Row>
              <Col style={{ width: 200 }} fixed>{fields.date}</Col>
              <Col fixed>{fields.dateRange}</Col>
            </Row>
            <Row>
              <Col style={{ overflow: 'auto', height: 130 }}>
                <pre>
                  {JSON.stringify(state, null, 2)}
                </pre>
              </Col>
            </Row>
            <Row gutter={10}>
              <Col>
                <Button disabled={!canSubmit()} type="primary" htmlType="submit">提交</Button>
                <Button onClick={resetDateRange} >重置</Button>
                <Button onClick={setDateRange}>setValue</Button>
              </Col>
            </Row>
          </div>
        )
      }}
    </Form>
  )
}

日期格式

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

class Demo extends React.Component {
  onChange(selectedDate) {
    console.log('selectedDate:', selectedDate);
  }
  render() {
    return (
      <div style={{ width: 200 }}>
        <DateInput
          format="YYYY # MM # DD"
          datePickerProps={{ todayButton: '今天' }}
          onChange={this.onChange.bind(this)}
        />
      </div>
    )
  }
}
export default Demo;

日期时间设置

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

class Demo extends React.Component {
  onChange(selectedDate) {
    console.log('selectedDate:', selectedDate);
  }
  render() {
    return (
      <div style={{ width: 200 }}>
        <DateInput
          format="YYYY/MM/DD HH:mm:ss"
          datePickerProps={{ showTime: true, todayButton: '今天' }}
          onChange={this.onChange.bind(this)}
        />
      </div>
    )
  }
}

export default Demo;

自动隐藏弹层

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

class Demo extends React.Component {
  onChange(selectedDate) {
    console.log('selectedDate:', selectedDate);
  }
  render() {
    return (
      <div style={{ maxWidth: 200 }}>
        <DateInput
          autoClose={true}
          format="YYYY/MM/DD HH:mm:ss"
          datePickerProps={{ showTime: true, todayButton: '今天' }}
          onChange={this.onChange.bind(this)}
        />
      </div>
    )
  }
}

export default Demo;

Props

参数说明类型默认值
value初始时间值Date-
placeholder输入框提示文字String-
allowClear是否显示清除按钮Booleantrue
format格式化时间,规则查看 <formatter> 文档StringYYYY/MM/DD
onChange选择一天时调用。Function(selectedDate:Date)-
popoverProps将参数传递给 <Popover> 组件Object-
datePickerProps将参数传递给 <DatePicker> 组件Object-
disabled组件 <Input> 的属性,禁用日历Boolean-
autoClose是否自动关闭弹层Booleanfalse

组件 DateInput 继承 <Input> 组件,更多属性文档请参考 <Input>

DateInputRange

v4.13.0 版本中增加 DateInputRange 组件。

参数说明类型默认值
value初始时间值Array<Date, string>-
placeholder输入框提示文字String-
allowClear是否显示清除按钮Booleantrue
format格式化时间,规则查看 <formatter> 文档StringYYYY/MM/DD
onChange选择一天时调用。Function(selectedDate:Date, dateRange: Array\)-
popoverProps将参数传递给 <Popover> 组件Object-
datePickerProps将参数传递给 <DatePicker> 组件Object-
disabled组件 <Input> 的属性,禁用日历Boolean-
bodyStyle选择框样式Object{ width: 300 }-

组件 DateInputRange 继承 <Input> 组件,更多属性文档请参考 <Input>

4.22.0

8 months ago

4.22.1

6 months ago

4.22.2

6 months ago

4.22.3

5 months ago

4.21.26

1 year ago

4.21.25

1 year ago

4.21.28

12 months ago

4.21.27

1 year ago

5.0.0-bate.2.1

1 year ago

5.0.0-bate.2.0

1 year ago

4.21.24

1 year ago

5.0.0-bate-19

1 year ago

4.21.22

1 year ago

4.21.21

1 year ago

4.21.23

1 year ago

5.0.0-bate-18

1 year ago

5.0.0-bate-14

1 year ago

5.0.0-bate-17

1 year ago

5.0.0-bate-10

1 year ago

5.0.0-bate-11

1 year ago

5.0.0-bate-12

1 year ago

5.0.0-bate-9

1 year ago

5.0.0-bate-7

1 year ago

5.0.0-bate-8

1 year ago

5.0.0-bate-6

1 year ago

4.21.20

1 year ago

4.21.19

2 years ago

4.21.18

2 years ago

4.21.15

2 years ago

4.21.17

2 years ago

4.21.16

2 years ago

5.0.0-bate-5

2 years ago

5.0.0-bate-3

2 years ago

5.0.0-bate-4

2 years ago

5.0.0-bate-1

2 years ago

5.0.0-bate-2

2 years ago

5.0.0-bate-0

2 years ago

4.21.13

2 years ago

4.21.14

2 years ago

4.21.11

2 years ago

4.21.12

2 years ago

4.21.10

2 years ago

4.21.1

2 years ago

4.21.2

2 years ago

4.21.3

2 years ago

4.21.4

2 years ago

4.21.0

2 years ago

4.20.0

2 years ago

4.21.9

2 years ago

4.21.5

2 years ago

4.21.6

2 years ago

4.21.7

2 years ago

4.21.8

2 years ago

4.18.1

2 years ago

4.18.0

2 years ago

4.17.0

2 years ago

4.16.0

2 years ago

4.16.1

2 years ago

4.16.2

2 years ago

4.19.0

2 years ago

4.15.1

2 years ago

4.14.1

2 years ago

4.14.2

2 years ago

4.14.0

2 years ago

4.13.7

2 years ago

4.13.8

2 years ago

4.13.9

2 years ago

4.13.11

2 years ago

4.13.12

2 years ago

4.13.10

2 years ago

4.15.0

2 years ago

4.10.5

2 years ago

4.10.6

2 years ago

4.10.7

2 years ago

4.9.9

2 years ago

4.10.1

2 years ago

4.10.2

2 years ago

4.10.3

2 years ago

4.10.4

2 years ago

4.10.0

2 years ago

4.13.6

2 years ago

4.13.2

2 years ago

4.13.3

2 years ago

4.13.4

2 years ago

4.13.5

2 years ago

4.13.0

2 years ago

4.13.1

2 years ago

4.12.0

2 years ago

4.12.1

2 years ago

4.12.2

2 years ago

4.11.4

2 years ago

4.11.5

2 years ago

4.11.6

2 years ago

4.9.11

2 years ago

4.9.10

2 years ago

4.11.0

2 years ago

4.11.1

2 years ago

4.11.2

2 years ago

4.11.3

2 years ago

4.9.7

3 years ago

4.9.6

3 years ago

4.9.4

3 years ago

4.9.3

3 years ago

4.9.2

3 years ago

4.9.1

3 years ago

4.9.0

3 years ago

4.8.9

3 years ago

4.8.8

3 years ago

4.7.16

3 years ago

4.8.5

3 years ago

4.8.4

3 years ago

4.8.7

3 years ago

4.8.6

3 years ago

4.8.1

3 years ago

4.8.0

3 years ago

4.8.3

3 years ago

4.8.2

3 years ago

4.7.13

3 years ago

4.7.14

3 years ago

4.7.15

3 years ago

4.7.12

3 years ago

4.7.10

3 years ago

4.7.11

3 years ago

4.7.9

3 years ago

4.7.8

3 years ago

4.7.6

3 years ago

4.7.7

3 years ago

4.7.5

3 years ago

4.7.4

3 years ago

4.7.3

3 years ago

4.7.2

3 years ago

4.7.0

3 years ago

4.6.19

3 years ago

4.6.15

3 years ago

4.6.16

3 years ago

4.6.17

3 years ago

4.6.18

3 years ago

4.6.14

4 years ago

4.6.13

4 years ago

4.6.11

4 years ago

4.6.12

4 years ago

4.6.10

4 years ago

4.6.9

4 years ago

4.6.8

4 years ago

4.6.7

4 years ago

4.6.6

4 years ago

4.6.3

4 years ago

4.6.4

4 years ago

4.6.2

4 years ago

4.6.1

4 years ago

4.6.0

4 years ago

4.5.0

4 years ago

4.4.1

4 years ago

4.4.0

4 years ago

4.3.1

4 years ago

4.2.3

4 years ago

4.2.5

4 years ago

4.3.0

4 years ago

4.2.14

4 years ago

4.2.1

4 years ago

4.2.0

4 years ago

4.1.2

4 years ago

4.1.0

4 years ago

4.1.1

4 years ago

4.0.0

4 years ago

4.0.0-alpha.8

4 years ago

4.0.0-alpha.7

4 years ago

4.0.0-alpha.6

4 years ago

4.0.0-alpha.3

4 years ago

4.0.0-alpha.2

4 years ago

4.0.0-alpha.1

4 years ago

4.0.0-alpha.0

4 years ago