diff --git a/assets/scss/basic.scss b/assets/scss/basic.scss index 370f8fc3..ccf728c9 100644 --- a/assets/scss/basic.scss +++ b/assets/scss/basic.scss @@ -14,9 +14,6 @@ @use "basic/root"; @use "basic/base"; -// Accent colors shared by the components that take one (`accent-` classes). -@use "basic/accent"; - // Components, in alphabetical order. `buttons` must go before `dropdown` and `nav`, see the notes // in `basic/_buttons.scss`. @use "basic/badge"; @@ -28,7 +25,6 @@ @use "basic/dialog"; @use "basic/dropdown"; @use "basic/form"; -@use "basic/icon"; @use "basic/image"; @use "basic/list-filter"; @use "basic/list-view"; @@ -37,7 +33,6 @@ @use "basic/navbar"; @use "basic/pager"; @use "basic/table"; -@use "basic/tile"; // Theme regions. @use "basic/regions"; diff --git a/assets/scss/basic/_accent.scss b/assets/scss/basic/_accent.scss deleted file mode 100644 index 9b92dc85..00000000 --- a/assets/scss/basic/_accent.scss +++ /dev/null @@ -1,16 +0,0 @@ -// Accent colors (`Accent`): every component that takes one adds the same `accent-` class, -// which sets --val-color--accent to the tone of the theme for that color (`_root.scss`). The -// styles of each component only read that variable. -.accent-blue { --val-color--accent: var(--val-color--blue); } -.accent-indigo { --val-color--accent: var(--val-color--indigo); } -.accent-purple { --val-color--accent: var(--val-color--purple); } -.accent-magenta { --val-color--accent: var(--val-color--magenta); } -.accent-pink { --val-color--accent: var(--val-color--pink); } -.accent-red { --val-color--accent: var(--val-color--red); } -.accent-orange { --val-color--accent: var(--val-color--orange); } -.accent-yellow { --val-color--accent: var(--val-color--yellow); } -.accent-lime { --val-color--accent: var(--val-color--lime); } -.accent-green { --val-color--accent: var(--val-color--green); } -.accent-teal { --val-color--accent: var(--val-color--teal); } -.accent-cyan { --val-color--accent: var(--val-color--cyan); } -.accent-gray { --val-color--accent: var(--val-color--gray); } diff --git a/assets/scss/basic/_icon.scss b/assets/scss/basic/_icon.scss deleted file mode 100644 index 4bb5be8d..00000000 --- a/assets/scss/basic/_icon.scss +++ /dev/null @@ -1,57 +0,0 @@ -// Inline SVG icons (`Icon`) sit on the text baseline like a glyph of the surrounding font. -svg.icon { - flex-shrink: 0; - vertical-align: -0.125em; -} - -// Color of an icon with an intent (`Icon::with_intent()`). -.icon-primary { color: var(--val-color--primary); } -.icon-neutral { color: var(--val-color--secondary); } -.icon-info { color: var(--val-color--info); } -.icon-success { color: var(--val-color--success); } -.icon-warning { color: var(--val-color--warning); } -.icon-severe { color: var(--val-color--danger); } - -// Icons of menu items (`with_icon_start()`/`with_icon_end()` of `nav::Item` and `dropdown::Item`). -// In a row of links, each icon keeps its distance from the label. -.nav-link > .icon-start { - margin-inline-end: 0.5em; -} -.nav-link > .icon-end { - margin-inline-start: 0.5em; -} - -// In a vertical list (dropdown menu or vertical nav) with any icon, every item is a flex row: the -// end icon goes to the edge, and an item without an icon on one side keeps that space empty, so -// that all the labels line up. The `:has()` selectors look only at the items of this list, not at -// those of a nested menu. -.dropdown-menu:has(> li > * > .icon) > li > :is(.dropdown-item, .dropdown-item-text), -.nav-vertical:has(> li > .nav-link > .icon) > li > .nav-link { - display: flex; - align-items: center; - gap: 0.5em; - - > .icon-start, - > .icon-end { - margin: 0; - } - > .icon-end { - margin-inline-start: auto; - } -} -.dropdown-menu:has(> li > * > .icon-start) > li > :is(.dropdown-item, .dropdown-item-text), -.nav-vertical:has(> li > .nav-link > .icon-start) > li > .nav-link { - &:not(:has(> .icon-start))::before { - content: ""; - flex: 0 0 1em; - } -} -// The toggle of a dropdown already shows its arrow at the end. -.dropdown-menu:has(> li > * > .icon-end) > li > :is(.dropdown-item, .dropdown-item-text), -.nav-vertical:has(> li > .nav-link > .icon-end) > li > .nav-link:not(.dropdown-toggle) { - &:not(:has(> .icon-end))::after { - content: ""; - flex: 0 0 1em; - margin-inline-start: auto; - } -} diff --git a/assets/scss/basic/_root.scss b/assets/scss/basic/_root.scss index 7e1953b5..c767a750 100644 --- a/assets/scss/basic/_root.scss +++ b/assets/scss/basic/_root.scss @@ -17,20 +17,6 @@ --val-color--info: #0dcaf0; --val-color--warning: #ffc107; --val-color--danger: #dc3545; - // Accent Colors (`Accent`): no meaning, only to tell elements apart - --val-color--blue: #0d6efd; - --val-color--indigo: #6610f2; - --val-color--purple: #6f42c1; - --val-color--magenta: #c026d3; - --val-color--pink: #d63384; - --val-color--red: #dc3545; - --val-color--orange: #fd7e14; - --val-color--yellow: #ffc107; - --val-color--lime: #65a30d; - --val-color--green: #198754; - --val-color--teal: #20c997; - --val-color--cyan: #0dcaf0; - --val-color--gray: #6c757d; // Other Colors --val-color--bg: #fafafa; --val-color--bg--muted: #dee2e6; diff --git a/assets/scss/basic/_tile.scss b/assets/scss/basic/_tile.scss deleted file mode 100644 index f6bb2175..00000000 --- a/assets/scss/basic/_tile.scss +++ /dev/null @@ -1,105 +0,0 @@ -// Access tiles (Tile): a large link with white text over its accent color and, when it has one, a -// blurred background image. The image goes below a veil of the accent color (from translucent to -// darkened), so the text keeps its contrast whatever the picture. The icon stays at the top and the -// texts at the bottom (also without an icon), so the icons of a row line up whatever the length of -// the descriptions. -.tile { - // The accent of the tile (`accent-`, see `_accent.scss`), with a fallback. - --tile-accent: var(--val-color--accent, var(--val-color--primary)); - position: relative; - isolation: isolate; - display: flex; - flex-direction: column; - min-height: 11rem; - padding: 1.5rem; - overflow: hidden; - color: #fff; - text-decoration: none; - background-color: var(--tile-accent); - border-radius: 0.75rem; - box-shadow: 0 0.25rem 0.75rem rgb(0 0 0 / 15%); - transition: transform 0.2s ease, box-shadow 0.2s ease; -} - -.tile::before { - content: ""; - position: absolute; - inset: 0; - z-index: -1; - background: linear-gradient( - 135deg, - color-mix(in srgb, var(--tile-accent) 75%, transparent), - color-mix(in srgb, var(--tile-accent) 55%, #000) - ); -} - -// Scaled up a little so that the blur does not leave light edges. -.tile > .tile-image { - position: absolute; - inset: 0; - z-index: -2; - width: 100%; - height: 100%; - object-fit: cover; - filter: blur(3px) saturate(80%); - transform: scale(1.08); - transition: transform 0.4s ease; -} - -.tile:hover, -.tile:focus-visible { - color: #fff; - transform: translateY(-0.25rem); - box-shadow: 0 0.75rem 1.5rem rgb(0 0 0 / 25%); -} - -.tile:hover > .tile-image, -.tile:focus-visible > .tile-image { - transform: scale(1.15); -} - -.tile:focus-visible { - outline: 3px solid var(--tile-accent); - outline-offset: 3px; -} - -.tile-body { - flex-grow: 1; - display: flex; - flex-direction: column; - justify-content: flex-end; - gap: 0.25rem; - text-shadow: 0 1px 3px rgb(0 0 0 / 40%); -} - -.tile-icon { - margin-bottom: auto; - padding-bottom: 1rem; - font-size: 2.5rem; - line-height: 1; -} - -.tile-title { - font-size: 1.375rem; - font-weight: 600; - line-height: 1.2; -} - -.tile-description { - font-size: 0.9375rem; - opacity: 0.9; -} - -// Disabled (`Tile::with_disabled()`): dimmed, without a link and without reacting to the pointer. -.tile.disabled { - pointer-events: none; - opacity: 0.65; - box-shadow: none; -} - -@media (prefers-reduced-motion: reduce) { - .tile, - .tile > .tile-image { - transition: none; - } -} diff --git a/examples/basic-nav.rs b/examples/basic-nav.rs index b26d7599..ba875b57 100644 --- a/examples/basic-nav.rs +++ b/examples/basic-nav.rs @@ -24,7 +24,7 @@ impl Extension for NavDemo { .with_item(dropdown::Item::header(Lc::n("Danger zone"))) .with_item(dropdown::Item::button(Lc::n("Reset settings"))), )) - .with_item(nav::Item::link(Lc::n("Disabled"), "#").with_disabled(true)); + .with_item(nav::Item::link_disabled(Lc::n("Disabled"), "#")); let user_menu = Dropdown::new() .with_title(Lc::n("Account")) diff --git a/examples/basic-navbar.rs b/examples/basic-navbar.rs index 46f29207..544d3d44 100644 --- a/examples/basic-navbar.rs +++ b/examples/basic-navbar.rs @@ -38,7 +38,10 @@ impl Extension for NavbarDemo { )), )) .with_item(nav::Item::link(Lc::t("navbar_active", &LOC), "/active").with_active(true)) - .with_item(nav::Item::link(Lc::t("navbar_disabled", &LOC), "#").with_disabled(true)); + .with_item(nav::Item::link_disabled( + Lc::t("navbar_disabled", &LOC), + "#", + )); let navbar = Navbar::brand_left(brand).with_item(navbar::Item::nav(main_nav)); diff --git a/examples/locale/en-US/theme-showcase.ftl b/examples/locale/en-US/theme-showcase.ftl index a33bb791..2a79de06 100644 --- a/examples/locale/en-US/theme-showcase.ftl +++ b/examples/locale/en-US/theme-showcase.ftl @@ -65,63 +65,6 @@ showcase_empty_table = A table without rows shows its message: showcase_block_buttons = Buttons -showcase_block_icons = Icons -showcase_icons_sizes = - Icons of the example's own set, the same with any theme, and of PageTop - (icon::Core), which each theme may replace with its own. Their size follows the - font size and their color, the intent: -showcase_icons_cards = Status cards with a large icon: -showcase_card_switch = Living room switch -showcase_card_outlet = Night outlet -showcase_card_battery = Server battery -showcase_card_active = Activated -showcase_card_low = Low power -showcase_icons_toolbar = - Icon-only buttons; the icon label names the button and shows up on hover: -showcase_tag = Tag -showcase_view = View -showcase_comment_action = Comment -showcase_notify = Notify -showcase_pin = Pin -showcase_hide = Hide -showcase_align_left = Align left -showcase_align_center = Center -showcase_align_right = Align right -showcase_align_justify = Justify -showcase_bold = Bold -showcase_italic = Italic -showcase_underline = Underline -showcase_icons_buttons = - Buttons with icon and text, with the icon at the start, at the end or on both sides: -showcase_new = New -showcase_filter = Filter -showcase_insert_image = Insert image -showcase_save = Save -showcase_discard = Discard -showcase_next = Next -showcase_move_to = Move to -showcase_icons_menus = - Menus with icons: options without an icon keep their space and the end icon sits at the edge. -showcase_nav_start = Get started -showcase_nav_styles = Styles -showcase_nav_grid = Grid -showcase_nav_folders = Folders -showcase_nav_templates = Templates -showcase_actions = Actions -showcase_duplicate = Duplicate -showcase_icons_table = Icons in a table: -showcase_col_name = Name -showcase_col_type = Type -showcase_type_folder = Folder -showcase_type_document = Document -showcase_delete = Delete - -showcase_block_tiles = Access tiles -showcase_tile_image = With a blurred background image under its color -showcase_tile_color = Only with its accent color -showcase_tile_no_icon = Without an icon -showcase_tile_disabled = Disabled: dimmed and without a link - 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. diff --git a/examples/locale/es-ES/theme-showcase.ftl b/examples/locale/es-ES/theme-showcase.ftl index d33c23d7..0ddce351 100644 --- a/examples/locale/es-ES/theme-showcase.ftl +++ b/examples/locale/es-ES/theme-showcase.ftl @@ -65,63 +65,6 @@ showcase_empty_table = Una tabla sin filas muestra su mensaje: showcase_block_buttons = Botones -showcase_block_icons = Iconos -showcase_icons_sizes = - Iconos del conjunto propio del ejemplo, iguales con cualquier tema, y de PageTop - (icon::Core), que cada tema puede sustituir por los suyos. Su tamaño sigue al de la - fuente y su color, a la intención: -showcase_icons_cards = Tarjetas de estado con un icono grande: -showcase_card_switch = Interruptor del salón -showcase_card_outlet = Enchufe nocturno -showcase_card_battery = Batería del servidor -showcase_card_active = Activado -showcase_card_low = Carga baja -showcase_icons_toolbar = - Botones sólo con icono; la etiqueta del icono da nombre al botón y aparece al pasar por encima: -showcase_tag = Etiquetar -showcase_view = Ver -showcase_comment_action = Comentar -showcase_notify = Avisar -showcase_pin = Fijar -showcase_hide = Ocultar -showcase_align_left = Alinear a la izquierda -showcase_align_center = Centrar -showcase_align_right = Alinear a la derecha -showcase_align_justify = Justificar -showcase_bold = Negrita -showcase_italic = Cursiva -showcase_underline = Subrayado -showcase_icons_buttons = - Botones con icono y texto, con el icono al principio, al final o a los dos lados: -showcase_new = Nuevo -showcase_filter = Filtrar -showcase_insert_image = Insertar imagen -showcase_save = Guardar -showcase_discard = Descartar -showcase_next = Siguiente -showcase_move_to = Mover a -showcase_icons_menus = - Menús con iconos: las opciones sin icono dejan su hueco y el icono final va junto al borde. -showcase_nav_start = Primeros pasos -showcase_nav_styles = Estilos -showcase_nav_grid = Rejilla -showcase_nav_folders = Carpetas -showcase_nav_templates = Plantillas -showcase_actions = Acciones -showcase_duplicate = Duplicar -showcase_icons_table = Iconos en una tabla: -showcase_col_name = Nombre -showcase_col_type = Tipo -showcase_type_folder = Carpeta -showcase_type_document = Documento -showcase_delete = Eliminar - -showcase_block_tiles = Recuadros de acceso -showcase_tile_image = Con una imagen de fondo difuminada bajo su color -showcase_tile_color = Sólo con su color de acento -showcase_tile_no_icon = Sin icono -showcase_tile_disabled = Deshabilitado: atenuado y sin enlace - 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. diff --git a/examples/navbar-menus.rs b/examples/navbar-menus.rs index e0c0122e..249669b0 100644 --- a/examples/navbar-menus.rs +++ b/examples/navbar-menus.rs @@ -106,14 +106,15 @@ fn menus_block() -> Block { )) .with_item(dropdown::Item::divider()) .with_item(dropdown::Item::label(Lc::t("menus_item_label", &LOC))) - .with_item( - dropdown::Item::link(Lc::t("menus_item_disabled", &LOC), "#") - .with_disabled(true), - ), + .with_item(dropdown::Item::link_disabled( + Lc::t("menus_item_disabled", &LOC), + "#", + )), )) - .with_item( - nav::Item::link(Lc::t("menus_item_disabled", &LOC), "#").with_disabled(true), - ), + .with_item(nav::Item::link_disabled( + Lc::t("menus_item_disabled", &LOC), + "#", + )), )) .with_item(navbar::Item::nav( Nav::new() @@ -685,7 +686,10 @@ fn demo_nav() -> Nav { "/something", )), )) - .with_item(nav::Item::link(Lc::t("menus_item_disabled", &LOC), "#").with_disabled(true)) + .with_item(nav::Item::link_disabled( + Lc::t("menus_item_disabled", &LOC), + "#", + )) } fn is_bootsier() -> bool { diff --git a/examples/theme-showcase.rs b/examples/theme-showcase.rs index 6f7e682e..c4dedc7d 100644 --- a/examples/theme-showcase.rs +++ b/examples/theme-showcase.rs @@ -24,46 +24,41 @@ impl Extension for ThemeShowcase { // 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. - // Algunas opciones llevan icono; en el desplegable, las que no lo tienen dejan su hueco. 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_icon_start(Icon::with(icon::Core::Home)), - ) + .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_icon_start(Icon::with(ShowcaseIcon::Pencil)), - ) + .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_icon_start(Icon::with(ShowcaseIcon::Chat)) - .with_icon_end(Icon::with(icon::Core::ChevronRight)), - ) - .with_item( - dropdown::Item::link(Lc::t("showcase_menu_disabled", &LOC), "#") - .with_disabled(true), - ), + .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_icon_end(Icon::with(ShowcaseIcon::External)), - ) - .with_item( - nav::Item::link(Lc::t("showcase_menu_disabled", &LOC), "#").with_disabled(true), - ); + .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). @@ -96,8 +91,6 @@ async fn theme_showcase(request: HttpRequest) -> Result { .with_child(checks_block()) .with_child(tables_block()) .with_child(buttons_block()) - .with_child(icons_block()) - .with_child(tiles_block()) .with_child(misc_block()); // Un mensaje de cada nivel, que muestra el listado del bloque de tablas entre su botón y la @@ -453,476 +446,6 @@ fn buttons(outline: bool) -> Flex { row } -// Conjunto de iconos propio del ejemplo, para mostrar cómo se integra uno: basta implementar -// `From for icon::Source` para pasarlos a `Icon::with()`. Son SVG en línea y se ven -// igual con cualquier tema, a diferencia de los de `icon::Core`, que cada tema puede sustituir por -// los de su propio conjunto (Bootsier, por los de Bootstrap Icons). -#[derive(Clone, Copy)] -enum ShowcaseIcon { - AlertCircle, - AlignCenter, - AlignJustify, - AlignLeft, - AlignRight, - Bell, - Bold, - Chat, - CheckCircle, - Eye, - EyeOff, - External, - File, - Filter, - Folder, - Image, - Italic, - Lightbulb, - Pencil, - Pin, - Plug, - Search, - Tag, - Underline, -} - -impl From for icon::Source { - fn from(icon: ShowcaseIcon) -> Self { - use ShowcaseIcon::*; - - let shapes = match icon { - AlertCircle => html! { - circle cx="8" cy="8" r="6.5" {} - path d="M8 4.75v3.75M8 11.25v.01" {} - }, - AlignCenter => html! { path d="M2 3.5h12M4 6.5h8M2 9.5h12M4 12.5h8" {} }, - AlignJustify => html! { path d="M2 3.5h12M2 6.5h12M2 9.5h12M2 12.5h12" {} }, - AlignLeft => html! { path d="M2 3.5h12M2 6.5h8M2 9.5h12M2 12.5h8" {} }, - AlignRight => html! { path d="M2 3.5h12M6 6.5h8M2 9.5h12M6 12.5h8" {} }, - Bell => html! { path d="M4 11.5V7a4 4 0 0 1 8 0v4.5l1 1H3zM6.5 14.5h3" {} }, - Bold => html! { - path d="M4.5 2.5H9a2.75 2.75 0 0 1 0 5.5H4.5zM4.5 8h5a2.75 2.75 0 0 1 0 5.5h-5z" {} - }, - Chat => html! { path d="M2.5 3.5h11V11H7l-3 2.5V11H2.5z" {} }, - CheckCircle => html! { - circle cx="8" cy="8" r="6.5" {} - path d="M5 8.25l2 2 4-4" {} - }, - Eye => html! { - path d="M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z" {} - circle cx="8" cy="8" r="2" {} - }, - EyeOff => html! { - path d="M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z" {} - circle cx="8" cy="8" r="2" {} - path d="M2.5 2.5l11 11" {} - }, - External => html! { path d="M9 2.5h4.5V7M13.5 2.5l-6 6M11.5 9.5v4h-9v-9h4" {} }, - File => html! { path d="M3.5 1.5h6l3 3v10h-9zM9.5 1.5v3h3" {} }, - Filter => html! { path d="M2 3h12l-4.5 5.5V13l-3-1.5v-3z" {} }, - Folder => html! { path d="M1.5 3.5H6L7.5 5h7v7.5h-13z" {} }, - Image => html! { - rect x="1.5" y="2.5" width="13" height="11" rx="1.5" {} - circle cx="10.5" cy="6" r="1.25" {} - path d="M1.5 11.5l4-4 3 3 2-2 4 4" {} - }, - Italic => html! { path d="M7 2.5h5M4 13.5h5M10 2.5l-4 11" {} }, - Lightbulb => html! { - path d="M6 11c0-.9-.4-1.5-1.2-2.3a4.25 4.25 0 1 1 6.4 0C10.4 9.5 10 10.1 10 11" {} - path d="M6 11h4M6.75 14h2.5" {} - }, - Pencil => html! { path d="M10.5 2.5l3 3L6 13H3v-3zM9 4l3 3" {} }, - Pin => html! { path d="M6 1.5h4M7 1.5v4L4.5 8.5h7L9 5.5v-4M8 8.5v6" {} }, - Plug => { - html! { path d="M5.5 1.5v3M10.5 1.5v3M3.5 4.5h9V7a4.5 4.5 0 0 1-9 0zM8 11.5v3" {} } - } - Search => html! { - circle cx="7" cy="7" r="4.5" {} - path d="M10.5 10.5l3.5 3.5" {} - }, - Tag => html! { - path d="M2.5 2.5h5l6 6-5 5-6-6z" {} - circle cx="5.5" cy="5.5" r="1" {} - }, - Underline => html! { path d="M4.5 2.5V7a3.5 3.5 0 0 0 7 0V2.5M3 14.5h10" {} }, - }; - icon::Source::svg( - "0 0 16 16", - html! { - g - fill="none" - stroke="currentColor" - stroke-width="1.5" - stroke-linecap="round" - stroke-linejoin="round" - { - (shapes) - } - }, - ) - } -} - -// Iconos en sus distintos usos: tamaños y colores, tarjetas de estado, barras de botones sólo con -// icono, botones con icono y texto, y una tabla. Mezcla el conjunto propio con el de PageTop. -fn icons_block() -> Block { - use ShowcaseIcon::*; - - let row = || { - Flex::new() - .with_wrap(flex::Behavior::Wrap) - .with_align(align::Items::Center) - .with_gap(align::Gap::Both(UnitValue::RelRem(0.75))) - .with_prop(Margin::new().with_bottom(UnitValue::RelRem(1.5))) - }; - let caption = |key: &'static str| { - Html::with(move |cx| { - html! { - p { (Lc::t(key, &LOC).using(cx)) } - } - }) - }; - // Botón sólo con icono: la etiqueta del icono es el nombre accesible del botón, y el texto - // emergente la muestra al pasar por encima. - let icon_button = |source: icon::Source, key: &'static str, style: button::Style| { - Button::plain(Lc::none()) - .with_style(style) - .with_title(Lc::t(key, &LOC)) - .with_icon_start(Icon::with(source).with_label(Lc::t(key, &LOC))) - }; - - // El tamaño sigue al de la fuente; el color, a la intención. - let mut sizes = row(); - for size in [1.0, 1.5, 2.0, 2.5, 3.0] { - sizes = sizes.with_child(Icon::with(Lightbulb).with_size(UnitValue::RelRem(size))); - } - let mut colors = row(); - for (source, intent) in [ - (icon::Source::from(Pin), Intent::Primary), - (Bell.into(), Intent::Neutral), - (Chat.into(), Intent::Info), - (CheckCircle.into(), Intent::Success), - (AlertCircle.into(), Intent::Warning), - (icon::Core::Close.into(), Intent::Severe), - ] { - colors = colors.with_child( - Icon::with(source) - .with_size(UnitValue::RelRem(1.5)) - .with_intent(intent), - ); - } - - // Tarjetas de estado: un icono grande de color, el nombre del aparato y su estado. - let card = |source: ShowcaseIcon, intent: Intent, title: &'static str, badge: Badge| { - Flex::new() - .with_direction(flex::Direction::Column) - .with_align(align::Items::Start) - .with_gap(align::Gap::Both(UnitValue::RelRem(0.5))) - .with_prop(Margin::new().with_bottom(UnitValue::RelRem(1.5))) - .with_child( - Icon::with(source) - .with_size(UnitValue::RelRem(2.5)) - .with_intent(intent), - ) - .with_child(Lc::t(title, &LOC)) - .with_child(badge) - }; - let cards = columns() - .with_child(card( - Lightbulb, - Intent::Warning, - "showcase_card_switch", - Badge::success(Lc::t("showcase_card_active", &LOC)), - )) - .with_child(card( - Plug, - Intent::Primary, - "showcase_card_outlet", - Badge::info(Lc::n("32 %")), - )) - .with_child(card( - AlertCircle, - Intent::Severe, - "showcase_card_battery", - Badge::severe(Lc::t("showcase_card_low", &LOC)), - )); - - // Barra de acciones de una nota, con botones de estilo enlace. Su propio relleno ya los separa, - // así que la fila no añade hueco entre ellos. - let mut actions = row().with_gap(align::Gap::Both(UnitValue::Zero)); - for (source, key) in [ - (Pencil, "showcase_edit"), - (Tag, "showcase_tag"), - (Eye, "showcase_view"), - (Chat, "showcase_comment_action"), - (Bell, "showcase_notify"), - (Pin, "showcase_pin"), - (EyeOff, "showcase_hide"), - ] { - actions = actions.with_child(icon_button(source.into(), key, button::Style::Link)); - } - - // Grupos de formato de texto, con botones pequeños de contorno. - let format_group = |items: &[(ShowcaseIcon, &'static str)]| { - let mut group = Flex::new().with_gap(align::Gap::Both(UnitValue::RelRem(0.25))); - for (source, key) in items { - group = group.with_child( - icon_button( - (*source).into(), - key, - button::Style::Outline(Intent::Neutral), - ) - .with_size(button::Size::Small), - ); - } - group - }; - let format = row() - .with_child(format_group(&[ - (AlignLeft, "showcase_align_left"), - (AlignCenter, "showcase_align_center"), - (AlignRight, "showcase_align_right"), - (AlignJustify, "showcase_align_justify"), - ])) - .with_child(format_group(&[ - (Bold, "showcase_bold"), - (Italic, "showcase_italic"), - (Underline, "showcase_underline"), - ])); - - // Botones con icono y texto: al principio, al final o a los dos lados de la etiqueta. - let mut buttons = row(); - for (start, key, end, style) in [ - ( - Some(icon::Source::from(icon::Core::Plus)), - "showcase_new", - None::, - button::Style::Solid(Intent::Primary), - ), - ( - Some(Search.into()), - "showcase_search", - None, - button::Style::Outline(Intent::Primary), - ), - ( - Some(Filter.into()), - "showcase_filter", - None, - button::Style::Outline(Intent::Neutral), - ), - ( - Some(Image.into()), - "showcase_insert_image", - None, - button::Style::Outline(Intent::Neutral), - ), - ( - Some(icon::Core::Check.into()), - "showcase_save", - None, - button::Style::Solid(Intent::Success), - ), - ( - Some(icon::Core::Close.into()), - "showcase_discard", - None, - button::Style::Outline(Intent::Severe), - ), - ( - None, - "showcase_next", - Some(icon::Core::ChevronRight.into()), - button::Style::Outline(Intent::Primary), - ), - ( - Some(Folder.into()), - "showcase_move_to", - Some(icon::Core::ChevronDown.into()), - button::Style::Outline(Intent::Neutral), - ), - ] { - buttons = buttons.with_child( - Button::plain(Lc::t(key, &LOC)) - .with_style(style) - .with_icon_start(start.map(Icon::with)) - .with_icon_end(end.map(Icon::with)), - ); - } - - // Menú vertical, como una barra lateral, y menú desplegable de acciones. Las opciones sin icono - // dejan su hueco para que las etiquetas queden alineadas; el icono final va junto al borde. - let sidebar = Nav::new() - .with_layout(nav::Layout::Vertical) - .with_prop(FlexItem::new().with_size(flex::ItemSize::Custom(UnitValue::RelRem(14.0)))) - .with_item( - nav::Item::link(Lc::t("showcase_nav_start", &LOC), "#") - .with_icon_start(Icon::with(Lightbulb)), - ) - .with_item( - nav::Item::link(Lc::t("showcase_nav_styles", &LOC), "#") - .with_icon_start(Icon::with(Pencil)), - ) - .with_item(nav::Item::link(Lc::t("showcase_nav_grid", &LOC), "#")) - .with_item( - nav::Item::link(Lc::t("showcase_nav_folders", &LOC), "#") - .with_icon_start(Icon::with(Folder)) - .with_icon_end(Icon::with(icon::Core::ChevronRight)), - ) - .with_item( - nav::Item::link(Lc::t("showcase_nav_templates", &LOC), "#") - .with_disabled(true) - .with_icon_start(Icon::with(File)) - .with_icon_end(Icon::with(Pin)), - ); - let actions_menu = Dropdown::new() - .with_title(Lc::t("showcase_actions", &LOC)) - .with_button_style(button::Style::Outline(Intent::Neutral)) - .with_item( - dropdown::Item::button(Lc::t("showcase_edit", &LOC)) - .with_icon_start(Icon::with(Pencil)), - ) - .with_item( - dropdown::Item::button(Lc::t("showcase_tag", &LOC)).with_icon_start(Icon::with(Tag)), - ) - .with_item(dropdown::Item::button(Lc::t("showcase_duplicate", &LOC))) - .with_item( - dropdown::Item::button(Lc::t("showcase_pin", &LOC)) - .with_icon_start(Icon::with(Pin)) - .with_icon_end(Icon::with(icon::Core::Check)), - ) - .with_item(dropdown::Item::divider()) - .with_item( - dropdown::Item::button(Lc::t("showcase_delete", &LOC)) - .with_icon_start(Icon::with(icon::Core::Close).with_intent(Intent::Severe)), - ); - let menus = Flex::new() - .with_wrap(flex::Behavior::Wrap) - .with_align(align::Items::Start) - .with_gap(align::Gap::Both(UnitValue::RelRem(2.0))) - .with_prop(Margin::new().with_bottom(UnitValue::RelRem(1.5))) - .with_child(sidebar) - .with_child(actions_menu); - - // Tabla con el tipo de cada fila en un icono y las acciones como botones sólo con icono. - let mut files = Table::new() - .with_column(Lc::t("showcase_col_name", &LOC)) - .with_column(Lc::t("showcase_col_type", &LOC)) - .with_column(Lc::t("showcase_col_actions", &LOC)); - for (name, folder) in [ - ("Backgrounds", true), - ("Shadows", true), - ("Document.txt", false), - ("Projects.draft", false), - ] { - let (source, kind) = match folder { - true => (Folder, "showcase_type_folder"), - false => (File, "showcase_type_document"), - }; - files.alter_row( - table::Row::new() - .with_cell(table::Cell::new( - Flex::new() - .with_align(align::Items::Center) - .with_gap(align::Gap::Both(UnitValue::RelRem(0.5))) - .with_child(Icon::with(source).with_intent(Intent::Neutral)) - .with_child(Lc::n(name)), - )) - .with_cell(Lc::t(kind, &LOC)) - .with_cell(table::Cell::new( - Flex::new() - .with_child(icon_button( - Eye.into(), - "showcase_view", - button::Style::Link, - )) - .with_child(icon_button( - Pencil.into(), - "showcase_edit", - button::Style::Link, - )) - .with_child(icon_button( - icon::Core::Close.into(), - "showcase_delete", - button::Style::Link, - )), - )), - ); - } - - Block::new() - .with_title(Lc::t("showcase_block_icons", &LOC)) - .with_child(caption("showcase_icons_sizes")) - .with_child(sizes) - .with_child(colors) - .with_child(caption("showcase_icons_cards")) - .with_child(cards) - .with_child(caption("showcase_icons_toolbar")) - .with_child(actions) - .with_child(format) - .with_child(caption("showcase_icons_buttons")) - .with_child(buttons) - .with_child(caption("showcase_icons_menus")) - .with_child(menus) - .with_child(caption("showcase_icons_table")) - .with_child(files) -} - -// Un recuadro de acceso por color de acento, en la rejilla habitual de una portada (una, dos y tres -// columnas). Alternan los casos: con la imagen de fondo que trae PageTop para `Intro` (difuminada -// bajo el color) o sólo con el color, y con o sin descripción. Al final, uno sin icono y otro -// deshabilitado. -fn tiles_block() -> Block { - use Accent::*; - - let tracks = |n| grid::Tracks::repeat(n, grid::AxisTrack::Fraction(1.0)); - let mut grid = Grid::new() - .with_columns(tracks(1)) - .with_columns_at(Breakpoint::Md, tracks(2)) - .with_columns_at(Breakpoint::Lg, tracks(3)) - .with_gap(align::Gap::Both(UnitValue::RelRem(1.5))); - let accents = [ - (Blue, "Blue", Icon::with(ShowcaseIcon::Folder)), - (Orange, "Orange", Icon::with(ShowcaseIcon::Image)), - (Green, "Green", Icon::with(ShowcaseIcon::CheckCircle)), - (Purple, "Purple", Icon::with(ShowcaseIcon::Lightbulb)), - (Red, "Red", Icon::with(ShowcaseIcon::AlertCircle)), - (Teal, "Teal", Icon::with(ShowcaseIcon::Tag)), - (Indigo, "Indigo", Icon::with(ShowcaseIcon::Chat)), - (Pink, "Pink", Icon::with(ShowcaseIcon::Bell)), - (Yellow, "Yellow", Icon::with(ShowcaseIcon::Pin)), - (Cyan, "Cyan", Icon::with(ShowcaseIcon::Plug)), - (Lime, "Lime", Icon::with(ShowcaseIcon::Eye)), - (Magenta, "Magenta", Icon::with(ShowcaseIcon::Search)), - ]; - for (i, (accent, name, icon)) in accents.into_iter().enumerate() { - let tile = Tile::link(Lc::n(name), "#") - .with_icon(icon) - .with_accent(accent); - grid = grid.with_child(match i % 3 { - 0 => tile - .with_description(Lc::t("showcase_tile_image", &LOC)) - .with_image(image::Source::plain("/pagetop/img/intro-header-sm.jpg")), - 1 => tile.with_description(Lc::t("showcase_tile_color", &LOC)), - _ => tile, - }); - } - grid = grid.with_child( - Tile::link(Lc::n("Gray"), "#") - .with_description(Lc::t("showcase_tile_no_icon", &LOC)) - .with_accent(Gray), - ); - grid = grid.with_child( - Tile::link(Lc::n("Disabled"), "#") - .with_description(Lc::t("showcase_tile_disabled", &LOC)) - .with_icon(Icon::with(ShowcaseIcon::EyeOff)) - .with_disabled(true), - ); - - Block::new() - .with_title(Lc::t("showcase_block_tiles", &LOC)) - .with_child(grid) -} - // Enlaces, insignias, paginación y mensajes, que también toman los colores del tema. fn misc_block() -> Block { let mut badges = Flex::new() diff --git a/extensions/pagetop-bootsier/assets/_bootsier-custom.scss b/extensions/pagetop-bootsier/assets/_bootsier-custom.scss index ab8427ce..9ac5e0fd 100644 --- a/extensions/pagetop-bootsier/assets/_bootsier-custom.scss +++ b/extensions/pagetop-bootsier/assets/_bootsier-custom.scss @@ -226,63 +226,6 @@ fieldset > legend { @extend .alert-danger; } -// Inline SVG icons (`Icon`) sit on the text baseline like the Bootstrap Icons glyphs. -svg.icon { - flex-shrink: 0; - vertical-align: -0.125em; -} - -// Color of an icon with an intent (`Icon::with_intent()`), named after the Bootsier palette. -@each $color in primary, secondary, success, info, warning, danger { - .icon-#{$color} { - color: var(--bs-#{$color}); - } -} - -// Icons of menu items (`with_icon_start()`/`with_icon_end()` of `nav::Item` and `dropdown::Item`). -// In a row of links, each icon keeps its distance from the label. -.nav-link > .icon-start { - margin-inline-end: 0.5em; -} -.nav-link > .icon-end { - margin-inline-start: 0.5em; -} - -// In a vertical list (dropdown menu or vertical nav) with any icon, every item is a flex row: the -// end icon goes to the edge, and an item without an icon on one side keeps that space empty, so -// that all the labels line up. The `:has()` selectors look only at the items of this list, not at -// those of a nested menu. -.dropdown-menu:has(> li > * > .icon) > li > :is(.dropdown-item, .dropdown-item-text), -.nav-vertical:has(> li > .nav-link > .icon) > li > .nav-link { - display: flex; - align-items: center; - gap: 0.5em; - - > .icon-start, - > .icon-end { - margin: 0; - } - > .icon-end { - margin-inline-start: auto; - } -} -.dropdown-menu:has(> li > * > .icon-start) > li > :is(.dropdown-item, .dropdown-item-text), -.nav-vertical:has(> li > .nav-link > .icon-start) > li > .nav-link { - &:not(:has(> .icon-start))::before { - content: ""; - flex: 0 0 1em; - } -} -// The toggle of a dropdown already shows its arrow at the end. -.dropdown-menu:has(> li > * > .icon-end) > li > :is(.dropdown-item, .dropdown-item-text), -.nav-vertical:has(> li > .nav-link > .icon-end) > li > .nav-link:not(.dropdown-toggle) { - &:not(:has(> .icon-end))::after { - content: ""; - flex: 0 0 1em; - margin-inline-start: auto; - } -} - // Sort indicator on sortable table headers (`table::SortLink`), using Bootstrap Icons' // sort-up/sort-down glyphs instead of the plain triangle from basic.css. .table-sort::after { @@ -590,119 +533,3 @@ svg.icon { @extend .alert; @extend .alert-danger; } - -// Accent colors (`Accent`): every component that takes one adds the same `accent-` class, -// which sets --bootsier-accent to the Bootstrap color of the same name (lime and magenta are added -// by Bootsier, see _bootsier-variables.scss). The styles of each component only read that variable. -// Quoted: unquoted, Sass reads names such as `yellow` or `cyan` as colors, not as text. -@each $name in "blue", "indigo", "purple", "magenta", "pink", "red", "orange", "yellow", "lime", - "green", "teal", "cyan", "gray" { - .accent-#{$name} { - --bootsier-accent: var(--bs-#{$name}); - } -} - -// Access tiles (Tile): a large link with white text over its accent color and, when it has one, a -// blurred background image. The image goes below a veil of the accent color (from translucent to -// darkened), so the text keeps its contrast whatever the picture. The icon stays at the top and the -// texts at the bottom (also without an icon), so the icons of a row line up whatever the length of -// the descriptions. -.tile { - // The accent of the tile (`accent-`, see above), with a fallback. - --tile-accent: var(--bootsier-accent, var(--bs-primary)); - position: relative; - isolation: isolate; - display: flex; - flex-direction: column; - min-height: 11rem; - padding: $spacer * 1.5; - overflow: hidden; - color: $white; - text-decoration: none; - background-color: var(--tile-accent); - border-radius: var(--bs-border-radius-xl); - box-shadow: var(--bs-box-shadow-sm); - transition: transform .2s ease, box-shadow .2s ease; - - &::before { - content: ""; - position: absolute; - inset: 0; - z-index: -1; - background: linear-gradient( - 135deg, - color-mix(in srgb, var(--tile-accent) 75%, transparent), - color-mix(in srgb, var(--tile-accent) 55%, #000) - ); - } - - // Scaled up a little so that the blur does not leave light edges. - > .tile-image { - position: absolute; - inset: 0; - z-index: -2; - width: 100%; - height: 100%; - object-fit: cover; - filter: blur(3px) saturate(80%); - transform: scale(1.08); - transition: transform .4s ease; - } - - &:hover, - &:focus-visible { - color: $white; - transform: translateY(-.25rem); - box-shadow: var(--bs-box-shadow); - - > .tile-image { - transform: scale(1.15); - } - } - - &:focus-visible { - outline: 3px solid var(--tile-accent); - outline-offset: 3px; - } - - // Disabled (`Tile::with_disabled()`): dimmed, without a link and without reacting to the pointer. - &.disabled { - pointer-events: none; - opacity: $btn-disabled-opacity; - box-shadow: none; - } - - @media (prefers-reduced-motion: reduce) { - &, - > .tile-image { - transition: none; - } - } -} - -.tile-body { - flex-grow: 1; - display: flex; - flex-direction: column; - justify-content: flex-end; - gap: $spacer * .25; - text-shadow: 0 1px 3px rgba($black, .4); -} - -.tile-icon { - margin-bottom: auto; - padding-bottom: $spacer; - font-size: 2.5rem; - line-height: 1; -} - -.tile-title { - font-size: $h4-font-size; - font-weight: $font-weight-semibold; - line-height: $headings-line-height; -} - -.tile-description { - font-size: .9375rem; - opacity: .9; -} diff --git a/extensions/pagetop-bootsier/assets/_bootsier-variables.scss b/extensions/pagetop-bootsier/assets/_bootsier-variables.scss index 92a0a38c..76d6117e 100644 --- a/extensions/pagetop-bootsier/assets/_bootsier-variables.scss +++ b/extensions/pagetop-bootsier/assets/_bootsier-variables.scss @@ -22,11 +22,6 @@ $info: #4cb5c4; // Teal of the screens in the Intro illustration. $light: #fff1db; // Cream of the Intro blocks. $dark: #1a202c; // Text color of Intro. -// Accent colors (`Accent`) that Bootstrap lacks, added to its $colors map in bootsier.scss so that -// they get their own --bs-lime and --bs-magenta like the others. Same tones as in Basic. -$lime: #65a30d; -$magenta: #c026d3; - // 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 diff --git a/extensions/pagetop-bootsier/assets/bootsier.scss b/extensions/pagetop-bootsier/assets/bootsier.scss index fb6934da..79ff1e3f 100644 --- a/extensions/pagetop-bootsier/assets/bootsier.scss +++ b/extensions/pagetop-bootsier/assets/bootsier.scss @@ -16,12 +16,6 @@ @import "bootstrap-5.3.8/scss/mixins"; @import "bootstrap-5.3.8/scss/utilities"; -// Bootsier additions to the Bootstrap maps -// --------------------------------------------------- -// The accent colors that Bootstrap lacks (see _bootsier-variables.scss). Only `root` uses $colors, -// to declare the --bs-* variables, so they must be added before importing it. -$colors: map-merge($colors, ("lime": $lime, "magenta": $magenta)); - // Bootstrap Layout & components // No "grid": page layout comes from PageTop's own Flex and Grid components. @import "bootstrap-5.3.8/scss/root"; diff --git a/extensions/pagetop-bootsier/src/lib.rs b/extensions/pagetop-bootsier/src/lib.rs index 9b533006..a597b81f 100644 --- a/extensions/pagetop-bootsier/src/lib.rs +++ b/extensions/pagetop-bootsier/src/lib.rs @@ -283,7 +283,6 @@ impl Theme for Bootsier { Container => |c| theme::bs::container::setup(c), Dialog => |c| theme::bs::dialog::setup(c), Dropdown => |c| theme::bs::dropdown::setup(c), - Icon => |c| theme::bs::icon::setup(c), Image => |c| theme::bs::image::setup(c), Nav => |c| theme::bs::nav::setup(c), Navbar => |c| theme::bs::navbar::setup(c), diff --git a/extensions/pagetop-bootsier/src/theme.rs b/extensions/pagetop-bootsier/src/theme.rs index bd1352e0..1286b959 100644 --- a/extensions/pagetop-bootsier/src/theme.rs +++ b/extensions/pagetop-bootsier/src/theme.rs @@ -82,8 +82,6 @@ pub use bs::form::select::SelectBsExt; #[doc(hidden)] pub use bs::form::textarea::TextareaBsExt; #[doc(hidden)] -pub use bs::icon::IconBsExt; -#[doc(hidden)] pub use bs::nav::NavBsExt; #[doc(hidden)] pub use bs::navbar::NavbarBsExt; diff --git a/extensions/pagetop-bootsier/src/theme/bs.rs b/extensions/pagetop-bootsier/src/theme/bs.rs index fa3e28e4..79c577ee 100644 --- a/extensions/pagetop-bootsier/src/theme/bs.rs +++ b/extensions/pagetop-bootsier/src/theme/bs.rs @@ -50,13 +50,6 @@ pub use form::select::SelectBsExt; #[doc(inline)] pub use form::textarea::TextareaBsExt; -// Icon. -pub mod icon; -#[doc(inline)] -pub use icon::Icon; -#[doc(inline)] -pub use icon::IconBsExt; - // Image. pub mod image; #[doc(inline)] @@ -92,9 +85,6 @@ pub use pagetop::base::component::table; #[doc(inline)] pub use table::Table; -// Tile. -pub use pagetop::base::component::Tile; - // Theme toggle. mod theme_toggle; pub use theme_toggle::theme_toggle; diff --git a/extensions/pagetop-bootsier/src/theme/bs/icon.rs b/extensions/pagetop-bootsier/src/theme/bs/icon.rs index 9b1d8af7..a0ba4f3a 100644 --- a/extensions/pagetop-bootsier/src/theme/bs/icon.rs +++ b/extensions/pagetop-bootsier/src/theme/bs/icon.rs @@ -1,68 +1,128 @@ -//! Definiciones para mostrar iconos ([`Icon`]). +use crate::theme::*; -use pagetop::prelude::*; +const DEFAULT_VIEWBOX: &str = "0 0 16 16"; -pub use pagetop::base::component::icon::{Core, Icon, Source}; - -/// Extensión de Bootsier para [`Icon`]. -/// -/// Añade los iconos de [Bootstrap Icons](https://icons.getbootstrap.com/), que Bootsier ya carga -/// como fuente de iconos en todas las páginas. Además, Bootsier muestra los iconos del conjunto de -/// PageTop ([`Core`]) con su equivalente de Bootstrap Icons. -/// -/// ```rust,no_run -/// use pagetop::prelude::*; -/// use pagetop_bootsier::theme::*; -/// -/// let home = bs::Icon::bi("house-fill").with_label(Lc::n("Home")); -/// ``` -pub trait IconBsExt: Sized { - /// Crea un icono de Bootstrap Icons a partir de su nombre, sin el prefijo `bi-` (p. ej. - /// `"house-fill"`). - fn bi(name: impl AsRef) -> Self; +#[derive(AutoDefault, Clone)] +pub enum IconKind { + #[default] + None, + Font(FontSize), + Svg { + shapes: Markup, + viewbox: AttrValue, + }, } -impl IconBsExt for Icon { - fn bi(name: impl AsRef) -> Self { - Icon::with(Source::font(util::join!("bi bi-", name.as_ref()))) +#[derive(AutoDefault, Clone, Debug, Getters)] +pub struct Icon { + /// Devuelve identificador, clases CSS, atributos HTML y valores extra del componente. + props: Props, + icon_kind: IconKind, + aria_label: AttrLc, +} + +#[async_trait] +impl Component for Icon { + fn new() -> Self { + Self::default() + } + + fn id(&self) -> Option { + self.props.get_id() + } + + fn setup(&mut self, _cx: &mut Context) { + if !matches!(self.icon_kind(), IconKind::None) { + self.alter_prop(PropsOp::prepend_classes("icon")); + } + if let IconKind::Font(font_size) = self.icon_kind() { + self.alter_prop(PropsOp::add_classes(font_size.as_str())); + } + } + + async fn prepare(&self, cx: &mut Context) -> Result { + Ok(match self.icon_kind() { + IconKind::None => html! {}, + IconKind::Font(_) => { + let aria_label = self.aria_label().lookup(cx); + let has_label = aria_label.is_some(); + html! { + i + (self.props().unpack(cx)) + role=[has_label.then_some("img")] + aria-label=[aria_label] + aria-hidden=[(!has_label).then_some("true")] + {} + } + } + IconKind::Svg { shapes, viewbox } => { + let aria_label = self.aria_label().lookup(cx); + let has_label = aria_label.is_some(); + let viewbox = viewbox.get().unwrap_or_else(|| DEFAULT_VIEWBOX.to_string()); + html! { + svg + xmlns="http://www.w3.org/2000/svg" + viewBox=(viewbox) + fill="currentColor" + focusable="false" + (self.props().unpack(cx)) + role=[has_label.then_some("img")] + aria-label=[aria_label] + aria-hidden=[(!has_label).then_some("true")] + { + (shapes) + } + } + } + }) } } -// **< Icon SETUP >********************************************************************************* +#[builder_impl] +impl Icon { + pub fn font() -> Self { + Self::default().with_icon_kind(IconKind::Font(FontSize::default())) + } -// Sustituye cada icono del conjunto de PageTop por su equivalente de Bootstrap Icons. El `setup()` -// del icono ya se ha ejecutado, así que las clases del glifo se añaden aquí; el origen cambia para -// que se pinte como glifo. -pub(crate) fn setup(icon: &mut Icon) { - let Some(&Source::Core(core)) = icon.source() else { - return; - }; - let classes = bi_classes(core); - icon.alter_prop(PropsOp::add_classes(classes)); - icon.alter_source(Source::font(classes)); -} + pub fn font_sized(font_size: FontSize) -> Self { + Self::default().with_icon_kind(IconKind::Font(font_size)) + } -#[rustfmt::skip] -const fn bi_classes(icon: Core) -> &'static str { - match icon { - Core::BarChart => "bi bi-bar-chart", - Core::Check => "bi bi-check-lg", - Core::ChevronDown => "bi bi-chevron-down", - Core::ChevronLeft => "bi bi-chevron-left", - Core::ChevronRight => "bi bi-chevron-right", - Core::ChevronUp => "bi bi-chevron-up", - Core::Close => "bi bi-x-lg", - Core::Gear => "bi bi-gear", - Core::Home => "bi bi-house", - Core::Key => "bi bi-key", - Core::Layers => "bi bi-layers", - Core::Minus => "bi bi-dash-lg", - Core::People => "bi bi-people", - Core::Person => "bi bi-person", - Core::Plus => "bi bi-plus-lg", - Core::QuestionCircle => "bi bi-question-circle", - Core::Shield => "bi bi-shield-lock", - Core::SignOut => "bi bi-box-arrow-right", - Core::Sliders => "bi bi-sliders", + pub fn svg(shapes: Markup) -> Self { + Self::default().with_icon_kind(IconKind::Svg { + shapes, + viewbox: AttrValue::default(), + }) + } + + pub fn svg_with_viewbox(shapes: Markup, viewbox: impl AsRef) -> Self { + Self::default().with_icon_kind(IconKind::Svg { + shapes, + viewbox: AttrValue::new(viewbox), + }) + } + + // **< Icon BUILDER >*************************************************************************** + + /// Establece el identificador único del componente; igual a `with_prop(PropsOp::set_id(id))`. + pub fn with_id(mut self, id: impl Into) -> Self { + self.props.alter_id(id); + self + } + + /// Modifica identificador, clases CSS, atributos HTML o valores extra del componente. + pub fn with_prop(mut self, op: impl Into) -> Self { + self.props.alter_prop(op); + self + } + + pub fn with_icon_kind(mut self, icon_kind: IconKind) -> Self { + self.icon_kind = icon_kind; + self + } + + pub fn with_aria_label(mut self, label: Lc) -> Self { + self.aria_label.alter_value(label); + self } } diff --git a/extensions/pagetop-bootsier/src/theme/bs/nav.rs b/extensions/pagetop-bootsier/src/theme/bs/nav.rs index c3b6189b..664316e3 100644 --- a/extensions/pagetop-bootsier/src/theme/bs/nav.rs +++ b/extensions/pagetop-bootsier/src/theme/bs/nav.rs @@ -42,7 +42,7 @@ pub(crate) const EXTRA_IN_NAVBAR: &str = "bootsier.nav.in_navbar"; /// bs::dropdown::Item::link(Lc::n("Another"), "/another"), /// ])), /// )) -/// .with_item(bs::nav::Item::link(Lc::n("Disabled"), "#").with_disabled(true)); +/// .with_item(bs::nav::Item::link_disabled(Lc::n("Disabled"), "#")); /// ``` #[builder_impl] pub trait NavBsExt { @@ -95,15 +95,13 @@ fn layout_class(layout: nav::Layout, classes: &mut String) { // `data-bs-toggle="dropdown"` para que el JS de Bootstrap lo reconozca (la clase `dropdown-toggle` // por sí sola sólo aporta el estilo, no la inicialización). pub(crate) async fn item_render(item: &Item, cx: &mut Context) -> Result { - let start = item.icon_start().render(cx).await; - let end = item.icon_end().render(cx).await; Ok(match item.item_kind() { ItemKind::Void => html! {}, ItemKind::Label(label) => html! { li (item.props().unpack(cx)) { span class="nav-link disabled" aria-disabled="true" { - (start) (label.using(cx)) (end) + (label.using(cx)) } } }, @@ -146,7 +144,7 @@ pub(crate) async fn item_render(item: &Item, cx: &mut Context) -> Result Result