gradient-forge 1.0.4 → 1.0.5
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/cli/index.mjs +15 -7
- package/package.json +1 -1
package/cli/index.mjs
CHANGED
|
@@ -188,18 +188,26 @@ body {
|
|
|
188
188
|
// Generate theme context
|
|
189
189
|
const generateContext = (themeId, mode) => {
|
|
190
190
|
return `"use client";
|
|
191
|
-
import
|
|
191
|
+
import { createContext, useContext, useEffect, useState, type ReactNode } from "react";
|
|
192
192
|
|
|
193
193
|
export type ThemeId = string;
|
|
194
194
|
export type ColorMode = string;
|
|
195
195
|
|
|
196
|
+
interface ThemeContextType {
|
|
197
|
+
themeId: string;
|
|
198
|
+
colorMode: string;
|
|
199
|
+
setThemeId: (id: string) => void;
|
|
200
|
+
setColorMode: (mode: string) => void;
|
|
201
|
+
themes: { id: string; label: string }[];
|
|
202
|
+
}
|
|
203
|
+
|
|
196
204
|
const allThemes = [
|
|
197
205
|
${themes.map(t => ` { id: "${t.id}", label: "${t.label}" }`).join(",\n")}
|
|
198
206
|
];
|
|
199
207
|
|
|
200
|
-
const ThemeContext
|
|
208
|
+
const ThemeContext = createContext<ThemeContextType | null>(null);
|
|
201
209
|
|
|
202
|
-
export const ThemeProvider = ({ children }: { children:
|
|
210
|
+
export const ThemeProvider = ({ children }: { children: ReactNode }) => {
|
|
203
211
|
const [themeId, setThemeId] = useState("${themeId}");
|
|
204
212
|
const [colorMode, setColorMode] = useState("${mode}");
|
|
205
213
|
|
|
@@ -231,8 +239,8 @@ export function ThemeSwitcher() {
|
|
|
231
239
|
const { themeId, colorMode, setThemeId, setColorMode, themes } = useTheme();
|
|
232
240
|
return (
|
|
233
241
|
<div style={{ display: "flex", gap: "8px", padding: "8px" }}>
|
|
234
|
-
<select value={themeId} onChange={(e
|
|
235
|
-
{themes.map((t
|
|
242
|
+
<select value={themeId} onChange={(e) => setThemeId(e.target.value)} style={{ padding: "4px" }}>
|
|
243
|
+
{themes.map((t) => <option key={t.id} value={t.id}>{t.label}</option>)}
|
|
236
244
|
</select>
|
|
237
245
|
<button onClick={() => setColorMode(colorMode === "dark" ? "light" : "dark")} style={{ padding: "4px 8px" }}>
|
|
238
246
|
{colorMode === "dark" ? "🌙" : "☀️"}
|
|
@@ -276,8 +284,8 @@ const setupNextJs = (projectRoot, themeId, mode) => {
|
|
|
276
284
|
let content = fs.readFileSync(layoutPath, "utf8");
|
|
277
285
|
|
|
278
286
|
if (!content.includes("ThemeProvider")) {
|
|
279
|
-
//
|
|
280
|
-
const importStmt = `import { ThemeProvider } from "
|
|
287
|
+
// Use @/ import path for Next.js
|
|
288
|
+
const importStmt = `import { ThemeProvider } from "@/components/theme/theme-context";`;
|
|
281
289
|
if (!content.includes(importStmt)) {
|
|
282
290
|
content = importStmt + "\n" + content;
|
|
283
291
|
}
|