@pvngu/vue-calculator
v0.1.3
Published
Touch-friendly POS calculator component for Vue 3. Built for checkout workflows where cashiers need fast arithmetic inside a modal or popover without leaving the POS screen.
Readme
vue-calculator
Touch-friendly POS calculator component for Vue 3. Built for checkout workflows where cashiers need fast arithmetic inside a modal or popover without leaving the POS screen.
Features
- Large keypad with tap and keyboard input.
- Decimal support and precision-safe arithmetic helpers.
- Clear, backspace, sign toggle, and percent.
- Copy current result with clipboard fallback.
- Undo for recent actions.
- Lightweight recent history with tap-to-reuse.
- Responsive layout for desktop and tablet.
Install
npm install vue-calculatorBasic usage
<script setup>
import { ref } from 'vue'
import { PosCalculator } from 'vue-calculator'
const value = ref('0')
function onEvaluate(payload) {
console.log('result', payload.result)
}
</script>
<template>
<PosCalculator v-model="value" compact @evaluate="onEvaluate" />
</template>Modal / popover integration notes
- Use
compactmode for constrained containers. - Set
autofocusto true when the overlay opens for immediate keyboard input. - Keep
keyboardenabled so numpad and operators work during checkout. - Listen to
@evaluateand feed result into your POS payment/discount field.
Component API
Props
modelValue: string | numberdefault"0"precision: numberdefault12maxHistory: numberdefault5keyboard: booleandefaulttruecompact: booleandefaultfalseshowHistory: booleandefaulttrueautofocus: booleandefaulttruetitle: stringdefault"POS Calculator"
Emits
update:modelValuecurrent display valuechangepayload{ value, expression }evaluatepayload{ expression, result }copycopied display stringerrorpayload{ code, message, error? }
Programmatic engine (headless)
import { useCalculatorEngine } from 'vue-calculator'
const calc = useCalculatorEngine({
initialValue: '0',
precision: 12,
maxHistory: 5
})
calc.inputDigit('1')
calc.setOperator('+')
calc.inputDigit('2')
const result = calc.evaluate()Development
npm run dev
npm run build