Skip to content

Pages and layout ​

A page is a list of blocks: sections, grids, tabs, tables, forms, metrics. Each user gets only the blocks of resources they may view; a container left empty disappears.

rust
impl Page for OverviewPage {
    const NAME: &'static str = "overview";
    const LABEL: &'static str = "Overview";
    type User = User;

    fn layout() -> Vec<Block> {
        let products = || Block::table(ProductResource::NAME);
        let suppliers = || Block::table(SupplierResource::NAME);
        vec![
            Block::section("Drafts", vec![products().filter("status", "draft").with_actions(vec!["reprice"])])
                .description("Products waiting to be published."),
            Block::grid(vec![
                Block::section("Categories", vec![Block::table(CategoryResource::NAME)]),
                Block::section("Suppliers", vec![suppliers()]),
            ])
            .columns([1, 2]),
            Block::tabs([
                ("Published", vec![products().filter("status", "published")]),
                ("Archived", vec![products().filter("status", "archived")]),
                ("Suppliers", vec![suppliers()]),
            ]),
        ]
    }
}

Grid columns ​

CodeResult
Block::grid(children)one row, a column per child
Block::grid(children).columns(4)4 equal columns, children wrap
Block::grid(children).columns([2, 10])one row, a weight per child: 2/12 and 10/12

When a user may not see a child, its weight goes with it and the row stays full. On narrow screens every block takes the whole row.

Experimental. Not ready for production use.