typography.py 3.5 KB

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