buefy 0.9.12 → 0.9.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/dist/buefy.css +1 -1
  2. package/dist/buefy.esm.js +106 -104
  3. package/dist/buefy.esm.min.js +2 -2
  4. package/dist/buefy.js +106 -104
  5. package/dist/buefy.min.css +1 -1
  6. package/dist/buefy.min.js +2 -2
  7. package/dist/cjs/autocomplete.js +4 -4
  8. package/dist/cjs/button.js +2 -2
  9. package/dist/cjs/carousel.js +5 -5
  10. package/dist/cjs/{chunk-47e1b22b.js → chunk-114191ae.js} +2 -2
  11. package/dist/cjs/{chunk-db3fa73a.js → chunk-2062216d.js} +1 -1
  12. package/dist/cjs/{chunk-d9a33552.js → chunk-2911aa4b.js} +45 -45
  13. package/dist/cjs/{chunk-de7a7f98.js → chunk-2ae50815.js} +3 -3
  14. package/dist/cjs/{chunk-01268607.js → chunk-2c7de785.js} +0 -0
  15. package/dist/cjs/{chunk-30d55827.js → chunk-30670fac.js} +2 -2
  16. package/dist/cjs/{chunk-c3495010.js → chunk-34949503.js} +0 -0
  17. package/dist/cjs/{chunk-2dc027c9.js → chunk-3cc5d9a6.js} +0 -0
  18. package/dist/cjs/{chunk-a14ca5bf.js → chunk-61023b09.js} +1 -1
  19. package/dist/cjs/{chunk-c5a552d4.js → chunk-6cb902f8.js} +0 -0
  20. package/dist/cjs/{chunk-7b13241d.js → chunk-7da0c017.js} +4 -2
  21. package/dist/cjs/{chunk-bd1feb6c.js → chunk-9e4cf4c5.js} +0 -0
  22. package/dist/cjs/{chunk-ea7e1e7e.js → chunk-a11294f9.js} +1 -1
  23. package/dist/cjs/{chunk-3aaecc36.js → chunk-c6fbc7b4.js} +1 -1
  24. package/dist/cjs/{chunk-dcf024d2.js → chunk-c7b2aa4b.js} +0 -0
  25. package/dist/cjs/{chunk-40697b2f.js → chunk-d0f8ea39.js} +6 -6
  26. package/dist/cjs/{chunk-c00639be.js → chunk-d120e215.js} +0 -0
  27. package/dist/cjs/{chunk-cb3ee6f4.js → chunk-d54e40f6.js} +0 -0
  28. package/dist/cjs/{chunk-adaa5792.js → chunk-f5106717.js} +2 -2
  29. package/dist/cjs/{chunk-66710d19.js → chunk-fe2f57ee.js} +1 -1
  30. package/dist/cjs/{chunk-344f6275.js → chunk-fefd7b77.js} +0 -0
  31. package/dist/cjs/clockpicker.js +7 -7
  32. package/dist/cjs/datepicker.js +8 -8
  33. package/dist/cjs/datetimepicker.js +10 -10
  34. package/dist/cjs/dialog.js +10 -10
  35. package/dist/cjs/dropdown.js +2 -2
  36. package/dist/cjs/field.js +1 -1
  37. package/dist/cjs/helpers.js +50 -50
  38. package/dist/cjs/icon.js +1 -1
  39. package/dist/cjs/image.js +1 -1
  40. package/dist/cjs/index.js +21 -21
  41. package/dist/cjs/input.js +3 -3
  42. package/dist/cjs/loading.js +1 -1
  43. package/dist/cjs/menu.js +1 -1
  44. package/dist/cjs/message.js +2 -2
  45. package/dist/cjs/modal.js +1 -1
  46. package/dist/cjs/notification.js +3 -3
  47. package/dist/cjs/numberinput.js +6 -6
  48. package/dist/cjs/pagination.js +2 -2
  49. package/dist/cjs/progress.js +1 -1
  50. package/dist/cjs/rate.js +1 -1
  51. package/dist/cjs/select.js +3 -3
  52. package/dist/cjs/slider.js +1 -1
  53. package/dist/cjs/snackbar.js +1 -1
  54. package/dist/cjs/steps.js +4 -4
  55. package/dist/cjs/table.js +7 -7
  56. package/dist/cjs/tabs.js +4 -4
  57. package/dist/cjs/taginput.js +4 -4
  58. package/dist/cjs/timepicker.js +9 -9
  59. package/dist/cjs/toast.js +1 -1
  60. package/dist/cjs/tooltip.js +1 -1
  61. package/dist/cjs/upload.js +1 -1
  62. package/dist/components/autocomplete/index.js +5 -5
  63. package/dist/components/autocomplete/index.min.js +1 -1
  64. package/dist/components/breadcrumb/index.js +1 -1
  65. package/dist/components/breadcrumb/index.min.js +1 -1
  66. package/dist/components/button/index.js +3 -3
  67. package/dist/components/button/index.min.js +1 -1
  68. package/dist/components/carousel/index.js +26 -26
  69. package/dist/components/carousel/index.min.js +1 -1
  70. package/dist/components/checkbox/index.js +1 -1
  71. package/dist/components/checkbox/index.min.js +1 -1
  72. package/dist/components/clockpicker/index.js +22 -20
  73. package/dist/components/clockpicker/index.min.js +2 -2
  74. package/dist/components/collapse/index.js +1 -1
  75. package/dist/components/collapse/index.min.js +1 -1
  76. package/dist/components/datepicker/index.js +71 -69
  77. package/dist/components/datepicker/index.min.js +2 -2
  78. package/dist/components/datetimepicker/index.js +71 -69
  79. package/dist/components/datetimepicker/index.min.js +2 -2
  80. package/dist/components/dialog/index.js +10 -10
  81. package/dist/components/dialog/index.min.js +1 -1
  82. package/dist/components/dropdown/index.js +6 -6
  83. package/dist/components/dropdown/index.min.js +1 -1
  84. package/dist/components/field/index.js +5 -3
  85. package/dist/components/field/index.min.js +2 -2
  86. package/dist/components/icon/index.js +3 -3
  87. package/dist/components/icon/index.min.js +1 -1
  88. package/dist/components/image/index.js +4 -4
  89. package/dist/components/image/index.min.js +1 -1
  90. package/dist/components/input/index.js +3 -3
  91. package/dist/components/input/index.min.js +1 -1
  92. package/dist/components/loading/index.js +3 -3
  93. package/dist/components/loading/index.min.js +1 -1
  94. package/dist/components/menu/index.js +3 -3
  95. package/dist/components/menu/index.min.js +1 -1
  96. package/dist/components/message/index.js +3 -3
  97. package/dist/components/message/index.min.js +1 -1
  98. package/dist/components/modal/index.js +3 -3
  99. package/dist/components/modal/index.min.js +1 -1
  100. package/dist/components/navbar/index.js +1 -1
  101. package/dist/components/navbar/index.min.js +1 -1
  102. package/dist/components/notification/index.js +3 -3
  103. package/dist/components/notification/index.min.js +1 -1
  104. package/dist/components/numberinput/index.js +6 -6
  105. package/dist/components/numberinput/index.min.js +1 -1
  106. package/dist/components/pagination/index.js +3 -3
  107. package/dist/components/pagination/index.min.js +1 -1
  108. package/dist/components/progress/index.js +6 -6
  109. package/dist/components/progress/index.min.js +1 -1
  110. package/dist/components/radio/index.js +1 -1
  111. package/dist/components/radio/index.min.js +1 -1
  112. package/dist/components/rate/index.js +3 -3
  113. package/dist/components/rate/index.min.js +1 -1
  114. package/dist/components/select/index.js +3 -3
  115. package/dist/components/select/index.min.js +1 -1
  116. package/dist/components/sidebar/index.js +1 -1
  117. package/dist/components/sidebar/index.min.js +1 -1
  118. package/dist/components/skeleton/index.js +1 -1
  119. package/dist/components/skeleton/index.min.js +1 -1
  120. package/dist/components/slider/index.js +7 -7
  121. package/dist/components/slider/index.min.js +1 -1
  122. package/dist/components/snackbar/index.js +3 -3
  123. package/dist/components/snackbar/index.min.js +1 -1
  124. package/dist/components/steps/index.js +14 -14
  125. package/dist/components/steps/index.min.js +1 -1
  126. package/dist/components/switch/index.js +1 -1
  127. package/dist/components/switch/index.min.js +1 -1
  128. package/dist/components/table/index.js +10 -10
  129. package/dist/components/table/index.min.js +1 -1
  130. package/dist/components/tabs/index.js +14 -14
  131. package/dist/components/tabs/index.min.js +1 -1
  132. package/dist/components/tag/index.js +1 -1
  133. package/dist/components/tag/index.min.js +1 -1
  134. package/dist/components/taginput/index.js +5 -5
  135. package/dist/components/taginput/index.min.js +1 -1
  136. package/dist/components/timepicker/index.js +22 -20
  137. package/dist/components/timepicker/index.min.js +2 -2
  138. package/dist/components/toast/index.js +3 -3
  139. package/dist/components/toast/index.min.js +1 -1
  140. package/dist/components/tooltip/index.js +1 -1
  141. package/dist/components/tooltip/index.min.js +1 -1
  142. package/dist/components/upload/index.js +1 -1
  143. package/dist/components/upload/index.min.js +1 -1
  144. package/dist/esm/autocomplete.js +5 -5
  145. package/dist/esm/button.js +3 -3
  146. package/dist/esm/carousel.js +5 -5
  147. package/dist/esm/{chunk-3dbb54cd.js → chunk-18e8b067.js} +1 -1
  148. package/dist/esm/{chunk-7d9db167.js → chunk-21fc0948.js} +6 -6
  149. package/dist/esm/{chunk-a146937d.js → chunk-22e9f916.js} +45 -45
  150. package/dist/esm/{chunk-18fcd4ac.js → chunk-29ca0df8.js} +0 -0
  151. package/dist/esm/{chunk-affd6df1.js → chunk-3773c62d.js} +0 -0
  152. package/dist/esm/{chunk-7ee6c15c.js → chunk-4b67a181.js} +1 -1
  153. package/dist/esm/{chunk-f97f6a90.js → chunk-6019fd7a.js} +2 -2
  154. package/dist/esm/{chunk-d9794c38.js → chunk-71a547bc.js} +0 -0
  155. package/dist/esm/{chunk-161dac72.js → chunk-75a5af93.js} +0 -0
  156. package/dist/esm/{chunk-4f046bae.js → chunk-799e084d.js} +0 -0
  157. package/dist/esm/{chunk-6b53dd42.js → chunk-83eb0d37.js} +2 -2
  158. package/dist/esm/{chunk-80ec133b.js → chunk-8d0f95b8.js} +3 -3
  159. package/dist/esm/{chunk-50188ced.js → chunk-9f7f7441.js} +0 -0
  160. package/dist/esm/{chunk-3098b0e9.js → chunk-ae8ab23a.js} +2 -2
  161. package/dist/esm/{chunk-0f30042f.js → chunk-b07e3182.js} +4 -2
  162. package/dist/esm/{chunk-a64bdef6.js → chunk-b0c0c6b0.js} +0 -0
  163. package/dist/esm/{chunk-cdfb7fda.js → chunk-c9c58d0c.js} +0 -0
  164. package/dist/esm/{chunk-f6b30428.js → chunk-d7f92d97.js} +1 -1
  165. package/dist/esm/{chunk-9957ac1a.js → chunk-d92f0cd9.js} +0 -0
  166. package/dist/esm/{chunk-72ad8d50.js → chunk-e7c9b2cb.js} +1 -1
  167. package/dist/esm/{chunk-8b279c1f.js → chunk-ece062a7.js} +1 -1
  168. package/dist/esm/clockpicker.js +7 -7
  169. package/dist/esm/datepicker.js +9 -9
  170. package/dist/esm/datetimepicker.js +10 -10
  171. package/dist/esm/dialog.js +10 -10
  172. package/dist/esm/dropdown.js +3 -3
  173. package/dist/esm/field.js +2 -2
  174. package/dist/esm/helpers.js +50 -50
  175. package/dist/esm/icon.js +2 -2
  176. package/dist/esm/image.js +2 -2
  177. package/dist/esm/index.js +21 -21
  178. package/dist/esm/input.js +4 -4
  179. package/dist/esm/loading.js +2 -2
  180. package/dist/esm/menu.js +1 -1
  181. package/dist/esm/message.js +2 -2
  182. package/dist/esm/modal.js +2 -2
  183. package/dist/esm/notification.js +3 -3
  184. package/dist/esm/numberinput.js +6 -6
  185. package/dist/esm/pagination.js +3 -3
  186. package/dist/esm/progress.js +1 -1
  187. package/dist/esm/rate.js +1 -1
  188. package/dist/esm/select.js +4 -4
  189. package/dist/esm/slider.js +1 -1
  190. package/dist/esm/snackbar.js +1 -1
  191. package/dist/esm/steps.js +4 -4
  192. package/dist/esm/table.js +7 -7
  193. package/dist/esm/tabs.js +4 -4
  194. package/dist/esm/taginput.js +4 -4
  195. package/dist/esm/timepicker.js +10 -10
  196. package/dist/esm/toast.js +1 -1
  197. package/dist/esm/tooltip.js +2 -2
  198. package/dist/esm/upload.js +1 -1
  199. package/package.json +171 -171
  200. package/src/components/breadcrumb/BreadcrumbItem.spec.js +25 -25
  201. package/src/components/carousel/CarouselList.vue +313 -313
  202. package/src/components/carousel/__snapshots__/CarouselList.spec.js.snap +156 -156
  203. package/src/components/datepicker/Datepicker.vue +843 -843
  204. package/src/components/dialog/Dialog.vue +256 -256
  205. package/src/components/field/Field.vue +3 -3
  206. package/src/components/image/Image.vue +309 -309
  207. package/src/components/numberinput/Numberinput.vue +309 -309
  208. package/src/utils/helpers.js +291 -291
