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

Adopt a new (more css-friendly) syntax #64

Open
ZeeCoder opened this issue Dec 28, 2017 · 2 comments
Open

Adopt a new (more css-friendly) syntax #64

ZeeCoder opened this issue Dec 28, 2017 · 2 comments

Comments

@ZeeCoder
Copy link
Owner

Based on the discussion here: https://twitter.com/innovati/status/946155332719599622

The new proposed syntax (that'll be mostly adopted by eqcss too if everything goes well):

.Container {
  ...
}

@container .Container (width >= 320px) {
  .Element {
    ...
  }
}

(Whether the query's name will be @container or @element is not decided yet, so I'll support both for the time being.)

Where @container applies styles to elements inside the element, given by the selector.

The following should be possible too, although not BEM-like, and not encouraged by this particular project:

@container .some-selector .Container (width >= 320px) {
  .some-selector .Element {
    ...
  }
}

This makes the job of preprocessors slightly harder though, since it's a bit hard to decide where the boundary is between container-selector and element-selector.

Consider the following:

.wrapper {
    .Container {
        ...

        .another-selector {
            .Element {
                @container (width >= 320px) {
                    ...
                }
            }
        }
    }
}

With @media queries, a prerpocessor would lift the media query on the top level, wrapping everything else inside, which is however not the desired result for us:

// This is wrong!
@container (width >= 320px) {
    .wrapper .Container .another-selector .Element {
        ...
    }
}

Even if preprocessors do handle @container queries differently, they have no way of telling at which point the container selector begin and end.

Maybe the following is the closest to a solution:

.wrapper {
    .Container {
        ...

        @container (width >= 320px) {
            .another-selector {
                .Element {
                    
                }
            }
        }
    }
}

Here preprocessors can assume that everything outside a @container query is the container selector, and needs to be put in between the query keyword and the conditions, and anything inside would be element / child selectors.
Resulting in:

// This is correct!
@container .wrapper .Container (width >= 320px) {
  .another-selector .Element {
    ...
  }
}
@ZeeCoder
Copy link
Owner Author

ZeeCoder commented Jan 1, 2018

with a postcss plugin, the current syntax could be used as-is too, if the selector part after @container is auto-injected before processing.

@ZeeCoder
Copy link
Owner Author

ZeeCoder commented Jan 3, 2018

Once this is done, the documentation needs to change to present the simpler syntax, and not the nested one.
The latter would also need more thorough documentation, since I think it's not highlighted that postcss-nested would need to be set up with the bubble option.
Otherwise it wouldn't process @container queries, and silently fail instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant