Drawer
Description
Drawer is a sheet that slides up from the bottom of the screen over a dimmed page, with a grab handle, a title with a close button, a scrolling content area and an optional footer. It is as tall as its content, up to 85% of the screen, and on screens wider than 768px it stays a 640px column in the middle. The user closes it by dragging the handle down, tapping outside it, or using the close button.
Use it for lists and short tasks on phones, where a Panel or a Modal would cover the whole screen. An existing modal can be shown as a drawer on mobile with Modal.DrawerOnMobile() instead of being rebuilt.
Usage
Create a drawer with Drawer(title), set its content with .Content(...) and an optional footer with .SetFooter(...), then call .Show().
Other options: .MaxHeight(...) caps the height, .FullHeight() keeps it at the full height for content that grows while open, .NoLightDismiss() and .NoDragToDismiss() turn off the two ways of closing it, and .NoHeader() leaves only the handle.
API reference
public sealed class Drawer : Layer<Drawer>, IHasBackgroundColor, IBindableComponent<bool>A sheet that slides up from the bottom of the screen over a dimmed page - the phone's answer to a Panel or a Modal. It has a grab handle, an optional title with a close button, a scrolling content area and an optional footer, and it can be dragged down to dismiss.
Remarks
A Modal that should become one of these on a phone does not need rebuilding: DrawerOnMobile renders the same modal inside a drawer while the page is in mobile mode.
- Namespace
- Tesserae
- Inheritance
- Layer<Drawer> → Drawer
- Implements
- IHasBackgroundColor, IBindableComponent<bool>
Constructors
| Name | Description |
|---|---|
| Drawer | Initializes a new instance of this class. |
| Overload | |
|---|---|
| Drawer(string) | Initializes a new instance of this class. |
| Drawer(IComponent) | Initializes a new instance of this class. |
Properties
| Name | Description |
|---|---|
| Content | Sets the content rendered inside the sheet. |
| Footer | Gets or sets the footer of the sheet, drawn below the scrolling content. |
| CanLightDismiss | Gets or sets whether tapping the dimmed page around the sheet closes it. True by default: a sheet is something the reader looks at and puts away. |
| ShowCloseButton | Gets or sets whether the close button is shown. |
| Background | Gets or sets the CSS background of the sheet. |
| LocksPageScroll | A drawer blocks the page behind it. |
| CanDragToDismiss | Gets or sets whether pulling the sheet down by its handle dismisses it. True by default. |
| IsOpen | Gets whether the sheet is on screen and not on its way out. |
public override IComponent Content { get ; set ; }Sets the content rendered inside the sheet.
public bool CanLightDismiss { get ; set ; }Gets or sets whether tapping the dimmed page around the sheet closes it. True by default: a sheet is something the reader looks at and puts away.
public bool ShowCloseButton { get ; set ; }Gets or sets whether the close button is shown.
public string Background { get ; set ; }Gets or sets the CSS background of the sheet.
protected override bool LocksPageScrollA drawer blocks the page behind it.
public bool CanDragToDismiss { get ; set ; }Gets or sets whether pulling the sheet down by its handle dismisses it. True by default.
Methods
| Name | Description |
|---|---|
| SetTitle | Sets the title shown beside the close button. Null leaves the header with only the button. |
| SetFooter | Sets the footer of the sheet. |
| MaxHeight | Caps the sheet's height, as a CSS size. It is 85% of the screen by default, so the page it covers is always still in sight above it; the sheet is otherwise as tall as its content. |
| FullHeight | Makes the sheet as tall as MaxHeight allows, whatever its content - for content that grows while it is open (a list still loading), which would otherwise make the sheet jump. |
| NoHeader | Leaves out the title row, for content that brings its own header - the sheet is then held by its handle alone. |
| NoContentPadding | Removes the padding around the content. |
| HideCloseButton | Hides the close button. The sheet can still be dragged down, and dismissed by tapping outside it. |
| LightDismiss | Enables light-dismiss behaviour (tapping outside the sheet closes it). On by default. |
| NoLightDismiss | Disables light-dismiss behaviour, for a sheet that asks for a decision. |
| NoDragToDismiss | Stops the sheet being dismissed by pulling it down, for one that asks for a decision. |
| OnHide | Registers a callback invoked when the sheet is hidden. |
| Show | Shows the sheet, sliding it up from the bottom. |
| Hide | Hides the sheet, sliding it back down. |
| AsObservable | Returns an observable that tracks the visibility of the sheet. |
| SetBoundValue | Programmatically shows or hides the sheet as part of a two-way binding. |
| Overload | |
|---|---|
| SetTitle(IComponent) | Sets the title shown beside the close button. Null leaves the header with only the button. |
| SetTitle(string) | Sets the title shown beside the close button. |
public Drawer MaxHeight(UnitSize height)Caps the sheet's height, as a CSS size. It is 85% of the screen by default, so the page it covers is always still in sight above it; the sheet is otherwise as tall as its content.
public Drawer FullHeight()Makes the sheet as tall as MaxHeight allows, whatever its content - for content that grows while it is open (a list still loading), which would otherwise make the sheet jump.
public Drawer NoHeader()Leaves out the title row, for content that brings its own header - the sheet is then held by its handle alone.
public Drawer NoContentPadding()Removes the padding around the content.
public Drawer HideCloseButton()Hides the close button. The sheet can still be dragged down, and dismissed by tapping outside it.
public Drawer LightDismiss()Enables light-dismiss behaviour (tapping outside the sheet closes it). On by default.
public Drawer NoLightDismiss()Disables light-dismiss behaviour, for a sheet that asks for a decision.
public Drawer NoDragToDismiss()Stops the sheet being dismissed by pulling it down, for one that asks for a decision.
public Drawer OnHide(OnHideHandler onHide)Registers a callback invoked when the sheet is hidden.
public override void Hide(Action onHidden = null)Hides the sheet, sliding it back down.
public IObservable<bool> AsObservable()Returns an observable that tracks the visibility of the sheet.
Fields
| Name | Description |
|---|---|
| DRAWER_TRANSITION_TIME | How long the sheet takes to slide in or out, in milliseconds. Kept in step with tss.drawer.css. |
| DRAG_TO_DISMISS_DISTANCE | How far the sheet has to be dragged down, in pixels, before letting go dismisses it. |
public const int DRAWER_TRANSITION_TIME = 250How long the sheet takes to slide in or out, in milliseconds. Kept in step with tss.drawer.css.