- 完整实现Apple HIG 2025设计系统 - 添加Modal弹窗组件(毛玻璃效果、流畅动画) - 添加FileUpload文件上传组件(拖拽、批量上传、进度显示) - 实现产品上传功能(支持DWG/GLB/GLTF文件) - 优化产品列表展示(可折叠的产品+SKU结构) - 实现Tab切换功能(3D模型管理、五金件、BOM、文档) - 修复主题系统hydration错误 - 优化按钮和间距,符合Apple设计规范 - 添加分享页面的Apple风格重设计 - 创建测试数据脚本
330 lines
9.4 KiB
TypeScript
330 lines
9.4 KiB
TypeScript
/**
|
|
* Apple 风格 Input 组件
|
|
*
|
|
* 基于苹果 Human Interface Guidelines 2025 的输入框组件
|
|
* 支持 Filled 和 Outlined 两种苹果标准样式
|
|
*
|
|
* @created 2025-12-11
|
|
*/
|
|
|
|
'use client'
|
|
|
|
import React from 'react'
|
|
import { cn } from '@/lib/utils'
|
|
import { Subhead, Caption1 } from './Typography'
|
|
|
|
// Input 变体类型
|
|
export type InputVariant = 'filled' | 'outlined'
|
|
export type InputSize = 'small' | 'regular' | 'large'
|
|
export type InputState = 'default' | 'error' | 'success' | 'warning'
|
|
|
|
// 组件 Props 接口
|
|
export interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'> {
|
|
/** 输入框变体 */
|
|
variant?: InputVariant
|
|
/** 输入框尺寸 */
|
|
size?: InputSize
|
|
/** 输入框状态 */
|
|
state?: InputState
|
|
/** 标签文本 */
|
|
label?: string
|
|
/** 帮助文本 */
|
|
helperText?: string
|
|
/** 错误文本 */
|
|
errorText?: string
|
|
/** 是否必填 */
|
|
required?: boolean
|
|
/** 左侧图标 */
|
|
leftIcon?: React.ReactNode
|
|
/** 右侧图标 */
|
|
rightIcon?: React.ReactNode
|
|
/** 容器类名 */
|
|
containerClassName?: string
|
|
}
|
|
|
|
/**
|
|
* Apple 风格 Input 组件
|
|
*/
|
|
export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
({
|
|
variant = 'filled',
|
|
size = 'regular',
|
|
state = 'default',
|
|
label,
|
|
helperText,
|
|
errorText,
|
|
required = false,
|
|
leftIcon,
|
|
rightIcon,
|
|
className,
|
|
containerClassName,
|
|
disabled,
|
|
...props
|
|
}, ref) => {
|
|
|
|
// 确定当前状态(错误优先)
|
|
const currentState = errorText ? 'error' : state
|
|
|
|
// 基础样式
|
|
const baseStyles = [
|
|
'w-full transition-all duration-apple-fast ease-apple-ease-out',
|
|
'font-apple-system text-apple-label-primary-light',
|
|
'placeholder:text-apple-label-tertiary-light',
|
|
'focus:outline-none focus:ring-2 focus:ring-offset-1',
|
|
'disabled:opacity-50 disabled:cursor-not-allowed',
|
|
'dark:text-apple-label-primary-dark',
|
|
'dark:placeholder:text-apple-label-tertiary-dark',
|
|
]
|
|
|
|
// 尺寸样式
|
|
const sizeStyles = {
|
|
small: ['px-3 py-2 text-apple-sm', 'h-8', 'rounded-apple-sm'], // 32px
|
|
regular: ['px-4 py-3 text-apple-base', 'h-11', 'rounded-apple-md'], // 44px
|
|
large: ['px-5 py-4 text-apple-lg', 'h-12', 'rounded-apple-lg'], // 48px
|
|
}
|
|
|
|
// 变体样式
|
|
const variantStyles = {
|
|
filled: [
|
|
'liquid-glass-subtle border-0',
|
|
'focus:liquid-glass focus:shadow-apple-md',
|
|
],
|
|
outlined: [
|
|
'bg-transparent border border-apple-separator-light',
|
|
'hover:border-apple-separator-dark/50',
|
|
'focus:border-apple-blue-light focus:shadow-apple-sm',
|
|
'dark:border-apple-separator-dark',
|
|
'dark:hover:border-apple-separator-light/50',
|
|
'dark:focus:border-apple-blue-dark',
|
|
],
|
|
}
|
|
|
|
// 状态样式
|
|
const stateStyles = {
|
|
default: {
|
|
ring: 'focus:ring-apple-blue-light/30 dark:focus:ring-apple-blue-dark/30',
|
|
border: '',
|
|
},
|
|
error: {
|
|
ring: 'focus:ring-apple-red-light/30 dark:focus:ring-apple-red-dark/30',
|
|
border: variant === 'outlined'
|
|
? 'border-apple-red-light dark:border-apple-red-dark'
|
|
: '',
|
|
},
|
|
success: {
|
|
ring: 'focus:ring-apple-green-light/30 dark:focus:ring-apple-green-dark/30',
|
|
border: variant === 'outlined'
|
|
? 'border-apple-green-light dark:border-apple-green-dark'
|
|
: '',
|
|
},
|
|
warning: {
|
|
ring: 'focus:ring-apple-orange-light/30 dark:focus:ring-apple-orange-dark/30',
|
|
border: variant === 'outlined'
|
|
? 'border-apple-orange-light dark:border-apple-orange-dark'
|
|
: '',
|
|
},
|
|
}
|
|
|
|
// 图标样式
|
|
const iconStyles = 'absolute top-1/2 transform -translate-y-1/2 text-apple-label-secondary-light dark:text-apple-label-secondary-dark'
|
|
const leftIconStyles = cn(iconStyles, 'left-3')
|
|
const rightIconStyles = cn(iconStyles, 'right-3')
|
|
|
|
// 输入框样式
|
|
const inputStyles = cn(
|
|
baseStyles,
|
|
sizeStyles[size],
|
|
variantStyles[variant],
|
|
stateStyles[currentState].ring,
|
|
stateStyles[currentState].border,
|
|
leftIcon && 'pl-10',
|
|
rightIcon && 'pr-10',
|
|
className
|
|
)
|
|
|
|
return (
|
|
<div className={cn('space-y-2', containerClassName)}>
|
|
{/* 标签 */}
|
|
{label && (
|
|
<label className="block text-apple-md font-apple-regular leading-apple-normal text-apple-label-primary-light dark:text-apple-label-primary-dark">
|
|
{label}
|
|
{required && (
|
|
<span className="text-apple-red-light dark:text-apple-red-dark ml-1">*</span>
|
|
)}
|
|
</label>
|
|
)}
|
|
|
|
{/* 输入框容器 */}
|
|
<div className="relative">
|
|
{/* 左侧图标 */}
|
|
{leftIcon && (
|
|
<div className={leftIconStyles}>
|
|
{leftIcon}
|
|
</div>
|
|
)}
|
|
|
|
{/* 输入框 */}
|
|
<input
|
|
ref={ref}
|
|
disabled={disabled}
|
|
className={inputStyles}
|
|
{...props}
|
|
/>
|
|
|
|
{/* 右侧图标 */}
|
|
{rightIcon && (
|
|
<div className={rightIconStyles}>
|
|
{rightIcon}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* 帮助文本或错误文本 */}
|
|
{(errorText || helperText) && (
|
|
<Caption1
|
|
className={cn(
|
|
'block',
|
|
errorText
|
|
? 'text-apple-red-light dark:text-apple-red-dark'
|
|
: 'text-apple-label-secondary-light dark:text-apple-label-secondary-dark'
|
|
)}
|
|
>
|
|
{errorText || helperText}
|
|
</Caption1>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
)
|
|
|
|
Input.displayName = 'Input'
|
|
|
|
/**
|
|
* Textarea 组件
|
|
*/
|
|
export interface TextareaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'size'> {
|
|
variant?: InputVariant
|
|
state?: InputState
|
|
label?: string
|
|
helperText?: string
|
|
errorText?: string
|
|
required?: boolean
|
|
containerClassName?: string
|
|
}
|
|
|
|
export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
({
|
|
variant = 'filled',
|
|
state = 'default',
|
|
label,
|
|
helperText,
|
|
errorText,
|
|
required = false,
|
|
className,
|
|
containerClassName,
|
|
disabled,
|
|
rows = 4,
|
|
...props
|
|
}, ref) => {
|
|
|
|
const currentState = errorText ? 'error' : state
|
|
|
|
const baseStyles = [
|
|
'w-full transition-all duration-apple-fast ease-apple-ease-out',
|
|
'font-apple-system text-apple-label-primary-light',
|
|
'placeholder:text-apple-label-tertiary-light',
|
|
'focus:outline-none focus:ring-2 focus:ring-offset-1',
|
|
'disabled:opacity-50 disabled:cursor-not-allowed',
|
|
'dark:text-apple-label-primary-dark',
|
|
'dark:placeholder:text-apple-label-tertiary-dark',
|
|
'px-4 py-3 text-apple-base rounded-apple-md',
|
|
'resize-vertical min-h-[88px]',
|
|
]
|
|
|
|
const variantStyles = {
|
|
filled: [
|
|
'liquid-glass-subtle border-0',
|
|
'focus:liquid-glass focus:shadow-apple-md',
|
|
],
|
|
outlined: [
|
|
'bg-transparent border border-apple-separator-light',
|
|
'hover:border-apple-separator-dark/50',
|
|
'focus:border-apple-blue-light focus:shadow-apple-sm',
|
|
'dark:border-apple-separator-dark',
|
|
'dark:hover:border-apple-separator-light/50',
|
|
'dark:focus:border-apple-blue-dark',
|
|
],
|
|
}
|
|
|
|
const stateStyles = {
|
|
default: {
|
|
ring: 'focus:ring-apple-blue-light/30 dark:focus:ring-apple-blue-dark/30',
|
|
border: '',
|
|
},
|
|
error: {
|
|
ring: 'focus:ring-apple-red-light/30 dark:focus:ring-apple-red-dark/30',
|
|
border: variant === 'outlined'
|
|
? 'border-apple-red-light dark:border-apple-red-dark'
|
|
: '',
|
|
},
|
|
success: {
|
|
ring: 'focus:ring-apple-green-light/30 dark:focus:ring-apple-green-dark/30',
|
|
border: variant === 'outlined'
|
|
? 'border-apple-green-light dark:border-apple-green-dark'
|
|
: '',
|
|
},
|
|
warning: {
|
|
ring: 'focus:ring-apple-orange-light/30 dark:focus:ring-apple-orange-dark/30',
|
|
border: variant === 'outlined'
|
|
? 'border-apple-orange-light dark:border-apple-orange-dark'
|
|
: '',
|
|
},
|
|
}
|
|
|
|
const textareaStyles = cn(
|
|
baseStyles,
|
|
variantStyles[variant],
|
|
stateStyles[currentState].ring,
|
|
stateStyles[currentState].border,
|
|
className
|
|
)
|
|
|
|
return (
|
|
<div className={cn('space-y-2', containerClassName)}>
|
|
{label && (
|
|
<label className="block text-apple-md font-apple-regular leading-apple-normal text-apple-label-primary-light dark:text-apple-label-primary-dark">
|
|
{label}
|
|
{required && (
|
|
<span className="text-apple-red-light dark:text-apple-red-dark ml-1">*</span>
|
|
)}
|
|
</label>
|
|
)}
|
|
|
|
<textarea
|
|
ref={ref}
|
|
disabled={disabled}
|
|
rows={rows}
|
|
className={textareaStyles}
|
|
{...props}
|
|
/>
|
|
|
|
{(errorText || helperText) && (
|
|
<Caption1
|
|
className={cn(
|
|
'block',
|
|
errorText
|
|
? 'text-apple-red-light dark:text-apple-red-dark'
|
|
: 'text-apple-label-secondary-light dark:text-apple-label-secondary-dark'
|
|
)}
|
|
>
|
|
{errorText || helperText}
|
|
</Caption1>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
)
|
|
|
|
Textarea.displayName = 'Textarea'
|
|
|
|
export default Input |