| 1 | use gpui::{ |
| 2 | Div, InteractiveElement, IntoElement, ParentElement, RenderOnce, Styled, |
| 3 | prelude::FluentBuilder as _, |
| 4 | }; |
| 5 | |
| 6 | use crate::{ActiveTheme as _, Collapsible, Selectable, h_flex, menu::DropdownMenu}; |
| 7 | |
| 8 | /// Footer for the [`super::Sidebar`]. |
| 9 | #[derive(IntoElement)] |
| 10 | pub struct SidebarFooter { |
| 11 | base: Div, |
| 12 | selected: bool, |
| 13 | collapsed: bool, |
| 14 | } |
| 15 | |
| 16 | impl SidebarFooter { |
| 17 | /// Create a new [`SidebarFooter`]. |
| 18 | pub fn new() -> Self { |
| 19 | Self { |
| 20 | base: h_flex().gap_2().w_full(), |
| 21 | selected: false, |
| 22 | collapsed: false, |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | impl Selectable for SidebarFooter { |
| 28 | fn selected(mut self, selected: bool) -> Self { |
| 29 | self.selected = selected; |
| 30 | self |
| 31 | } |
| 32 | |
| 33 | fn is_selected(&self) -> bool { |
| 34 | self.selected |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | impl Collapsible for SidebarFooter { |
| 39 | fn is_collapsed(&self) -> bool { |
| 40 | self.collapsed |
| 41 | } |
| 42 | |
| 43 | fn collapsed(mut self, collapsed: bool) -> Self { |
| 44 | self.collapsed = collapsed; |
| 45 | self |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | impl ParentElement for SidebarFooter { |
| 50 | fn extend(&mut self, elements: impl IntoIterator<Item = gpui::AnyElement>) { |
| 51 | self.base.extend(elements); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | impl Styled for SidebarFooter { |
| 56 | fn style(&mut self) -> &mut gpui::StyleRefinement { |
| 57 | self.base.style() |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | impl InteractiveElement for SidebarFooter { |
| 62 | fn interactivity(&mut self) -> &mut gpui::Interactivity { |
| 63 | self.base.interactivity() |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | impl DropdownMenu for SidebarFooter {} |
| 68 | |
| 69 | impl RenderOnce for SidebarFooter { |
| 70 | fn render(self, _: &mut gpui::Window, cx: &mut gpui::App) -> impl gpui::IntoElement { |
| 71 | h_flex() |
| 72 | .id("sidebar-footer") |
| 73 | .gap_2() |
| 74 | .p_2() |
| 75 | .w_full() |
| 76 | .justify_between() |
| 77 | .rounded(cx.theme().radius) |
| 78 | .hover(|this| { |
| 79 | this.bg(cx.theme().tokens.sidebar_accent) |
| 80 | .text_color(cx.theme().sidebar_accent_foreground) |
| 81 | }) |
| 82 | .when(self.selected, |this| { |
| 83 | this.bg(cx.theme().tokens.sidebar_accent) |
| 84 | .text_color(cx.theme().sidebar_accent_foreground) |
| 85 | }) |
| 86 | .child(self.base) |
| 87 | } |
| 88 | } |