flex.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. LiteralFlexDirection = Literal["row", "column", "row-reverse", "column-reverse"]
  13. LiteralFlexWrap = Literal["nowrap", "wrap", "wrap-reverse"]
  14. class Flex(el.Div, RadixThemesComponent):
  15. """Component for creating flex layouts."""
  16. tag = "Flex"
  17. # Change the default rendered element for the one passed as a child, merging their props and behavior.
  18. as_child: Var[bool]
  19. # How child items are layed out: "row" | "column" | "row-reverse" | "column-reverse"
  20. direction: Var[LiteralFlexDirection]
  21. # Alignment of children along the main axis: "start" | "center" | "end" | "baseline" | "stretch"
  22. align: Var[LiteralAlign]
  23. # Alignment of children along the cross axis: "start" | "center" | "end" | "between"
  24. justify: Var[LiteralJustify]
  25. # Whether children should wrap when they reach the end of their container: "nowrap" | "wrap" | "wrap-reverse"
  26. wrap: Var[LiteralFlexWrap]
  27. # Gap between children: "0" - "9"
  28. spacing: Var[LiteralSpacing]
  29. # Reflex maps the "spacing" prop to "gap" prop.
  30. _rename_props: Dict[str, str] = {"spacing": "gap"}