Skip to content

Commit 6fadcdc

Browse files
committed
2.2.8
1 parent 7fad5f7 commit 6fadcdc

File tree

4 files changed

+142
-132
lines changed

4 files changed

+142
-132
lines changed

Diff for: dist/vue-numeric.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-numeric",
3-
"version": "2.2.7",
3+
"version": "2.2.8",
44
"description": "Input field component to display currency value based on Vue.",
55
"author": "Kevin Ongko",
66
"main": "dist/vue-numeric.min.js",
@@ -46,7 +46,7 @@
4646
"cross-env": "^5.0.5",
4747
"css-loader": "^0.28.7",
4848
"eslint": "^4.6.0",
49-
"eslint-plugin-vue": "3.13.1",
49+
"eslint-plugin-vue": "^4.0.0-beta.0",
5050
"karma": "^1.7.1",
5151
"karma-coverage": "^1.1.1",
5252
"karma-mocha": "^1.3.0",

Diff for: src/vue-numeric.vue

+96-91
Original file line numberDiff line numberDiff line change
@@ -9,123 +9,128 @@
99
v-model="amount"
1010
v-if="!readOnly"
1111
>
12-
<span v-else ref="readOnly">{{ amount }}</span>
12+
<span
13+
v-else
14+
ref="readOnly"
15+
>{{ amount }}</span>
1316
</template>
1417

