reflex 0.3.9a3__py3-none-any.whl → 0.3.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of reflex might be problematic. Click here for more details.

Files changed (247) hide show
  1. reflex/__init__.py +3 -1
  2. reflex/__init__.pyi +3 -1
  3. reflex/app.py +116 -86
  4. reflex/compiler/compiler.py +110 -0
  5. reflex/compiler/utils.py +13 -12
  6. reflex/components/base/app_wrap.pyi +1 -0
  7. reflex/components/base/body.pyi +2 -0
  8. reflex/components/base/document.pyi +10 -0
  9. reflex/components/base/fragment.pyi +2 -0
  10. reflex/components/base/head.pyi +4 -0
  11. reflex/components/base/link.pyi +4 -0
  12. reflex/components/base/meta.pyi +8 -0
  13. reflex/components/base/script.pyi +2 -0
  14. reflex/components/chakra/base.pyi +7 -0
  15. reflex/components/chakra/datadisplay/badge.pyi +2 -0
  16. reflex/components/chakra/datadisplay/code.pyi +4 -0
  17. reflex/components/chakra/datadisplay/divider.pyi +2 -0
  18. reflex/components/chakra/datadisplay/keyboard_key.pyi +2 -0
  19. reflex/components/chakra/datadisplay/list.pyi +8 -0
  20. reflex/components/chakra/datadisplay/stat.pyi +12 -0
  21. reflex/components/chakra/datadisplay/table.pyi +18 -0
  22. reflex/components/chakra/datadisplay/tag.pyi +9 -0
  23. reflex/components/chakra/disclosure/accordion.pyi +10 -0
  24. reflex/components/chakra/disclosure/tabs.py +8 -0
  25. reflex/components/chakra/disclosure/tabs.pyi +10 -0
  26. reflex/components/chakra/disclosure/transition.pyi +12 -0
  27. reflex/components/chakra/disclosure/visuallyhidden.pyi +2 -0
  28. reflex/components/chakra/feedback/alert.pyi +8 -0
  29. reflex/components/chakra/feedback/circularprogress.pyi +4 -0
  30. reflex/components/chakra/feedback/progress.pyi +2 -0
  31. reflex/components/chakra/feedback/skeleton.pyi +6 -0
  32. reflex/components/chakra/feedback/spinner.pyi +2 -0
  33. reflex/components/chakra/forms/button.pyi +4 -0
  34. reflex/components/chakra/forms/checkbox.pyi +4 -0
  35. reflex/components/chakra/forms/colormodeswitch.pyi +7 -0
  36. reflex/components/chakra/forms/date_picker.pyi +2 -0
  37. reflex/components/chakra/forms/date_time_picker.pyi +2 -0
  38. reflex/components/chakra/forms/editable.pyi +8 -0
  39. reflex/components/chakra/forms/email.pyi +2 -0
  40. reflex/components/chakra/forms/form.pyi +10 -0
  41. reflex/components/chakra/forms/iconbutton.py +1 -0
  42. reflex/components/chakra/forms/iconbutton.pyi +2 -0
  43. reflex/components/chakra/forms/input.pyi +12 -0
  44. reflex/components/chakra/forms/numberinput.pyi +10 -0
  45. reflex/components/chakra/forms/password.pyi +2 -0
  46. reflex/components/chakra/forms/pininput.pyi +4 -0
  47. reflex/components/chakra/forms/radio.pyi +4 -0
  48. reflex/components/chakra/forms/rangeslider.pyi +8 -0
  49. reflex/components/chakra/forms/select.pyi +4 -0
  50. reflex/components/chakra/forms/slider.pyi +10 -0
  51. reflex/components/chakra/forms/switch.pyi +2 -0
  52. reflex/components/chakra/forms/textarea.pyi +2 -0
  53. reflex/components/chakra/forms/time_picker.pyi +2 -0
  54. reflex/components/chakra/layout/aspect_ratio.pyi +2 -0
  55. reflex/components/chakra/layout/box.pyi +2 -0
  56. reflex/components/chakra/layout/card.pyi +7 -0
  57. reflex/components/chakra/layout/center.pyi +6 -0
  58. reflex/components/chakra/layout/container.pyi +2 -0
  59. reflex/components/chakra/layout/flex.pyi +2 -0
  60. reflex/components/chakra/layout/grid.pyi +6 -0
  61. reflex/components/chakra/layout/html.pyi +2 -0
  62. reflex/components/chakra/layout/spacer.pyi +2 -0
  63. reflex/components/chakra/layout/stack.pyi +6 -0
  64. reflex/components/chakra/layout/wrap.pyi +4 -0
  65. reflex/components/chakra/media/avatar.pyi +6 -0
  66. reflex/components/chakra/media/icon.pyi +4 -0
  67. reflex/components/chakra/media/image.pyi +2 -0
  68. reflex/components/chakra/navigation/breadcrumb.pyi +8 -0
  69. reflex/components/chakra/navigation/link.pyi +2 -0
  70. reflex/components/chakra/navigation/linkoverlay.pyi +4 -0
  71. reflex/components/chakra/navigation/stepper.pyi +18 -0
  72. reflex/components/chakra/overlay/alertdialog.pyi +14 -0
  73. reflex/components/chakra/overlay/drawer.pyi +14 -0
  74. reflex/components/chakra/overlay/menu.pyi +16 -0
  75. reflex/components/chakra/overlay/modal.pyi +14 -0
  76. reflex/components/chakra/overlay/popover.pyi +18 -0
  77. reflex/components/chakra/overlay/tooltip.pyi +2 -0
  78. reflex/components/chakra/typography/heading.pyi +2 -0
  79. reflex/components/chakra/typography/highlight.pyi +2 -0
  80. reflex/components/chakra/typography/span.pyi +2 -0
  81. reflex/components/chakra/typography/text.pyi +2 -0
  82. reflex/components/component.py +41 -3
  83. reflex/components/core/__init__.py +2 -0
  84. reflex/components/core/banner.pyi +3 -0
  85. reflex/components/core/client_side_routing.pyi +4 -0
  86. reflex/components/core/colors.py +21 -0
  87. reflex/components/core/cond.py +11 -2
  88. reflex/components/core/debounce.pyi +1 -0
  89. reflex/components/core/layout/__init__.py +1 -0
  90. reflex/components/core/match.py +44 -18
  91. reflex/components/core/upload.py +8 -2
  92. reflex/components/core/upload.pyi +7 -1
  93. reflex/components/datadisplay/dataeditor.pyi +2 -0
  94. reflex/components/el/element.pyi +2 -0
  95. reflex/components/el/elements/base.pyi +2 -0
  96. reflex/components/el/elements/forms.py +3 -0
  97. reflex/components/el/elements/forms.pyi +32 -0
  98. reflex/components/el/elements/inline.pyi +56 -0
  99. reflex/components/el/elements/media.pyi +28 -0
  100. reflex/components/el/elements/metadata.pyi +10 -0
  101. reflex/components/el/elements/other.pyi +14 -0
  102. reflex/components/el/elements/scripts.pyi +6 -0
  103. reflex/components/el/elements/sectioning.pyi +30 -0
  104. reflex/components/el/elements/tables.pyi +20 -0
  105. reflex/components/el/elements/typography.pyi +30 -0
  106. reflex/components/gridjs/datatable.pyi +4 -0
  107. reflex/components/lucide/__init__.py +5 -0
  108. reflex/components/lucide/icon.py +1484 -0
  109. reflex/components/lucide/icon.pyi +1594 -0
  110. reflex/components/markdown/markdown.pyi +2 -0
  111. reflex/components/moment/moment.pyi +2 -0
  112. reflex/components/next/base.pyi +2 -0
  113. reflex/components/next/image.pyi +2 -0
  114. reflex/components/next/link.pyi +2 -0
  115. reflex/components/next/video.pyi +2 -0
  116. reflex/components/plotly/plotly.pyi +4 -0
  117. reflex/components/radix/primitives/__init__.py +10 -0
  118. reflex/components/radix/primitives/accordion.py +51 -32
  119. reflex/components/radix/primitives/accordion.pyi +16 -3
  120. reflex/components/radix/primitives/base.pyi +4 -0
  121. reflex/components/radix/primitives/drawer.py +240 -0
  122. reflex/components/radix/primitives/drawer.pyi +814 -0
  123. reflex/components/radix/primitives/form.py +40 -7
  124. reflex/components/radix/primitives/form.pyi +32 -10
  125. reflex/components/radix/primitives/progress.py +2 -2
  126. reflex/components/radix/primitives/progress.pyi +6 -0
  127. reflex/components/radix/primitives/slider.pyi +10 -0
  128. reflex/components/radix/themes/base.py +46 -12
  129. reflex/components/radix/themes/base.pyi +23 -9
  130. reflex/components/radix/themes/components/__init__.py +4 -2
  131. reflex/components/radix/themes/components/alertdialog.py +13 -12
  132. reflex/components/radix/themes/components/alertdialog.pyi +23 -351
  133. reflex/components/radix/themes/components/aspectratio.py +2 -5
  134. reflex/components/radix/themes/components/aspectratio.pyi +4 -51
  135. reflex/components/radix/themes/components/avatar.py +3 -4
  136. reflex/components/radix/themes/components/avatar.pyi +4 -57
  137. reflex/components/radix/themes/components/badge.py +3 -4
  138. reflex/components/radix/themes/components/badge.pyi +4 -56
  139. reflex/components/radix/themes/components/button.py +2 -3
  140. reflex/components/radix/themes/components/button.pyi +3 -51
  141. reflex/components/radix/themes/components/callout.py +9 -12
  142. reflex/components/radix/themes/components/callout.pyi +24 -217
  143. reflex/components/radix/themes/components/card.py +1 -2
  144. reflex/components/radix/themes/components/card.pyi +4 -51
  145. reflex/components/radix/themes/components/checkbox.py +11 -5
  146. reflex/components/radix/themes/components/checkbox.pyi +13 -112
  147. reflex/components/radix/themes/components/contextmenu.py +21 -21
  148. reflex/components/radix/themes/components/contextmenu.pyi +26 -401
  149. reflex/components/radix/themes/components/dialog.py +13 -16
  150. reflex/components/radix/themes/components/dialog.pyi +20 -303
  151. reflex/components/radix/themes/components/dropdownmenu.py +196 -32
  152. reflex/components/radix/themes/components/dropdownmenu.pyi +147 -389
  153. reflex/components/radix/themes/components/hovercard.py +5 -5
  154. reflex/components/radix/themes/components/hovercard.pyi +11 -151
  155. reflex/components/radix/themes/components/iconbutton.py +56 -4
  156. reflex/components/radix/themes/components/iconbutton.pyi +25 -71
  157. reflex/components/radix/themes/components/icons.pyi +4 -0
  158. reflex/components/radix/themes/components/inset.py +1 -2
  159. reflex/components/radix/themes/components/inset.pyi +4 -51
  160. reflex/components/radix/themes/components/popover.py +12 -12
  161. reflex/components/radix/themes/components/popover.pyi +14 -201
  162. reflex/components/radix/themes/components/radiogroup.py +47 -20
  163. reflex/components/radix/themes/components/radiogroup.pyi +26 -171
  164. reflex/components/radix/themes/components/scrollarea.py +2 -3
  165. reflex/components/radix/themes/components/scrollarea.pyi +4 -51
  166. reflex/components/radix/themes/components/select.py +28 -25
  167. reflex/components/radix/themes/components/select.pyi +43 -419
  168. reflex/components/radix/themes/components/separator.py +4 -5
  169. reflex/components/radix/themes/components/separator.pyi +5 -52
  170. reflex/components/radix/themes/components/slider.py +8 -5
  171. reflex/components/radix/themes/components/slider.pyi +9 -60
  172. reflex/components/radix/themes/components/switch.py +6 -4
  173. reflex/components/radix/themes/components/switch.pyi +5 -53
  174. reflex/components/radix/themes/components/table.py +14 -15
  175. reflex/components/radix/themes/components/table.pyi +22 -351
  176. reflex/components/radix/themes/components/tabs.py +9 -6
  177. reflex/components/radix/themes/components/tabs.pyi +18 -205
  178. reflex/components/radix/themes/components/textarea.py +2 -3
  179. reflex/components/radix/themes/components/textarea.pyi +10 -53
  180. reflex/components/radix/themes/components/textfield.py +105 -4
  181. reflex/components/radix/themes/components/textfield.pyi +200 -108
  182. reflex/components/radix/themes/components/tooltip.py +102 -2
  183. reflex/components/radix/themes/components/tooltip.pyi +66 -110
  184. reflex/components/radix/themes/layout/__init__.py +7 -0
  185. reflex/components/radix/themes/layout/base.pyi +2 -0
  186. reflex/components/radix/themes/layout/box.py +2 -2
  187. reflex/components/radix/themes/layout/box.pyi +4 -104
  188. reflex/components/radix/themes/layout/center.py +19 -0
  189. reflex/components/radix/themes/layout/center.pyi +261 -0
  190. reflex/components/radix/themes/layout/container.py +2 -2
  191. reflex/components/radix/themes/layout/container.pyi +4 -104
  192. reflex/components/radix/themes/layout/flex.py +2 -2
  193. reflex/components/radix/themes/layout/flex.pyi +4 -105
  194. reflex/components/radix/themes/layout/grid.pyi +2 -0
  195. reflex/components/radix/themes/layout/section.py +2 -2
  196. reflex/components/radix/themes/layout/section.pyi +4 -104
  197. reflex/components/radix/themes/layout/spacer.py +19 -0
  198. reflex/components/radix/themes/layout/spacer.pyi +261 -0
  199. reflex/components/radix/themes/layout/stack.py +60 -0
  200. reflex/components/radix/themes/layout/stack.pyi +537 -0
  201. reflex/components/radix/themes/typography/blockquote.py +2 -3
  202. reflex/components/radix/themes/typography/blockquote.pyi +4 -51
  203. reflex/components/radix/themes/typography/code.py +2 -3
  204. reflex/components/radix/themes/typography/code.pyi +4 -56
  205. reflex/components/radix/themes/typography/em.py +1 -2
  206. reflex/components/radix/themes/typography/em.pyi +4 -51
  207. reflex/components/radix/themes/typography/heading.py +2 -3
  208. reflex/components/radix/themes/typography/heading.pyi +4 -51
  209. reflex/components/radix/themes/typography/kbd.py +1 -2
  210. reflex/components/radix/themes/typography/kbd.pyi +4 -51
  211. reflex/components/radix/themes/typography/link.py +34 -3
  212. reflex/components/radix/themes/typography/link.pyi +41 -86
  213. reflex/components/radix/themes/typography/quote.py +1 -2
  214. reflex/components/radix/themes/typography/quote.pyi +4 -51
  215. reflex/components/radix/themes/typography/strong.py +1 -2
  216. reflex/components/radix/themes/typography/strong.pyi +4 -51
  217. reflex/components/radix/themes/typography/text.py +2 -3
  218. reflex/components/radix/themes/typography/text.pyi +4 -51
  219. reflex/components/radix/themes/typography.py +10 -11
  220. reflex/components/react_player/audio.pyi +2 -0
  221. reflex/components/react_player/react_player.pyi +2 -0
  222. reflex/components/react_player/video.pyi +2 -0
  223. reflex/components/recharts/cartesian.pyi +38 -0
  224. reflex/components/recharts/charts.pyi +22 -0
  225. reflex/components/recharts/general.pyi +10 -0
  226. reflex/components/recharts/polar.pyi +12 -0
  227. reflex/components/recharts/recharts.pyi +4 -0
  228. reflex/components/suneditor/editor.pyi +2 -0
  229. reflex/components/tags/tag.py +1 -1
  230. reflex/constants/base.py +5 -1
  231. reflex/constants/colors.py +80 -0
  232. reflex/constants/event.py +10 -1
  233. reflex/page.py +1 -1
  234. reflex/reflex.py +4 -0
  235. reflex/style.py +8 -3
  236. reflex/testing.py +21 -10
  237. reflex/utils/format.py +13 -9
  238. reflex/utils/prerequisites.py +41 -3
  239. reflex/utils/serializers.py +14 -0
  240. reflex/utils/telemetry.py +8 -2
  241. reflex/utils/types.py +36 -2
  242. reflex/vars.py +53 -18
  243. {reflex-0.3.9a3.dist-info → reflex-0.3.10.dist-info}/METADATA +1 -2
  244. {reflex-0.3.9a3.dist-info → reflex-0.3.10.dist-info}/RECORD +247 -233
  245. {reflex-0.3.9a3.dist-info → reflex-0.3.10.dist-info}/WHEEL +1 -1
  246. {reflex-0.3.9a3.dist-info → reflex-0.3.10.dist-info}/LICENSE +0 -0
  247. {reflex-0.3.9a3.dist-info → reflex-0.3.10.dist-info}/entry_points.txt +0 -0
