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

Add container query support #807

Merged
merged 14 commits into from
Sep 5, 2022
Merged

Add container query support #807

merged 14 commits into from
Sep 5, 2022

Conversation

mattcompiles
Copy link
Contributor

This PR adds support for container queries via the new @container key. It also adds a new top-level API called createContainer to allow for local scoping of container names.

Example usage:

import {
  style,
  createContainer
} from '@vanilla-extract/css';

const sidebar = createContainer();

const myStyle = style({
  containerName: sidebar,
  '@container': {
    [`${sidebar} (min-width: 768px)`]: {
      padding: 10
    }
  }
});

@mattcompiles mattcompiles requested a review from a team September 5, 2022 12:15
@changeset-bot
Copy link

changeset-bot bot commented Sep 5, 2022

🦋 Changeset detected

Latest commit: 96305e6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@vanilla-extract/babel-plugin Minor
@vanilla-extract/css Minor
@fixtures/features Patch
@fixtures/low-level Patch
@fixtures/recipes Patch
@fixtures/sprinkles Patch
@fixtures/themed Patch
@fixtures/unused-modules Patch
vanilla-extract-example-webpack-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@markdalgleish
Copy link
Contributor

Should the blurb on the docs home page be updated? Here's a suggested change:

-Write maintainable CSS at scale without sacrificing platform features. Variables, selectors, pseudo‑classes, media/feature queries, keyframes, font‑face fules and global styles are all supported.
+Write maintainable CSS at scale without sacrificing platform features. Variables, selectors, pseudo‑classes, media/feature/container queries, keyframes, font‑face and global styles are all supported.

Note I changed font-face rules to font-face so it stays on 3 lines.

Copy link
Contributor

@markdalgleish markdalgleish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work 🎉

Comment on lines +374 to +376
const containerQuery = `@container ${query}`;

const conditions = [...parentConditions, containerQuery];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Noticed that containerQuery is not used, as a hangover from transformMedia. But given this is now a carbon copy of transformSupports should we look at sharing code here? Or are we deliberately preferring verbosity for readability?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I like these being separate even though they are basically the same. Not sure there's much to gain by merging them outside of less lines of code.

Comment on lines +13 to +40
```ts compiled
// sidebar.css.ts
import {
style,
createContainer
} from '@vanilla-extract/css';

export const sidebarContainer = createContainer();

export const sidebar = style({
containerName: sidebarContainer
});

// navigation.css.ts
import {
style,
createContainer
} from '@vanilla-extract/css';
import { sidebarContainer } from './sidebar.css.ts';

export const navigation = style({
'@container': {
[`${sidebarContainer} (min-width: 400px)`]: {
display: 'flex'
}
}
});
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😘👌

Copy link
Contributor

@michaeltaranto michaeltaranto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome stuff 🚀

@mattcompiles mattcompiles merged commit b0b3662 into master Sep 5, 2022
@mattcompiles mattcompiles deleted the container-queries branch September 5, 2022 23:38
@seek-oss-ci seek-oss-ci mentioned this pull request Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants