-
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.
feature(ToggleGroup): Add ToggleGroup examples
- Loading branch information
Ari Breitkreuz
committed
Feb 6, 2024
1 parent
e623644
commit 6c65c16
Showing
10 changed files
with
225 additions
and
3 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,22 @@ | ||
use crate::{example, example::ExamplePage}; | ||
use yew::prelude::*; | ||
use patternfly_yew::prelude::*; | ||
|
||
#[function_component(ToggleGroupExample)] | ||
pub fn toast() -> Html { | ||
let example1 = example!("Basic" => "toggle_group.1.example"); | ||
let example2 = example!("Single Select" => "toggle_group.2.example"); | ||
let example3 = example!("Icons" => "toggle_group.3.example"); | ||
let example4 = example!("Icons and Text" => "toggle_group.4.example"); | ||
let example5 = example!("Compact" => "toggle_group.5.example"); | ||
|
||
html!( | ||
<ExamplePage title="Toggle Group"> | ||
{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,51 @@ | ||
{ | ||
#[function_component(ToggleGroupBasicDemo)] | ||
fn toggle_group_basic() -> Html { | ||
let first_selected = use_state(|| false); | ||
let second_selected = use_state(|| false); | ||
let onclick_first = use_callback(first_selected.clone(), |_, selected| { | ||
selected.set(!(**selected)) | ||
}); | ||
let onclick_second = use_callback(second_selected.clone(), |_, selected| { | ||
selected.set(!(**selected)) | ||
}); | ||
|
||
let all_disabled = use_state(|| false); | ||
let onclick_all_disabled = use_callback(all_disabled.clone(), |_, all_disabled| { | ||
all_disabled.set(!(**all_disabled)) | ||
}); | ||
let label = if *all_disabled { | ||
"Enable back" | ||
} else { | ||
"Disable all" | ||
}; | ||
|
||
html! { | ||
<Stack gutter=true> | ||
<StackItem> | ||
<Button onclick={onclick_all_disabled.clone()} {label} variant={ButtonVariant::Primary}/> | ||
</StackItem> | ||
<StackItem> | ||
<ToggleGroup all_disabled={*all_disabled}> | ||
<ToggleGroupItem | ||
text="Option 1" | ||
key=0 | ||
onchange={onclick_first.clone()} | ||
selected={*first_selected} | ||
/> | ||
<ToggleGroupItem | ||
text="Option 2" | ||
key=1 | ||
onchange={onclick_second.clone()} | ||
selected={*second_selected} | ||
/> | ||
<ToggleGroupItem text="Option 3" key=2 disabled=true /> | ||
</ToggleGroup> | ||
</StackItem> | ||
</Stack> | ||
} | ||
} | ||
html! { | ||
<ToggleGroupBasicDemo /> | ||
} | ||
} |
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,40 @@ | ||
{ | ||
#[function_component(ToggleGroupSingleSelect)] | ||
fn toggle_group_single_select() -> Html { | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
enum Choices { | ||
One, | ||
Two, | ||
Three, | ||
} | ||
let selected = use_state(|| None); | ||
let callback = use_callback(selected.clone(), |input, selected| { | ||
selected.set(Some(input)) | ||
}); | ||
html! { | ||
<ToggleGroup> | ||
<ToggleGroupItem | ||
text="Option 1" | ||
key=0 | ||
onchange={let cb = callback.clone(); move |_| cb.emit(Choices::One)} | ||
selected={*selected == Some(Choices::One)} | ||
/> | ||
<ToggleGroupItem | ||
text="Option 2" | ||
key=1 | ||
onchange={let cb = callback.clone(); move |_| cb.emit(Choices::Two)} | ||
selected={*selected == Some(Choices::Two)} | ||
/> | ||
<ToggleGroupItem | ||
text="Option 3" | ||
key=2 | ||
onchange={let cb = callback.clone(); move |_| cb.emit(Choices::Three)} | ||
selected={*selected == Some(Choices::Three)} | ||
/> | ||
</ToggleGroup> | ||
} | ||
} | ||
html! { | ||
<ToggleGroupSingleSelect /> | ||
} | ||
} |
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,33 @@ | ||
{ | ||
#[function_component(ToggleGroupIcons)] | ||
fn toggle_group_icons() -> Html { | ||
let first_selected = use_state(|| false); | ||
let second_selected = use_state(|| false); | ||
let third_selected = use_state(|| true); | ||
html! { | ||
<ToggleGroup> | ||
<ToggleGroupItem | ||
icon={html!(Icon::Copy)} | ||
key=0 | ||
onchange={let state = first_selected.clone(); move |_| state.set(!(*state))} | ||
selected={*first_selected} | ||
/> | ||
<ToggleGroupItem | ||
icon={html!(Icon::Undo)} | ||
key=1 | ||
onchange={let state = second_selected.clone(); move |_| state.set(!(*state))} | ||
selected={*second_selected} | ||
/> | ||
<ToggleGroupItem | ||
icon={html!(Icon::ShareSquare)} | ||
key=2 | ||
onchange={let state = third_selected.clone(); move |_| state.set(!(*state))} | ||
selected={*third_selected} | ||
/> | ||
</ToggleGroup> | ||
} | ||
} | ||
html! { | ||
<ToggleGroupIcons /> | ||
} | ||
} |
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,36 @@ | ||
{ | ||
#[function_component(ToggleGroupIconsAndText)] | ||
fn toggle_group_icons_and_text() -> Html { | ||
let first_selected = use_state(|| false); | ||
let second_selected = use_state(|| false); | ||
let third_selected = use_state(|| false); | ||
html! { | ||
<ToggleGroup> | ||
<ToggleGroupItem | ||
icon={html!(Icon::Copy)} | ||
text="Copy" | ||
key=0 | ||
onchange={let state = first_selected.clone(); move |_| state.set(!(*state))} | ||
selected={*first_selected} | ||
/> | ||
<ToggleGroupItem | ||
icon={html!(Icon::Undo)} | ||
text="Undo" | ||
key=1 | ||
onchange={let state = second_selected.clone(); move |_| state.set(!(*state))} | ||
selected={*second_selected} | ||
/> | ||
<ToggleGroupItem | ||
icon={html!(Icon::ShareSquare)} | ||
text="Share" | ||
key=2 | ||
onchange={let state = third_selected.clone(); move |_| state.set(!(*state))} | ||
selected={*third_selected} | ||
/> | ||
</ToggleGroup> | ||
} | ||
} | ||
html! { | ||
<ToggleGroupIconsAndText /> | ||
} | ||
} |
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,34 @@ | ||
{ | ||
#[function_component(ToggleGroupCompact)] | ||
fn toggle_group_basic() -> Html { | ||
let first_selected = use_state(|| false); | ||
let second_selected = use_state(|| false); | ||
let onclick_first = use_callback(first_selected.clone(), |_, selected| { | ||
selected.set(!(**selected)) | ||
}); | ||
let onclick_second = use_callback(second_selected.clone(), |_, selected| { | ||
selected.set(!(**selected)) | ||
}); | ||
|
||
html! { | ||
<ToggleGroup compact=true> | ||
<ToggleGroupItem | ||
text="Option 1" | ||
key=0 | ||
onchange={onclick_first.clone()} | ||
selected={*first_selected} | ||
/> | ||
<ToggleGroupItem | ||
text="Option 2" | ||
key=1 | ||
onchange={onclick_second.clone()} | ||
selected={*second_selected} | ||
/> | ||
<ToggleGroupItem text="Option 3" key=2 disabled=true /> | ||
</ToggleGroup> | ||
} | ||
} | ||
html! { | ||
<ToggleGroupCompact /> | ||
} | ||
} |