@@ -115,7 +115,7 @@ class BaseComponent(Base, ABC):
115
115
 
116
116
 
117
117
  # Map from component to styling.
118
- ComponentStyle = Dict[Union[str, Type[BaseComponent]], Any]
118
+ ComponentStyle = Dict[Union[str, Type[BaseComponent], Callable], Any]
119
119
  ComponentChild = Union[types.PrimitiveType, Var, BaseComponent]
120
120
 
121
121
 
@@ -155,6 +155,12 @@ class Component(BaseComponent, ABC):
155
155
  # only components that are allowed as children
156
156
  _valid_children: List[str] = []
157
157
 
158
+ # only components that are allowed as parent
159
+ _valid_parents: List[str] = []
160
+
161
+ # props to change the name of
162
+ _rename_props: Dict[str, str] = {}
163
+
158
164
  # custom attribute
159
165
  custom_attrs: Dict[str, Union[Var, str]] = {}
160
166
 
@@ -597,10 +603,13 @@ class Component(BaseComponent, ABC):
597
603
  Returns:
598
604
  The component with the additional style.
599
605
  """
606
+ component_style = None
600
607
  if type(self) in style:
601
608
  # Extract the style for this component.
602
609
  component_style = Style(style[type(self)])
603
-
610
+ if self.create in style:
611
+ component_style = Style(style[self.create])
612
+ if component_style is not None:
604
613
  # Only add style props that are not overridden.
605
614
  component_style = {
606
615
  k: v for k, v in component_style.items() if k not in self.style
@@ -642,8 +651,24 @@ class Component(BaseComponent, ABC):
642
651
  ),
643
652
  autofocus=self.autofocus,
644
653
  )
654
+ self._replace_prop_names(rendered_dict)
645
655
  return rendered_dict
646
656
 
657
+ def _replace_prop_names(self, rendered_dict) -> None:
658
+ """Replace the prop names in the render dictionary.
659
+
660
+ Args:
661
+ rendered_dict: The render dictionary with all the component props and event handlers.
662
+ """
663
+ # fast path
664
+ if not self._rename_props:
665
+ return
666
+
667
+ for ix, prop in enumerate(rendered_dict["props"]):
668
+ for old_prop, new_prop in self._rename_props.items():
669
+ if prop.startswith(old_prop):
670
+ rendered_dict["props"][ix] = prop.replace(old_prop, new_prop)
671
+
647
672
  def _validate_component_children(self, children: List[Component]):
648
673
  """Validate the children components.
