@deskpro/react-datepicker-hijri

中文文档
1.5.3-alpha.5发布于 2025/05/08MITESM + CJS近 30 天下载 5244

A simple and reusable datepicker component for React

原始使用文档
文档目录12 节
  1. Installation
  2. Configuration
  3. Time picker
  4. Localization
  5. Compatibility
  6. React
  7. Browser Support
  8. Local Development
  9. The examples
  10. Accessibility
  11. Keyboard support
  12. License

React Date Picker

npm version Build Status Dependency Status codecov Downloads

A simple and reusable Datepicker component for React (Demo)

Installation

The package can be installed via NPM:

npm install @deskpro/react-datepicker-hijri --save

You’ll need to install react, propTypes, moment and moment-hijri separately since those dependencies aren’t included in the package. Below is a simple example of how to use the Datepicker in a React view. You will also need to require the CSS file from this package (or provide your own). The example below shows how to include the CSS from this package if your build system supports requiring CSS files (Webpack is one that does).

import React from "react";
import DatePicker from "@deskpro/react-datepicker-hijri";
import moment from "moment-hijri";

import "@deskpro/react-datepicker-hijri/dist/react-datepicker.css";

// CSS Modules, react-datepicker-cssmodules.css
// import '@deskpro/react-datepicker-hijri/dist/react-datepicker-cssmodules.css';

class Example extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      startDate: moment()
    };
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(date) {
    this.setState({
      startDate: date
    });
  }

  render() {
    return (
      <DatePicker
        selected={this.state.startDate}
        onChange={this.handleChange}
        calendar="hijri"
      />
    );
  }
}

Configuration

The most basic use of the DatePicker can be described with:

<DatePicker selected={this.state.date} onChange={this.handleChange} />

You can use onSelect event handler which fires each time some calendar date has been selected

<DatePicker selected={this.state.date}
  onSelect={this.handleSelect} //when day is clicked
  onChange={this.handleChange} //only when value has changed
/>

onClickOutside handler may be useful to close datepicker in inline mode

See here for a full list of props that may be passed to the component. Examples are given on the main website.

Time picker

You can also include a time picker by adding the showTimeSelect prop

<DatePicker
  selected={this.state.date}
  onChange={this.handleChange}
  showTimeSelect
  dateFormat="LLL"
/>

Times will be displayed at 30-minute intervals by default (default configurable via timeInterval prop)

More examples of how to use the time picker are given on the main website

Localization

The date picker relies on moment.js internationalization to localize its display components. By default, the date picker will use the locale globally set in moment, which is English. Locales can be changed in the following ways:

  • Globally by calling moment.locale(lang)
  • Picker-specific by providing the locale prop

Locales can be further configured in moment with various customization options.

As of version 0.23, the weekdays and weekStart DatePicker props have been removed. Instead, they can be configured with the weekdaysMin and week.dow moment locale customization options.

Compatibility

React

We're always trying to stay compatible with the latest version of React. We can't support all older versions of React.

Latest compatible versions:

  • React 15.5 or newer: All above React-datepicker v.0.40.0
  • React 15.4.1: needs React-datepicker v0.40.0, newer won't work (due to react-onclickoutside dependencies)
  • React 0.14 or newer: All above React-datepicker v0.13.0
  • React 0.13: React-datepicker v0.13.0
  • pre React 0.13: React-datepicker v0.6.2

Browser Support

The date picker is compatible with the latest versions of Chrome, Firefox, and IE10+.

Unfortunately, it is difficult to support legacy browsers while maintaining our ability to develop new features in the future. For IE9 support, it is known that the classlist polyfill is needed, but this may change or break at any point in the future.

Local Development

The master branch contains the latest version of the Datepicker component. To start your example app, you can run yarn start. This starts a simple webserver on http://localhost:8080.

You can run yarn test to execute the test suite and linters. To help you develop the component we’ve set up some tests that cover the basic functionality (can be found in /tests). Even though we’re big fans of testing, this only covers a small piece of the component. We highly recommend you add tests when you’re adding new functionality.

The examples

The examples are hosted within the docs folder and are ran in the simple app that loads the Datepicker. To extend the examples with a new example, you can simply duplicate one of the existing examples and change the unique properties of your example.

Accessibility

Keyboard support

  • Left: Move to the previous day.
  • Right: Move to the next day.
  • Up: Move to the previous week.
  • Down: Move to the next week.
  • PgUp: Move to the previous month.
  • PgDn: Move to the next month.
  • Home: Move to the previous year.
  • End: Move to the next year.
  • Enter/Esc/Tab: close the calendar. (Enter & Esc calls preventDefault)

License

Copyright (c) 2017 HackerOne Inc. and individual contributors. Licensed under MIT license, see LICENSE for the full license.

版本与发布记录

@deskpro/react-datepicker-hijri 共发布 10 个版本,首次发布于 2018/05/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.5.3-alpha.5latest2025/05/081.5 年前
1.5.3-alpha.42025/05/081.5 年前
1.5.3-alpha.32025/05/081.5 年前
1.5.3-alpha.22025/05/081.5 年前
1.5.3-alpha.12025/05/081.5 年前
1.5.22025/05/071.5 年前

关于 @deskpro/react-datepicker-hijri 的常见问题

@deskpro/react-datepicker-hijri 是什么?

A simple and reusable datepicker component for React

如何安装 @deskpro/react-datepicker-hijri?

在项目目录运行 npm install @deskpro/react-datepicker-hijri,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^16.0.0)、moment(^2.20.0)、react-dom(^16.0.0)、moment-hijri(^2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@deskpro/react-datepicker-hijri 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/deskpro__react-datepicker-hijri 是否存在。

@deskpro/react-datepicker-hijri 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@deskpro/react-datepicker-hijri 可以商用吗?

@deskpro/react-datepicker-hijri 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@deskpro/react-datepicker-hijri 的下载量有多少?

根据 npm 官方下载统计,@deskpro/react-datepicker-hijri 在 2026/10/12 – 2026/11/10 这 30 天内被下载 5,244 次,日均约 175 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@deskpro/react-datepicker-hijri 还在维护吗?

最新版本 1.5.3-alpha.5 发布于 2025/05/08(1.5 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/05/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。