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

Responsive Global Styles #20244

Open
johnstonphilip opened this issue Feb 14, 2020 · 4 comments
Open

Responsive Global Styles #20244

johnstonphilip opened this issue Feb 14, 2020 · 4 comments

Comments

@johnstonphilip
Copy link
Contributor

@johnstonphilip johnstonphilip commented Feb 14, 2020

Problem to solve
A single global style will not work at all screen widths. For example, a really large font size might look great on desktop, but not look as great on mobile.

Example:
Screen Shot 2020-02-14 at 12 28 37 PM
Screen Shot 2020-02-14 at 12 27 38 PM

Describe the solution you'd like
I would like to see separate global-style controls for specific screen widths, similar to the concept of CSS Media Queries.

The technical side of this will likely need to fit with the Global Styles proposal:
#19611

I believe this should be something considered with "The Parts" as defined in #19611:

  • Responsive Default theme styles
  • Responsive Theme styles (e.g. Twenty Twenty)
  • Responsive User styles
  • Merged styles
  • CSS Variable rendering

One approach to deal with this might be to make the value of the style an object, with each key being the max-screen-width where that value would be used. Something like this:

{
	"global": {
		"color": {
			"text": {
				"600px": "red",
				"1000px": "blue",
				"1500px": "green"
		}
	}
}

This would then have to be exposed somewhere in the UI when allowing user overrides. This probably fits best with the site block:
#16998

As far as how to display that in a UI, one possible idea is to allow the user to resize the viewport, similarly to how the Chrome Inspector does, with the controls auto-updating to affect only that screen-width and smaller. This allows people to see how it looks at a set width, fix it, and move on, without needing to see an "option" for the screen width, and instead making a simple "decision" instead (Decisions, not Options).
Screen Shot 2020-02-14 at 12 25 04 PM

This is only one possible set of ideas to deal with this, and I am sure there are many "gotchas" I have not thought about, as this is not an easy problem to solve from a UI/UX perspective. Feedback welcome for sure! @ItsJonQ

@ItsJonQ
Copy link
Contributor

@ItsJonQ ItsJonQ commented Feb 14, 2020

@johnstonphilip Thanks for getting this issue started! You've provided a wonderful breakdown, which will be helpful as we consider the more difficult challenges of Global Styling 😅

One approach to deal with this might be to make the value of the style an object, with each key being the max-screen-width where that value would be used. Something like this:

That's a great approach. I've seen this strategy applied in various Sass implementation. A similar strategy would be to use Array values, like what's happening with Theme spec.

The tricky part is that without context of why, the values feel very cryptic. The Array values of Theme Spec feel super cryptic. Your Object example less so, as the px values provide some ideas.

This leads me nicely into another aspect of designing the Global Styling system.

The system's foundations have to work/render as expected. On top of that, the code used to customize/define these styles must feel intuitive + easy to write as well

🤗

@epiqueras
Copy link
Contributor

@epiqueras epiqueras commented Feb 15, 2020

The reason theme specs don't use this object form is that breakpoints are the same for every property. Having the numbers as keys to every responsive value for every responsive property would be pretty unnecessary data duplication and make it harder to change the breakpoints without changing the values.

@johnstonphilip
Copy link
Contributor Author

@johnstonphilip johnstonphilip commented Feb 17, 2020

@epiqueras Thanks for shedding some light on that. It looks like breakpoints are added in a breakpoints array in the Theme spec here.

To clarify my understanding from "Skipping breakpoints", adding a new breakpoint after-the-fact would require adding a new value to each propertty's breakpoints array, and essentially defaulting those to null. Is that correct?

For example, if my breakpoints array was this

{
  breakpoints: [
    '40em', '56em', '64em',
  ],
}

And my property's breakpoint settings were this:

width: [10%, 15%, '25%'],

But then I update my breakpoints array to have a new breakpoint after-the-fact like this:

{
  breakpoints: [
    '10em', '40em', '56em', '64em',
  ],
}

My property's breakpoint settings would need to be updated as well like this:

width: [null, 10%, 15%, '25%'],

Is that accurate?

@epiqueras
Copy link
Contributor

@epiqueras epiqueras commented Feb 17, 2020

Yes, but we could smoothly interpolate the missing value until the user fills it.

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

Successfully merging a pull request may close this issue.

None yet
3 participants