| 1 | use gpui_kit::assets::IconName; |
| 2 | use gpui_kit::component::h_flex; |
| 3 | use gpui_kit::prelude::FluentBuilder as _; |
| 4 | use gpui_kit::*; |
| 5 | |
| 6 | use super::widgets::icon; |
| 7 | use crate::connection_banner::BannerText; |
| 8 | use crate::theme; |
| 9 | use app_ui_kit::layout::{ISLAND_GAP, RAIL_WIDTH}; |
| 10 | |
| 11 | const BANNER_HEIGHT: f32 = 32.; |
| 12 | const BANNER_TEXT_SIZE: f32 = 12.; |
| 13 | const BANNER_ICON_SIZE: f32 = 14.; |
| 14 | |
| 15 | pub fn render_connection_banner( |
| 16 | banner: BannerText, |
| 17 | on_retry: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, |
| 18 | ) -> impl IntoElement { |
| 19 | h_flex() |
| 20 | .debug_selector(|| "shell/connection-banner".into()) |
| 21 | .flex_none() |
| 22 | .h(px(BANNER_HEIGHT)) |
| 23 | .ml(px(RAIL_WIDTH)) |
| 24 | .mr(px(ISLAND_GAP)) |
| 25 | .mb(px(ISLAND_GAP)) |
| 26 | .px(px(12.)) |
| 27 | .gap(px(8.)) |
| 28 | .items_center() |
| 29 | .rounded(px(8.)) |
| 30 | .bg(theme::amber().opacity(0.14)) |
| 31 | .text_size(px(BANNER_TEXT_SIZE)) |
| 32 | .text_color(theme::text()) |
| 33 | .child(icon( |
| 34 | IconName::TriangleAlert, |
| 35 | BANNER_ICON_SIZE, |
| 36 | theme::amber(), |
| 37 | )) |
| 38 | .child(div().min_w_0().truncate().child(banner.text)) |
| 39 | .children(banner.detail.map(|detail| { |
| 40 | div() |
| 41 | .flex_none() |
| 42 | .text_color(theme::text_muted()) |
| 43 | .child(detail) |
| 44 | })) |
| 45 | .when_some(banner.action, |row, label| { |
| 46 | row.child( |
| 47 | div() |
| 48 | .id("connection-banner-action") |
| 49 | .flex_none() |
| 50 | .ml_auto() |
| 51 | .px(px(8.)) |
| 52 | .py(px(2.)) |
| 53 | .rounded(px(6.)) |
| 54 | .cursor_pointer() |
| 55 | .font_weight(FontWeight::SEMIBOLD) |
| 56 | .text_color(theme::accent_text()) |
| 57 | .hover(|button| button.bg(theme::row_hover())) |
| 58 | .child(label) |
| 59 | .on_click(on_retry), |
| 60 | ) |
| 61 | }) |
| 62 | } |