Enable as specification at declaration for composed components
#507
Replies: 4 comments 1 reply
-
|
Alternative API: const Box = styled('div', {})
cont Text = styled(Box.as('p'), {})Benefit of this is when we make |
Beta Was this translation helpful? Give feedback.
-
|
I was able to come up with a pattern to solve this in the userland. Posting below for those who seek solution for the same const BoxAs = <T extends Parameters<typeof styled>[0]>(tag: T) => styled(tag, {});
const Box = BoxAs("div");
const TextAs = <T extends Parameters<typeof styled>[0]>(tag: T) => styled(BoxAs(tag), {});
const Text = TextAs("p");
const TextLink = styled(TextAs("a"), {});Full example: https://codesandbox.io/s/composition-with-default-as-mf3x9 |
Beta Was this translation helpful? Give feedback.
-
|
@dylanklohr @afzalsayed96 check out #609 for some ideas related to this. |
Beta Was this translation helpful? Give feedback.
-
|
This feature was previously proposed, but was rejected for several reasons. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
The existing polymorphic
asprop from@stitches/reactworks incredibly well for allowing control over the rendered element at time of consumption. One thing that has been a frequent pain point however is that there is no way to specify a value foraswhen composing components.Example
This leads to forcing instances of
<Text />to provide a value forasevery time it is consumed.Current Workaround
but this forces the onus of handling polymorphism for any other
propsthat may be provided to<Text />to consumers.Desired Solution
If one is able to provide a value for the
asprop when declaring a newstyledcomponent that composes another component, like the following, consumers would be able to have access to the full power and awesome DX that@stitches/reactoffers, with greater flexibility for component compositionAlternative APIs
Optional third Argument
Array as first Argument
Special
@asPropertyPotentially Related Issues/Discussions
asprop onstyled(Component)components #448Beta Was this translation helpful? Give feedback.
All reactions