-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: implement search input * chore: bump pf-yew version
- Loading branch information
1 parent
eaff417
commit 60b127b
Showing
10 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,25 @@ | ||
use crate::{example, example::ExamplePage}; | ||
|
||
use patternfly_yew::prelude::*; | ||
use yew::prelude::*; | ||
|
||
#[function_component(SearchInputExample)] | ||
pub fn search_input() -> Html { | ||
let example1 = example! ("Basic" => "search_input.1.example"); | ||
let example2 = example! ("Match with result count" => "search_input.2.example"); | ||
let example3 = example! ("Match with navigable options" => "search_input.3.example"); | ||
let example4 = example! ("With submit button" => "search_input.4.example"); | ||
let example5 = example! ("With expandable button" => "search_input.5.example"); | ||
|
||
html! { | ||
<> | ||
<ExamplePage title="Search Input"> | ||
{example1} | ||
{example2} | ||
{example3} | ||
{example4} | ||
{example5} | ||
</ExamplePage> | ||
</> | ||
} | ||
} |
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,31 @@ | ||
{ | ||
#[function_component(SearchInputExampleBasic)] | ||
fn basic() -> Html { | ||
let colors = &["red", "green", "blue", "black", "yellow", "purple"]; | ||
|
||
let value = use_state(String::new); | ||
let onchange = use_callback(value.clone(), |new, old| old.set(new)); | ||
let onclear = use_callback(value.clone(), |_, val| val.set(String::new())); | ||
let possible_values: Vec<&'static str> = colors | ||
.iter() | ||
.filter(|c| c.starts_with(&value.to_lowercase())) | ||
.map(|c| *c) | ||
.collect(); | ||
html! { | ||
<> | ||
<SearchInput | ||
placeholder={"Find by name"} | ||
value={(*value).clone()} | ||
{onchange} | ||
{onclear} | ||
/> | ||
<div> | ||
{format!("Possible results: {possible_values:?}")} | ||
</div> | ||
</> | ||
} | ||
} | ||
html! { | ||
<SearchInputExampleBasic/> | ||
} | ||
} |
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,25 @@ | ||
{ | ||
#[function_component(SearchInputExampleResults)] | ||
fn results() -> Html { | ||
let value = use_state(String::new); | ||
let results = use_state(|| ResultsCount::Absolute(0)); | ||
let onchange = use_callback((value.clone(), results.clone()), |new, (value, results)| { | ||
results.set(ResultsCount::Absolute(3)); | ||
value.set(new); | ||
}); | ||
let onclear = use_callback((value.clone(), results.clone()), |_, (value, results)| { | ||
results.set(ResultsCount::Absolute(0)); | ||
value.set(String::new()) | ||
}); | ||
html! { | ||
<SearchInput | ||
placeholder={"Find by name"} | ||
value={(*value).clone()} | ||
{onchange} | ||
{onclear} | ||
results_count={(*results).clone()} | ||
/> | ||
} | ||
} | ||
html! { <SearchInputExampleResults/> } | ||
} |
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,42 @@ | ||
{ | ||
#[function_component(SearchInputExampleNavigable)] | ||
fn navigable() -> Html { | ||
let value = use_state(String::new); | ||
let results = use_state(|| 0); | ||
let current_result = use_state(|| 1); | ||
|
||
let onchange = use_callback((value.clone(), results.clone()), |new, (value, results)| { | ||
results.set(3); | ||
value.set(new) | ||
}); | ||
let onclear = use_callback((value.clone(), results.clone()), |_, (value, results)| { | ||
results.set(0); | ||
value.set(String::new()) | ||
}); | ||
let onnextclick = use_callback( | ||
(current_result.clone(), results.clone()), | ||
|_, (current_result, results_count)| { | ||
let new_result = (**current_result + 1).min(**results_count); | ||
current_result.set(new_result) | ||
} | ||
); | ||
let onpreviousclick = use_callback(current_result.clone(), |_, current_result| { | ||
let new_result = (**current_result - 1).max(1); | ||
current_result.set(new_result) | ||
}); | ||
html! { | ||
<SearchInput | ||
placeholder={"Find by name"} | ||
value={(*value).clone()} | ||
{onchange} | ||
{onclear} | ||
results_count={ResultsCount::Fraction(*current_result, *results)} | ||
{onnextclick} | ||
{onpreviousclick} | ||
previous_navigation_button_disabled={*current_result == 1} | ||
next_navigation_button_disabled={*current_result == *results} | ||
/> | ||
} | ||
} | ||
html! { <SearchInputExampleNavigable/> } | ||
} |
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,21 @@ | ||
{ | ||
#[function_component(SearchInputExampleSubmit)] | ||
fn submit() -> Html { | ||
let value = use_state(String::new); | ||
|
||
let onchange = use_callback(value.clone(), |new, old| old.set(new)); | ||
let onsearch = use_callback(value.clone(), |(_, new), old| old.set(new)); | ||
let onclear = use_callback(value.clone(), |_, old| old.set(String::new())); | ||
|
||
html! { | ||
<SearchInput | ||
placeholder={"Find by name"} | ||
value={(*value).clone()} | ||
{onchange} | ||
{onsearch} | ||
{onclear} | ||
/> | ||
} | ||
} | ||
html! { <SearchInputExampleSubmit/> } | ||
} |
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,26 @@ | ||
{ | ||
#[function_component(SearchInputExampleExpand)] | ||
fn expand() -> Html { | ||
let value = use_state(String::new); | ||
let expanded = use_state(|| false); | ||
|
||
let onchange = use_callback(value.clone(), |new, value| value.set(new)); | ||
let ontoggleexpand = use_callback(expanded.clone(), |(_, prev): (MouseEvent, bool), curr| curr.set(!prev)); | ||
let expandable = SearchInputExpandableProperties { | ||
expanded: *expanded, | ||
ontoggleexpand, | ||
toggle_aria_label: AttrValue::from("Expandable input search toggle"), | ||
}; | ||
let onclear = use_callback(value.clone(), |_, value| value.set(String::new())); | ||
html! { | ||
<SearchInput | ||
placeholder={"Find by name"} | ||
value={(*value).clone()} | ||
{onchange} | ||
{expandable} | ||
{onclear} | ||
/> | ||
} | ||
} | ||
html! { <SearchInputExampleExpand/> } | ||
} |