-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
feat: styled.extend #250
feat: styled.extend #250
Conversation
fba9dec
to
3ebdcd7
Compare
de6ddbc
to
65fe5f6
Compare
Interesting gotcha, we can extend We can do this: const borderInlineWidth = style({
prop: ['biw', 'borderInlineWidth'],
css: 'borderInlineWidth',
themeGet: getSpace,
})
const myStyled = styled.extend(borderInlineWidth)
const Dummy = myStyled``
<Dummy biw={1} /> // border-inline-width: 4px; ✅ but we can't do this: const Dummy = myStyled`
border-inline-width: 1;
`
<Dummy /> // border-inline-width: 1; ❌ The reason is that I added a skipped test for this, for now. To fix it properly, we would need |
This is otherwise coming together nicely. I just need to review a couple types that got lost along the way. |
I misunderstood how xstyled's css function interacts with emotion's css function, so I added this complicated code in c400c70. More recently, while working on styled-components#250, I discovered that it's also broken, because it converts a function argument into an array. This simpler code does the one thing it needs to do: add string separators for the tagged template literal for the number of generators. It also produces a slightly more efficient result, because it tests `generators.length` before making the created function, rather than testing it every time the function runs.
I misunderstood how xstyled's css function interacts with emotion's css function, so I added this complicated code in c400c70. More recently, while working on styled-components#250, I discovered that it's also broken, because it converts a function argument into an array. This simpler code does the one thing it needs to do: add string separators for the tagged template literal for the number of generators. It also produces a slightly more efficient result, because it tests `generators.length` before making the created function, rather than testing it every time the function runs.
I misunderstood how xstyled's css function interacts with emotion's css function, so I added this complicated code in c400c70. More recently, while working on styled-components#250, I discovered that it's also broken, because it converts a function argument into an array. This simpler code does the one thing it needs to do: add string separators for the tagged template literal for the number of generators. It also produces a slightly more efficient result, because it tests `generators.length` before making the created function, rather than testing it every time the function runs.
I misunderstood how xstyled's css function interacts with emotion's css function, so I added this complicated code in c400c70. More recently, while working on styled-components#250, I discovered that it's also broken, because it converts a function argument into an array. This simpler code does the one thing it needs to do: add string separators for the tagged template literal for the number of generators. It also produces a slightly more efficient result, because it tests `generators.length` before making the created function, rather than testing it every time the function runs.
I misunderstood how xstyled's css function interacts with emotion's css function, so I added this complicated code in c400c70. More recently, while working on styled-components#250, I discovered that it's also broken, because it converts a function argument into an array. This simpler code does the one thing it needs to do: add string separators for the tagged template literal for the number of generators. It also produces a slightly more efficient result, because it does more work up front (testing `generators.length` and concatting arrays) before the resulting function, rather than every time the function runs.
65fe5f6
to
196dbb0
Compare
I misunderstood how xstyled's css function interacts with emotion's css function, so I added this complicated code in c400c70. More recently, while working on #250, I discovered that it's also broken, because it converts a function argument into an array. This simpler code does the one thing it needs to do: add string separators for the tagged template literal for the number of generators. It also produces a slightly more efficient result, because it does more work up front (testing `generators.length` and concatting arrays) before the resulting function, rather than every time the function runs.
This is a relatively pure refactor without new functionality, in preparation for adding `styled.extend()` First, add `createStyled` to emit `styled` given a generator function. Second, replace `styledWithGenerator` by `styled.*.withGenerator` (styled-components) and `styled(*, { generator })` (emotion). This avoids the creator needing to emit more than one function with different capabitilies.
This works similarly to `x.extend()`. The styled component will respond to the props supported by the supplied generator(s). However it doesn't do extra replacments on the CSS template string, because that would additionally require `createPropGetters` and `createTransform`.
196dbb0
to
8c90dba
Compare
Tests run clean, but build fails with various TS errors.
It's not clear to me how I'm using named and default exports together in any way that's different from before. and the second error seems to be referencing Voldemort. |
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.
It is a good start but I think we should not release it until we have the good API for that. It will be probably for a v3.1.
@gregberge Agreed. The more I work on this, the more it needs to be holistic instead of piecemeal. Also I need to learn TS better, but it's taking longer than I'd anticipated. |
Closed in favor of #262 |
I misunderstood how xstyled's css function interacts with emotion's css function, so I added this complicated code in c400c70. More recently, while working on #250, I discovered that it's also broken, because it converts a function argument into an array. This simpler code does the one thing it needs to do: add string separators for the tagged template literal for the number of generators. It also produces a slightly more efficient result, because it does more work up front (testing `generators.length` and concatting arrays) before the resulting function, rather than every time the function runs.
Summary
For proper pluggability, we need
styled.extend
to complement the existingx.extend
. See #246This is not the API I would like eventually for a unified xstyled creator, but it's still worthwhile and a step in the right direction.
API details
Add
createStyled
(likecreateX
) so thatstyled.extend
can call it.The recently-added
styledWithGenerator
becomesstyled.withGenerator
for styled-components, andstyled(..., {generator})
for emotion, in each case adhering to their existing API without changing function arities.Status
This is a work in progress...
styled.extend