When working in components directory:
- Always use Tailwind for styling (utility-first, design-token driven)
- Use Motion (package
motion, import motion/react) for meaningful, subtle animations and drag-and-drop (never for decoration only)
- Follow component naming conventions and feature-based structure
- Apply modern UI/UX best practices for clean, intuitive, accessible interfaces
React component guidelines
- Prefer small, focused components with a single responsibility.
- Use server components by default, client components only when needed (state, effects, browser APIs).
- Keep props typed and explicit; avoid
any.
- Lift state only as high as necessary; use Zustand for shared app state when appropriate.
- Derive state instead of duplicating it; avoid unnecessary re-renders (memoize heavy children/selectors).
Tailwind & design system
- Use Tailwind utilities as the primary styling mechanism.
- Centralize colors, spacing, and typography through the existing design tokens (e.g.
bg-background, text-foreground, primary, muted).
- Prefer composed classes in
className over ad-hoc inline styles.
- Keep class lists readable:
- Group related utilities (layout → spacing → typography → color → effects).
- Extract reusable UI patterns into components instead of copy-pasting long class strings.
- Respect dark mode using the app’s theme tokens; never hardcode light-only colors.
Canonical Tailwind usage:
export function Card({ title, children }: { title: string; children: React.ReactNode }) {
return (
<section className="rounded-xl border bg-card p-4 shadow-sm">
<h2 className="mb-2 text-lg font-semibold text-card-foreground">{title}</h2>
<div className="text-sm text-muted-foreground">{children}</div>
</section>
);
}
Motion (animation & drag) principles
- Use Motion for:
- Page transitions, modals/drawers, toasts.
- Emphasizing hierarchy and feedback (hover/press/selection states beyond basic CSS).
- Drag-and-drop of game assets (cards, tokens); use
DraggableAsset or motion with drag/dragConstraints/onDragEnd.
- Prefer variants for complex components and consistent motion across states.
- Animate opacity and transforms (
x/y/scale/rotate) instead of layout properties; use layout for smooth reflows.
- Honor
prefers-reduced-motion and offer non-animated fallbacks for essential interactions.
Canonical motion usage:
import { motion } from "motion/react";
const cardVariants = {
hidden: { opacity: 0, y: 8 },
visible: { opacity: 1, y: 0 },
};
export function AnimatedCard(props: React.ComponentProps<"div">) {
return (
<motion.div
variants={cardVariants}
initial="hidden"
animate="visible"
transition={{ duration: 0.22, ease: "easeOut" }}
{...props}
/>
);
}
UX, accessibility & performance
- Always:
- Use semantic HTML (
button, nav, header, main, section, form, label, etc.).
- Ensure proper keyboard support (tab order,
Enter/Space activation, focus styles).
- Provide accessible names (
aria-label, aria-labelledby) where needed.
- Keep layouts responsive-first:
- Design for mobile, then enhance with responsive Tailwind breakpoints.
- Optimize perceived performance:
- Use skeletons/spinners where loading is noticeable.
- Avoid blocking the main thread with heavy computations in client components.
- Prefer streaming/server data fetching where possible.
Consistency & maintainability
- Reuse shadcn-ui and existing components before creating new ones.
- Keep files small and colocate logic by feature.
- Use clear naming for components and props (
PrimaryButton, isOpen, onClose).
- Delete dead code and avoid half-implemented components; keep the UI surface polished.
1---2name: frontend3description: Working on frontend components4---5When working in components directory:67- Always use **Tailwind** for styling (utility-first, design-token driven)8- Use **Motion** (package `motion`, import `motion/react`) for meaningful, subtle animations and drag-and-drop (never for decoration only)9- Follow **component naming conventions** and feature-based structure10- Apply **modern UI/UX best practices** for clean, intuitive, accessible interfaces1112## React component guidelines1314- Prefer **small, focused components** with a single responsibility.15- Use **server components by default**, client components only when needed (state, effects, browser APIs).16- Keep props **typed and explicit**; avoid `any`.17- Lift state only as high as necessary; use **Zustand** for shared app state when appropriate.18- Derive state instead of duplicating it; avoid unnecessary re-renders (memoize heavy children/selectors).1920## Tailwind & design system2122- Use **Tailwind utilities** as the primary styling mechanism.23- Centralize colors, spacing, and typography through the existing **design tokens** (e.g. `bg-background`, `text-foreground`, `primary`, `muted`).24- Prefer **composed classes** in `className` over ad-hoc inline styles.25- Keep class lists readable:26 - Group related utilities (layout → spacing → typography → color → effects).27 - Extract **reusable UI patterns** into components instead of copy-pasting long class strings.28- Respect dark mode using the app’s theme tokens; never hardcode light-only colors.2930Canonical Tailwind usage:3132```tsx33export function Card({ title, children }: { title: string; children: React.ReactNode }) {34 return (35 <section className="rounded-xl border bg-card p-4 shadow-sm">36 <h2 className="mb-2 text-lg font-semibold text-card-foreground">{title}</h2>37 <div className="text-sm text-muted-foreground">{children}</div>38 </section>39 );40}41```4243## Motion (animation & drag) principles4445- Use **Motion** for:46 - Page transitions, modals/drawers, toasts.47 - Emphasizing hierarchy and feedback (hover/press/selection states beyond basic CSS).48 - **Drag-and-drop** of game assets (cards, tokens); use `DraggableAsset` or `motion` with `drag`/`dragConstraints`/`onDragEnd`.49- Prefer **variants** for complex components and consistent motion across states.50- Animate **opacity and transforms** (`x/y/scale/rotate`) instead of layout properties; use `layout` for smooth reflows.51- Honor `prefers-reduced-motion` and offer non-animated fallbacks for essential interactions.5253Canonical motion usage:5455```tsx56import { motion } from "motion/react";5758const cardVariants = {59 hidden: { opacity: 0, y: 8 },60 visible: { opacity: 1, y: 0 },61};6263export function AnimatedCard(props: React.ComponentProps<"div">) {64 return (65 <motion.div66 variants={cardVariants}67 initial="hidden"68 animate="visible"69 transition={{ duration: 0.22, ease: "easeOut" }}70 {...props}71 />72 );73}74```7576## UX, accessibility & performance7778- Always:79 - Use **semantic HTML** (`button`, `nav`, `header`, `main`, `section`, `form`, `label`, etc.).80 - Ensure proper keyboard support (tab order, `Enter`/`Space` activation, focus styles).81 - Provide accessible names (`aria-label`, `aria-labelledby`) where needed.82- Keep layouts **responsive-first**:83 - Design for mobile, then enhance with responsive Tailwind breakpoints.84- Optimize perceived performance:85 - Use **skeletons/spinners** where loading is noticeable.86 - Avoid blocking the main thread with heavy computations in client components.87 - Prefer streaming/server data fetching where possible.8889## Consistency & maintainability9091- Reuse **shadcn-ui** and existing components before creating new ones.92- Keep files small and colocate logic by feature.93- Use **clear naming** for components and props (`PrimaryButton`, `isOpen`, `onClose`).94- Delete dead code and avoid half-implemented components; keep the UI surface polished.