From d83f8b0f7f2ff369be47b9556e0e2a364fc94b20 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Mon, 16 Nov 2026 14:22:18 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Renueva=20los=20estilos=20de=20B?= =?UTF-8?q?asic=20y=20Bootsier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Bootsier: paleta propia a partir del logotipo, campos rellenos con sombra al enfocar, fieldsets y mensajes con sombra en vez de borde, desplegables sin borde, migas con fondo y paginador adaptable. - Bootsier: quita la rejilla de Bootstrap (la maquetación es de Flex y Grid) y el container-fluid interior de la barra de navegación. - Basic: margen inferior en campos y bloques, padding lateral en el envoltorio de la página y paginador que se reparte en varias líneas. - Nuevo ejemplo theme-showcase con todos los componentes en los dos temas. --- assets/scss/basic.scss | 1 + assets/scss/basic/_base.scss | 4 +- assets/scss/basic/_block.scss | 4 + assets/scss/basic/_form.scss | 16 +- assets/scss/basic/_navbar.scss | 5 +- assets/scss/basic/_pager.scss | 7 + examples/locale/en-US/theme-showcase.ftl | 72 +++ examples/locale/es-ES/theme-showcase.ftl | 72 +++ examples/theme-showcase.rs | 488 ++++++++++++++++++ .../assets/_bootsier-custom.scss | 157 +++++- .../assets/_bootsier-utilities.scss | 6 +- .../assets/_bootsier-variables.scss | 67 +++ .../pagetop-bootsier/assets/bootsier.scss | 2 +- .../src/theme/bs/navbar/component.rs | 108 ++-- 14 files changed, 930 insertions(+), 79 deletions(-) create mode 100644 assets/scss/basic/_block.scss create mode 100644 examples/locale/en-US/theme-showcase.ftl create mode 100644 examples/locale/es-ES/theme-showcase.ftl create mode 100644 examples/theme-showcase.rs diff --git a/assets/scss/basic.scss b/assets/scss/basic.scss index 70110aa6..ccf728c9 100644 --- a/assets/scss/basic.scss +++ b/assets/scss/basic.scss @@ -17,6 +17,7 @@ // Components, in alphabetical order. `buttons` must go before `dropdown` and `nav`, see the notes // in `basic/_buttons.scss`. @use "basic/badge"; +@use "basic/block"; @use "basic/brand"; @use "basic/breadcrumb"; @use "basic/buttons"; diff --git a/assets/scss/basic/_base.scss b/assets/scss/basic/_base.scss index 203b656d..804b374a 100644 --- a/assets/scss/basic/_base.scss +++ b/assets/scss/basic/_base.scss @@ -16,8 +16,10 @@ body { -webkit-tap-highlight-color: transparent; } -// Header, Aside, Content and Footer are stacked in that order, using the full available width. +// Header, Aside, Content and Footer are stacked in that order, using the full available width, with +// side padding (the same as containers) so the content never touches the edges of the screen. .wrapper { display: flex; flex-direction: column; + padding-inline: 1rem; } diff --git a/assets/scss/basic/_block.scss b/assets/scss/basic/_block.scss new file mode 100644 index 00000000..e555d7bf --- /dev/null +++ b/assets/scss/basic/_block.scss @@ -0,0 +1,4 @@ +// Space below each block, so consecutive blocks (and what follows them) do not sit right together. +.block { + margin-bottom: 2rem; +} diff --git a/assets/scss/basic/_form.scss b/assets/scss/basic/_form.scss index 6fdc3d7e..173a2926 100644 --- a/assets/scss/basic/_form.scss +++ b/assets/scss/basic/_form.scss @@ -3,9 +3,17 @@ margin-left: 0.25rem; } +// Fields are spaced below, as in Bootsier, so the first one of a form or a fieldset starts right +// at its top; the last one leaves no gap. +.form-field { + margin-bottom: 1rem; +} +.form-field:last-child { + margin-bottom: 0; +} + .form-label { display: block; - margin-top: 1em; } .form-text { @@ -25,7 +33,7 @@ } fieldset { - margin: 2rem 0 1rem; + margin: 0 0 1rem; background: var(--val-color--bg); } fieldset > legend { @@ -42,10 +50,6 @@ fieldset > legend { min-height: 1.5rem; margin-bottom: 0.25rem; } -// A single checkbox has no label above it to give it room, as the other fields do. -.form-field.form-check:not(.form-check-inline) { - margin-top: 1em; -} .form-check-inline { display: inline-grid; margin-right: 1rem; diff --git a/assets/scss/basic/_navbar.scss b/assets/scss/basic/_navbar.scss index fb393727..75f56634 100644 --- a/assets/scss/basic/_navbar.scss +++ b/assets/scss/basic/_navbar.scss @@ -1,10 +1,11 @@ @use "breakpoints" as bp; +// No side padding, so the bar lines up with the rest of the page (fixed bars below get it back). .navbar { display: flex; align-items: center; gap: 1rem; - padding: 0.5rem 1rem; + padding-block: 0.5rem; } .navbar-toggle { @@ -53,12 +54,14 @@ .navbar.sticky-bottom { background-color: var(--val-color--bg); } +// Fixed bars span the whole viewport, so they keep some side padding off its edges. .navbar.fixed-top, .navbar.fixed-bottom { position: fixed; right: 0; left: 0; z-index: 1030; + padding-inline: 1rem; } .navbar.fixed-top { top: 0; diff --git a/assets/scss/basic/_pager.scss b/assets/scss/basic/_pager.scss index be2c7c6e..b6604bec 100644 --- a/assets/scss/basic/_pager.scss +++ b/assets/scss/basic/_pager.scss @@ -33,8 +33,10 @@ margin-inline-end: 0; } +// Cells wrap onto more lines when they don't fit, so a long pager never gets wider than the screen. .pagination { display: flex; + flex-wrap: wrap; align-items: center; gap: 0.25rem; list-style: none; @@ -94,6 +96,11 @@ display: flex; align-items: center; } +// The page number is a form field: without the bottom margin fields take elsewhere, so it lines up +// with the button. +.pager-jump-input { + margin-bottom: 0; +} .pager-jump:focus-within { border-radius: 0.375rem; box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--val-color--primary) 25%, transparent); diff --git a/examples/locale/en-US/theme-showcase.ftl b/examples/locale/en-US/theme-showcase.ftl new file mode 100644 index 00000000..2a79de06 --- /dev/null +++ b/examples/locale/en-US/theme-showcase.ftl @@ -0,0 +1,72 @@ +showcase_title = Theme showcase + +showcase_menu_home = Home +showcase_menu_components = Components +showcase_menu_forms = Forms +showcase_menu_fields = Fields +showcase_menu_buttons = Buttons +showcase_menu_others = Others +showcase_menu_messages = Messages +showcase_menu_disabled = Disabled +showcase_menu_docs = Documentation +showcase_menu_sign_up = Sign up +showcase_menu_login = Log in + +showcase_block_fields = Text fields and dropdowns +showcase_name = Name +showcase_name_help = Help text, smaller and lighter than the label. +showcase_email = Email +showcase_email_placeholder = name@example.com +showcase_focus = With focus +showcase_font = Font +showcase_disabled = Disabled +showcase_readonly = Read-only +showcase_disabled_select = Disabled dropdown +showcase_comment = Comment +showcase_comment_placeholder = Write here... +showcase_floating = Floating label + +showcase_block_checks = Checks, switches and options +showcase_checks = Checks +showcase_check_off = Unchecked +showcase_check_on = Checked +showcase_check_disabled = Disabled +showcase_switches = Switches +showcase_switch_off = Off +showcase_switch_on = On +showcase_switch_disabled = Disabled +showcase_options = Options +showcase_option_small = Small +showcase_option_medium = Medium +showcase_option_large = Large +showcase_options_help = The disabled option cannot be chosen. + +showcase_filter_hint = + Change a value without pressing "Filter": the filter marks the changed fields and highlights + its button until it is applied. +showcase_search = Search +showcase_search_placeholder = Name or email... +showcase_status = Status +showcase_status_any = Any +showcase_status_active = Active +showcase_status_blocked = Blocked +showcase_only_admins = Administrators only + +showcase_block_tables = List filters and tables +showcase_new_user = New user +showcase_col_user = User +showcase_col_email = Email +showcase_col_status = Status +showcase_col_last_access = Last access +showcase_col_actions = Actions +showcase_status_pending = Pending +showcase_edit = Edit +showcase_empty_table = A table without rows shows its message: + +showcase_block_buttons = Buttons + +showcase_block_misc = Links, badges and pagination +showcase_link_text = A paragraph with a link in the middle of the text. +showcase_msg_info = An informative message. +showcase_msg_warning = A warning message. +showcase_msg_error = An error message. diff --git a/examples/locale/es-ES/theme-showcase.ftl b/examples/locale/es-ES/theme-showcase.ftl new file mode 100644 index 00000000..0ddce351 --- /dev/null +++ b/examples/locale/es-ES/theme-showcase.ftl @@ -0,0 +1,72 @@ +showcase_title = Muestrario del tema + +showcase_menu_home = Inicio +showcase_menu_components = Componentes +showcase_menu_forms = Formularios +showcase_menu_fields = Campos +showcase_menu_buttons = Botones +showcase_menu_others = Otros +showcase_menu_messages = Mensajes +showcase_menu_disabled = Deshabilitado +showcase_menu_docs = Documentación +showcase_menu_sign_up = Registrarse +showcase_menu_login = Iniciar sesión + +showcase_block_fields = Campos de texto y listas +showcase_name = Nombre +showcase_name_help = Texto de ayuda, más pequeño y claro que la etiqueta. +showcase_email = Correo electrónico +showcase_email_placeholder = nombre@ejemplo.com +showcase_focus = Con el foco +showcase_font = Fuente +showcase_disabled = Deshabilitado +showcase_readonly = Sólo lectura +showcase_disabled_select = Lista deshabilitada +showcase_comment = Comentario +showcase_comment_placeholder = Escribe aquí... +showcase_floating = Etiqueta flotante + +showcase_block_checks = Casillas, interruptores y opciones +showcase_checks = Casillas +showcase_check_off = Sin marcar +showcase_check_on = Marcada +showcase_check_disabled = Deshabilitada +showcase_switches = Interruptores +showcase_switch_off = Apagado +showcase_switch_on = Encendido +showcase_switch_disabled = Deshabilitado +showcase_options = Opciones +showcase_option_small = Pequeño +showcase_option_medium = Mediano +showcase_option_large = Grande +showcase_options_help = La opción deshabilitada no se puede elegir. + +showcase_filter_hint = + Cambia algún valor sin pulsar «Filtrar»: el filtro marca los campos cambiados y destaca su + botón hasta que se aplica. +showcase_search = Buscar +showcase_search_placeholder = Nombre o correo... +showcase_status = Estado +showcase_status_any = Cualquiera +showcase_status_active = Activo +showcase_status_blocked = Bloqueado +showcase_only_admins = Sólo administradores + +showcase_block_tables = Filtros de listados y tablas +showcase_new_user = Nuevo usuario +showcase_col_user = Usuario +showcase_col_email = Correo electrónico +showcase_col_status = Estado +showcase_col_last_access = Último acceso +showcase_col_actions = Acciones +showcase_status_pending = Pendiente +showcase_edit = Editar +showcase_empty_table = Una tabla sin filas muestra su mensaje: + +showcase_block_buttons = Botones + +showcase_block_misc = Enlaces, insignias y paginación +showcase_link_text = Un párrafo con un enlace en medio del texto. +showcase_msg_info = Un mensaje informativo. +showcase_msg_warning = Un mensaje de aviso. +showcase_msg_error = Un mensaje de error. diff --git a/examples/theme-showcase.rs b/examples/theme-showcase.rs new file mode 100644 index 00000000..c4dedc7d --- /dev/null +++ b/examples/theme-showcase.rs @@ -0,0 +1,488 @@ +use pagetop::prelude::*; +use pagetop_bootsier::theme::*; + +include_locales!(LOC from "examples/locale"); + +struct ThemeShowcase; + +#[async_trait] +impl Extension for ThemeShowcase { + fn dependencies(&self) -> Vec { + vec![&pagetop_bootsier::Bootsier] + } + + async fn initialize(&self) -> Result<(), BoxError> { + let brand = Brand::new() + .with_image( + // Recuadro en el color primario de Bootsier (petróleo, `#0e6973`), con la línea + // clara que elige el logotipo por contraste. Se ve igual en los dos modos de color. + Image::with(image::Source::logo(PageTopSvg::TileRGB(14, 105, 115))) + .with_size(image::Size::Both(UnitValue::Px(36))), + ) + .with_title(Lc::n("PageTop")) + .with_route(Route::from("/")); + + // Menú completo: enlace activo, desplegable con secciones, enlace externo y deshabilitado. + // Ocupa el espacio libre entre la marca y el menú de la cuenta, con sus opciones centradas. + let main_menu = Nav::new() + .with_layout(nav::Layout::Center) + .with_prop(FlexItem::new().with_grow(flex::ItemGrow::Is1)) + .with_item(nav::Item::link(Lc::t("showcase_menu_home", &LOC), "/").with_active(true)) + .with_item(nav::Item::dropdown( + Dropdown::new() + .with_title(Lc::t("showcase_menu_components", &LOC)) + .with_item(dropdown::Item::header(Lc::t("showcase_menu_forms", &LOC))) + .with_item(dropdown::Item::link( + Lc::t("showcase_menu_fields", &LOC), + "#", + )) + .with_item(dropdown::Item::link( + Lc::t("showcase_menu_buttons", &LOC), + "#", + )) + .with_item(dropdown::Item::divider()) + .with_item(dropdown::Item::header(Lc::t("showcase_menu_others", &LOC))) + .with_item(dropdown::Item::link( + Lc::t("showcase_menu_messages", &LOC), + "#", + )) + .with_item(dropdown::Item::link_disabled( + Lc::t("showcase_menu_disabled", &LOC), + "#", + )), + )) + .with_item(nav::Item::link_blank( + Lc::t("showcase_menu_docs", &LOC), + "https://docs.rs/pagetop", + )) + .with_item(nav::Item::link_disabled( + Lc::t("showcase_menu_disabled", &LOC), + "#", + )); + + // Menú de la cuenta al final de la barra y, con Bootsier, el selector de modo de color + // (claro, oscuro o automático). + let mut user_menu = Nav::new() + .with_prop(FlexItem::push_end()) + .with_item(nav::Item::link(Lc::t("showcase_menu_sign_up", &LOC), "#")) + .with_item(nav::Item::link(Lc::t("showcase_menu_login", &LOC), "#")); + if is_bootsier() { + user_menu = user_menu.with_item(bs::theme_toggle()); + } + + let header = Navbar::brand_left(brand) + .with_expand(Breakpoint::Lg) + .with_item(navbar::Item::nav(main_menu)) + .with_item(navbar::Item::nav(user_menu)); + + InRegion::Global(&CoreRegions::Header).add(header); + Ok(()) + } + + fn configure_router(&self, routes: Routes) -> Routes { + routes.public_route("/", web::get(theme_showcase)) + } +} + +async fn theme_showcase(request: HttpRequest) -> Result { + let mut page = Page::new(request) + .with_title(Lc::t("showcase_title", &LOC)) + .with_child(fields_block()) + .with_child(checks_block()) + .with_child(tables_block()) + .with_child(buttons_block()) + .with_child(misc_block()); + + // Un mensaje de cada nivel, que muestra el listado del bloque de tablas entre su botón y la + // tabla, como haría con el aviso de un borrado. + page.push_message(MessageLevel::Info, Lc::t("showcase_msg_info", &LOC)); + page.push_message(MessageLevel::Warning, Lc::t("showcase_msg_warning", &LOC)); + page.push_message(MessageLevel::Error, Lc::t("showcase_msg_error", &LOC)); + + page.render().await +} + +// Bootsier aporta piezas propias que otros temas no tienen: el selector de modo de color, las +// etiquetas flotantes y los botones de los colores claro y oscuro de su paleta. +fn is_bootsier() -> bool { + global::SETTINGS.app.theme.eq_ignore_ascii_case("bootsier") +} + +// Rejilla de una columna en pantallas pequeñas, dos a partir de `Md` y tres a partir de `Lg`. Sin +// hueco entre filas: ya separa los campos su propio margen. +fn columns() -> Grid { + let tracks = |n| grid::Tracks::repeat(n, grid::AxisTrack::Fraction(1.0)); + Grid::new() + .with_columns(tracks(1)) + .with_columns_at(Breakpoint::Md, tracks(2)) + .with_columns_at(Breakpoint::Lg, tracks(3)) + .with_gap(align::Gap::Distinct { + row: UnitValue::None, + column: UnitValue::RelRem(1.5), + }) +} + +// Campos de texto y listas en sus distintos estados. +fn fields_block() -> Block { + let mut grid = columns() + .with_child( + form::input::Field::text() + .with_name("name") + .with_label(Lc::t("showcase_name", &LOC)) + .with_value("Ana García") + .with_help_text(Lc::t("showcase_name_help", &LOC)) + .with_required(true), + ) + .with_child( + form::input::Field::email() + .with_name("email") + .with_label(Lc::t("showcase_email", &LOC)) + .with_placeholder(Lc::t("showcase_email_placeholder", &LOC)), + ) + .with_child( + form::input::Field::text() + .with_name("focus") + .with_label(Lc::t("showcase_focus", &LOC)) + .with_value("1200") + .with_autofocus(true), + ) + .with_child( + form::select::Field::new() + .with_name("font") + .with_label(Lc::t("showcase_font", &LOC)) + .with_item(form::select::Item::new( + "playfair", + Lc::n("Playfair Display"), + )) + .with_item(form::select::Item::new("source", Lc::n("Source Sans 3"))) + .with_item(form::select::Item::new("roboto", Lc::n("Roboto"))), + ) + .with_child( + form::input::Field::text() + .with_name("disabled") + .with_label(Lc::t("showcase_disabled", &LOC)) + .with_value("Ana García") + .with_disabled(true), + ) + .with_child( + form::input::Field::email() + .with_name("readonly") + .with_label(Lc::t("showcase_readonly", &LOC)) + .with_value("ana@example.com") + .with_readonly(true), + ) + .with_child( + form::select::Field::new() + .with_name("disabled_font") + .with_label(Lc::t("showcase_disabled_select", &LOC)) + .with_item(form::select::Item::new( + "playfair", + Lc::n("Playfair Display"), + )) + .with_disabled(true), + ) + .with_child( + form::Textarea::new() + .with_name("comment") + .with_label(Lc::t("showcase_comment", &LOC)) + .with_placeholder(Lc::t("showcase_comment_placeholder", &LOC)), + ); + if is_bootsier() { + grid = grid.with_child( + form::input::Field::text() + .with_name("floating") + .with_label(Lc::t("showcase_floating", &LOC)) + .with_value("Ana García") + .with_floating_label(true), + ); + } + + // El último campo no tiene margen inferior y, si es el más alto de su fila, la rejilla acaba en + // su borde. El margen de la rejilla repone ese espacio, como el que dejan debajo los demás + // bloques. + Block::new() + .with_title(Lc::t("showcase_block_fields", &LOC)) + .with_child(grid.with_prop(Margin::new().with_bottom(UnitValue::RelRem(1.0)))) +} + +// Casillas, interruptores y botones de opción, marcados, sin marcar y deshabilitados. +fn checks_block() -> Block { + Block::new() + .with_title(Lc::t("showcase_block_checks", &LOC)) + .with_child( + columns() + .with_child( + form::Fieldset::new() + .with_legend(Lc::t("showcase_checks", &LOC)) + .with_child( + form::Checkbox::new() + .with_name("check_off") + .with_label(Lc::t("showcase_check_off", &LOC)), + ) + .with_child( + form::Checkbox::new() + .with_name("check_on") + .with_label(Lc::t("showcase_check_on", &LOC)) + .with_checked(true), + ) + .with_child( + form::Checkbox::new() + .with_name("check_disabled") + .with_label(Lc::t("showcase_check_disabled", &LOC)) + .with_disabled(true), + ), + ) + .with_child( + form::Fieldset::new() + .with_legend(Lc::t("showcase_switches", &LOC)) + .with_child( + form::Checkbox::switch() + .with_name("switch_off") + .with_label(Lc::t("showcase_switch_off", &LOC)), + ) + .with_child( + form::Checkbox::switch() + .with_name("switch_on") + .with_label(Lc::t("showcase_switch_on", &LOC)) + .with_checked(true), + ) + .with_child( + form::Checkbox::switch() + .with_name("switch_disabled") + .with_label(Lc::t("showcase_switch_disabled", &LOC)) + .with_disabled(true), + ), + ) + .with_child( + form::Fieldset::new() + .with_legend(Lc::t("showcase_options", &LOC)) + .with_child( + form::radio::Field::new() + .with_name("size") + .with_item(form::radio::Item::new( + "small", + Lc::t("showcase_option_small", &LOC), + )) + .with_item( + form::radio::Item::new( + "medium", + Lc::t("showcase_option_medium", &LOC), + ) + .with_checked(true), + ) + .with_item( + form::radio::Item::new( + "large", + Lc::t("showcase_option_large", &LOC), + ) + .with_disabled(true), + ) + .with_help_text(Lc::t("showcase_options_help", &LOC)), + ), + ), + ) +} + +// Filtro de listado, listado completo (botón de acción, tabla con cabeceras ordenables y +// paginador) y tabla vacía. +fn tables_block() -> Block { + // Columna ordenable; `dir` marca la que determina el orden vigente. + let sortable = |key: &'static str, sort: &str, dir: Option| { + table::Column::new(Lc::t(key, &LOC)) + .with_sort(table::SortLink::new(util::join!("/?sort=", sort)).with_dir(dir)) + }; + + let mut users = Table::new() + .with_column(sortable("showcase_col_user", "user", Some(SortDir::Asc))) + .with_column(sortable("showcase_col_email", "email", None)) + .with_column(Lc::t("showcase_col_status", &LOC)) + .with_column(sortable("showcase_col_last_access", "access", None)) + .with_column(Lc::t("showcase_col_actions", &LOC)); + for (user, email, status, access) in [ + ("ana", "ana@example.com", "active", "2026-11-14 09:12"), + ("bruno", "bruno@example.com", "pending", "-"), + ("carmen", "carmen@example.com", "active", "2026-11-13 18:40"), + ("david", "david@example.com", "blocked", "2026-10-02 11:05"), + ] { + let badge = match status { + "active" => Badge::success(Lc::t("showcase_status_active", &LOC)), + "pending" => Badge::warning(Lc::t("showcase_status_pending", &LOC)), + _ => Badge::severe(Lc::t("showcase_status_blocked", &LOC)), + }; + users.alter_row( + table::Row::new() + .with_cell(user) + .with_cell(email) + .with_cell(table::Cell::new(badge)) + .with_cell(access) + .with_cell(table::Cell::new( + Button::anchor(Lc::t("showcase_edit", &LOC), "#") + .with_style(button::Style::Link), + )), + ); + } + + let list = ListView::new() + .with_id("showcase-users") + .with_action( + Button::anchor(Lc::t("showcase_new_user", &LOC), "#") + .with_style(button::Style::Solid(Intent::Primary)), + ) + .with_table(users) + .with_pager( + Pager::new() + .with_base_path("/") + .with_current_page(1) + .with_items_per_page(4) + .with_total_items(14), + ); + + // Sin filas, la tabla muestra su mensaje predeterminado. + let empty = Table::new() + .with_column(Lc::t("showcase_col_user", &LOC)) + .with_column(Lc::t("showcase_col_email", &LOC)) + .with_column(Lc::t("showcase_col_status", &LOC)); + + Block::new() + .with_title(Lc::t("showcase_block_tables", &LOC)) + .with_child(Html::with(|cx| { + html! { + p { (Lc::t("showcase_filter_hint", &LOC).using(cx)) } + } + })) + // El filtro va fuera del listado: si se reemplazara con él, el campo de búsqueda perdería + // el foco al actualizar sólo el listado. + .with_child( + ListFilter::new() + .with_filter_action("/") + .with_field( + form::input::Field::search() + .with_name("q") + .with_label(Lc::t("showcase_search", &LOC)) + .with_placeholder(Lc::t("showcase_search_placeholder", &LOC)), + ) + .with_field( + form::select::Field::new() + .with_name("status") + .with_label(Lc::t("showcase_status", &LOC)) + .with_item(form::select::Item::new( + "", + Lc::t("showcase_status_any", &LOC), + )) + .with_item(form::select::Item::new( + "active", + Lc::t("showcase_status_active", &LOC), + )) + .with_item(form::select::Item::new( + "blocked", + Lc::t("showcase_status_blocked", &LOC), + )), + ) + .with_field( + form::Checkbox::new() + .with_name("admins") + .with_label(Lc::t("showcase_only_admins", &LOC)), + ), + ) + .with_child(list) + .with_child(Html::with(|cx| { + html! { + p { (Lc::t("showcase_empty_table", &LOC).using(cx)) } + } + })) + .with_child(empty) +} + +// Botones macizos y de contorno de todas las intenciones. +fn buttons_block() -> Block { + Block::new() + .with_title(Lc::t("showcase_block_buttons", &LOC)) + .with_child( + Flex::new() + .with_direction(flex::Direction::Column) + .with_gap(align::Gap::Both(UnitValue::RelRem(0.5))) + .with_prop(Margin::new().with_bottom(UnitValue::RelRem(1.5))) + .with_child(buttons(false)) + .with_child(buttons(true)), + ) +} + +// Una fila con un botón por intención. Con Bootsier, también los colores claro y oscuro de su +// paleta, que no corresponden a ninguna intención. El estilo enlace sólo va en la fila maciza. +fn buttons(outline: bool) -> Flex { + let style = |intent| match outline { + false => button::Style::Solid(intent), + true => button::Style::Outline(intent), + }; + + let mut row = Flex::new() + .with_wrap(flex::Behavior::Wrap) + .with_gap(align::Gap::Both(UnitValue::RelRem(0.5))); + for (label, intent) in [ + ("Primary", Intent::Primary), + ("Neutral", Intent::Neutral), + ("Info", Intent::Info), + ("Success", Intent::Success), + ("Warning", Intent::Warning), + ("Severe", Intent::Severe), + ] { + row = row.with_child(Button::plain(Lc::n(label)).with_style(style(intent))); + } + if is_bootsier() { + for (label, color) in [ + ("Light", BootsierColors::Light), + ("Dark", BootsierColors::Dark), + ] { + row = row.with_child( + Button::plain(Lc::n(label)) + .with_style(style(Intent::Neutral)) + .with_color(color), + ); + } + } + if !outline { + row = row.with_child(Button::plain(Lc::n("Link")).with_style(button::Style::Link)); + } + row +} + +// Enlaces, insignias, paginación y mensajes, que también toman los colores del tema. +fn misc_block() -> Block { + let mut badges = Flex::new() + .with_wrap(flex::Behavior::Wrap) + .with_gap(align::Gap::Both(UnitValue::RelRem(0.5))); + for badge in [ + Badge::primary(Lc::n("Primary")), + Badge::neutral(Lc::n("Neutral")), + Badge::info(Lc::n("Info")), + Badge::success(Lc::n("Success")), + Badge::warning(Lc::n("Warning")), + Badge::severe(Lc::n("Severe")), + ] { + badges = badges.with_child(badge); + } + + Block::new() + .with_title(Lc::t("showcase_block_misc", &LOC)) + .with_child(Html::with(|cx| { + html! { + p { (Lc::t("showcase_link_text", &LOC).using(cx)) } + } + })) + .with_child(badges) + // Con 50 páginas y la actual en medio aparecen todas sus piezas: anterior y siguiente, las + // elipsis de los tramos ocultos a cada lado, el resumen y el formulario para saltar a una + // página. + .with_child( + Pager::new() + .with_base_path("/") + .with_current_page(24) + .with_items_per_page(10) + .with_total_items(500), + ) +} + +#[pagetop::main] +async fn main() -> std::io::Result<()> { + Application::prepare(&ThemeShowcase).await.run().await +} diff --git a/extensions/pagetop-bootsier/assets/_bootsier-custom.scss b/extensions/pagetop-bootsier/assets/_bootsier-custom.scss index ed317b38..9ac5e0fd 100644 --- a/extensions/pagetop-bootsier/assets/_bootsier-custom.scss +++ b/extensions/pagetop-bootsier/assets/_bootsier-custom.scss @@ -19,6 +19,46 @@ font-display: swap; } +// Background of the form fields ($input-bg in _bootsier-variables.scss), of disabled fields +// ($input-disabled-bg), of unchecked checks ($form-check-input-bg), of fieldsets, of dropdown menus +// ($dropdown-bg) and of breadcrumbs ($breadcrumb-bg), color of the group titles of dropdown menus +// ($dropdown-header-color, a lighter gray than their items in light mode, nearly white in dark +// mode), color of the legends of fieldsets (darker than Bootstrap's secondary color in light mode, +// since their thin weight makes them lighter), and shadow of focused fields +// ($input-focus-box-shadow), for each color mode. On a dark background the primary color barely +// shows, so the dark mode uses a lighter tint of it with more opacity. +:root, +[data-bs-theme="light"] { + --bootsier-input-bg: #f1f3f4; + --bootsier-input-disabled-bg: #f7f8f9; + --bootsier-check-bg: #e2e5e8; + --bootsier-fieldset-bg: #fefefe; + --bootsier-dropdown-bg: #fdfdfd; + --bootsier-breadcrumb-bg: #f8f9fa; + --bootsier-dropdown-header-color: rgba(var(--bs-body-color-rgb), .65); + --bootsier-legend-color: rgba(var(--bs-body-color-rgb), .9); + --bootsier-focus-shadow: 0 0 2px #{rgba($primary, .15)}, 0 0 6px #{rgba($primary, .35)}; +} + +@include color-mode(dark, true) { + --bootsier-input-bg: #{$gray-800}; + --bootsier-input-disabled-bg: #31363b; + --bootsier-check-bg: #{$gray-700}; + --bootsier-fieldset-bg: #292e33; + --bootsier-dropdown-bg: #3e444a; + --bootsier-breadcrumb-bg: #292e33; + --bootsier-dropdown-header-color: rgba(var(--bs-emphasis-color-rgb), .85); + --bootsier-legend-color: var(--bs-secondary-color); + --bootsier-focus-shadow: + 0 0 2px #{rgba(tint-color($primary, 60%), .4)}, 0 0 6px #{rgba(tint-color($primary, 60%), .7)}; +} + +// Disabled form fields also fade as disabled buttons do. +.form-control:disabled, +.form-select:disabled { + opacity: $btn-disabled-opacity; +} + // Font-relative top offset to keep the skip-link hidden at any font size. .skip-link { top: -3em; @@ -48,12 +88,20 @@ margin: 1rem 0; } -// Fieldset with border and floating legend. +// Space below each block (Block), from Bootstrap's spacing unit, so consecutive blocks (and what +// follows them) do not sit right together. Twice $spacer, as the 2rem of the Basic theme. +.block { + margin-bottom: $spacer * 2; +} + +// Fieldset outlined only by a soft shadow (Bootstrap's reboot already removes the border), with a +// floating legend. fieldset { position: relative; - background-color: var(--bs-body-bg); - border: var(--bs-border-width) solid var(--bs-border-color); + background-color: var(--bootsier-fieldset-bg); border-radius: var(--bs-border-radius); + // Offset down with a negative spread: strongest below, softer at the sides, faintest on top. + box-shadow: 0 1px 3px rgba(0, 0, 0, .10), 0 4px 8px -2px rgba(0, 0, 0, .22); padding: 2rem 1rem 1rem; margin: 2rem 0 1rem; } @@ -63,13 +111,14 @@ fieldset > legend { top: 0; left: 1rem; transform: translateY(-50%); - color: var(--bs-secondary-color); + color: var(--bootsier-legend-color); background-color: var(--bs-body-bg); - border: var(--bs-border-width) solid var(--bs-border-color); + // Soft outline with the gray of the form fields, in both color modes. + border: var(--bs-border-width) solid var(--bootsier-input-bg); border-radius: var(--bs-border-radius); padding: 0.125rem 0.75rem; font-size: ($font-size-sm + $font-size-base) / 2; - font-weight: var(--bs-font-weight-normal); + font-weight: $font-weight-light; line-height: 1.25; width: fit-content; max-width: 75%; @@ -82,6 +131,11 @@ fieldset > legend { margin-bottom: 1rem; } +// Labels start a little inside, clear of the rounded corner of their field. +.form-label { + padding-left: .25rem; +} + // Gap between group label and first inline check. .form-label + .form-check-inline { margin-left: 1rem; @@ -99,11 +153,68 @@ fieldset > legend { text-align: center; } +// Images with this class show their colors inverted in dark mode, such as a dark logo that would +// otherwise blend into the background. Only for images that keep their look when inverted: a full +// color one would change its hues. +[data-bs-theme="dark"] .image-invert-dark { + filter: invert(1); +} + +// Dropdown menus have no border (_bootsier-variables.scss), so a soft shadow sets them apart from +// the content they cover, as fieldsets are outlined. Bootstrap only adds its own with +// $enable-shadows. +.dropdown-menu { + box-shadow: 0 1px 3px rgba(0, 0, 0, .10), 0 4px 8px -2px rgba(0, 0, 0, .22); +} + +// Group titles of dropdown menus in a lighter weight than their items. +.dropdown-header { + font-weight: $font-weight-light; +} + +// Navbars have no inner container, so they line up with the rest of the page. Fixed bars span the +// whole viewport, so they take back the side padding of a container off its edges. +.navbar.fixed-top, +.navbar.fixed-bottom { + padding-right: $container-padding-x * .5; + padding-left: $container-padding-x * .5; +} + +// The first link of the first menu and the last link of the last menu drop their outer padding, so +// their text lines up with the rest of the page (next to the brand, its own margin keeps them +// apart). Collapsed bars stack their links with no side padding already. +.navbar-nav:first-child > .nav-item:first-child > .nav-link { + padding-left: 0; +} +.navbar-nav:last-child > .nav-item:last-child > .nav-link { + padding-right: 0; +} + +// Disabled links of navbars, lighter in dark mode: Bootstrap's 30% of the text color barely shows +// on the dark background (links take 65%). +[data-bs-theme="dark"] .navbar { + --bs-navbar-disabled-color: rgba(var(--bs-emphasis-color-rgb), .45); +} + // Messages component. Classes are fixed by pagetop core (`.message`, `.message-info`, // `.message-warning`, `.message-error`); reusing Bootstrap's own `.alert`/`.alert-*` styles keeps // the palette in sync with the active Bootstrap theme instead of duplicating it here. .message { @extend .alert; + // Outlined by a shadow tinted with the text color of each variant instead of a border. A single + // offset shadow is always stronger below than at the sides, so three are combined (left, right + // and below) to reach the same width on those three sides, leaving the top faint. + --bootsier-message-shadow: color-mix(in srgb, var(--bs-alert-color) 35%, transparent); + border: 0; + box-shadow: + 0 1px 2px color-mix(in srgb, var(--bs-alert-color) 15%, transparent), + -4px 0 6px -4px var(--bootsier-message-shadow), + 4px 0 6px -4px var(--bootsier-message-shadow), + 0 3px 6px -3px var(--bootsier-message-shadow); +} +// No shadow in dark mode, where it barely shows: the background of each variant is enough. +[data-bs-theme="dark"] .message { + box-shadow: none; } .message-info { @extend .alert-info; @@ -133,6 +244,14 @@ fieldset > legend { opacity: 1; } +// Message of a table without rows, as in the Basic theme: centered, in italics and muted (inside +// .table, to win over the color Bootstrap gives to every cell). +.table .table-empty { + text-align: center; + font-style: italic; + color: var(--bs-secondary-color); +} + // List filters (ListFilter): fields and button on one row, wrapping when there is no room. .list-filter { display: flex; @@ -150,8 +269,9 @@ fieldset > legend { // colors and opacity change, never sizes: the dot always takes its room, hidden, so nothing moves // when it shows up. A vivid orange, set apart from the primary color of the button, darkened just // enough to keep a 3:1 contrast against the background. Every changed field gets the dot by its -// label, once per field (on the title of a group); text fields and dropdowns also show a gray -// background. Floating labels are left out: Bootstrap draws their background with `::after`. +// label, once per field (on the title of a group); text fields, dropdowns and checks also show +// their border in that color. Floating labels are left out: Bootstrap draws their background with +// `::after`. .list-filter { --list-filter-mark: #{mix(#000, $orange, 15%)}; } @@ -173,12 +293,11 @@ fieldset > legend { .form-control, .form-select, .form-check-input { - background-color: var(--bs-secondary-bg); + border-color: var(--list-filter-mark); } .form-check-input:checked { background-color: var(--list-filter-mark); - border-color: var(--list-filter-mark); } } @@ -244,6 +363,24 @@ fieldset > legend { margin-inline-end: 0; } +// Joined cells, as in Bootstrap, but wrapping onto more lines when they don't fit: a long pager +// never gets wider than the screen (mobile browsers would zoom out the whole page). Each line +// overlaps the border of the one above, as cells do side by side. On small screens they also get +// smaller, so that more of them fit on a line. +.pagination { + flex-wrap: wrap; +} +.pagination .page-link { + margin-bottom: calc(var(--bs-pagination-border-width) * -1); +} +@include media-breakpoint-down(sm) { + .pagination { + --bs-pagination-padding-x: .5rem; + --bs-pagination-padding-y: .25rem; + --bs-pagination-font-size: #{$font-size-base * .875}; + } +} + // By default, .page-link-icon shows the text of pager_previous_label/pager_next_label // ("Previous"/"Next"). The full accessible text lives separately, in the link's aria-label, so // replacing the visible text here with a symbol does not affect accessibility. To use "‹"/"›" diff --git a/extensions/pagetop-bootsier/assets/_bootsier-utilities.scss b/extensions/pagetop-bootsier/assets/_bootsier-utilities.scss index 4192158e..f75435ac 100644 --- a/extensions/pagetop-bootsier/assets/_bootsier-utilities.scss +++ b/extensions/pagetop-bootsier/assets/_bootsier-utilities.scss @@ -1,8 +1,4 @@ -// Bootstrap utility extensions. Imported just before utilities/api so variable changes take effect. - -// CSS Grid (Bootstrap 5): disable legacy grid classes and enable native CSS Grid. -$enable-grid-classes: false; -$enable-cssgrid: true; +// Bootstrap utility extensions. Imported just before utilities/api so the changes take effect. // Extend the $utilities map with additional classes. $utilities: map-merge( diff --git a/extensions/pagetop-bootsier/assets/_bootsier-variables.scss b/extensions/pagetop-bootsier/assets/_bootsier-variables.scss index 61eb6a25..76d6117e 100644 --- a/extensions/pagetop-bootsier/assets/_bootsier-variables.scss +++ b/extensions/pagetop-bootsier/assets/_bootsier-variables.scss @@ -10,7 +10,74 @@ $font-family-sans-serif: "Source Sans 3", system-ui, -apple-system, "Segoe UI", "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; +// Theme colors from the PageTop logo and the Intro component: warm neutrals and state colors of the +// same palette, with a petrol blue as the primary color. The text Bootstrap picks for their +// buttons (white or black) keeps a contrast of at least 4.5:1 with all of them. +$primary: #0e6973; // Petrol blue, a cool counterpoint to the warm palette. +$secondary: #6e604a; // Warm gray of the logo, darkened. +$success: #4d7c0f; // Lime of the logo, as olive green. +$danger: #b91c1c; // Red of the Intro button. +$warning: #ffb84b; // Amber of the logo. +$info: #4cb5c4; // Teal of the screens in the Intro illustration. +$light: #fff1db; // Cream of the Intro blocks. +$dark: #1a202c; // Text color of Intro. + +// Filled form fields: text fields, dropdowns and checks take a gray background, one for each color +// mode (--bootsier-input-bg, declared in _bootsier-custom.scss), and the same color as their +// border, which only shows when it changes color (validation). Checked checks already take the +// same color for both. +$input-bg: var(--bootsier-input-bg); +$input-border-color: $input-bg; +// Unchecked checks, radios and switches take a somewhat darker gray (--bootsier-check-bg), since +// they are small and would barely stand out with the background of text fields. +$form-check-input-bg: var(--bootsier-check-bg); +$form-check-input-border: var(--bs-border-width) solid $form-check-input-bg; +// Disabled fields take a lighter background (--bootsier-input-disabled-bg), with the border in the +// same color, and also fade (see _bootsier-custom.scss). +$input-disabled-bg: var(--bootsier-input-disabled-bg); +$input-disabled-border-color: $input-disabled-bg; +// Focused text fields and dropdowns keep their border hidden and stand out with a shadow in the +// primary color, equally wide on all four sides, one for each color mode (--bootsier-focus-shadow, +// declared in _bootsier-custom.scss). Checks keep Bootstrap's focus ring, with no border. +$input-focus-border-color: $input-bg; +$input-focus-box-shadow: var(--bootsier-focus-shadow); +$form-select-focus-box-shadow: $input-focus-box-shadow; +$form-check-input-focus-border: $form-check-input-bg; +// Bootstrap draws the knob of focused switches with $input-focus-border-color inside an SVG, where +// CSS variables do not work: keep its default color. +$form-switch-focus-color: tint-color($primary, 50%); + +// Labels closer to their field (Bootstrap's default is .5rem), and two pixels smaller than the +// body text (16px with the 18px of $font-size-base; Bootstrap's default inherits it). +$form-label-margin-bottom: .125rem; +$form-label-font-size: $font-size-base - .125rem; + +// Lighter help text than Bootstrap's (.75 opacity), still above a 4.5:1 contrast in both color +// modes (4.9:1 on white), and slightly smaller (Bootstrap's default is .875em). +$form-text-color: rgba(var(--bs-body-color-rgb), .65); +$form-text-font-size: .8125em; + // Table cells centered vertically, as in the Basic theme: with Bootstrap's default (top), a cell // holding a button is taller and the text of the other cells sticks to the top of the row. Header // cells keep Bootstrap's bottom alignment. $table-cell-vertical-align: middle; + +// Dropdown menus: a gray background between those of fieldsets and text fields, one for each color +// mode (--bootsier-dropdown-bg, declared in _bootsier-custom.scss), with no outer border nor +// rounded corners; dividers keep the border color. The hovered item takes the gray of text fields, +// since Bootstrap's (--bs-tertiary-bg) would match the menu background. +$dropdown-bg: var(--bootsier-dropdown-bg); +$dropdown-border-width: 0; +$dropdown-border-radius: 0; +$dropdown-inner-border-radius: 0; +$dropdown-link-hover-bg: var(--bootsier-input-bg); +// Group titles of dropdown menus, lighter in light mode (--bootsier-dropdown-header-color). +$dropdown-header-color: var(--bootsier-dropdown-header-color); + +// Breadcrumbs: a light gray background, one for each color mode (--bootsier-breadcrumb-bg, declared +// in _bootsier-custom.scss), padding that keeps the text off its edges, and 16px text (1rem), +// smaller than the 18px of $font-size-base. +$breadcrumb-bg: var(--bootsier-breadcrumb-bg); +$breadcrumb-padding-y: .5rem; +$breadcrumb-padding-x: .75rem; +$breadcrumb-font-size: 1rem; diff --git a/extensions/pagetop-bootsier/assets/bootsier.scss b/extensions/pagetop-bootsier/assets/bootsier.scss index 94fcf61e..79ff1e3f 100644 --- a/extensions/pagetop-bootsier/assets/bootsier.scss +++ b/extensions/pagetop-bootsier/assets/bootsier.scss @@ -17,12 +17,12 @@ @import "bootstrap-5.3.8/scss/utilities"; // Bootstrap Layout & components +// No "grid": page layout comes from PageTop's own Flex and Grid components. @import "bootstrap-5.3.8/scss/root"; @import "bootstrap-5.3.8/scss/reboot"; @import "bootstrap-5.3.8/scss/type"; @import "bootstrap-5.3.8/scss/images"; @import "bootstrap-5.3.8/scss/containers"; -@import "bootstrap-5.3.8/scss/grid"; @import "bootstrap-5.3.8/scss/tables"; @import "bootstrap-5.3.8/scss/forms"; @import "bootstrap-5.3.8/scss/buttons"; diff --git a/extensions/pagetop-bootsier/src/theme/bs/navbar/component.rs b/extensions/pagetop-bootsier/src/theme/bs/navbar/component.rs index f8728e38..7de60cd7 100644 --- a/extensions/pagetop-bootsier/src/theme/bs/navbar/component.rs +++ b/extensions/pagetop-bootsier/src/theme/bs/navbar/component.rs @@ -261,68 +261,66 @@ pub(crate) async fn render(navbar: &Navbar, cx: &mut Context) -> Result { + @match layout { + // Barra más sencilla: sólo contenido. + bs::navbar::Layout::Simple => { + (items) + }, + + // Barra sencilla que se puede contraer/expandir. + bs::navbar::Layout::SimpleToggle => { + (button(cx, TOGGLE_COLLAPSE, &id_content)) + div id=(&id_content) class="collapse navbar-collapse" { (items) - }, + } + }, - // Barra sencilla que se puede contraer/expandir. - bs::navbar::Layout::SimpleToggle => { - (button(cx, TOGGLE_COLLAPSE, &id_content)) - div id=(&id_content) class="collapse navbar-collapse" { - (items) - } - }, + // Barra con marca a la izquierda, siempre visible. El contenedor ocupa el espacio + // que deja la marca y coloca en él los contenidos, como en las barras que se + // contraen. Sin `collapse`, `setup()` garantiza `navbar-expand` y Bootstrap lo + // muestra siempre. + bs::navbar::Layout::SimpleBrandLeft(brand) => { + (brand.render(cx).await) + div class="navbar-collapse" { (items) } + }, - // Barra con marca a la izquierda, siempre visible. El contenedor deja los - // contenidos junto a la marca: sin él, el `space-between` de `container-fluid` - // los llevaría al extremo opuesto. Sin `collapse`, `setup()` garantiza - // `navbar-expand` y Bootstrap lo muestra siempre. - bs::navbar::Layout::SimpleBrandLeft(brand) => { - (brand.render(cx).await) - div class="navbar-collapse" { (items) } - }, + // Barra con marca a la izquierda y botón a la derecha. + bs::navbar::Layout::BrandLeft(brand) => { + (brand.render(cx).await) + (button(cx, TOGGLE_COLLAPSE, &id_content)) + div id=(&id_content) class="collapse navbar-collapse" { + (items) + } + }, - // Barra con marca a la izquierda y botón a la derecha. - bs::navbar::Layout::BrandLeft(brand) => { - (brand.render(cx).await) - (button(cx, TOGGLE_COLLAPSE, &id_content)) - div id=(&id_content) class="collapse navbar-collapse" { - (items) - } - }, + // Barra con botón a la izquierda y marca a la derecha. + bs::navbar::Layout::BrandRight(brand) => { + (button(cx, TOGGLE_COLLAPSE, &id_content)) + (brand.render(cx).await) + div id=(&id_content) class="collapse navbar-collapse" { + (items) + } + }, - // Barra con botón a la izquierda y marca a la derecha. - bs::navbar::Layout::BrandRight(brand) => { - (button(cx, TOGGLE_COLLAPSE, &id_content)) - (brand.render(cx).await) - div id=(&id_content) class="collapse navbar-collapse" { - (items) - } - }, + // Barra cuyo contenido se muestra en un panel lateral, sin marca. + bs::navbar::Layout::Offcanvas(panel) => { + (button(cx, TOGGLE_OFFCANVAS, &id_content)) + (panel.render_panel(cx, &id_content, &items)) + }, - // Barra cuyo contenido se muestra en un panel lateral, sin marca. - bs::navbar::Layout::Offcanvas(panel) => { - (button(cx, TOGGLE_OFFCANVAS, &id_content)) - (panel.render_panel(cx, &id_content, &items)) - }, + // Barra con marca a la izquierda y contenido en un panel lateral. + bs::navbar::Layout::OffcanvasBrandLeft(brand, panel) => { + (brand.render(cx).await) + (button(cx, TOGGLE_OFFCANVAS, &id_content)) + (panel.render_panel(cx, &id_content, &items)) + }, - // Barra con marca a la izquierda y contenido en un panel lateral. - bs::navbar::Layout::OffcanvasBrandLeft(brand, panel) => { - (brand.render(cx).await) - (button(cx, TOGGLE_OFFCANVAS, &id_content)) - (panel.render_panel(cx, &id_content, &items)) - }, - - // Barra con contenido en un panel lateral y marca a la derecha. - bs::navbar::Layout::OffcanvasBrandRight(brand, panel) => { - (button(cx, TOGGLE_OFFCANVAS, &id_content)) - (brand.render(cx).await) - (panel.render_panel(cx, &id_content, &items)) - }, - } + // Barra con contenido en un panel lateral y marca a la derecha. + bs::navbar::Layout::OffcanvasBrandRight(brand, panel) => { + (button(cx, TOGGLE_OFFCANVAS, &id_content)) + (brand.render(cx).await) + (panel.render_panel(cx, &id_content, &items)) + }, } } })