1 | // IGNORE IT -->
|
2 |
|
3 |
|
4 | # Better-datepicker
|
5 | A PC Datepicker
|
6 |
|
7 | ![](https://camo.githubusercontent.com/b39d1e12ba779319ff9bab0f56ba7e41f108d898/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a756d6f646164612f76756558696e2e737667)
|
8 | ![code-test](https://github.com/Js-Monkey/better-datepicker/workflows/code-test/badge.svg)
|
9 | ![](https://www.travis-ci.org/Js-Monkey/better-datepicker.svg?branch=master)
|
10 | ![](https://img.shields.io/codecov/c/github/js-monkey/better-datepicker/master.svg)
|
11 | ![](http://img.badgesize.io/https://unpkg.com/better-datepicker@0.0.7/dist/betterDatePicker.es5.js)
|
12 | [![install size](https://packagephobia.com/badge?p=better-datepicker)](https://packagephobia.com/result?p=better-datepicker)
|
13 |
|
14 | ## Doc
|
15 | https://js-monkey.github.io/better-datepicker/
|
16 |
|
17 | ## Demo
|
18 |
|
19 | <img width="240px" src="https://raw.githubusercontent.com/jumodada/img-store/main/better-datepciker-demo.png"/>
|
20 |
|
21 | ## Installing
|
22 |
|
23 | Using npm:
|
24 |
|
25 | ```bash
|
26 | $ npm i better-datepicker
|
27 | ```
|
28 |
|
29 | Using yarn:
|
30 |
|
31 | ```bash
|
32 | $ yarn add better-datepicker
|
33 | ```
|
34 |
|
35 | ## Usage
|
36 |
|
37 | es6
|
38 | ```js
|
39 | import {createDatePicker} from 'better-datepicker'
|
40 | import 'better-datepicker/index.css'
|
41 | ```
|
42 | CommonJS
|
43 |
|
44 | ```js
|
45 | const {createDatePicker} = require('better-datepicker').default
|
46 | require('better-datepicker/index.css')
|
47 | ```
|
48 |
|
49 |
|
50 | ## Example
|
51 |
|
52 | ```html
|
53 | <input type="text" id="input">
|
54 | ```
|
55 |
|
56 | ```js
|
57 | const input = document.querySelector('#input')
|
58 | createDatePicker(input,{
|
59 | placement: 'bottom',
|
60 | type: 'date',
|
61 | zIndex: 2000,
|
62 | format: 'yyyy/MM/dd'
|
63 | })
|
64 | ```
|
65 |
|
66 | you can also
|
67 |
|
68 | ```html
|
69 | <div id="wrapper">
|
70 | <span>Including children, find the first inputElement</span>
|
71 | <input type="text">
|
72 | </div>
|
73 | <script >
|
74 | const input = document.querySelector('#wrapper')
|
75 | createDatePicker(input,{
|
76 | placement: 'bottom',
|
77 | type: 'date',
|
78 | zIndex: 2000,
|
79 | format: 'yyyy/MM/dd'
|
80 | })
|
81 | </script>
|
82 | ```
|
83 |
|
84 | todo: support virtual dom
|
85 |
|
86 | # Options Validator
|
87 |
|
88 | If the format is illegal, it will use default value
|
89 |
|
90 | ## Options
|
91 |
|
92 | | Options | Description | Type | Accepted Values | Default |
|
93 | |---------|------------ |---------- |------------- |-------- |
|
94 | | type | Type of datepicker | string | date/date-range/month/month-range/year/year-range | date |
|
95 | | format | To set the date format | string | - | yyyy/mm/dd |
|
96 | | placement | Placement of datepicker | string | top/bottom/right/left | bottom |
|
97 | | disabledDate | Specifies the date that cannot be selected | function | - | - |
|
98 | | offset | Distance between Picker and inputElement | number | - | 12 |
|
99 | | insertTo | Name of the node inserted | string | body/parent | body |
|
100 | | binding | Bind the value of the inputElement | boolean | - | true |
|
101 | | themeColor | Theme color(selected、hover、range-start、range-end), like *#2ECC71* | string | - | -
|
102 | | rangeBgColor | The backgroundColor that element is in range ,It's usually lighter than the themeColor | string | - | -
|
103 |
|
104 |
|
105 |
|
106 | ## Instance methods
|
107 |
|
108 | | name | Description | params |
|
109 | |---------|------------ |------------ |
|
110 | | destroyed | destroyed the datepicker,clear InputElement value| -
|
111 | | onChange | called callback when date has changed |(callback)
|
112 | | update | Update configuration, remove old datepicker | (options)
|
113 | | getCurrentDate | get current date | -
|
114 | | open | open the datepicker | -
|
115 | | close | close the datepicker | -
|
116 | | clear | clear the date | -
|
117 |
|
118 | ## TODO LIST
|
119 |
|
120 | | versions | Description|
|
121 | |---------|------------ |
|
122 | | 0.2.0 | support week |
|
123 | | 0.3.0 | instance methods support open、close |
|
124 | | 0.5.0 | methods support set defaultOptions |
|
125 | | 0.7.0 | options support unlinkPanels、zIndex、readonly、disabled、default-value |
|
126 | | 0.9.0 | - |
|
127 |
|
128 | ## Browser support
|
129 |
|
130 | todo
|