-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow Styled tags to be updated via withComponent #232
Conversation
bab4bf4
to
6bdf000
Compare
938bb62
to
fd75382
Compare
Fixing tests today. |
fd75382
to
a548480
Compare
Codecov Report
@@ Coverage Diff @@
## master #232 +/- ##
==========================================
+ Coverage 97.33% 97.34% +0.01%
==========================================
Files 17 17
Lines 563 566 +3
Branches 134 134
==========================================
+ Hits 548 551 +3
Misses 11 11
Partials 4 4
Continue to review full report at Codecov.
|
7dbac4f
to
ecc3d6a
Compare
29ee322
to
ba9d250
Compare
Running into some errors due to updates. Adding some documentation for |
1b30e59
to
d3ecb31
Compare
- Add `withComponent` method to create new styled component - Update react test - Update snapshot
3b7992c
to
2e4c66d
Compare
Fixed up errors, but running into an issue where components created with See Avatar class name here: https://deploy-preview-232--emotion.netlify.com/#withcomponent Example. <span data-reactroot="" class="css-Circle-wrfx8o0 css-mzfoqi">
<img src="/a76dfa0d18a0536af9e917cdb8f873b9.png" class="css-1 css-mzfoqi">
</span> @tkh44 / @mitchellhamilton , could this cause collisions? I was able to get it to use the same class as Circle |
@ifyoumakeit This is because we create those unique classes with the identifier in the babel plugin. We could create a unique class for |
I need to think about this a bit more. We want to get this in version 8, but I want to do it right. |
Makes sense, definitely want to make sure the solution is performant/useful and fits in well with the future of emotion. |
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.
lgtm
docs/styled.md
Outdated
@@ -66,3 +66,18 @@ const H2 = styled('h2')('some-other-class', { | |||
}) | |||
|
|||
``` | |||
|
|||
### withComponent |
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.
I think we should make this its own file. Mention it and link to this new file. This way when we make docs pages withComponent will have its own page.
@@ -90,6 +90,12 @@ export default function(tag, options: { e: string }) { | |||
Styled.__emotion_styles = styles | |||
Styled.__emotion_base = baseTag | |||
|
|||
Styled.withComponent = nextTag => { | |||
return createStyled(nextTag, options)(styles) |
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.
👍 this is much cleaner and more obvious from first glance. Thanks @mitchellhamilton .
What:
Added
withComponent
method to allowstyled
components to update tag name. Components can also be extended via this method.Why:
Tags may need to be changed to comply with accessibility and HTML standards. One use case is headings (h1, h2, etc...) that may need to be swapped depending on document depth.
The method na
How:
Added a new method to the
Styled
component that re-callscreateStyled
with the new tag/component.Checklist: