duck.html.components.snackbar

Snackbar component for displaying brief messages at the top of the screen.

Module Contents

Classes

Snackbar

Snackbar component for showing brief notifications.

Data

SNACKBAR_SCRIPT

API

duck.html.components.snackbar.SNACKBAR_SCRIPT = <Multiline-String>
class duck.html.components.snackbar.Snackbar(text: str | None = None, type: str = 'info', variant: str = 'filled', timeout: int | None = None, **kwargs)[source]

Bases: duck.html.components.container.FlexContainer

Snackbar component for showing brief notifications.

Initialization

Initialize the snackbar.

Parameters:
  • text – Snackbar message text.

  • type – Snackbar type. Must be info, success, error, or warning.

  • variant – Visual style. Must be filled (solid background) or glacier (frosted, outlined glass look).

  • timeout – Auto-hide timeout in milliseconds.

  • **kwargs – Additional component keyword arguments.

Raises:

ValueError – If the snackbar type or variant is invalid.

_apply_variant_style() None[source]

Apply the background/border/text styling for the current type + variant combination.

allowed_types

None

allowed_variants

None

get_type_color(type: str) str[source]

Return the accent color for a snackbar type.

Parameters:

type – Snackbar type.

Returns:

The configured CSS color for the snackbar type.

hide() None[source]

Hide the snackbar from Python.

on_create() None[source]

Initialize and compose the snackbar.

set_timeout(timeout: int | None) None[source]

Set the default JavaScript auto-hide timeout.

Parameters:

timeout – Auto-hide timeout in milliseconds, or None to disable.

set_type(type: str) None[source]

Set snackbar type and background color.

Parameters:

type – Snackbar type. Must be info, success, error, or warning.

Raises:

ValueError – If the snackbar type is invalid.

set_type_color(type: str, color: str) None[source]

Set the color for a snackbar type.

Parameters:
  • type – Snackbar type.

  • color – CSS color value.

Raises:

ValueError – If the snackbar type is invalid.

set_variant(variant: str) None[source]

Set the snackbar’s visual variant.

Parameters:

variant – Visual style. Must be filled or glacier.

Raises:

ValueError – If the variant is invalid.

show() None[source]

Show the snackbar from Python.