@themed.js/react
v0.1.0
Published
React bindings for Themed.js
Downloads
107
Maintainers
Readme
@themed.js/react
React bindings for Themed.js - hooks and context provider for theme management.
Installation
npm install @themed.js/core @themed.js/reactUsage
Setup Provider
import { ThemeProvider } from '@themed.js/react';
function App() {
return (
<ThemeProvider
defaultTheme="light"
ai={{ provider: 'openai', apiKey: 'sk-xxx' }}
>
<MyApp />
</ThemeProvider>
);
}useTheme Hook
import { useTheme } from '@themed.js/react';
function ThemeSwitcher() {
const { theme, themes, apply } = useTheme();
return (
<div>
<p>Current: {theme?.name}</p>
{themes.map(t => (
<button key={t.id} onClick={() => apply(t.id)}>
{t.name}
</button>
))}
</div>
);
}useAITheme Hook
import { useAITheme } from '@themed.js/react';
function AIGenerator() {
const { generate, isGenerating, error } = useAITheme();
return (
<button
onClick={() => generate('A warm autumn theme')}
disabled={isGenerating}
>
{isGenerating ? 'Generating...' : 'Generate'}
</button>
);
}API
ThemeProvider Props
defaultTheme- Default theme IDthemes- Additional themes to registerai- AI configurationstorage- Storage configurationonThemeChange- Theme change callback
useTheme Returns
theme- Current themethemes- All themesapply(id)- Apply themeregister(theme)- Register theme
useAITheme Returns
generate(prompt)- Generate themeadjust(instruction)- Adjust current themeisGenerating- Loading stateerror- Error state
License
MIT
