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            .size_full()
22            .bg(cx.theme().colors().surface_background)
23            .child(
24                div()
25                    .id("project-panel-contents")
26                    .w_full()
27                    .flex()
28                    .flex_col()
29                    .overflow_y_scroll()
30                    .child(
31                        List::new(static_project_panel_single_items())
32                            .header(ListHeader::new("FILES"))
33                            .empty_message("No files in directory"),
34                    )
35                    .child(
36                        List::new(static_project_panel_project_items())
37                            .header(ListHeader::new("PROJECT"))
38                            .empty_message("No folders in directory"),
39                    ),
40            )
41            .child(
42                Input::new("Find something...")
43                    .value("buffe".to_string())
44                    .state(InteractionState::Focused),
45            )
46    }
47}
48
49use gpui::ElementId;
50#[cfg(feature = "stories")]
51pub use stories::*;
52
53#[cfg(feature = "stories")]
54mod stories {
55    use super::*;
56    use crate::{Panel, Story};
57    use gpui::{Div, Render};
58
59    pub struct ProjectPanelStory;
60
61    impl Render for ProjectPanelStory {
62        type Element = Div<Self>;
63
64        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
65            Story::container(cx)
66                .child(Story::title_for::<_, ProjectPanel>(cx))
67                .child(Story::label(cx, "Default"))
68                .child(
69                    Panel::new("project-panel-outer", cx)
70                        .child(ProjectPanel::new("project-panel-inner")),
71                )
72        }
73    }
74}