fluidattacks-designs 0.12.0

Fluid Attacks design system, GPUI variant: desktop widgets over the shared tokens
//! `CloudImage` — the web Cloudinary illustration by public id.
//!
//! Ids must be in the design system's illustration list (the images fetch);
//! they resolve from the local cache through [`crate::Assets`]. Apps that
//! need arbitrary Cloudinary ids at runtime bring their own gpui http client
//! and use `img(uri)` directly.
//!
//! Web props this port leaves to the fetch pipeline: `transformation` is fixed
//! per id at fetch time, `lazyload` and `placeholder` are network-progress
//! concerns the local cache removes, and `alt` has no sink in gpui yet.

use gpui::prelude::FluentBuilder as _;
use gpui::{img, px, App, IntoElement, RenderOnce, SharedString, Styled as _, Window};

#[derive(IntoElement)]
pub struct CloudImage {
    public_id: SharedString,
    width: Option<f32>,
    height: Option<f32>,
}

impl CloudImage {
    pub fn new(public_id: impl Into<SharedString>) -> Self {
        Self {
            public_id: public_id.into(),
            width: None,
            height: None,
        }
    }

    #[must_use]
    pub const fn width(mut self, width: f32) -> Self {
        self.width = Some(width);
        self
    }

    #[must_use]
    pub const fn height(mut self, height: f32) -> Self {
        self.height = Some(height);
        self
    }
}

impl RenderOnce for CloudImage {
    fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
        img(format!("images/{}.png", self.public_id))
            .when_some(self.width, |el, width| el.w(px(width)))
            .when_some(self.height, |el, height| el.h(px(height)))
    }
}