npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@uiw/react-time-picker

v4.22.3

Published

TimePicker component

Downloads

1,321

Readme

TimePicker 时间选择器

Buy me a coffee Open in unpkg NPM Downloads npm version

当用户需要输入一个时间,可以点击标准输入框,弹出时间面板进行选择。

import { TimePicker } from 'uiw';
// or
import TimePicker from '@uiw/react-time-picker';

基础用法

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

const Demo = () => (
  <Row gutter={10}>
    <Col style={{ width: 200 }} fixed>
      <TimePicker
        onChange={(formatDate, date) => {
          console.log('--->', formatDate, date);
        }}
      />
    </Col>
    <Col style={{ width: 200 }} fixed>
      <TimePicker format="HH:mm" precision="minute" />
    </Col>
    <Col style={{ width: 200 }} fixed>
      <TimePicker format="HH" precision="hour" />
    </Col>
  </Row>
)
export default Demo;

设置初始值

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

const Demo = () => {
  const value = new Date(2018, 1, 24, 4,5,35);
  return (
    <Row gutter={10}>
      <Col style={{ width: 200 }} fixed>
        <TimePicker value={value} />
      </Col>
      <Col style={{ width: 200 }} fixed>
        <TimePicker value={value} format="HH:mm" precision="minute" />
      </Col>
      <Col style={{ width: 200 }} fixed>
        <TimePicker value={value} format="HH" precision="hour" />
      </Col>
    </Row>
  )
}
export default Demo;

设置按钮大小

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

const Demo = () => {
  const value = new Date(2018, 1, 24, 4,5,35);
  return (
    <Row gutter={10}>
      <Col style={{ width: 200 }} fixed>
        <TimePicker size="small" value={value} />
      </Col>
      <Col style={{ width: 200 }} fixed>
        <TimePicker value={value} format="HH" precision="hour" />
      </Col>
      <Col style={{ width: 200 }} fixed>
        <TimePicker size="large" value={value} format="HH:mm" precision="minute" />
      </Col>
    </Row>
  )
}
export default Demo;

表单中应用

在表单返回的数据,并没有将 format 格式化后的数据返回给你,而是返回的一个 Date,你可以通过 formatter 重新格式化。

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

const Demo = () => (
  <div>
    <Form
      onSubmit={({initial, current}) => {
        console.log('-->>', initial, current);
        if(current.date) {
          Notify.success({
            title: '提交成功!',
            description: `表单提交时间成功,时间为:${formatter('HH:mm:ss', current.date)}`,
          });
        } else {
          Notify.error({
            title: '提交失败!',
            description: <span>表单提交时间成功,时间为:<b>空</b>,将自动填充初始化值!</span>,
          });
        }
      }}
      fields={{
        date: {
          labelClassName: 'fieldLabel',
          labelFor: 'date-inline',
          children: <TimePicker />
        },
      }}
    >
      {({ fields, state, canSubmit }) => {
        return (
          <Row gutter={10}>
            <Col style={{ width: 200 }} fixed>{fields.date}</Col>
            <Col>
              <Button disabled={!canSubmit()} type="primary" htmlType="submit">提交</Button>
            </Col>
          </Row>
        )
      }}
    </Form>
  </div>
)
export default Demo;

禁用

可以使用 disabledHours disabledMinutes disabledSeconds 禁用部分时间选择。

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

const Demo = () => (
  <Row gutter={10} style={{ maxWidth: 360 }}>
      <Col style={{ width: 200 }} fixed>
      <TimePicker
        disabledMinutes={(minute, type) => {
          if (minute % 15 !== 0) {
            return true;
          }
        }}
        disabledHours={(hour, type, date) => {
          // console.log('~~:', hour, type, date);
          if (hour < 3) {
            return true;
          }
        }}
      />
    </Col>
    <Col style={{ width: 200 }} fixed>
      <TimePicker disabled value={new Date(2018, 1, 24, 4,5,35)} />
    </Col>
  </Row>
)
export default Demo;

不显示禁用

可以使用 hideDisabled 将禁用的部分时间隐藏。

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

const Demo = () => (
  <Row gutter={10} style={{ maxWidth: 360 }}>
    <Col style={{ width: 200 }} fixed>
      <TimePicker
        hideDisabled
        disabledMinutes={(minute, type) => {
          if (minute % 15 !== 0) {
            return true;
          }
        }}
        disabledHours={(hour, type, date) => {
          // console.log('~~:', hour, type, date);
          if (hour < 3) {
            return true;
          }
        }}
      />
    </Col>
  </Row>
)
export default Demo;

间隔时间

可以使用 hideDisabled 将禁用的部分时间隐藏。

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

const Demo = () => (
  <Row gutter={10} style={{ maxWidth: 360 }}>
    <Col style={{ width: 200 }} fixed>
      <TimePicker
        hideDisabled
        disabledMinutes={(minute, date) => {
          if (minute % 15 !== 0) {
            return true;
          }
        }}
        disabledSeconds={(second, date) => {
          if (second % 15 !== 0) {
            return true;
          }
        }}
      />
    </Col>
  </Row>
)
export default Demo;

Props

| 参数 | 说明 | 类型 | 默认值 | |--------- |-------- |--------- |-------- | | value | 初始时间值 | Date | - | | placeholder | 输入框提示文字 | String | - | | format | 格式化时间,规则查看 formatter 文档 | Function | HH:mm:ss | | precision | 选择时间精确度 | Enum{hour, minute, second} | false | | disabled | 禁用全部操作 | Boolean | false | | disabledHours | 禁止选择部分小时选项 | Function(hour, type{Hours, Minutes, Seconds}, selectedDate) | - | | disabledMinutes | 禁止选择部分分钟选项 | Function(minute, type{Hours, Minutes, Seconds}, selectedDate) | - | | disabledSeconds | 禁止选择部分秒选项 | Function(second, type{Hours, Minutes, Seconds}, selectedDate) | - | | hideDisabled | 不可选择的项隐藏 | Boolean | false | | onChange | 时间选择的回调函数 | Function(formatDate, Date, type{Hours, Minutes, Seconds}, , num, disableds) | - |

[email protected]+ 组件集成部分 Input,不再通过 inputProps 属性传值,更多属性请参考 Input

~~Props.inputProps~~

[email protected]+ 将不支持此属性

| 参数 | 说明 | 类型 | 默认值 | |--------- |-------- |--------- |-------- | | ~~inputProps~~ | ~~将参数传递给 <Input> 组件~~ | Object | - |

Props.popoverProps

| 参数 | 说明 | 类型 | 默认值 | |--------- |-------- |--------- |-------- | | popoverProps | 将参数传递给 <Popover> 组件 | Object | - |