Skip to main content

gpui_component/dialog/
description.rs

1use gpui::{
2    AnyElement, App, IntoElement, ParentElement, RenderOnce, StyleRefinement, Styled, Window,
3};
4use gpui_base::DialogDescription as BaseDialogDescription;
5
6use crate::{ActiveTheme as _, StyledExt as _};
7
8/// Description element for a dialog header.
9///
10/// Typically used inside a DialogHeader component to provide additional context.
11///
12/// # Examples
13///
14/// ```ignore
15/// DialogDescription::new("This action cannot be undone.")
16/// ```
17#[derive(IntoElement)]
18pub struct DialogDescription {
19    base: BaseDialogDescription,
20    style: StyleRefinement,
21    children: Vec<AnyElement>,
22}
23
24impl DialogDescription {
25    pub fn new() -> Self {
26        Self {
27            base: BaseDialogDescription::new(),
28            style: StyleRefinement::default(),
29            children: vec![],
30        }
31    }
32}
33
34impl ParentElement for DialogDescription {
35    fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
36        self.children.extend(elements);
37    }
38}
39
40impl Styled for DialogDescription {
41    fn style(&mut self) -> &mut StyleRefinement {
42        &mut self.style
43    }
44}
45
46impl RenderOnce for DialogDescription {
47    fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
48        self.base
49            .text_sm()
50            .text_color(cx.theme().muted_foreground)
51            .refine_style(&self.style)
52            .children(self.children)
53    }
54}