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

class

Drawer

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

NameDescription
DrawerInitializes a new instance of this class.
Constructor
Drawer
Overload
Drawer(string)Initializes a new instance of this class.
Drawer(IComponent)Initializes a new instance of this class.
Drawer(string)
public Drawer(string title = null) : this(string.IsNullOrEmpty(title) ? null : TextBlock(title).SemiBold())

Initializes a new instance of this class.

Parameters

title string
Drawer(IComponent)
public Drawer(IComponent title)

Initializes a new instance of this class.

Parameters

title IComponent

Properties

NameDescription
ContentSets the content rendered inside the sheet.
FooterGets or sets the footer of the sheet, drawn below the scrolling content.
CanLightDismissGets 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.
ShowCloseButtonGets or sets whether the close button is shown.
BackgroundGets or sets the CSS background of the sheet.
LocksPageScrollA drawer blocks the page behind it.
CanDragToDismissGets or sets whether pulling the sheet down by its handle dismisses it. True by default.
IsOpenGets whether the sheet is on screen and not on its way out.
Property
Drawer.Content
public override IComponent Content { get ; set ; }

Sets the content rendered inside the sheet.

Property
Drawer.Footer
public IComponent Footer { get ; set ; }

Gets or sets the footer of the sheet, drawn below the scrolling content.

Property
Drawer.CanLightDismiss
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.

Property
Drawer.ShowCloseButton
public bool ShowCloseButton { get ; set ; }

Gets or sets whether the close button is shown.

Property
Drawer.Background
public string Background { get ; set ; }

Gets or sets the CSS background of the sheet.

Property
Drawer.LocksPageScroll
protected override bool LocksPageScroll

A drawer blocks the page behind it.

Property
Drawer.CanDragToDismiss
public bool CanDragToDismiss { get ; set ; }

Gets or sets whether pulling the sheet down by its handle dismisses it. True by default.

Property
Drawer.IsOpen
public bool IsOpen

Gets whether the sheet is on screen and not on its way out.

Methods

NameDescription
SetTitleSets the title shown beside the close button. Null leaves the header with only the button.
SetFooterSets the footer of the sheet.
MaxHeightCaps 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.
FullHeightMakes 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.
NoHeaderLeaves out the title row, for content that brings its own header - the sheet is then held by its handle alone.
NoContentPaddingRemoves the padding around the content.
HideCloseButtonHides the close button. The sheet can still be dragged down, and dismissed by tapping outside it.
LightDismissEnables light-dismiss behaviour (tapping outside the sheet closes it). On by default.
NoLightDismissDisables light-dismiss behaviour, for a sheet that asks for a decision.
NoDragToDismissStops the sheet being dismissed by pulling it down, for one that asks for a decision.
OnHideRegisters a callback invoked when the sheet is hidden.
ShowShows the sheet, sliding it up from the bottom.
HideHides the sheet, sliding it back down.
AsObservableReturns an observable that tracks the visibility of the sheet.
SetBoundValueProgrammatically shows or hides the sheet as part of a two-way binding.
Method
Drawer.SetTitle
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.
SetTitle(IComponent)
public Drawer SetTitle(IComponent title)

Sets the title shown beside the close button. Null leaves the header with only the button.

Parameters

title IComponent
SetTitle(string)
public Drawer SetTitle(string title)

Sets the title shown beside the close button.

Parameters

title string
Method
Drawer.SetFooter
public Drawer SetFooter(IComponent footer)

Sets the footer of the sheet.

Method
Drawer.MaxHeight
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.

Method
Drawer.FullHeight
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.

Method
Drawer.NoHeader
public Drawer NoHeader()

Leaves out the title row, for content that brings its own header - the sheet is then held by its handle alone.

Method
Drawer.NoContentPadding
public Drawer NoContentPadding()

Removes the padding around the content.

Method
Drawer.HideCloseButton
public Drawer HideCloseButton()

Hides the close button. The sheet can still be dragged down, and dismissed by tapping outside it.

Method
Drawer.LightDismiss
public Drawer LightDismiss()

Enables light-dismiss behaviour (tapping outside the sheet closes it). On by default.

Method
Drawer.NoLightDismiss
public Drawer NoLightDismiss()

Disables light-dismiss behaviour, for a sheet that asks for a decision.

Method
Drawer.NoDragToDismiss
public Drawer NoDragToDismiss()

Stops the sheet being dismissed by pulling it down, for one that asks for a decision.

Method
Drawer.OnHide
public Drawer OnHide(OnHideHandler onHide)

Registers a callback invoked when the sheet is hidden.

Method
Drawer.Show
public override Drawer Show()

Shows the sheet, sliding it up from the bottom.

Method
Drawer.Hide
public override void Hide(Action onHidden = null)

Hides the sheet, sliding it back down.

Method
Drawer.AsObservable
public IObservable<bool> AsObservable()

Returns an observable that tracks the visibility of the sheet.

Method
Drawer.SetBoundValue
public void SetBoundValue(bool value)

Programmatically shows or hides the sheet as part of a two-way binding.

Fields

NameDescription
DRAWER_TRANSITION_TIMEHow long the sheet takes to slide in or out, in milliseconds. Kept in step with tss.drawer.css.
DRAG_TO_DISMISS_DISTANCEHow far the sheet has to be dragged down, in pixels, before letting go dismisses it.
Field
Drawer.DRAWER_TRANSITION_TIME
public const int DRAWER_TRANSITION_TIME = 250

How long the sheet takes to slide in or out, in milliseconds. Kept in step with tss.drawer.css.

Field
Drawer.DRAG_TO_DISMISS_DISTANCE
private const int DRAG_TO_DISMISS_DISTANCE = 80

How far the sheet has to be dragged down, in pixels, before letting go dismisses it.

See also