grid.py 1.6 KB

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