input_documentation.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from nicegui import ui
  2. from ...model import UiElementDocumentation
  3. class InputDocumentation(UiElementDocumentation, element=ui.input):
  4. def main_demo(self) -> None:
  5. ui.input(label='Text', placeholder='start typing',
  6. on_change=lambda e: result.set_text('you typed: ' + e.value),
  7. validation={'Input too long': lambda value: len(value) < 20})
  8. result = ui.label()
  9. def more(self) -> None:
  10. @self.demo('Autocompletion', '''
  11. The `autocomplete` feature provides suggestions as you type, making input easier and faster.
  12. The parameter `options` is a list of strings that contains the available options that will appear.
  13. ''')
  14. def autocomplete_demo():
  15. options = ['AutoComplete', 'NiceGUI', 'Awesome']
  16. ui.input(label='Text', placeholder='start typing', autocomplete=options)
  17. @self.demo('Clearable', '''
  18. The `clearable` prop from [Quasar](https://quasar.dev/) adds a button to the input that clears the text.
  19. ''')
  20. def clearable():
  21. i = ui.input(value='some text').props('clearable')
  22. ui.label().bind_text_from(i, 'value')
  23. @self.demo('Styling', '''
  24. Quasar has a lot of [props to change the appearance](https://quasar.dev/vue-components/input).
  25. It is even possible to style the underlying input with `input-style` and `input-class` props
  26. and use the provided slots to add custom elements.
  27. ''')
  28. def styling():
  29. ui.input(placeholder='start typing').props('rounded outlined dense')
  30. ui.input('styling', value='some text') \
  31. .props('input-style="color: blue" input-class="font-mono"')
  32. with ui.input(value='custom clear button').classes('w-64') as i:
  33. ui.button(color='orange-8', on_click=lambda: i.set_value(None), icon='delete') \
  34. .props('flat dense').bind_visibility_from(i, 'value')