1
0

intro.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from typing import Callable
  2. from nicegui import ui
  3. from ..style import subheading
  4. from .demo import demo
  5. def create_intro() -> None:
  6. @_main_page_demo('Styling', '''
  7. While having reasonable defaults, you can still modify the look of your app with CSS as well as Tailwind and Quasar classes.
  8. ''')
  9. def formatting_demo():
  10. ui.icon('thumb_up')
  11. ui.markdown('This is **Markdown**.')
  12. ui.html('This is <strong>HTML</strong>.')
  13. with ui.row():
  14. ui.label('CSS').style('color: #888; font-weight: bold')
  15. ui.label('Tailwind').classes('font-serif')
  16. ui.label('Quasar').classes('q-ml-xl')
  17. ui.link('NiceGUI on GitHub', 'https://github.com/zauberzeug/nicegui')
  18. @_main_page_demo('Common UI Elements', '''
  19. NiceGUI comes with a collection of commonly used UI elements.
  20. ''')
  21. def common_elements_demo():
  22. from nicegui.events import ValueChangeEventArguments
  23. def show(event: ValueChangeEventArguments):
  24. name = type(event.sender).__name__
  25. ui.notify(f'{name}: {event.value}')
  26. ui.button('Button', on_click=lambda: ui.notify('Click'))
  27. with ui.row():
  28. ui.checkbox('Checkbox', on_change=show)
  29. ui.switch('Switch', on_change=show)
  30. ui.radio(['A', 'B', 'C'], value='A', on_change=show).props('inline')
  31. with ui.row():
  32. ui.input('Text input', on_change=show)
  33. ui.select(['One', 'Two'], value='One', on_change=show)
  34. ui.link('And many more...', '/documentation').classes('mt-8')
  35. @_main_page_demo('Value Binding', '''
  36. Binding values between UI elements and data models is built into NiceGUI.
  37. ''')
  38. def binding_demo():
  39. class Demo:
  40. def __init__(self):
  41. self.number = 1
  42. demo = Demo()
  43. v = ui.checkbox('visible', value=True)
  44. with ui.column().bind_visibility_from(v, 'value'):
  45. ui.slider(min=1, max=3).bind_value(demo, 'number')
  46. ui.toggle({1: 'A', 2: 'B', 3: 'C'}).bind_value(demo, 'number')
  47. ui.number().bind_value(demo, 'number')
  48. def _main_page_demo(title: str, explanation: str) -> Callable:
  49. def decorator(f: Callable) -> Callable:
  50. subheading(title)
  51. ui.markdown(explanation).classes('bold-links arrow-links')
  52. return demo(f)
  53. return decorator