flex.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """Declarative layout and common spacing props."""
  2. from __future__ import annotations
  3. from typing import Literal
  4. from reflex import el
  5. from reflex.vars import Var
  6. from ..base import (
  7. LiteralAlign,
  8. LiteralJustify,
  9. LiteralSize,
  10. )
  11. from .base import LayoutComponent
  12. LiteralFlexDirection = Literal["row", "column", "row-reverse", "column-reverse"]
  13. LiteralFlexDisplay = Literal["none", "inline-flex", "flex"]
  14. LiteralFlexWrap = Literal["nowrap", "wrap", "wrap-reverse"]
  15. class Flex(el.Div, LayoutComponent):
  16. """Component for creating flex layouts."""
  17. tag = "Flex"
  18. # Change the default rendered element for the one passed as a child, merging their props and behavior.
  19. as_child: Var[bool]
  20. # How to display the element: "none" | "inline-flex" | "flex"
  21. display: Var[LiteralFlexDisplay]
  22. # How child items are layed out: "row" | "column" | "row-reverse" | "column-reverse"
  23. direction: Var[LiteralFlexDirection]
  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. # Whether children should wrap when they reach the end of their container: "nowrap" | "wrap" | "wrap-reverse"
  29. wrap: Var[LiteralFlexWrap]
  30. # Gap between children: "0" - "9"
  31. gap: Var[LiteralSize]