Merge Component and ComponentPreview trait (#28365)
- Merge `Component` and `ComponentPreview` trait - Adds a number of component previews - Removes a number of stories Release Notes: - N/A
This commit is contained in:
@@ -3,8 +3,10 @@ use smallvec::SmallVec;
|
||||
|
||||
use crate::{ListHeader, prelude::*};
|
||||
|
||||
use super::Checkbox;
|
||||
|
||||
/// A group of settings.
|
||||
#[derive(IntoElement)]
|
||||
#[derive(IntoElement, RegisterComponent)]
|
||||
pub struct SettingsGroup {
|
||||
header: SharedString,
|
||||
children: SmallVec<[AnyElement; 2]>,
|
||||
@@ -34,3 +36,75 @@ impl RenderOnce for SettingsGroup {
|
||||
.children(self.children)
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for SettingsGroup {
|
||||
fn scope() -> ComponentScope {
|
||||
ComponentScope::Layout
|
||||
}
|
||||
|
||||
fn name() -> &'static str {
|
||||
"SettingsGroup"
|
||||
}
|
||||
|
||||
fn description() -> Option<&'static str> {
|
||||
Some("A group of settings with a header, used to organize related settings.")
|
||||
}
|
||||
|
||||
fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {
|
||||
Some(
|
||||
v_flex()
|
||||
.gap_6()
|
||||
.children(vec![
|
||||
example_group_with_title(
|
||||
"Basic Usage",
|
||||
vec![
|
||||
single_example(
|
||||
"Empty Group",
|
||||
SettingsGroup::new("General Settings").into_any_element(),
|
||||
),
|
||||
single_example(
|
||||
"With Children",
|
||||
SettingsGroup::new("Appearance")
|
||||
.child(
|
||||
Checkbox::new("dark_mode", ToggleState::Unselected)
|
||||
.label("Dark Mode"),
|
||||
)
|
||||
.child(
|
||||
Checkbox::new("high_contrast", ToggleState::Unselected)
|
||||
.label("High Contrast"),
|
||||
)
|
||||
.into_any_element(),
|
||||
),
|
||||
],
|
||||
),
|
||||
example_group_with_title(
|
||||
"Multiple Groups",
|
||||
vec![single_example(
|
||||
"Two Groups",
|
||||
v_flex()
|
||||
.gap_4()
|
||||
.child(
|
||||
SettingsGroup::new("General").child(
|
||||
Checkbox::new("auto_update", ToggleState::Selected)
|
||||
.label("Auto Update"),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
SettingsGroup::new("Editor")
|
||||
.child(
|
||||
Checkbox::new("line_numbers", ToggleState::Selected)
|
||||
.label("Show Line Numbers"),
|
||||
)
|
||||
.child(
|
||||
Checkbox::new("word_wrap", ToggleState::Unselected)
|
||||
.label("Word Wrap"),
|
||||
),
|
||||
)
|
||||
.into_any_element(),
|
||||
)],
|
||||
),
|
||||
])
|
||||
.into_any_element(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user