How to use css-mediaquery - 10 common examples

To help you get started, we’ve selected a few css-mediaquery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DomainGroupOSS / react-media-query-hoc / src / media-query-provider.js View on Github external
const media = Object.keys(this.props.queries).reduce((acc, queryName) => {
      const query = this.props.queries[queryName];

      if (this.props.values) {
        acc[queryName] = cssMediaQuery.match(query, this.props.values);
      } else {
        // if the consumer has not set `values` and is server rendering, default to false
        // because we don't know the screen size
        acc[queryName] = hasMatchMedia
          ? window.matchMedia(query).matches
          : false;
      }

      return acc;
    }, {});
github mui-org / material-ui / docs / src / pages / components / use-media-query / ServerSide.js View on Github external
const ssrMatchMedia = query => ({
    matches: mediaQuery.match(query, {
      // The estimated CSS width of the browser.
      width: 800,
    }),
  });
github pocketjoso / penthouse / src / non-matching-media-query-remover.js View on Github external
function _isMatchingMediaQuery (mediaQuery, matchConfig) {
  // TODO: use the media query parsing from css-tree instead
  let mediaAST
  try {
    mediaAST = cssMediaQuery.parse(mediaQuery)
  } catch (e) {
    // cant parse, most likely browser cant either
    return false
  }

  var keep = mediaAST.some(function (mq) {
    // not sure why css-mediaquery library sometimes flags the inverse as type,
    // rather than the inverse field, but for our purposes we want to treat
    // them the same.
    const isInverse = mq.inverse || mq.type === 'not'
    if (
      (!isInverse && mq.type === 'print') ||
      (isInverse && mq.type === 'screen')
    ) {
      return false
    }
github pocketjoso / penthouse / lib / phantomjs / non-matching-media-query-remover.js View on Github external
function _isMatchingMediaQuery (rule, matchConfig) {
  if (rule.type !== 'media') {
    // ignore (keep) all non media query rules
    return true
  }

  var mediaAST
  try {
    mediaAST = cssMediaQuery.parse(rule.media)
  } catch (e) {
    // cant parse, most likely browser cant either
    return false
  }
  var keep = mediaAST.some(function (mq) {
    if (mq.type === 'print') {
      return false
    }
    // f.e. @media all {}
    // go for false positives over false negatives,
    // i.e. accept @media randomThing {}
    if (mq.expressions.length === 0) {
      return true
    }
    return mq.expressions.some(function (expression) {
      if (expression.modifier === 'min') {
github trurl-master / jsdom-testing-mocks / src / mocks / viewport.js View on Github external
get matches() {
      return mediaQuery.match(query, state.currentDesc)
    },
    media: query,
github telus / tds-core / config / jest / __mocks__ / matchMedia.js View on Github external
const doesQueryMatch = (query, viewportSize) => {
  if (!viewportSize) {
    return true
  }

  return mediaQuery.match(query, {
    type: 'screen',
    width: `${viewportSize}px`,
  })
}
github OrigenStudio / material-ui-layout / example / config / material-ui / theme.js View on Github external
? (query: string) => ({
              matches: mediaQuery.match(query, {
                width: theme.breakpoints.values[INITIAL_BREAKPOINT],
              }),
            })
          : undefined,
github vitalets / react-native-extended-stylesheet / src / replacers / media-queries.js View on Github external
mqKeys.forEach(key => {
      const mqStr = key.replace(PREFIX, '');
      const isMatch = mediaQuery.match(mqStr, matchObject);
      if (isMatch) {
        merge(res, obj[key]);
      }
    });
  }
github jtangelder / grunt-stripmq / tasks / lib / stripmq.js View on Github external
ast.stylesheet.rules = ast.stylesheet.rules.reduce(function (rules, rule) {
        if (rule.type === 'media') {
            if (mediaQuery.match(rule.media, options)) {
                rules.push.apply(rules, rule.rules);
            }
        }
        else {
            rules.push(rule);
        }
        return rules;
    }, []);
    return ast;
github tuckerconnelly / react-native-match-media / index.js View on Github external
get matches() {
    return mediaQuery.match(this._query, {
      type: 'screen',
      ...Dimensions.get('window'),
    })
  }

css-mediaquery

Parses and determines if a given CSS Media Query matches a set of values.

BSD
Latest version published 10 years ago

Package Health Score

65 / 100
Full package analysis

Similar packages