grid.py 1.7 KB

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