create-huenei-template 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-component/SKILL.md +288 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-component/references/component-patterns.md +358 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-di/SKILL.md +387 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-di/references/di-patterns.md +519 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-directives/SKILL.md +437 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-directives/references/directive-patterns.md +570 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-forms/SKILL.md +434 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-forms/references/form-patterns.md +398 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-http/SKILL.md +366 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-http/references/http-patterns.md +448 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-routing/SKILL.md +395 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-routing/references/routing-patterns.md +472 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-signals/SKILL.md +302 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-signals/references/signal-patterns.md +404 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-ssr/SKILL.md +435 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-ssr/references/ssr-patterns.md +497 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-testing/SKILL.md +660 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-testing/references/testing-patterns.md +707 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-tooling/SKILL.md +352 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/angular-tooling/references/tooling-patterns.md +448 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-accessibility/SKILL.md +780 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-advanced-components/SKILL.md +718 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-advanced-design-systems/SKILL.md +612 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-advanced-layouts/SKILL.md +594 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-animations/SKILL.md +432 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-animations/references/animation-patterns.md +427 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-debugging/SKILL.md +354 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-debugging/references/troubleshooting-guide.md +306 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-framework-integration/SKILL.md +578 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-framework-integration/references/react-patterns.md +353 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-fundamentals-v4/SKILL.md +608 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-fundamentals-v4/references/advanced-theme-patterns.md +215 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-fundamentals-v4/references/custom-utilities-guide.md +281 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-mobile-first/SKILL.md +768 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-performance/SKILL.md +374 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-performance/references/bundle-optimization.md +244 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-plugins/SKILL.md +505 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-responsive-darkmode/SKILL.md +601 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-responsive-darkmode/references/advanced-responsive-patterns.md +485 -0
- package/dist/templates/frontend/angular-base/.cursor/skills/web-design-guidelines/SKILL.md +39 -0
- package/dist/templates/frontend/angular-base/package.json +0 -1
- package/dist/templates/frontend/angular-base/pnpm-lock.yaml +8183 -0
- package/package.json +1 -1
- package/templates/frontend/angular-base/.cursor/skills/angular-component/SKILL.md +288 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-component/references/component-patterns.md +358 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-di/SKILL.md +387 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-di/references/di-patterns.md +519 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-directives/SKILL.md +437 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-directives/references/directive-patterns.md +570 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-forms/SKILL.md +434 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-forms/references/form-patterns.md +398 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-http/SKILL.md +366 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-http/references/http-patterns.md +448 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-routing/SKILL.md +395 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-routing/references/routing-patterns.md +472 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-signals/SKILL.md +302 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-signals/references/signal-patterns.md +404 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-ssr/SKILL.md +435 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-ssr/references/ssr-patterns.md +497 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-testing/SKILL.md +660 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-testing/references/testing-patterns.md +707 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-tooling/SKILL.md +352 -0
- package/templates/frontend/angular-base/.cursor/skills/angular-tooling/references/tooling-patterns.md +448 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-accessibility/SKILL.md +780 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-advanced-components/SKILL.md +718 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-advanced-design-systems/SKILL.md +612 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-advanced-layouts/SKILL.md +594 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-animations/SKILL.md +432 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-animations/references/animation-patterns.md +427 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-debugging/SKILL.md +354 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-debugging/references/troubleshooting-guide.md +306 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-framework-integration/SKILL.md +578 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-framework-integration/references/react-patterns.md +353 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-fundamentals-v4/SKILL.md +608 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-fundamentals-v4/references/advanced-theme-patterns.md +215 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-fundamentals-v4/references/custom-utilities-guide.md +281 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-mobile-first/SKILL.md +768 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-performance/SKILL.md +374 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-performance/references/bundle-optimization.md +244 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-plugins/SKILL.md +505 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-responsive-darkmode/SKILL.md +601 -0
- package/templates/frontend/angular-base/.cursor/skills/tailwindcss-responsive-darkmode/references/advanced-responsive-patterns.md +485 -0
- package/templates/frontend/angular-base/.cursor/skills/web-design-guidelines/SKILL.md +39 -0
- package/templates/frontend/angular-base/package.json +0 -1
- package/templates/frontend/angular-base/pnpm-lock.yaml +8183 -0
- package/templates/frontend/angular-base/package-lock.json +0 -13321
package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-responsive-darkmode/SKILL.md
ADDED
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: tailwindcss-responsive-darkmode
|
|
3
|
+
description: Tailwind CSS responsive design and dark mode implementation patterns for 2025/2026
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Tailwind CSS Responsive Design & Dark Mode (2025/2026)
|
|
7
|
+
|
|
8
|
+
## Responsive Design
|
|
9
|
+
|
|
10
|
+
### Mobile-First Approach (Industry Standard 2025/2026)
|
|
11
|
+
|
|
12
|
+
Tailwind uses a mobile-first breakpoint system. With over 60% of global web traffic from mobile devices and Google's mobile-first indexing, this approach is essential.
|
|
13
|
+
|
|
14
|
+
**Key Principle**: Unprefixed utilities apply to ALL screen sizes. Breakpoint prefixes apply at that size AND ABOVE.
|
|
15
|
+
|
|
16
|
+
```html
|
|
17
|
+
<!-- CORRECT: Mobile-first (progressive enhancement) -->
|
|
18
|
+
<div class="text-sm md:text-base lg:text-lg">...</div>
|
|
19
|
+
|
|
20
|
+
<!-- INCORRECT: Desktop-first thinking -->
|
|
21
|
+
<div class="lg:text-lg md:text-base text-sm">...</div>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Default Breakpoints
|
|
25
|
+
|
|
26
|
+
| Prefix | Min Width | Typical Devices | CSS Media Query |
|
|
27
|
+
|--------|-----------|-----------------|-----------------|
|
|
28
|
+
| (none) | 0px | All mobile phones | All sizes |
|
|
29
|
+
| `sm:` | 640px (40rem) | Large phones, small tablets | `@media (min-width: 640px)` |
|
|
30
|
+
| `md:` | 768px (48rem) | Tablets (portrait) | `@media (min-width: 768px)` |
|
|
31
|
+
| `lg:` | 1024px (64rem) | Tablets (landscape), laptops | `@media (min-width: 1024px)` |
|
|
32
|
+
| `xl:` | 1280px (80rem) | Desktops | `@media (min-width: 1280px)` |
|
|
33
|
+
| `2xl:` | 1536px (96rem) | Large desktops | `@media (min-width: 1536px)` |
|
|
34
|
+
|
|
35
|
+
### 2025/2026 Device Coverage
|
|
36
|
+
|
|
37
|
+
Common device sizes to test:
|
|
38
|
+
- **320px**: Older iPhones, smallest supported
|
|
39
|
+
- **375px**: Modern iPhone base (~17% of mobile)
|
|
40
|
+
- **390-430px**: Modern large phones (~35% of mobile)
|
|
41
|
+
- **768px**: iPad portrait
|
|
42
|
+
- **1024px**: iPad landscape, laptops
|
|
43
|
+
- **1280px**: Standard laptops/desktops
|
|
44
|
+
- **1440px**: Large desktops
|
|
45
|
+
- **1920px**: Full HD displays
|
|
46
|
+
|
|
47
|
+
### Custom Breakpoints
|
|
48
|
+
|
|
49
|
+
```css
|
|
50
|
+
@theme {
|
|
51
|
+
/* Add custom breakpoints for specific content needs */
|
|
52
|
+
--breakpoint-xs: 20rem; /* 320px - very small devices */
|
|
53
|
+
--breakpoint-3xl: 100rem; /* 1600px */
|
|
54
|
+
--breakpoint-4xl: 120rem; /* 1920px - full HD */
|
|
55
|
+
|
|
56
|
+
/* Override existing breakpoints based on YOUR content */
|
|
57
|
+
--breakpoint-sm: 36rem; /* 576px - when content needs space */
|
|
58
|
+
--breakpoint-lg: 62rem; /* 992px - common content width */
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Usage:
|
|
63
|
+
```html
|
|
64
|
+
<div class="grid xs:grid-cols-2 3xl:grid-cols-6">
|
|
65
|
+
<!-- Custom breakpoints work like built-in ones -->
|
|
66
|
+
</div>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Content-Driven Breakpoints (2025 Best Practice)
|
|
70
|
+
|
|
71
|
+
Instead of targeting devices, let your content determine breakpoints:
|
|
72
|
+
|
|
73
|
+
```css
|
|
74
|
+
@theme {
|
|
75
|
+
/* Based on content needs, not device specs */
|
|
76
|
+
--breakpoint-prose: 65ch; /* Optimal reading width */
|
|
77
|
+
--breakpoint-content: 75rem; /* Main content max */
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Test your design at various widths and add breakpoints where layout breaks.
|
|
82
|
+
|
|
83
|
+
### Responsive Examples
|
|
84
|
+
|
|
85
|
+
#### Responsive Grid
|
|
86
|
+
|
|
87
|
+
```html
|
|
88
|
+
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
|
|
89
|
+
<div>Item 1</div>
|
|
90
|
+
<div>Item 2</div>
|
|
91
|
+
<div>Item 3</div>
|
|
92
|
+
<div>Item 4</div>
|
|
93
|
+
</div>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Responsive Typography
|
|
97
|
+
|
|
98
|
+
```html
|
|
99
|
+
<h1 class="text-2xl sm:text-3xl md:text-4xl lg:text-5xl font-bold">
|
|
100
|
+
Responsive Heading
|
|
101
|
+
</h1>
|
|
102
|
+
|
|
103
|
+
<p class="text-sm md:text-base lg:text-lg leading-relaxed">
|
|
104
|
+
Responsive paragraph text
|
|
105
|
+
</p>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Responsive Spacing
|
|
109
|
+
|
|
110
|
+
```html
|
|
111
|
+
<section class="py-8 md:py-12 lg:py-16 px-4 md:px-8 lg:px-12">
|
|
112
|
+
<div class="max-w-4xl mx-auto">
|
|
113
|
+
Content with responsive padding
|
|
114
|
+
</div>
|
|
115
|
+
</section>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Responsive Navigation
|
|
119
|
+
|
|
120
|
+
```html
|
|
121
|
+
<nav class="flex flex-col md:flex-row items-center justify-between">
|
|
122
|
+
<div class="hidden md:flex gap-4">
|
|
123
|
+
<!-- Desktop navigation -->
|
|
124
|
+
</div>
|
|
125
|
+
<button class="md:hidden">
|
|
126
|
+
<!-- Mobile menu button -->
|
|
127
|
+
</button>
|
|
128
|
+
</nav>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### Show/Hide Based on Screen Size
|
|
132
|
+
|
|
133
|
+
```html
|
|
134
|
+
<!-- Hidden on mobile, visible on desktop -->
|
|
135
|
+
<div class="hidden md:block">Desktop only</div>
|
|
136
|
+
|
|
137
|
+
<!-- Visible on mobile, hidden on desktop -->
|
|
138
|
+
<div class="block md:hidden">Mobile only</div>
|
|
139
|
+
|
|
140
|
+
<!-- Different content per breakpoint -->
|
|
141
|
+
<span class="sm:hidden">XS</span>
|
|
142
|
+
<span class="hidden sm:inline md:hidden">SM</span>
|
|
143
|
+
<span class="hidden md:inline lg:hidden">MD</span>
|
|
144
|
+
<span class="hidden lg:inline xl:hidden">LG</span>
|
|
145
|
+
<span class="hidden xl:inline 2xl:hidden">XL</span>
|
|
146
|
+
<span class="hidden 2xl:inline">2XL</span>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Container Queries (v4) - 2025 Game-Changer
|
|
150
|
+
|
|
151
|
+
Container queries enable component-level responsiveness, independent of viewport size. This is essential for reusable components in 2025.
|
|
152
|
+
|
|
153
|
+
```css
|
|
154
|
+
@plugin "@tailwindcss/container-queries";
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```html
|
|
158
|
+
<!-- Mark parent as a query container -->
|
|
159
|
+
<div class="@container">
|
|
160
|
+
<div class="flex flex-col @md:flex-row @lg:gap-8">
|
|
161
|
+
<!-- Responds to container size, not viewport -->
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
|
|
165
|
+
<!-- Named containers for multiple contexts -->
|
|
166
|
+
<div class="@container/card">
|
|
167
|
+
<div class="@lg/card:grid-cols-2 grid grid-cols-1">
|
|
168
|
+
<!-- Responds specifically to 'card' container -->
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Container Query Breakpoints
|
|
174
|
+
|
|
175
|
+
| Class | Min-width | Use Case |
|
|
176
|
+
|-------|-----------|----------|
|
|
177
|
+
| `@xs` | 20rem (320px) | Small widgets |
|
|
178
|
+
| `@sm` | 24rem (384px) | Compact cards |
|
|
179
|
+
| `@md` | 28rem (448px) | Standard cards |
|
|
180
|
+
| `@lg` | 32rem (512px) | Wide cards |
|
|
181
|
+
| `@xl` | 36rem (576px) | Full-width components |
|
|
182
|
+
| `@2xl` | 42rem (672px) | Large containers |
|
|
183
|
+
| `@3xl` | 48rem (768px) | Page sections |
|
|
184
|
+
|
|
185
|
+
### When to Use Container vs Viewport Queries
|
|
186
|
+
|
|
187
|
+
| Container Queries | Viewport Queries |
|
|
188
|
+
|-------------------|------------------|
|
|
189
|
+
| Reusable components | Page-level layouts |
|
|
190
|
+
| Cards in various contexts | Navigation bars |
|
|
191
|
+
| Sidebar widgets | Hero sections |
|
|
192
|
+
| CMS/embedded content | Full-width sections |
|
|
193
|
+
|
|
194
|
+
### Max-Width Breakpoints
|
|
195
|
+
|
|
196
|
+
Target screens below a certain size:
|
|
197
|
+
|
|
198
|
+
```html
|
|
199
|
+
<!-- Only on screens smaller than md (< 768px) -->
|
|
200
|
+
<div class="md:hidden">Small screens only</div>
|
|
201
|
+
|
|
202
|
+
<!-- Custom max-width media query -->
|
|
203
|
+
<div class="[@media(max-width:600px)]:text-sm">
|
|
204
|
+
Custom max-width
|
|
205
|
+
</div>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Dark Mode
|
|
209
|
+
|
|
210
|
+
### Strategy: Media (Default)
|
|
211
|
+
|
|
212
|
+
Dark mode follows the user's operating system preference using `prefers-color-scheme`:
|
|
213
|
+
|
|
214
|
+
```css
|
|
215
|
+
@import "tailwindcss";
|
|
216
|
+
/* No additional configuration needed */
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
```html
|
|
220
|
+
<div class="bg-white dark:bg-gray-900">
|
|
221
|
+
<h1 class="text-gray-900 dark:text-white">Title</h1>
|
|
222
|
+
<p class="text-gray-600 dark:text-gray-300">Content</p>
|
|
223
|
+
</div>
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Strategy: Selector (Manual Toggle)
|
|
227
|
+
|
|
228
|
+
Control dark mode with a CSS class:
|
|
229
|
+
|
|
230
|
+
```css
|
|
231
|
+
@import "tailwindcss";
|
|
232
|
+
|
|
233
|
+
@custom-variant dark (&:where(.dark, .dark *));
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
```html
|
|
237
|
+
<!-- Add .dark class to html or body to enable dark mode -->
|
|
238
|
+
<html class="dark">
|
|
239
|
+
<body>
|
|
240
|
+
<div class="bg-white dark:bg-gray-900">
|
|
241
|
+
Content
|
|
242
|
+
</div>
|
|
243
|
+
</body>
|
|
244
|
+
</html>
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### JavaScript Toggle
|
|
248
|
+
|
|
249
|
+
```javascript
|
|
250
|
+
// Simple toggle
|
|
251
|
+
function toggleDarkMode() {
|
|
252
|
+
document.documentElement.classList.toggle('dark');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// With localStorage persistence
|
|
256
|
+
function initDarkMode() {
|
|
257
|
+
const isDark = localStorage.getItem('darkMode') === 'true' ||
|
|
258
|
+
(!localStorage.getItem('darkMode') &&
|
|
259
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
260
|
+
|
|
261
|
+
document.documentElement.classList.toggle('dark', isDark);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function toggleDarkMode() {
|
|
265
|
+
const isDark = document.documentElement.classList.toggle('dark');
|
|
266
|
+
localStorage.setItem('darkMode', isDark);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Initialize on page load
|
|
270
|
+
initDarkMode();
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Three-Way Toggle (Light/Dark/System)
|
|
274
|
+
|
|
275
|
+
```javascript
|
|
276
|
+
const themes = ['light', 'dark', 'system'];
|
|
277
|
+
|
|
278
|
+
function setTheme(theme) {
|
|
279
|
+
localStorage.setItem('theme', theme);
|
|
280
|
+
applyTheme();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function applyTheme() {
|
|
284
|
+
const theme = localStorage.getItem('theme') || 'system';
|
|
285
|
+
const isDark = theme === 'dark' ||
|
|
286
|
+
(theme === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
287
|
+
|
|
288
|
+
document.documentElement.classList.toggle('dark', isDark);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Listen for system preference changes
|
|
292
|
+
window.matchMedia('(prefers-color-scheme: dark)')
|
|
293
|
+
.addEventListener('change', () => {
|
|
294
|
+
if (localStorage.getItem('theme') === 'system') {
|
|
295
|
+
applyTheme();
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
applyTheme();
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Data Attribute Strategy
|
|
303
|
+
|
|
304
|
+
```css
|
|
305
|
+
@custom-variant dark (&:where([data-theme="dark"], [data-theme="dark"] *));
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
```html
|
|
309
|
+
<html data-theme="dark">
|
|
310
|
+
<body>
|
|
311
|
+
<div class="bg-white dark:bg-gray-900">Content</div>
|
|
312
|
+
</body>
|
|
313
|
+
</html>
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Dark Mode with Next.js (next-themes)
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
npm install next-themes
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
```jsx
|
|
323
|
+
// app/providers.tsx
|
|
324
|
+
'use client';
|
|
325
|
+
|
|
326
|
+
import { ThemeProvider } from 'next-themes';
|
|
327
|
+
|
|
328
|
+
export function Providers({ children }) {
|
|
329
|
+
return (
|
|
330
|
+
<ThemeProvider attribute="class" defaultTheme="system">
|
|
331
|
+
{children}
|
|
332
|
+
</ThemeProvider>
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
```jsx
|
|
338
|
+
// app/layout.tsx
|
|
339
|
+
import { Providers } from './providers';
|
|
340
|
+
|
|
341
|
+
export default function RootLayout({ children }) {
|
|
342
|
+
return (
|
|
343
|
+
<html lang="en" suppressHydrationWarning>
|
|
344
|
+
<body>
|
|
345
|
+
<Providers>{children}</Providers>
|
|
346
|
+
</body>
|
|
347
|
+
</html>
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
```jsx
|
|
353
|
+
// components/ThemeToggle.tsx
|
|
354
|
+
'use client';
|
|
355
|
+
|
|
356
|
+
import { useTheme } from 'next-themes';
|
|
357
|
+
|
|
358
|
+
export function ThemeToggle() {
|
|
359
|
+
const { theme, setTheme } = useTheme();
|
|
360
|
+
|
|
361
|
+
return (
|
|
362
|
+
<button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
|
|
363
|
+
Toggle Theme
|
|
364
|
+
</button>
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### Dark Mode Color Palette
|
|
370
|
+
|
|
371
|
+
```html
|
|
372
|
+
<!-- Text colors -->
|
|
373
|
+
<p class="text-gray-900 dark:text-gray-100">Primary text</p>
|
|
374
|
+
<p class="text-gray-600 dark:text-gray-400">Secondary text</p>
|
|
375
|
+
<p class="text-gray-400 dark:text-gray-500">Muted text</p>
|
|
376
|
+
|
|
377
|
+
<!-- Background colors -->
|
|
378
|
+
<div class="bg-white dark:bg-gray-900">Page background</div>
|
|
379
|
+
<div class="bg-gray-50 dark:bg-gray-800">Card background</div>
|
|
380
|
+
<div class="bg-gray-100 dark:bg-gray-700">Elevated background</div>
|
|
381
|
+
|
|
382
|
+
<!-- Border colors -->
|
|
383
|
+
<div class="border border-gray-200 dark:border-gray-700">Bordered element</div>
|
|
384
|
+
|
|
385
|
+
<!-- Interactive elements -->
|
|
386
|
+
<button class="bg-blue-500 hover:bg-blue-600 dark:bg-blue-600 dark:hover:bg-blue-700">
|
|
387
|
+
Button
|
|
388
|
+
</button>
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### Dark Mode with CSS Variables
|
|
392
|
+
|
|
393
|
+
```css
|
|
394
|
+
@theme {
|
|
395
|
+
/* Light mode colors (default) */
|
|
396
|
+
--color-bg-primary: oklch(1 0 0);
|
|
397
|
+
--color-bg-secondary: oklch(0.98 0 0);
|
|
398
|
+
--color-text-primary: oklch(0.15 0 0);
|
|
399
|
+
--color-text-secondary: oklch(0.4 0 0);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/* Dark mode overrides */
|
|
403
|
+
@media (prefers-color-scheme: dark) {
|
|
404
|
+
:root {
|
|
405
|
+
--color-bg-primary: oklch(0.15 0 0);
|
|
406
|
+
--color-bg-secondary: oklch(0.2 0 0);
|
|
407
|
+
--color-text-primary: oklch(0.95 0 0);
|
|
408
|
+
--color-text-secondary: oklch(0.7 0 0);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
```html
|
|
414
|
+
<div class="bg-[var(--color-bg-primary)] text-[var(--color-text-primary)]">
|
|
415
|
+
Semantic colors
|
|
416
|
+
</div>
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### Typography Plugin Dark Mode
|
|
420
|
+
|
|
421
|
+
```html
|
|
422
|
+
<article class="prose dark:prose-invert">
|
|
423
|
+
<!-- Markdown content automatically adapts to dark mode -->
|
|
424
|
+
</article>
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
## Combining Responsive and Dark Mode
|
|
428
|
+
|
|
429
|
+
```html
|
|
430
|
+
<!-- Different layouts AND colors based on screen size and theme -->
|
|
431
|
+
<div class="
|
|
432
|
+
grid grid-cols-1 md:grid-cols-2
|
|
433
|
+
bg-white dark:bg-gray-900
|
|
434
|
+
p-4 md:p-8
|
|
435
|
+
text-gray-900 dark:text-white
|
|
436
|
+
">
|
|
437
|
+
<div class="hidden dark:md:block">
|
|
438
|
+
Only visible on md+ screens in dark mode
|
|
439
|
+
</div>
|
|
440
|
+
</div>
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
## Best Practices (2025/2026)
|
|
444
|
+
|
|
445
|
+
### 1. Start Mobile, Then Enhance
|
|
446
|
+
|
|
447
|
+
```html
|
|
448
|
+
<!-- CORRECT: Mobile-first progression -->
|
|
449
|
+
<div class="text-sm md:text-base lg:text-lg">
|
|
450
|
+
|
|
451
|
+
<!-- WRONG: Desktop-first thinking (more code, more bugs) -->
|
|
452
|
+
<div class="lg:text-lg md:text-base text-sm">
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
### 2. Touch-Friendly Interactive Elements
|
|
456
|
+
|
|
457
|
+
WCAG 2.2 requires 24x24px minimum, but 44x44px is recommended:
|
|
458
|
+
|
|
459
|
+
```html
|
|
460
|
+
<!-- Touch-friendly button (44px minimum) -->
|
|
461
|
+
<button class="min-h-11 min-w-11 px-4 py-2.5">
|
|
462
|
+
Click me
|
|
463
|
+
</button>
|
|
464
|
+
|
|
465
|
+
<!-- Touch-friendly navigation link -->
|
|
466
|
+
<a href="#" class="block py-3 px-4 min-h-11">
|
|
467
|
+
Navigation Item
|
|
468
|
+
</a>
|
|
469
|
+
|
|
470
|
+
<!-- Adequate spacing between touch targets -->
|
|
471
|
+
<div class="flex gap-3">
|
|
472
|
+
<button class="min-h-11 px-4 py-2">Button 1</button>
|
|
473
|
+
<button class="min-h-11 px-4 py-2">Button 2</button>
|
|
474
|
+
</div>
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
### 3. Fluid Typography (Eliminates Breakpoint Jumps)
|
|
478
|
+
|
|
479
|
+
```css
|
|
480
|
+
@theme {
|
|
481
|
+
--text-fluid-base: clamp(1rem, 0.9rem + 0.5vw, 1.25rem);
|
|
482
|
+
--text-fluid-lg: clamp(1.25rem, 1rem + 1.25vw, 2rem);
|
|
483
|
+
--text-fluid-xl: clamp(1.5rem, 1rem + 2.5vw, 3rem);
|
|
484
|
+
}
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
```html
|
|
488
|
+
<h1 class="text-fluid-xl font-bold">Smoothly Scaling Heading</h1>
|
|
489
|
+
<p class="text-fluid-base leading-relaxed">Smoothly scaling body text.</p>
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
### 2. Use Semantic Dark Mode Colors
|
|
493
|
+
|
|
494
|
+
```css
|
|
495
|
+
@theme {
|
|
496
|
+
/* Instead of raw colors, use semantic names */
|
|
497
|
+
--color-surface: oklch(1 0 0);
|
|
498
|
+
--color-surface-dark: oklch(0.15 0 0);
|
|
499
|
+
--color-on-surface: oklch(0.1 0 0);
|
|
500
|
+
--color-on-surface-dark: oklch(0.95 0 0);
|
|
501
|
+
}
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
### 3. Test All Breakpoints
|
|
505
|
+
|
|
506
|
+
Use the debug-screens plugin during development:
|
|
507
|
+
|
|
508
|
+
```bash
|
|
509
|
+
npm install -D @tailwindcss/debug-screens
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
```css
|
|
513
|
+
@plugin "@tailwindcss/debug-screens";
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
### 4. Reduce Repetition with Components
|
|
517
|
+
|
|
518
|
+
```css
|
|
519
|
+
/* components.css */
|
|
520
|
+
@layer components {
|
|
521
|
+
.card {
|
|
522
|
+
@apply bg-white dark:bg-gray-800 rounded-lg p-6 shadow-sm;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
.section {
|
|
526
|
+
@apply py-12 md:py-16 lg:py-24;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
### 5. Consider Color Contrast
|
|
532
|
+
|
|
533
|
+
Ensure sufficient contrast in both light and dark modes (WCAG 2.2):
|
|
534
|
+
- **Normal text**: 4.5:1 contrast ratio minimum
|
|
535
|
+
- **Large text (18pt+)**: 3:1 contrast ratio minimum
|
|
536
|
+
- **Interactive elements**: 3:1 against adjacent colors
|
|
537
|
+
|
|
538
|
+
```html
|
|
539
|
+
<!-- Good contrast in both modes -->
|
|
540
|
+
<button class="
|
|
541
|
+
bg-blue-600 text-white
|
|
542
|
+
dark:bg-blue-500 dark:text-white
|
|
543
|
+
hover:bg-blue-700 dark:hover:bg-blue-400
|
|
544
|
+
/* Focus ring for accessibility */
|
|
545
|
+
focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2
|
|
546
|
+
">
|
|
547
|
+
Action
|
|
548
|
+
</button>
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
### 6. Reduced Motion Preference
|
|
552
|
+
|
|
553
|
+
Respect users who prefer reduced motion:
|
|
554
|
+
|
|
555
|
+
```html
|
|
556
|
+
<div class="
|
|
557
|
+
transition-transform duration-300
|
|
558
|
+
hover:scale-105
|
|
559
|
+
motion-reduce:transition-none
|
|
560
|
+
motion-reduce:hover:scale-100
|
|
561
|
+
">
|
|
562
|
+
Respects motion preferences
|
|
563
|
+
</div>
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
### 7. Performance-Optimized Responsive Images
|
|
567
|
+
|
|
568
|
+
```html
|
|
569
|
+
<!-- Lazy load below-fold images -->
|
|
570
|
+
<img
|
|
571
|
+
src="image.jpg"
|
|
572
|
+
alt="Description"
|
|
573
|
+
loading="lazy"
|
|
574
|
+
class="w-full h-auto"
|
|
575
|
+
/>
|
|
576
|
+
|
|
577
|
+
<!-- Responsive srcset -->
|
|
578
|
+
<img
|
|
579
|
+
src="medium.jpg"
|
|
580
|
+
srcset="small.jpg 400w, medium.jpg 800w, large.jpg 1200w"
|
|
581
|
+
sizes="(min-width: 1024px) 50vw, 100vw"
|
|
582
|
+
alt="Responsive image"
|
|
583
|
+
loading="lazy"
|
|
584
|
+
class="w-full h-auto"
|
|
585
|
+
/>
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
### 8. Safe Area Handling (Notched Devices)
|
|
589
|
+
|
|
590
|
+
```css
|
|
591
|
+
@utility safe-area-pb {
|
|
592
|
+
padding-bottom: env(safe-area-inset-bottom);
|
|
593
|
+
}
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
```html
|
|
597
|
+
<!-- Bottom navigation respects device notch -->
|
|
598
|
+
<nav class="fixed bottom-0 inset-x-0 safe-area-pb bg-white border-t">
|
|
599
|
+
Navigation
|
|
600
|
+
</nav>
|
|
601
|
+
```
|