project_panel.rs

 1use crate::prelude::*;
 2use crate::{
 3    static_project_panel_project_items, static_project_panel_single_items, Input, List, ListHeader,
 4};
 5
 6#[derive(Component)]
 7pub struct ProjectPanel {
 8    id: ElementId,
 9}
10
11impl ProjectPanel {
12    pub fn new(id: impl Into<ElementId>) -> Self {
13        Self { id: id.into() }
14    }
15
16    fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
17        div()
18            .id(self.id.clone())
19            .flex()
20            .flex_col()
21            .w_full()
22            .h_full()
23            .bg(cx.theme().colors().surface)
24            .child(
25                div()
26                    .id("project-panel-contents")
27                    .w_full()
28                    .flex()
29                    .flex_col()
30                    .overflow_y_scroll()
31                    .child(
32                        List::new(static_project_panel_single_items())
33                            .header(ListHeader::new("FILES").toggle(ToggleState::Toggled))
34                            .empty_message("No files in directory")
35                            .toggle(ToggleState::Toggled),
36                    )
37                    .child(
38                        List::new(static_project_panel_project_items())
39                            .header(ListHeader::new("PROJECT").toggle(ToggleState::Toggled))
40                            .empty_message("No folders in directory")
41                            .toggle(ToggleState::Toggled),
42                    ),
43            )
44            .child(
45                Input::new("Find something...")
46                    .value("buffe".to_string())
47                    .state(InteractionState::Focused),
48            )
49    }
50}
51
52use gpui2::ElementId;
53#[cfg(feature = "stories")]
54pub use stories::*;
55
56#[cfg(feature = "stories")]
57mod stories {
58    use super::*;
59    use crate::{Panel, Story};
60    use gpui2::{Div, Render};
61
62    pub struct ProjectPanelStory;
63
64    impl Render for ProjectPanelStory {
65        type Element = Div<Self>;
66
67        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
68            Story::container(cx)
69                .child(Story::title_for::<_, ProjectPanel>(cx))
70                .child(Story::label(cx, "Default"))
71                .child(
72                    Panel::new("project-panel-outer", cx)
73                        .child(ProjectPanel::new("project-panel-inner")),
74                )
75        }
76    }
77}