Skip to content

Commit f5c0014

Browse files
.
1 parent 2b15ccb commit f5c0014

File tree

13 files changed

+241
-191
lines changed

13 files changed

+241
-191
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ todo_*
4242
tempCodeRunnerFile.*
4343
*.tgz
4444
/testapps
45+
46+
shadcn-theme-editor/README.md
47+
shadcn-theme-editor/usage.md

README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<div align="center">
2+
3+
# 🎨 Shadcn Theme Editor
4+
5+
**Effortless Shadcn Theme Customization Made Simple**
6+
7+
Manage Shadcn theme colors with an **intuitive UI**, adjust styles in real-time, and keep your design consistent without diving into raw CSS.
8+
9+
---
10+
11+
![Next.js](https://img.shields.io/badge/Next.js-000000.svg?style&logo=Next.js&logoColor=white)
12+
![React](https://img.shields.io/badge/React-61DAFB.svg?style&logo=React&logoColor=black)
13+
![TypeScript](https://img.shields.io/badge/TypeScript-3178C6.svg?style&logo=TypeScript&logoColor=white)
14+
15+
![GitHub last commit](https://img.shields.io/github/last-commit/programming-with-ia/shadcn-theme-editor)
16+
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/programming-with-ia/shadcn-theme-editor)
17+
![GitHub top language](https://img.shields.io/github/languages/top/programming-with-ia/shadcn-theme-editor)
18+
19+
![npm bundle size](https://badgen.net/bundlephobia/min/shadcn-theme-editor@latest)
20+
[![NPM Version](https://img.shields.io/npm/v/shadcn-theme-editor?logo=npm)](https://www.npmjs.com/package/shadcn-theme-editor)
21+
[![GitHub](https://img.shields.io/badge/shadcn_theme_editor-161b22?logo=github)](https://github.com/programming-with-ia/shadcn-theme-editor)
22+
23+
</div>
24+
25+
---
26+
27+
# 📍 Overview
28+
29+
The **Shadcn Theme Editor** is a lightweight component designed to simplify theme customization in Shadcn projects.
30+
31+
- 🎛 **Visual UI** for adjusting theme colors
32+
-**Real-time preview** of changes
33+
- 🌗 **Supports light & dark mode** via the `html.dark` class
34+
- 🛠 Works seamlessly with Shadcn components
35+
- 📦 Install as a **dev dependency** (recommended, due to bundle size)
36+
37+
This makes it a **must-have dev tool** for anyone building with [shadcn/ui](https://ui.shadcn.com/).
38+
39+
---
40+
41+
## 🚀 Installation
42+
43+
There are two ways to install **shadcn-theme-editor**:
44+
45+
1. **[Via npm/yarn/pnpm/bun](#install-npm)** (as a dev dependency)
46+
2. **[Via Scaflo CLI](#install-scaflo-cli)** (copies fully editable components)
47+
48+
---
49+
50+
<h3 id="install-npm">1️⃣ Install via npm (as a dev dependency)</h3>
51+
52+
Install the package as a development dependency:
53+
54+
```bash
55+
# npm
56+
npm install --save-dev shadcn-theme-editor
57+
58+
# yarn
59+
yarn add --dev shadcn-theme-editor
60+
61+
# pnpm
62+
pnpm add -D shadcn-theme-editor
63+
64+
# bun
65+
bun add -D shadcn-theme-editor
66+
```
67+
68+
---
69+
70+
**TailwindCSS**:
71+
- Tailwind v4
72+
73+
```diff
74+
@import "tailwindcss";
75+
76+
+@source "../node_modules/shadcn-theme-editor"; /** <-- depends on your project structure */
77+
```
78+
79+
- Tailwind v3
80+
81+
```diff
82+
module.exports = {
83+
content: [
84+
// ...
85+
+ "./node_modules/shadcn-theme-editor/**/*", /** <-- depends on your project structure */
86+
],
87+
// ...
88+
};
89+
90+
```
91+
92+
---
93+
94+
<h3 id="install-scaflo-cli">2️⃣ Install via Scaflo CLI</h3>
95+
96+
The [Scaflo CLI](https://github.com/programming-with-ia/scaflo) installs Shadcn Theme Editor as source components into your project, so you can fully customize them.
97+
98+
```bash
99+
# pnpm (recommended)
100+
pnpm dlx shadcn@latest add sheet button accordion
101+
pnpm dlx [email protected] https://shadcnthemeeditor.vercel.app/r/editor.json -e %COMPONENTS%/shadcn-theme-editor
102+
103+
# or with npx
104+
npx shadcn@latest add sheet button accordion
105+
npx [email protected] https://shadcnthemeeditor.vercel.app/r/editor.json -e %COMPONENTS%/shadcn-theme-editor
106+
107+
# or with bun
108+
bunx shadcn@latest add sheet button accordion
109+
bunx [email protected] https://shadcnthemeeditor.vercel.app/r/editor.json -e %COMPONENTS%/shadcn-theme-editor
110+
```
111+
112+
Follow the CLI prompts to generate and configure the components inside your own codebase.
113+
114+
> ⚠️ Note for **Next.js**: Add `"use client";` to `components/shadcn-theme-editor/index.tsx`.
115+
116+
---
117+
118+
## 📖 Usage
119+
120+
Import the component and add it to your layout:
121+
122+
<!--
123+
> **Tip**
124+
> It is preferable to use this component within the `ThemeProvider`, as follows:
125+
`import { ThemeProvider } from 'next-themes';` -->
126+
127+
```tsx
128+
import ShadcnThemeEditor from "shadcn-theme-editor";
129+
```
130+
131+
### Load in Development Only
132+
Exclude the editor from production builds:
133+
134+
```tsx
135+
let ShadcnThemeEditor: any;
136+
if (process.env.NODE_ENV === 'development') {
137+
import('shadcn-theme-editor').then(module => {
138+
ShadcnThemeEditor = module.default; // or module, depending on the module's export
139+
});
140+
} else {
141+
// eslint-disable-next-line react/display-name
142+
ShadcnThemeEditor = ()=>null
143+
}
144+
```
145+
146+
and use
147+
148+
```tsx
149+
<ShadcnThemeEditor />
150+
```
151+
152+
</br>
153+
154+
## 🖼️ Screenshots
155+
156+
<p align="center">
157+
<img align="center" src="https://raw.githubusercontent.com/programming-with-ia/shadcn-theme-editor/master/screenshots/shadcn-theme-editor.png" alt="screenshot">
158+
</p>
159+
160+
For detailed UI examples, see: [usage.md](./usage.md)
161+
162+
## ⚙️ Props
163+
164+
| Prop | Type | Default | Description |
165+
| ------------------ | ------------------------ | -------------------------------- | ------------------------------------------------------- |
166+
| `side` | `"left"` | `"right"` | `"left"` | Position of the editor sidebar. |
167+
| `className` | `string` | `undefined` | Extra CSS classes for the root element. |
168+
| `triggerClassName` | `string` | `undefined` | Extra CSS classes for the trigger button. |
169+
| `title` | `string` | `"Shadcn Theme Editor"` | Sidebar header text. |
170+
| `customColors` | `Record<string, string>` | `undefined` | Map of CSS vars → labels (e.g. `--primary: "Primary"`). |
171+
| `getContainer` | `() => HTMLElement` | `() => document.documentElement` | Element where dynamic styles will be injected. |
172+
173+
## 🙌 Special Thanks
174+
175+
- [Julian](https://github.com/jln13x) creator of [ui.jln.dev](https://ui.jln.dev/), featuring 10,000+ Shadcn themes.
176+
177+
## 📄 License
178+
179+
Licensed under the MIT License.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"lint": "turbo run lint",
88
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
99
"check-types": "turbo run check-types",
10-
"pkg-build": "turbo run build --filter=shadcn-theme-editor && tsx scripts/scaflo.ts"
10+
"pkg-build": "turbo run build --filter=shadcn-theme-editor && tsx scripts/scaflo.ts && tsx scripts/copy-files.ts"
1111
},
1212
"devDependencies": {
1313
"@types/fs-extra": "^11.0.4",
@@ -23,7 +23,7 @@
2323
"typescript": "5.9.2",
2424
"typescript-eslint": "^8.27.0"
2525
},
26-
"packageManager": "pnpm@9.0.0",
26+
"packageManager": "pnpm@9.15.4",
2727
"engines": {
2828
"node": ">=18"
2929
},
78 KB
Loading

screenshots/usage-pic.png

167 KB
Loading

scripts/copy-files.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import fs from "fs-extra";
2+
import path from "path";
3+
import { editorPath, rootDir } from "./paths";
4+
5+
function copyFiles() {
6+
try {
7+
["README.md", "usage.md"].forEach((file) => {
8+
const src = path.join(rootDir, file);
9+
const dest = path.join(editorPath, file);
10+
11+
fs.copyFileSync(src, dest);
12+
console.log(`✅ Copied ${file}${dest}`);
13+
});
14+
} catch (err) {
15+
console.error("❌ Error copying files:", err);
16+
}
17+
}
18+
19+
// Example usage
20+
copyFiles();

scripts/paths.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import path from "path";
2+
import { fileURLToPath } from "url";
3+
4+
export const currentFile = fileURLToPath(import.meta.url);
5+
export const rootDir = path.resolve(path.dirname(currentFile), "..");
6+
7+
export const editorPath = path.join(rootDir, "/shadcn-theme-editor");
8+
export const editorMainPath = path.join(editorPath, "/src/(main)/");
9+
export const outputPath = path.join(rootDir, "/web/public/r/editor.json");

scripts/scaflo.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from "fs-extra";
22
import path from "path";
33
import { fileURLToPath } from "url";
4+
import { editorMainPath, editorPath, outputPath } from "./paths";
45

56
//* Scaflo types
67

@@ -20,12 +21,7 @@ type JsonStructure = {
2021
registryDependencies: string[]; //* modified (shadcn's components)
2122
};
2223

23-
const currentFile = fileURLToPath(import.meta.url);
24-
const rootDir = path.resolve(path.dirname(currentFile), "..");
2524

26-
const editorPath = path.join(rootDir, "/shadcn-theme-editor");
27-
const editorMainPath = path.join(editorPath, "/src/(main)/");
28-
const outputPath = path.join(rootDir, "/web/public/r/editor.json");
2925

3026
fs.ensureDirSync(path.dirname(outputPath));
3127

0 commit comments

Comments
 (0)