column_documentation.py 900 B

123456789101112131415161718192021222324252627
  1. from nicegui import ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. with ui.column():
  5. ui.label('label 1')
  6. ui.label('label 2')
  7. ui.label('label 3')
  8. def more() -> None:
  9. @text_demo('Masonry or Pinterest-Style Layout', '''
  10. To create a masonry/pinterest layout, the normal ui.column can not be used.
  11. But it can be archived with a few Tailwind CSS classes.
  12. ''')
  13. def masonry() -> None:
  14. from random import choice, randint
  15. with ui.element('div').classes('columns-3 w-full gap-2'):
  16. for i in range(0, 9):
  17. height = f'h-{choice([8, 12, 14, 16, 20])}'
  18. color = f'bg-sky-{randint(1,5)}00'
  19. classes = f'w-full mb-2 {height} {color} break-inside-avoid'
  20. with ui.element('div').classes(classes):
  21. ui.label(f'Content #{i+1}')