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

Element queries! #7

Open
MichaelArestad opened this issue Aug 3, 2020 · 7 comments
Open

Element queries! #7

MichaelArestad opened this issue Aug 3, 2020 · 7 comments
Assignees

Comments

@MichaelArestad
Copy link
Collaborator

I would love to see some element queries to make the interface components even more flexible. For example, if the parent container is less than 200px wide, then make the grid one column instead of two.

@ItsJonQ
Copy link
Owner

ItsJonQ commented Aug 3, 2020

Rad!! I'll see what it takes to seamlessly integrate this:
http://marcj.github.io/css-element-queries/

@ItsJonQ ItsJonQ added the styles label Aug 3, 2020
@ItsJonQ ItsJonQ self-assigned this Aug 4, 2020
@ItsJonQ
Copy link
Owner

ItsJonQ commented Aug 4, 2020

Looks like there's also this:

https://github.com/marcj/css-element-queries

@ItsJonQ
Copy link
Owner

ItsJonQ commented Aug 4, 2020

@MichaelArestad It looks like these libraries work quite differently (the 2 links I shared above).

Is there a particular solution you had in mind?

Also! Do you know how it's currently being used in Gutenberg? (I think it's there... At least, I remember reading about it)

@griffbrad
Copy link

I believe @jasmussen did some work with element queries in Gutenberg late last year:
WordPress/gutenberg#18745

@jasmussen
Copy link
Collaborator

The Placeholder component in the block editor uses a JS resize observer to provide element queries. It's working well, and provides the feature in a compatible way today, which might work well here.

The polyfill I tried did not play well with react, as it relied on setting classnames that were quickly sanitized away by the system.

@ItsJonQ
Copy link
Owner

ItsJonQ commented Aug 4, 2020

Oooo... I see. It was a ad-hoc implementation, rather than something with CSS compiling.

It would be nice to have a... it just works. Kind of workflow :)

https://github.com/marcj/css-element-queries

Seems to be the most promising solution.

Ultimately, it works with (and uses) valid CSS:

.widget-name[min-width~="400px"] h2 {
    font-size: 18px;
}

It's just the DOM target binding bit that's the tricky part. 🤔

@ItsJonQ
Copy link
Owner

ItsJonQ commented Aug 4, 2020

Note to self: (Apologies in advance, the following may not make sense...)

  • Create some sort of useEQ() hook + matching context pair
  • Ref the HTMLElement for responsiveness to that context
  • Consumer of the hook can write CSS-in-JS, which gets parsed + init() (via EQ library) with useEQ() hook

@ItsJonQ ItsJonQ added the systems label Aug 5, 2020
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

4 participants