use topcoat::{
context::Cx,
view::{BoxView, ViewExt, view},
};
use super::super::Panel;
use crate::{Color, Text};
#[derive(Debug, Clone)]
pub struct Environment {
name: Text,
color: Color,
}
impl Environment {
pub fn new(name: impl Into<Text>) -> Self {
Self {
name: name.into(),
color: Color::Warning,
}
}
#[must_use]
pub fn color(mut self, color: Color) -> Self {
self.color = color;
self
}
pub(crate) fn name(&self, cx: &Cx) -> String {
self.name.localize(cx)
}
pub(crate) fn ribbon<'a>(&self, cx: &'a Cx) -> BoxView<'a> {
let name = self.name(cx);
let stripe = format!(
"pointer-events-none fixed inset-x-0 top-0 z-50 h-0.5 {}",
self.color.fill_class()
);
let badge = format!(
"pointer-events-none fixed bottom-3 left-1/2 z-50 -translate-x-1/2 rounded-full px-3 \
py-0.5 text-xs font-medium text-white shadow-sm {}",
self.color.fill_class()
);
view! {
<div class=(stripe) aria-hidden="true"></div>
<div class=(badge) role="note" data-environment=(name.clone())>(name)</div>
}
.boxed()
}
}
impl Panel {
#[must_use]
pub fn environment(mut self, environment: Environment) -> Self {
self.environment = Some(environment);
self
}
}