Xinon mobile/improve
This commit is contained in:
43
public/mobile/shared/useNumericKeypad.js
Normal file
43
public/mobile/shared/useNumericKeypad.js
Normal file
@@ -0,0 +1,43 @@
|
||||
export function useNumericKeypad(initialValue = '1') {
|
||||
const { ref } = Vue;
|
||||
const quantity = ref(initialValue);
|
||||
|
||||
const appendDigit = (digit) => {
|
||||
if (digit === '.' && quantity.value.includes('.')) return;
|
||||
if (quantity.value === '0' && digit !== '.') {
|
||||
quantity.value = digit;
|
||||
} else {
|
||||
quantity.value += digit;
|
||||
}
|
||||
};
|
||||
|
||||
const deleteDigit = () => {
|
||||
quantity.value = quantity.value.length > 1 ? quantity.value.slice(0, -1) : '0';
|
||||
};
|
||||
|
||||
const clearQuantity = () => {
|
||||
quantity.value = '0';
|
||||
};
|
||||
|
||||
const setQuantity = (value) => {
|
||||
quantity.value = String(value);
|
||||
};
|
||||
|
||||
const increment = (amount = 1) => {
|
||||
quantity.value = String(Math.max(1, parseFloat(quantity.value) + amount));
|
||||
};
|
||||
|
||||
const decrement = (amount = 1) => {
|
||||
quantity.value = String(Math.max(1, parseFloat(quantity.value) - amount));
|
||||
};
|
||||
|
||||
return {
|
||||
quantity,
|
||||
appendDigit,
|
||||
deleteDigit,
|
||||
clearQuantity,
|
||||
setQuantity,
|
||||
increment,
|
||||
decrement
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user