reflex 0.3.6__py3-none-any.whl → 0.3.7__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.
- reflex/.templates/jinja/web/pages/base_page.js.jinja2 +2 -0
- reflex/__init__.py +29 -6
- reflex/__init__.pyi +2 -0
- reflex/app.py +3 -0
- reflex/components/__init__.py +2 -0
- reflex/components/chakra/__init__.py +23 -0
- reflex/components/{media → chakra/media}/image.py +1 -28
- reflex/components/chakra/media/image.pyi +120 -0
- reflex/components/component.py +27 -2
- reflex/components/datadisplay/datatable.py +1 -37
- reflex/components/datadisplay/datatable.pyi +1 -11
- reflex/components/el/elements/forms.py +43 -1
- reflex/components/el/elements/forms.pyi +26 -1
- reflex/components/graphing/plotly.py +0 -22
- reflex/components/graphing/plotly.pyi +0 -12
- reflex/components/media/__init__.py +0 -1
- reflex/components/media/image.pyi +0 -9
- reflex/components/next/__init__.py +8 -0
- reflex/components/next/base.py +8 -0
- reflex/components/next/base.pyi +91 -0
- reflex/components/next/image.py +114 -0
- reflex/components/next/image.pyi +122 -0
- reflex/components/next/video.py +33 -0
- reflex/components/next/video.pyi +92 -0
- reflex/components/radix/primitives/__init__.py +3 -0
- reflex/components/radix/primitives/accordion.py +279 -0
- reflex/components/radix/primitives/accordion.pyi +619 -0
- reflex/components/radix/themes/__init__.py +4 -73
- reflex/components/radix/themes/base.py +7 -7
- reflex/components/radix/themes/base.pyi +21 -21
- reflex/components/radix/themes/components/__init__.py +193 -0
- reflex/components/radix/themes/components/alertdialog.py +72 -0
- reflex/components/radix/themes/components/alertdialog.pyi +733 -0
- reflex/components/radix/themes/components/aspectratio.py +20 -0
- reflex/components/radix/themes/components/aspectratio.pyi +144 -0
- reflex/components/radix/themes/components/avatar.py +38 -0
- reflex/components/radix/themes/components/avatar.pyi +233 -0
- reflex/components/radix/themes/components/badge.py +38 -0
- reflex/components/radix/themes/components/badge.pyi +291 -0
- reflex/components/radix/themes/components/button.py +39 -0
- reflex/components/radix/themes/components/button.pyi +330 -0
- reflex/components/radix/themes/components/callout.py +49 -0
- reflex/components/radix/themes/components/callout.pyi +668 -0
- reflex/components/radix/themes/components/card.py +25 -0
- reflex/components/radix/themes/components/card.pyi +214 -0
- reflex/components/radix/themes/components/checkbox.py +67 -0
- reflex/components/radix/themes/components/checkbox.pyi +249 -0
- reflex/components/radix/themes/components/contextmenu.py +134 -0
- reflex/components/radix/themes/{typography.pyi → components/contextmenu.pyi} +182 -602
- reflex/components/radix/themes/components/dialog.py +75 -0
- reflex/components/radix/themes/components/dialog.pyi +739 -0
- reflex/components/radix/themes/components/dropdownmenu.py +101 -0
- reflex/components/radix/themes/components/dropdownmenu.pyi +1065 -0
- reflex/components/radix/themes/components/hovercard.py +63 -0
- reflex/components/radix/themes/components/hovercard.pyi +487 -0
- reflex/components/radix/themes/components/iconbutton.py +39 -0
- reflex/components/radix/themes/components/iconbutton.pyi +332 -0
- reflex/components/radix/themes/components/icons.py +400 -0
- reflex/components/radix/themes/components/icons.pyi +185 -0
- reflex/components/radix/themes/components/inset.py +44 -0
- reflex/components/radix/themes/components/inset.pyi +230 -0
- reflex/components/radix/themes/components/popover.py +85 -0
- reflex/components/radix/themes/components/popover.pyi +634 -0
- reflex/components/radix/themes/components/radiogroup.py +72 -0
- reflex/components/radix/themes/components/radiogroup.pyi +369 -0
- reflex/components/radix/themes/components/scrollarea.py +31 -0
- reflex/components/radix/themes/components/scrollarea.pyi +165 -0
- reflex/components/radix/themes/components/select.py +137 -0
- reflex/components/radix/themes/{layout.pyi → components/select.pyi} +422 -418
- reflex/components/radix/themes/components/separator.py +30 -0
- reflex/components/radix/themes/components/separator.pyi +218 -0
- reflex/components/radix/themes/components/slider.py +68 -0
- reflex/components/radix/themes/components/slider.pyi +254 -0
- reflex/components/radix/themes/components/switch.py +68 -0
- reflex/components/radix/themes/components/switch.pyi +250 -0
- reflex/components/radix/themes/components/table.py +79 -0
- reflex/components/radix/themes/components/table.pyi +1485 -0
- reflex/components/radix/themes/components/tabs.py +65 -0
- reflex/components/radix/themes/components/tabs.pyi +549 -0
- reflex/components/radix/themes/components/textarea.py +68 -0
- reflex/components/radix/themes/components/textarea.pyi +333 -0
- reflex/components/radix/themes/{components.py → components/textfield.py} +3 -87
- reflex/components/radix/themes/{components.pyi → components/textfield.pyi} +202 -591
- reflex/components/radix/themes/layout/__init__.py +13 -0
- reflex/components/radix/themes/layout/base.py +48 -0
- reflex/components/radix/themes/layout/base.pyi +195 -0
- reflex/components/radix/themes/layout/box.py +12 -0
- reflex/components/radix/themes/layout/box.pyi +252 -0
- reflex/components/radix/themes/layout/container.py +23 -0
- reflex/components/radix/themes/layout/container.pyi +260 -0
- reflex/components/radix/themes/layout/flex.py +45 -0
- reflex/components/radix/themes/layout/flex.pyi +303 -0
- reflex/components/radix/themes/layout/grid.py +53 -0
- reflex/components/radix/themes/layout/grid.pyi +203 -0
- reflex/components/radix/themes/layout/section.py +20 -0
- reflex/components/radix/themes/layout/section.pyi +260 -0
- reflex/components/radix/themes/typography/__init__.py +21 -0
- reflex/components/radix/themes/typography/base.py +12 -0
- reflex/components/radix/themes/typography/blockquote.py +36 -0
- reflex/components/radix/themes/typography/blockquote.pyi +282 -0
- reflex/components/radix/themes/typography/code.py +40 -0
- reflex/components/radix/themes/typography/code.pyi +292 -0
- reflex/components/radix/themes/typography/em.py +18 -0
- reflex/components/radix/themes/typography/em.pyi +199 -0
- reflex/components/radix/themes/typography/heading.py +50 -0
- reflex/components/radix/themes/typography/heading.pyi +298 -0
- reflex/components/radix/themes/typography/kbd.py +25 -0
- reflex/components/radix/themes/typography/kbd.pyi +208 -0
- reflex/components/radix/themes/typography/link.py +49 -0
- reflex/components/radix/themes/typography/link.pyi +238 -0
- reflex/components/radix/themes/typography/quote.py +18 -0
- reflex/components/radix/themes/typography/quote.pyi +200 -0
- reflex/components/radix/themes/typography/strong.py +18 -0
- reflex/components/radix/themes/typography/strong.pyi +199 -0
- reflex/components/radix/themes/typography/text.py +50 -0
- reflex/components/radix/themes/typography/text.pyi +298 -0
- reflex/constants/__init__.py +1 -0
- reflex/constants/base.py +7 -0
- reflex/constants/config.py +1 -1
- reflex/model.py +2 -1
- reflex/reflex.py +5 -0
- reflex/state.py +11 -0
- reflex/style.py +120 -10
- reflex/testing.py +4 -4
- reflex/utils/format.py +9 -5
- reflex/utils/prerequisites.py +49 -6
- reflex/utils/processes.py +8 -1
- reflex/utils/serializers.py +83 -0
- reflex/utils/types.py +22 -1
- reflex/vars.py +24 -1
- {reflex-0.3.6.dist-info → reflex-0.3.7.dist-info}/METADATA +3 -2
- {reflex-0.3.6.dist-info → reflex-0.3.7.dist-info}/RECORD +135 -42
- reflex/components/radix/themes/layout.py +0 -155
- {reflex-0.3.6.dist-info → reflex-0.3.7.dist-info}/LICENSE +0 -0
- {reflex-0.3.6.dist-info → reflex-0.3.7.dist-info}/WHEEL +0 -0
- {reflex-0.3.6.dist-info → reflex-0.3.7.dist-info}/entry_points.txt +0 -0
reflex/__init__.py
CHANGED
|
@@ -4,10 +4,13 @@ Anything imported here will be available in the default Reflex import as `rx.*`.
|
|
|
4
4
|
To signal to typecheckers that something should be reexported,
|
|
5
5
|
we use the Flask "import name as name" syntax.
|
|
6
6
|
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
7
9
|
import importlib
|
|
8
10
|
from typing import Type
|
|
9
11
|
|
|
10
12
|
from reflex.page import page as page
|
|
13
|
+
from reflex.utils import console
|
|
11
14
|
from reflex.utils.format import to_snake_case
|
|
12
15
|
|
|
13
16
|
_ALL_COMPONENTS = [
|
|
@@ -181,10 +184,6 @@ _ALL_COMPONENTS = [
|
|
|
181
184
|
"StatGroup",
|
|
182
185
|
"StatHelpText",
|
|
183
186
|
"StatLabel",
|
|
184
|
-
"StatArrow",
|
|
185
|
-
"StatGroup",
|
|
186
|
-
"StatHelpText",
|
|
187
|
-
"StatLabel",
|
|
188
187
|
"StatNumber",
|
|
189
188
|
"Step",
|
|
190
189
|
"StepDescription",
|
|
@@ -250,7 +249,7 @@ _MAPPING = {
|
|
|
250
249
|
"reflex.base": ["base", "Base"],
|
|
251
250
|
"reflex.compiler": ["compiler"],
|
|
252
251
|
"reflex.compiler.utils": ["get_asset_path"],
|
|
253
|
-
"reflex.components": _ALL_COMPONENTS,
|
|
252
|
+
"reflex.components": _ALL_COMPONENTS + ["chakra", "next"],
|
|
254
253
|
"reflex.components.component": ["memo"],
|
|
255
254
|
"reflex.components.graphing": ["recharts"],
|
|
256
255
|
"reflex.components.datadisplay.moment": ["MomentDelta"],
|
|
@@ -286,7 +285,31 @@ _MAPPING = {
|
|
|
286
285
|
"reflex.utils": ["utils"],
|
|
287
286
|
"reflex.vars": ["vars", "cached_var", "Var"],
|
|
288
287
|
}
|
|
289
|
-
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _reverse_mapping(mapping: dict[str, list]) -> dict[str, str]:
|
|
291
|
+
"""Reverse the mapping used to lazy loading, and check for conflicting name.
|
|
292
|
+
|
|
293
|
+
Args:
|
|
294
|
+
mapping: The mapping to reverse.
|
|
295
|
+
|
|
296
|
+
Returns:
|
|
297
|
+
The reversed mapping.
|
|
298
|
+
"""
|
|
299
|
+
reversed_mapping = {}
|
|
300
|
+
for key, values in mapping.items():
|
|
301
|
+
for value in values:
|
|
302
|
+
if value not in reversed_mapping:
|
|
303
|
+
reversed_mapping[value] = key
|
|
304
|
+
else:
|
|
305
|
+
console.warn(
|
|
306
|
+
f"Key {value} is present multiple times in the imports _MAPPING: {key} / {reversed_mapping[value]}"
|
|
307
|
+
)
|
|
308
|
+
return reversed_mapping
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
# _MAPPING = {value: key for key, values in _MAPPING.items() for value in values}
|
|
312
|
+
_MAPPING = _reverse_mapping(_MAPPING)
|
|
290
313
|
|
|
291
314
|
|
|
292
315
|
def _removeprefix(text, prefix):
|
reflex/__init__.pyi
CHANGED
|
@@ -440,6 +440,8 @@ from reflex.components import clear_selected_files as clear_selected_files
|
|
|
440
440
|
from reflex.components import EditorButtonList as EditorButtonList
|
|
441
441
|
from reflex.components import EditorOptions as EditorOptions
|
|
442
442
|
from reflex.components import NoSSRComponent as NoSSRComponent
|
|
443
|
+
from reflex.components import chakra as chakra
|
|
444
|
+
from reflex.components import next as next
|
|
443
445
|
from reflex.components.component import memo as memo
|
|
444
446
|
from reflex.components.graphing import recharts as recharts
|
|
445
447
|
from reflex.components.datadisplay.moment import MomentDelta as MomentDelta
|
reflex/app.py
CHANGED
|
@@ -667,6 +667,9 @@ class App(Base):
|
|
|
667
667
|
# Merge the component style with the app style.
|
|
668
668
|
component.add_style(self.style)
|
|
669
669
|
|
|
670
|
+
if self.theme is not None:
|
|
671
|
+
component.apply_theme(self.theme)
|
|
672
|
+
|
|
670
673
|
# Add component.get_imports() to all_imports.
|
|
671
674
|
all_imports.update(component.get_imports())
|
|
672
675
|
|
reflex/components/__init__.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"""Import all the components."""
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
|
+
from . import next as next
|
|
4
5
|
from .base import Script
|
|
6
|
+
from .chakra import *
|
|
5
7
|
from .component import Component
|
|
6
8
|
from .component import NoSSRComponent as NoSSRComponent
|
|
7
9
|
from .datadisplay import *
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Chakra components."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import importlib
|
|
5
|
+
from typing import Type
|
|
6
|
+
|
|
7
|
+
from .media.image import Image
|
|
8
|
+
|
|
9
|
+
image = Image.create
|
|
10
|
+
|
|
11
|
+
# _MAPPING = {
|
|
12
|
+
# "image": "media",
|
|
13
|
+
# }
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# def __getattr__(name: str) -> Type:
|
|
17
|
+
# print(f"importing {name}")
|
|
18
|
+
# if name not in _MAPPING:
|
|
19
|
+
# return importlib.import_module(name)
|
|
20
|
+
|
|
21
|
+
# module = importlib.import_module(_MAPPING[name], package=".")
|
|
22
|
+
|
|
23
|
+
# return getattr(module, name) if name != _MAPPING[name].rsplit(".")[-1] else module
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"""An image component."""
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
|
-
import base64
|
|
5
|
-
import io
|
|
6
4
|
from typing import Any, Optional, Union
|
|
7
5
|
|
|
8
6
|
from reflex.components.component import Component
|
|
9
7
|
from reflex.components.libs.chakra import ChakraComponent, LiteralImageLoading
|
|
10
|
-
from reflex.utils.serializers import serializer
|
|
11
8
|
from reflex.vars import Var
|
|
12
9
|
|
|
13
10
|
|
|
@@ -15,7 +12,7 @@ class Image(ChakraComponent):
|
|
|
15
12
|
"""Display an image."""
|
|
16
13
|
|
|
17
14
|
tag = "Image"
|
|
18
|
-
|
|
15
|
+
alias = "ChakraImage"
|
|
19
16
|
# How to align the image within its bounds. It maps to css `object-position` property.
|
|
20
17
|
align: Var[str]
|
|
21
18
|
|
|
@@ -79,27 +76,3 @@ class Image(ChakraComponent):
|
|
|
79
76
|
if src is not None and not isinstance(src, (Var)):
|
|
80
77
|
props["src"] = Var.create(value=src, _var_is_string=True)
|
|
81
78
|
return super().create(*children, **props)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
try:
|
|
85
|
-
from PIL.Image import Image as Img
|
|
86
|
-
|
|
87
|
-
@serializer
|
|
88
|
-
def serialize_image(image: Img) -> str:
|
|
89
|
-
"""Serialize a plotly figure.
|
|
90
|
-
|
|
91
|
-
Args:
|
|
92
|
-
image: The image to serialize.
|
|
93
|
-
|
|
94
|
-
Returns:
|
|
95
|
-
The serialized image.
|
|
96
|
-
"""
|
|
97
|
-
buff = io.BytesIO()
|
|
98
|
-
image.save(buff, format=getattr(image, "format", None) or "PNG")
|
|
99
|
-
image_bytes = buff.getvalue()
|
|
100
|
-
base64_image = base64.b64encode(image_bytes).decode("utf-8")
|
|
101
|
-
mime_type = getattr(image, "get_format_mimetype", lambda: "image/png")()
|
|
102
|
-
return f"data:{mime_type};base64,{base64_image}"
|
|
103
|
-
|
|
104
|
-
except ImportError:
|
|
105
|
-
pass
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Stub file for reflex/components/chakra/media/image.py"""
|
|
2
|
+
# ------------------- DO NOT EDIT ----------------------
|
|
3
|
+
# This file was generated by `scripts/pyi_generator.py`!
|
|
4
|
+
# ------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
from typing import Any, Dict, Literal, Optional, Union, overload
|
|
7
|
+
from reflex.vars import Var, BaseVar, ComputedVar
|
|
8
|
+
from reflex.event import EventChain, EventHandler, EventSpec
|
|
9
|
+
from reflex.style import Style
|
|
10
|
+
from typing import Any, Optional, Union
|
|
11
|
+
from reflex.components.component import Component
|
|
12
|
+
from reflex.components.libs.chakra import ChakraComponent, LiteralImageLoading
|
|
13
|
+
from reflex.vars import Var
|
|
14
|
+
|
|
15
|
+
class Image(ChakraComponent):
|
|
16
|
+
def get_event_triggers(self) -> dict[str, Union[Var, Any]]: ...
|
|
17
|
+
@overload
|
|
18
|
+
@classmethod
|
|
19
|
+
def create( # type: ignore
|
|
20
|
+
cls,
|
|
21
|
+
*children,
|
|
22
|
+
align: Optional[Union[Var[str], str]] = None,
|
|
23
|
+
fallback: Optional[Component] = None,
|
|
24
|
+
fallback_src: Optional[Union[Var[str], str]] = None,
|
|
25
|
+
fit: Optional[Union[Var[str], str]] = None,
|
|
26
|
+
html_height: Optional[Union[Var[str], str]] = None,
|
|
27
|
+
html_width: Optional[Union[Var[str], str]] = None,
|
|
28
|
+
ignore_fallback: Optional[Union[Var[bool], bool]] = None,
|
|
29
|
+
loading: Optional[
|
|
30
|
+
Union[Var[Literal["eager", "lazy"]], Literal["eager", "lazy"]]
|
|
31
|
+
] = None,
|
|
32
|
+
src: Optional[Union[Var[Any], Any]] = None,
|
|
33
|
+
alt: Optional[Union[Var[str], str]] = None,
|
|
34
|
+
src_set: Optional[Union[Var[str], str]] = None,
|
|
35
|
+
style: Optional[Style] = None,
|
|
36
|
+
key: Optional[Any] = None,
|
|
37
|
+
id: Optional[Any] = None,
|
|
38
|
+
class_name: Optional[Any] = None,
|
|
39
|
+
autofocus: Optional[bool] = None,
|
|
40
|
+
custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
|
|
41
|
+
on_blur: Optional[
|
|
42
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
43
|
+
] = None,
|
|
44
|
+
on_click: Optional[
|
|
45
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
46
|
+
] = None,
|
|
47
|
+
on_context_menu: Optional[
|
|
48
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
49
|
+
] = None,
|
|
50
|
+
on_double_click: Optional[
|
|
51
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
52
|
+
] = None,
|
|
53
|
+
on_error: Optional[
|
|
54
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
55
|
+
] = None,
|
|
56
|
+
on_focus: Optional[
|
|
57
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
58
|
+
] = None,
|
|
59
|
+
on_load: Optional[
|
|
60
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
61
|
+
] = None,
|
|
62
|
+
on_mount: Optional[
|
|
63
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
64
|
+
] = None,
|
|
65
|
+
on_mouse_down: Optional[
|
|
66
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
67
|
+
] = None,
|
|
68
|
+
on_mouse_enter: Optional[
|
|
69
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
70
|
+
] = None,
|
|
71
|
+
on_mouse_leave: Optional[
|
|
72
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
73
|
+
] = None,
|
|
74
|
+
on_mouse_move: Optional[
|
|
75
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
76
|
+
] = None,
|
|
77
|
+
on_mouse_out: Optional[
|
|
78
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
79
|
+
] = None,
|
|
80
|
+
on_mouse_over: Optional[
|
|
81
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
82
|
+
] = None,
|
|
83
|
+
on_mouse_up: Optional[
|
|
84
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
85
|
+
] = None,
|
|
86
|
+
on_scroll: Optional[
|
|
87
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
88
|
+
] = None,
|
|
89
|
+
on_unmount: Optional[
|
|
90
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
91
|
+
] = None,
|
|
92
|
+
**props
|
|
93
|
+
) -> "Image":
|
|
94
|
+
"""Create an Image component.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
*children: The children of the image.
|
|
98
|
+
align: How to align the image within its bounds. It maps to css `object-position` property.
|
|
99
|
+
fallback: Fallback Reflex component to show if image is loading or image fails.
|
|
100
|
+
fallback_src: Fallback image src to show if image is loading or image fails.
|
|
101
|
+
fit: How the image to fit within its bounds. It maps to css `object-fit` property.
|
|
102
|
+
html_height: The native HTML height attribute to the passed to the img.
|
|
103
|
+
html_width: The native HTML width attribute to the passed to the img.
|
|
104
|
+
ignore_fallback: If true, opt out of the fallbackSrc logic and use as img.
|
|
105
|
+
loading: "eager" | "lazy"
|
|
106
|
+
src: The path/url to the image or PIL image object.
|
|
107
|
+
alt: The alt text of the image.
|
|
108
|
+
src_set: Provide multiple sources for an image, allowing the browser to select the most appropriate source based on factors like screen resolution and device capabilities. Learn more _[here](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images)_
|
|
109
|
+
style: The style of the component.
|
|
110
|
+
key: A unique key for the component.
|
|
111
|
+
id: The id for the component.
|
|
112
|
+
class_name: The class name for the component.
|
|
113
|
+
autofocus: Whether the component should take the focus once the page is loaded
|
|
114
|
+
custom_attrs: custom attribute
|
|
115
|
+
**props: The props of the image.
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
The Image component.
|
|
119
|
+
"""
|
|
120
|
+
...
|
reflex/components/component.py
CHANGED
|
@@ -40,7 +40,7 @@ from reflex.event import (
|
|
|
40
40
|
call_event_handler,
|
|
41
41
|
get_handler_args,
|
|
42
42
|
)
|
|
43
|
-
from reflex.style import Style
|
|
43
|
+
from reflex.style import Style, format_as_emotion
|
|
44
44
|
from reflex.utils import console, format, imports, types
|
|
45
45
|
from reflex.utils.imports import ImportVar
|
|
46
46
|
from reflex.utils.serializers import serializer
|
|
@@ -288,6 +288,7 @@ class Component(BaseComponent, ABC):
|
|
|
288
288
|
|
|
289
289
|
kwargs["style"] = Style(
|
|
290
290
|
{
|
|
291
|
+
**self.get_fields()["style"].default,
|
|
291
292
|
**style,
|
|
292
293
|
**{attr: value for attr, value in kwargs.items() if attr not in fields},
|
|
293
294
|
}
|
|
@@ -445,6 +446,26 @@ class Component(BaseComponent, ABC):
|
|
|
445
446
|
|
|
446
447
|
return _compile_component(self)
|
|
447
448
|
|
|
449
|
+
def _apply_theme(self, theme: Component):
|
|
450
|
+
"""Apply the theme to this component.
|
|
451
|
+
|
|
452
|
+
Args:
|
|
453
|
+
theme: The theme to apply.
|
|
454
|
+
"""
|
|
455
|
+
pass
|
|
456
|
+
|
|
457
|
+
def apply_theme(self, theme: Component):
|
|
458
|
+
"""Apply a theme to the component and its children.
|
|
459
|
+
|
|
460
|
+
Args:
|
|
461
|
+
theme: The theme to apply.
|
|
462
|
+
"""
|
|
463
|
+
self._apply_theme(theme)
|
|
464
|
+
for child in self.children:
|
|
465
|
+
if not isinstance(child, Component):
|
|
466
|
+
continue
|
|
467
|
+
child.apply_theme(theme)
|
|
468
|
+
|
|
448
469
|
def _render(self, props: dict[str, Any] | None = None) -> Tag:
|
|
449
470
|
"""Define how to render the component in React.
|
|
450
471
|
|
|
@@ -603,7 +624,7 @@ class Component(BaseComponent, ABC):
|
|
|
603
624
|
Returns:
|
|
604
625
|
The dictionary of the component style as value and the style notation as key.
|
|
605
626
|
"""
|
|
606
|
-
return {"
|
|
627
|
+
return {"css": Var.create(format_as_emotion(self.style))}
|
|
607
628
|
|
|
608
629
|
def render(self) -> Dict:
|
|
609
630
|
"""Render the component.
|
|
@@ -785,6 +806,10 @@ class Component(BaseComponent, ABC):
|
|
|
785
806
|
for child in self.children:
|
|
786
807
|
dynamic_imports |= child.get_dynamic_imports()
|
|
787
808
|
|
|
809
|
+
for prop in self.get_component_props():
|
|
810
|
+
if getattr(self, prop) is not None:
|
|
811
|
+
dynamic_imports |= getattr(self, prop).get_dynamic_imports()
|
|
812
|
+
|
|
788
813
|
# Return the dynamic imports
|
|
789
814
|
return dynamic_imports
|
|
790
815
|
|
|
@@ -7,7 +7,7 @@ from typing import Any, Dict, List, Union
|
|
|
7
7
|
from reflex.components.component import Component
|
|
8
8
|
from reflex.components.tags import Tag
|
|
9
9
|
from reflex.utils import imports, types
|
|
10
|
-
from reflex.utils.serializers import serialize
|
|
10
|
+
from reflex.utils.serializers import serialize
|
|
11
11
|
from reflex.vars import BaseVar, ComputedVar, Var
|
|
12
12
|
|
|
13
13
|
|
|
@@ -129,39 +129,3 @@ class DataTable(Gridjs):
|
|
|
129
129
|
|
|
130
130
|
# Render the table.
|
|
131
131
|
return super()._render()
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
try:
|
|
135
|
-
from pandas import DataFrame
|
|
136
|
-
|
|
137
|
-
def format_dataframe_values(df: DataFrame) -> List[List[Any]]:
|
|
138
|
-
"""Format dataframe values to a list of lists.
|
|
139
|
-
|
|
140
|
-
Args:
|
|
141
|
-
df: The dataframe to format.
|
|
142
|
-
|
|
143
|
-
Returns:
|
|
144
|
-
The dataframe as a list of lists.
|
|
145
|
-
"""
|
|
146
|
-
return [
|
|
147
|
-
[str(d) if isinstance(d, (list, tuple)) else d for d in data]
|
|
148
|
-
for data in list(df.values.tolist())
|
|
149
|
-
]
|
|
150
|
-
|
|
151
|
-
@serializer
|
|
152
|
-
def serialize_dataframe(df: DataFrame) -> dict:
|
|
153
|
-
"""Serialize a pandas dataframe.
|
|
154
|
-
|
|
155
|
-
Args:
|
|
156
|
-
df: The dataframe to serialize.
|
|
157
|
-
|
|
158
|
-
Returns:
|
|
159
|
-
The serialized dataframe.
|
|
160
|
-
"""
|
|
161
|
-
return {
|
|
162
|
-
"columns": df.columns.tolist(),
|
|
163
|
-
"data": format_dataframe_values(df),
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
except ImportError:
|
|
167
|
-
pass
|
|
@@ -11,7 +11,7 @@ from typing import Any, Dict, List, Union
|
|
|
11
11
|
from reflex.components.component import Component
|
|
12
12
|
from reflex.components.tags import Tag
|
|
13
13
|
from reflex.utils import imports, types
|
|
14
|
-
from reflex.utils.serializers import serialize
|
|
14
|
+
from reflex.utils.serializers import serialize
|
|
15
15
|
from reflex.vars import BaseVar, ComputedVar, Var
|
|
16
16
|
|
|
17
17
|
class Gridjs(Component):
|
|
@@ -183,13 +183,3 @@ class DataTable(Gridjs):
|
|
|
183
183
|
ValueError: If a pandas dataframe is passed in and columns are also provided.
|
|
184
184
|
"""
|
|
185
185
|
...
|
|
186
|
-
|
|
187
|
-
try:
|
|
188
|
-
from pandas import DataFrame
|
|
189
|
-
|
|
190
|
-
def format_dataframe_values(df: DataFrame) -> List[List[Any]]: ...
|
|
191
|
-
@serializer
|
|
192
|
-
def serialize_dataframe(df: DataFrame) -> dict: ...
|
|
193
|
-
|
|
194
|
-
except ImportError:
|
|
195
|
-
pass
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"""Element classes. This is an auto-generated file. Do not edit. See ../generate.py."""
|
|
2
|
-
from typing import Union
|
|
2
|
+
from typing import Any, Dict, Union
|
|
3
3
|
|
|
4
4
|
from reflex.components.el.element import Element
|
|
5
|
+
from reflex.constants.event import EventTriggers
|
|
5
6
|
from reflex.vars import Var
|
|
6
7
|
|
|
7
8
|
from .base import BaseHTML
|
|
@@ -205,6 +206,21 @@ class Input(BaseHTML):
|
|
|
205
206
|
# The width of the input (only for type="image")
|
|
206
207
|
width: Var[Union[str, int, bool]]
|
|
207
208
|
|
|
209
|
+
def get_event_triggers(self) -> Dict[str, Any]:
|
|
210
|
+
"""Get the event triggers that pass the component's value to the handler.
|
|
211
|
+
|
|
212
|
+
Returns:
|
|
213
|
+
A dict mapping the event trigger to the var that is passed to the handler.
|
|
214
|
+
"""
|
|
215
|
+
return {
|
|
216
|
+
**super().get_event_triggers(),
|
|
217
|
+
EventTriggers.ON_CHANGE: lambda e0: [e0.target.value],
|
|
218
|
+
EventTriggers.ON_FOCUS: lambda e0: [e0.target.value],
|
|
219
|
+
EventTriggers.ON_BLUR: lambda e0: [e0.target.value],
|
|
220
|
+
EventTriggers.ON_KEY_DOWN: lambda e0: [e0.key],
|
|
221
|
+
EventTriggers.ON_KEY_UP: lambda e0: [e0.key],
|
|
222
|
+
}
|
|
223
|
+
|
|
208
224
|
|
|
209
225
|
class Label(BaseHTML):
|
|
210
226
|
"""Display the label element."""
|
|
@@ -341,6 +357,17 @@ class Select(BaseHTML):
|
|
|
341
357
|
# Number of visible options in a drop-down list
|
|
342
358
|
size: Var[Union[str, int, bool]]
|
|
343
359
|
|
|
360
|
+
def get_event_triggers(self) -> Dict[str, Any]:
|
|
361
|
+
"""Get the event triggers that pass the component's value to the handler.
|
|
362
|
+
|
|
363
|
+
Returns:
|
|
364
|
+
A dict mapping the event trigger to the var that is passed to the handler.
|
|
365
|
+
"""
|
|
366
|
+
return {
|
|
367
|
+
**super().get_event_triggers(),
|
|
368
|
+
EventTriggers.ON_CHANGE: lambda e0: [e0.target.value],
|
|
369
|
+
}
|
|
370
|
+
|
|
344
371
|
|
|
345
372
|
class Textarea(BaseHTML):
|
|
346
373
|
"""Display the textarea element."""
|
|
@@ -388,3 +415,18 @@ class Textarea(BaseHTML):
|
|
|
388
415
|
|
|
389
416
|
# How the text in the textarea is to be wrapped when submitting the form
|
|
390
417
|
wrap: Var[Union[str, int, bool]]
|
|
418
|
+
|
|
419
|
+
def get_event_triggers(self) -> Dict[str, Any]:
|
|
420
|
+
"""Get the event triggers that pass the component's value to the handler.
|
|
421
|
+
|
|
422
|
+
Returns:
|
|
423
|
+
A dict mapping the event trigger to the var that is passed to the handler.
|
|
424
|
+
"""
|
|
425
|
+
return {
|
|
426
|
+
**super().get_event_triggers(),
|
|
427
|
+
EventTriggers.ON_CHANGE: lambda e0: [e0.target.value],
|
|
428
|
+
EventTriggers.ON_FOCUS: lambda e0: [e0.target.value],
|
|
429
|
+
EventTriggers.ON_BLUR: lambda e0: [e0.target.value],
|
|
430
|
+
EventTriggers.ON_KEY_DOWN: lambda e0: [e0.key],
|
|
431
|
+
EventTriggers.ON_KEY_UP: lambda e0: [e0.key],
|
|
432
|
+
}
|
|
@@ -7,8 +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 Union
|
|
10
|
+
from typing import Any, Dict, Union
|
|
11
11
|
from reflex.components.el.element import Element
|
|
12
|
+
from reflex.constants.event import EventTriggers
|
|
12
13
|
from reflex.vars import Var
|
|
13
14
|
from .base import BaseHTML
|
|
14
15
|
|
|
@@ -589,6 +590,7 @@ class Form(BaseHTML):
|
|
|
589
590
|
...
|
|
590
591
|
|
|
591
592
|
class Input(BaseHTML):
|
|
593
|
+
def get_event_triggers(self) -> Dict[str, Any]: ...
|
|
592
594
|
@overload
|
|
593
595
|
@classmethod
|
|
594
596
|
def create( # type: ignore
|
|
@@ -725,6 +727,9 @@ class Input(BaseHTML):
|
|
|
725
727
|
on_blur: Optional[
|
|
726
728
|
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
727
729
|
] = None,
|
|
730
|
+
on_change: Optional[
|
|
731
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
732
|
+
] = None,
|
|
728
733
|
on_click: Optional[
|
|
729
734
|
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
730
735
|
] = None,
|
|
@@ -737,6 +742,12 @@ class Input(BaseHTML):
|
|
|
737
742
|
on_focus: Optional[
|
|
738
743
|
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
739
744
|
] = None,
|
|
745
|
+
on_key_down: Optional[
|
|
746
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
747
|
+
] = None,
|
|
748
|
+
on_key_up: Optional[
|
|
749
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
750
|
+
] = None,
|
|
740
751
|
on_mount: Optional[
|
|
741
752
|
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
742
753
|
] = None,
|
|
@@ -1877,6 +1888,7 @@ class Progress(BaseHTML):
|
|
|
1877
1888
|
...
|
|
1878
1889
|
|
|
1879
1890
|
class Select(BaseHTML):
|
|
1891
|
+
def get_event_triggers(self) -> Dict[str, Any]: ...
|
|
1880
1892
|
@overload
|
|
1881
1893
|
@classmethod
|
|
1882
1894
|
def create( # type: ignore
|
|
@@ -1952,6 +1964,9 @@ class Select(BaseHTML):
|
|
|
1952
1964
|
on_blur: Optional[
|
|
1953
1965
|
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
1954
1966
|
] = None,
|
|
1967
|
+
on_change: Optional[
|
|
1968
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
1969
|
+
] = None,
|
|
1955
1970
|
on_click: Optional[
|
|
1956
1971
|
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
1957
1972
|
] = None,
|
|
@@ -2042,6 +2057,7 @@ class Select(BaseHTML):
|
|
|
2042
2057
|
...
|
|
2043
2058
|
|
|
2044
2059
|
class Textarea(BaseHTML):
|
|
2060
|
+
def get_event_triggers(self) -> Dict[str, Any]: ...
|
|
2045
2061
|
@overload
|
|
2046
2062
|
@classmethod
|
|
2047
2063
|
def create( # type: ignore
|
|
@@ -2131,6 +2147,9 @@ class Textarea(BaseHTML):
|
|
|
2131
2147
|
on_blur: Optional[
|
|
2132
2148
|
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
2133
2149
|
] = None,
|
|
2150
|
+
on_change: Optional[
|
|
2151
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
2152
|
+
] = None,
|
|
2134
2153
|
on_click: Optional[
|
|
2135
2154
|
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
2136
2155
|
] = None,
|
|
@@ -2143,6 +2162,12 @@ class Textarea(BaseHTML):
|
|
|
2143
2162
|
on_focus: Optional[
|
|
2144
2163
|
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
2145
2164
|
] = None,
|
|
2165
|
+
on_key_down: Optional[
|
|
2166
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
2167
|
+
] = None,
|
|
2168
|
+
on_key_up: Optional[
|
|
2169
|
+
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
2170
|
+
] = None,
|
|
2146
2171
|
on_mount: Optional[
|
|
2147
2172
|
Union[EventHandler, EventSpec, list, function, BaseVar]
|
|
2148
2173
|
] = None,
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"""Component for displaying a plotly graph."""
|
|
2
2
|
|
|
3
|
-
import json
|
|
4
3
|
from typing import Any, Dict, List
|
|
5
4
|
|
|
6
5
|
from reflex.components.component import NoSSRComponent
|
|
7
|
-
from reflex.utils.serializers import serializer
|
|
8
6
|
from reflex.vars import Var
|
|
9
7
|
|
|
10
8
|
try:
|
|
@@ -42,23 +40,3 @@ class Plotly(PlotlyLib):
|
|
|
42
40
|
|
|
43
41
|
# If true, the graph will resize when the window is resized.
|
|
44
42
|
use_resize_handler: Var[bool]
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
try:
|
|
48
|
-
from plotly.graph_objects import Figure
|
|
49
|
-
from plotly.io import to_json
|
|
50
|
-
|
|
51
|
-
@serializer
|
|
52
|
-
def serialize_figure(figure: Figure) -> list:
|
|
53
|
-
"""Serialize a plotly figure.
|
|
54
|
-
|
|
55
|
-
Args:
|
|
56
|
-
figure: The figure to serialize.
|
|
57
|
-
|
|
58
|
-
Returns:
|
|
59
|
-
The serialized figure.
|
|
60
|
-
"""
|
|
61
|
-
return json.loads(str(to_json(figure)))["data"]
|
|
62
|
-
|
|
63
|
-
except ImportError:
|
|
64
|
-
pass
|
|
@@ -7,10 +7,8 @@ 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
|
-
import json
|
|
11
10
|
from typing import Any, Dict, List
|
|
12
11
|
from reflex.components.component import NoSSRComponent
|
|
13
|
-
from reflex.utils.serializers import serializer
|
|
14
12
|
from reflex.vars import Var
|
|
15
13
|
|
|
16
14
|
try:
|
|
@@ -185,13 +183,3 @@ class Plotly(PlotlyLib):
|
|
|
185
183
|
TypeError: If an invalid child is passed.
|
|
186
184
|
"""
|
|
187
185
|
...
|
|
188
|
-
|
|
189
|
-
try:
|
|
190
|
-
from plotly.graph_objects import Figure # type: ignore
|
|
191
|
-
from plotly.io import to_json
|
|
192
|
-
|
|
193
|
-
@serializer
|
|
194
|
-
def serialize_figure(figure: Figure) -> list: ... # type: ignore
|
|
195
|
-
|
|
196
|
-
except ImportError:
|
|
197
|
-
pass
|