project_panel.rs

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