Skip to content

Styling subcomponents based on import #7582

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

Open
dxlbnl opened this issue Jun 3, 2022 · 2 comments
Open

Styling subcomponents based on import #7582

dxlbnl opened this issue Jun 3, 2022 · 2 comments
Labels
css Stuff related to Svelte's built-in CSS handling

Comments

@dxlbnl
Copy link
Contributor

dxlbnl commented Jun 3, 2022

Describe the problem

I'd like to be able to override some styles (margins, paddings, colors) for a component I import in a higher order component.

Describe the proposed solution

Styled components allow for higher level components to override styles (as long as they all are styled components).
I think we could add something similar to svelte, since we know what generated classname a component has on compiletime, so we'd be able to replace the selector with the proper classname.

<style>
import Link from './Link.svelte'
</style>

<Link ... />

<style>
  {Link}:hover {
    fill: rebeccapurple;
  </style>

Alternatives considered

Passing custom property solutions are available, but that would require the imported component to expose all the possible values.

Importance

would make my life easier

@baseballyama
Copy link
Member

This discussion has been conducted here in the past.
And we decided not to implement it.

sveltejs/rfcs#22

This is personal opinion but for such a use case, I prefer that implement a child component with a variant prop as a style pattern, and style of the child component changes according to the passed variant.
Them child components can keep responsibility to render with correct styling.

@zigphrid
Copy link

This discussion has been conducted here in the past. And we decided not to implement it.

sveltejs/rfcs#22

This is personal opinion but for such a use case, I prefer that implement a child component with a variant prop as a style pattern, and style of the child component changes according to the passed variant. Them child components can keep responsibility to render with correct styling.

Your case implementation is structurally incorrect.
The simplest example is the button component. Stylistic and functional variations (for example, the search button, the close button, the burger menu button, etc.) are wrong to describe in the original component of the button, it is more logical to describe them in separate wrapping components.

Best regards.

@Rich-Harris Rich-Harris added the css Stuff related to Svelte's built-in CSS handling label Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css Stuff related to Svelte's built-in CSS handling
Projects
None yet
Development

No branches or pull requests

4 participants