date_documentation.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. from nicegui import ui
  2. from ...model import UiElementDocumentation
  3. class DateDocumentation(UiElementDocumentation, element=ui.date):
  4. def main_demo(self) -> None:
  5. ui.date(value='2023-01-01', on_change=lambda e: result.set_text(e.value))
  6. result = ui.label()
  7. def more(self) -> None:
  8. @self.demo('Input element with date picker', '''
  9. This demo shows how to implement a date picker with an input element.
  10. We place an icon in the input element's append slot.
  11. When the icon is clicked, we open a menu with a date picker.
  12. The date is bound to the input element's value.
  13. So both the input element and the date picker will stay in sync whenever the date is changed.
  14. ''')
  15. def date():
  16. with ui.input('Date') as date:
  17. with date.add_slot('append'):
  18. ui.icon('edit_calendar').on('click', lambda: menu.open()).classes('cursor-pointer')
  19. with ui.menu() as menu:
  20. ui.date().bind_value(date)
  21. @self.demo('Date filter', '''
  22. This demo shows how to filter the dates in a date picker.
  23. In order to pass a function to the date picker, we use the `:options` property.
  24. The leading `:` tells NiceGUI that the value is a JavaScript expression.
  25. ''')
  26. def date_filter():
  27. ui.date().props('''default-year-month=2023/01 :options="date => date <= '2023/01/15'"''')