Skip to content
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

[Syntax] set-layer:name and get-layer:name attributes for the <style> tag and CSS @layer - pass style to subcomponent #7465

Open
lukaszpolowczyk opened this issue Apr 16, 2022 · 1 comment
Labels
css Stuff related to Svelte's built-in CSS handling

Comments

@lukaszpolowczyk
Copy link

lukaszpolowczyk commented Apr 16, 2022

Describe the problem

Passing CSS styles between components.
Sometimes I have a style in a parent component and can't conveniently pass it to the subordinate components.

Describe the proposed solution

The set-layer and get-layer attributes for the <style> tag + use of the CSS standard @layer.
The set-layer and get-layer attributes are analogous to Svelte set/getContext.

Example:

<!-- Com.svelte -->
<script>
import SubCom from "./SubCom.svelte";
</script>
<style set-layer:name>
	@layer name {
		.class1 {}
	}
</style>
<div class="class1"></div>
<SubCom/>
<!-- SubCom.svelte -->
<div class="class1 class2"></div>
<style get-layer:name>
	@layer self, name;
	
	@layer self {
		.class2 {}
	}
</style>

Features

  • The use of @layer, besides (following the standard) setting the order of styles, has the function of naming the style fragment, so that it can be passed to the subcomponent more easily.
  • Both set-layer and get-layer can be used multiple times when you want to split and pass more style fragments.
  • The style passed by set/get-layer must be available only for those components where these attributes are used. This is not supposed to work like :global or have any leakage.
  • Layer names shouldn't leak either, they should only be visible to the components where they are used, and not available in an external CSS file for example.

(name set-layer and get-layer - temporary, something to think of)

EDIT: after experimenting I think using @layer is a bad idea, or at least problematic. You need to use your own at-rule e.g. @module @fragment @expose - unfortunately this is a non-standard syntax and I'm not happy about it.

Alternatives considered

This is a new version of that idea - #6422

And the rest that everyone knows about like :global, various CSS preprocessors.

I think ideas like "passing classes" is much worse than my proposal.
Passing CSS variables is not that at all.

Importance

would make my life easier

@lukaszpolowczyk lukaszpolowczyk changed the title [Syntax] set-layer:layer and get-layer:layer attributes for the <style> tag - pass style to subcomponent [Syntax] set-layer:layer and get-layer:layer attributes for the <style> tag and @layer - pass style to subcomponent Apr 16, 2022
@lukaszpolowczyk lukaszpolowczyk changed the title [Syntax] set-layer:layer and get-layer:layer attributes for the <style> tag and @layer - pass style to subcomponent [Syntax] set-layer:layer and get-layer:layer attributes for the <style> tag and CSS @layer - pass style to subcomponent Apr 16, 2022
@lukaszpolowczyk lukaszpolowczyk changed the title [Syntax] set-layer:layer and get-layer:layer attributes for the <style> tag and CSS @layer - pass style to subcomponent [Syntax] set-layer:name and get-layer:name attributes for the <style> tag and CSS @layer - pass style to subcomponent Apr 16, 2022
@lukaszpolowczyk
Copy link
Author

lukaszpolowczyk commented May 1, 2022

@smithliam I want the style not to be visible outside the source component and the target component. It should not leak either up or down - in harmony with the Svelte idea.

EDIT: Oh, I see you may have deleted the comment.

@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

2 participants