This repository was archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathutil.js
89 lines (84 loc) · 1.81 KB
/
util.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
83
84
85
86
87
88
89
import moment from 'moment'
const _keyDownViewHelper = [
{
prev: false,
next: true,
exit: true,
unit: 'day',
upDown: 7
},
{
prev: true,
next: true,
unit: 'months',
upDown: 3
},
{
prev: true,
next: false,
unit: 'years',
upDown: 3
}
]
const KEYS = {
backspace: 8,
tab: 9,
enter: 13,
esc: 27,
left: 37,
up: 38,
right: 39,
down: 40
}
export default {
keyDownActions(code) {
const _viewHelper = _keyDownViewHelper[this.state.currentView]
const unit = _viewHelper.unit
const currentDate = this.state.date || moment().startOf('day')
switch (code) {
case KEYS.left:
this.setInternalDate(currentDate.subtract(1, unit))
break
case KEYS.right:
this.setInternalDate(currentDate.add(1, unit))
break
case KEYS.up:
this.setInternalDate(currentDate.subtract(_viewHelper.upDown, unit))
break
case KEYS.down:
this.setInternalDate(currentDate.add(_viewHelper.upDown, unit))
break
case KEYS.enter:
if (_viewHelper.prev) {
this.prevView(currentDate)
}
if (_viewHelper.exit) {
this.setInputDate(currentDate)
this.setVisibility(false)
}
break
case KEYS.esc:
this.setVisibility(false)
break
case KEYS.tab:
this.props.hideOnBlur && this.setVisibility(false)
break
default:
break
}
},
checkForMobile(hideTouchKeyboard) {
let readOnly = false
// do not break server side rendering:
try {
if (
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
) {
readOnly = true
}
} catch (e) {
console.warn(e) //eslint-disable-line
}
return readOnly
}
}