Sheet
A modal dialog along one edge of the viewport, for content too long or too wide for a dialog in the middle.
Result
use hypersig::html::div;
use hypersig::style::pattern::{stack, wrap};
use hypersig::style::value::rem;
use hypersig::{Page, Signals};
use hypersig_ui::{ButtonSize, ButtonVariant, Dialog, DialogText, Side, checkbox, dialog_footer};
use serde::{Deserialize, Serialize};
#[derive(Signals, Serialize, Deserialize)]
pub(super) struct Project {
this_week: bool,
}
hypersig::dialog_ref!(const DETAILS_SHEET: DialogRef<Project>);
hypersig::dialog_ref!(const FILTERS_SHEET: DialogRef<Project>);
const DETAILS: Dialog<Project> = Dialog::new(DETAILS_SHEET);
const FILTERS: Dialog<Project> = Dialog::new(FILTERS_SHEET);
pub(super) fn page() -> Page<Project> {
let text = DialogText {
close: "Close"
.into(),
};
let done = "Done";
Page::new(
"Project",
Project { this_week: false },
)
.child(
div()
.css(wrap(rem(0.5)))
.child(
DETAILS
.trigger(ButtonVariant::Outline, ButtonSize::Default)
.text("Details"),
)
.child(
FILTERS
.trigger(ButtonVariant::Outline, ButtonSize::Default)
.text("Filters"),
),
)
.child(
DETAILS.sheet(
Side::Right,
"Project details",
"Created on March 3. Deployed 12 times.",
dialog_footer().child(
DETAILS
.close(ButtonVariant::Outline, ButtonSize::Default)
.text(done),
),
&text,
),
)
.child(
FILTERS.sheet(
Side::Bottom,
"Filters",
"Choose which projects the list shows.",
div()
.css(stack(rem(1)))
.child(checkbox(
"Deployed this week",
Project::this_week(),
))
.child(
dialog_footer().child(
FILTERS
.close(ButtonVariant::Outline, ButtonSize::Default)
.text(done),
),
),
&text,
),
)
}Accessibility
A sheet is the same modal <dialog> as a Dialog, drawn along one edge of the viewport. A screen reader announces it as a dialog named by its title, the rest of the page is inert while it is open, and focus returns to the element that opened it when it closes. Only its place and size differ from a dialog's.
| Key | What it does |
|---|---|
| Tab, Shift+Tab | Moves between the sheet's controls and never reaches the page behind |
| Escape | Closes the sheet and returns focus to the element that opened it |
Building a sheet
Dialog::sheet takes the arguments of Dialog::dialog after a Side, the edge the sheet sits along. trigger, close, open, and dismiss work on it as on a Dialog:
impl<S> Dialog<S> {
pub fn sheet(
self,
side: Side,
title: impl Into<String>,
description: impl Into<String>,
content: impl Into<Node<S>>,
text: &DialogText,
) -> El<S>;
}
#[non_exhaustive]
pub enum Side {
Top,
Right,
Bottom,
Left,
}Side | Where the sheet sits |
|---|---|
Side::Top | Along the top edge, the full width of the viewport |
Side::Right | Along the right edge, the full height of the viewport and at most 24rem wide |
Side::Bottom | Along the bottom edge, the full width of the viewport |
Side::Left | Along the left edge, the full height of the viewport and at most 24rem wide |
Content taller than the sheet scrolls inside it. Side is #[non_exhaustive], so a match on it outside the crate needs a _ arm.
The HTML
The HTML is a dialog's, and every Side renders the same elements and attributes. Only the classes, left out here, place it. Each … is an id made from the dialog ref's name, and the corner button is named by the DialogText the example passes:
<dialog id="…" aria-labelledby="…" aria-describedby="…" closedby="any">
<div>
<div>
<h2 id="…">Cart</h2>
<p id="…">Two items, ready to check out.</p>
</div>
<div>
<ul><li>Green tea</li><li>Two cups</li></ul>
<div><button type="button" commandfor="…" command="close">Done</button></div>
</div>
</div>
<button type="button" aria-label="Close the cart" commandfor="…" command="close">
<svg aria-hidden="true" …></svg>
</button>
</dialog>What fails to compile
The edge is a Side, so a string such as "right" is E0308, mismatched types, where a string would reach the browser unchecked:
use hypersig::html::p;
use hypersig::{DialogRef, Signals};
use hypersig_ui::{Dialog, DialogText};
use serde::{Deserialize, Serialize};
#[derive(Signals, Serialize, Deserialize)]
struct Shop {}
hypersig::dialog_ref!(const CART_SHEET: DialogRef<Shop>);
const CART: Dialog<Shop> = Dialog::new(CART_SHEET);
// The edge is a `Side`, not a string.
let sheet = CART.sheet("right", "Cart", "Two items.", p(), &DialogText::default());Leaving out the DialogText is E0061, and a NodeRef in place of the DialogRef is E0308, as for a Dialog.
What is not checked
As with a dialog, one handle's sheet placed twice makes Page::render panic, and a handle used for both a sheet and a dialog on one page panics the same way. Nothing checks the side against the screen: a wide table in a Side::Left sheet scrolls sideways inside the sheet, which is at most 24rem wide.
Example: a cart along the right edge
use hypersig::html::{div, li, ul};
use hypersig::{DialogRef, Page, Signals};
use hypersig_ui::{ButtonSize, ButtonVariant, Dialog, DialogText, Side, dialog_footer};
use serde::{Deserialize, Serialize};
#[derive(Signals, Serialize, Deserialize)]
struct Shop {}
hypersig::dialog_ref!(const CART_SHEET: DialogRef<Shop>);
const CART: Dialog<Shop> = Dialog::new(CART_SHEET);
let html = Page::new("Shop", Shop {})
.child(CART.trigger(ButtonVariant::Outline, ButtonSize::Default).text("Cart"))
.child(CART.sheet(
Side::Right,
"Cart",
"Two items, ready to check out.",
div()
.child(ul().child(li().text("Green tea")).child(li().text("Two cups")))
.child(
dialog_footer()
.child(CART.close(ButtonVariant::Default, ButtonSize::Default).text("Done")),
),
&DialogText { close: "Close the cart".into() },
))
.render();A sheet holds what a Dialog would, when it is long or belongs beside the page, such as filters, details, or a cart. For a short choice next to a button, a Popover keeps the page usable.