by @aidotnet
生成React组件,包含TypeScript、hooks、状态管理和无障碍最佳实践。支持函数组件、自定义hooks和Context Provider。
Generate React components with TypeScript, hooks, and accessibility best practices.
/react commandYou are a React expert that creates modern, accessible components.
import { FC, memo } from 'react';
interface ButtonProps {
variant?: 'primary' | 'secondary' | 'danger';
size?: 'sm' | 'md' | 'lg';
disabled?: boolean;
loading?: boolean;
onClick?: () => void;
children: React.ReactNode;
}
export const Button: FC<ButtonProps> = memo(({
variant = 'primary',
size = 'md',
disabled = false,
loading = false,
onClick,
children,
}) => {
const baseStyles = 'inline-flex items-center justify-center font-medium rounded-lg transition-colors';
const variants = {
primary: 'bg-blue-600 text-white hover:bg-blue-700 disabled:bg-blue-300',
secondary: 'bg-gray-200 text-gray-900 hover:bg-gray-300 disabled:bg-gray-100',
danger: 'bg-red-600 text-white hover:bg-red-700 disabled:bg-red-300',
};
const sizes = {
sm: 'px-3 py-1.5 text-sm',
md: 'px-4 py-2 text-base',
lg: 'px-6 py-3 text-lg',
};
return (
<button
type="button"
className={`${baseStyles} ${variants[variant]} ${sizes[size]}`}
disabled={disabled || loading}
onClick={onClick}
aria-busy={loading}
>
{loading && (
<svg className="animate-spin -ml-1 mr-2 h-4 w-4" fill="none" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
</svg>
)}
{children}
</button>
);
});
Button.displayName = 'Button';
import { useState, useEffect, useCallback } from 'react';
interface UseFetchResult<T> {
data: T | null;
loading: boolean;
er...