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
Add setup function for pragma, forwardRef, and theme #76
Conversation
src/styled.js
Outdated
return function Styled(props) { | ||
const _props = (_ctx.p = Object.assign({}, props)); | ||
function Styled(props, ref) { | ||
const theme = useTheme(); |
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.
Does it has to be a function? Could it be a plain object? Could become a perf bottleneck on user land.
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 to get feature parity with other CSS-in-JS theming capability, i.e.
const useTheme = () => useContext(ThemeContext)
Here's how it's similarly done in styled-components@5
- https://github.com/styled-components/styled-components/blob/v5/packages/styled-components/src/models/StyledComponent.js#L129
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.
For non context user, it could be just () => theme
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 so great! 🙏 Thank you for opening this!
This is really great! Really love it! How do you feel about it? Can you add the tests and everything? What can I help you with? |
src/styled.js
Outdated
let h; | ||
const setPragma = pragma => (h = pragma); | ||
let h, forwardRef, useTheme; | ||
const setup = (_h, _forwardRef, _useTheme = () => {}) => { |
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.
How about not defining a default _useTheme
? Would that break?
src/styled.js
Outdated
const _props = (_ctx.p = Object.assign({}, props)); | ||
function Styled(props, ref) { | ||
const theme = useTheme(); | ||
const _props = (_ctx.p = Object.assign(theme ? { theme } : {}, props)); |
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.
Also what do you think?
const _props = (_ctx.p = Object.assign(theme ? { theme } : {}, props)); | |
const _props = (_ctx.p = Object.assign(useTheme ? useTheme() : {}, props)); |
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.
Technically it's possible, but usually useTheme
just returns theme
instead of { theme }
, e.g. https://github.com/styled-components/styled-components/blob/v5/packages/styled-components/src/hooks/useTheme.js
It'd have to be like this instead,
const _props = (_ctx.p = Object.assign(useTheme ? { theme: useTheme() } : {}, props));
Let me give it a spin and see how the bundle size looks like, coz with gzip more code != bigger bundle size and vice-versa 😁
Did I mention how exciting this looks? 😄 Can't wait to have the theme support in. I can see myself using it, for sure! This is a good one! Really appreciate your time on this! 👍 |
Done the changes for both
I'll work on the tests for this. |
Hi, |
Hey @nksaraf thanks for checking goober all along! 🙂 Well anything that comes to mind! There a couple more things inside the issues that can be tackled as well. Give them a try see what you can do. Thank you for your time! |
@cristianbote I've updated the implementation slightly. I observed that in styled-components, the I've also added unit and integration tests for the changes. |
This was going strong up to a month or so ago. Is this PR still moving forward? Is something holding it up? Are we still holding out hope it can get 0.02 kb smaller? |
Hey @ryansolid! :) Thanks for stopping by! Well, it's just really my lack of time to do a perf bench on this and check the sizes. Also, this will definitely be a major version upgrade, since the whole |
Oh and documentation about the changes. |
Had a look into this change sets and it seems that this would add some considerable size. Something like |
Co-Authored-By: Jovi De Croock <decroockjovi@gmail.com>
Co-Authored-By: Jovi De Croock <decroockjovi@gmail.com>
Hey @donysukardi things are happening! 🥳😎 Thanks to @JoviDeCroock for pushing this with his PR for autoprefixer. Overall this will end up under 1024B 🥳👍🥜 wohoo! So excited! This will definitely be v2 |
The tests failures are my doing 😑 sorry. I resolved the conflicts but somehow missed stuff. Will correct then asap |
This is awesome! I am excited!! Let me know if there's anything else I can help with :D |
Awesome! @donysukardi I think @JoviDeCroock opened a PR against yours to fix the test failures. In here https://github.com/donysukardi/goober/pull/1/files I think that would make this to pass. |
Alrighty! 😄 everything is fine. The above failures are expected 👍 Thank you soo much @donysukardi! 🎉 🌟 |
Pending tasks
This change increases the bundle size though. Any idea how we could trim it to fit the maxSize?
Related Issues: Theming (#61), forwardRef (#63)