sticky.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. """Components for displaying the Reflex sticky logo."""
  2. from reflex.components.component import ComponentNamespace
  3. from reflex.components.core.colors import color
  4. from reflex.components.core.cond import color_mode_cond
  5. from reflex.components.core.responsive import desktop_only
  6. from reflex.components.el.elements.inline import A
  7. from reflex.components.el.elements.media import Path, Rect, Svg
  8. from reflex.components.radix.themes.typography.text import Text
  9. from reflex.style import Style
  10. class StickyLogo(Svg):
  11. """A simple Reflex logo SVG with only the letter R."""
  12. @classmethod
  13. def create(cls):
  14. """Create the simple Reflex logo SVG.
  15. Returns:
  16. The simple Reflex logo SVG.
  17. """
  18. return super().create(
  19. Rect.create(width="16", height="16", rx="2", fill="#6E56CF"),
  20. Path.create(d="M10 9V13H12V9H10Z", fill="white"),
  21. Path.create(d="M4 3V13H6V9H10V7H6V5H10V7H12V3H4Z", fill="white"),
  22. width="16",
  23. height="16",
  24. viewBox="0 0 16 16",
  25. xmlns="http://www.w3.org/2000/svg",
  26. )
  27. def add_style(self):
  28. """Add the style to the component.
  29. Returns:
  30. The style of the component.
  31. """
  32. return Style(
  33. {
  34. "fill": "white",
  35. }
  36. )
  37. class StickyLabel(Text):
  38. """A label that displays the Reflex sticky."""
  39. @classmethod
  40. def create(cls):
  41. """Create the sticky label.
  42. Returns:
  43. The sticky label.
  44. """
  45. return super().create("Built with Reflex")
  46. def add_style(self):
  47. """Add the style to the component.
  48. Returns:
  49. The style of the component.
  50. """
  51. return Style(
  52. {
  53. "color": color("slate", 1),
  54. "font_weight": "600",
  55. "font_family": "'Instrument Sans', sans-serif",
  56. "font_size": "0.875rem",
  57. "line_height": "1rem",
  58. "letter_spacing": "-0.00656rem",
  59. }
  60. )
  61. class StickyBadge(A):
  62. """A badge that displays the Reflex sticky logo."""
  63. @classmethod
  64. def create(cls):
  65. """Create the sticky badge.
  66. Returns:
  67. The sticky badge.
  68. """
  69. return super().create(
  70. StickyLogo.create(),
  71. desktop_only(StickyLabel.create()),
  72. href="https://reflex.dev",
  73. target="_blank",
  74. width="auto",
  75. padding="0.375rem",
  76. align="center",
  77. text_align="center",
  78. )
  79. def add_style(self):
  80. """Add the style to the component.
  81. Returns:
  82. The style of the component.
  83. """
  84. return Style(
  85. {
  86. "position": "fixed",
  87. "bottom": "1rem",
  88. "right": "1rem",
  89. "display": "flex",
  90. "flex-direction": "row",
  91. "gap": "0.375rem",
  92. "align-items": "center",
  93. "width": "auto",
  94. "border-radius": "0.5rem",
  95. "color": color_mode_cond("#E5E7EB", "#27282B"),
  96. "border": color_mode_cond("1px solid #27282B", "1px solid #E5E7EB"),
  97. "background-color": color_mode_cond("#151618", "#FCFCFD"),
  98. "padding": "0.375rem",
  99. "transition": "background-color 0.2s ease-in-out",
  100. "box-shadow": "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
  101. "z-index": "9998",
  102. "cursor": "pointer",
  103. },
  104. )
  105. class StickyNamespace(ComponentNamespace):
  106. """Sticky components namespace."""
  107. __call__ = staticmethod(StickyBadge.create)
  108. label = staticmethod(StickyLabel.create)
  109. logo = staticmethod(StickyLogo.create)
  110. sticky = StickyNamespace()