Skip to content

Commit 6d42a3a

Browse files
committed
migrate reflex components to that style
1 parent a0f199d commit 6d42a3a

94 files changed

Lines changed: 4465 additions & 3725 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/reflex-docgen/src/reflex_docgen/__init__.py

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,6 @@ class ComponentDocumentation:
3636
] = ()
3737

3838

39-
def get_prop(
40-
prop_name: str, prop_annotated_type: InspectedAnnotation
41-
) -> PropDocumentation:
42-
"""Get a Prop object from a prop name and annotated type.
43-
44-
Args:
45-
prop_name: The name of the prop.
46-
prop_annotated_type: The annotated type of the prop.
47-
48-
Returns:
49-
The Prop object for the prop.
50-
"""
51-
doc = next(
52-
(
53-
annotation.documentation
54-
for annotation in prop_annotated_type.metadata
55-
if isinstance(annotation, Doc)
56-
),
57-
None,
58-
)
59-
if doc is not None:
60-
default_value = None
61-
for default_indicator in ["Defaults to", "Default:"]:
62-
if default_indicator in doc:
63-
doc, default_value = doc.split(default_indicator, maxsplit=1)
64-
default_value = default_value.strip().rstrip(".")
65-
doc = doc.strip().rstrip(".")
66-
break
67-
else:
68-
default_value = None
69-
return PropDocumentation(
70-
name=prop_name,
71-
type=prop_annotated_type.type,
72-
description=doc.rstrip(".") + "." if doc else None,
73-
default_value=default_value,
74-
)
75-
76-
7739
def get_component_props(
7840
component_cls: type[Component],
7941
) -> tuple[PropDocumentation, ...]:
@@ -85,18 +47,33 @@ def get_component_props(
8547
Returns:
8648
The props for the component.
8749
"""
88-
props = component_cls.get_props()
89-
hints = get_type_hints(component_cls, include_extras=True)
90-
91-
return tuple(
92-
get_prop(
93-
prop_name,
94-
inspect_annotation(
95-
hints[prop_name], annotation_source=AnnotationSource.CLASS
96-
),
50+
props = component_cls.get_js_fields()
51+
52+
result = []
53+
for prop_name, component_field in props.items():
54+
doc = component_field.doc
55+
default_value = None
56+
57+
# If the field has a doc attribute and no Annotated[..., Doc(...)] was found,
58+
# use the field's doc as the description.
59+
if doc is not None:
60+
for default_indicator in ["Defaults to", "Default:"]:
61+
if default_indicator in doc:
62+
doc, default_value = doc.split(default_indicator, maxsplit=1)
63+
default_value = default_value.strip().rstrip(".")
64+
doc = doc.strip().rstrip(".")
65+
break
66+
67+
result.append(
68+
PropDocumentation(
69+
name=prop_name,
70+
type=component_field.type_,
71+
description=doc.rstrip(".") + "." if doc else None,
72+
default_value=default_value,
73+
)
9774
)
98-
for prop_name in props
99-
)
75+
76+
return tuple(result)
10077

10178

10279
def generate_documentation(component_cls: type[Component]) -> ComponentDocumentation:

pyi_hashes.json

Lines changed: 102 additions & 102 deletions
Large diffs are not rendered by default.

reflex/components/base/error_boundary.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from reflex.components.component import Component
5+
from reflex.components.component import Component, field
66
from reflex.components.datadisplay.logo import svg_logo
77
from reflex.components.el import a, button, div, h2, hr, p, pre, svg
88
from reflex.event import EventHandler, set_clipboard
@@ -39,11 +39,13 @@ class ErrorBoundary(Component):
3939
library = "react-error-boundary@6.1.1"
4040
tag = "ErrorBoundary"
4141

42-
# Fired when the boundary catches an error.
43-
on_error: EventHandler[on_error_spec]
42+
on_error: EventHandler[on_error_spec] = field(
43+
doc="Fired when the boundary catches an error."
44+
)
4445

45-
# Rendered instead of the children when an error is caught.
46-
fallback_render: Var[Component]
46+
fallback_render: Var[Component] = field(
47+
doc="Rendered instead of the children when an error is caught."
48+
)
4749

4850
@classmethod
4951
def create(cls, *children, **props):

reflex/components/base/link.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Display the title of the current page."""
22

3+
from reflex.components.component import field
34
from reflex.components.el.elements.base import BaseHTML
45
from reflex.vars.base import Var
56

@@ -9,35 +10,28 @@ class RawLink(BaseHTML):
910

1011
tag = "link"
1112

12-
# The href.
13-
href: Var[str]
13+
href: Var[str] = field(doc="The href.")
1414

15-
# The type of link.
16-
rel: Var[str]
15+
rel: Var[str] = field(doc="The type of link.")
1716

1817

1918
class ScriptTag(BaseHTML):
2019
"""A script tag with the specified type and source."""
2120

2221
tag = "script"
2322

24-
# The type of script represented.
25-
type_: Var[str]
23+
type_: Var[str] = field(doc="The type of script represented.")
2624

27-
# The URI of an external script.
28-
source: Var[str]
25+
source: Var[str] = field(doc="The URI of an external script.")
2926

30-
# Metadata to verify the content of the script.
31-
integrity: Var[str]
27+
integrity: Var[str] = field(doc="Metadata to verify the content of the script.")
3228

33-
# Whether to allow cross-origin requests.
34-
crossorigin: Var[str]
29+
crossorigin: Var[str] = field(doc="Whether to allow cross-origin requests.")
3530

36-
# Indicates which referrer to send when fetching the script.
37-
referrer_policy: Var[str]
31+
referrer_policy: Var[str] = field(
32+
doc="Indicates which referrer to send when fetching the script."
33+
)
3834

39-
# Whether to asynchronously load the script.
40-
is_async: Var[bool]
35+
is_async: Var[bool] = field(doc="Whether to asynchronously load the script.")
4136

42-
# Whether to defer loading the script.
43-
defer: Var[bool]
37+
defer: Var[bool] = field(doc="Whether to defer loading the script.")

reflex/components/base/meta.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
from reflex.components.base.bare import Bare
6+
from reflex.components.component import field
67
from reflex.components.el import elements
78
from reflex.components.el.elements.metadata import Meta as Meta # for compatibility
89
from reflex.vars.base import Var
@@ -30,12 +31,14 @@ def render(self) -> dict:
3031
class Description(elements.Meta):
3132
"""A component that displays the title of the current page."""
3233

33-
# The type of the description.
34-
name: Var[str] = Var.create("description")
34+
name: Var[str] = field(
35+
default=Var.create("description"), doc="The type of the description."
36+
)
3537

3638

3739
class Image(elements.Meta):
3840
"""A component that displays the title of the current page."""
3941

40-
# The type of the image.
41-
property: Var[str] = Var.create("og:image")
42+
property: Var[str] = field(
43+
default=Var.create("og:image"), doc="The type of the image."
44+
)

0 commit comments

Comments
 (0)