date_documentation.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.date)
  4. def main_demo() -> None:
  5. ui.date(value='2023-01-01', on_change=lambda e: result.set_text(e.value))
  6. result = ui.label()
  7. @doc.demo('Input element with date picker', '''
  8. This demo shows how to implement a date 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 date 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 date is bound to the input element's value.
  15. So both the input element and the date picker will stay in sync whenever the date is changed.
  16. ''')
  17. def date_picker_demo():
  18. with ui.input('Date') as date:
  19. with ui.menu().props('no-parent-event') as menu:
  20. with ui.date().bind_value(date):
  21. with ui.row().classes('justify-end'):
  22. ui.button('Close', on_click=menu.close).props('flat')
  23. with date.add_slot('append'):
  24. ui.icon('edit_calendar').on('click', menu.open).classes('cursor-pointer')
  25. @doc.demo('Date filter', '''
  26. This demo shows how to filter the dates in a date picker.
  27. In order to pass a function to the date picker, we use the `:options` property.
  28. The leading `:` tells NiceGUI that the value is a JavaScript expression.
  29. ''')
  30. def date_filter():
  31. ui.date().props('''default-year-month=2023/01 :options="date => date <= '2023/01/15'"''')
  32. doc.reference(ui.date)