You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add timeout method for ui.notification (#4444)
This PR is based on #4437 , which explores a way to make notifications
dismiss after a certain period of time.
This PR provides a method called `timeout` that allows people to
directly override the value of timeout (instead of manually modifying
the value of the props)
I did a simple test.It worked well.
```python
# notification.py (This PR did)
class Notification(Element, component='notification.js'):
...
@Property
def timeout(self) -> Optional[float]:
"""The timout value of the notification."""
return self._props['options']['timeout']
@timeout.setter
def timeout(self,value: Optional[float]) -> None:
self._props["options"]["timeout"] = (value or 0) *1000
self.update()
# test.py
import asyncio
from nicegui import ui
async def test_set_timeout():
n = ui.notification("Test Notification",timeout=None)
n.on_dismiss(lambda:print("Notification Dismiss."))
await asyncio.sleep(3)
n.message="Test Done"
n.timeout = 3 # This is a new method
ui.button("Test").on_click(test_set_timeout)
ui.run()
```
That's all.
If you have any suggestions for changes to this PR, please let me know.
Thanks a lot.
---------
Co-authored-by: Falko Schindler <[email protected]>
0 commit comments