@tydavidson/design-system 1.1.20 → 1.2.2

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.
@@ -1,6 +1,6 @@
1
1
  # Theme Usage Guide
2
2
 
3
- This guide explains how to use the theme system in the Float Design System.
3
+ This guide explains how to use the modern, simplified theme system in the Float Design System, compatible with the Next.js App Router.
4
4
 
5
5
  ## Quick Start
6
6
 
@@ -12,281 +12,122 @@ npm install @tydavidson/design-system
12
12
 
13
13
  ### 2. Import CSS
14
14
 
15
- ```tsx
16
- // In your main CSS file or layout
17
- import '@tydavidson/design-system/src/themes/theme.css';
15
+ In your main CSS file (e.g., `app/globals.css`), import the theme styles:
16
+
17
+ ```css
18
+ @import '@tydavidson/design-system/src/themes/theme.css';
18
19
  ```
19
20
 
20
21
  ### 3. Set Up Theme Provider
21
22
 
22
- ```tsx
23
- // app/layout.tsx
24
- import { ClientThemeProvider } from '@tydavidson/design-system/themes';
25
-
26
- export default function RootLayout({ children }) {
27
- return (
28
- <html lang="en" suppressHydrationWarning>
29
- <body>
30
- <ClientThemeProvider>
31
- {children}
32
- </ClientThemeProvider>
33
- </body>
34
- </html>
35
- );
36
- }
37
- ```
38
-
39
- ### 4. Use Theme Toggle
23
+ The `ThemeProvider` must be used within a Client Component. The recommended approach is to create a dedicated `providers.tsx` file to house all client-side providers.
40
24
 
25
+ **Create `app/components/providers.tsx`:**
41
26
  ```tsx
42
- // In any component
43
- import { ClientThemeToggle } from '@tydavidson/design-system/themes';
44
-
45
- export default function MyPage() {
46
- return (
47
- <div>
48
- <h1>My App</h1>
49
- <ClientThemeToggle />
50
- </div>
51
- );
52
- }
53
- ```
54
-
55
- ## Available Components
56
-
57
- ### Server Component Safe Components
58
-
59
- These components can be used in Server Components without any issues:
60
-
61
- - **`ClientThemeProvider`** - Theme provider for Server Components
62
- - **`ClientThemeToggle`** - Theme toggle for Server Components
63
- - **`useThemeServer`** - Server-safe theme hook
64
-
65
- ### Client Component Only Components
27
+ "use client"
66
28
 
67
- These components can only be used in Client Components:
29
+ import { ThemeProvider } from "@tydavidson/design-system"
68
30
 
69
- - **`ThemeProvider`** - Standard theme provider (use `ClientThemeProvider` instead)
70
- - **`ThemeProviderNoSSR`** - NoSSR theme provider (use `ClientThemeProvider` instead)
71
-
72
- ## Usage Examples
73
-
74
- ### Server Components
75
-
76
- ```tsx
77
- import { ClientThemeToggle, useThemeServer } from '@tydavidson/design-system/themes';
78
-
79
- export default function ServerComponent() {
80
- const { theme, isDark } = useThemeServer();
81
-
31
+ export function Providers({ children }: { children: React.ReactNode }) {
82
32
  return (
83
- <div className={isDark ? 'dark' : 'light'}>
84
- <h1>Current theme: {theme}</h1>
85
- <ClientThemeToggle />
86
- </div>
87
- );
33
+ <ThemeProvider
34
+ attribute="class"
35
+ defaultTheme="system"
36
+ enableSystem
37
+ disableTransitionOnChange
38
+ >
39
+ {children}
40
+ </ThemeProvider>
41
+ )
88
42
  }
89
43
  ```
90
44
 
91
- ### Client Components
92
-
45
+ **Update your root layout `app/layout.tsx`:**
93
46
  ```tsx
94
- 'use client';
95
- import { ClientThemeToggle } from '@tydavidson/design-system/themes';
47
+ import { Providers } from "./components/providers"
96
48
 
97
- export default function ClientComponent() {
98
- return (
99
- <div>
100
- <h1>My Client Component</h1>
101
- <ClientThemeToggle />
102
- </div>
103
- );
104
- }
105
- ```
106
-
107
- ### Layout Setup
108
-
109
- ```tsx
110
- // app/layout.tsx
111
- import { ClientThemeProvider } from '@tydavidson/design-system/themes';
112
-
113
- export default function RootLayout({ children }) {
49
+ export default function RootLayout({
50
+ children,
51
+ }: {
52
+ children: React.ReactNode
53
+ }) {
114
54
  return (
115
55
  <html lang="en" suppressHydrationWarning>
116
56
  <body>
117
- <ClientThemeProvider
118
- attribute="class"
119
- defaultTheme="system"
120
- enableSystem
121
- disableTransitionOnChange
122
- >
57
+ <Providers>
123
58
  {children}
124
- </ClientThemeProvider>
59
+ </Providers>
125
60
  </body>
126
61
  </html>
127
- );
62
+ )
128
63
  }
