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

Convert Svelte components styles into Stylify optimized CSS #273

Open
katriellucas opened this issue Feb 26, 2024 · 2 comments
Open

Convert Svelte components styles into Stylify optimized CSS #273

katriellucas opened this issue Feb 26, 2024 · 2 comments
Assignees
Labels
🚀feature New feature or request @stylify/stylify Targeting @stylify/stylify package

Comments

@katriellucas
Copy link

katriellucas commented Feb 26, 2024

Describe the problem

Stylify is already very close to vanilla CSS, woudn't be interesting to be able convert the native style tags that already exists on Svelte files to Stylify optimized classes? The proposal is basically converting the CSS inside the components.

Describe the proposed solution

What I thought:

// PrimaryButton.svelte
<button class="primary-button">Button</button>

<style> // Might also be interesting to add lang="stylify" attribute to hint the compilation
  primary-button {
    padding: 10px 15px;
    font-size: 16px;
    cursor: pointer;
  }
</style>

compiled into:

// html
<button class="a b c">Button</button>

// stylify.css
a: {
  padding: 10px 15px;
}

b: {
  font-size: 16px;
}

c: {
  cursor: pointer;
}

Alternatives considered

Do nothing, with the current component syntax, it's possible to achieve something similar:

<!--
  stylify-components
    'primary-button': `padding:10px_15px font-size:16px cursor:pointer`
  /stylify-components
-->

But we lose perks like syntax highlight, utility class generation and other, so it's not exactly the same, you end up with some repeated classes due to how stylify componentization works.

Importance

would make my life easier

@Machy8 Machy8 added 🚀feature New feature or request @stylify/stylify Targeting @stylify/stylify package labels Feb 26, 2024
@Machy8 Machy8 self-assigned this Feb 26, 2024
@Machy8
Copy link
Member

Machy8 commented Feb 26, 2024

Thanks for the submit @katriellucas!

@Machy8
Copy link
Member

Machy8 commented Feb 26, 2024

Additional ideas:

  • The following approach would work anywere: it would match native stylify definition block and process content between it.
  • It would process the block and then remove it from the file so no additional css will be generated
<style>
// stylify-components:css
  primary-button {
    padding: 10px 15px;
    font-size: 16px;
    cursor: pointer;
  }
// /stylify-components
</style>

another way

<style stylify-components>
  primary-button {
    padding: 10px 15px;
    font-size: 16px;
    cursor: pointer;
  }
</style>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀feature New feature or request @stylify/stylify Targeting @stylify/stylify package
Projects
None yet
Development

No branches or pull requests

2 participants