Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alert and Toast timeout #250

Merged
merged 4 commits into from Sep 7, 2019
Merged

Alert and Toast timeout #250

merged 4 commits into from Sep 7, 2019

Conversation

tcbegley
Copy link
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
Collaborator Author

@tcbegley 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
2 checks passed
@tcbegley tcbegley deleted the alert-timeout branch Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant