1
0

time_documentation.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.time)
  4. def main_demo() -> None:
  5. ui.time(value='12:00', on_change=lambda e: result.set_text(e.value))
  6. result = ui.label()
  7. @doc.demo('Input element with time picker', '''
  8. This demo shows how to implement a time picker with an input element.
  9. We place an icon in the input element's append slot.
  10. When the icon is clicked, we open a menu with a time picker.
  11. [QMenu](https://quasar.dev/vue-components/menu)'s "no-parent-event" prop is used
  12. to prevent opening the menu when clicking into the input field.
  13. As the menu doesn't come with a "Close" button by default, we add one for convenience.
  14. The time is bound to the input element's value.
  15. So both the input element and the time picker will stay in sync whenever the time is changed.
  16. ''')
  17. def time_picker_demo():
  18. with ui.input('Time') as time:
  19. with ui.menu().props('no-parent-event') as menu:
  20. with ui.time().bind_value(time):
  21. with ui.row().classes('justify-end'):
  22. ui.button('Close', on_click=menu.close).props('flat')
  23. with time.add_slot('append'):
  24. ui.icon('access_time').on('click', menu.open).classes('cursor-pointer')
  25. doc.reference(ui.time)