prefers-color-scheme

Crates.ioprefers-color-scheme
lib.rsprefers-color-scheme
version0.1.1
sourcesrc
created_at2021-12-16 11:48:56.592221
updated_at2021-12-16 11:51:55.693514
descriptionCSS prefers dark/light media query binding
homepagehttps://github.com/unlink2/prefers-color-scheme
repository
max_upload_size
id499143
size1,771
Lukas (unlink2)

documentation

README

color-scheme

Table of content

Installation

Usage

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>();
}

License

This program is distributed under the terms of the MIT License.

Contributing

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.

TODO

Commit count: 0

cargo fmt