feat(ui): 重构核心 UI 组件库,新增 shadcn/ui 组件
- 重构 Button、Card、Badge、Input、Textarea 等基础组件 - 新增 Accordion、Alert、Dialog、Dropdown、Form 等 shadcn/ui 组件 - 新增 AnimatedCounter、StatsShowcase、MetricCard 等数据展示组件 - 新增 ScrollReveal 滚动动画组件 - 重构 Toast 通知系统与 Tooltip 提示组件 - 更新设计令牌系统,对齐新品牌视觉
This commit is contained in:
@@ -1,55 +1,34 @@
|
||||
import * as React from "react"
|
||||
import { cn } from "@/lib/utils"
|
||||
import * as React from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
|
||||
label?: string
|
||||
error?: string
|
||||
'data-testid'?: string
|
||||
}
|
||||
|
||||
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||
({ className, label, error, id, ...props }, ref) => {
|
||||
const generatedId = React.useId()
|
||||
const textareaId = id || generatedId
|
||||
const errorId = `${textareaId}-error`
|
||||
|
||||
/**
|
||||
* 标准 shadcn/ui Textarea 组件
|
||||
* 遵循 shadcn/ui 规范:纯 textarea 元素 + data-slot + cn 工具
|
||||
*
|
||||
* 若需 label/error 属性,请使用 LabeledTextarea 组件
|
||||
*/
|
||||
const Textarea = React.forwardRef<HTMLTextAreaElement, React.ComponentProps<'textarea'>>(
|
||||
({ className, ...props }, ref) => {
|
||||
return (
|
||||
<div className="w-full">
|
||||
{label && (
|
||||
<label
|
||||
htmlFor={textareaId}
|
||||
className="block text-sm font-medium text-[var(--color-text-secondary)] mb-2"
|
||||
>
|
||||
{label}
|
||||
{props.required && <span className="text-[var(--color-brand-primary)] ml-1">*</span>}
|
||||
</label>
|
||||
<textarea
|
||||
data-slot="textarea"
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'placeholder:text-text-hint selection:bg-brand selection:text-white',
|
||||
'flex min-h-[80px] w-full rounded-md border border-border-primary bg-bg-primary px-3 py-2 text-base',
|
||||
'transition-all duration-fast outline-none',
|
||||
'disabled:cursor-not-allowed disabled:opacity-50',
|
||||
'md:text-sm',
|
||||
'focus-visible:border-brand focus-visible:ring-2 focus-visible:ring-brand/30',
|
||||
'hover:border-border-secondary',
|
||||
'touch-manipulation resize-y',
|
||||
className
|
||||
)}
|
||||
<textarea
|
||||
id={textareaId}
|
||||
data-slot="textarea"
|
||||
data-testid={props['data-testid']}
|
||||
className={cn(
|
||||
"placeholder:text-[var(--color-text-hint)] selection:bg-[var(--color-primary)] selection:text-white min-h-[140px] w-full rounded-lg border border-[var(--color-border-primary)] bg-[var(--color-bg-section)] px-4 py-3 text-base text-[var(--color-text-primary)] shadow-sm transition-all duration-300 outline-none disabled:cursor-not-allowed disabled:opacity-50 md:min-h-[80px] md:text-sm md:py-2 resize-none",
|
||||
"focus-visible:border-[var(--color-primary)] focus-visible:ring-2 focus-visible:ring-[var(--color-primary)]/50 focus-visible:shadow-lg focus-visible:shadow-[var(--color-primary)]/20",
|
||||
"hover:border-[var(--color-text-secondary)]",
|
||||
error && "border-[var(--color-brand-primary)] focus-visible:border-[var(--color-brand-primary)] focus-visible:ring-[var(--color-brand-primary)]/50",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
aria-required={props.required ? "true" : undefined}
|
||||
aria-invalid={error ? "true" : "false"}
|
||||
aria-describedby={error ? errorId : undefined}
|
||||
{...props}
|
||||
/>
|
||||
{error && (
|
||||
<p id={errorId} className="mt-1 text-sm text-[var(--color-brand-primary)]" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
)
|
||||
Textarea.displayName = "Textarea"
|
||||
);
|
||||
Textarea.displayName = 'Textarea';
|
||||
|
||||
export { Textarea }
|
||||
export { Textarea };
|
||||
|
||||
Reference in New Issue
Block a user