beyond-rails 0.0.168 → 0.0.169

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 703ebdb0a1c1eb6e9455b1d5fd7fb59f213fc05982b9e28e88118355a8ebea4c
4
- data.tar.gz: 9762c05edd97cfeae03c7b463002ffc279e032fc25754b9f614ae73ce35b507e
3
+ metadata.gz: 49ec4ce14c6dc10a0421a4a1ea13e7e84d43e16733c0f03e5e24d08d868a861d
4
+ data.tar.gz: 207de6d5af44a0cd8e886cc99e04f2fabae1345a986a0f107ea58a9341913c6e
5
5
  SHA512:
6
- metadata.gz: c74193e9a1ddc3f99ff63b277722f542af50d84e9097caeb4ea23f449f0472356654d355285807fec523c28fb3c01a5532654313d0a46eb694e76972ebe924bb
7
- data.tar.gz: 1a03b4780d221cbd8d57e6d132bfded963ae81c0d902ffe72645d1a1867ba2f867b539da84d02b95a03a23d6e5d84a8c337c3210d5d713704248f3b1d5dbbd83
6
+ metadata.gz: e5c34deb7ade4b8f7e5c75a1c06729c363ddec9aa8d39566b3d215cd4895db48c79a82c8da51977e6bb09699dda59b114415f0143524f8688d57a718b0543d9d
7
+ data.tar.gz: 3229d5c3480d21320655a067c36b6fb597e74acf74348634796fb192c0213a66345dc87c6d8f8d812ba12d75ba1ce1ec25fdbb82e43c800dd6bac09c043d2f38
@@ -0,0 +1,131 @@
1
+ import parse from 'date-fns/parse'
2
+ import set from 'date-fns/set'
3
+ import noop from 'lodash.noop'
4
+ import TimeInput from './TimeInput'
5
+ import TimeMenu from './TimeMenu'
6
+ import supportDom from '../helpers/supportDom'
7
+ import { DEFAULT_TIMEZONE } from '../consts'
8
+ import dateToTimestamp from '@superlanding/datetotimestamp'
9
+ import timestampToDate from '@superlanding/timestamptodate'
10
+
11
+ @supportDom
12
+ export default class Timepicker {
13
+
14
+ constructor(dom, timestamp, options = {}) {
15
+ this.dom = dom
16
+ this.options = options
17
+ this.options.change = options.change || noop
18
+ this.tz = options.tz || DEFAULT_TIMEZONE
19
+
20
+ this.date = (timestamp === null) ? null : timestampToDate(timestamp)
21
+ this.focused = false
22
+ this.backdropMode = options.backdropMode || 'auto'
23
+ this.init()
24
+ }
25
+
26
+ init() {
27
+ this.timeInput = new TimeInput(
28
+ this.dom,
29
+ this.date,
30
+ this.options
31
+ )
32
+ this.timeMenu = new TimeMenu()
33
+ this.addEvents()
34
+ }
35
+
36
+ clearInputStatus() {
37
+ this.timeInput.clearStatus()
38
+ }
39
+
40
+ handleTimeInputFocus() {
41
+ const { timeInput } = this
42
+ this.focused = true
43
+ this.clearInputStatus()
44
+ timeInput.setActive(true)
45
+ this.timeMenu.show({ src: this.dom, date: timeInput.date })
46
+ }
47
+
48
+ handleTimeInputKeyUp(event) {
49
+ const { date, timeInput } = this
50
+ const { value } = event.target
51
+
52
+ if ((! timeInput.required) && (value === '')) {
53
+ this.nextDate = null
54
+ return
55
+ }
56
+ const res = parse(event.target.value, timeInput.timePattern, date)
57
+ this.nextDate = null
58
+
59
+ if (res.toString() === 'Invalid Date') {
60
+ return timeInput.setDanger(true)
61
+ }
62
+ timeInput.setDanger(false)
63
+ this.nextDate = res
64
+ }
65
+
66
+ handleTimeInputBlur() {
67
+ const { nextDate, date, timeInput } = this
68
+
69
+ if (nextDate) {
70
+ this.date = nextDate
71
+ timeInput.setDate(nextDate)
72
+ this.nextDate = null
73
+ }
74
+ else if (date) {
75
+ timeInput.setDate(date)
76
+ }
77
+ }
78
+
79
+ emitChange() {
80
+ const { date } = this
81
+ this.options.change({
82
+ date,
83
+ timestamp: dateToTimestamp(date)
84
+ })
85
+ }
86
+
87
+ hide() {
88
+ this.focused = false
89
+ this.clearInputStatus()
90
+ this.timeMenu.hide()
91
+ }
92
+
93
+ addEvents() {
94
+
95
+ this.timeInput.on('focus', () => this.handleTimeInputFocus())
96
+ this.timeInput.on('keyup', event => this.handleTimeInputKeyUp(event))
97
+ this.timeInput.on('blur', () => this.handleTimeInputBlur())
98
+
99
+ this.timeMenu.on('click', (event, res) => {
100
+ if (this.date === null) {
101
+ this.date = set(new Date(), { hours: res.hour, minutes: res.minute })
102
+ }
103
+ else {
104
+ this.date = set(this.date, { hours: res.hour, minutes: res.minute })
105
+ }
106
+ this.timeInput.setDate(this.date)
107
+ this.timeMenu.hide()
108
+ this.clearInputStatus()
109
+ this.emitChange()
110
+ })
111
+
112
+ this.addEvent(document, 'click', event => {
113
+ if (this.focused) {
114
+ this.focused = false
115
+ return
116
+ }
117
+ if (this.backdropMode === 'manual') {
118
+ return
119
+ }
120
+ if (event.target === this.dom) {
121
+ return
122
+ }
123
+ this.hide()
124
+ })
125
+ }
126
+
127
+ destroy() {
128
+ this.timeInput.destroy()
129
+ this.timeMenu.destroy()
130
+ }
131
+ }
data/src/js/index.js CHANGED
@@ -17,6 +17,7 @@ import Navbar from './components/Navbar'
17
17
  import Radio from './components/Radio'
18
18
  import SearchDropdown from './components/SearchDropdown'
19
19
  import Sidebar from './components/Sidebar'
20
+ import Timepicker from './components/Timepicker'
20
21
  import Tabbox from './components/Tabbox'
21
22
  import Toast from './components/Toast'
22
23
  import Tooltip from './components/Tooltip'
@@ -38,6 +39,7 @@ export {
38
39
  Radio,
39
40
  SearchDropdown,
40
41
  Sidebar,
42
+ Timepicker,
41
43
  Tabbox,
42
44
  Toast,
43
45
  Tooltip,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beyond-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.168
4
+ version: 0.0.169
5
5
  platform: ruby
6
6
  authors:
7
7
  - kmsheng
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-05-15 00:00:00.000000000 Z
12
+ date: 2020-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sassc
@@ -112,6 +112,7 @@ files:
112
112
  - src/js/components/Tabbox.js
113
113
  - src/js/components/TimeInput.js
114
114
  - src/js/components/TimeMenu.js
115
+ - src/js/components/Timepicker.js
115
116
  - src/js/components/Toast.js
116
117
  - src/js/components/ToastItem.js
117
118
  - src/js/components/Tooltip.js