1---2name: ui-skill3description: UI implementation best practices and conventions for building user interfaces. Use this skill when implementing UI.4---5
6### Technologies
7- Use the following tech to implement the UI:
8 - React 18+
9 - Next.js 16+
10 - Tailwind CSS
11 - Shadcn UI
12 - Framer Motion
13 - Lucide Icons
14
15## Workflow
16
171. Planing
18- Thoroughly understand the requirements
19- Investigate the codebase for existing components and patterns that can be reused
20- Locate where to implement the new UI following the project [Page, Layout and Component Structure](./PAGE_LAYOUT_COMPONENT_STRUCTURE.md)
21- Identify shadcn components and/or blocks that can be used directly or as bases for new components following the [Shadcn UI Components exploration and selection workflow](#shadcn-ui-components-exploration-and-selection-workflow)
22- Suggest user with at least 2 design options refereing the design best practices.
23
242. Implement the pieces
25- Install any shadcn components that has been selected in the planning phase following the [Shadcn UI Components installation and usage workflow](#shadcn-ui-components-installation-and-usage-workflow)
26- Create new components if needed.
27
284. Building the UI
29- Implement the final UI by composing the selected shadcn components and/or newly created components.
30
31
32## Server and Client Components
33
34### Default Behavior
35- All components in `app/` are React Server Components by default
36- Server Components render on the server and can be cached
37- Client Components execute in the browser and enable interactivity
38
39### When to Use Client Components
40Use the `"use client"` directive at the top of a file when you need:
41- State management (`useState`, `useReducer`)
42- Event handlers (`onClick`, `onChange`, etc.)
43- Lifecycle hooks (`useEffect`, `useLayoutEffect`)
44- Browser-only APIs (`window`, `localStorage`, geolocation)
45- Custom React hooks that depend on state/effects
46
47### When to Use Server Components (default)
48Keep components as Server Components when:
49- Fetching data from databases or APIs
50- Accessing backend resources directly
51- Keeping sensitive information secure (API keys, tokens)
52- Reducing JavaScript bundle size
53
54### Best Practices
55- **Minimize Client Components** - Only mark components that need interactivity as Client Components
56- **Push "use client" Deep** - Add the directive to the lowest component that needs it, not parent containers
57- **Composition Pattern** - Pass Server Components as `children` props to Client Components to keep server-rendered content
58- **Data Passing** - Server Components can pass serializable data as props to Client Components
59- **Context Providers** - Wrap providers in Client Components and import into Server Components
60- **Third-Party Libraries** - If a library requires browser APIs, wrap it in your own Client Component
61
62### Security
63- Only environment variables prefixed with `NEXT_PUBLIC_` are exposed to the browser
64- Use the `server-only` package to prevent accidental server code imports in Client Components
65
66
67## Shadcn UI Components exploration and selection workflow
68
69Notes: The registry name is ALWAYS @shadcn when using shadcn tools.
70
711. Use the mcp__shadcn__list_items_in_registries tool to list components in the @shadcn registry
722. Use the mcp__shadcn__search_items_in_registries to fuzzy search for components in the @shadcn registry using keywords
73
74### Shadcn UI Components installation and usage workflow
75
763. Check if the component has already been installed by running `ls components/ui/' in the project root/
774. For components that is not installed install them using `pnpm dlx shadcn@latest add [component]` e.g. pnpm dlx shadcn@latest add button card
785. Before using the component read docuemntion:
79 - Use the mcp__shadcn__get_item_examples_from_registries tool to get usage examples for the component from the @shadcn registry
80 - Check the component source code in the `components/ui/[component]` folder
81
82
83## Page, Layout and Component Structure
84
85### Layout
86- Layouts are used for shared UI, logic and data fetching that is common across multiple pages.
87- Try to make the layout as static as possible, avoid adding dynamic content or data fetching in the layout.
88- Make the higher order layout be shared across the most pages possible.
89- Create new nested layouts when needed to avoid making the higher order layout dynamic.
90
91
92### Page
93- Pages are used for specific routes and can contain dynamic content and data fetching.
94
95
96### Components
97- Components are used for reusable UI pieces that can be shared across pages and layouts.
98- ONLY create components for UI pieces that are reused in at least 2 places or you expect to reuse them in the future.
99- For pieces of code that will not be reused, create them directly in the page or layout file.
100- **Keep Server Components by default** - Only add `"use client"` to components that need interactivity
101- **Push interactivity deep** - Add the `"use client"` directive to the lowest component that needs it (e.g., a button), not the parent container
102- **Example**: A card with a clickable button → Card is Server Component, Button is Client Component
103
104
105### Styling
106- Use Tailwind CSS utility classes for styling.
107- ALWAYS reach for shadcn token variables when styling e.g. bg-primary, text-secondary, etc. first before using raw Tailwind CSS classes.
108- If variation of the shadcn token variables is needed use bg-primary/50, text-secondary/80, etc. to adjust opacity.
109
110#### Shadcn varialbes
111
112
113### **Global**
114
115| Token | Meaning | Use |
116| ------------ | ------------ | -------------------------------- |
117| `background` | Base canvas | Page background, global surfaces |
118| `foreground` | Primary text | Main body text, default icons |
119
120### **Surfaces / Elevation**
121
122| Token | Meaning | Use |
123| -------------------- | -------------------- | --------------------------------------- |
124| `card` | Elevated container | Cards, panels, modular content sections |
125| `card-foreground` | Text inside card | Headlines & body inside cards |
126| `popover` | Floating surface | Menus, dropdowns, tooltips |
127| `popover-foreground` | Text inside popovers | Menu text, tooltip text |
128
129### **Tone / Quiet Content**
130
131| Token | Meaning | Use |
132| ------------------ | -------------- | --------------------------------------------- |
133| `muted` | Subtle surface | Low-attention UI, placeholders, subtle blocks |
134| `muted-foreground` | Subtle text | Metadata, timestamps, helper labels |
135
136### **Actions / Brand Hierarchy**
137
138| Token | Meaning | Use |
139| ---------------------- | --------------------------- | -------------------------------------------------- |
140| `primary` | Main brand / primary action | Primary buttons, strongest calls-to-action |
141| `primary-foreground` | Text on primary | Button text/icons on primary |
142| `secondary` | Supporting action | Secondary buttons, low-priority actions |
143| `secondary-foreground` | Text on secondary | Text/icons on secondary surfaces |
144| `accent` | Highlight / selection | Hover states, selected list items, subtle emphasis |
145| `accent-foreground` | Text on accent | Text inside accent states |
146
147### **Danger / Errors**
148
149| Token | Meaning | Use |
150| ------------------------ | ------------------- | ----------------------------------- |
151| `destructive` | Critical danger | Delete actions, destructive buttons |
152| `destructive-foreground` | Text on destructive | Text/icons on danger surfaces |
153
154### **Structure / Inputs**
155
156| Token | Meaning | Use |
157| -------- | ---------------- | -------------------------------------------- |
158| `border` | Structural lines | Dividers, container edges, card borders |
159| `input` | Form affordance | Input borders/backgrounds |
160| `ring` | Focus halo | Keyboard focus states, accessibility outline |
161
162### **Navigation / Sidebar**
163
164| Token | Meaning | Use |
165| ---------------------------- | ---------------------------- | ------------------------- |
166| `sidebar` | App nav surface | Left nav panel background |
167| `sidebar-foreground` | Nav text | Sidebar labels & icons |
168| `sidebar-primary` | Nav primary action/highlight | Active item, nav CTA |
169| `sidebar-primary-foreground` | Text on sidebar primary | Text/icons in active nav |
170| `sidebar-accent` | Hover/selection in nav | Hover, sub-selection |
171| `sidebar-accent-foreground` | Text on nav accent | Text/icons |
172| `sidebar-border` | Nav separators | Sidebar boundaries |
173| `sidebar-ring` | Nav focus | Focus in navigation area |
174
175### **Data**
176
177| Token | Meaning | Use |
178| ------------ | ----------------------- | --------------------------------- |
179| `chart-1..5` | Categorical data colors | Data visualizations only (not UI) |
180
181### **Shape**
182
183| Token | Meaning | Use |
184| -------- | -------------- | ------------------------------------ |
185| `radius` | Base curvature | Global rounding scale for components |
186
187
188
189
190