text.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. """Components for rendering text.
  2. https://www.radix-ui.com/themes/docs/theme/typography
  3. """
  4. from __future__ import annotations
  5. from typing import Literal
  6. from reflex import el
  7. from reflex.vars import Var
  8. from ..base import (
  9. LiteralAccentColor,
  10. RadixThemesComponent,
  11. )
  12. from .base import (
  13. LiteralTextAlign,
  14. LiteralTextSize,
  15. LiteralTextTrim,
  16. LiteralTextWeight,
  17. )
  18. LiteralType = Literal["p", "label", "div", "span"]
  19. class Text(el.Span, RadixThemesComponent):
  20. """A foundational text primitive based on the <span> element."""
  21. tag = "Text"
  22. # Change the default rendered element for the one passed as a child, merging their props and behavior.
  23. as_child: Var[bool]
  24. # Change the default rendered element into a semantically appropriate alternative (cannot be used with asChild)
  25. as_: Var[LiteralType] = "p" # type: ignore
  26. # Text size: "1" - "9"
  27. size: Var[LiteralTextSize]
  28. # Thickness of text: "light" | "regular" | "medium" | "bold"
  29. weight: Var[LiteralTextWeight]
  30. # Alignment of text in element: "left" | "center" | "right"
  31. align: Var[LiteralTextAlign]
  32. # Removes the leading trim space: "normal" | "start" | "end" | "both"
  33. trim: Var[LiteralTextTrim]
  34. # Overrides the accent color inherited from the Theme.
  35. color_scheme: Var[LiteralAccentColor]
  36. # Whether to render the text with higher contrast color
  37. high_contrast: Var[bool]