Skip to content

alexkazik/yew-bootstrap-icons

Repository files navigation

crate yew-bootstrap-icons

Bootstrap icons for yew

Version

This release is for yew 0.2.0 and contains bootstrap-icons-v1.10.5.

Icons

All icons are available as a constant:

let icon = BI::HEART;
let empty_icon = BI::empty(); // or BI::default()
html!{
    <h1>{"I"} {icon} {BI::GEAR}</h1>
}

Files

The files can be added though several ways:

  • Copy them yourself from the website
  • Use BIFiles::cdn()
  • Use BIFiles::copy() - see below
  • Access the data via BIFiles::FILES and deliver them yourself

Automatically copy the files

There are some options, two are explained below.

  1. Either way you now have to specify your wasm-program in index.html:

    <link data-trunk rel="rust" data-bin="name-of-app" />

    (Because there are now two binaries and trunk can't decide.)

  2. Add a binary to your Cargo.toml

    [[bin]]
    name = "copy-bootstrap-icons"

Option 1: Copy to dist

  1. Create the file src/bin/copy-bootstrap-icons.rs with:

    use std::path::PathBuf;
    use yew_bootstrap_icons::BIFiles;
    
    fn main() -> Result<(), std::io::Error> {
        let path = PathBuf::from(
            std::env::var("TRUNK_STAGING_DIR").expect("Environment variable TRUNK_STAGING_DIR"),
        )
        .join(BIFiles::NAME);
        if !path.is_dir() {
            std::fs::create_dir(&path)?;
        }
        BIFiles::copy(&path)
    }
  2. Add the css to your index.html

    <link rel="stylesheet" href="bootstrap-icons-v1.10.5/bootstrap-icons.css" />

    (Don't forget to set <base data-trunk-public-url />.)

  3. Add the program to your Trunk.toml

    [[hooks]]
    stage = "build"
    command = "cargo"
    command_arguments = ["run", "--bin", "copy-bootstrap-icons"]

Option 2: Copy to source (and let trunk copy it to dist)

This means that trunk will add the hash to the css-file.

It is assumed that your directory for static files is called static, if not change the paths below.

  1. Create the file src/bin/copy-bootstrap-icons.rs with:

    use std::path::PathBuf;
    use yew_bootstrap_icons::BIFiles;
    
    fn main() -> Result<(), std::io::Error> {
        let path = &PathBuf::from(
            std::env::var("TRUNK_SOURCE_DIR").expect("Environment variable TRUNK_SOURCE_DIR"),
        )
        .join("static")
        .join(BIFiles::NAME);
        if !path.is_dir() {
            std::fs::create_dir(&path)?;
        }
        BIFiles::copy(&path)
    }
  2. Add the css to your index.html

    <link data-trunk rel="css" href="static/bootstrap-icons-v1.10.5/bootstrap-icons.css" />
    <link data-trunk rel="copy-dir" href="static/bootstrap-icons-v1.10.5/fonts" />
  3. Add the program to your Trunk.toml

    [[hooks]]
    stage = "pre_build"
    command = "cargo"
    command_arguments = ["run", "--bin", "copy-bootstrap-icons"]

License

This project is licensed under either of

at your option.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages