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

Feature: st.toast #6783

Merged
merged 26 commits into from
Jul 12, 2023
Merged

Feature: st.toast #6783

merged 26 commits into from
Jul 12, 2023

Conversation

mayagbarnes
Copy link
Collaborator

@mayagbarnes mayagbarnes commented Jun 2, 2023

📚 Context

Adds a new widget for notification toasts using st.toast - covers the use case for notifications that don't disrupt the flow/organization of the existing app. This is distinct from the existing st.warning, st.error, st.success & st.info, which are inline. st.toast params are as follows:
text(str) - Short message for the toast.
icon(None or str) - An optional, keyword-only argument that specifies an emoji to use as the icon for the toast. Shortcodes are not allowed, please use a single character instead. E.g. "🚨", "🔥", "🤖", etc. Defaults to None, which means no icon is displayed.

  • What kind of change does this PR introduce?
    • Feature
    • Refactor

NOTE: This PR also creates a new event rendering construct in an effort to distinguish events from persistent elements like widgets. The path is as follows:

  • new RootContainer constant -> EVENT
  • lib/streamlit/__init__.py -> toast mapped to event.toast vs. other methods on main
  • AppView.tsx has a new EventContainer that uses existing renderBlock method that takes in event elements

🧪 Testing Done

  • Screenshots included
  • Added/Updated unit tests
  • Added/Updated e2e tests

🌐 References

lib/streamlit/elements/alert.py Fixed Show fixed Hide fixed
lib/streamlit/elements/toast.py Fixed Show fixed Hide fixed
@@ -1565,6 +1565,8 @@ export class App extends PureComponent<Props, State> {
value={{
initialSidebarState,
wideMode: userSettings.wideMode,
toastAdjustment:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When host is Community Cloud, toolbar items are sent - this is used as a proxy to check whether toast position should be moved up not to interfere with their Manage App button


if TYPE_CHECKING:
from streamlit.delta_generator import DeltaGenerator
from streamlit.type_util import SupportsStr


def validate_emoji(maybe_emoji: Optional[str]) -> str:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved function to string_util.py so it can be shared with toast

@mayagbarnes mayagbarnes changed the title [WIP] Feature: st.toast Feature: st.toast Jun 2, 2023
@mayagbarnes mayagbarnes added the QA-Needed QA is Required label Jun 5, 2023
@mayagbarnes mayagbarnes marked this pull request as ready for review June 5, 2023 23:11
Copy link
Collaborator

@vdonato vdonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Most of my comments are nits, but I'll probably want to take a second pass at this later given the length of the PR + app/lib split. I'm guessing this should be easy to do since this PR will likely be open awhile while waiting for QA.

It'd also be good to have @tconkling sanity check this for the app/lib split implications since I'm not yet entirely confident in my ability to reason about what should live where, but nothing stuck out to me about how everything is organized.

frontend/src/app/components/AppView/styled-components.ts Outdated Show resolved Hide resolved
e2e/specs/st_toast.spec.js Outdated Show resolved Hide resolved
lib/streamlit/elements/toast.py Outdated Show resolved Hide resolved
frontend/src/lib/components/elements/Toast/Toast.test.tsx Outdated Show resolved Hide resolved
frontend/src/lib/components/elements/Toast/Toast.test.tsx Outdated Show resolved Hide resolved
Comment on lines 52 to 54
width: "288px",
marginTop: "8px",
borderRadius: "4px",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would be nice to move these into the theme object if there are reasonable places to put them (same comment for a few other magic values in this file + throughout the PR)

@sfc-gh-dmatthews
Copy link
Contributor

Hi @mayagbarnes, I'm just working on the docs and just FYI I'm getting a nit warning on line 28 about using is instead of == with a literal.

if toast_text is "":

Cheers!

@sfc-gh-jcarroll
Copy link
Collaborator

@mayagbarnes we had a late request in office hours today to conform better with other APIs and name the first parameter body instead of text. We only use text currently for spinner and progress and everything else uses body.

I'm very sorry for missing this earlier!! If it's a big effort to change or otherwise warrants further discussion, let me know, happy to do it.

@mayagbarnes mayagbarnes added QA-Done QA is Complete and removed QA-Needed QA is Required labels Jul 11, 2023
@mayagbarnes mayagbarnes merged commit 64e1a39 into develop Jul 12, 2023
85 checks passed
@mayagbarnes mayagbarnes deleted the feature/toast branch July 12, 2023 03:21
tconkling added a commit to tconkling/streamlit that referenced this pull request Jul 12, 2023
* develop:
  Feature: st.toast (streamlit#6783)
  Bump semver from 5.7.1 to 5.7.2 in /frontend (streamlit#6982)
  Add host communication e2e tests  (streamlit#6806)
  Re-add homepage to package.json (streamlit#6987)
  Remove unnecessary code and Add rm commands to make clean (streamlit#6980)
  Allow setting placeholder for st.selectbox (streamlit#6913)
  Allow setting placeholder for st.multiselect (streamlit#6901)
  Also use bottom padding in embedded mode for chat input (streamlit#6979)
  Feature/st lib (streamlit#6692)
  Remove unused import (streamlit#6977)
  Release 1.24.1 (streamlit#6965)
  Update st.audio/st.video docstrings (streamlit#6964)
  Slightly simplify bug report template (streamlit#6972)
  Fix baseweb warnings by using longhand properties (streamlit#6976)
eric-skydio pushed a commit to eric-skydio/streamlit that referenced this pull request Dec 20, 2023
Adds a new widget for notification toasts using st.toast - covers the use case for notifications that don't disrupt the flow/organization of the existing app. This is distinct from the existing st.warning, st.error, st.success & st.info, which are inline. 
NOTE: This PR also creates a new event rendering construct in an effort to distinguish events from persistent elements like widgets. The path is as follows:
- new RootContainer constant -> EVENT
- lib/streamlit/__init__.py -> toast mapped to event.toast vs. other methods on main
- AppView.tsx has a new EventContainer that uses existing renderBlock method that takes in event elements
zyxue pushed a commit to zyxue/streamlit that referenced this pull request Mar 22, 2024
Adds a new widget for notification toasts using st.toast - covers the use case for notifications that don't disrupt the flow/organization of the existing app. This is distinct from the existing st.warning, st.error, st.success & st.info, which are inline. 
NOTE: This PR also creates a new event rendering construct in an effort to distinguish events from persistent elements like widgets. The path is as follows:
- new RootContainer constant -> EVENT
- lib/streamlit/__init__.py -> toast mapped to event.toast vs. other methods on main
- AppView.tsx has a new EventContainer that uses existing renderBlock method that takes in event elements
zyxue pushed a commit to zyxue/streamlit that referenced this pull request Apr 16, 2024
Adds a new widget for notification toasts using st.toast - covers the use case for notifications that don't disrupt the flow/organization of the existing app. This is distinct from the existing st.warning, st.error, st.success & st.info, which are inline. 
NOTE: This PR also creates a new event rendering construct in an effort to distinguish events from persistent elements like widgets. The path is as follows:
- new RootContainer constant -> EVENT
- lib/streamlit/__init__.py -> toast mapped to event.toast vs. other methods on main
- AppView.tsx has a new EventContainer that uses existing renderBlock method that takes in event elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants