grid.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """Declarative layout and common spacing props."""
  2. from __future__ import annotations
  3. from typing import Dict, Literal
  4. from reflex import el
  5. from reflex.vars import Var
  6. from ..base import (
  7. LiteralAlign,
  8. LiteralJustify,
  9. LiteralSpacing,
  10. RadixThemesComponent,
  11. )
  12. LiteralGridFlow = Literal["row", "column", "dense", "row-dense", "column-dense"]
  13. class Grid(el.Div, RadixThemesComponent):
  14. """Component for creating grid layouts."""
  15. tag = "Grid"
  16. # Change the default rendered element for the one passed as a child, merging their props and behavior.
  17. as_child: Var[bool]
  18. # Number of columns
  19. columns: Var[str]
  20. # Number of rows
  21. rows: Var[str]
  22. # How the grid items are layed out: "row" | "column" | "dense" | "row-dense" | "column-dense"
  23. flow: Var[LiteralGridFlow]
  24. # Alignment of children along the main axis: "start" | "center" | "end" | "baseline" | "stretch"
  25. align: Var[LiteralAlign]
  26. # Alignment of children along the cross axis: "start" | "center" | "end" | "between"
  27. justify: Var[LiteralJustify]
  28. # Gap between children: "0" - "9"
  29. spacing: Var[LiteralSpacing]
  30. # Gap between children horizontal: "0" - "9"
  31. spacing_x: Var[LiteralSpacing]
  32. # Gap between children vertical: "0" - "9"
  33. spacing_y: Var[LiteralSpacing]
  34. # Reflex maps the "spacing" prop to "gap" prop.
  35. _rename_props: Dict[str, str] = {
  36. "spacing": "gap",
  37. "spacing_x": "gap_x",
  38. "spacing_y": "gap_y",
  39. }