Añade el primer componente básico nativo

Este componente renderiza directamente código HTML durante el
renderizado del documento.
This commit is contained in:
Manuel Cillero 2025-07-24 09:11:29 +02:00
parent 37df2ada75
commit ed25a17e80
6 changed files with 40 additions and 7 deletions

4
src/base/component.rs Normal file
View file

@ -0,0 +1,4 @@
//! Componentes nativos proporcionados por `PageTop`.
mod html;
pub use html::Html;

View file

@ -0,0 +1,28 @@
use crate::prelude::*;
/// Componente básico para renderizar directamente código HTML.
#[derive(AutoDefault)]
pub struct Html(Markup);
impl ComponentTrait for Html {
fn new() -> Self {
Html::default()
}
fn prepare_component(&self, _cx: &mut Context) -> PrepareMarkup {
PrepareMarkup::With(html! { (self.0) })
}
}
impl Html {
/// Crear una instancia con el código HTML del argumento.
pub fn with(html: Markup) -> Self {
Html(html)
}
/// Modifica el código HTML de la instancia con el nuevo código del argumento.
pub fn alter_html(&mut self, html: Markup) -> &mut Self {
self.0 = html;
self
}
}