1use gpui::AnyElement;
 2use smallvec::SmallVec;
 3
 4use crate::prelude::*;
 5
 6use super::Checkbox;
 7
 8#[derive(IntoElement, RegisterComponent)]
 9pub struct SettingsContainer {
10    children: SmallVec<[AnyElement; 2]>,
11}
12
13impl Default for SettingsContainer {
14    fn default() -> Self {
15        Self::new()
16    }
17}
18
19impl SettingsContainer {
20    pub fn new() -> Self {
21        Self {
22            children: SmallVec::new(),
23        }
24    }
25}
26
27impl ParentElement for SettingsContainer {
28    fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
29        self.children.extend(elements)
30    }
31}
32
33impl RenderOnce for SettingsContainer {
34    fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
35        v_flex().px_2().gap_1().children(self.children)
36    }
37}
38
39impl Component for SettingsContainer {
40    fn scope() -> ComponentScope {
41        ComponentScope::Layout
42    }
43
44    fn name() -> &'static str {
45        "SettingsContainer"
46    }
47
48    fn description() -> Option<&'static str> {
49        Some("A container for organizing and displaying settings in a structured manner.")
50    }
51
52    fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {
53        Some(
54            v_flex()
55                .gap_6()
56                .children(vec![
57                    example_group_with_title(
58                        "Basic Usage",
59                        vec![
60                            single_example(
61                                "Empty Container",
62                                SettingsContainer::new().into_any_element(),
63                            ),
64                            single_example(
65                                "With Content",
66                                SettingsContainer::new()
67                                    .child(Label::new("Setting 1"))
68                                    .child(Label::new("Setting 2"))
69                                    .child(Label::new("Setting 3"))
70                                    .into_any_element(),
71                            ),
72                        ],
73                    ),
74                    example_group_with_title(
75                        "With Different Elements",
76                        vec![single_example(
77                            "Mixed Content",
78                            SettingsContainer::new()
79                                .child(Label::new("Text Setting"))
80                                .child(Checkbox::new("checkbox", ToggleState::Unselected))
81                                .child(Button::new("button", "Click me"))
82                                .into_any_element(),
83                        )],
84                    ),
85                ])
86                .into_any_element(),
87        )
88    }
89}