Skip to content
GitHub11 stars

Generates toast notifications.

<ToastProvider ToastManager="_toasts">
    <button type="button" @onclick="CreateToast" class="toast-button">
        Create toast

Anatomy

Import the primitives and assemble the parts. The viewport holds stacked toasts, each a ToastRoot, and anchored toasts, each a ToastRoot in a ToastPositioner:

@using Blazix.Primitives

<ToastProvider>
    <ToastPortal>
        <ToastViewport>
            <ToastRoot>
                <ToastContent>
                    <ToastTitle />
                    <ToastDescription />
                    <ToastAction />
                    <ToastClose />
                </ToastContent>
            </ToastRoot>

            <ToastPositioner>
                <ToastRoot>
                    <ToastArrow />
                    <ToastContent>
                        <ToastTitle />
                        <ToastDescription />
                        <ToastAction />
                        <ToastClose />
                    </ToastContent>
                </ToastRoot>
            </ToastPositioner>
        </ToastViewport>
    </ToastPortal>
</ToastProvider>

API Reference

ToastRoot

Renders a <div> element.

ParameterTypeDefault
Toastrequired ToastObject -
Render RenderFragment<ToastRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-expanded

Present when the toast is expanded in the viewport.

boolean
data-limited

Present when the toast was limited because the toast limit was exceeded.

boolean
data-swipe-direction

The direction the toast was swiped.

'up' | 'down' | 'left' | 'right'
data-swiping

Present when the toast is being swiped.

boolean
data-type

The type of the toast.

string
data-starting-style

Present when the toast begins animating in.

-
data-ending-style

Present when the toast is animating out.

-
CSS variableType
--toast-height

Indicates the measured natural height of the toast in pixels.

number
--toast-index

Indicates the index of the toast in the list.

number
--toast-offset-y

Indicates the vertical pixels offset of the toast in the list when expanded.

number
--toast-swipe-movement-x

Indicates the horizontal swipe movement of the toast.

number
--toast-swipe-movement-y

Indicates the vertical swipe movement of the toast.

number

ToastProvider

Doesn't render its own HTML element.

ParameterTypeDefault
ToastManager ToastManager? -
Timeout int 5000
Limit int 3
ChildContent

The part's content.

RenderFragment? -

ToastPortal

Doesn't render its own HTML element.

ParameterTypeDefault
ChildContent

The part's content.

RenderFragment? -

ToastPositioner

Renders a <div> element.

ParameterTypeDefault
Toastrequired ToastObject -
Anchor string? -
Side Side? -
Align Align? -
SideOffset int? -
AlignOffset int? -
CollisionPadding int? -
ArrowPadding int? -
Sticky bool? -
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-anchor-hidden

Present when the anchor is hidden.

-
data-align

Indicates how the toast is aligned relative to specified side.

'start' | 'center' | 'end'
data-side

Indicates which side the toast is positioned relative to the trigger.

'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'
CSS variableType
--anchor-height

The anchor's height.

number
--anchor-width

The anchor's width.

number
--available-height

The available height between the anchor and the edge of the viewport.

number
--available-width

The available width between the anchor and the edge of the viewport.

number
--transform-origin

The coordinates that this element is anchored to. Used for animations and transitions.

string

ToastArrow

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-uncentered

Present when the toast arrow is uncentered.

-
data-align

Indicates how the toast is aligned relative to specified side.

'start' | 'center' | 'end'
data-side

Indicates which side the toast is positioned relative to the anchor.

'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

ToastContent

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-behind

Present when the toast is behind the frontmost toast in the stack.

boolean
data-expanded

Present when the toast viewport is expanded.

boolean

ToastTitle

Renders a <h2> element.

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-type

The type of the toast.

string

ToastDescription

Renders a <p> element.

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-type

The type of the toast.

string

ToastClose

Renders a <button> element.

ParameterTypeDefault
NativeButton bool? -
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-type

The type of the toast.

string

ToastAction

Renders a <button> element.

ParameterTypeDefault
NativeButton bool? -
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-type

The type of the toast.

string

ToastViewport

Renders a <div> element.

ParameterTypeDefault
Template RenderFragment<ToastObject>? -
SwipeDirections IReadOnlyList<string> -
Render RenderFragment<ToastViewportRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-expanded

Indicates toasts are expanded in the viewport.

boolean
CSS variableType
--toast-frontmost-height

Indicates the height of the frontmost toast.

number