-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ea2d30
commit 961e2e4
Showing
8 changed files
with
187 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use ::yew::prelude::*; | ||
|
||
#[derive(PartialEq, Properties)] | ||
pub struct Props { | ||
pub is_revealed: bool, | ||
pub on_reveal: Callback<MouseEvent>, | ||
pub on_new_pokemon: Callback<MouseEvent>, | ||
} | ||
|
||
#[function_component] | ||
pub fn ButtonInput( | ||
Props { | ||
is_revealed, | ||
on_reveal, | ||
on_new_pokemon, | ||
}: &Props, | ||
) -> Html { | ||
if *is_revealed { | ||
html! {<button type="button" onclick={on_new_pokemon.clone()}>{"Next"}</button>} | ||
} else { | ||
html! {<button type="button" onclick={on_reveal.clone()}>{"Reveal"}</button>} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
pub mod button_input; | ||
pub mod guesser; | ||
pub mod pokemon_image; | ||
pub mod pokemon_label; | ||
pub mod repo_link; | ||
pub mod settings_menu; | ||
pub mod starburst; | ||
pub mod text_input; | ||
pub mod title; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use ::yew::prelude::*; | ||
use wasm_bindgen::JsCast; | ||
use web_sys::HtmlElement; | ||
use web_sys::HtmlInputElement; | ||
|
||
#[derive(PartialEq, Properties)] | ||
pub struct Props { | ||
pub is_revealed: bool, | ||
pub on_reveal: Callback<MouseEvent>, | ||
pub on_new_pokemon: Callback<MouseEvent>, | ||
pub name: AttrValue, | ||
} | ||
|
||
#[function_component] | ||
pub fn TextInput( | ||
Props { | ||
name, | ||
is_revealed, | ||
on_reveal, | ||
on_new_pokemon, | ||
}: &Props, | ||
) -> Html { | ||
let on_submit = { | ||
let name = name.clone(); | ||
let on_reveal = on_reveal.clone(); | ||
Callback::from(move |event: MouseEvent| { | ||
let target: HtmlInputElement = event.target_unchecked_into(); | ||
let text_input: HtmlInputElement = | ||
target.previous_element_sibling().unwrap().unchecked_into(); | ||
let guess = text_input.value(); | ||
if guess.trim().eq_ignore_ascii_case(&name) { | ||
on_reveal.emit(event); | ||
} else { | ||
text_input | ||
.parent_element() | ||
.map(|parent| parent.class_list().add_1("incorrect-guess")); | ||
} | ||
}) | ||
}; | ||
|
||
let onkeydown = Callback::from(|event: KeyboardEvent| { | ||
if event.key() == "Enter" { | ||
let target: HtmlInputElement = event.target_unchecked_into(); | ||
let target = if target.id() == "submit" { | ||
target | ||
} else { | ||
target.next_element_sibling().unwrap().unchecked_into() | ||
}; | ||
target.click(); | ||
} | ||
}); | ||
|
||
let onanimationend = Callback::from(move |event: AnimationEvent| { | ||
let target: HtmlElement = event.target_unchecked_into(); | ||
let _ = target.class_list().remove_1("incorrect-guess"); | ||
}); | ||
|
||
html! { | ||
<> | ||
if *is_revealed { | ||
<button type="button" onclick={on_new_pokemon}>{"Next"}</button> | ||
} else { | ||
<div class="text-guess" {onanimationend}> | ||
<input type="text" id="guess" onkeydown={onkeydown.clone()}/> | ||
<input type="button" id="submit" value="🡆" onclick={on_submit} {onkeydown}/> | ||
</div> | ||
<button type="button" onclick={on_reveal.clone()}>{"Reveal"}</button> | ||
} | ||
</> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters