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
Implement raw HTML elements #627
Conversation
Dynamic exports can't be statically analyzed. Going to take the approach of compiling out to __init__.py now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job adding all this! There's some lint errors to clean up then we can merge it in.
will this be merge any time soon? |
Yes this will be merged this weekend. Sorry this last week has been crazy busy for us. |
Take your time. I'm just asking because my project rely heavily on this feature. 😆 |
We need to test this pr more. This will be out in the 0.1.22 release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, looks good!
This PR adds raw HTML elements under the
pynecone.el
namespace that can be used in conjunction withclass_name
and stylesheets to support Tailwind and other custom workflows. (Support for stylesheets is not included in this PR, I’ll make a separate PR for that.)The following is now possible:
This PR contributes the following files under
pynecone/el/
:element.py
Subclasses
Component
in order to remove the Chakrasx
prop from the render.sx
has been replaced with the rawstyle
prop, meaning when you say something likeIt is compiled to:
constants.py
This file contains constants that are used in generating base elements:
1.
ELEMENTS
: A list of all valid HTML elements (including deprecated and obsolete ones) from MDN.2.
ATTR_TO_ELEMENTS
: A dict mapping HTML attributes to all the elements that can possess those attributes. (e.g."autofocus": ["button", "input", ...]
)3.
PROP_TO_ELEMENTS
(derived fromATTR_TO_ELEMENTS
): A dict mapping Pynecone props (e.g.auto_focus
) to the elements which can possess them.4.
_POSSIBLE_STANDARD_NAMES
: Used internally to go from HTML attribute names to their React versions.5.
ELEMENT_TO_PROPS
: This is justPROP_TO_ELEMENTS
inverted; maps elements to the props that they can legally possess.generate.py
This is the main compilation script. It's pretty short, so just read the source code. TL;DR, it uses a simple template to generate a subclass of
Element
for each element inELEMENT_TO_PROPS
, and outputs all the generated code toelements/__init__.py
.elements/__init__.py
Contains all the generated elements. Should not need manual review, just skim if necessary.
Design Decisions
<del />
element is calledDel
, but it's used asel.del_
sincedel
(lowercase) is a reserved keyword. I could have made the subclass nameDel_
, but I don't think that makes sense since reserved keywords are case-sensitive andDel
works fine. This way, as a rule of thumb, you can assume that if something in the API resembles a keyword, you just need to append an underscore (with the exception of theclass
prop, which is used asclass_name
).async
is a reserved keyword; theasync_
prop is used instead.pynecone/el/elements/__init__.py
) rather than multiple files (pynecone/els/elements/a.py
,pynecone/els/elements/abbr.py
, etc.) because we don't want to manually edit the generated code. The generated file contains a "Do not edit" warning to this effect.Misc.
All Submissions:
Type of change
New Feature Submission:
Changes To Core Features: