typography.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.vars import Var
  7. from .base import (
  8. CommonMarginProps,
  9. LiteralAccentColor,
  10. LiteralVariant,
  11. RadixThemesComponent,
  12. )
  13. LiteralTextWeight = Literal["light", "regular", "medium", "bold"]
  14. LiteralTextAlign = Literal["left", "center", "right"]
  15. LiteralTextSize = Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"]
  16. LiteralTextTrim = Literal["normal", "start", "end", "both"]
  17. class Text(CommonMarginProps, RadixThemesComponent):
  18. """A foundational text primitive based on the <span> element."""
  19. tag: str = "Text"
  20. # Change the default rendered element for the one passed as a child, merging their props and behavior.
  21. as_child: Var[bool]
  22. # Change the default rendered element into a semantically appropriate alternative (cannot be used with asChild)
  23. as_: Var[str]
  24. # Text size: "1" - "9"
  25. size: Var[LiteralTextSize]
  26. # Thickness of text: "light" | "regular" | "medium" | "bold"
  27. weight: Var[LiteralTextWeight]
  28. # Alignment of text in element: "left" | "center" | "right"
  29. align: Var[LiteralTextAlign]
  30. # Removes the leading trim space: "normal" | "start" | "end" | "both"
  31. trim: Var[LiteralTextTrim]
  32. # Overrides the accent color inherited from the Theme.
  33. color: Var[LiteralAccentColor]
  34. # Whether to render the text with higher contrast color
  35. high_contrast: Var[bool]
  36. class Heading(Text):
  37. """A semantic heading element."""
  38. tag: str = "Heading"
  39. class Blockquote(CommonMarginProps, RadixThemesComponent):
  40. """A block level extended quotation."""
  41. tag: str = "Blockquote"
  42. # Text size: "1" - "9"
  43. size: Var[LiteralTextSize]
  44. # Thickness of text: "light" | "regular" | "medium" | "bold"
  45. weight: Var[LiteralTextWeight]
  46. # Overrides the accent color inherited from the Theme.
  47. color: Var[LiteralAccentColor]
  48. # Whether to render the text with higher contrast color
  49. high_contrast: Var[bool]
  50. class Code(Blockquote):
  51. """Marks text to signify a short fragment of computer code."""
  52. tag: str = "Code"
  53. # The visual variant to apply: "solid" | "soft" | "outline" | "ghost"
  54. variant: Var[LiteralVariant]
  55. class Em(CommonMarginProps, RadixThemesComponent):
  56. """Marks text to stress emphasis."""
  57. tag: str = "Em"
  58. class Kbd(CommonMarginProps, RadixThemesComponent):
  59. """Represents keyboard input or a hotkey."""
  60. tag: str = "Kbd"
  61. # Text size: "1" - "9"
  62. size: Var[LiteralTextSize]
  63. LiteralLinkUnderline = Literal["auto", "hover", "always"]
  64. class Link(CommonMarginProps, RadixThemesComponent):
  65. """A semantic element for navigation between pages."""
  66. tag: str = "Link"
  67. # Change the default rendered element for the one passed as a child, merging their props and behavior.
  68. as_child: Var[bool]
  69. # Text size: "1" - "9"
  70. size: Var[LiteralTextSize]
  71. # Thickness of text: "light" | "regular" | "medium" | "bold"
  72. weight: Var[LiteralTextWeight]
  73. # Removes the leading trim space: "normal" | "start" | "end" | "both"
  74. trim: Var[LiteralTextTrim]
  75. # Sets the visibility of the underline affordance: "auto" | "hover" | "always"
  76. underline: Var[LiteralLinkUnderline]
  77. # Overrides the accent color inherited from the Theme.
  78. color: Var[LiteralAccentColor]
  79. # Whether to render the text with higher contrast color
  80. high_contrast: Var[bool]
  81. class Quote(CommonMarginProps, RadixThemesComponent):
  82. """A short inline quotation."""
  83. tag: str = "Quote"
  84. class Strong(CommonMarginProps, RadixThemesComponent):
  85. """Marks text to signify strong importance."""
  86. tag: str = "Strong"