QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.71k stars 1.29k forks source link

feat(qwik-core): `useStylesWithScope` that introduces `:scope` pseudo class to scope styles to the component manually. #6613

Closed genki closed 3 months ago

genki commented 3 months ago

Overview

What is it?

Description

The useStyles$ can style entire page but it couldn't scope to components. The useStylesScoped$ can style scoped to the component but it couldn't style its child components. So I added one more thing, the useStyleWithScope$ that introduces the :scope pseudo class to scope styles manually.

By using this function, you can use :scope pseudo class to be replaced with .${scopeId}.

:scope {
  background: red
}

The above css is to be like this:

.⭐️5yhoz-0 {
  background: red
}

Use cases and why

While the useStylesScoped$ put the scopeId to every rules in the CSS, this function can select rules to put it. So you can scope styles to the component and its children such as <Link> too.

Checklist:

netlify[bot] commented 3 months ago

Deploy request for qwik-insights pending review.

Visit the deploys page to approve it

Name Link
Latest commit 25b2ad560eb9d5c9d81b6716f2a9462aa23ad576
genki commented 3 months ago

Ah something went wrong in my git work. I will retry.