✨ Añade iconos a botones y menús

Nuevo componente Icon con un pequeño conjunto propio (`icon::Core`) que
cada tema puede sustituir; Bootsier usa Bootstrap Icons. `Button`,
`nav::Item` y `dropdown::Item` admiten iconos al principio y al final, y
el panel de administración los usa en secciones y páginas.
This commit is contained in:
Manuel Cillero 2026-11-22 23:08:28 +01:00
parent d83f8b0f7f
commit 5d6852382a
23 changed files with 1098 additions and 161 deletions

View file

@ -2,6 +2,7 @@ use crate::auth::{PermissionRef, PermissionRegistry, has_permission};
use crate::base::action::admin::{
DeclareAdminActions, DeclareAdminPages, DeclareAdminSections, DeclareAdminTasks,
};
use crate::base::component::{Icon, icon};
use crate::core::component::{Context, Contextual};
use crate::locale::Lc;
use crate::{Getters, Weight, builder_impl, trace, util};
@ -36,6 +37,8 @@ pub struct AdminSection {
/// Devuelve el peso para ordenar las secciones (menor = antes).
#[getters(copy)]
weight: Weight,
/// Devuelve el icono que acompaña al título en la navegación (si lo tiene).
icon: Option<Icon>,
}
#[builder_impl]
@ -48,6 +51,7 @@ impl AdminSection {
key,
title,
weight: 0,
icon: None,
}
}
@ -70,6 +74,13 @@ impl AdminSection {
self.weight = weight;
self
}
/// Asigna o quita el icono que acompaña al título de la sección en la navegación del panel
/// ([`Nav::admin()`](crate::base::component::Nav::admin)).
pub fn with_icon(mut self, icon: impl Into<Option<Icon>>) -> Self {
self.icon = icon.into();
self
}
}
// **< AdminPage >**********************************************************************************
@ -104,6 +115,8 @@ pub struct AdminPage {
/// ([`Routes::admin_route()`](crate::web::Routes::admin_route)).
#[getters(copy)]
permission: PermissionRef,
/// Devuelve el icono que acompaña al título en la navegación (si lo tiene).
icon: Option<Icon>,
}
#[builder_impl]
@ -126,6 +139,7 @@ impl AdminPage {
description: Lc::none(),
weight: 0,
permission,
icon: None,
}
}
@ -149,6 +163,16 @@ impl AdminPage {
self
}
/// Asigna o quita el icono que acompaña al título de la página en la navegación del panel
/// ([`Nav::admin()`](crate::base::component::Nav::admin)).
///
/// Con un icono del conjunto de PageTop ([`icon::Core`](crate::base::component::icon::Core)),
/// la extensión no depende de ningún tema y cada tema puede mostrar el equivalente del suyo.
pub fn with_icon(mut self, icon: impl Into<Option<Icon>>) -> Self {
self.icon = icon.into();
self
}
// **< AdminPage GETTERS >**********************************************************************
/// Devuelve `true` si el usuario actual puede acceder a esta página.
@ -605,16 +629,22 @@ fn relative(path: String) -> String {
// Secciones habituales del panel, declaradas antes que las de las extensiones.
fn default_sections() -> Vec<AdminSection> {
[
("people", "admin_section_people", 10),
("structure", "admin_section_structure", 20),
("config", "admin_section_config", 30),
("reports", "admin_section_reports", 40),
("help", "admin_section_help", 50),
]
.into_iter()
.map(|(key, title, weight)| AdminSection::new(key, Lc::l(title)).with_weight(weight))
.collect()
#[rustfmt::skip]
let sections = [
("people", "admin_section_people", 10, icon::Core::People),
("structure", "admin_section_structure", 20, icon::Core::Layers),
("config", "admin_section_config", 30, icon::Core::Sliders),
("reports", "admin_section_reports", 40, icon::Core::BarChart),
("help", "admin_section_help", 50, icon::Core::QuestionCircle),
];
sections
.into_iter()
.map(|(key, title, weight, icon)| {
AdminSection::new(key, Lc::l(title))
.with_weight(weight)
.with_icon(Icon::with(icon))
})
.collect()
}
#[cfg(test)]