# uxcore-calendar

> calendar componment for react

Latest version **0.10.45** (published 2023-04-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install uxcore-calendar
pnpm add uxcore-calendar
yarn add uxcore-calendar
bun add uxcore-calendar
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.10.45 |
| Published | 2023-04-26 |
| First published | 2015-08-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 16 |
| Unpacked size | 552.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | vincent.bian |
| Maintainers | taoqili, vincent.bian, eternalsky, surfacew, ex90rts |
| Keywords | react, react-calendar, react-uxcore-calendar, uxcore-calendar |

## Links

- npm: https://www.npmjs.com/package/uxcore-calendar
- Repository: https://github.com/uxcore/uxcore-calendar
- Issues: https://github.com/uxcore/uxcore-calendar/issues
- npm.io page: https://npm.io/package/uxcore-calendar

## Dependencies (16)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [moment](https://npm.io/package/moment.md) ^2.17.1
- [rc-util](https://npm.io/package/rc-util.md) 4.x
- [classnames](https://npm.io/package/classnames.md) ^2.1.2
- [prop-types](https://npm.io/package/prop-types.md) 15.x
- [uxcore-tag](https://npm.io/package/uxcore-tag.md) ^2.2.3
- [rc-calendar](https://npm.io/package/rc-calendar.md) ~9.9.0
- [uxcore-icon](https://npm.io/package/uxcore-icon.md) ^0.1.2
- [object-assign](https://npm.io/package/object-assign.md) ^4.0.0
- [uxcore-button](https://npm.io/package/uxcore-button.md) ^0.4.6
- [rc-time-picker](https://npm.io/package/rc-time-picker.md) ^3.0.0
- [uxcore-select2](https://npm.io/package/uxcore-select2.md) ^0.5.0
- [uxcore-tooltip](https://npm.io/package/uxcore-tooltip.md) ^0.4.0
- [uxcore-formatter](https://npm.io/package/uxcore-formatter.md) ^0.1.2
- [create-react-class](https://npm.io/package/create-react-class.md) 15.x
- [react-lifecycles-compat](https://npm.io/package/react-lifecycles-compat.md) ^3.0.4

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.10.45 (latest) — 2023-04-26
- 0.10.44 — 2023-03-31
- 0.10.43 — 2023-03-03
- 0.10.42 — 2023-02-27
- 0.10.41 — 2020-09-15
- 0.10.40 — 2020-09-15
- 0.10.39 — 2020-08-27
- 0.10.38 — 2020-08-27
- 0.10.37 — 2020-08-27
- 0.10.36 — 2020-08-06
- 0.10.35 — 2020-07-15
- 0.10.34 — 2019-09-27
- 0.10.33 — 2019-06-18
- 0.10.32 — 2019-06-17
- 0.10.31 — 2019-06-12
- … 119 more at https://npm.io/package/uxcore-calendar/versions

## README

# uxcore-calendar

---

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
[![Dependency Status][dep-image]][dep-url]
[![devDependency Status][devdep-image]][devdep-url]
[![NPM downloads][downloads-image]][npm-url]

[![Sauce Test Status][sauce-image]][sauce-url]

[npm-image]: http://img.shields.io/npm/v/uxcore-calendar.svg?style=flat-square
[npm-url]: http://npmjs.org/package/uxcore-calendar
[travis-image]: https://img.shields.io/travis/uxcore/uxcore-calendar.svg?style=flat-square
[travis-url]: https://travis-ci.org/uxcore/uxcore-calendar
[coveralls-image]: https://img.shields.io/coveralls/uxcore/uxcore-calendar.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/uxcore/uxcore-calendar?branch=master
[dep-image]: http://img.shields.io/david/uxcore/uxcore-calendar.svg?style=flat-square
[dep-url]: https://david-dm.org/uxcore/uxcore-calendar
[devdep-image]: http://img.shields.io/david/dev/uxcore/uxcore-calendar.svg?style=flat-square
[devdep-url]: https://david-dm.org/uxcore/uxcore-calendar#info=devDependencies
[downloads-image]: https://img.shields.io/npm/dm/uxcore-calendar.svg
[sauce-image]: https://saucelabs.com/browser-matrix/uxcore-calendar.svg
[sauce-url]: https://saucelabs.com/u/uxcore-calendar

## TL;DR

transfer ui component for react

#### setup develop environment

```sh
$ git clone https://github.com/uxcore/uxcore-calendar
$ cd uxcore-calendar
$ npm install
$ npm start
```

## Usage

```js
var Calendar = require('uxcore-calendar');
const {
  MonthCalendar, YearCalendar, RangeCalendar, CalendarFull, MiniWeek
} = Calendar;
React.render(
  (<Calendar />),
  document.getElementById('target')
);
```

### demo
http://uxco.re/components/calendar/

## API
- onSelect(date, formatDateString)
    - date `date`
    - formatDateString `string`

## Attention

0.8.0 之后，我们使用 moment 替代了 gregorianCalendar，在一些格式上和用法上有了一些变化。


## 共通 Props

|参数|说明|类型|默认值|
|---|----|---|------|
|placeholder|占位符|string|请选择日期|
|locale|`en-us`,`zh-cn` 和 `pl-pl`|string|`zh-cn`|
|disabledDate|不可选择的日期|(currentDate) => boolean|无|
|onSelect|当日期被选中时触发|function(date)|无|
|disabled|禁用|boolean|false|
|getPopupContainer| 弹出的菜单渲染在哪个容器中 | function(trigger:Node):Node | () => document.body|
|size| 尺寸，支持 large/middle/small | string | large |
|allowClear| 是否支持清空 | boolean | true |
|onOpenChange | 在下拉面板展开、收起时调用 | function(open) | noop |
|defaultOpenValue| 在值为空的情况下，日历面板默认展示的值 | boolean |  |

### props

|参数|说明|类型|默认值|
|---|----|---|------|
|value|日期|string/number|无|
|defaultValue|日期|string/number|无|
|format|展示的日期格式|string|'YYYY-MM-DD'|
|disabledTime|不可选择的时间，返回格式见下文|function(date)||
|showTime|是否显示时间选择面板|boolean|false|
|showHour|时间选择面板是否显示小时|boolean|true|
|showSecond|时间选择面板是否显示秒|boolean|true|
|timePicker|自己传入定制的 timePicker|React Element|-|
|yearSelectOffset | 年选择器中第一个年份与当前选中值之间的距离，例如当前为 1997 年，距离为 50，则最早可选择年份为 1947 年 | number | 50 |
|yearSelectTotal| 年选择器中年份的总数，如最早可选为 1947 年，总数为 100，则可选年份范围为 1947 - 2047 | number | 100 |
|renderSidebar|sidebar|React Element|() => React.Node
|renderFooter|extra foot|React Element|() => React.Node


#### disabledTime 例子

``` javascript
function range(start, end) {
  const result = [];
  for (let i = start; i < end; i++) {
    result.push(i);
  }
  return result;
}

function disabledTime() {
  return {
    disabledHours: () => range(0, 24).splice(4, 20),
    disabledMinutes: () => range(30, 60),
    disabledSeconds: () => [55, 56],
  };
}
```

### MonthCalendar Props

|参数|说明|类型|默认值|
|---|----|---|------|
|value|日期|string/number|无|
|defaultValue|日期|string/number|无|
|format|展示的日期格式|string|'yyyy-MM'|
|allowedMonthRange|允许的月份范围,与disableDate互斥|object|

### YearCalendar Props

|参数|说明|类型|默认值|
|---|----|---|------|
|value|日期|string/number|无|
|defaultValue|日期|string/number|无|
|format|展示的日期格式|string|'yyyy'|

### RangeCalendar Props

参数基本与 Calendar 相同

|参数|说明|类型|默认值|
|---|----|---|------|
|value|日期|array|无|
|defaultValue|日期|array|无|
|quickSelectRanges|快捷日期选择|array|无|

####  RangeCalendar 例子
``` js
<RangeCalendar
    size="large"
    value={rangeValue}
    quickSelectRanges={[
        {
            text: '19年1、2月份',
            value: {
                start: '2019-01',
                end: '2019-02'
            }
        },
        {
            text: '18年S2',
            value: {
                start: '2018-09',
                end: '2019-03'
            }
        }
    ]}
    onSelect={(v, formatted) => {
      this.onRangeSelect(v, formatted);
    }}
/>
```

### CalendarFull props

|参数|说明|类型|可选值|默认值|
|------|----|---|------|-|
|value|日期|string/number|无||
|defaultValue|默认日期|string/number|||
|type|类型|string|time/week/month|'time'|
|startHour|面板开始时间（小时）|number||9|
|endHour|面板结束时间（小时）|number||23|
|step|面板间隔时间(分钟)|number||60|
|format|展示的日期格式|string|'YYYY-MM-DD'||
|disabledTime|不可选择的时间段，返回格式见下文|function(date)|||
|disabledDate|不可选择的时间日期|function(date)|||
|showHeader|是否显示头部|boolean|true||
|onSelect|当面板日期被选中时触发|function(date)|||
|onTypeChange|当切换面板类型时触发|function()|||
|weekRender|周视图面板中每个格子的渲染函数|function(current,formatDate)|||
|dateRender|月视图面板中每个格子的渲染函数|function(current,formatDate)|||
|timeRender|日视图面板中每个格子的渲染函数|function(current,formatDate)|||
|headerComponent|头部自定义组件|React Element|||
|headerRender|头部自定义渲染函数|function(current,type)|||
|scheduleRender|渲染面板中的函数，可以跨日程显示详情|Calendar.util.generateScheduleContent(events)|||
|getPopupContainer|指定渲染日程的容器|function|||


### MiniWeek props

|参数|说明|类型|可选值|默认值|
|------|----|---|------|-|
|locale|中英文|string|zh-cn/en|zh-cn|
|events|渲染的日程事件|array||[]|
|scheduleRender|用来渲染具体日程下的事件|function(dateInfo)|||

####  CalendarFull 例子
``` js
//events.js
const events =  [
  {
    start: '2018-10-24 13:00', // 事件开始时间
    end: '2018-10-31 23:00', // 事件结束时间
    // 事件的回调函数
    render: ({current,startHour,endHour,step,type}) => {}
  },
];
<CalendarFull
  value={this.state.value}
  onSelect={this.onSelect}
  type="month"
  locale="zh-cn"
  format="yyyy/MM/dd"
  scheduleRender={Calendar.util.generateScheduleContent(events)}
  startHour={12}
  endHour={18}
  step={40}
  />
```

####  MiniWeek 例子
```js
miniWeekRender(dateInfo){
  /**
   * 返回的dateInfo结构如下
   * {
   *   events: [],当前时间下的日程事件
   *   label: 当前时间是星期几
   *   value: 当前日期
   * }
  */
}

<MiniWeek
  locale="zh-cn"
  events={events}
  scheduleRender={this.miniWeekRender}
  >
  <div className="schedule-container">
    <h3>这是日程渲染事件</h3>
  </div
</MiniWeek>
```

```js
 <MiniWeek
  value="2018-12-24"
  locale="en-us"
  events={events}
  scheduleRender={this.miniWeekRender}
  getPopupContainer={() => this.miniRender}
/>
<div className="miniweek-container" ref={(c) => { this.miniRender = c; }} />
```


#### util

> 一些辅助函数，用于某些套餐化定制

* Calendar.util.generateContentRender(code, locale): 用于在日历上标注非常规的休假、上班以及日程。
    * code should be an object like this {'xxxx-xx-xx': ['work/leave/schedule']}
    * locale should be `zh-cn` or `en-us`

* Calendar.util.generateScheduleContent(events):用于在日历中展示跨日程详情
 > Tips:当不确定日程详情中是否有跨日程事件时，推荐使用scheduleRender
   events 为对象数组，格式如下：
```js
[{
    start: '2018-10-16 13:00',//事件开始时间
    end: '2018-10-16 14:00',//事件结束时间
    //事件的回调函数
    render: () => <div>10-10 </div>
}]
```

---
_Source: https://npm.io/package/uxcore-calendar · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