129
64
  ```
130
65
 
131
- ## Theme Configuration
132
-
133
- ### CSS Variables
134
-
135
- The theme system uses CSS custom properties for colors:
136
-
137
- ```css
138
- :root {
139
- --bg-primary: #ffffff;
140
- --text-primary: #000000;
141
- --accent-primary: #3b82f6;
142
- }
143
-
144
- .dark {
145
- --bg-primary: #000000;
146
- --text-primary: #ffffff;
147
- --accent-primary: #60a5fa;
148
- }
149
- ```
150
-
151
- ### Tailwind Configuration
152
-
153
- Configure Tailwind to use the CSS variables:
154
-
155
- ```js
156
- // tailwind.config.js
157
- module.exports = {
158
- darkMode: ["class"],
159
- content: [
160
- "./src/**/*.{js,ts,jsx,tsx}",
161
- "./node_modules/@tydavidson/design-system/dist/**/*.{js,mjs}",
162
- ],
163
- theme: {
164
- extend: {
165
- colors: {
166
- background: "var(--bg-primary)",
167
- foreground: "var(--text-primary)",
168
- primary: {
169
- DEFAULT: "var(--accent-primary)",
170
- foreground: "var(--text-primary)",
171
- },
172
- },
173
- },
174
- },
175
- };
176
- ```
177
-
178
- ## Theme Utilities
66
+ ### 4. Use Theme Toggle
179
67
 
180
- ### Server-Safe Theme Detection
68
+ You can now use the `ClientThemeToggle` in any component.
181
69
 
182
70
  ```tsx
183
- import { useThemeServer } from '@tydavidson/design-system/themes';
71
+ import { ClientThemeToggle } from '@tydavidson/design-system/themes';
184
72
 
