用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tools-only/X-Skills --skill elegant-design-components-and-accessibility命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | elegant-design-components-and-accessibility |
| description | Component Architecture and Accessibility |
Build from small to large:
interface ButtonProps {
variant?: 'primary' | 'secondary' | 'ghost' | 'destructive';
size?: 'sm' | 'md' | 'lg';
loading?: boolean;
disabled?: boolean;
children: React.ReactNode;
onClick?: () => void;
type?: 'button' | 'submit' | 'reset';
}
export function Button({
variant = 'primary',
size = 'md',
loading = false,
disabled = false,
children,
onClick,
type = 'button'
}: ButtonProps) {
return (
<button
type={type}
className={`btn btn-${variant} btn-${size}`}
onClick={onClick}
disabled={disabled || loading}
aria-busy={loading}
>
{loading ? <Spinner /> : children}
</button>
);
}
Prefer composable components:
// Good: Composable
<Card>
<CardHeader>
<CardTitle>Title</CardTitle>
</CardHeader>
<CardContent>
Content here
</CardContent>
</Card>
// Avoid: Props hell
<Card
title="Title"
content="Content"
headerActions={[...]}
footer={...}
/>
Use proper HTML elements:
// Good
<button onClick={handleClick}>Click me</button>
<nav>...</nav>
<main>...</main>
<article>...</article>
// Bad
<div onClick={handleClick}>Click me</div>
<div className="nav">...</div>
// Icon-only button
<button aria-label="Close dialog">
<X size={16} />
</button>
// Form field with description
<div>
<label htmlFor="email">Email</label>
<input
id="email"
type="email"
aria-describedby="email-hint"
/>
<p id="email-hint">We'll never share your email</p>
</div>
// Dynamic content
<div aria-live="polite" aria-atomic="true">
{status}
</div>
All interactive elements must be keyboard accessible:
function Dialog({ open, onClose }: DialogProps) {
useEffect(() => {
if (!open) return;
const handleEscape = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose();
};
document.addEventListener('keydown', handleEscape);
return () => document.removeEventListener('keydown', handleEscape);
}, [open, onClose]);
return (
<div
role="dialog"
aria-modal="true"
tabIndex={-1}
>
{/* Dialog content */}
</div>
);
}
Focus management:
function Modal({ open }: { open: boolean }) {
const modalRef = useRef<HTMLDivElement>(null);
const previousFocus = useRef<HTMLElement | null>(null);
useEffect(() => {
if (open) {
// Save current focus
previousFocus.current = document.activeElement as HTMLElement;
// Focus modal
modalRef.current?.focus();
} else {
// Restore focus
previousFocus.current?.focus();
}
}, [open]);
return (
<div ref={modalRef} tabIndex={-1} role="dialog">
{/* Modal content */}
</div>
);
}
WCAG Requirements:
/* Good contrast */
.good-text {
background: #ffffff;
color: #222222; /* 16.1:1 */
}
/* Poor contrast - fails WCAG */
.poor-text {
background: #ffffff;
color: #999999; /* 2.8:1 */
}
Test with:
// Skip navigation
<a href="#main-content" className="skip-link">
Skip to main content
</a>
// Alternative text for images
<img src="..." alt="Descriptive text" />
// Hidden labels for icon buttons
<button>
<span className="sr-only">Delete item</span>
<Trash size={16} aria-hidden="true" />
</button>
/* Screen reader only content */
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
function FormField({
label,
error,
required,
...inputProps
}: FormFieldProps) {
const id = useId();
const errorId = `${id}-error`;
return (
<div className="form-field">
<label htmlFor={id}>
{label}
{required && <span aria-label="required">*</span>}
</label>
<input
id={id}
aria-invalid={!!error}
aria-describedby={error ? errorId : undefined}
aria-required={required}
{...inputProps}
/>
{error && (
<p id={errorId} className="error" role="alert">
{error}
</p>
)}
</div>
);
}