project_panel.rs

  1use crate::{
  2    prelude::*, static_project_panel_project_items, static_project_panel_single_items, Input, List,
  3    ListHeader,
  4};
  5use gpui::prelude::*;
  6use gpui::Div;
  7use gpui::Stateful;
  8
  9#[derive(RenderOnce)]
 10pub struct ProjectPanel {
 11    id: ElementId,
 12}
 13
 14impl<V: 'static> Component<V> for ProjectPanel {
 15    type Rendered = Stateful<V, Div<V>>;
 16
 17    fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
 18        div()
 19            .id(self.id.clone())
 20            .flex()
 21            .flex_col()
 22            .size_full()
 23            .bg(cx.theme().colors().surface_background)
 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()
 33                            .header(ListHeader::new("FILES"))
 34                            .empty_message("No files in directory")
 35                            .children(static_project_panel_single_items()),
 36                    )
 37                    .child(
 38                        List::new()
 39                            .header(ListHeader::new("PROJECT"))
 40                            .empty_message("No folders in directory")
 41                            .children(static_project_panel_project_items()),
 42                    ),
 43            )
 44            .child(
 45                Input::new("Find something...")
 46                    .value("buffe".to_string())
 47                    .state(InteractionState::Focused),
 48            )
 49    }
 50}
 51
 52impl ProjectPanel {
 53    pub fn new(id: impl Into<ElementId>) -> Self {
 54        Self { id: id.into() }
 55    }
 56
 57    fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
 58        div()
 59            .id(self.id.clone())
 60            .flex()
 61            .flex_col()
 62            .size_full()
 63            .bg(cx.theme().colors().surface_background)
 64            .child(
 65                div()
 66                    .id("project-panel-contents")
 67                    .w_full()
 68                    .flex()
 69                    .flex_col()
 70                    .overflow_y_scroll()
 71                    .child(
 72                        List::new()
 73                            .header(ListHeader::new("FILES"))
 74                            .empty_message("No files in directory")
 75                            .children(static_project_panel_single_items()),
 76                    )
 77                    .child(
 78                        List::new()
 79                            .header(ListHeader::new("PROJECT"))
 80                            .empty_message("No folders in directory")
 81                            .children(static_project_panel_project_items()),
 82                    ),
 83            )
 84            .child(
 85                Input::new("Find something...")
 86                    .value("buffe".to_string())
 87                    .state(InteractionState::Focused),
 88            )
 89    }
 90}
 91
 92use gpui::ElementId;
 93#[cfg(feature = "stories")]
 94pub use stories::*;
 95
 96#[cfg(feature = "stories")]
 97mod stories {
 98    use super::*;
 99    use crate::{Panel, Story};
100    use gpui::{Div, Render};
101
102    pub struct ProjectPanelStory;
103
104    impl Render<Self> for ProjectPanelStory {
105        type Element = Div<Self>;
106
107        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
108            Story::container(cx)
109                .child(Story::title_for::<_, ProjectPanel>(cx))
110                .child(Story::label(cx, "Default"))
111                .child(
112                    Panel::new("project-panel-outer", cx)
113                        .child(ProjectPanel::new("project-panel-inner")),
114                )
115        }
116    }
117}