185
- export default function ServerComponent() {
186
- const { theme, isDark } = useThemeServer();
187
-
73
+ export default function MyPage() {
188
74
  return (
189
- <div className={isDark ? 'dark-theme' : 'light-theme'}>
190
- Current theme: {theme}
75
+ <div>
76
+ <h1>My App</h1>
77
+ <ClientThemeToggle />
191
78
  </div>
192
79
  );
193
80
  }
194
81
  ```
195
82
 
196
- ### Theme Utilities
197
-
198
- ```tsx
199
- import {
200
- isDarkTheme,
201
- mapColorToShadcnVariant,
202
- mapVariantToShadcnVariant,
203
- getColorVariantClasses
204
- } from '@tydavidson/design-system/themes';
205
-
206
- // Check if theme is dark
207
- const isDark = isDarkTheme('dark', 'dark');
208
-
209
- // Map design system colors to shadcn variants
210
- const variant = mapColorToShadcnVariant('brand'); // 'default'
211
-
212
- // Map design system variants to shadcn variants
213
- const shadcnVariant = mapVariantToShadcnVariant('primary'); // 'default'
214
-
215
- // Get Tailwind classes for color/variant combinations
216
- const classes = getColorVariantClasses('brand', 'primary');
217
- ```
218
-
219
- ## Migration Guide
220
-
221
- ### From Previous Versions
222
-
223
- If you were using the old theme system:
224
-
225
- **Before:**
226
- ```tsx
227
- import { ThemeToggle, useTheme } from '@tydavidson/design-system/themes';
83
+ ## Available Components
228
84
 
229
- export default function MyComponent() {
230
- const { theme, setTheme } = useTheme();
231
- return <ThemeToggle />;
232
- }
233
- ```
85
+ ### `ThemeProvider`
86
+ The main provider for the theme system. It is a Client Component that wraps the `next-themes` provider with sensible defaults for the design system.
234
87
 
235
- **After:**
236
- ```tsx
237
- import { ClientThemeToggle, useThemeServer } from '@tydavidson/design-system/themes';
88
+ ### `ClientThemeToggle`
89
+ A Server Component-safe theme toggle button. This component can be used anywhere in your application.
238
90
 
239
- export default function MyComponent() {
240
- const { theme } = useThemeServer();
241
- return <ClientThemeToggle />;
242
- }
243
- ```
244
-
245
- ### Key Changes
246
-
247
- 1. **`ThemeToggle`** → **`ClientThemeToggle`** (Server Component safe)
248
- 2. **`useTheme`** → **`useThemeServer`** (Server Component safe)
249
- 3. **`ThemeProvider`** → **`ClientThemeProvider`** (Server Component safe)
91
+ ### `useThemeServer`
92
+ A Server Component-safe hook that returns the default theme values. This is useful for accessing theme information in Server Components without causing client-side re-renders.
250
93
 
251
94
  ## Troubleshooting
252
95
 
253
96
  ### Common Issues
254
97
 
255
- 1. **Theme not switching**: Ensure `ClientThemeProvider` is wrapping your app
256
- 2. **Hydration errors**: Add `suppressHydrationWarning` to your `<html>` element
257
- 3. **CSS not loading**: Import the theme CSS file
258
- 4. **TypeScript errors**: The package includes types, no additional @types needed
259
-
260
- ### Server Component Compatibility
261
-
262
- All exported components are now Server Component safe. If you encounter any issues:
263
-
264
- 1. Use `ClientThemeToggle` instead of `ThemeToggle`
265
- 2. Use `ClientThemeProvider` instead of `ThemeProvider`
266
- 3. Use `useThemeServer` instead of `useTheme`
98
+ 1. **Theme not switching**: Ensure `ThemeProvider` is wrapping your app within a Client Component (like the `providers.tsx` file shown above).
99
+ 2. **Hydration errors**: Add `suppressHydrationWarning` to your `<html>` element in the root layout.
100
+ 3. **CSS not loading**: Make sure you have imported the `theme.css` file in your global stylesheet.
267
101
 
268
102
  ## API Reference
269
103
 
270
- ### ClientThemeProvider
104
+ ### ThemeProvider
271
105
 
272
- Theme provider component for Server Component compatibility.
106
+ A wrapper around the `next-themes` `ThemeProvider`. It accepts all the same props.
273
107
 
108
+ **Example Usage:**
274
109
  ```tsx
275
- import { ClientThemeProvider } from '@tydavidson/design-system/themes';
276
-
277
- <ClientThemeProvider
278
- attribute="class"
279
- defaultTheme="system"
280
- enableSystem
281
- disableTransitionOnChange
282
- >
283
- {children}
284
- </ClientThemeProvider>
110
+ // app/components/providers.tsx
111
+ "use client"
112
+
113
+ import { ThemeProvider } from "@tydavidson/design-system"
114
+
115
+ export function Providers({ children }: { children: React.ReactNode }) {
116
+ return (
117
+ <ThemeProvider
118
+ attribute="class"
119
+ defaultTheme="dark"
120
+ enableSystem={false}
121
+ >
122
+ {children}
123
+ </ThemeProvider>
124
+ )
125
+ }
285
126
  ```
286
127
 
287
128
  ### ClientThemeToggle
288
129
 
289
- Theme toggle component for Server Component compatibility.
130
+ A theme toggle button that is safe to use in both Server and Client Components.
290
131
 
291
132
  ```tsx
292
133
  import { ClientThemeToggle } from '@tydavidson/design-system/themes';
@@ -300,18 +141,10 @@ import { ClientThemeToggle } from '@tydavidson/design-system/themes';
300
141
 
301
142
  ### useThemeServer
302
143
 
303
- Server-safe theme hook that returns default theme values.
144
+ A server-safe hook that provides default theme values.
304
145
 
305
146
  ```tsx
306
147
  import { useThemeServer } from '@tydavidson/design-system/themes';
307
148
 
308
- const { theme, setTheme, resolvedTheme, isDark } = useThemeServer();
309
- ```
310
-
311
- ## Version Compatibility
312
-
313
- | Next.js Version | Design System Version | Notes |
314
- |----------------|----------------------|-------|
315
- | 13+ (App Router) | 1.1.17+ | Full Server Component support |
316
- | 12+ (Pages Router) | 1.1.0+ | Basic compatibility |
317
- | < 12 | Not supported | Use newer Next.js version |
149
+ const { theme, isDark } = useThemeServer();
150
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tydavidson/design-system",
3
- "version": "1.1.20",
3
+ "version": "1.2.2",
4
4
  "description": "Float Design System with email components and theme system",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -21,7 +21,12 @@
21
21
  "import": "./dist/themes/index.mjs",
22
22
  "require": "./dist/themes/index.js"
23
23
  },
24
- "./themes/theme.css": "./src/themes/theme.css"
24
+ "./tokens": {
25
+ "types": "./dist/tokens/index.d.ts",
26
+ "import": "./dist/tokens/index.mjs",
27
+ "require": "./dist/tokens/index.js"
28
+ },
29
+ "./themes/theme.css": "./dist/themes/theme.css"
25
30
  },
26
31
  "files": [
27
32
  "dist",