Bootstrap icons for yew
This release is for yew 0.2.0 and contains bootstrap-icons-v1.10.5.
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>
}
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
There are some options, two are explained below.
-
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.)
-
Add a binary to your
Cargo.toml
[[bin]] name = "copy-bootstrap-icons"
-
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) }
-
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 />
.) -
Add the program to your
Trunk.toml
[[hooks]] stage = "build" command = "cargo" command_arguments = ["run", "--bin", "copy-bootstrap-icons"]
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.
-
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) }
-
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" />
-
Add the program to your
Trunk.toml
[[hooks]] stage = "pre_build" command = "cargo" command_arguments = ["run", "--bin", "copy-bootstrap-icons"]
This project is licensed under either of
at your option.