-
Notifications
You must be signed in to change notification settings - Fork 101
/
index.js
82 lines (74 loc) · 2.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import 'flatpickr/dist/themes/material_green.css'
import React, { Component } from 'react'
import { render } from 'react-dom'
import Flatpickr from '../lib/index.js'
class App extends Component {
state = {
v: '2016-01-01 01:01',
onChange: (_, str) => {
console.info(str)
}
}
componentDidMount() {
setTimeout(() => {
this.setState(state => ({
v: state.v.replace('2016', '2017'),
onChange: (_, str) => {
console.info('New change handler: ', str)
}
}))
}, 2000)
}
render() {
const { v } = this.state
return (
<main>
<Flatpickr data-enable-time className='test'
onChange={[
(_, str) => console.info(str),
() => {} // test hookPropType
]} />
<Flatpickr data-enable-time defaultValue='2016-11-11 11:11'
onChange={(_, str) => console.info(str)} />
<Flatpickr data-enable-time value={v}
onChange={(_, str) => console.info(str)} />
<Flatpickr value={v} options={{minDate: '2016-11-01'}}
onChange={(_, str) => console.info(str)} />
<Flatpickr value={[v, '2016-01-10']} options={{mode: 'range'}}
onChange={(_, str) => console.info(str)} />
<Flatpickr onChange={this.state.onChange}
onOpen={() => { console.info('opened (by prop)') }}
options={{
onClose: () => {
console.info('closed (by option)')
},
maxDate: new Date()
}} />
<Flatpickr value={new Date()}
onChange={(_, str) => console.info(str)} />
<Flatpickr value={v} options={{wrap: true}}
onChange={(_, str) => console.info(str)}
>
<input type='text' data-input />
<button type='button' data-toggle>Toggle</button>
<button type='button' data-clear>Clear</button>
</Flatpickr>
<Flatpickr
defaultValue='2019-05-05'
onCreate={(flatpickr) => { this.calendar = flatpickr }}
onDestroy={() => { delete this.calendar }}
render={({ defaultValue }, ref)=>{
return (
<div>
<input defaultValue={ defaultValue } ref={ref} />
<button onClick={() => this.calendar.setDate(new Date())}>Today</button>
</div>
)
}} />
</main>
)
}
}
window.init = () => {
render(<App />, document.querySelector('#container'))
}