2 unstable releases

0.2.0-alpha.1 Sep 8, 2024
0.1.0 Oct 21, 2023

#419 in Text processing

Download history 74/week @ 2024-09-06 28/week @ 2024-09-13 23/week @ 2024-09-20 8/week @ 2024-09-27 2/week @ 2024-10-04 2/week @ 2024-10-11 1/week @ 2024-10-18

59 downloads per month

MIT/Apache

30KB
501 lines

Lookbook

UI preview framework for Dioxus

Crates.io version docs.rs docs nightly docs CI status


/// To-Do Task.
#[preview]
pub fn TaskPreview(
    /// Label of the task.
    #[lookbook(default = "Ice skating")]
    label: String,

    /// Content of the task.
    #[lookbook(default = "Central Park")]
    content: String,

    /// List of tags.
    #[lookbook(default = vec![String::from("A")])]
    tags: Json<Vec<String>>,
) -> Element {
    rsx!(
        div {
            h4 { "{label}" }
            p { "{content}" }
            div { { tags.0.iter().map(|tag| rsx!(li { "{tag}" })) } }
        }
    )
}

#[component]
fn app() -> Element {
    rsx!(LookBook {
        home: |()| rsx!("Home"),
        previews: [TaskPreview]
    })
}

fn main() {
    dioxus::launch(app)
}

Usage

First add Lookbook as a dependency to your project.

cargo add lookbook --git https://github.com/matthunz/lookbook

Then create a preview like the one above and add it to a lookbook.

fn app() -> Element {
    rsx!(LookBook {
        home: |()| rsx!("Home"),
        previews: [TaskPreview]
    })
}

fn main() {
    dioxus_web::launch(app)
}

Run with dx serve!

Running examples

Run the examples with dx serve --example {name}.

Dependencies

~21–30MB
~458K SLoC