Skip to content

Commit f3eadd6

Browse files
committed
Updated component and docs
1 parent 5e1f367 commit f3eadd6

File tree

4 files changed

+57
-139
lines changed

4 files changed

+57
-139
lines changed

docs/.vuepress/components/BaseNumber.vue

-109
This file was deleted.

docs/.vuepress/components/PlayGround.vue

+17-16
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
<div class="grid gap-y-4 md:grid-cols-2 md:gap-x-8 items-center my-8">
44
<div class="grid">
55
<div class="font-medium mb-2">Component</div>
6-
<BaseNumber
6+
<number
77
v-model="price"
88
v-bind="config"
9+
class="shadow-sm rounded-md text-base transition-all disabled:cursor-not-allowed disabled:border-gray-300 disabled:text-gray-300 focus:border-primary focus:ring focus:ring-offset-0 focus:ring-primary focus:ring-opacity-50"
910
/>
1011
<div class="mt-2">
1112
Number value: <code class="ml-2">{{ price }}</code>
@@ -91,30 +92,30 @@ export default {
9192
return {
9293
updated: true,
9394
exportDialogVisible: false,
94-
price: 154.52,
95-
priceDirective: 154.52,
95+
price: 1234.567,
96+
priceDirective: 1234.567,
9697
config: {
97-
decimal: ".",
98-
separator: ",",
99-
prefix: "$",
100-
suffix: "",
98+
decimal: '.',
99+
separator: ',',
100+
prefix: '$',
101+
suffix: '',
101102
precision: 2,
102-
nullValue: "",
103+
nullValue: '',
103104
masked: false,
104105
reverseFill: false,
105106
},
106-
};
107+
}
107108
},
108109
watch: {
109110
config: {
110111
deep: true,
111-
handler (val) {
112+
handler(val) {
112113
this.updated = false
113114
this.$nextTick(() => {
114-
this.updated = true;
115-
});
116-
}
117-
}
118-
}
119-
};
115+
this.updated = true
116+
})
117+
},
118+
},
119+
},
120+
}
120121
</script>

src/component.vue

+21-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export default {
3131
type: Boolean,
3232
default: options.reverseFill,
3333
},
34+
prefill: {
35+
type: Boolean,
36+
default: options.prefill,
37+
},
3438
precision: {
3539
type: Number,
3640
default: () => options.precision,
@@ -39,12 +43,18 @@ export default {
3943
type: [Number, Boolean],
4044
default: () => options.minimumFractionDigits,
4145
},
42-
max: [Number, Boolean, String],
43-
min: [Number, Boolean, String],
4446
decimal: {
4547
type: String,
4648
default: () => options.decimal,
4749
},
50+
min: {
51+
type: [Number, Boolean],
52+
default: () => options.min,
53+
},
54+
max: {
55+
type: [Number, Boolean],
56+
default: () => options.max,
57+
},
4858
separator: {
4959
type: String,
5060
default: () => options.separator,
@@ -61,7 +71,7 @@ export default {
6171
directives: {
6272
number: directive,
6373
},
64-
emits: ['update:modelValue', 'input:modelValue'],
74+
emits: ['update:model-value'],
6575
data() {
6676
return {
6777
maskedValue: this.modelValue,
@@ -72,18 +82,23 @@ export default {
7282
input({ target }) {
7383
this.maskedValue = target.value
7484
this.unmaskedValue = target.unmaskedValue
75-
this.$emit('input:modelValue', this.emittedValue)
7685
},
7786
change() {
78-
this.$emit('update:modelValue', this.emittedValue)
87+
this.$emit('update:model-value', this.emittedValue)
7988
},
8089
},
8190
computed: {
8291
emittedValue() {
8392
return this.masked ? this.maskedValue : this.unmaskedValue
8493
},
8594
config() {
86-
return this.$props
95+
const config = {}
96+
Object.keys(this.$props)
97+
.filter((item) => item !== 'modelValue')
98+
.forEach((item) => {
99+
config[item] = this.$props[item]
100+
})
101+
return config
87102
},
88103
},
89104
watch: {

src/core.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function FacadeInputEvent() {
1010
return new CustomEvent('input', {
1111
bubbles: true,
1212
cancelable: true,
13-
detail: { facade: true }
13+
detail: { facade: true },
1414
})
1515
}
1616

@@ -22,7 +22,7 @@ export function FacadeChangeEvent() {
2222
return new CustomEvent('change', {
2323
bubbles: true,
2424
cancelable: true,
25-
detail: { facade: true }
25+
detail: { facade: true },
2626
})
2727
}
2828

@@ -33,7 +33,8 @@ export function FacadeChangeEvent() {
3333
* @param {HTMLInputElement} el
3434
*/
3535
export function getInputElement(el) {
36-
const inputElement = el instanceof HTMLInputElement ? el : el.querySelector('input')
36+
const inputElement =
37+
el instanceof HTMLInputElement ? el : el.querySelector('input')
3738

3839
/* istanbul ignore next */
3940
if (!inputElement) {
@@ -49,7 +50,9 @@ export function getInputElement(el) {
4950
* @param {Number} position
5051
*/
5152
export function updateCursor(el, position) {
52-
const setSelectionRange = () => { el.setSelectionRange(position, position) }
53+
const setSelectionRange = () => {
54+
el.setSelectionRange(position, position)
55+
}
5356
setSelectionRange()
5457
// Android Fix
5558
setTimeout(setSelectionRange(), 1)
@@ -63,7 +66,11 @@ export function updateCursor(el, position) {
6366
* @param {Boolean} options.emit Wether to dispatch a new InputEvent or not
6467
* @param {Boolean} options.force Forces the update even if the old value and the new value are the same
6568
*/
66-
export function updateValue(el, vnode, { emit = true, force = false, clean = false } = {}) {
69+
export function updateValue(
70+
el,
71+
vnode,
72+
{ emit = true, force = false, clean = false } = {}
73+
) {
6774
const { config } = el[CONFIG_KEY]
6875
let { oldValue } = el[CONFIG_KEY]
6976
let currentValue = vnode && vnode.props ? vnode.props.value : el.value
@@ -77,10 +84,10 @@ export function updateValue(el, vnode, { emit = true, force = false, clean = fal
7784

7885
// check value with in range max and min value
7986
if (clean) {
80-
if (config.max && unmasked > config.max) {
87+
if (Number(config.max) && unmasked > Number(config.max)) {
8188
masked = number.format(config.max)
8289
unmasked = number.unformat(config.max)
83-
} else if (config.min && unmasked < config.min) {
90+
} else if (Number(config.min) && unmasked < Number(config.min)) {
8491
masked = number.format(config.min)
8592
unmasked = number.unformat(config.min)
8693
}
@@ -96,7 +103,11 @@ export function updateValue(el, vnode, { emit = true, force = false, clean = fal
96103

97104
// this part needs to be outside the above IF statement for vuetify in firefox
98105
// drawback is that we endup with two's input events in firefox
99-
return emit && el.dispatchEvent(FacadeInputEvent()) && el.dispatchEvent(FacadeChangeEvent())
106+
return (
107+
emit &&
108+
el.dispatchEvent(FacadeInputEvent()) &&
109+
el.dispatchEvent(FacadeChangeEvent())
110+
)
100111
}
101112
}
102113

0 commit comments

Comments
 (0)