| 1 | use gpui::{ |
| 2 | AnyElement, App, IntoElement, ParentElement, RenderOnce, StyleRefinement, Styled, Window, |
| 3 | }; |
| 4 | |
| 5 | use crate::{StyledExt as _, v_flex}; |
| 6 | |
| 7 | /// Header section of a dialog, typically contains DialogTitle and DialogDescription. |
| 8 | /// |
| 9 | /// # Examples |
| 10 | /// |
| 11 | /// ```ignore |
| 12 | /// DialogHeader::new() |
| 13 | /// .child(DialogTitle::new().child("Delete Account")) |
| 14 | /// .child(DialogDescription::new().child("This action cannot be undone.")) |
| 15 | /// ``` |
| 16 | #[derive(IntoElement)] |
| 17 | pub struct DialogHeader { |
| 18 | style: StyleRefinement, |
| 19 | children: Vec<AnyElement>, |
| 20 | } |
| 21 | |
| 22 | impl DialogHeader { |
| 23 | pub fn new() -> Self { |
| 24 | Self { |
| 25 | style: StyleRefinement::default(), |
| 26 | children: Vec::new(), |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | impl ParentElement for DialogHeader { |
| 32 | fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) { |
| 33 | self.children.extend(elements); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | impl Styled for DialogHeader { |
| 38 | fn style(&mut self) -> &mut StyleRefinement { |
| 39 | &mut self.style |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | impl RenderOnce for DialogHeader { |
| 44 | fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement { |
| 45 | v_flex() |
| 46 | .gap_2() |
| 47 | .refine_style(&self.style) |
| 48 | .children(self.children) |
| 49 | } |
| 50 | } |