based/examples/ui.rs
2025-01-21 16:39:47 +01:00

54 lines
1.4 KiB
Rust

use based::asset::AssetRoutes;
use based::request::{RequestContext, StringResponse};
use based::ui::components::{AppBar, Shell};
use based::ui::htmx::{Event, HTMXAttributes};
use based::ui::prelude::*;
use maud::Render;
use maud::html;
use rocket::routes;
use rocket::{State, get};
#[get("/")]
pub async fn index_page(ctx: RequestContext, shell: &State<Shell>) -> StringResponse {
let content = AppBar("MyApp", None).render();
let content = html!(
h1 { "Hello World!" };
(
Screen::medium(Hover(Background(Nothing()).color(Red::_700))).on(
Background(Text("HELLO!")).color(Blue::_700)
)
)
(Hover(
Cursor::NorthEastResize.on(
Padding(Text("").color(&Gray::_400)).x(ScreenValue::_10)
)
).on(
Link("/test", Text("Hello")).hx_get("/test").hx_get("/test").hx_trigger(
Event::on_load().delay("2s")
.and(Event::on_revealed())
)
)
)
(content)
);
shell.render_page(content, "Hello World", ctx).await
}
#[rocket::launch]
async fn launch() -> _ {
// Logging
env_logger::init();
let shell = Shell::new(Nothing(), Nothing(), Nothing()).use_ui();
rocket::build()
.mount("/", routes![index_page])
.mount_assets() // Mount included assets routes
.manage(shell) // Manage global shell reference
}