csstype icon indicating copy to clipboard operation
csstype copied to clipboard

Add @media features

Open jacobrask opened this issue 6 years ago • 5 comments

Would be very useful for libraries that accept media query features.

https://developer.mozilla.org/en-US/docs/Web/CSS/@media#Media_features

jacobrask avatar Feb 07 '19 12:02 jacobrask

I concider these features to be handled by vendors the way they like it. The problem is that there's endless different combinations of @media and there's no way to type properties after a specific pattern that I know of. Same thing as for CSS Custom Properties and @supports. But if you anyone have any suggestions I would appreciate if you shared them.

frenic avatar Feb 07 '19 13:02 frenic

The way I figured I could type my own media query utility function is like this:

interface MaxWidthQuery {
  maxWidth: number | string;
}
interface MinWidthQuery {
  minWidth: number | string;
}
interface OrientationQuery {
  orientation: 'portrait' | 'landscape';
}
interface ScreenQuery {
  screen: boolean;
}
interface HoverQuery {
  hover: 'none' | 'hover';
}

type MediaQuery =
  | MaxWidthQuery
  | MinWidthQuery
  | HoverQuery
  | OrientationQuery
  | ScreenQuery;

function json2mq(query: MediaQuery) { ... }

json2mq({ orientation: 'landscape', screen: true })

Etc, but it's not really worth maintaining that list if it's only for a single project.

jacobrask avatar Feb 07 '19 16:02 jacobrask

The whole purpose of CSSType is to autogenerate types from other sources (with a small exception of SVG CSS properties 😉). The only source I could find of CSS media queries was this and the only thing it contains is client support of all features so it wouldn't be enough. If you can find another source containing enough data to autogenerate this it would be more interesting.

frenic avatar May 17 '19 08:05 frenic

Hi ✌️
I'm newbie here, sorry if I'm commenting in the wrong place!

I found a source that I believe is ideal for this case! Webref specifically @webref/css.

I found the content in this file.

codermarcos avatar Jan 03 '22 13:01 codermarcos

Interesting, that looks useful for sure. Thanks 👍

frenic avatar Jan 20 '22 10:01 frenic