♻️ (pagetop): Logotipo embebido y Badge en Intent
- `PageTopSvg::markup_with()` fusiona `Props` y controla la etiqueta accesible directamente en el `<svg>`. - `Image` ya no duplica accesibilidad para el logotipo y corrige el `alt` vacío en el resto de fuentes (Responsive/Thumbnail/Plain). - Sustituye `BadgeKind` y el `ColorName`/`IntoColor` de `core/theme` por un `Intent` compartido.
This commit is contained in:
parent
4ba66f5995
commit
e24b9ab9de
15 changed files with 199 additions and 187 deletions
|
|
@ -1,28 +1,12 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
// **< BadgeKind >**********************************************************************************
|
||||
|
||||
/// Tipo de [`Badge`].
|
||||
#[derive(AutoDefault, Clone, Copy, Debug, PartialEq)]
|
||||
pub enum BadgeKind {
|
||||
Primary,
|
||||
#[default]
|
||||
Secondary,
|
||||
Success,
|
||||
Info,
|
||||
Warning,
|
||||
Danger,
|
||||
}
|
||||
|
||||
// **< Badge >**************************************************************************************
|
||||
|
||||
/// Componente para mostrar una **etiqueta corta informativa** (*badge*).
|
||||
///
|
||||
/// # Ejemplo
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use pagetop::prelude::*;
|
||||
/// let badge = Badge::labeled(Lc::n("Admin")).with_kind(BadgeKind::Danger);
|
||||
/// let badge = Badge::labeled(Lc::n("Admin")).with_intent(Intent::Danger);
|
||||
///
|
||||
/// // Equivalente usando el constructor directo del tipo.
|
||||
/// let badge = Badge::danger(Lc::n("Admin"));
|
||||
|
|
@ -33,9 +17,10 @@ pub struct Badge {
|
|||
props: Props,
|
||||
/// Devuelve la etiqueta del badge.
|
||||
label: Lc,
|
||||
/// Devuelve el tipo del badge.
|
||||
/// Devuelve la intención semántica del badge.
|
||||
#[getters(copy)]
|
||||
kind: BadgeKind,
|
||||
#[default(Intent::Secondary)]
|
||||
intent: Intent,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
|
@ -48,16 +33,11 @@ impl Component for Badge {
|
|||
self.props.get_id()
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn setup(&mut self, _cx: &Context) {
|
||||
self.alter_prop(PropsOp::prepend_classes(match self.kind() {
|
||||
BadgeKind::Primary => "badge badge-primary",
|
||||
BadgeKind::Secondary => "badge badge-secondary",
|
||||
BadgeKind::Success => "badge badge-success",
|
||||
BadgeKind::Info => "badge badge-info",
|
||||
BadgeKind::Warning => "badge badge-warning",
|
||||
BadgeKind::Danger => "badge badge-danger",
|
||||
}));
|
||||
self.alter_prop(PropsOp::prepend_classes(util::join!(
|
||||
"badge badge-",
|
||||
self.intent().as_str()
|
||||
)));
|
||||
}
|
||||
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
|
|
@ -70,7 +50,7 @@ impl Component for Badge {
|
|||
}
|
||||
|
||||
impl Badge {
|
||||
/// Crea un badge predeterminado (`BadgeKind::default()`) con la etiqueta indicada.
|
||||
/// Crea un badge predeterminado (`Intent::default()`) con la etiqueta indicada.
|
||||
pub fn labeled(label: Lc) -> Self {
|
||||
Self {
|
||||
label,
|
||||
|
|
@ -82,7 +62,7 @@ impl Badge {
|
|||
pub fn primary(label: Lc) -> Self {
|
||||
Self {
|
||||
label,
|
||||
kind: BadgeKind::Primary,
|
||||
intent: Intent::Primary,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -91,7 +71,7 @@ impl Badge {
|
|||
pub fn secondary(label: Lc) -> Self {
|
||||
Self {
|
||||
label,
|
||||
kind: BadgeKind::Secondary,
|
||||
intent: Intent::Secondary,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -100,7 +80,7 @@ impl Badge {
|
|||
pub fn success(label: Lc) -> Self {
|
||||
Self {
|
||||
label,
|
||||
kind: BadgeKind::Success,
|
||||
intent: Intent::Success,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -109,7 +89,7 @@ impl Badge {
|
|||
pub fn info(label: Lc) -> Self {
|
||||
Self {
|
||||
label,
|
||||
kind: BadgeKind::Info,
|
||||
intent: Intent::Info,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -118,7 +98,7 @@ impl Badge {
|
|||
pub fn warning(label: Lc) -> Self {
|
||||
Self {
|
||||
label,
|
||||
kind: BadgeKind::Warning,
|
||||
intent: Intent::Warning,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -127,7 +107,7 @@ impl Badge {
|
|||
pub fn danger(label: Lc) -> Self {
|
||||
Self {
|
||||
label,
|
||||
kind: BadgeKind::Danger,
|
||||
intent: Intent::Danger,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -155,10 +135,10 @@ impl Badge {
|
|||
self
|
||||
}
|
||||
|
||||
/// Establece el tipo del badge.
|
||||
/// Establece la intención semántica del badge.
|
||||
#[builder_fn]
|
||||
pub fn with_kind(mut self, kind: BadgeKind) -> Self {
|
||||
self.kind = kind;
|
||||
pub fn with_intent(mut self, intent: Intent) -> Self {
|
||||
self.intent = intent;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue