card_documentation.py 1.8 KB

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