♻️ (bootsier): Sustituye BreakPoint por Breakpoint
Elimina el enum BreakPoint propio de Bootsier. Los componentes pasan a usar el Breakpoint del núcleo, cuyo nombre y ancho resuelve el tema activo.
This commit is contained in:
parent
307ca6f62c
commit
5bf28ef4f0
10 changed files with 185 additions and 113 deletions
|
|
@ -26,7 +26,7 @@ const EXTRA_WIDTH: &str = "bootsier.container.width";
|
|||
///
|
||||
/// let main = bs::Container::main()
|
||||
/// .with_id("main-page")
|
||||
/// .with_width(bs::container::Width::From(BreakPoint::LG))
|
||||
/// .with_width(bs::container::Width::From(Breakpoint::Lg))
|
||||
/// .with_prop(PropsOp::add_classes(class::Bg::with(BootsierColors::Light)))
|
||||
/// .with_prop(PropsOp::add_classes(class::Text::with(BootsierColors::Dark)))
|
||||
/// .with_prop(PropsOp::add_classes(class::Border::with(ScaleSize::One)))
|
||||
|
|
@ -61,7 +61,7 @@ pub enum Width {
|
|||
Default,
|
||||
/// Aplica los anchos máximos predefinidos a partir del punto de ruptura indicado. Por debajo de
|
||||
/// ese punto de ruptura ocupa el 100% del ancho disponible.
|
||||
From(BreakPoint),
|
||||
From(Breakpoint),
|
||||
/// Ocupa el 100% del ancho disponible siempre.
|
||||
Fluid,
|
||||
/// Ocupa el 100% del ancho disponible hasta un ancho máximo explícito.
|
||||
|
|
@ -72,30 +72,34 @@ impl Width {
|
|||
const CONTAINER: &str = "container";
|
||||
|
||||
/// Añade la clase asociada al ancho del contenedor a la cadena de clases.
|
||||
///
|
||||
/// El nombre del punto de ruptura se resuelve en el tema activo de `cx`.
|
||||
#[inline]
|
||||
pub fn push_to(self, classes: &mut String) {
|
||||
pub fn push_to(self, cx: &Context, classes: &mut String) {
|
||||
match self {
|
||||
Self::Default => BreakPoint::None.push_to(classes, Self::CONTAINER, ""),
|
||||
Self::From(bp) => bp.push_to(classes, Self::CONTAINER, ""),
|
||||
Self::Default => {
|
||||
push_breakpoint_class(cx, Breakpoint::Xs, classes, Self::CONTAINER, "")
|
||||
}
|
||||
Self::From(bp) => push_breakpoint_class(cx, bp, classes, Self::CONTAINER, ""),
|
||||
Self::Fluid | Self::FluidMax(_) => {
|
||||
BreakPoint::None.push_to(classes, Self::CONTAINER, "fluid")
|
||||
push_breakpoint_class(cx, Breakpoint::Xs, classes, Self::CONTAINER, "fluid")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Devuelve la clase asociada al ancho del contenedor.
|
||||
pub fn to_class(self) -> String {
|
||||
pub fn to_class(self, cx: &Context) -> String {
|
||||
let mut class = String::new();
|
||||
self.push_to(&mut class);
|
||||
self.push_to(cx, &mut class);
|
||||
class
|
||||
}
|
||||
}
|
||||
|
||||
// **< Container SETUP >****************************************************************************
|
||||
|
||||
pub(crate) fn setup(container: &mut Container) {
|
||||
pub(crate) fn setup(container: &mut Container, cx: &Context) {
|
||||
let width = container.props().extra_or(EXTRA_WIDTH, Width::default());
|
||||
container.alter_prop(PropsOp::prepend_classes(width.to_class()));
|
||||
container.alter_prop(PropsOp::prepend_classes(width.to_class(cx)));
|
||||
if let Width::FluidMax(w) = width
|
||||
&& w.is_measurable()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ pub(crate) async fn render(
|
|||
let auto_close = auto_close.opt_str();
|
||||
let menu_classes = {
|
||||
let mut classes = "dropdown-menu".to_string();
|
||||
menu_align.push_to(&mut classes);
|
||||
menu_align.push_to(cx, &mut classes);
|
||||
classes
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -112,65 +112,69 @@ impl Direction {
|
|||
/// Alineación horizontal del menú desplegable [`Dropdown`](crate::theme::bs::Dropdown).
|
||||
///
|
||||
/// Permite alinear el menú al inicio o al final del botón (respetando LTR/RTL) y añadirle una
|
||||
/// alineación diferente a partir de un punto de ruptura ([`BreakPoint`]).
|
||||
/// alineación diferente a partir de un punto de ruptura ([`Breakpoint`]).
|
||||
#[derive(AutoDefault, Clone, Copy, Debug, PartialEq)]
|
||||
pub enum MenuAlign {
|
||||
/// Alineación al inicio (comportamiento por defecto).
|
||||
#[default]
|
||||
Start,
|
||||
/// Alineación al inicio a partir del punto de ruptura indicado.
|
||||
StartAt(BreakPoint),
|
||||
StartAt(Breakpoint),
|
||||
/// Alineación al inicio por defecto, y al final a partir de un punto de ruptura válido.
|
||||
StartAndEnd(BreakPoint),
|
||||
StartAndEnd(Breakpoint),
|
||||
/// Alineación al final.
|
||||
End,
|
||||
/// Alineación al final a partir del punto de ruptura indicado.
|
||||
EndAt(BreakPoint),
|
||||
EndAt(Breakpoint),
|
||||
/// Alineación al final por defecto, y al inicio a partir de un punto de ruptura válido.
|
||||
EndAndStart(BreakPoint),
|
||||
EndAndStart(Breakpoint),
|
||||
}
|
||||
|
||||
impl MenuAlign {
|
||||
/// Añade las clases de alineación a la cadena de clases (sin incluir la base `dropdown-menu`).
|
||||
///
|
||||
/// El nombre del punto de ruptura se resuelve en el tema activo de `cx`.
|
||||
#[inline]
|
||||
pub fn push_to(self, classes: &mut String) {
|
||||
pub fn push_to(self, cx: &Context, classes: &mut String) {
|
||||
const MENU: &str = "dropdown-menu";
|
||||
|
||||
match self {
|
||||
// Alineación por defecto (start), no añade clases extra.
|
||||
Self::Start => {}
|
||||
|
||||
// `dropdown-menu-{bp}-start`
|
||||
Self::StartAt(bp) => {
|
||||
bp.push_to(classes, "dropdown-menu", "start");
|
||||
push_breakpoint_class(cx, bp, classes, MENU, "start");
|
||||
}
|
||||
|
||||
// `dropdown-menu-start` + `dropdown-menu-{bp}-end`
|
||||
Self::StartAndEnd(bp) => {
|
||||
BreakPoint::None.push_to(classes, "dropdown-menu", "start");
|
||||
bp.push_to(classes, "dropdown-menu", "end");
|
||||
push_breakpoint_class(cx, Breakpoint::Xs, classes, MENU, "start");
|
||||
push_breakpoint_class(cx, bp, classes, MENU, "end");
|
||||
}
|
||||
|
||||
// `dropdown-menu-end`
|
||||
Self::End => {
|
||||
BreakPoint::None.push_to(classes, "dropdown-menu", "end");
|
||||
push_breakpoint_class(cx, Breakpoint::Xs, classes, MENU, "end");
|
||||
}
|
||||
|
||||
// `dropdown-menu-{bp}-end`
|
||||
Self::EndAt(bp) => {
|
||||
bp.push_to(classes, "dropdown-menu", "end");
|
||||
push_breakpoint_class(cx, bp, classes, MENU, "end");
|
||||
}
|
||||
|
||||
// `dropdown-menu-end` + `dropdown-menu-{bp}-start`
|
||||
Self::EndAndStart(bp) => {
|
||||
BreakPoint::None.push_to(classes, "dropdown-menu", "end");
|
||||
bp.push_to(classes, "dropdown-menu", "start");
|
||||
push_breakpoint_class(cx, Breakpoint::Xs, classes, MENU, "end");
|
||||
push_breakpoint_class(cx, bp, classes, MENU, "start");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Devuelve las clases de alineación del menú (sin incluir la base `dropdown-menu`).
|
||||
pub fn to_class(self) -> String {
|
||||
pub fn to_class(self, cx: &Context) -> String {
|
||||
let mut classes = String::new();
|
||||
self.push_to(&mut classes);
|
||||
self.push_to(cx, &mut classes);
|
||||
classes
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ const EXTRA_EXPAND: &str = "bootsier.navbar.expand";
|
|||
/// # use pagetop::prelude::*;
|
||||
/// # use pagetop_bootsier::theme::*;
|
||||
/// let navbar = bs::Navbar::simple_toggle()
|
||||
/// .with_expand(BreakPoint::MD)
|
||||
/// .with_expand(Breakpoint::Md)
|
||||
/// .with_item(bs::navbar::Item::nav(
|
||||
/// bs::Nav::new()
|
||||
/// .with_item(bs::nav::Item::link(Lc::n("Home"), "/"))
|
||||
|
|
@ -88,7 +88,7 @@ const EXTRA_EXPAND: &str = "bootsier.navbar.expand";
|
|||
/// .with_route(Route::from("/"));
|
||||
///
|
||||
/// let navbar = bs::Navbar::brand_right(brand)
|
||||
/// .with_expand(BreakPoint::LG)
|
||||
/// .with_expand(Breakpoint::Lg)
|
||||
/// .with_item(bs::navbar::Item::nav(
|
||||
/// bs::Nav::new()
|
||||
/// .with_kind(bs::nav::Kind::Pills)
|
||||
|
|
@ -152,7 +152,7 @@ pub trait NavbarBootsier {
|
|||
fn offcanvas_brand_right(brand: Brand, oc: bs::Offcanvas) -> Self;
|
||||
|
||||
/// Define a partir de qué punto de ruptura la barra de navegación deja de colapsar.
|
||||
fn with_expand(self, bp: BreakPoint) -> Self;
|
||||
fn with_expand(self, bp: Breakpoint) -> Self;
|
||||
|
||||
/// Define dónde se mostrará la barra de navegación dentro del documento.
|
||||
fn with_position(self, position: bs::navbar::Position) -> Self;
|
||||
|
|
@ -187,7 +187,7 @@ impl NavbarBootsier for Navbar {
|
|||
navbar
|
||||
}
|
||||
|
||||
fn with_expand(mut self, bp: BreakPoint) -> Self {
|
||||
fn with_expand(mut self, bp: Breakpoint) -> Self {
|
||||
self.alter_prop(PropsOp::set_extra(EXTRA_EXPAND, bp));
|
||||
self
|
||||
}
|
||||
|
|
@ -200,15 +200,15 @@ impl NavbarBootsier for Navbar {
|
|||
|
||||
// **< Navbar SETUP >*******************************************************************************
|
||||
|
||||
pub(crate) fn setup(navbar: &mut Navbar) {
|
||||
pub(crate) fn setup(navbar: &mut Navbar, cx: &Context) {
|
||||
// Sin `with_expand()`, colapsa por debajo de 768px, igual que el tema Basic (que no tiene
|
||||
// punto de ruptura configurable y siempre usa ese umbral, ver `static/css/basic.css`).
|
||||
let expand = navbar.props().extra_or(EXTRA_EXPAND, BreakPoint::MD);
|
||||
let expand = navbar.props().extra_or(EXTRA_EXPAND, Breakpoint::Md);
|
||||
let position = navbar
|
||||
.props()
|
||||
.extra_or(EXTRA_POSITION, bs::navbar::Position::default());
|
||||
let mut classes = String::new();
|
||||
expand.push_to(&mut classes, "navbar-expand", "");
|
||||
push_breakpoint_class(cx, expand, &mut classes, "navbar-expand", "");
|
||||
position.push_to(&mut classes);
|
||||
if !classes.is_empty() {
|
||||
navbar.alter_prop(PropsOp::add_classes(classes));
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ pub struct Offcanvas {
|
|||
/// Devuelve el título del panel.
|
||||
title: Lc,
|
||||
/// Devuelve el punto de ruptura configurado para cambiar el comportamiento del panel.
|
||||
breakpoint: BreakPoint,
|
||||
breakpoint: Breakpoint,
|
||||
/// Devuelve el comportamiento configurado para la capa de fondo.
|
||||
backdrop: bs::offcanvas::Backdrop,
|
||||
/// Indica si la página principal puede desplazarse mientras el panel está abierto.
|
||||
|
|
@ -77,8 +77,8 @@ impl Component for Offcanvas {
|
|||
|
||||
// Clases CSS por defecto para el panel.
|
||||
self.alter_prop(PropsOp::prepend_classes({
|
||||
let mut classes = "offcanvas".to_string();
|
||||
self.breakpoint().push_to(&mut classes, "offcanvas", "");
|
||||
let mut classes = String::new();
|
||||
push_breakpoint_class(cx, *self.breakpoint(), &mut classes, "offcanvas", "");
|
||||
self.placement().push_to(&mut classes);
|
||||
self.visibility().push_to(&mut classes);
|
||||
classes
|
||||
|
|
@ -118,10 +118,10 @@ impl Offcanvas {
|
|||
/// ([`Offcanvas`]).
|
||||
/// - **Por encima**, el contenido del panel se muestra tal cual, integrado en la página.
|
||||
///
|
||||
/// Por ejemplo, con `BreakPoint::Lg`, será *offcanvas* en móviles y tabletas, y visible
|
||||
/// directamente en pantallas grandes. Por defecto usa `BreakPoint::None` para que sea
|
||||
/// Por ejemplo, con `Breakpoint::Lg`, será *offcanvas* en móviles y tabletas, y visible
|
||||
/// directamente en pantallas grandes. Por defecto usa `Breakpoint::Xs` para que sea
|
||||
/// *offcanvas* siempre.
|
||||
pub fn with_breakpoint(mut self, bp: BreakPoint) -> Self {
|
||||
pub fn with_breakpoint(mut self, bp: Breakpoint) -> Self {
|
||||
self.breakpoint = bp;
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
//! Tipos enumerados para construir clases del tema.
|
||||
|
||||
mod breakpoint;
|
||||
pub use breakpoint::BreakPoint;
|
||||
|
||||
mod color;
|
||||
pub use color::{BootsierColors, OpacityLevel};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,61 +0,0 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
/// Puntos de ruptura (*breakpoints*) para aplicar diseño *responsive*.
|
||||
#[derive(AutoDefault, Clone, Copy, Debug, PartialEq)]
|
||||
pub enum BreakPoint {
|
||||
/// **Menos de 576px**. Dispositivos muy pequeños: teléfonos en modo vertical.
|
||||
#[default]
|
||||
None,
|
||||
/// **576px o más**. Dispositivos pequeños: teléfonos en modo horizontal.
|
||||
SM,
|
||||
/// **768px o más**. Dispositivos medianos: tabletas.
|
||||
MD,
|
||||
/// **992px o más**. Dispositivos grandes: puestos de escritorio.
|
||||
LG,
|
||||
/// **1200px o más**. Dispositivos muy grandes: puestos de escritorio grandes.
|
||||
XL,
|
||||
/// **1400px o más**. Dispositivos extragrandes: puestos de escritorio más grandes.
|
||||
XXL,
|
||||
}
|
||||
|
||||
impl BreakPoint {
|
||||
/// Devuelve la identificación del punto de ruptura (`"sm"`, `"md"`, etc.), o `""` para `None`.
|
||||
#[rustfmt::skip]
|
||||
#[inline]
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::None => "",
|
||||
Self::SM => "sm",
|
||||
Self::MD => "md",
|
||||
Self::LG => "lg",
|
||||
Self::XL => "xl",
|
||||
Self::XXL => "xxl",
|
||||
}
|
||||
}
|
||||
|
||||
// Añade el punto de ruptura con un prefijo y un sufijo (opcional) a la cadena de clases.
|
||||
//
|
||||
// - Para `None`: `prefix` o `prefix-suffix` (si `suffix` no está vacío).
|
||||
// - Para `SM..XXL`: `prefix-{breakpoint}` o `prefix-{breakpoint}-{suffix}`.
|
||||
#[inline]
|
||||
pub(crate) fn push_to(self, classes: &mut String, prefix: &str, suffix: &str) {
|
||||
if prefix.is_empty() {
|
||||
return;
|
||||
}
|
||||
if !classes.is_empty() {
|
||||
classes.push(' ');
|
||||
}
|
||||
match self {
|
||||
Self::None => classes.push_str(prefix),
|
||||
_ => {
|
||||
classes.push_str(prefix);
|
||||
classes.push('-');
|
||||
classes.push_str(self.as_str());
|
||||
}
|
||||
}
|
||||
if !suffix.is_empty() {
|
||||
classes.push('-');
|
||||
classes.push_str(suffix);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue