견적서에 계산기추가

This commit is contained in:
ysCha 2025-12-23 15:30:27 +09:00
parent 59b65df1d6
commit dc080a8737

View File

@ -3,7 +3,7 @@ import { createCalculator } from '@/util/calc-utils'
import '@/styles/calc.scss'
export const CalculatorInput = forwardRef(
({ value, onChange, label, options = {}, id, className = 'calculator-input', readOnly = false, placeholder, name='', disabled = false }, ref) => {
({ value, onChange, label, options = {}, id, className = 'calculator-input', readOnly = false, placeholder, name='', disabled = false, maxLength = 6 }, ref) => {
const [showKeypad, setShowKeypad] = useState(false)
const [displayValue, setDisplayValue] = useState(value || '0')
const [hasOperation, setHasOperation] = useState(false)
@ -48,6 +48,14 @@ export const CalculatorInput = forwardRef(
const calculator = calculatorRef.current
let newDisplayValue = ''
// maxLength
if (maxLength > 0) {
const currentLength = (calculator.currentOperand || '').length + (calculator.previousOperand || '').length + (calculator.operation || '').length
if (currentLength >= maxLength) {
return
}
}
// 2
const shouldPreventInput = (value) => {
if (!value) return false
@ -57,6 +65,10 @@ export const CalculatorInput = forwardRef(
//
const appendNumber = (current, num) => {
// maxLength
if (maxLength > 0 && (current + num).length > maxLength) {
return current
}
// 0 0
if (current === '0' && num !== '.' && !current.includes('.')) {
return num.toString()
@ -407,6 +419,7 @@ export const CalculatorInput = forwardRef(
placeholder={placeholder}
autoComplete={'off'}
disabled={disabled}
maxLength={maxLength}
/>
{showKeypad && !readOnly && (