@designcrowd/fe-shared-lib 1.1.4-rte-2 → 1.1.4-rte-3
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.
package/package.json
CHANGED
|
@@ -20,12 +20,13 @@
|
|
|
20
20
|
@touchcancel="clearLongPressTimers($event)"
|
|
21
21
|
/>
|
|
22
22
|
<input
|
|
23
|
-
v-if="disableManualInput"
|
|
24
23
|
:ref="numberStepperRef"
|
|
25
|
-
class="
|
|
26
|
-
|
|
24
|
+
:class="[
|
|
25
|
+
inputClasses,
|
|
26
|
+
'border-radius-none tw-w-full tw-text-center tw-border tw-border-solid tw-border-grayscale-500 tw-border-l-0 tw-border-r-0 tw-rounded-none',
|
|
27
|
+
]"
|
|
27
28
|
type="text"
|
|
28
|
-
:
|
|
29
|
+
:value="number"
|
|
29
30
|
pattern="[0-9]"
|
|
30
31
|
:disabled="disabled || disableManualInput"
|
|
31
32
|
@wheel="onMouseWheel"
|
|
@@ -34,23 +35,7 @@
|
|
|
34
35
|
@keydown.up="onArrowDown('up')"
|
|
35
36
|
@keydown.down="onArrowDown('down')"
|
|
36
37
|
@focus="$emit(FOCUSED_EVENT)"
|
|
37
|
-
@blur="
|
|
38
|
-
/>
|
|
39
|
-
<NumberInput
|
|
40
|
-
v-else
|
|
41
|
-
:min="min"
|
|
42
|
-
:max="max"
|
|
43
|
-
:model-value="number"
|
|
44
|
-
:element-classes="[
|
|
45
|
-
inputClasses,
|
|
46
|
-
'tw-w-full tw-text-center tw-border tw-border-solid tw-border-grayscale-500 tw-border-l-0 tw-border-r-0 tw-rounded-none',
|
|
47
|
-
]"
|
|
48
|
-
:rounded-corners="false"
|
|
49
|
-
@wheel="onMouseWheel"
|
|
50
|
-
@input="onSetInput"
|
|
51
|
-
@keyup="clearLongPressTimers"
|
|
52
|
-
@keydown.up="onArrowDown('up')"
|
|
53
|
-
@keydown.down="onArrowDown('down')"
|
|
38
|
+
@blur.stop="checkLimit"
|
|
54
39
|
/>
|
|
55
40
|
<Button
|
|
56
41
|
variant="flat"
|
|
@@ -77,12 +62,10 @@
|
|
|
77
62
|
<script>
|
|
78
63
|
import { ref } from 'vue';
|
|
79
64
|
import Button from '../Button/Button.vue';
|
|
80
|
-
import NumberInput from '../NumberInput/NumberInput.vue';
|
|
81
65
|
|
|
82
66
|
export default {
|
|
83
67
|
components: {
|
|
84
68
|
Button,
|
|
85
|
-
NumberInput,
|
|
86
69
|
},
|
|
87
70
|
props: {
|
|
88
71
|
// The value returned when a variable is assigned to v-model
|
|
@@ -288,32 +271,17 @@ export default {
|
|
|
288
271
|
}
|
|
289
272
|
}
|
|
290
273
|
},
|
|
274
|
+
|
|
291
275
|
onInput(e) {
|
|
292
276
|
if (!this.disabled) {
|
|
293
|
-
const
|
|
277
|
+
const newVal = parseFloat(e.target.value);
|
|
294
278
|
let newNumber = 0;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
newNumber = value.slice(0, -1);
|
|
300
|
-
} else if (typeof size === 'string') {
|
|
301
|
-
// TODO: revist linting
|
|
302
|
-
// eslint-disable-next-line no-undef
|
|
303
|
-
const integer = Math.round(parseFloat(size));
|
|
304
|
-
newNumber = Number.isNaN(integer) ? this.number : integer;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
if (value) {
|
|
308
|
-
if (value < this.min) {
|
|
309
|
-
newNumber = this.min;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
if (this.max && value > this.max) {
|
|
313
|
-
newNumber = this.max;
|
|
314
|
-
}
|
|
279
|
+
if (newVal > this.max) {
|
|
280
|
+
newNumber = this.max;
|
|
281
|
+
} else if (Number.isNaN(newVal)) {
|
|
282
|
+
newNumber = 0;
|
|
315
283
|
} else {
|
|
316
|
-
newNumber =
|
|
284
|
+
newNumber = newVal;
|
|
317
285
|
}
|
|
318
286
|
|
|
319
287
|
this.number = newNumber;
|
|
@@ -322,12 +290,20 @@ export default {
|
|
|
322
290
|
this.$emit('input', this.number);
|
|
323
291
|
}
|
|
324
292
|
},
|
|
325
|
-
|
|
326
|
-
let
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
293
|
+
checkLimit(e) {
|
|
294
|
+
let newNumber = 0;
|
|
295
|
+
if (e.target.value === '') {
|
|
296
|
+
newNumber = this.min;
|
|
297
|
+
} else if (Number.isNaN(this.number)) {
|
|
298
|
+
newNumber = this.min;
|
|
299
|
+
} else if (this.number <= this.min) {
|
|
300
|
+
newNumber = this.min;
|
|
301
|
+
} else if (this.number > this.max) {
|
|
302
|
+
newNumber = this.max;
|
|
303
|
+
} else {
|
|
304
|
+
newNumber = this.number;
|
|
305
|
+
}
|
|
306
|
+
this.$emit('update:modelValue', newNumber);
|
|
331
307
|
},
|
|
332
308
|
},
|
|
333
309
|
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import NumberInput from './NumberInput.vue';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
title: 'Components/Number Input',
|
|
5
|
-
component: NumberInput,
|
|
6
|
-
parameters: {
|
|
7
|
-
layout: 'centered',
|
|
8
|
-
},
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const NumberInputStory = () => {
|
|
12
|
-
return {
|
|
13
|
-
components: {
|
|
14
|
-
NumberInput,
|
|
15
|
-
},
|
|
16
|
-
template: `
|
|
17
|
-
<div>
|
|
18
|
-
<div>Min 12, Max 128</div>
|
|
19
|
-
<NumberInput :min="12" :max="128" :model-value="16"/>
|
|
20
|
-
<div class="tw-mt-8">Min 0, max 100, Manually emptying the input box should fall back to 0 as min value</div>
|
|
21
|
-
<NumberInput :min="0" :max="100" :model-value="16"/>
|
|
22
|
-
</div>
|
|
23
|
-
|
|
24
|
-
`,
|
|
25
|
-
};
|
|
26
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<input
|
|
3
|
-
ref="numberInput"
|
|
4
|
-
:value="numberValue"
|
|
5
|
-
type="text"
|
|
6
|
-
class="tw-w-full"
|
|
7
|
-
:class="[
|
|
8
|
-
elementClasses,
|
|
9
|
-
{
|
|
10
|
-
'border-radius-none': !roundedCorners,
|
|
11
|
-
},
|
|
12
|
-
]"
|
|
13
|
-
@input.stop="setInput"
|
|
14
|
-
@blur.stop="checkLimit"
|
|
15
|
-
/>
|
|
16
|
-
</template>
|
|
17
|
-
|
|
18
|
-
<script>
|
|
19
|
-
export default {
|
|
20
|
-
props: {
|
|
21
|
-
min: {
|
|
22
|
-
type: Number,
|
|
23
|
-
required: false,
|
|
24
|
-
default: 0,
|
|
25
|
-
},
|
|
26
|
-
max: {
|
|
27
|
-
type: Number,
|
|
28
|
-
required: false,
|
|
29
|
-
default: 100,
|
|
30
|
-
},
|
|
31
|
-
modelValue: {
|
|
32
|
-
type: String,
|
|
33
|
-
required: false,
|
|
34
|
-
default: undefined,
|
|
35
|
-
},
|
|
36
|
-
elementClasses: {
|
|
37
|
-
type: String,
|
|
38
|
-
required: false,
|
|
39
|
-
default: '',
|
|
40
|
-
},
|
|
41
|
-
label: {
|
|
42
|
-
type: String,
|
|
43
|
-
required: false,
|
|
44
|
-
default: undefined,
|
|
45
|
-
},
|
|
46
|
-
roundedCorners: {
|
|
47
|
-
type: Boolean,
|
|
48
|
-
default: true,
|
|
49
|
-
},
|
|
50
|
-
step: {
|
|
51
|
-
type: Number,
|
|
52
|
-
required: false,
|
|
53
|
-
default: 1,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
data() {
|
|
57
|
-
return {
|
|
58
|
-
numberValue: this.modelValue,
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
watch: {
|
|
62
|
-
modelValue(v) {
|
|
63
|
-
this.numberValue = v;
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
methods: {
|
|
67
|
-
focus() {
|
|
68
|
-
this.$refs.numberInput.focus();
|
|
69
|
-
},
|
|
70
|
-
setInput(e) {
|
|
71
|
-
const newVal = parseFloat(e.target.value);
|
|
72
|
-
let newNumber = 0;
|
|
73
|
-
if (newVal > this.max) {
|
|
74
|
-
newNumber = this.max;
|
|
75
|
-
} else if (Number.isNaN(newVal)) {
|
|
76
|
-
newNumber = 0;
|
|
77
|
-
} else {
|
|
78
|
-
newNumber = newVal;
|
|
79
|
-
}
|
|
80
|
-
this.updateValue(newNumber, e);
|
|
81
|
-
},
|
|
82
|
-
checkLimit(e) {
|
|
83
|
-
let newNumber = 0;
|
|
84
|
-
if (e.target.value === '') {
|
|
85
|
-
newNumber = this.min;
|
|
86
|
-
} else if (Number.isNaN(this.numberValue)) {
|
|
87
|
-
newNumber = this.min;
|
|
88
|
-
} else if (this.numberValue <= this.min) {
|
|
89
|
-
newNumber = this.min;
|
|
90
|
-
} else if (this.numberValue > this.max) {
|
|
91
|
-
newNumber = this.max;
|
|
92
|
-
} else {
|
|
93
|
-
newNumber = this.numberValue;
|
|
94
|
-
}
|
|
95
|
-
this.updateValue(newNumber, e);
|
|
96
|
-
},
|
|
97
|
-
updateValue(value, e) {
|
|
98
|
-
this.numberValue = value;
|
|
99
|
-
e.target.value = value;
|
|
100
|
-
this.$emit('input', e, value);
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
</script>
|
|
105
|
-
<style scoped>
|
|
106
|
-
input::-webkit-outer-spin-button,
|
|
107
|
-
input::-webkit-inner-spin-button {
|
|
108
|
-
-webkit-appearance: none;
|
|
109
|
-
margin: 0;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
.border-radius-none {
|
|
113
|
-
border-radius: 0 !important;
|
|
114
|
-
}
|
|
115
|
-
</style>
|