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::*;
 6
 7#[derive(Component)]
 8pub struct ProjectPanel {
 9    id: ElementId,
10}
11
12impl ProjectPanel {
13    pub fn new(id: impl Into<ElementId>) -> Self {
14        Self { id: id.into() }
15    }
16
17    fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
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(static_project_panel_single_items())
33                            .header(ListHeader::new("FILES"))
34                            .empty_message("No files in directory"),
35                    )
36                    .child(
37                        List::new(static_project_panel_project_items())
38                            .header(ListHeader::new("PROJECT"))
39                            .empty_message("No folders in directory"),
40                    ),
41            )
42            .child(
43                Input::new("Find something...")
44                    .value("buffe".to_string())
45                    .state(InteractionState::Focused),
46            )
47    }
48}
49
50use gpui::ElementId;
51#[cfg(feature = "stories")]
52pub use stories::*;
53
54#[cfg(feature = "stories")]
55mod stories {
56    use super::*;
57    use crate::{Panel, Story};
58    use gpui::{Div, Render};
59
60    pub struct ProjectPanelStory;
61
62    impl Render for ProjectPanelStory {
63        type Element = Div<Self>;
64
65        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
66            Story::container(cx)
67                .child(Story::title_for::<_, ProjectPanel>(cx))
68                .child(Story::label(cx, "Default"))
69                .child(
70                    Panel::new("project-panel-outer", cx)
71                        .child(ProjectPanel::new("project-panel-inner")),
72                )
73        }
74    }
75}