├── .babelrc
├── .editorconfig
├── .gitignore
├── LICENSE
├── README.md
├── doc
└── index.md
├── examples
├── .gitignore
├── index.html
└── src
│ ├── components
│ ├── App.css
│ ├── App.js
│ ├── Example.css
│ ├── Example.js
│ └── MyTimePicker.js
│ ├── main.css
│ └── main.js
├── package.json
├── src
├── components
│ ├── Calendar.js
│ ├── DatePicker.js
│ ├── Day.js
│ ├── DaysOfWeek.js
│ ├── DaysViewHeading.js
│ ├── MonthSelector.js
│ └── MonthsViewHeading.js
├── index.js
├── styles
│ └── basic.css
└── utils
│ ├── assets.js
│ ├── moment-helper.js
│ └── persian.js
└── webpack.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "es2015",
4 | "stage-0",
5 | "react"
6 | ]
7 | }
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*]
2 | indent_style = space
3 | end_of_line = lf
4 | indent_size = 2
5 | charset = utf-8
6 | trim_trailing_whitespace = true
7 |
8 | [*.md]
9 | max_line_length = 0
10 | trim_trailing_whitespace = false
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Node template
3 | # Logs
4 | logs
5 | *.log
6 | npm-debug.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 |
13 | # Directory for instrumented libs generated by jscoverage/JSCover
14 | lib-cov
15 |
16 | # Coverage directory used by tools like istanbul
17 | coverage
18 |
19 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
20 | .grunt
21 |
22 | # node-waf configuration
23 | .lock-wscript
24 |
25 | # Compiled binary addons (http://nodejs.org/api/addons.html)
26 | build/Release
27 |
28 | # Dependency directories
29 | node_modules
30 | jspm_packages
31 |
32 | # Optional npm cache directory
33 | .npm
34 |
35 | # Optional REPL history
36 | .node_repl_history
37 |
38 | .idea
39 | lib
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Mohamad Mohebifar
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Persian Date Picker :calendar:
2 |
3 | [](https://www.gitcheese.com/donate/users/6104558/repos/43522564)
4 |
5 | [Persian calendar](https://en.wikipedia.org/wiki/Solar_Hijri_calendar) and date picker components for [React](https://facebook.github.io/react/). This is an open source project made in [@evandhq](https://github.com/evandhq) team.
6 |
7 | [See the demo.](https://evandhq.github.io/react-persian-datepicker)
8 |
9 |
10 | React Persian Date Picker مجموعهای از کامپوننتهای ReactJS مورد نیاز جهت ایجاد ورود و نمایش تاریخ هجری شمسی است. این نرمافزار متنباز در ایوند توسعه یافتهاست.
11 |
16 |
17 | # Installation
18 |
19 | Use npm to install the package:
20 |
21 | ```
22 | npm install react-persian-datepicker --save
23 | ```
24 |
25 | # Usage
26 | This package offers two components, `Calendar` and `DatePicker`. The first of which is a simple calendar that you can use in whichever way you want. The second one is an actual input with an input-ish behaviour.
27 |
28 | This package uses [moment-jalaali](https://github.com/jalaali/moment-jalaali) under the hood and all the values are basically moment objects.
29 |
30 | Below is a basic example.
31 |
32 | ```es6
33 | import React from 'react';
34 | import { Calendar, DatePicker } from 'react-persian-datepicker';
35 |
36 | const MyComponent = () => (
37 |
38 |
39 | {/* Calendar Component */}
40 |
41 |
42 |
43 |
44 | {/* Date Picker Component */}
45 |
46 |
47 |
48 | );
49 | ```
50 | # API Documentaion
51 | Current API documentation for **v3.0.2** is [available](https://github.com/evandhq/react-persian-datepicker/blob/master/doc/index.md) and for more examples [take a look at here](https://github.com/evandhq/react-persian-datepicker/blob/master/examples/src/components/App.js#L43).
52 |
53 | Note that you need `css-loader` for `/\.css$/` files enabled to have the styles working as we use css modules to put classnames in place. Otherwise, you'll have to pass an object of class names (like a css module) as `styles` prop. This way, you can develop your own stylesheet for the calendar according to the [basic one](https://github.com/evandhq/react-persian-datepicker/blob/master/src/styles/basic.css). The only thing that you will need to do is to require the css file that you made and pass it as `styles` prop to either `Calendar` or `DatePicker`.
54 |
--------------------------------------------------------------------------------
/doc/index.md:
--------------------------------------------------------------------------------
1 | # API Documentation
2 | This documentation is for **v3.0.2**. if you are using another version, you may update this file and make a PR. Contributions are totally welcomed ;)
3 |
4 | ## DatePicker
5 | A jalaali date picker component for react.
6 |
7 | ### Example
8 | ```
9 | import {DatePicker} from 'react-persian-datepicker'
10 | // or const DatePicker = require('react-persian-datepicker').DatePicker
11 |
12 | ...
13 | render () {
14 | return ;
15 | }
16 | ```
17 | For more examples please visit [github page](https://evandhq.github.io/react-persian-datepicker/) or see `examples/` directory.
18 |
19 | ### Options
20 |
21 | Property | Type | Default | Required | Description
22 | :-------------------|:------:|:--------------:|:--------:|:----------------------------------------
23 | value | object | null | | usable to create controlled datepicker, if `defaultValue` provided it takes it's value
24 | defaultValue | object | null | | sets default value for datepicker
25 | onChange | func | | | it sends updated `momentjs` object as argument to provided function. By default it sets the datepicker value, if you need to implement this, consider updating `value` accordingly
26 | onFocus | func | | | by default it makes datepicker visible. if you need to implement this, please see `handleFocus` method in the [source code](https://github.com/thg303/react-persian-datepicker/blob/master/src/components/DatePicker.js#L63)
27 | onBlur | func | | | it sends actual `blur` event as argument, by default it handles visibility and the value of the datepicker and then runs this callback.
28 | children | node | | | it is not used in this component, (propbably should be removed in the next version)
29 | min | object | | | accepts a `Date` or `Moment` object as the minimum value for datepicker
30 | max | object | | | accepts a `Date` or `Moment` object as the maximum value for datepicker
31 | defaultMonth| object | | | sets Calendar's default starting month, see `Calendar` documentations below for more details.
32 | inputFormat | string | "jYYYY/jM/jD" | | sets how date should appear in the input field. see [moment-jalaali documentations](https://github.com/jalaali/moment-jalaali) for more details
33 | removable | bool | | | it is not used in this component, (propbably should be removed in the next version)
34 | timePickerComponent | func | | | if provided, it would show up in the datepicker. it should be a React Component which accepts four properties: `min`, `max`, `momentValue`, `setMomentValue`, datepicker will send corrsendponding `min`, `max` and `momentValue` and uses `setMomentValue` which sets the datepicker value internally. for more details see the [source code](https://github.com/thg303/react-persian-datepicker/blob/master/src/components/DatePicker.js), you may also find an implemented TimePicker component at [examples/src/components/MyTimePicker.js](https://github.com/evandhq/react-persian-datepicker/blob/master/examples/src/components/MyTimePicker.js)
35 | calendarStyles| object | [basic.css](https://github.com/thg303/react-persian-datepicker/blob/master/src/styles/basic.css) | | css object which will be used in the `Calendar` component
36 | calendarContainerProps| object | `{}` | | this object will be passed as `containerProps` in the `Calendar` component
37 |
38 | ## Calendar
39 | A jalaali Calendar for react. It uses **Persian** locales by default.
40 |
41 | ### Example
42 | ```
43 | import {Calendar} from 'react-persian-datepicker'
44 | // or const Calendar = require('react-persian-datepicker').Calendar
45 |
46 | ...
47 | render () {
48 | return ;
49 | }
50 | ```
51 | For more examples please visit [github page](https://evandhq.github.io/react-persian-datepicker/) or see `examples/` directory.
52 |
53 | ### Options
54 |
55 | Property | Type | Default | Required | Description
56 | :-------------------|:------:|:--------------:|:--------:|:----------------------------------------
57 | min | object | | | accepts a `Date` or `Moment` object as the minimum day for Calendar
58 | max | object | | | accepts a `Date` or `Moment` object as the maximum day for Calendar
59 | styles | object | [basic.css](https://github.com/thg303/react-persian-datepicker/blob/master/src/styles/basic.css) | | css object which will be used.
60 | selectedDay | object | null | | sets default selected day
61 | defaultMonth| object | | | sets Calendar's default starting month, if not set, the `selectedDay`'s month will be used, if it was not set too, it sets current month.
62 | onSelect | func | | | if provided, it will be called after user clicked on a day. the `selectedDay` (moment object) will be passed as argument to the function.
63 | onClickOutside | func | | | if provided, it will be called after user clicked outside of calendar. it uses [react-onclickoutside package](https://github.com/Pomax/react-onclickoutside) and used by `DatePicker` component
64 | containerProps | object | `{}` | | it is not used in this component, (propbably should be removed in the next version)
65 |
66 | ## outsideClickIgnoreClass
67 | It is a simple string "ignore--click--outside" used as a class flag in CSS.
68 |
69 | ---
70 | Documentation by [thg303](https://github.com/thg303) at 2017/8/9
71 |
--------------------------------------------------------------------------------
/examples/.gitignore:
--------------------------------------------------------------------------------
1 | build.js
--------------------------------------------------------------------------------
/examples/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | React Persian Datepicker
6 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/examples/src/components/App.css:
--------------------------------------------------------------------------------
1 | :local(.jumbotron) {
2 | background-color: #216ba5;
3 | color: #dedede;
4 | text-align: center;
5 | padding: 20px;
6 | }
7 |
8 | :local(.jumbotron) a {
9 | color: #fff;
10 | text-decoration: none;
11 | }
12 |
13 | :local(.examples) {
14 | padding-top: 30px;
15 | }
--------------------------------------------------------------------------------
/examples/src/components/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Example from './Example';
3 | import styles from './App.css';
4 | import { Calendar, DatePicker } from '../../../src/index';
5 | import MyTimePicker from './MyTimePicker';
6 | import moment from 'moment-jalali';
7 |
8 | const generateRandomMoment = () => {
9 | return moment()
10 | .hour(Math.round(Math.random() * 23))
11 | .minute(Math.round(Math.random() * 60))
12 | .add(Math.round(Math.random() * 100), 'day');
13 | }
14 |
15 | export default class App extends Component {
16 | state = {
17 | value: moment(),
18 | someValue: new moment()
19 | };
20 |
21 | render() {
22 | return (
23 |