based/examples/ui.rs

55 lines
1.4 KiB
Rust
Raw Normal View History

2025-01-21 16:39:47 +01:00
use based::asset::AssetRoutes;
2025-01-14 22:56:07 +01:00
use based::request::{RequestContext, StringResponse};
2025-01-15 18:28:59 +01:00
use based::ui::components::{AppBar, Shell};
use based::ui::htmx::{Event, HTMXAttributes};
2025-01-21 16:39:47 +01:00
use based::ui::prelude::*;
2025-01-14 22:56:07 +01:00
use maud::Render;
use maud::html;
use rocket::routes;
2025-01-21 16:39:47 +01:00
use rocket::{State, get};
2025-01-14 22:56:07 +01:00
#[get("/")]
2025-01-21 16:39:47 +01:00
pub async fn index_page(ctx: RequestContext, shell: &State<Shell>) -> StringResponse {
2025-01-14 22:56:07 +01:00
let content = AppBar("MyApp", None).render();
let content = html!(
h1 { "Hello World!" };
2025-01-17 16:28:56 +01:00
(
2025-01-21 09:00:45 +01:00
Screen::medium(Hover(Background(Nothing()).color(Red::_700))).on(
Background(Text("HELLO!")).color(Blue::_700)
2025-01-17 16:28:56 +01:00
)
)
2025-01-15 18:28:59 +01:00
(Hover(
2025-01-16 18:22:52 +01:00
Cursor::NorthEastResize.on(
Padding(Text("").color(&Gray::_400)).x(ScreenValue::_10)
2025-01-15 18:28:59 +01:00
)
2025-01-16 18:22:52 +01:00
).on(
Link("/test", Text("Hello")).hx_get("/test").hx_get("/test").hx_trigger(
Event::on_load().delay("2s")
.and(Event::on_revealed())
)
)
)
2025-01-15 18:28:59 +01:00
2025-01-14 22:56:07 +01:00
(content)
);
2025-01-21 16:39:47 +01:00
shell.render_page(content, "Hello World", ctx).await
2025-01-14 22:56:07 +01:00
}
#[rocket::launch]
async fn launch() -> _ {
// Logging
env_logger::init();
2025-01-21 16:39:47 +01:00
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
2025-01-14 22:56:07 +01:00
}