649
674
 
@@ -651,7 +676,8 @@ class Component(BaseComponent, ABC):
651
676
  children: The children of the component.
652
677
 
653
678
  """
654
- if not self._invalid_children and not self._valid_children:
679
+ skip_parentable = all(child._valid_parents == [] for child in children)
680
+ if not self._invalid_children and not self._valid_children and skip_parentable:
655
681
  return
656
682
 
657
683
  comp_name = type(self).__name__
@@ -671,6 +697,15 @@ class Component(BaseComponent, ABC):
671
697
  f"The component `{comp_name}` only allows the components: {valid_child_list} as children. Got `{child_name}` instead."
672
698
  )
673
699
 
700
+ def validate_vaild_parent(child_name, valid_parents):
701
+ if comp_name not in valid_parents:
702
+ valid_parent_list = ", ".join(
703
+ [f"`{v_parent}`" for v_parent in valid_parents]
704
+ )
705
+ raise ValueError(
706
+ f"The component `{child_name}` can only be a child of the components: {valid_parent_list}. Got `{comp_name}` instead."
707
+ )
708
+
674
709
  for child in children:
675
710
  name = type(child).__name__
676
711
 
@@ -680,6 +715,9 @@ class Component(BaseComponent, ABC):
680
715
  if self._valid_children:
681
716
  validate_valid_child(name)
682
717
 
718
+ if child._valid_parents:
719
+ validate_vaild_parent(name, child._valid_parents)
720
+
683
721
  @staticmethod
684
722
  def _get_vars_from_event_triggers(
685
723
  event_triggers: dict[str, EventChain | Var],
@@ -1,6 +1,8 @@
1
1
  """Core Reflex components."""
2
2
 
3
+ from . import layout as layout
3
4
  from .banner import ConnectionBanner, ConnectionModal
5
+ from .colors import color
4
6
  from .cond import Cond, cond
5
7
  from .debounce import DebounceInput
6
8
  from .foreach import Foreach
@@ -34,6 +34,7 @@ class WebsocketTargetURL(Bare):
34
34
  id: Optional[Any] = None,
35
35
  class_name: Optional[Any] = None,
36
36
  autofocus: Optional[bool] = None,
37
+ _rename_props: Optional[Dict[str, str]] = None,
37
38
  custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
38
39
  on_blur: Optional[
39
40
  Union[EventHandler, EventSpec, list, function, BaseVar]
@@ -102,6 +103,7 @@ class ConnectionBanner(Component):
102
103
  id: Optional[Any] = None,
103
104
  class_name: Optional[Any] = None,
104
105
  autofocus: Optional[bool] = None,
106
+ _rename_props: Optional[Dict[str, str]] = None,
105
107
  custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
106
108
  on_blur: Optional[
107
109
  Union[EventHandler, EventSpec, list, function, BaseVar]
@@ -171,6 +173,7 @@ class ConnectionModal(Component):
171
173
  id: Optional[Any] = None,
172
174
  class_name: Optional[Any] = None,
173
175
  autofocus: Optional[bool] = None,
176
+ _rename_props: Optional[Dict[str, str]] = None,
174
177
  custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
175
178
  on_blur: Optional[
176
179
  Union[EventHandler, EventSpec, list, function, BaseVar]
@@ -26,6 +26,7 @@ class ClientSideRouting(Component):
26
26
  id: Optional[Any] = None,
27
27
  class_name: Optional[Any] = None,
28
28
  autofocus: Optional[bool] = None,
29
+ _rename_props: Optional[Dict[str, str]] = None,
29
30
  custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
30
31
  on_blur: Optional[
31
32
  Union[EventHandler, EventSpec, list, function, BaseVar]
@@ -83,6 +84,7 @@ class ClientSideRouting(Component):
83
84
  id: The id for the component.
84
85
  class_name: The class name for the component.
85
86
  autofocus: Whether the component should take the focus once the page is loaded
87
+ _rename_props: props to change the name of
86
88
  custom_attrs: custom attribute
87
89
  **props: The props of the component.
88
90
 
@@ -108,6 +110,7 @@ class Default404Page(Component):
108
110
  id: Optional[Any] = None,
109
111
  class_name: Optional[Any] = None,
110
112
  autofocus: Optional[bool] = None,
113
+ _rename_props: Optional[Dict[str, str]] = None,
111
114
  custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
112
115
  on_blur: Optional[
113
116
  Union[EventHandler, EventSpec, list, function, BaseVar]
@@ -165,6 +168,7 @@ class Default404Page(Component):
165
168
  id: The id for the component.
166
169
  class_name: The class name for the component.
167
170
  autofocus: Whether the component should take the focus once the page is loaded
171
+ _rename_props: props to change the name of
168
172
  custom_attrs: custom attribute
169
173
  **props: The props of the component.
170
174
 
@@ -0,0 +1,21 @@
1
+ """The colors used in Reflex are a wrapper around https://www.radix-ui.com/colors."""
2
+
3
+ from reflex.constants.colors import Color, ColorType, ShadeType
4
+
5
+
6
+ def color(
7
+ color: ColorType,
8
+ shade: ShadeType = 7,
9
+ alpha: bool = False,
10
+ ) -> Color:
11
+ """Create a color object.
12
+
13
+ Args:
14
+ color: The color to use.
15
+ shade: The shade of the color to use.
16
+ alpha: Whether to use the alpha variant of the color.
17
+
18
+ Returns:
19
+ The color object.
20
+ """
21
+ return Color(color, shade, alpha)
@@ -59,10 +59,10 @@ class Cond(MemoizationLeaf):
59
59
  )
60
60
 
61
61
  def _get_props_imports(self):
62
- """Get the imports needed for components props.
62
+ """Get the imports needed for component's props.
63
63
 
64
64
  Returns:
65
- The imports for the components props of the component.
65
+ The imports for the component's props of the component.
66
66
  """
67
67
  return []
68
68
 
@@ -100,6 +100,15 @@ class Cond(MemoizationLeaf):
100
100
  _IS_TRUE_IMPORT,
101
101
  )
102
102
 
103
+ def _apply_theme(self, theme: Component):
104
+ """Apply the theme to this component.
105
+
106
+ Args:
107
+ theme: The theme to apply.
108
+ """
109
+ self.comp1.apply_theme(theme) # type: ignore
110
+ self.comp2.apply_theme(theme) # type: ignore
111
+
103
112
 
104
113
  @overload
105
114
  def cond(condition: Any, c1: Component, c2: Any) -> Component:
@@ -30,6 +30,7 @@ class DebounceInput(Component):
30
30
  id: Optional[Any] = None,
31
31
  class_name: Optional[Any] = None,
32
32
  autofocus: Optional[bool] = None,
33
+ _rename_props: Optional[Dict[str, str]] = None,
33
34
  custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
34
35
  on_blur: Optional[
35
36
  Union[EventHandler, EventSpec, list, function, BaseVar]
@@ -0,0 +1 @@
1
+ """Core layout components."""
@@ -5,6 +5,7 @@ from typing import Any, Dict, List, Optional, Tuple, Union
5
5
  from reflex.components.base import Fragment
6
6
  from reflex.components.component import BaseComponent, Component, MemoizationLeaf
7
7
  from reflex.components.tags import MatchTag, Tag
8
+ from reflex.style import Style
8
9
  from reflex.utils import format, imports, types
9
10
  from reflex.utils.exceptions import MatchTypeError
10
11
  from reflex.vars import BaseVar, Var, VarData
@@ -94,13 +95,33 @@ class Match(MemoizationLeaf):
94
95
  if not isinstance(cases[-1], tuple):
95
96
  default = cases.pop()
96
97
  default = (
97
- Var.create(default, _var_is_string=type(default) is str)
98
+ cls._create_case_var_with_var_data(default)
98
99
  if not isinstance(default, BaseComponent)
99
100
  else default
100
101
  )
101
102
 
102
103
  return cases, default # type: ignore
103
104
 
105
+ @classmethod
106
+ def _create_case_var_with_var_data(cls, case_element):
107
+ """Convert a case element into a Var.If the case
108
+ is a Style type, we extract the var data and merge it with the
109
+ newly created Var.
110
+
111
+ Args:
112
+ case_element: The case element.
113
+
114
+ Returns:
115
+ The case element Var.
116
+ """
117
+ _var_data = case_element._var_data if isinstance(case_element, Style) else None # type: ignore
118
+ case_element = Var.create(
119
+ case_element, _var_is_string=type(case_element) is str
120
+ )
121
+ if _var_data is not None:
122
+ case_element._var_data = VarData.merge(case_element._var_data, _var_data) # type: ignore
123
+ return case_element
124
+
104
125
  @classmethod
105
126
  def _process_match_cases(cls, cases: List) -> List[List[BaseVar]]:
106
127
  """Process the individual match cases.
@@ -130,7 +151,7 @@ class Match(MemoizationLeaf):
130
151
  for element in case:
131
152
  # convert all non component element to vars.
132
153
  el = (
133
- Var.create(element, _var_is_string=type(element) is str)
154
+ cls._create_case_var_with_var_data(element)
134
155
  if not isinstance(element, BaseComponent)
135
156
  else element
136
157
  )
@@ -199,6 +220,7 @@ class Match(MemoizationLeaf):
199
220
  cond=match_cond_var,
200
221
  match_cases=match_cases,
201
222
  default=default,
223
+ children=[case[-1] for case in match_cases] + [default], # type: ignore
202
224
  )
203
225
  )
204
226
 
@@ -243,19 +265,23 @@ class Match(MemoizationLeaf):
243
265
  tag.name = "match"
244
266
  return dict(tag)
245
267
 
246
- def _get_imports(self):
247
- merged_imports = super()._get_imports()
248
- # Obtain the imports of all components the in match case.
249
- for case in self.match_cases:
250
- if isinstance(case[-1], BaseComponent):
251
- merged_imports = imports.merge_imports(
252
- merged_imports,
253
- case[-1].get_imports(),
254
- )
255
- # Get the import of the default case component.
256
- if isinstance(self.default, BaseComponent):
257
- merged_imports = imports.merge_imports(
258
- merged_imports,
259
- self.default.get_imports(),
260
- )
261
- return merged_imports
268
+ def _get_imports(self) -> imports.ImportDict:
269
+ return imports.merge_imports(
270
+ super()._get_imports(),
271
+ getattr(self.cond._var_data, "imports", {}),
272
+ )
273
+
274
+ def _apply_theme(self, theme: Component):
275
+ """Apply the theme to this component.
276
+
277
+ Args:
278
+ theme: The theme to apply.
279
+ """
280
+ # apply theme to return components.
281
+ for match_case in self.match_cases:
282
+ if isinstance(match_case[-1], Component):
283
+ match_case[-1].apply_theme(theme)
284
+
285
+ # apply theme to default component
286
+ if isinstance(self.default, Component):
287
+ self.default.apply_theme(theme)
@@ -1,7 +1,7 @@
1
1
  """A file upload component."""
2
2
  from __future__ import annotations
3
3
 
4
- from typing import Any, Dict, List, Optional, Union
4
+ from typing import Any, ClassVar, Dict, List, Optional, Union
5
5
 
6
6
  from reflex import constants
7
7
  from reflex.components.chakra.forms.input import Input
@@ -137,6 +137,9 @@ class Upload(Component):
137
137
  # Whether to disable using the space/enter keys to upload.
138
138
  no_keyboard: Var[bool]
139
139
 
140
+ # Marked True when any Upload component is created.
141
+ is_used: ClassVar[bool] = False
142
+
140
143
  @classmethod
141
144
  def create(cls, *children, **props) -> Component:
142
145
  """Create an upload component.
@@ -148,6 +151,9 @@ class Upload(Component):
148
151
  Returns:
149
152
  The upload component.
150
153
  """
154
+ # Mark the Upload component as used in the app.
155
+ cls.is_used = True
156
+
151
157
  # get only upload component props
152
158
  supported_props = cls.get_props()
153
159
  upload_props = {
@@ -192,5 +198,5 @@ class Upload(Component):
192
198
  @staticmethod
193
199
  def _get_app_wrap_components() -> dict[tuple[int, str], Component]:
194
200
  return {
195
- (5, "UploadFilesProvider"): UploadFilesProvider(),
201
+ (5, "UploadFilesProvider"): UploadFilesProvider.create(),
196
202
  }
@@ -7,7 +7,7 @@ from typing import Any, Dict, Literal, Optional, Union, overload
7
7
  from reflex.vars import Var, BaseVar, ComputedVar
8
8
  from reflex.event import EventChain, EventHandler, EventSpec
9
9
  from reflex.style import Style
10
- from typing import Any, Dict, List, Optional, Union
10
+ from typing import Any, ClassVar, Dict, List, Optional, Union
11
11
  from reflex import constants
12
12
  from reflex.components.chakra.forms.input import Input
13
13
  from reflex.components.chakra.layout.box import Box
@@ -39,6 +39,7 @@ class UploadFilesProvider(Component):
39
39
  id: Optional[Any] = None,
40
40
  class_name: Optional[Any] = None,
41
41
  autofocus: Optional[bool] = None,
42
+ _rename_props: Optional[Dict[str, str]] = None,
42
43
  custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
43
44
  on_blur: Optional[
44
45
  Union[EventHandler, EventSpec, list, function, BaseVar]
@@ -96,6 +97,7 @@ class UploadFilesProvider(Component):
96
97
  id: The id for the component.
97
98
  class_name: The class name for the component.
98
99
  autofocus: Whether the component should take the focus once the page is loaded
100
+ _rename_props: props to change the name of
99
101
  custom_attrs: custom attribute
100
102
  **props: The props of the component.
101
103
 
@@ -108,6 +110,8 @@ class UploadFilesProvider(Component):
108
110
  ...
109
111
 
110
112
  class Upload(Component):
113
+ is_used: ClassVar[bool] = False
114
+
111
115
  @overload
112
116
  @classmethod
113
117
  def create( # type: ignore
@@ -129,6 +133,7 @@ class Upload(Component):
129
133
  id: Optional[Any] = None,
130
134
  class_name: Optional[Any] = None,
131
135
  autofocus: Optional[bool] = None,
136
+ _rename_props: Optional[Dict[str, str]] = None,
132
137
  custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
133
138
  on_blur: Optional[
134
139
  Union[EventHandler, EventSpec, list, function, BaseVar]
@@ -198,6 +203,7 @@ class Upload(Component):
198
203
  id: The id for the component.
199
204
  class_name: The class name for the component.
200
205
  autofocus: Whether the component should take the focus once the page is loaded
206
+ _rename_props: props to change the name of
201
207
  custom_attrs: custom attribute
202
208
  **props: The properties of the component.
203
209
 
@@ -134,6 +134,7 @@ class DataEditor(NoSSRComponent):
134
134
  id: Optional[Any] = None,
135
135
  class_name: Optional[Any] = None,
136
136
  autofocus: Optional[bool] = None,
137
+ _rename_props: Optional[Dict[str, str]] = None,
137
138
  custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
138
139
  on_cell_activated: Optional[
139
140
  Union[EventHandler, EventSpec, list, function, BaseVar]
@@ -223,6 +224,7 @@ class DataEditor(NoSSRComponent):
223
224
  id: The id for the component.
224
225
  class_name: The class name for the component.
225
226
  autofocus: Whether the component should take the focus once the page is loaded
227
+ _rename_props: props to change the name of
226
228
  custom_attrs: custom attribute
227
229
  **props: The props of the data editor.
228
230
 
@@ -20,6 +20,7 @@ class Element(Component):
20
20
  id: Optional[Any] = None,
21
21
  class_name: Optional[Any] = None,
22
22
  autofocus: Optional[bool] = None,
23
+ _rename_props: Optional[Dict[str, str]] = None,
23
24
  custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
24
25
  on_blur: Optional[
25
26
  Union[EventHandler, EventSpec, list, function, BaseVar]
@@ -77,6 +78,7 @@ class Element(Component):
77
78
  id: The id for the component.
78
79
  class_name: The class name for the component.
79
80
  autofocus: Whether the component should take the focus once the page is loaded
81
+ _rename_props: props to change the name of
80
82
  custom_attrs: custom attribute
81
83
  **props: The props of the component.
82
84
 
@@ -65,6 +65,7 @@ class BaseHTML(Element):
65
65
  id: Optional[Any] = None,
66
66
  class_name: Optional[Any] = None,
67
67
  autofocus: Optional[bool] = None,
68
+ _rename_props: Optional[Dict[str, str]] = None,
68
69
  custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
69
70
  on_blur: Optional[
70
71
  Union[EventHandler, EventSpec, list, function, BaseVar]
@@ -139,6 +140,7 @@ class BaseHTML(Element):
139
140
  id: The id for the component.
140
141
  class_name: The class name for the component.
141
142
  autofocus: Whether the component should take the focus once the page is loaded
143
+ _rename_props: props to change the name of
142
144
  custom_attrs: custom attribute
143
145
  **props: The props of the component.
144
146
 
@@ -413,6 +413,9 @@ class Textarea(BaseHTML):
413
413
  # Visible number of lines in the text control
414
414
  rows: Var[Union[str, int, bool]]
415
415
 
416
+ # The controlled value of the textarea, read only unless used with on_change
417
+ value: Var[Union[str, int, bool]]
418
+
416
419
  # How the text in the textarea is to be wrapped when submitting the form
417
420
  wrap: Var[Union[str, int, bool]]
418
421