-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[✨] a way to declare component$
which shares parent component styling scope
#2726
Comments
@mhevery Can you check this? I made an initial PoC. export default component$(() =>{
useStylesScoped$(`.red {color: red}`);
return <div>
<Child>text</Child>
</div>;
});
export const Child = component$((props) => {
useStylesScoped$(`.center {...}`);
return <span {...props} class="center red">Hello: <Slot/></span>
}, {
styleScope: 'inherit'
}) will render a child with red text. Currently, the option is passed with jsx(
Virtual,
{
['q:cmpOption']: options,
[OnRenderProp]: componentQrl,
[QSlot]: props[QSlot],
[_IMMUTABLE]: (props as any)[_IMMUTABLE],
children: props.children,
props,
},
finalKey
) as any; and passed to Context at |
I think @manucorporat is more familiar with that code. |
I think adding options to the component itself is the wrong approach, this is an issue only with
However... this is a problem created because
I think it's a safe model to keep styles scoped to the component itself, if there is a need to pass it to a children right now it's possible to do it by doing: export default component$(() =>{
const {scopeId} = useStylesScoped$(`.red {color: red}`);
return <div>
<Child class={[scopeId, 'red'}}>text</Child>
</div>;
}); We could make it even easier by doing: export default component$(() =>{
const {className} = useStylesScoped$(`.red {color: red}`);
return <div>
<Child class={scopedClass('red')}>text</Child>
</div>;
}); |
Closing this as |
Is your feature request related to a problem?
The above does not work because the
red
is scoped to the component. This makes stylingLink
component rather difficult.The styling would work fine if the
Link
component was light-component, but becauseLink
needs to useuseMethods()
it needs to be wrapped incomponent$()
Describe the solution you'd like
Have the ability to declare
component$()
in a way that inherits the scoped styling of the parent. This is useful:<Link/>
The resulting DOM would be:
Describe alternatives you've considered
Using lite-component, but that is not possible in all of the cases (such as when the component needs use-method access)
Additional context
Related issues which should be solved with this:
The text was updated successfully, but these errors were encountered: