import React from 'react'; import { CalcButton } from './CalcButton'; import { useCalculator2Store } from '../state'; import { useCalculator2Gestures } from '../hooks/useCalculator2Gestures'; import { colors } from '../res/colors'; import { strings } from '../res/strings'; /** * 运算符键盘 — 1列5行 * 翻译自 AOSP pad_operator_one_col.xml * * del/clr * ÷ * × * − * + */ interface OperatorPadProps { style?: React.CSSProperties; } export const OperatorPad: React.FC = ({ style }) => { const state = useCalculator2Store(s => s.state); const inputOperator = useCalculator2Store(s => s.inputOperator); const onDelete = useCalculator2Store(s => s.onDelete); const onClear = useCalculator2Store(s => s.onClear); const { bindAction } = useCalculator2Gestures(); // del/clr 切换:INPUT 态 → del; RESULT/ERROR 态 → clr const isDelMode = state === 'INPUT' || state === 'EVALUATE'; const operators = [ { label: strings.op_div, op: '/', actionId: 'op.div' }, { label: strings.op_mul, op: '*', actionId: 'op.mul' }, { label: strings.op_sub, op: '-', actionId: 'op.sub' }, { label: strings.op_add, op: '+', actionId: 'op.add' }, ]; return (
{/* del / clr */} {/* ÷ × − + */} {operators.map(({ label, op, actionId }) => ( inputOperator(op)} {...bindAction(actionId)} /> ))}
); };