Actionable rules that merge solid UX design principles with modern TypeScript + React front-end practices to deliver accessible, performant, research-driven web applications.
Stop designing in the dark. Your users deserve better than guesswork, and your development team deserves workflows that actually deliver results.
You've been there: spending weeks building beautiful interfaces only to watch users struggle with basic tasks. Analytics show drop-offs. Support tickets pile up. Stakeholders question design decisions with zero data to back them up.
The problem isn't your design skills—it's the gap between UX research and frontend implementation. Most teams either:
These Cursor Rules bridge the gap between UX research and TypeScript/React development. Instead of treating design and development as separate phases, you'll build a continuous discovery process where every component is validated, accessible, and measurable.
What you get:
Run user tests every sprint with ≥5 participants through Maze integration. No more building features that users can't actually use.
WCAG 2.2 AA compliance isn't optional—it's baked into every component pattern. Screen readers, keyboard navigation, and semantic HTML become automatic.
Every design choice backed by qualitative interviews and quantitative analytics. Session replays auto-tag rage-clicks directly to your backlog.
Core Web Vitals targets (LCP ≤2.5s, FID ≤100ms) with optimistic UI patterns that make interactions feel instant.
// Generated from Figma design tokens
const tokens = {
colors: {
primary: '#2563eb',
error: '#dc2626'
},
spacing: {
xs: '4px',
sm: '8px',
md: '16px'
}
}
// Component with built-in research validation
export const CheckoutForm = () => {
const { isLoading, error, submitOrder } = useCheckout();
const { trackEvent } = useAnalytics();
const handleSubmit = async (data: OrderData) => {
trackEvent('checkout_attempt', {
step: 'payment',
user_type: 'returning'
});
try {
await submitOrder(data);
// Optimistic UI update
} catch (err) {
// User-friendly error from research insights
showError(errorMapper.paymentFailed(err));
}
};
return (
<form onSubmit={handleSubmit} aria-label="Complete your order">
{/* Accessible form fields with inline validation */}
</form>
);
};
Your development process becomes a research machine:
// Built-in accessibility patterns
export const Modal = ({ isOpen, onClose, children, ...props }) => {
const dialogRef = useRef<HTMLDialogElement>(null);
useEffect(() => {
if (isOpen) {
dialogRef.current?.showModal();
// Trap focus, prevent body scroll
trapFocus(dialogRef.current);
}
}, [isOpen]);
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose();
};
return (
<dialog
ref={dialogRef}
onKeyDown={handleKeyDown}
aria-modal="true"
role="dialog"
{...props}
>
<div className={styles.content}>
{children}
</div>
</dialog>
);
};
# Install the UX development stack
npm install @types/react @testing-library/react @axe-core/react
npm install framer-motion react-query @storybook/react
npm install style-dictionary figma-tokens-transformer
// design-tokens.json (auto-generated from Figma)
{
"colors": {
"primary": {
"50": "#eff6ff",
"500": "#3b82f6",
"900": "#1e3a8a"
}
},
"spacing": {
"xs": "4px",
"sm": "8px",
"md": "16px",
"lg": "24px",
"xl": "32px"
}
}
src/
├── features/
│ ├── checkout/
│ │ ├── components/
│ │ ├── hooks/
│ │ ├── tests/
│ │ └── research/
│ │ ├── user-interviews.md
│ │ ├── usability-tests.md
│ │ └── analytics-tracking.ts
├── components/
├── hooks/
└── tests/
// Automated accessibility testing
describe('CheckoutForm', () => {
it('meets WCAG 2.2 AA standards', async () => {
const { container } = render(<CheckoutForm />);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
it('supports keyboard navigation', async () => {
const user = userEvent.setup();
render(<CheckoutForm />);
await user.tab(); // Should focus first input
await user.tab(); // Should focus second input
await user.keyboard('{Enter}'); // Should submit
});
});
// errorMapper.ts - Convert technical errors to user-friendly messages
export const errorMapper = {
paymentFailed: (error: Error) => {
// Based on user research: users want specific, actionable guidance
if (error.code === 'CARD_DECLINED') {
return {
title: 'Payment method declined',
message: 'Try a different card or contact your bank',
action: 'Update payment method'
};
}
return {
title: 'Payment could not be processed',
message: 'Please try again or contact support',
action: 'Retry payment'
};
}
};
Your development process transforms from "build and hope" to "research, validate, and ship with confidence." Every component you create is accessible, tested with real users, and optimized for human behavior.
Stop guessing what users want. Start building interfaces that actually work for the humans who use them.
You are an expert in the following technology stack:
• Human-Centered & Evidence-Based UX • TypeScript 5+ • React 18+ / Next.js 14+
• HTML5 / Semantic ARIA • CSS3 / SCSS / CSS Modules • Jest / Cypress / Playwright
• Figma (Dev Mode) • Sketch • Axure RP • Maze • Agile UX / Lean UX / SAFe
Key Principles
- Design for humans first: empathy, accessibility, emotional resonance.
- Decisions must be backed by qualitative & quantitative user research (interviews, usability tests, analytics, heat-maps).
- Follow familiarity, progressive disclosure, personalization, and visual hierarchy.
- Iterate rapidly: Build–Measure–Learn loops every sprint (≤2 weeks).
- Balance AI-driven automation with user control & transparency (explainability).
- Consistency over novelty: shared design language, tokenized styles, reusable components.
- Build accessibility in from the start (WCAG 2.2 AA min).
TypeScript / JavaScript Rules
- Prefer React functional components with Hooks; no class components.
- All files are `.tsx` unless they export pure logic (`.ts`).
- Strict compiler options: `"strict": true`, `"noUncheckedIndexedAccess": true`.
- Interfaces > type aliases for exported contracts; use `type` for unions.
- File naming: `kebab-case` for folders, `PascalCase` for React components, `camelCase` for functions/vars.
- Component Structure order: imports → styled-components/CSS Modules → constants → types → component → exports.
- Keep components ≤200 LOC; split UI & logic via hooks (`useStepWizard`, `usePricingCalculator`).
- Descriptive state names with auxiliaries (`isLoading`, `hasError`, `shouldAnimate`).
- Use Early Return pattern; never nest more than 2 `if`s.
- Accessibility:
• All interactive elements use semantic HTML (button, a, input).
• Tie labels with `htmlFor`, describe errors via `aria-describedby`, announce live updates via `aria-live="polite"`.
• Keyboard first: `tabIndex` order, visible focus ring, Esc to close modals.
- Styling:
• Use CSS Modules or Tailwind v3; no global cascade leakage.
• Tokenize colors, spacing, radius in `design-tokens.json` generated from Figma.
• Follow 4-point spacing grid.
Error Handling & Validation
- Validate user input client-side & server-side; never rely on one.
- Display errors inline, closest to the field, in plain language (no codes).
- Prevent loss of user input on error (persist draft in localStorage).
- Use try/catch around async functions; convert technical errors into UX-friendly messages in a central `errorMapper.ts`.
- Use toast/snackbar only for global, non-blocking errors; dialogs for destructive, blocking confirmations.
- Log errors to Sentry with user ID & contextual breadcrumbs (but never PII).
React-Specific Rules
- State management hierarchy: local state → `useContext` → Redux Toolkit / Zustand (only when cross-cutting).
- Data fetching via React Query; use `staleTime` tuned to UX needs.
- Lazy-load heavy routes/components with `React.lazy` + `Suspense` + skeletons.
- Show perceived performance: optimistic UI for CRUD, shimmer placeholders for lists >300 ms.
- Use `framer-motion` for micro-interactions (duration 120–250 ms).
- Adopt feature flags (`launchdarkly`) for A/B & gradual roll-outs.
Testing & Research
- Continuous Discovery: Recruit ≥5 users per sprint for moderated tests through Maze.
- Unit tests (Jest) coverage ≥80 % branches for shared utilities & hooks.
- Component tests (Testing Library + Playwright) for critical workflows (sign-up, checkout).
- Acceptance tests executed nightly on Chrome + Safari + Firefox (latest, ‑1).
- A/B & multivariate tests via Next.js middleware + analytics; run ≥7 days or until 95 % statistical power.
- Session replays (FullStory/Hotjar) auto-tag rage-clicks to backlog.
Performance
- Core Web Vitals: LCP ≤2.5 s, FID ≤100 ms, CLS ≤0.1.
- Use `next/image` with AVIF/WebP, `priority` on hero only.
- Pre-connect to critical domains, lazy-load non-critical scripts (chat, analytics).
- Bundle budgets: JS ≤150 kB gz, CSS ≤50 kB gz.
Security & Privacy
- Mask sensitive fields (`password`, `creditCard`) in logs and replays.
- Consent gate for analytics cookies (GDPR/CCPA compliant).
- Content-Security-Policy: no `unsafe-inline`; use nonces for dynamic styles.
- Do not store PII in localStorage/sessionStorage; use HTTP-only cookies.
File / Folder Structure (src/)
- `components/` – presentational React components
- `features/<domain>/` – state, hooks, slices, sub-components
- `hooks/` – shared custom hooks
- `styles/` – design tokens, global reset, utility classes
- `tests/` – e2e and helpers
Tooling Workflow
1. Ideate in Figma; keep one source of truth for tokens.
2. Export tokens via Style Dictionary → `design-tokens.json`.
3. Generate component prototypes with Storybook; run `chromatic` for visual regression.
4. Use `husky` + `lint-staged` to run ESLint (`@typescript-eslint`, `jsx-a11y`), Stylelint, Jest on pre-commit.
5. CI pipeline: lint → test → build → Percy visual diff → deploy preview (Vercel) → Maze test link.
Common Pitfalls & Guards
- 🛑 Never commit static copy of design files; always embed Figma file ID.
- 🛑 Do not hard-code copy; all strings in `locales/{lang}.json` for i18n & testing.
- ✅ Run Axe automated accessibility checks on every PR.
- ✅ Add loading/error states for every async component before marking ticket "done".
Glossary
HCD = Human-Centered Design, PD = Progressive Disclosure, HIG = Human Interface Guidelines, VRT = Visual Regression Testing.