-
Notifications
You must be signed in to change notification settings - Fork 616
Adapts Blankslate to render proportionally in narrow areas #3869
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
Conversation
🦋 Changeset detectedLatest commit: d2367ab The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Uh oh! @mperrotti, the image you shared is missing helpful alt text. Check your pull request body. Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image. Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs. |
src/Blankslate/Blankslate.tsx
Outdated
--borderColor-default-local-fallback: ${get('colors.border.default')}; | ||
--fgColor-muted-local-fallback: ${get('colors.fg.muted')}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have the new Primitives colors yet, so we need to provide fallbacks using JS.
size-limit report 📦
|
@@ -0,0 +1,7 @@ | |||
--- | |||
'@primer/react': patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good news: This is the first component in primer/react (outside of drafts) that uses css modules. ✨
To get the css into dotcom, we need to import a single css file for primer/react (similar to primer/css)
Bad news:
This is a breaking change because now we require you to include a css file for an existing component that we didn't earlier? Without that stylesheet, existing BlankSlate instances would become unstyled.
(New components get a free pass because it's a new component with a new import statement, but tricker to change existing components like this)
Probably still fine to squeeze into dotcom, but not for open source?
The ideal order for us would be to add the one primer/react css file requirement in v36. Once that's done, we can keep adding more css bundled to that file, no worries
@joshblack @langermank Is there a workaround for this that comes to mind? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think there's any way we can use BaseStyles to import CSS modules?
If this has to be a breaking change, should we hold off on this until the next major release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think there's any way we can use BaseStyles to import CSS modules?
We can't use BaseStyles to import CSS modules, buuuut we could use it as a temporary place to add global css for components! 😈
If this has to be a breaking change, should we hold off on this until the next major release?
For the css files, yes. But we could break this into 2 parts:
- one that adds styles for narrow areas but still uses styled-components (not breaking change)
- another that moves the styled-components to a css file that needs import (breaking change)
To release the 2nd PR (breaking), our options are:
- Add it to v36 (not recommended this late in the release)
- Don't migrate styles to css files for Blankslate right now, continue using the sx prop until the next major release (usually, we would do this)
- Do a quick v37 release right after v36 with this change and related primitive changes (i don't mind this at all)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one that adds styles for narrow areas but still uses styled-components (not breaking change)
This isn't going to be possible since styled-components
doesn't recognize @container
, and it will get stripped out.
I think doing a quick v37 release right after v36 is the best path forward. I don't think there's any way to handle these updates without introducing a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't going to be possible since styled-components doesn't recognize
@container
, and it will get stripped out.
As far as I know, styled-components doesn't validate syntax though and strip it out. Here's an example of container queries with styled-components: https://codesandbox.io/s/zen-hill-v939m3?file=/src/App.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@siddharthkp - so your official suggestion is to add <style type="text/css">{ContainerQuery}</style>
inline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To unblock this PR: It sounds icky but Yes 😅 (hoping that dotcom doesn't have any problems with that)
Follow up would be to start collecting candidates for v37 where we can make a css file import required.
Of course, we also have the option of pausing this PR and releasing with it the next major release. But, I'm honestly don't know what the timeline for that would look like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I missed this in the thread earlier, but would another option here be to use createGlobalStyle
? e.g.
import { createGlobalStyle } from 'styled-components';
const ContainerQueryStyles = createGlobalStyle`
.BlankspaceContainer {
container: blankslate / inline-size;
}
@container blankslate (min-width: 34rem) {
/* ... */
}
`;
function Blankslate({border, children, narrow, spacious}: BlankslateProps) {
return (
<>
<ContainerQueryStyles />
<StyledBlankslate data-border={border} data-narrow={narrow} data-spacious={spacious}>
{children}
</StyledBlankslate>
</>
);
}
Was curious if this ended up working as expected. I think this has an advantage of having a shared stylesheet instead of having a <style>
tag per instance of Blankslate (if it works, that is 😅)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joshblack - I think using createGlobalStyle
would still results in @container (max-width:600px)
getting written without an open curly brace. Check out @siddharthkp 's comment above for more context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, makes sense! Thanks @mperrotti for clarifying
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a tiny bug, otherwise looks good!
Should test this visually in dotcom once before merging just to make sure the container query works as expected
Co-authored-by: Siddharth Kshetrapal <siddharthkp@github.com>
@siddharthkp - I used this integration test PR and confirmed everything works as expected. I checked using the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- No breaking changes
- Mike has tested our hack works with dotcom
ship it!
* adapts Blankslate to render proportionally in narrow areas * adds color token fallbacks * adds changeset * formats CSS with Prettier * rm dead css module style * uses smarter primitives * tweaks type scale * improves token usage * upgrades styled-components, converts Blankslate styles back to styled-components * adds comment explaining why 34rem for min-width * renders an inline style block to get around styled-component 5.x limitations around container blocks * Update src/Blankslate/Blankslate.tsx Co-authored-by: Siddharth Kshetrapal <siddharthkp@github.com> --------- Co-authored-by: Siddharth Kshetrapal <siddharthkp@github.com>
Relates to https://github.com/github/primer/issues/2678
Before:

After:

Changelog
New
Nothing new
Changed
styled-components
so we can use the@container
rule blockRemoved
Nothing removed
Rollout strategy
Testing & Reviewing
Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.