♻️ (bootsier): Usa nuevo Props en Navbar/Offcanvas
This commit is contained in:
parent
62219584b0
commit
2202a2350c
2 changed files with 27 additions and 23 deletions
|
|
@ -136,9 +136,7 @@ const TOGGLE_OFFCANVAS: &str = "offcanvas";
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(AutoDefault, Clone, Debug, Getters)]
|
#[derive(AutoDefault, Clone, Debug, Getters)]
|
||||||
pub struct Navbar {
|
pub struct Navbar {
|
||||||
#[getters(skip)]
|
/// Devuelve identificador, clases CSS y atributos HTML del componente.
|
||||||
id: AttrId,
|
|
||||||
/// Devuelve los atributos HTML y clases CSS de la barra de navegación.
|
|
||||||
props: Props,
|
props: Props,
|
||||||
/// Devuelve el punto de ruptura configurado.
|
/// Devuelve el punto de ruptura configurado.
|
||||||
expand: BreakPoint,
|
expand: BreakPoint,
|
||||||
|
|
@ -156,10 +154,14 @@ impl Component for Navbar {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(&self) -> Option<String> {
|
fn id(&self) -> Option<String> {
|
||||||
self.id.get()
|
self.props.get_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(&mut self, _cx: &Context) {
|
fn setup(&mut self, cx: &Context) {
|
||||||
|
// Asegura que la barra de navegación tiene un identificador único.
|
||||||
|
self.alter_prop(PropsOp::ensure_id(cx.build_id::<Self>(1)));
|
||||||
|
|
||||||
|
// Clases CSS por defecto para la barra de navegación.
|
||||||
self.alter_prop(PropsOp::prepend_classes({
|
self.alter_prop(PropsOp::prepend_classes({
|
||||||
let mut classes = "navbar".to_string();
|
let mut classes = "navbar".to_string();
|
||||||
self.expand().push_class(&mut classes, "navbar-expand", "");
|
self.expand().push_class(&mut classes, "navbar-expand", "");
|
||||||
|
|
@ -198,11 +200,11 @@ impl Component for Navbar {
|
||||||
return Ok(html! {});
|
return Ok(html! {});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asegura que la barra tiene un `id` para poder asociarlo al colapso/offcanvas.
|
// `setup()` garantiza que habrá un `id` antes de renderizar.
|
||||||
let id = cx.required_id::<Self>(self.id(), 1);
|
let id = self.id().unwrap();
|
||||||
|
|
||||||
Ok(html! {
|
Ok(html! {
|
||||||
nav id=(&id) (self.props()) {
|
nav (self.props()) {
|
||||||
div class="container-fluid" {
|
div class="container-fluid" {
|
||||||
@match self.layout() {
|
@match self.layout() {
|
||||||
// Barra más sencilla: sólo contenido.
|
// Barra más sencilla: sólo contenido.
|
||||||
|
|
@ -335,14 +337,14 @@ impl Navbar {
|
||||||
|
|
||||||
// **< Navbar BUILDER >*************************************************************************
|
// **< Navbar BUILDER >*************************************************************************
|
||||||
|
|
||||||
/// Establece el identificador único (`id`) de la barra de navegación.
|
/// Establece el identificador único del componente; igual a `with_prop(PropsOp::set_id(id))`.
|
||||||
#[builder_fn]
|
#[builder_fn]
|
||||||
pub fn with_id(mut self, id: impl AsRef<str>) -> Self {
|
pub fn with_id(mut self, id: impl Into<CowStr>) -> Self {
|
||||||
self.id.alter_id(id);
|
self.props.alter_id(id);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modifica los atributos HTML o las clases CSS de la barra de navegación.
|
/// Modifica identificador, clases CSS o atributos HTML del componente.
|
||||||
///
|
///
|
||||||
/// También acepta clases predefinidas para:
|
/// También acepta clases predefinidas para:
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,7 @@ use crate::theme::*;
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(AutoDefault, Clone, Debug, Getters)]
|
#[derive(AutoDefault, Clone, Debug, Getters)]
|
||||||
pub struct Offcanvas {
|
pub struct Offcanvas {
|
||||||
#[getters(skip)]
|
/// Devuelve identificador, clases CSS y atributos HTML del componente.
|
||||||
id: AttrId,
|
|
||||||
/// Devuelve los atributos HTML y clases CSS del panel.
|
|
||||||
props: Props,
|
props: Props,
|
||||||
/// Devuelve el título del panel.
|
/// Devuelve el título del panel.
|
||||||
title: L10n,
|
title: L10n,
|
||||||
|
|
@ -69,10 +67,14 @@ impl Component for Offcanvas {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(&self) -> Option<String> {
|
fn id(&self) -> Option<String> {
|
||||||
self.id.get()
|
self.props.get_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(&mut self, _cx: &Context) {
|
fn setup(&mut self, cx: &Context) {
|
||||||
|
// Asegura que el panel tiene un identificador único.
|
||||||
|
self.alter_prop(PropsOp::ensure_id(cx.build_id::<Self>(1)));
|
||||||
|
|
||||||
|
// Clases CSS por defecto para el panel.
|
||||||
self.alter_prop(PropsOp::prepend_classes({
|
self.alter_prop(PropsOp::prepend_classes({
|
||||||
let mut classes = "offcanvas".to_string();
|
let mut classes = "offcanvas".to_string();
|
||||||
self.breakpoint().push_class(&mut classes, "offcanvas", "");
|
self.breakpoint().push_class(&mut classes, "offcanvas", "");
|
||||||
|
|
@ -90,14 +92,14 @@ impl Component for Offcanvas {
|
||||||
impl Offcanvas {
|
impl Offcanvas {
|
||||||
// **< Offcanvas BUILDER >**********************************************************************
|
// **< Offcanvas BUILDER >**********************************************************************
|
||||||
|
|
||||||
/// Establece el identificador único (`id`) del panel.
|
/// Establece el identificador único del componente; igual a `with_prop(PropsOp::set_id(id))`.
|
||||||
#[builder_fn]
|
#[builder_fn]
|
||||||
pub fn with_id(mut self, id: impl AsRef<str>) -> Self {
|
pub fn with_id(mut self, id: impl Into<CowStr>) -> Self {
|
||||||
self.id.alter_id(id);
|
self.props.alter_id(id);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modifica los atributos HTML o las clases CSS del panel.
|
/// Modifica identificador, clases CSS o atributos HTML del componente.
|
||||||
#[builder_fn]
|
#[builder_fn]
|
||||||
pub fn with_prop(mut self, op: PropsOp) -> Self {
|
pub fn with_prop(mut self, op: PropsOp) -> Self {
|
||||||
self.props.alter_prop(op);
|
self.props.alter_prop(op);
|
||||||
|
|
@ -172,7 +174,8 @@ impl Offcanvas {
|
||||||
return html! {};
|
return html! {};
|
||||||
}
|
}
|
||||||
|
|
||||||
let id = cx.required_id::<Self>(self.id(), 1);
|
// `setup()` garantiza que habrá un `id` antes de renderizar.
|
||||||
|
let id = self.id().unwrap();
|
||||||
let id_label = util::join!(id, "-label");
|
let id_label = util::join!(id, "-label");
|
||||||
let id_target = util::join!("#", id);
|
let id_target = util::join!("#", id);
|
||||||
|
|
||||||
|
|
@ -191,7 +194,6 @@ impl Offcanvas {
|
||||||
|
|
||||||
html! {
|
html! {
|
||||||
div
|
div
|
||||||
id=(&id)
|
|
||||||
(self.props())
|
(self.props())
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
data-bs-scroll=[body_scroll]
|
data-bs-scroll=[body_scroll]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue