Live preview of themes with sample components
Visualize your theme with color palettes, typography samples, and custom components. Test themes before deployment.
The ThemePreview component creates a visual testing environment where you can see how your theme looks with real components. It displays color palettes, typography samples, spacing scales, and allows you to preview custom components.
1import { ThemePreview } from '@shohojdhara/atomix/theme/devtools';
2import { createTheme } from '@shohojdhara/atomix/theme';
3
4const theme = createTheme({
5 name: 'My Theme',
6 palette: {
7 primary: { main: '#7AFFD7' },
8 secondary: { main: '#FF5733' },
9 },
10});
11
12function App() {
13 return (
14 <ThemePreview
15 theme={theme}
16 showDetails={true}
17 showPalette={true}
18 showTypography={true}
19 showSpacing={false}
20 />
21 );
22}1import { Button, Card } from '@shohojdhara/atomix';
2
3<ThemePreview theme={theme} showPalette={true}>
4 {/* Your custom components */}
5 <Button variant="primary">Test Button</Button>
6 <Card className="u-p-4">
7 <h3>Test Card</h3>
8 <p>Testing theme with actual components</p>
9 </Card>
10</ThemePreview>| Prop | Type | Default | Description |
|---|---|---|---|
theme | Theme | Required | Theme object to preview |
showDetails | boolean | true | Show theme metadata and details |
showPalette | boolean | true | Show color palette visualization |
showTypography | boolean | true | Show typography samples |
showSpacing | boolean | false | Show spacing scale visualization |
children | ReactNode | - | Custom components to render with theme |
className | string | - | Custom CSS class name |
style | CSSProperties | - | Inline styles object |
Create a comprehensive testing environment:
1import { ThemePreview } from '@shohojdhara/atomix/theme/devtools';
2import { Button, Card, Input, Badge } from '@shohojdhara/atomix';
3
4function ThemeTestingSuite({ theme }) {
5 return (
6 <ThemePreview
7 theme={theme}
8 showPalette={true}
9 showTypography={true}
10 >
11 <div className="component-tests">
12 <section>
13 <h3>Buttons</h3>
14 <Button variant="primary">Primary</Button>
15 <Button variant="secondary">Secondary</Button>
16 <Button variant="outline">Outline</Button>
17 </section>
18
19 <section>
20 <h3>Form Elements</h3>
21 <Input placeholder="Test input" />
22 <Input type="email" placeholder="Email" />
23 </section>
24
25 <section>
26 <h3>Cards</h3>
27 <Card className="u-p-4">
28 <h4>Card Title</h4>
29 <p>Card content with theme applied</p>
30 </Card>
31 </section>
32
33 <section>
34 <h3>Badges</h3>
35 <Badge variant="primary">Primary</Badge>
36 <Badge variant="success">Success</Badge>
37 <Badge variant="error">Error</Badge>
38 </section>
39 </div>
40 </ThemePreview>
41 );
42}Add theme preview to Storybook stories:
1// .storybook/preview.tsx
2import { ThemePreview } from '@shohojdhara/atomix/theme/devtools';
3
4export const decorators = [
5 (Story, context) => {
6 const theme = context.globals.theme;
7
8 return (
9 <ThemePreview
10 theme={theme}
11 showDetails={false}
12 showPalette={false}
13 >
14 <Story />
15 </ThemePreview>
16 );
17 },
18];
19
20// In your stories
21export const WithTheme = {
22 decorators: [
23 (Story) => (
24 <ThemePreview theme={myCustomTheme}>
25 <Story />
26 </ThemePreview>
27 ),
28 ],
29};Preview multiple themes side by side:
1function MultiThemePreview() {
2 const themes = [lightTheme, darkTheme, customTheme];
3
4 return (
5 <div className="theme-grid">
6 {themes.map((theme) => (
7 <div key={theme.name} className="theme-preview-container">
8 <h3>{theme.name}</h3>
9 <ThemePreview
10 theme={theme}
11 showPalette={true}
12 showTypography={false}
13 >
14 <Button>Test Button</Button>
15 <Card className="u-p-3">Sample Card</Card>
16 </ThemePreview>
17 </div>
18 ))}
19 </div>
20 );
21}Use ThemePreview during theme creation to see changes in real-time:
Show theme options to clients or stakeholders:
Include in theme documentation:
Combine ThemePreview with other devtools: