Skip to main content

gpui_component/dialog/
header.rs

1use gpui::{
2    AnyElement, App, IntoElement, ParentElement, RenderOnce, StyleRefinement, Styled, Window,
3};
4
5use 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)]
17pub struct DialogHeader {
18    style: StyleRefinement,
19    children: Vec<AnyElement>,
20}
21
22impl DialogHeader {
23    pub fn new() -> Self {
24        Self {
25            style: StyleRefinement::default(),
26            children: Vec::new(),
27        }
28    }
29}
30
31impl ParentElement for DialogHeader {
32    fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
33        self.children.extend(elements);
34    }
35}
36
37impl Styled for DialogHeader {
38    fn style(&mut self) -> &mut StyleRefinement {
39        &mut self.style
40    }
41}
42
43impl 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}