import type { CSSProperties, ReactNode } from 'react'; import type { BaseNumberInputProps } from '@pisell/utils'; /** * 从 @pisell/utils 重新导出公共类型 */ export type { DisplayState, ValidationResult, NumberInputState, BaseNumberInputProps, } from '@pisell/utils'; /** * PisellNumber 组件 Props 类型定义 * * 基于 Ant Design InputNumber,提供三态视图(只读/编辑/禁用) */ export interface PisellNumberProps extends BaseNumberInputProps { /** * 显示模式 * - read: 只读态,纯文本展示 * - edit: 编辑态,显示输入控件 * @default 'edit' */ mode?: 'read' | 'edit'; /** * 是否禁用 * @default false */ disabled?: boolean; /** * 回车键回调 * @param value 当前值 */ onPressEnter?: (value: number | null) => void; /** * 步进值 * @default 1 */ step?: number; /** * 小数精度(小数位数) * @example precision={2} 表示保留2位小数 */ precision?: number; /** * 是否使用千分位分隔符 * @default false * @example 1234567 → 1,234,567 */ useGrouping?: boolean; /** * 自定义格式化函数 * @param value 数值 * @returns 格式化后的字符串 * @example * formatter={(value) => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')} */ formatter?: (value: number | null) => string; /** * 自定义解析函数(将显示值转换为数值) * @param displayValue 显示的字符串 * @returns 解析后的数值 * @example * parser={(value) => value.replace(/\$\s?|(,*)/g, '')} */ parser?: (displayValue: string | undefined) => number | null; /** * 是否自动修正超出范围的值 * @default false * @description 当值超出 min/max 范围时,自动修正为边界值 */ autoCorrect?: boolean; /** * 占位文本 * @default '请输入数字' */ placeholder?: string; /** * 是否显示清空按钮 * @default false */ allowClear?: boolean; /** * 是否自动聚焦 * @default false */ autoFocus?: boolean; /** * 前缀图标或文本 */ prefix?: ReactNode; /** * 后缀图标或文本 */ suffix?: ReactNode; /** * 前置标签 * @example addonBefore="¥" */ addonBefore?: ReactNode; /** * 后置标签 * @example addonAfter="元" */ addonAfter?: ReactNode; /** * 输入框尺寸 * @default 'middle' */ size?: 'large' | 'middle' | 'small'; /** * 是否启用键盘上下键 * @default true */ keyboard?: boolean; /** * 控制字符 * @description 自定义控制字符,用于格式化显示 */ controls?: boolean | { upIcon?: ReactNode; downIcon?: ReactNode; }; /** * 字号 * @example '14px' 或 14 */ fontSize?: string | number; /** * 字重 * @example 'bold' 或 600 */ fontWeight?: string | number; /** * 文本颜色 * @example '#000000' 或 'rgba(0, 0, 0, 0.85)' */ color?: string; /** * 文本对齐方式 * @default 'left' */ textAlign?: 'left' | 'center' | 'right'; /** * 空值时的显示文本 * @default '-' */ emptyText?: string; /** * 自定义类名 */ className?: string; /** * 自定义样式 */ style?: CSSProperties; /** * ARIA 标签 */ 'aria-label'?: string; /** * ARIA 描述 */ 'aria-describedby'?: string; /** * HTML id 属性 */ id?: string; /** * HTML name 属性 */ name?: string; }