Crates.io | prefers-color-scheme |
lib.rs | prefers-color-scheme |
version | 0.1.1 |
source | src |
created_at | 2021-12-16 11:48:56.592221 |
updated_at | 2021-12-16 11:51:55.693514 |
description | CSS prefers dark/light media query binding |
homepage | https://github.com/unlink2/prefers-color-scheme |
repository | |
max_upload_size | |
id | 499143 |
size | 1,771 |
This is a very simple binding to the prefers-color-scheme media query.
The sample program in example can be run with trunk serve
.
Usage:
use prefers_color_scheme::{prefers_dark, prefers_light};
use yew::prelude::*;
enum Msg {
Query,
}
struct Model {}
impl Component for Model {
type Message = Msg;
type Properties = ();
fn create(_ctx: &Context<Self>) -> Self {
Self {}
}
fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::Query => true,
}
}
fn view(&self, ctx: &Context<Self>) -> Html {
// This gives us a component's "`Scope`" which allows us to send messages, etc to the component.
let link = ctx.link();
html! {
<div>
<button onclick={link.callback(|_| Msg::Query)}>{ "Query" }</button>
<p>{"Prefers Dark:"} { prefers_dark() }</p>
<p>{"Prefers Light:"} { prefers_light() }</p>
</div>
}
}
}
fn main() {
yew::start_app::<Model>();
}
This program is distributed under the terms of the MIT License.
All contributions are welcome. Both pull requests and issue reports are always appreciated. Please make sure that all existing tests pass before submitting a pull request.