1518
<script>
1619
import accounting from 'accounting-js'
1720
1821
export default {
19-
name: 'vue-numeric',
22+
name: 'VueNumeric',
2023
2124
props: {
2225
/**
2326
* Currency symbol.
2427
*/
2528
currency: {
29+
type: String,
2630
default: '',
27-
required: false,
28-
type: String
31+
required: false
2932
},
3033
3134
/**
3235
* Maximum value allowed.
3336
*/
3437
max: {
38+
type: Number,
3539
default: Number.MAX_SAFE_INTEGER || 9007199254740991,
3640
required: false,
37-
type: Number
3841
},
3942
4043
/**
4144
* Minimum value allowed.
4245
*/
4346
min: {
47+
type: Number,
4448
default: Number.MIN_SAFE_INTEGER || -9007199254740991,
45-
required: false,
46-
type: Number
49+
required: false
4750
},
4851
4952
/**
5053
* Enable/Disable minus value.
5154
*/
5255
minus: {
56+
type: Boolean,
5357
default: false,
54-
required: false,
55-
type: Boolean
58+
required: false
5659
},
5760
5861
/**
5962
* Input placeholder.
6063
*/
6164
placeholder: {
62-
required: false,
63-
type: String
65+
type: String,
66+
default: '',
67+
required: false
6468
},
6569
6670
/**
6771
* Value when the input is empty
6872
*/
6973
emptyValue: {
74+
type: [Number, String],
7075
default: '',
71-
required: false,
72-
type: [Number, String]
76+
required: false
7377
},
7478
7579
/**
7680
* Number of decimals.
7781
* Decimals symbol are the opposite of separator symbol.
7882
*/
7983
precision: {
80-
required: false,
81-
type: Number
84+
type: Number,
85+
default: 0,
86+
required: false
8287
},
8388
8489
/**
8590
* Thousand separator type.
8691
* Separator props accept either . or , (default).
8792
*/
8893
separator: {
94+
type: String,
8995
default: ',',
90-
required: false,
91-
type: String
96+
required: false
9297
},
9398
9499
/**
95100
* v-model value.
96101
*/
97102
value: {
103+
type: [Number, String],
98104
default: 0,
99-
required: true,
100-
type: [Number, String]
105+
required: true
101106
},
102107
103108
/**
104109
* Hide input and show value in text only.
105110
*/
106111
readOnly: {
112+
type: Boolean,
107113
default: false,
108-
required: false,
109-
type: Boolean
114+
required: false
110115
},
111116
112117
/**
113118
* Class for the span tag when readOnly props is true.
114119
*/
115120
readOnlyClass: {
121+
type: String,
116122
default: '',
117-
required: false,
118-
type: String
123+
required: false
119124
},
120125
121126
/**
122127
* Position of currency symbol
123128
* Symbol position props accept either 'suffix' or 'prefix' (default).
124129
*/
125130
currencySymbolPosition: {
131+
type: String,
126132
default: 'prefix',
127-
required: false,
128-
type: String
133+
required: false
129134
}
130135
},
131136
@@ -179,6 +184,72 @@ export default {
179184
}
180185
},
181186
187+
watch: {
188+
/**
189+
* Watch for value change from other input with same v-model.
190+
* @param {Number} newValue
191+
*/
192+
valueNumber (newValue) {
193+
if (this.$refs.numeric !== document.activeElement) {
194+
this.amount = this.format(newValue)
195+
}
196+
},
197+
198+
/**
199+
* When readOnly is true, replace the span tag class.
200+
* @param {Boolean} newValue
201+
* @param {Boolean} oldValue
202+
*/
203+
readOnly (newValue, oldValue) {
204+
if (oldValue === false && newValue === true) {
205+
this.$nextTick(() => {
206+
this.$refs.readOnly.className = this.readOnlyClass
207+
})
208+
}
209+
},
210+
211+
/**
212+
* Immediately reflect separator changes
213+
*/
214+
separator () {
215+
this.process(this.valueNumber)
216+
this.amount = this.format(this.valueNumber)
217+
},
218+
219+
/**
220+
* Immediately reflect currency changes
221+
*/
222+
currency () {
223+
this.process(this.valueNumber)
224+
this.amount = this.format(this.valueNumber)
225+
},
226+
227+
/**
228+
* Immediately reflect precision changes
229+
*/
230+
precision () {
231+
this.process(this.valueNumber)
232+
this.amount = this.format(this.valueNumber)
233+
}
234+
},
235+
236+
mounted () {
237+
// Set default value props when placeholder undefined.
238+
if (!this.placeholder) {
239+
this.process(this.valueNumber)
240+
this.amount = this.format(this.valueNumber)
241+
242+
// In case of delayed props value.
243+
setTimeout(() => {
244+
this.process(this.valueNumber)
245+
this.amount = this.format(this.valueNumber)
246+
}, 500)
247+
}
248+
249+
// Set read-only span element's class
250+
if (this.readOnly) this.$refs.readOnly.className = this.readOnlyClass
251+
},
252+
182253
methods: {
183254
/**
184255
* Handle blur event.
@@ -258,72 +329,6 @@ export default {
258329
const toUnformat = typeof value === 'string' && value === '' ? this.emptyValue : value
259330
return accounting.unformat(toUnformat, this.decimalSeparator)
260331
}
261-
},
262-
263-
watch: {
264-
/**
265-
* Watch for value change from other input with same v-model.
266-
* @param {Number} newValue
267-
*/
268-
valueNumber (newValue) {
269-
if (this.$refs.numeric !== document.activeElement) {
270-
this.amount = this.format(newValue)
271-
}
272-
},
273-
274-
/**
275-
* When readOnly is true, replace the span tag class.
276-
* @param {Boolean} newValue
277-
* @param {Boolean} oldValue
278-
*/
279-
readOnly (newValue, oldValue) {
280-
if (oldValue === false && newValue === true) {
281-
this.$nextTick(() => {
282-
this.$refs.readOnly.className = this.readOnlyClass
283-
})
284-
}
285-
},
286-
287-
/**
288-
* Immediately reflect separator changes
289-
*/
290-
separator () {
291-
this.process(this.valueNumber)
292-
this.amount = this.format(this.valueNumber)
293-
},
294-
295-
/**
296-
* Immediately reflect currency changes
297-
*/
298-
currency () {
299-
this.process(this.valueNumber)
300-
this.amount = this.format(this.valueNumber)
301-
},
302-
303-
/**
304-
* Immediately reflect precision changes
305-
*/
306-
precision () {
307-
this.process(this.valueNumber)
308-
this.amount = this.format(this.valueNumber)
309-
}
310-
},
311-
312-
mounted () {
313-
// Set default value props when placeholder undefined.
314-
if (!this.placeholder) {
315-
this.process(this.valueNumber)
316-
this.amount = this.format(this.valueNumber)
317-
318-
// In case of delayed props value.
319-
setTimeout(() => {
320-
this.process(this.valueNumber)
321-
this.amount = this.format(this.valueNumber)
322-
}, 500)
323-
}
324-
325-
// Set read-only span element's class
326-
if (this.readOnly) this.$refs.readOnly.className = this.readOnlyClass
327332
}
328333
}
329334
</script>

0 commit comments

Comments
 (0)