Fix routing issues (#144)

Co-authored-by: Cecile Tonglet <cecile.tonglet@cecton.com>
This commit is contained in:
Yohan Boogaert 2022-07-14 23:41:38 +02:00 committed by GitHub
parent 3f96db6a7e
commit b36ba41637
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 88 additions and 51 deletions

4
Cargo.lock generated
View file

@ -1923,9 +1923,9 @@ dependencies = [
[[package]] [[package]]
name = "xtask-wasm" name = "xtask-wasm"
version = "0.1.4" version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a078921c435f7181ac151ebd655c5c6ec4456f37b16aa52a3ad242ccee8016c" checksum = "72b8fc162610b6505cf16d401b6cd58659a22767dc6ed0e9dd9cc9e59614f178"
dependencies = [ dependencies = [
"fs_extra", "fs_extra",
"lazy_static", "lazy_static",

View file

@ -25,7 +25,6 @@ id_tree = { version = "1.7", optional = true }
wasm-bindgen = "0.2" wasm-bindgen = "0.2"
gloo = "0.6" gloo = "0.6"
[build-dependencies] [build-dependencies]
regex = { version = "1", default-features = false, features = ["std", "unicode-perl"] } regex = { version = "1", default-features = false, features = ["std", "unicode-perl"] }
heck = "0.3" heck = "0.3"

View file

@ -1,3 +1,8 @@
[build] [build]
publish = "target/release/dist" publish = "target/release/dist"
command = "cargo xtask dist --release" command = "cargo xtask dist --release"
[[redirects]]
from = "/*"
to = "/index.html"
status = 200

View file

@ -1,4 +1,5 @@
use yew::prelude::*; use yew::prelude::*;
use yew::virtual_dom::AttrValue;
#[derive(Clone, PartialEq, Properties)] #[derive(Clone, PartialEq, Properties)]
pub struct ButtonGroupProps { pub struct ButtonGroupProps {
@ -11,7 +12,7 @@ pub struct ButtonGroupProps {
#[prop_or_default] #[prop_or_default]
pub large: bool, pub large: bool,
#[prop_or_default] #[prop_or_default]
pub style: Option<String>, pub style: Option<AttrValue>,
#[prop_or_default] #[prop_or_default]
pub children: html::Children, pub children: html::Children,
#[prop_or_default] #[prop_or_default]

View file

@ -1,5 +1,6 @@
use crate::{Icon, IconName, Intent, Spinner, ICON_SIZE_LARGE}; use crate::{Icon, IconName, Intent, Spinner, ICON_SIZE_LARGE};
use yew::prelude::*; use yew::prelude::*;
use yew::virtual_dom::AttrValue;
#[derive(Clone, PartialEq, Properties)] #[derive(Clone, PartialEq, Properties)]
pub struct ButtonProps { pub struct ButtonProps {
@ -24,13 +25,13 @@ pub struct ButtonProps {
#[prop_or_default] #[prop_or_default]
pub intent: Option<Intent>, pub intent: Option<Intent>,
#[prop_or_default] #[prop_or_default]
pub title: String, pub title: Option<AttrValue>,
#[prop_or_default] #[prop_or_default]
pub onclick: Callback<MouseEvent>, pub onclick: Callback<MouseEvent>,
#[prop_or_default] #[prop_or_default]
pub class: Classes, pub class: Classes,
#[prop_or_default] #[prop_or_default]
pub style: Option<String>, pub style: Option<AttrValue>,
#[prop_or_default] #[prop_or_default]
pub children: html::Children, pub children: html::Children,
} }

View file

@ -1,6 +1,7 @@
use crate::icon::ICON_SIZE_LARGE; use crate::icon::ICON_SIZE_LARGE;
use crate::{Icon, IconName, Intent}; use crate::{Icon, IconName, Intent};
use yew::prelude::*; use yew::prelude::*;
use yew::virtual_dom::AttrValue;
#[derive(Clone, PartialEq, Properties)] #[derive(Clone, PartialEq, Properties)]
pub struct CalloutProps { pub struct CalloutProps {
@ -13,7 +14,7 @@ pub struct CalloutProps {
#[prop_or_default] #[prop_or_default]
pub intent: Option<Intent>, pub intent: Option<Intent>,
#[prop_or_default] #[prop_or_default]
pub title: Option<String>, pub title: Option<AttrValue>,
pub children: html::Children, pub children: html::Children,
} }

View file

@ -176,7 +176,8 @@ impl Component for Collapse {
if !self.translated { if !self.translated {
content_style.push_str("transform: translateY(0px); "); content_style.push_str("transform: translateY(0px); ");
} else if let Some(ref height_when_open) = self.height_when_open { } else if let Some(ref height_when_open) = self.height_when_open {
content_style.push_str(&format!("transform: translateY(-{}); ", height_when_open)); content_style
.push_str(format!("transform: translateY(-{})", height_when_open).as_str());
} else { } else {
unreachable!("height_when_open was undefined while translated is set"); unreachable!("height_when_open was undefined while translated is set");
} }

View file

@ -1,5 +1,6 @@
use crate::{Icon, IconName, Intent, H6}; use crate::{Icon, IconName, Intent, H6};
use yew::prelude::*; use yew::prelude::*;
use yew::virtual_dom::AttrValue;
#[derive(Clone, PartialEq, Properties)] #[derive(Clone, PartialEq, Properties)]
pub struct MenuProps { pub struct MenuProps {
@ -41,7 +42,7 @@ pub struct MenuItemProps {
#[prop_or_default] #[prop_or_default]
pub disabled: bool, pub disabled: bool,
#[prop_or_default] #[prop_or_default]
pub href: Option<String>, pub href: Option<AttrValue>,
#[prop_or_default] #[prop_or_default]
pub label: Option<yew::virtual_dom::VNode>, pub label: Option<yew::virtual_dom::VNode>,
#[prop_or_default] #[prop_or_default]

View file

@ -1,5 +1,6 @@
use crate::{if_html, Icon, IconName, Intent, Text}; use crate::{if_html, Icon, IconName, Intent, Text};
use yew::prelude::*; use yew::prelude::*;
use yew::virtual_dom::AttrValue;
#[derive(Clone, PartialEq, Properties)] #[derive(Clone, PartialEq, Properties)]
pub struct TagProps { pub struct TagProps {
@ -31,11 +32,11 @@ pub struct TagProps {
#[prop_or_default] #[prop_or_default]
pub round: bool, pub round: bool,
#[prop_or_default] #[prop_or_default]
pub title: Option<String>, pub title: Option<AttrValue>,
#[prop_or_default] #[prop_or_default]
pub class: Classes, pub class: Classes,
#[prop_or_default] #[prop_or_default]
pub style: Option<String>, pub style: Option<AttrValue>,
} }
#[function_component(Tag)] #[function_component(Tag)]

View file

@ -1,4 +1,5 @@
use yew::prelude::*; use yew::prelude::*;
use yew::virtual_dom::AttrValue;
#[derive(Clone, PartialEq, Properties)] #[derive(Clone, PartialEq, Properties)]
pub struct TextProps { pub struct TextProps {
@ -12,9 +13,9 @@ pub struct TextProps {
#[prop_or_default] #[prop_or_default]
pub inline: bool, pub inline: bool,
#[prop_or_default] #[prop_or_default]
pub title: Option<String>, pub title: Option<AttrValue>,
#[prop_or_default] #[prop_or_default]
pub style: Option<String>, pub style: Option<AttrValue>,
} }
#[function_component(Text)] #[function_component(Text)]

View file

@ -5,7 +5,7 @@ use std::{
}; };
use xtask_wasm::{ use xtask_wasm::{
anyhow::{Context, Result}, anyhow::{Context, Result},
clap, clap, DistResult,
}; };
#[derive(clap::Parser)] #[derive(clap::Parser)]
@ -26,28 +26,28 @@ fn main() -> Result<()> {
let cli: Cli = clap::Parser::parse(); let cli: Cli = clap::Parser::parse();
match cli { match cli {
Cli::Dist(arg) => { Cli::Dist(dist) => {
log::info!("Generating package..."); log::info!("Generating package...");
download_css(false)?; download_css(false)?;
let result = arg let DistResult { dist_dir, .. } = dist
.static_dir_path("yewprint-doc/static") .static_dir_path("yewprint-doc/static")
.run("yewprint-doc")?; .run("yewprint-doc")?;
fs::copy( fs::copy("yewprint-doc/src/logo.svg", dist_dir.join("favicon.svg"))?;
"yewprint-doc/src/logo.svg",
result.dist_dir.join("favicon.svg"),
)?;
} }
Cli::Watch(arg) => { Cli::Watch(watch) => {
let mut command = process::Command::new("cargo"); let mut command = process::Command::new("cargo");
command.args(["xtask", "dist"]); command.args(["xtask", "dist"]);
arg.run(command)?; watch.run(command)?;
} }
Cli::Start(arg) => { Cli::Start(dev_server) => {
arg.arg("dist").start(xtask_wasm::default_dist_dir(false))?; dev_server
.arg("dist")
.not_found("index.html")
.start(xtask_wasm::default_dist_dir(false))?;
} }
Cli::UpdateCSS => download_css(true)?, Cli::UpdateCSS => download_css(true)?,
} }

View file

@ -41,7 +41,7 @@ pub struct App {
pub enum Msg { pub enum Msg {
ToggleLight, ToggleLight,
GoToMenu(DocMenu), GoToMenu(MouseEvent, DocMenu),
} }
impl Component for App { impl Component for App {
@ -60,7 +60,8 @@ impl Component for App {
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool { fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg { match msg {
Msg::ToggleLight => self.dark_theme ^= true, Msg::ToggleLight => self.dark_theme ^= true,
Msg::GoToMenu(doc_menu) => { Msg::GoToMenu(event, doc_menu) => {
event.prevent_default();
if let Some(history) = ctx.link().history() { if let Some(history) = ctx.link().history() {
history.push(doc_menu); history.push(doc_menu);
} else { } else {
@ -98,122 +99,146 @@ impl Component for App {
/> />
<MenuItem <MenuItem
text={html!("Button")} text={html!("Button")}
href="/button"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Button))} .callback(|e| Msg::GoToMenu(e, DocMenu::Button))}
/> />
<MenuItem <MenuItem
text={html!("ButtonGroup")} text={html!("ButtonGroup")}
href="/button-group"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::ButtonGroup))} .callback(|e| Msg::GoToMenu(e, DocMenu::ButtonGroup))}
/> />
<MenuItem <MenuItem
text={html!("Callout")} text={html!("Callout")}
href="/callout"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Callout))} .callback(|e| Msg::GoToMenu(e, DocMenu::Callout))}
/> />
<MenuItem <MenuItem
text={html!("Card")} text={html!("Card")}
href="/card"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Card))} .callback(|e| Msg::GoToMenu(e, DocMenu::Card))}
/> />
<MenuItem <MenuItem
text={html!("Checkbox")} text={html!("Checkbox")}
href="/progress-bar"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Checkbox))} .callback(|e| Msg::GoToMenu(e, DocMenu::Checkbox))}
/> />
<MenuItem <MenuItem
text={html!("Collapse")} text={html!("Collapse")}
href="/collapse"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Collapse))} .callback(|e| Msg::GoToMenu(e, DocMenu::Collapse))}
/> />
<MenuItem <MenuItem
text={html!("ControlGroup")} text={html!("ControlGroup")}
href="/control-group"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::ControlGroup))} .callback(|e| Msg::GoToMenu(e, DocMenu::ControlGroup))}
/> />
<MenuItem <MenuItem
text={html!("Divider")} text={html!("Divider")}
href="/divider"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Divider))} .callback(|e| Msg::GoToMenu(e, DocMenu::Divider))}
/> />
<MenuItem <MenuItem
text={html!("HtmlSelect")} text={html!("HtmlSelect")}
href="/html-select"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::HtmlSelect))} .callback(|e| Msg::GoToMenu(e, DocMenu::HtmlSelect))}
/> />
<MenuItem <MenuItem
text={html!("Icon")} text={html!("Icon")}
href="/icon"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Icon))} .callback(|e| Msg::GoToMenu(e, DocMenu::Icon))}
/> />
<MenuItem <MenuItem
text={html!("InputGroup")} text={html!("InputGroup")}
href="/input-group"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::InputGroup))} .callback(|e| Msg::GoToMenu(e, DocMenu::InputGroup))}
/> />
<MenuItem <MenuItem
text={html!("Menu")} text={html!("Menu")}
href="/menu"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Menu))} .callback(|e| Msg::GoToMenu(e, DocMenu::Menu))}
/> />
<MenuItem <MenuItem
text={html!("NumericInput")} text={html!("NumericInput")}
href="/numeric-input"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::NumericInput))} .callback(|e| Msg::GoToMenu(e, DocMenu::NumericInput))}
/> />
<MenuItem <MenuItem
text={html!("PanelStack")} text={html!("PanelStack")}
href="/panel-stack"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::PanelStack))} .callback(|e| Msg::GoToMenu(e, DocMenu::PanelStack))}
/> />
<MenuItem <MenuItem
text={html!("ProgressBar")} text={html!("ProgressBar")}
href="/progress-bar"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::ProgressBar))} .callback(|e| Msg::GoToMenu(e, DocMenu::ProgressBar))}
/> />
<MenuItem <MenuItem
text={html!("Radio")} text={html!("Radio")}
href="/radio"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Radio))} .callback(|e| Msg::GoToMenu(e, DocMenu::Radio))}
/> />
<MenuItem <MenuItem
text={html!("Slider")} text={html!("Slider")}
onclick={ctx.link().callback(|_| Msg::GoToMenu(DocMenu::Slider))} href="/slider"
onclick={ctx.link().callback(|e| Msg::GoToMenu(e, DocMenu::Slider))}
/> />
<MenuItem <MenuItem
text={html!("Spinner")} text={html!("Spinner")}
href="/spinner"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Spinner))} .callback(|e| Msg::GoToMenu(e, DocMenu::Spinner))}
/> />
<MenuItem <MenuItem
text={html!("Switch")} text={html!("Switch")}
href="/switch"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Switch))} .callback(|e| Msg::GoToMenu(e, DocMenu::Switch))}
/> />
<MenuItem <MenuItem
text={html!("Tabs")} text={html!("Tabs")}
href="/tabs"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Tabs))} .callback(|e| Msg::GoToMenu(e, DocMenu::Tabs))}
/> />
<MenuItem <MenuItem
text={html!("Tag")} text={html!("Tag")}
href="/tag"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Tag))} .callback(|e| Msg::GoToMenu(e, DocMenu::Tag))}
/> />
<MenuItem <MenuItem
text={html!("Text")} text={html!("Text")}
href="/text"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Text))} .callback(|e| Msg::GoToMenu(e, DocMenu::Text))}
/> />
<MenuItem <MenuItem
text={html!("TextArea")} text={html!("TextArea")}
href="/text-area"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::TextArea))} .callback(|e| Msg::GoToMenu(e, DocMenu::TextArea))}
/> />
<MenuItem <MenuItem
text={html!("Tree")} text={html!("Tree")}
href="/tree"
onclick={ctx.link() onclick={ctx.link()
.callback(|_| Msg::GoToMenu(DocMenu::Tree))} .callback(|e| Msg::GoToMenu(e, DocMenu::Tree))}
/> />
// NOTE: thanks to keep this list of <MenuItem> sorted // NOTE: thanks to keep this list of <MenuItem> sorted
// alphabetically (except for the light switch) // alphabetically (except for the light switch)
@ -341,12 +366,13 @@ pub enum DocMenu {
Tabs, Tabs,
#[at("/tag")] #[at("/tag")]
Tag, Tag,
#[at("/textarea")] #[at("/text-area")]
TextArea, TextArea,
#[at("/text")] #[at("/text")]
Text, Text,
#[at("/tree")] #[at("/tree")]
Tree, Tree,
#[not_found]
#[at("/")] #[at("/")]
Home, Home,
} }