snackbar

package
v0.1.122 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package snackbar contains Material 3 Snackbar components.

Reference: [Snackbars](https://m3.material.io/components/snackbar/overview) Specs: [Snackbars Specs](https://m3.material.io/components/snackbar/specs)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Snackbar added in v0.1.94

func Snackbar(
	data *SnackbarData,
	options ...SnackbarOption,
) api.Composable

Snackbar displays a brief message at the bottom of the screen.

To display a snackbar, use [SnackbarHostState.ShowSnackbar].

func SnackbarHost

func SnackbarHost(hostState SnackbarHostState) compose.Composable

SnackbarHost is a composable that displays snackbars from the given SnackbarHostState.

It shows at most one snackbar at a time. Duration-based auto-dismiss is managed via LaunchedEffect keyed on the current snackbar.

func SnackbarHostWithContent added in v0.1.94

func SnackbarHostWithContent(hostState SnackbarHostState, content func(data *SnackbarData) api.Composable) compose.Composable

SnackbarHostWithContent is a composable that displays snackbars with a custom content builder. This matches Kotlin's SnackbarHost(hostState, snackbar = { data -> ... }) pattern.

Types

type SnackbarData added in v0.1.94

type SnackbarData struct {
	Context context.Context

	Visuals SnackbarVisuals

	// Gio clickable state — persists across frames for immediate-mode rendering
	ActionClickable  widget.Clickable
	DismissClickable widget.Clickable
	// contains filtered or unexported fields
}

SnackbarData represents the data of one particular Snackbar as managed by SnackbarHostState. Matches Kotlin's SnackbarData interface.

func (*SnackbarData) Dismiss added in v0.1.94

func (d *SnackbarData) Dismiss()

Dismiss notifies that the Snackbar was dismissed (by timeout or user).

func (*SnackbarData) PerformAction added in v0.1.94

func (d *SnackbarData) PerformAction()

PerformAction notifies that the action on the Snackbar was clicked.

type SnackbarDefaultsData added in v0.1.94

type SnackbarDefaultsData struct {
	Shape                     shape.Shape
	Color                     graphics.Color
	ContentColor              graphics.Color
	ActionColor               graphics.Color
	ActionContentColor        graphics.Color
	DismissActionContentColor graphics.Color
}

func SnackbarDefaults added in v0.1.94

func SnackbarDefaults(theme material3.ThemeInterface) SnackbarDefaultsData

type SnackbarDuration added in v0.1.94

type SnackbarDuration int

SnackbarDuration controls how long a snackbar will be shown. Matches Kotlin's SnackbarDuration enum.

const (
	// SnackbarDurationShort shows the snackbar for a short period (4s).
	SnackbarDurationShort SnackbarDuration = iota
	// SnackbarDurationLong shows the snackbar for a longer period (10s).
	SnackbarDurationLong
	// SnackbarDurationIndefinite shows the snackbar until explicitly dismissed or action is clicked.
	SnackbarDurationIndefinite
)

func (SnackbarDuration) ToDuration added in v0.1.94

func (d SnackbarDuration) ToDuration() time.Duration

ToDuration converts a SnackbarDuration to a time.Duration. Returns 0 for Indefinite (meaning no auto-dismiss).

type SnackbarHostState

type SnackbarHostState interface {
	ShowSnackbar(message string, options ...SnackbarOption)
	CurrentSnackbarData() *SnackbarData
	// contains filtered or unexported methods
}

func RememberSnackbarHostState added in v0.1.94

func RememberSnackbarHostState(c compose.Composer) SnackbarHostState

RememberSnackbarHostState creates a remembered SnackbarHostState tied to the composer lifecycle.

type SnackbarOption

type SnackbarOption func(*SnackbarOptions)

SnackbarOption is a functional option for configuring a snackbar.

func WithActionLabel added in v0.1.94

func WithActionLabel(label string) SnackbarOption

WithActionLabel sets an action button label on the snackbar.

func WithContext added in v0.1.94

func WithContext(ctx context.Context) SnackbarOption

func WithDismissAction added in v0.1.94

func WithDismissAction() SnackbarOption

WithDismissAction enables a dismiss action on the snackbar.

func WithDuration

func WithDuration(duration SnackbarDuration) SnackbarOption

WithDuration sets the display duration of the snackbar.

func WithModifier added in v0.1.94

func WithModifier(m ui.Modifier) SnackbarOption

func WithOnResult added in v0.1.94

func WithOnResult(callback func(SnackbarResult)) SnackbarOption

WithOnResult sets a callback invoked when the snackbar is dismissed or its action is performed.

type SnackbarOptions

type SnackbarOptions struct {
	Modifier ui.Modifier

	Context           context.Context
	Duration          SnackbarDuration
	ActionLabel       string
	WithDismissAction bool
	OnResult          func(SnackbarResult)

	Shape                     shape.Shape
	ContainerColor            graphics.Color
	ContentColor              graphics.Color
	ActionColor               graphics.Color
	ActionContentColor        graphics.Color
	DismissActionContentColor graphics.Color
}

SnackbarOptions holds configuration for a snackbar.

func DefaultOptions

func DefaultOptions() SnackbarOptions

DefaultOptions returns the default snackbar options. Matches Kotlin: Short duration when no action, Indefinite when action present.

type SnackbarResult added in v0.1.94

type SnackbarResult int

SnackbarResult represents the outcome of a snackbar being shown. Matches Kotlin's SnackbarResult enum.

const (
	// SnackbarDismissed indicates the snackbar was dismissed by timeout or by the user.
	SnackbarDismissed SnackbarResult = iota
	// SnackbarActionPerformed indicates the action button was clicked.
	SnackbarActionPerformed
)

type SnackbarVisuals added in v0.1.94

type SnackbarVisuals struct {
	Message           string
	ActionLabel       string
	WithDismissAction bool
	Duration          SnackbarDuration
}

SnackbarVisuals holds the visual representation for a particular Snackbar. Matches Kotlin's SnackbarVisuals interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL