reflex 0.3.9a1__py3-none-any.whl → 0.3.9a2__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 (37) hide show
  1. reflex/.templates/jinja/web/pages/utils.js.jinja2 +1 -1
  2. reflex/app.py +3 -4
  3. reflex/components/component.py +3 -1
  4. reflex/components/core/match.py +8 -4
  5. reflex/components/markdown/markdown.py +1 -0
  6. reflex/components/radix/__init__.py +2 -0
  7. reflex/components/radix/primitives/__init__.py +14 -1
  8. reflex/components/radix/primitives/accordion.py +426 -69
  9. reflex/components/radix/primitives/accordion.pyi +41 -11
  10. reflex/components/radix/primitives/base.py +4 -0
  11. reflex/components/radix/primitives/base.pyi +81 -0
  12. reflex/components/radix/primitives/form.py +4 -2
  13. reflex/components/radix/primitives/form.pyi +2 -2
  14. reflex/components/radix/primitives/progress.py +4 -2
  15. reflex/components/radix/primitives/progress.pyi +2 -2
  16. reflex/components/radix/primitives/slider.py +7 -5
  17. reflex/components/radix/primitives/slider.pyi +5 -5
  18. reflex/components/radix/themes/components/__init__.py +6 -2
  19. reflex/components/radix/themes/components/callout.py +36 -5
  20. reflex/components/radix/themes/components/callout.pyi +273 -9
  21. reflex/components/radix/themes/components/checkbox.py +41 -4
  22. reflex/components/radix/themes/components/checkbox.pyi +231 -8
  23. reflex/components/radix/themes/components/icons.py +1 -0
  24. reflex/components/radix/themes/components/radiogroup.py +65 -1
  25. reflex/components/radix/themes/components/radiogroup.pyi +252 -2
  26. reflex/components/radix/themes/components/select.py +81 -1
  27. reflex/components/radix/themes/components/select.pyi +237 -1
  28. reflex/state.py +6 -3
  29. reflex/style.py +15 -0
  30. reflex/utils/prerequisites.py +3 -1
  31. reflex/utils/types.py +4 -1
  32. reflex/vars.py +36 -3
  33. {reflex-0.3.9a1.dist-info → reflex-0.3.9a2.dist-info}/METADATA +1 -1
  34. {reflex-0.3.9a1.dist-info → reflex-0.3.9a2.dist-info}/RECORD +37 -37
  35. {reflex-0.3.9a1.dist-info → reflex-0.3.9a2.dist-info}/LICENSE +0 -0
  36. {reflex-0.3.9a1.dist-info → reflex-0.3.9a2.dist-info}/WHEEL +0 -0
  37. {reflex-0.3.9a1.dist-info → reflex-0.3.9a2.dist-info}/entry_points.txt +0 -0
@@ -1,6 +1,8 @@
1
1
  """Interactive components provided by @radix-ui/themes."""
2
- from typing import Any, Dict, Literal
2
+ from typing import Any, Dict, List, Literal, Union
3
3
 
4
+ import reflex as rx
5
+ from reflex.components.component import Component
4
6
  from reflex.vars import Var
5
7
 
6
8
  from ..base import (
@@ -144,3 +146,81 @@ class SelectSeparator(CommonMarginProps, RadixThemesComponent):
144
146
  """Trigger an action or event, such as submitting a form or displaying a dialog."""
145
147
 
146
148
  tag = "Select.Separator"
149
+
150
+
151
+ class HighLevelSelect(SelectRoot):
152
+ """High level wrapper for the Select component."""
153
+
154
+ # The items of the select.
155
+ items: Var[List[str]]
156
+
157
+ # The placeholder of the select.
158
+ placeholder: Var[str]
159
+
160
+ # The label of the select.
161
+ label: Var[str]
162
+
163
+ # The color of the select.
164
+ color: Var[LiteralAccentColor]
165
+
166
+ # Whether to render the select with higher contrast color against background.
167
+ high_contrast: Var[bool]
168
+
169
+ # The variant of the select.
170
+ variant: Var[Literal["classic", "surface", "soft", "ghost"]]
171
+
172
+ # The radius of the select.
173
+ radius: Var[LiteralRadius]
174
+
175
+ # The width of the select.
176
+ width: Var[str]
177
+
178
+ @classmethod
179
+ def create(cls, items: Union[List[str], Var[List[str]]], **props) -> Component:
180
+ """Create a select component.
181
+
182
+ Args:
183
+ items: The items of the select.
184
+ **props: Additional properties to apply to the select component.
185
+
186
+ Returns:
187
+ The select component.
188
+ """
189
+ content_props = {
190
+ prop: props.pop(prop) for prop in ["high_contrast"] if prop in props
191
+ }
192
+
193
+ trigger_props = {
194
+ prop: props.pop(prop)
195
+ for prop in ["placeholder", "variant", "radius", "width"]
196
+ if prop in props
197
+ }
198
+
199
+ color = props.pop("color", None)
200
+
201
+ if color is not None:
202
+ content_props["color_scheme"] = color
203
+ trigger_props["color_scheme"] = color
204
+
205
+ label = props.pop("label", None)
206
+
207
+ if isinstance(items, Var):
208
+ child = [
209
+ rx.foreach(items, lambda item: SelectItem.create(item, value=item))
210
+ ]
211
+ else:
212
+ child = [SelectItem.create(item, value=item) for item in items]
213
+
214
+ return SelectRoot.create(
215
+ SelectTrigger.create(
216
+ **trigger_props,
217
+ ),
218
+ SelectContent.create(
219
+ SelectGroup.create(
220
+ SelectLabel.create(label) if label is not None else "",
221
+ *child,
222
+ ),
223
+ **content_props,
224
+ ),
225
+ **props,
226
+ )
@@ -7,7 +7,9 @@ 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, Literal
10
+ from typing import Any, Dict, List, Literal, Union
11
+ import reflex as rx
12
+ from reflex.components.component import Component
11
13
  from reflex.vars import Var
12
14
  from ..base import (
13
15
  CommonMarginProps,
@@ -1452,3 +1454,237 @@ class SelectSeparator(CommonMarginProps, RadixThemesComponent):
1452
1454
  A new component instance.
1453
1455
  """
1454
1456
  ...
1457
+
1458
+ class HighLevelSelect(SelectRoot):
1459
+ @overload
1460
+ @classmethod
1461
+ def create( # type: ignore
1462
+ cls,
1463
+ *children,
1464
+ items: Optional[Union[Var[List[str]], List[str]]] = None,
1465
+ placeholder: Optional[Union[Var[str], str]] = None,
1466
+ label: Optional[Union[Var[str], str]] = None,
1467
+ color: Optional[
1468
+ Union[
1469
+ Var[
1470
+ Literal[
1471
+ "tomato",
1472
+ "red",
1473
+ "ruby",
1474
+ "crimson",
1475
+ "pink",
1476
+ "plum",
1477
+ "purple",
1478
+ "violet",
1479
+ "iris",
1480
+ "indigo",
1481
+ "blue",
1482
+ "cyan",
1483
+ "teal",
1484
+ "jade",
1485
+ "green",
1486
+ "grass",
1487
+ "brown",
1488
+ "orange",
1489
+ "sky",
1490
+ "mint",
1491
+ "lime",
1492
+ "yellow",
1493
+ "amber",
1494
+ "gold",
1495
+ "bronze",
1496
+ "gray",
1497
+ ]
1498
+ ],
1499
+ Literal[
1500
+ "tomato",
1501
+ "red",
1502
+ "ruby",
1503
+ "crimson",
1504
+ "pink",
1505
+ "plum",
1506
+ "purple",
1507
+ "violet",
1508
+ "iris",
1509
+ "indigo",
1510
+ "blue",
1511
+ "cyan",
1512
+ "teal",
1513
+ "jade",
1514
+ "green",
1515
+ "grass",
1516
+ "brown",
1517
+ "orange",
1518
+ "sky",
1519
+ "mint",
1520
+ "lime",
1521
+ "yellow",
1522
+ "amber",
1523
+ "gold",
1524
+ "bronze",
1525
+ "gray",
1526
+ ],
1527
+ ]
1528
+ ] = None,
1529
+ high_contrast: Optional[Union[Var[bool], bool]] = None,
1530
+ variant: Optional[
1531
+ Union[
1532
+ Var[Literal["classic", "surface", "soft", "ghost"]],
1533
+ Literal["classic", "surface", "soft", "ghost"],
1534
+ ]
1535
+ ] = None,
1536
+ radius: Optional[
1537
+ Union[
1538
+ Var[Literal["none", "small", "medium", "large", "full"]],
1539
+ Literal["none", "small", "medium", "large", "full"],
1540
+ ]
1541
+ ] = None,
1542
+ width: Optional[Union[Var[str], str]] = None,
1543
+ size: Optional[Union[Var[Literal[1, 2, 3]], Literal[1, 2, 3]]] = None,
1544
+ default_value: Optional[Union[Var[str], str]] = None,
1545
+ value: Optional[Union[Var[str], str]] = None,
1546
+ default_open: Optional[Union[Var[bool], bool]] = None,
1547
+ open: Optional[Union[Var[bool], bool]] = None,
1548
+ name: Optional[Union[Var[str], str]] = None,
1549
+ disabled: Optional[Union[Var[bool], bool]] = None,
1550
+ required: Optional[Union[Var[bool], bool]] = None,
1551
+ m: Optional[
1552
+ Union[
1553
+ Var[Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"]],
1554
+ Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"],
1555
+ ]
1556
+ ] = None,
1557
+ mx: Optional[
1558
+ Union[
1559
+ Var[Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"]],
1560
+ Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"],
1561
+ ]
1562
+ ] = None,
1563
+ my: Optional[
1564
+ Union[
1565
+ Var[Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"]],
1566
+ Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"],
1567
+ ]
1568
+ ] = None,
1569
+ mt: Optional[
1570
+ Union[
1571
+ Var[Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"]],
1572
+ Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"],
1573
+ ]
1574
+ ] = None,
1575
+ mr: Optional[
1576
+ Union[
1577
+ Var[Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"]],
1578
+ Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"],
1579
+ ]
1580
+ ] = None,
1581
+ mb: Optional[
1582
+ Union[
1583
+ Var[Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"]],
1584
+ Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"],
1585
+ ]
1586
+ ] = None,
1587
+ ml: Optional[
1588
+ Union[
1589
+ Var[Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"]],
1590
+ Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"],
1591
+ ]
1592
+ ] = None,
1593
+ style: Optional[Style] = None,
1594
+ key: Optional[Any] = None,
1595
+ id: Optional[Any] = None,
1596
+ class_name: Optional[Any] = None,
1597
+ autofocus: Optional[bool] = None,
1598
+ custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
1599
+ on_blur: Optional[
1600
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1601
+ ] = None,
1602
+ on_click: Optional[
1603
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1604
+ ] = None,
1605
+ on_context_menu: Optional[
1606
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1607
+ ] = None,
1608
+ on_double_click: Optional[
1609
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1610
+ ] = None,
1611
+ on_focus: Optional[
1612
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1613
+ ] = None,
1614
+ on_mount: Optional[
1615
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1616
+ ] = None,
1617
+ on_mouse_down: Optional[
1618
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1619
+ ] = None,
1620
+ on_mouse_enter: Optional[
1621
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1622
+ ] = None,
1623
+ on_mouse_leave: Optional[
1624
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1625
+ ] = None,
1626
+ on_mouse_move: Optional[
1627
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1628
+ ] = None,
1629
+ on_mouse_out: Optional[
1630
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1631
+ ] = None,
1632
+ on_mouse_over: Optional[
1633
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1634
+ ] = None,
1635
+ on_mouse_up: Optional[
1636
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1637
+ ] = None,
1638
+ on_open_change: Optional[
1639
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1640
+ ] = None,
1641
+ on_scroll: Optional[
1642
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1643
+ ] = None,
1644
+ on_unmount: Optional[
1645
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1646
+ ] = None,
1647
+ on_value_change: Optional[
1648
+ Union[EventHandler, EventSpec, list, function, BaseVar]
1649
+ ] = None,
1650
+ **props
1651
+ ) -> "HighLevelSelect":
1652
+ """Create a select component.
1653
+
1654
+ Args:
1655
+ items: The items of the select.
1656
+ items: The items of the select.
1657
+ placeholder: The placeholder of the select.
1658
+ label: The label of the select.
1659
+ color: The color of the select.
1660
+ high_contrast: Whether to render the select with higher contrast color against background.
1661
+ variant: The variant of the select.
1662
+ radius: The radius of the select.
1663
+ width: The width of the select.
1664
+ size: The size of the select: "1" | "2" | "3"
1665
+ default_value: The value of the select when initially rendered. Use when you do not need to control the state of the select.
1666
+ value: The controlled value of the select. Should be used in conjunction with on_value_change.
1667
+ default_open: The open state of the select when it is initially rendered. Use when you do not need to control its open state.
1668
+ open: The controlled open state of the select. Must be used in conjunction with on_open_change.
1669
+ name: The name of the select control when submitting the form.
1670
+ disabled: When True, prevents the user from interacting with select.
1671
+ required: When True, indicates that the user must select a value before the owning form can be submitted.
1672
+ m: Margin: "0" - "9"
1673
+ mx: Margin horizontal: "0" - "9"
1674
+ my: Margin vertical: "0" - "9"
1675
+ mt: Margin top: "0" - "9"
1676
+ mr: Margin right: "0" - "9"
1677
+ mb: Margin bottom: "0" - "9"
1678
+ ml: Margin left: "0" - "9"
1679
+ style: The style of the component.
1680
+ key: A unique key for the component.
1681
+ id: The id for the component.
1682
+ class_name: The class name for the component.
1683
+ autofocus: Whether the component should take the focus once the page is loaded
1684
+ custom_attrs: custom attribute
1685
+ **props: Additional properties to apply to the select component.
1686
+
1687
+ Returns:
1688
+ The select component.
1689
+ """
1690
+ ...
reflex/state.py CHANGED
@@ -315,7 +315,7 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
315
315
  cls.new_backend_vars = {
316
316
  name: value
317
317
  for name, value in cls.__dict__.items()
318
- if types.is_backend_variable(name)
318
+ if types.is_backend_variable(name, cls)
319
319
  and name not in cls.inherited_backend_vars
320
320
  and not isinstance(value, FunctionType)
321
321
  }
@@ -878,7 +878,10 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
878
878
  setattr(self.parent_state, name, value)
879
879
  return
880
880
 
881
- if types.is_backend_variable(name) and name not in RESERVED_BACKEND_VAR_NAMES:
881
+ if (
882
+ types.is_backend_variable(name, self.__class__)
883
+ and name not in RESERVED_BACKEND_VAR_NAMES
884
+ ):
882
885
  self._backend_vars.__setitem__(name, value)
883
886
  self.dirty_vars.add(name)
884
887
  self._mark_dirty()
@@ -1177,7 +1180,7 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1177
1180
  subdelta = {
1178
1181
  prop: getattr(self, prop)
1179
1182
  for prop in delta_vars
1180
- if not types.is_backend_variable(prop)
1183
+ if not types.is_backend_variable(prop, self.__class__)
1181
1184
  }
1182
1185
  if len(subdelta) > 0:
1183
1186
  delta[self.get_full_name()] = subdelta
reflex/style.py CHANGED
@@ -220,3 +220,18 @@ def format_as_emotion(style_dict: dict[str, Any]) -> dict[str, Any] | None:
220
220
  emotion_style[key] = value
221
221
  if emotion_style:
222
222
  return emotion_style
223
+
224
+
225
+ def convert_dict_to_style_and_format_emotion(
226
+ raw_dict: dict[str, Any]
227
+ ) -> dict[str, Any] | None:
228
+ """Convert a dict to a style dict and then format as emotion.
229
+
230
+ Args:
231
+ raw_dict: The dict to convert.
232
+
233
+ Returns:
234
+ The emotion dict.
235
+
236
+ """
237
+ return format_as_emotion(Style(raw_dict))
@@ -163,7 +163,9 @@ def get_app(reload: bool = False) -> ModuleType:
163
163
  from reflex.state import State
164
164
 
165
165
  # Reset rx.State subclasses to avoid conflict when reloading.
166
- State.class_subclasses.clear()
166
+ for subclass in tuple(State.class_subclasses):
167
+ if subclass.__module__ == module:
168
+ State.class_subclasses.remove(subclass)
167
169
  # Reload the app module.
168
170
  importlib.reload(app)
169
171
 
reflex/utils/types.py CHANGED
@@ -251,15 +251,18 @@ def is_valid_var_type(type_: Type) -> bool:
251
251
  return _issubclass(type_, StateVar) or serializers.has_serializer(type_)
252
252
 
253
253
 
254
- def is_backend_variable(name: str) -> bool:
254
+ def is_backend_variable(name: str, cls: Type | None = None) -> bool:
255
255
  """Check if this variable name correspond to a backend variable.
256
256
 
257
257
  Args:
258
258
  name: The name of the variable to check
259
+ cls: The class of the variable to check
259
260
 
260
261
  Returns:
261
262
  bool: The result of the check
262
263
  """
264
+ if cls is not None and name.startswith(f"_{cls.__name__}__"):
265
+ return False
263
266
  return name.startswith("_") and not name.startswith("__")
264
267
 
265
268
 
reflex/vars.py CHANGED
@@ -421,6 +421,26 @@ class Var:
421
421
  and self._var_data == other._var_data
422
422
  )
423
423
 
424
+ def _merge(self, other) -> Var:
425
+ """Merge two or more dicts.
426
+
427
+ Args:
428
+ other: The other var to merge.
429
+
430
+ Returns:
431
+ The merged var.
432
+
433
+ Raises:
434
+ ValueError: If the other value to be merged is None.
435
+ """
436
+ if other is None:
437
+ raise ValueError("The value to be merged cannot be None.")
438
+ if not isinstance(other, Var):
439
+ other = Var.create(other)
440
+ return self._replace(
441
+ _var_name=f"{{...{self._var_name}, ...{other._var_name}}}" # type: ignore
442
+ )
443
+
424
444
  def to_string(self, json: bool = True) -> Var:
425
445
  """Convert a var to a string.
426
446
 
@@ -677,6 +697,16 @@ class Var:
677
697
 
678
698
  left_operand, right_operand = (other, self) if flip else (self, other)
679
699
 
700
+ def get_operand_full_name(operand):
701
+ # operand vars that are string literals need to be wrapped in back ticks.
702
+ return (
703
+ operand._var_name_unwrapped
704
+ if operand._var_is_string
705
+ and not operand._var_state
706
+ and operand._var_is_local
707
+ else operand._var_full_name
708
+ )
709
+
680
710
  if other is not None:
681
711
  # check if the operation between operands is valid.
682
712
  if op and not self.is_valid_operation(
@@ -688,18 +718,21 @@ class Var:
688
718
  f"Unsupported Operand type(s) for {op}: `{left_operand._var_full_name}` of type {left_operand._var_type.__name__} and `{right_operand._var_full_name}` of type {right_operand._var_type.__name__}" # type: ignore
689
719
  )
690
720
 
721
+ left_operand_full_name = get_operand_full_name(left_operand)
722
+ right_operand_full_name = get_operand_full_name(right_operand)
723
+
691
724
  # apply function to operands
692
725
  if fn is not None:
693
726
  if invoke_fn:
694
727
  # invoke the function on left operand.
695
- operation_name = f"{left_operand._var_full_name}.{fn}({right_operand._var_full_name})" # type: ignore
728
+ operation_name = f"{left_operand_full_name}.{fn}({right_operand_full_name})" # type: ignore
696
729
  else:
697
730
  # pass the operands as arguments to the function.
698
- operation_name = f"{left_operand._var_full_name} {op} {right_operand._var_full_name}" # type: ignore
731
+ operation_name = f"{left_operand_full_name} {op} {right_operand_full_name}" # type: ignore
699
732
  operation_name = f"{fn}({operation_name})"
700
733
  else:
701
734
  # apply operator to operands (left operand <operator> right_operand)
702
- operation_name = f"{left_operand._var_full_name} {op} {right_operand._var_full_name}" # type: ignore
735
+ operation_name = f"{left_operand_full_name} {op} {right_operand_full_name}" # type: ignore
703
736
  operation_name = format.wrap(operation_name, "(")
704
737
  else:
705
738
  # apply operator to left operand (<operator> left_operand)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: reflex
3
- Version: 0.3.9a1
3
+ Version: 0.3.9a2
4
4
  Summary: Web apps in pure Python.
5
5
  Home-page: https://reflex.dev
6
6
  License: Apache-2.0