1
0

card_documentation.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from nicegui import ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. with ui.card().tight() as card:
  5. ui.image('https://picsum.photos/id/684/640/360')
  6. with ui.card_section():
  7. ui.label('Lorem ipsum dolor sit amet, consectetur adipiscing elit, ...')
  8. def more() -> None:
  9. @text_demo('The issue with nested borders', '''
  10. The following example shows a table nested in a card.
  11. Cards have a default padding in NiceGUI, so the table is not flush with the card's border.
  12. The table has the `flat` and `bordered` props set, so it should have a border.
  13. However, due to the way QCard is designed, the border is not visible (first card).
  14. There are two ways to fix this:
  15. - To get the original QCard behavior, use the `tight` method (second card).
  16. It removes the padding and the table border collapses with the card border.
  17. - To preserve the padding _and_ the table border, move the table into another container like a `ui.row` (third card).
  18. See https://github.com/zauberzeug/nicegui/issues/726 for more information.
  19. ''')
  20. def custom_context_menu() -> None:
  21. columns = [{'name': 'age', 'label': 'Age', 'field': 'age'}]
  22. rows = [{'age': '16'}, {'age': '18'}, {'age': '21'}]
  23. with ui.row():
  24. with ui.card():
  25. ui.table(columns, rows).props('flat bordered')
  26. with ui.card().tight():
  27. ui.table(columns, rows).props('flat bordered')
  28. with ui.card():
  29. with ui.row():
  30. ui.table(columns, rows).props('flat bordered')