@@ -1,309 +1,309 @@
1
- <template>
2
- <div class="b-numberinput field" :class="fieldClasses">
3
- <p
4
- v-for="control in controlsLeft"
5
- :key="control"
6
- :class="['control', control]"
7
- @mouseup="onStopLongPress"
8
- @mouseleave="onStopLongPress"
9
- @touchend="onStopLongPress"
10
- @touchcancel="onStopLongPress"
11
- >
12
- <button
13
- type="button"
14
- class="button"
15
- :class="buttonClasses"
16
- :disabled="isDisabled(control)"
17
- :aria-label="control === 'plus' ? ariaPlusLabel : ariaMinusLabel"
18
- @mousedown="
19
- !isDisabled(control) && onStartLongPress($event, control === 'plus')
20
- "
21
- @touchstart.prevent="
22
- !isDisabled(control) && onStartLongPress($event, control === 'plus')
23
- "
24
- @click="
25
- !isDisabled(control) && onControlClick($event, control === 'plus')
26
- "
27
- >
28
- <b-icon
29
- both
30
- :icon="control"
31
- :pack="iconPack"
32
- :size="iconSize" />
33
- </button>
34
- </p>
35
- <b-input
36
- type="number"
37
- ref="input"
38
- v-model="computedValue"
39
- v-bind="$attrs"
40
- :step="minStepNumber"
41
- :max="max"
42
- :min="min"
43
- :size="size"
44
- :disabled="disabled"
45
- :readonly="!editable"
46
- :loading="loading"
47
- :rounded="rounded"
48
- :icon="icon"
49
- :icon-pack="iconPack"
50
- :autocomplete="autocomplete"
51
- :expanded="expanded"
52
- :placeholder="placeholder"
53
- :use-html5-validation="useHtml5Validation"
54
- @focus="$emit('focus', $event)"
55
- @blur="$emit('blur', $event)"
56
- />
57
-
58
- <p
59
- v-for="control in controlsRight"
60
- :key="control"
61
- :class="['control', control]"
62
- @mouseup="onStopLongPress"
63
- @mouseleave="onStopLongPress"
64
- @touchend="onStopLongPress"
65
- @touchcancel="onStopLongPress"
66
- >
67
- <button
68
- type="button"
69
- class="button"
70
- :class="buttonClasses"
71
- :disabled="isDisabled(control)"
72
- :aria-label="control === 'plus' ? ariaPlusLabel : ariaMinusLabel"
73
- @mousedown="
74
- !isDisabled(control) && onStartLongPress($event, control === 'plus')
75
- "
76
- @touchstart.prevent="
77
- !isDisabled(control) && onStartLongPress($event, control === 'plus')
78
- "
79
- @click="
80
- !isDisabled(control) && onControlClick($event, control === 'plus')
81
- "
82
- >
83
- <b-icon
84
- both
85
- :icon="control"
86
- :pack="iconPack"
87
- :size="iconSize" />
88
- </button>
89
- </p>
90
- </div>
91
- </template>
92
-
93
- <script>
94
- import Icon from '../icon/Icon'
95
- import Input from '../input/Input'
96
- import FormElementMixin from '../../utils/FormElementMixin'
97
-
98
- export default {
99
- name: 'BNumberinput',
100
- components: {
101
- [Icon.name]: Icon,
102
- [Input.name]: Input
103
- },
104
- mixins: [FormElementMixin],
105
- inheritAttrs: false,
106
- props: {
107
- value: Number,
108
- min: {
109
- type: [Number, String]
110
- },
111
- max: [Number, String],
112
- step: [Number, String],
113
- minStep: [Number, String],
114
- exponential: [Boolean, Number],
115
- disabled: Boolean,
116
- type: {
117
- type: String,
118
- default: 'is-primary'
119
- },
120
- editable: {
121
- type: Boolean,
122
- default: true
123
- },
124
- controls: {
125
- type: Boolean,
126
- default: true
127
- },
128
- controlsAlignment: {
129
- type: String,
130
- default: 'center',
131
- validator: (value) => {
132
- return [
133
- 'left',
134
- 'right',
135
- 'center'
136
- ].indexOf(value) >= 0
137
- }
138
- },
139
- controlsRounded: {
140
- type: Boolean,
141
- default: false
142
- },
143
- controlsPosition: String,
144
- placeholder: [Number, String],
145
- ariaMinusLabel: String,
146
- ariaPlusLabel: String
147
- },
148
- data() {
149
- return {
150
- newValue: this.value,
151
- newStep: this.step || 1,
152
- newMinStep: this.minStep,
153
- timesPressed: 1,
154
- _elementRef: 'input'
155
- }
156
- },
157
- computed: {
158
- computedValue: {
159
- get() {
160
- return this.newValue
161
- },
162
- set(value) {
163
- let newValue = Number(value) || null
164
- if (value === '' || value === undefined || value === null) {
165
- if (this.minNumber !== undefined) {
166
- newValue = this.minNumber
167
- } else {
168
- newValue = null
169
- }
170
- }
171
- this.newValue = newValue
172
- if (newValue === null) {
173
- this.$emit('input', newValue)
174
- } else if (!isNaN(newValue) && newValue !== '-0') {
175
- this.$emit('input', Number(newValue))
176
- }
177
- this.$nextTick(() => {
178
- if (this.$refs.input) {
179
- this.$refs.input.checkHtml5Validity()
180
- }
181
- })
182
- }
183
- },
184
- controlsLeft() {
185
- if (this.controls && this.controlsAlignment !== 'right') {
186
- return this.controlsAlignment === 'left' ? ['minus', 'plus'] : ['minus']
187
- }
188
- return []
189
- },
190
- controlsRight() {
191
- if (this.controls && this.controlsAlignment !== 'left') {
192
- return this.controlsAlignment === 'right' ? ['minus', 'plus'] : ['plus']
193
- }
194
- return []
195
- },
196
- fieldClasses() {
197
- return [
198
- { 'has-addons': this.controlsPosition === 'compact' },
199
- { 'is-grouped': this.controlsPosition !== 'compact' },
200
- { 'is-expanded': this.expanded }
201
- ]
202
- },
203
- buttonClasses() {
204
- return [this.type, this.size, { 'is-rounded': this.controlsRounded }]
205
- },
206
- minNumber() {
207
- return typeof this.min === 'string' ? parseFloat(this.min) : this.min
208
- },
209
- maxNumber() {
210
- return typeof this.max === 'string' ? parseFloat(this.max) : this.max
211
- },
212
- stepNumber() {
213
- return typeof this.newStep === 'string' ? parseFloat(this.newStep) : this.newStep
214
- },
215
- minStepNumber() {
216
- const step = typeof this.newMinStep !== 'undefined' ? this.newMinStep : this.newStep
217
- return typeof step === 'string' ? parseFloat(step) : step
218
- },
219
- disabledMin() {
220
- return this.computedValue - this.stepNumber < this.minNumber
221
- },
222
- disabledMax() {
223
- return this.computedValue + this.stepNumber > this.maxNumber
224
- },
225
- stepDecimals() {
226
- const step = this.minStepNumber.toString()
227
- const index = step.indexOf('.')
228
- if (index >= 0) {
229
- return step.substring(index + 1).length
230
- }
231
- return 0
232
- }
233
- },
234
- watch: {
235
- /**
236
- * When v-model is changed:
237
- * 1. Set internal value.
238
- */
239
- value: {
240
- immediate: true,
241
- handler(value) {
242
- this.newValue = value
243
- }
244
- },
245
- step(value) {
246
- this.newStep = value
247
- },
248
- minStep(value) {
249
- this.newMinStep = value
250
- }
251
- },
252
- methods: {
253
- isDisabled(control) {
254
- return this.disabled || (control === 'plus' ? this.disabledMax : this.disabledMin)
255
- },
256
- decrement() {
257
- if (typeof this.minNumber === 'undefined' || this.computedValue - this.stepNumber >= this.minNumber) {
258
- if (this.computedValue === null || typeof this.computedValue === 'undefined') {
259
- if (this.maxNumber) {
260
- this.computedValue = this.maxNumber
261
- return
262
- }
263
- this.computedValue = 0
264
- }
265
- const value = this.computedValue - this.stepNumber
266
- this.computedValue = parseFloat(value.toFixed(this.stepDecimals))
267
- }
268
- },
269
- increment() {
270
- if (typeof this.maxNumber === 'undefined' || this.computedValue + this.stepNumber <= this.maxNumber) {
271
- if (this.computedValue === null || typeof this.computedValue === 'undefined') {
272
- if (this.minNumber) {
273
- this.computedValue = this.minNumber
274
- return
275
- }
276
- this.computedValue = 0
277
- }
278
- const value = this.computedValue + this.stepNumber
279
- this.computedValue = parseFloat(value.toFixed(this.stepDecimals))
280
- }
281
- },
282
- onControlClick(event, inc) {
283
- // IE 11 -> filter click event
284
- if (event.detail !== 0 || event.type !== 'click') return
285
- if (inc) this.increment()
286
- else this.decrement()
287
- },
288
- longPressTick(inc) {
289
- if (inc) this.increment()
290
- else this.decrement()
291
-
292
- this._$intervalRef = setTimeout(() => {
293
- this.longPressTick(inc)
294
- }, this.exponential ? (250 / (this.exponential * this.timesPressed++)) : 250)
295
- },
296
- onStartLongPress(event, inc) {
297
- if (event.button !== 0 && event.type !== 'touchstart') return
298
- clearTimeout(this._$intervalRef)
299
- this.longPressTick(inc)
300
- },
301
- onStopLongPress() {
302
- if (!this._$intervalRef) return
303
- this.timesPressed = 1
304
- clearTimeout(this._$intervalRef)
305
- this._$intervalRef = null
306
- }
307
- }
308
- }
309
- </script>
1
+ <template>
2
+ <div class="b-numberinput field" :class="fieldClasses">
3
+ <p
4
+ v-for="control in controlsLeft"
5
+ :key="control"
6
+ :class="['control', control]"
7
+ @mouseup="onStopLongPress"
8
+ @mouseleave="onStopLongPress"
9
+ @touchend="onStopLongPress"
10
+ @touchcancel="onStopLongPress"
11
+ >
12
+ <button
13
+ type="button"
14
+ class="button"
15
+ :class="buttonClasses"
16
+ :disabled="isDisabled(control)"
17
+ :aria-label="control === 'plus' ? ariaPlusLabel : ariaMinusLabel"
18
+ @mousedown="
19
+ !isDisabled(control) && onStartLongPress($event, control === 'plus')
20
+ "
21
+ @touchstart.prevent="
22
+ !isDisabled(control) && onStartLongPress($event, control === 'plus')
23
+ "
24
+ @click="
25
+ !isDisabled(control) && onControlClick($event, control === 'plus')
26
+ "
27
+ >
28
+ <b-icon
29
+ both
30
+ :icon="control"
31
+ :pack="iconPack"
32
+ :size="iconSize" />
33
+ </button>
34
+ </p>
35
+ <b-input
36
+ type="number"
37
+ ref="input"
38
+ v-model="computedValue"
39
+ v-bind="$attrs"
40
+ :step="minStepNumber"
41
+ :max="max"
42
+ :min="min"
43
+ :size="size"
44
+ :disabled="disabled"
45
+ :readonly="!editable"
46
+ :loading="loading"
47
+ :rounded="rounded"
48
+ :icon="icon"
49
+ :icon-pack="iconPack"
50
+ :autocomplete="autocomplete"
51
+ :expanded="expanded"
52
+ :placeholder="placeholder"
53
+ :use-html5-validation="useHtml5Validation"
54
+ @focus="$emit('focus', $event)"
55
+ @blur="$emit('blur', $event)"
56
+ />
57
+
58
+ <p
59
+ v-for="control in controlsRight"
60
+ :key="control"
61
+ :class="['control', control]"
62
+ @mouseup="onStopLongPress"
63
+ @mouseleave="onStopLongPress"
64
+ @touchend="onStopLongPress"
65
+ @touchcancel="onStopLongPress"
66
+ >
67
+ <button
68
+ type="button"
69
+ class="button"
70
+ :class="buttonClasses"
71
+ :disabled="isDisabled(control)"
72
+ :aria-label="control === 'plus' ? ariaPlusLabel : ariaMinusLabel"
73
+ @mousedown="
74
+ !isDisabled(control) && onStartLongPress($event, control === 'plus')
75
+ "
76
+ @touchstart.prevent="
77
+ !isDisabled(control) && onStartLongPress($event, control === 'plus')
78
+ "
79
+ @click="
80
+ !isDisabled(control) && onControlClick($event, control === 'plus')
81
+ "
82
+ >
83
+ <b-icon
84
+ both
85
+ :icon="control"
86
+ :pack="iconPack"
87
+ :size="iconSize" />
88
+ </button>
89
+ </p>
90
+ </div>
91
+ </template>
92
+
93
+ <script>
94
+ import Icon from '../icon/Icon'
95
+ import Input from '../input/Input'
96
+ import FormElementMixin from '../../utils/FormElementMixin'
97
+
98
+ export default {
99
+ name: 'BNumberinput',
100
+ components: {
101
+ [Icon.name]: Icon,
102
+ [Input.name]: Input
103
+ },
104
+ mixins: [FormElementMixin],
105
+ inheritAttrs: false,
106
+ props: {
107
+ value: Number,
108
+ min: {
109
+ type: [Number, String]
110
+ },
111
+ max: [Number, String],
112
+ step: [Number, String],
113
+ minStep: [Number, String],
114
+ exponential: [Boolean, Number],
115
+ disabled: Boolean,
116
+ type: {
117
+ type: String,
118
+ default: 'is-primary'
119
+ },
120
+ editable: {
121
+ type: Boolean,
122
+ default: true
123
+ },
124
+ controls: {
125
+ type: Boolean,
126
+ default: true
127
+ },
128
+ controlsAlignment: {
129
+ type: String,
130
+ default: 'center',
131
+ validator: (value) => {
132
+ return [
133
+ 'left',
134
+ 'right',
135
+ 'center'
136
+ ].indexOf(value) >= 0
137
+ }
138
+ },
139
+ controlsRounded: {
140
+ type: Boolean,
141
+ default: false
142
+ },
143
+ controlsPosition: String,
144
+ placeholder: [Number, String],
145
+ ariaMinusLabel: String,
146
+ ariaPlusLabel: String
147
+ },
148
+ data() {
149
+ return {
150
+ newValue: this.value,
151
+ newStep: this.step || 1,
152
+ newMinStep: this.minStep,
153
+ timesPressed: 1,
154
+ _elementRef: 'input'
155
+ }
156
+ },
157
+ computed: {
158
+ computedValue: {
159
+ get() {
160
+ return this.newValue
161
+ },
162
+ set(value) {
163
+ let newValue = Number(value) || null
164
+ if (value === '' || value === undefined || value === null) {
165
+ if (this.minNumber !== undefined) {
166
+ newValue = this.minNumber
167
+ } else {
168
+ newValue = null
169
+ }
170
+ }
171
+ this.newValue = newValue
172
+ if (newValue === null) {
173
+ this.$emit('input', newValue)
174
+ } else if (!isNaN(newValue) && newValue !== '-0') {
175
+ this.$emit('input', Number(newValue))
176
+ }
177
+ this.$nextTick(() => {
178
+ if (this.$refs.input) {
179
+ this.$refs.input.checkHtml5Validity()
180
+ }
181
+ })
182
+ }
183
+ },
184
+ controlsLeft() {
185
+ if (this.controls && this.controlsAlignment !== 'right') {
186
+ return this.controlsAlignment === 'left' ? ['minus', 'plus'] : ['minus']
187
+ }
188
+ return []
189
+ },
190
+ controlsRight() {
191
+ if (this.controls && this.controlsAlignment !== 'left') {
192
+ return this.controlsAlignment === 'right' ? ['minus', 'plus'] : ['plus']
193
+ }
194
+ return []
195
+ },
196
+ fieldClasses() {
197
+ return [
198
+ { 'has-addons': this.controlsPosition === 'compact' },
199
+ { 'is-grouped': this.controlsPosition !== 'compact' },
200
+ { 'is-expanded': this.expanded }
201
+ ]
202
+ },
203
+ buttonClasses() {
204
+ return [this.type, this.size, { 'is-rounded': this.controlsRounded }]
205
+ },
206
+ minNumber() {
207
+ return typeof this.min === 'string' ? parseFloat(this.min) : this.min
208
+ },
209
+ maxNumber() {
210
+ return typeof this.max === 'string' ? parseFloat(this.max) : this.max
211
+ },
212
+ stepNumber() {
213
+ return typeof this.newStep === 'string' ? parseFloat(this.newStep) : this.newStep
214
+ },
215
+ minStepNumber() {
216
+ const step = typeof this.newMinStep !== 'undefined' ? this.newMinStep : this.newStep
217
+ return typeof step === 'string' ? parseFloat(step) : step
218
+ },
219
+ disabledMin() {
220
+ return this.computedValue - this.stepNumber < this.minNumber
221
+ },
222
+ disabledMax() {
223
+ return this.computedValue + this.stepNumber > this.maxNumber
224
+ },
225
+ stepDecimals() {
226
+ const step = this.minStepNumber.toString()
227
+ const index = step.indexOf('.')
228
+ if (index >= 0) {
229
+ return step.substring(index + 1).length
230
+ }
231
+ return 0
232
+ }
233
+ },
234
+ watch: {
235
+ /**
236
+ * When v-model is changed:
237
+ * 1. Set internal value.
238
+ */
239
+ value: {
240
+ immediate: true,
241
+ handler(value) {
242
+ this.newValue = value
243
+ }
244
+ },
245
+ step(value) {
246
+ this.newStep = value
247
+ },
248
+ minStep(value) {
249
+ this.newMinStep = value
250
+ }
251
+ },
252
+ methods: {
253
+ isDisabled(control) {
254
+ return this.disabled || (control === 'plus' ? this.disabledMax : this.disabledMin)
255
+ },
256
+ decrement() {
257
+ if (typeof this.minNumber === 'undefined' || this.computedValue - this.stepNumber >= this.minNumber) {
258
+ if (this.computedValue === null || typeof this.computedValue === 'undefined') {
259
+ if (this.maxNumber) {
260
+ this.computedValue = this.maxNumber
261
+ return
262
+ }
263
+ this.computedValue = 0
264
+ }
265
+ const value = this.computedValue - this.stepNumber
266
+ this.computedValue = parseFloat(value.toFixed(this.stepDecimals))
267
+ }
268
+ },
269
+ increment() {
270
+ if (typeof this.maxNumber === 'undefined' || this.computedValue + this.stepNumber <= this.maxNumber) {
271
+ if (this.computedValue === null || typeof this.computedValue === 'undefined') {
272
+ if (this.minNumber) {
273
+ this.computedValue = this.minNumber
274
+ return
275
+ }
276
+ this.computedValue = 0
277
+ }
278
+ const value = this.computedValue + this.stepNumber
279
+ this.computedValue = parseFloat(value.toFixed(this.stepDecimals))
280
+ }
281
+ },
282
+ onControlClick(event, inc) {
283
+ // IE 11 -> filter click event
284
+ if (event.detail !== 0 || event.type !== 'click') return
285
+ if (inc) this.increment()
286
+ else this.decrement()
287
+ },
288
+ longPressTick(inc) {
289
+ if (inc) this.increment()
290
+ else this.decrement()
291
+
292
+ this._$intervalRef = setTimeout(() => {
293
+ this.longPressTick(inc)
294
+ }, this.exponential ? (250 / (this.exponential * this.timesPressed++)) : 250)
295
+ },
296
+ onStartLongPress(event, inc) {
297
+ if (event.button !== 0 && event.type !== 'touchstart') return
298
+ clearTimeout(this._$intervalRef)
299
+ this.longPressTick(inc)
300
+ },
301
+ onStopLongPress() {
302
+ if (!this._$intervalRef) return
303
+ this.timesPressed = 1
304
+ clearTimeout(this._$intervalRef)
305
+ this._$intervalRef = null
306
+ }
307
+ }
308
+ }
309
+ </script>