Skip to content

Alert and Toast timeout#250

Merged
tcbegley merged 4 commits intomasterfrom
alert-timeout
Sep 7, 2019
Merged

Alert and Toast timeout#250
tcbegley merged 4 commits intomasterfrom
alert-timeout

Conversation

@tcbegley
Copy link
Copy Markdown
Collaborator

@tcbegley tcbegley commented Sep 6, 2019

This PR addresses #190, adding a duration prop to both Alert and Toast allowing user to specify a timeout in milliseconds after which the alert or toast is dismissed.

@tcbegley
Copy link
Copy Markdown
Collaborator Author

tcbegley commented Sep 6, 2019

This can be tested by installing the pre-release

pip install dash-bootstrap-components==0.7.1rc3

Here's a simple example app for testing:

import dash
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output, State

app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = dbc.Container(
    [
        dbc.Button("Toggle alert", id="alert-button"),
        dbc.Button("Toggle toast", id="toast-button"),
        dbc.Alert(
            "This is an alert",
            duration=3000,
            is_open=True,
            id="alert",
            dismissable=True,
        ),
        dbc.Toast(
            "This is a toast",
            header="I will dismiss",
            duration=3000,
            id="toast",
            is_open=True,
            dismissable=True,
        ),
    ]
)


def toggle(n, is_open):
    if n:
        return not is_open
    return is_open


app.callback(
    Output("alert", "is_open"),
    [Input("alert-button", "n_clicks")],
    [State("alert", "is_open")],
)(toggle)

app.callback(
    Output("toast", "is_open"),
    [Input("toast-button", "n_clicks")],
    [State("toast", "is_open")],
)(toggle)


if __name__ == "__main__":
    app.run_server(debug=True)

@happyshows if you have a chance to try this out and let me know what you think that would be much appreciated

@tcbegley tcbegley merged commit ddafe8d into master Sep 7, 2019
@tcbegley tcbegley deleted the alert-timeout branch September 7, 2019 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant