sveltejs / svelte-preprocess

A ✨ magical ✨ Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, Coffeescript, TypeScript, Pug and much more.
MIT License
1.73k stars 147 forks source link

Nested SCSS selectors global by default #592

Open SamMousa opened 1 year ago

SamMousa commented 1 year ago

Is your feature request related to a problem? Please describe. I'm always frustrated when I use nested SCSS and have to apply :global() at all nested levels.

Describe the solution you'd like CSS scoping already happens at the top level of my selector, so there's no need to also scope any child selectors since they are already scoped to the component by their parent selector.

Describe alternatives you've considered Currently I wrap everything in :global():

.imagemap {
        min-height: 200px;
        background-color: red;
        width: 100%;
        position: relative;
        canvas {
            width: 100% !important;
            height: 100% !important;
            min-width: 100%;
            max-width: 100%;
            min-height: 100%;
            max-height: 100%;
        }

        :global(.canvas-wrapper) {
            z-index: 10;
            display: none;
        }

        :global(.canvas-wrapper.loaded) {
            display: block;
        }

        &[data-hover] {
            cursor: pointer;
        }
    }

How important is this feature to you? There is a workable workaround; it just doesn't feel clean. I'm writing code that works but its meaning is different from what is conveyed. I'm not creating global styles; I'm creating component scoped styles that happen to have multiple selectors.

Additional context