견적서에 계산기추가
This commit is contained in:
parent
59b65df1d6
commit
dc080a8737
@ -3,7 +3,7 @@ import { createCalculator } from '@/util/calc-utils'
|
|||||||
import '@/styles/calc.scss'
|
import '@/styles/calc.scss'
|
||||||
|
|
||||||
export const CalculatorInput = forwardRef(
|
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 [showKeypad, setShowKeypad] = useState(false)
|
||||||
const [displayValue, setDisplayValue] = useState(value || '0')
|
const [displayValue, setDisplayValue] = useState(value || '0')
|
||||||
const [hasOperation, setHasOperation] = useState(false)
|
const [hasOperation, setHasOperation] = useState(false)
|
||||||
@ -48,6 +48,14 @@ export const CalculatorInput = forwardRef(
|
|||||||
const calculator = calculatorRef.current
|
const calculator = calculatorRef.current
|
||||||
let newDisplayValue = ''
|
let newDisplayValue = ''
|
||||||
|
|
||||||
|
// maxLength 체크
|
||||||
|
if (maxLength > 0) {
|
||||||
|
const currentLength = (calculator.currentOperand || '').length + (calculator.previousOperand || '').length + (calculator.operation || '').length
|
||||||
|
if (currentLength >= maxLength) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 소수점 이하 2자리 제한 로직 추가
|
// 소수점 이하 2자리 제한 로직 추가
|
||||||
const shouldPreventInput = (value) => {
|
const shouldPreventInput = (value) => {
|
||||||
if (!value) return false
|
if (!value) return false
|
||||||
@ -57,6 +65,10 @@ export const CalculatorInput = forwardRef(
|
|||||||
|
|
||||||
// 숫자 추가 함수
|
// 숫자 추가 함수
|
||||||
const appendNumber = (current, num) => {
|
const appendNumber = (current, num) => {
|
||||||
|
// maxLength 체크
|
||||||
|
if (maxLength > 0 && (current + num).length > maxLength) {
|
||||||
|
return current
|
||||||
|
}
|
||||||
// 현재 값이 0이고 소수점이 없을 때 0이 아닌 숫자를 입력하면 대체
|
// 현재 값이 0이고 소수점이 없을 때 0이 아닌 숫자를 입력하면 대체
|
||||||
if (current === '0' && num !== '.' && !current.includes('.')) {
|
if (current === '0' && num !== '.' && !current.includes('.')) {
|
||||||
return num.toString()
|
return num.toString()
|
||||||
@ -407,6 +419,7 @@ export const CalculatorInput = forwardRef(
|
|||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
autoComplete={'off'}
|
autoComplete={'off'}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
maxLength={maxLength}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{showKeypad && !readOnly && (
|
{showKeypad && !readOnly && (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user