Skip to content

Commit

Permalink
Merge branch 'pr/alexkazik/30'
Browse files Browse the repository at this point in the history
  • Loading branch information
isosphere committed Nov 12, 2023
2 parents af08ffe + b810894 commit bb19075
Show file tree
Hide file tree
Showing 21 changed files with 2,508 additions and 21 deletions.
25 changes: 24 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions examples/basics/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use yew::prelude::*;

use yew_bootstrap::component::*;
use yew_bootstrap::icons::*;
use yew_bootstrap::util::*;

enum Msg {}
Expand All @@ -18,13 +19,13 @@ impl Component for Model {
let brand = BrandType::BrandIcon {
text: AttrValue::from("Yew Bootstrap"),
url: Some(AttrValue::from("https://yew.rs")),
icon: AttrValue::from("rocket")
icon: BI::ROCKET,
};

html! {
<>
{include_inline()}
{include_cdn_icons()}
{BIFiles::cdn()}
<NavBar nav_id={"test-nav"} class="navbar-expand-lg navbar-light bg-light" brand={brand}>
<NavItem text="link 1" />
<NavItem text="link 2" />
Expand Down
5 changes: 3 additions & 2 deletions examples/forms/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use yew::prelude::*;
use gloo_console::debug;

use yew_bootstrap::component::*;
use yew_bootstrap::icons::*;
use yew_bootstrap::util::*;
use yew_bootstrap::component::form::*;

Expand Down Expand Up @@ -156,13 +157,13 @@ impl Component for Model {
let brand = BrandType::BrandIcon {
text: AttrValue::from("Yew Bootstrap"),
url: Some(AttrValue::from("https://yew.rs")),
icon: AttrValue::from("rocket")
icon: BI::ROCKET,
};

html! {
<>
{include_inline()}
{include_cdn_icons()}
{BIFiles::cdn()}
<NavBar nav_id={"test-nav"} class="navbar-expand-lg navbar-light bg-light" brand={brand}>
<NavItem text="link 1" />
<NavItem text="link 2" />
Expand Down
13 changes: 13 additions & 0 deletions examples/icons/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "icons"
version = "0.1.0"
authors = ["ALeX Kazik <alex@kazik.de>"]
edition = "2021"
license = "MIT"

[dependencies]
yew = { version = "0.21", features = ["csr"] }
yew-bootstrap = { path = "../../packages/yew-bootstrap" }

[[bin]]
name = "copy-bootstrap-icons"
61 changes: 61 additions & 0 deletions examples/icons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Example of automatically copying the bootstrap-icons files

This is copies the required files to the `dist` directory, which is recommended.

Please see [the documentation](https://docs.rs/yew-bootstrap/latest/yew_bootstrap/icons/index.html) for more information.

A copy of `bootstrap-icons` is included and should change only rarely. `trunk` does not add a hash to generated files, and thus a change in those files won't be detected by `trunk`.

## Instructions

1. `Cargo.toml`

Add the build-executed binary.

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

2. `src/bin/copy-bootstrap-icons.rs`

Create the program to copy the files.

```rust
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)
}
```

3. `index.html`

Set base reference, link the required CSS and specify your WASM program[^1].

[^1]: Since we'll be writing a build-executed program, there are now two binaries and trunk needs to know which is your WASM binary.

```html
<base data-trunk-public-url />
<link rel="stylesheet" href="bootstrap-icons-v1.10.5/bootstrap-icons.css" />
<link data-trunk rel="rust" data-bin="name-of-app" />
```

4. `Trunk.toml`

Add a hook to run the build-executed program.

```toml
[[hooks]]
stage = "build"
command = "cargo"
command_arguments = ["run", "--bin", "copy-bootstrap-icons"]
```
4 changes: 4 additions & 0 deletions examples/icons/Trunk.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[[hooks]]
stage = "build"
command = "cargo"
command_arguments = ["run", "--bin", "copy-bootstrap-icons"]
10 changes: 10 additions & 0 deletions examples/icons/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<base data-trunk-public-url/>
<meta charset="utf-8"/>
<title>Yew App</title>
<link rel="stylesheet" href="bootstrap-icons-v1.10.5/bootstrap-icons.css"/>
<link data-trunk rel="rust" data-bin="icons"/>
</head>
</html>
13 changes: 13 additions & 0 deletions examples/icons/src/bin/copy-bootstrap-icons.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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)
}
13 changes: 13 additions & 0 deletions examples/icons/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use yew::prelude::*;
use yew_bootstrap::icons::*;

#[function_component(App)]
fn app() -> Html {
html! {
<h1>{"I"}<span style="color: red">{BI::HEART_FILL}</span>{BI::GEAR_FILL}</h1>
}
}

fn main() {
yew::Renderer::<App>::new().render();
}
6 changes: 5 additions & 1 deletion packages/yew-bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yew-bootstrap"
version = "0.6.3"
version = "0.7.0"
authors = ["Matthew Scheffel <matt@dataheck.com>", "Foorack <max@foorack.com>"]
edition = "2021"
license = "MIT"
Expand All @@ -23,3 +23,7 @@ log = "0.4"
[dev-dependencies]
wasm-bindgen = "0.2.*"
web-sys = { version = "0.3.*", features = ["HtmlTextAreaElement", "HtmlSelectElement"] }

[build-dependencies]
convert_case = { version = "0.6.0", default-features = false }
anyhow = { version = "1.0.75", default-features = false, features = ["std"] }
2 changes: 1 addition & 1 deletion packages/yew-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Add the dependency next to the regular yew dependency:
```toml
[dependencies]
yew = "0.21"
yew-bootstrap = "0.6"
yew-bootstrap = "0.7"
```

To use form callback functions, the following dependencies should be added:
Expand Down
Loading

0 comments on commit bb19075

Please sign in to comment.