ratatui_toolkit/primitives/dialog/methods/
with_theme.rs

1//! Method to apply an AppTheme to the Dialog.
2
3use crate::primitives::dialog::Dialog;
4use crate::services::theme::AppTheme;
5use ratatui::style::{Modifier, Style};
6
7impl<'a> Dialog<'a> {
8    /// Applies theme colors to the dialog.
9    ///
10    /// This method configures the dialog's border colors for each dialog type,
11    /// as well as button styles, based on the provided theme.
12    ///
13    /// # Theme Mapping
14    ///
15    /// - Info dialogs use `theme.info`
16    /// - Success dialogs use `theme.success`
17    /// - Warning dialogs use `theme.warning`
18    /// - Error dialogs use `theme.error`
19    /// - Confirm dialogs use `theme.primary`
20    /// - Dialog background uses `theme.background_panel`
21    /// - Dialog text uses `theme.text`
22    /// - Selected button uses `theme.selected_text` on `theme.primary` background
23    ///
24    /// # Arguments
25    ///
26    /// * `theme` - The application theme to apply
27    ///
28    /// # Returns
29    ///
30    /// Self with theme colors applied for method chaining.
31    ///
32    /// # Example
33    ///
34    /// ```rust,no_run
35    /// use ratatui_toolkit::{Dialog, DialogType, AppTheme};
36    ///
37    /// let theme = AppTheme::default();
38    /// let dialog = Dialog::new("Info", "This is a message")
39    ///     .dialog_type(DialogType::Info)
40    ///     .with_theme(&theme);
41    /// ```
42    pub fn with_theme(mut self, theme: &AppTheme) -> Self {
43        // Set dialog type colors
44        self.theme_info_color = Some(theme.info);
45        self.theme_success_color = Some(theme.success);
46        self.theme_warning_color = Some(theme.warning);
47        self.theme_error_color = Some(theme.error);
48        self.theme_confirm_color = Some(theme.primary);
49
50        // Set dialog background and text style
51        self.style = Style::default().bg(theme.background_panel).fg(theme.text);
52
53        // Set button styles
54        self.button_selected_style = Style::default()
55            .fg(theme.selected_text)
56            .bg(theme.primary)
57            .add_modifier(Modifier::BOLD);
58        self.button_style = Style::default().fg(theme.text);
59
60        self
61    }
62}