Yii2 Components - Snackbars

Snackbars

Snackbar class is a widget to render flash messages as MDC snackbars.
vip9008\MDC\components\Snackbar

Usage

A basic usage looks like the following:

<?php
echo Snackbar::widget();
?>

The above code will render a snackbar for each flash message in the session.

Snackbars will be activated automatically on document ready event.

Customization options

Snackbars can be further customized by changing the available widgets options.

<?php
echo Snackbar::widget([
    /**
     * @var array Snackbars container Html attributes in terms of $attribute => $value.
     * Note: Snackbars container ID is set to #mdc-snackbars and cannot be changed.
     */
    'options' => [],
    /**
     * @var array Snackbar types configuration for flash messages.
     * This array is setup as $type => $cssClass.
     */
    'snackbarTypes' => [
        'error'   => 'snackbar-error',
        'danger'  => 'snackbar-danger',
        'success' => 'snackbar-success',
        'info'    => 'snackbar-info',
        'warning' => 'snackbar-warning',
    ],
    /**
     * @var float Time in seconds before removing an active snackbar.
     * cannot be less than 4 or more than 10.
     */
    'snackbarTime' => 4.0,
    /**
     * @var array|null the action buttons Html attributs in terms of $attribute => $value.
     * if set to null action button will not be rendered.
     * default tag is [[button]] can be changed to [[a]] tag, example: ['tag' => 'a']
     * default label is [[Yii::t('yii', 'Dismiss')]] can be customized, example: ['label' => 'OK']
     */
    'actionButton' => null,
]);
?>

For more information about snackbars. see snackbars.