card_documentation.py 2.2 KB

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