input_documentation.py 1.8 KB

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