Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GTM-345]Define component props in class for doc discoverability #4183

Merged
merged 20 commits into from
Nov 1, 2024

Conversation

ElijahAhianyo
Copy link
Collaborator

@ElijahAhianyo ElijahAhianyo commented Oct 16, 2024

Defines/Moves create method args where possible in components as props so reflex-web can discover them

@ElijahAhianyo ElijahAhianyo changed the title [WIP]Define component props in class for doc discoverability [GTM-345]Define component props in class for doc discoverability Oct 18, 2024
Copy link

linear bot commented Oct 18, 2024

@ElijahAhianyo ElijahAhianyo marked this pull request as ready for review October 18, 2024 14:03
Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think we can take this as is, because some of these create kwargs that are replaced by props are not valid as Var

@@ -411,6 +411,12 @@ class CodeBlock(Component):
# Props passed down to the code tag.
code_tag_props: Var[Dict[str, str]]

# Whether a copy button should appear.
can_copy: Var[Optional[bool]] = Var.create(False)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other problem here is now these are annotated and treated as Var... but in many cases, the code in the create is using python if statements and potential other operations that are not valid on Var types.

I'd be more okay defining these as regular model fields (i.e. without the Var), but then i don't think they'd be automatically picked up by the pyi generator and the doc generation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regular model fields get picked up by the pyi generator and reflex-web. Some kwargs (that were moved) accept literals or vars. Maybe in this case it might be worth specifying the typing of these model fields to accept both literals and vars

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example rx.list where items can be an iterable or a var containing an iterable so an appropriate typing here might be
items: Optional[Union[Iterable, Var[Iterable]]] = None

reflex/components/radix/primitives/accordion.py Outdated Show resolved Hide resolved
reflex/components/radix/themes/color_mode.py Outdated Show resolved Hide resolved
reflex/components/radix/themes/layout/list.py Outdated Show resolved Hide resolved
reflex/components/radix/themes/layout/list.py Outdated Show resolved Hide resolved
reflex/components/radix/themes/layout/list.py Outdated Show resolved Hide resolved
masenf
masenf previously approved these changes Oct 25, 2024
reflex/components/radix/primitives/accordion.py Outdated Show resolved Hide resolved
Co-authored-by: Masen Furer <m_github@0x26.net>
masenf
masenf previously approved these changes Oct 30, 2024
@ElijahAhianyo ElijahAhianyo merged commit bcd5177 into main Nov 1, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants