| Crates.io | leptos_theme |
| lib.rs | leptos_theme |
| version | 0.1.2 |
| created_at | 2024-01-05 21:33:53.965281+00 |
| updated_at | 2024-02-08 17:17:23.179859+00 |
| description | A theme abstraction for leptos applications. |
| homepage | |
| repository | https://github.com/friendlymatthew/leptos-theme |
| max_upload_size | |
| id | 1090499 |
| size | 9,601 |
leptos-theme effortlessly toggles between light and dark modes in your leptos application.
You can set up dark mode with two lines:
Wrap your project with <ThemeProvider />:
view! {
<Stylesheet id="leptos" href="/pkg/demo.css"/>
<ThemeProvider>
<Router>
<Routes>
<Route path="/" view=HomePage/>
<Route path=":else" view=ErrorPage/>
</Routes>
</Router>
</ThemeProvider>
}
Now your HomePage and ErrorPage are dark mode ready!
Toggle themes on-the-fly with use_theme():
use leptos_theme::{
theme::use_theme,
types::Theme
};
// inside <HomePage />
let current_theme = use_theme();
view! {
<button
on:click=move |_| {
theme_signal.set(Theme::Light);
}>
<p>Light Mode</p>
</button>
}
That's it!
prefers-color-schemeleptos_theme supports both class and data attribute selectors.
For a tailwind + class selector demo: https://leptos-theme.vercel.app/
For a pure CSS + data selector demo: https://leptos-theme-data-attribute.vercel.app/
Check the issues page and feel free to post a PR!
Robert and I created leptos_theme with the intention of usability. If you encounter any bugs, issues, or feature requests, please feel free to open an issue.
v.1.2 February 8th, 2024leptos to 0.6.5