Real-time theme editing with instant preview
Edit themes visually or with JSON, see changes instantly, and export your customized theme for use in your application.
The ThemeLiveEditor component combines visual editing tools with a JSON editor to provide a flexible theme creation experience. Changes are reflected instantly in the preview, making it easy to experiment and iterate quickly.
1import { ThemeLiveEditor } from '@shohojdhara/atomix/theme/devtools';
2import { createTheme } from '@shohojdhara/atomix/theme';
3
4const initialTheme = createTheme({
5 name: 'My Theme',
6 palette: {
7 primary: { main: '#7AFFD7' },
8 secondary: { main: '#FF5733' },
9 },
10});
11
12function App() {
13 const handleThemeChange = (newTheme) => {
14 console.log('Theme updated:', newTheme);
15 };
16
17 return (
18 <ThemeLiveEditor
19 initialTheme={initialTheme}
20 onChange={handleThemeChange}
21 />
22 );
23}1import { useState } from 'react';
2
3function ThemeBuilder() {
4 const [theme, setTheme] = useState(initialTheme);
5
6 return (
7 <div>
8 <ThemeLiveEditor
9 initialTheme={theme}
10 onChange={setTheme}
11 />
12
13 <button onClick={() => saveTheme(theme)}>
14 Save Theme
15 </button>
16 </div>
17 );
18}| Prop | Type | Default | Description |
|---|---|---|---|
initialTheme | Theme | Required | Initial theme to edit |
onChange | (theme: Theme) => void | Required | Callback when theme changes |
className | string | - | Custom CSS class name |
style | CSSProperties | - | Inline styles object |
The visual editor provides intuitive controls for common theme properties:
For advanced editing, switch to JSON mode:
Export your theme in multiple ways:
Create a complete theme builder with save/load functionality:
1import { ThemeLiveEditor, ThemePreview } from '@shohojdhara/atomix/theme/devtools';
2import { useState } from 'react';
3
4function ThemeBuilderApp() {
5 const [theme, setTheme] = useState(defaultTheme);
6 const [savedThemes, setSavedThemes] = useState([]);
7
8 const handleSave = () => {
9 const themeName = prompt('Enter theme name:');
10 if (themeName) {
11 setSavedThemes([
12 ...savedThemes,
13 { name: themeName, theme: theme }
14 ]);
15 }
16 };
17
18 const handleLoad = (savedTheme) => {
19 setTheme(savedTheme.theme);
20 };
21
22 return (
23 <div className="theme-builder">
24 <div className="sidebar">
25 <h3>Saved Themes</h3>
26 {savedThemes.map((saved) => (
27 <button
28 key={saved.name}
29 onClick={() => handleLoad(saved)}
30 >
31 {saved.name}
32 </button>
33 ))}
34 </div>
35
36 <div className="editor">
37 <ThemeLiveEditor
38 initialTheme={theme}
39 onChange={setTheme}
40 />
41 <button onClick={handleSave}>Save Theme</button>
42 </div>
43
44 <div className="preview">
45 <ThemePreview theme={theme} />
46 </div>
47 </div>
48 );
49}Sync theme changes across multiple users:
1import { useEffect, useState } from 'react';
2
3function CollaborativeThemeEditor({ roomId }) {
4 const [theme, setTheme] = useState(defaultTheme);
5
6 // Sync with backend
7 useEffect(() => {
8 const socket = connectToRoom(roomId);
9
10 socket.on('theme-update', (newTheme) => {
11 setTheme(newTheme);
12 });
13
14 return () => socket.disconnect();
15 }, [roomId]);
16
17 const handleChange = (newTheme) => {
18 setTheme(newTheme);
19 // Broadcast to other users
20 broadcastThemeUpdate(roomId, newTheme);
21 };
22
23 return (
24 <ThemeLiveEditor
25 initialTheme={theme}
26 onChange={handleChange}
27 />
28 );
29}Add undo/redo functionality to the editor:
1function ThemeEditorWithHistory() {
2 const [history, setHistory] = useState([defaultTheme]);
3 const [currentIndex, setCurrentIndex] = useState(0);
4
5 const currentTheme = history[currentIndex];
6
7 const handleChange = (newTheme) => {
8 const newHistory = history.slice(0, currentIndex + 1);
9 setHistory([...newHistory, newTheme]);
10 setCurrentIndex(newHistory.length);
11 };
12
13 const undo = () => {
14 if (currentIndex > 0) {
15 setCurrentIndex(currentIndex - 1);
16 }
17 };
18
19 const redo = () => {
20 if (currentIndex < history.length - 1) {
21 setCurrentIndex(currentIndex + 1);
22 }
23 };
24
25 return (
26 <div>
27 <div className="controls">
28 <button onClick={undo} disabled={currentIndex === 0}>
29 Undo
30 </button>
31 <button onClick={redo} disabled={currentIndex === history.length - 1}>
32 Redo
33 </button>
34 </div>
35
36 <ThemeLiveEditor
37 initialTheme={currentTheme}
38 onChange={handleChange}
39 />
40 </div>
41 );
42}| Shortcut | Action |
|---|---|
Cmd/Ctrl + S | Export theme |
Cmd/Ctrl + C | Copy theme JSON to clipboard |
Cmd/Ctrl + F | Format JSON (in JSON mode) |
Cmd/Ctrl + Z | Undo (if implemented) |
Cmd/Ctrl + Shift + Z | Redo (if implemented) |
Combine ThemeLiveEditor with other devtools: