npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-container-query-2

v0.2.6

Published

Vue plugin for working with css container query

Downloads

12

Readme

Vue Container Query 2

🧐 Because vue-container-query was taken, and API is a little like vue-container-query package. So, thank you the maintainer.

Vue plugin for working with css container query as easy as possible.

💥 This is the beta version. It's safe for production, but keep an eye on documentations if you wanted to upgrade the package. There probably will be breaking changes in first major release


Installation

npm install vue-container-query-2
// or
yarn add vue-container-query-2

This is also available on jsdeliver and unpkg.


Usage

Import and register the vue-container-query-2 plugin first.

import VueContainerQuery from 'vue-container-query-2';
Vue.use(VueContainerQuery, options);

And :tada: voila, now you have a cq option in every SFCs like below

export default {
  name: 'SearchField',
  cq: {
    large: { minWidth: 900 },
    medium: { maxWidth: 600 },
    small: { maxWidth: 460 }
  },
  data() {
      return {}
  },
  ...

:warning: for maxWidth you get <=, but for minWidth it's > and no =. So the behavior is not quite like CSS Media Queries. Although it's a little bit more well formatted. But it may change during next major release. so, heads up.


After defining breakpoints, you'll have reactive $cq variable in your component. You can use this anyhow you need. Maybe dynamic classes, maybe show/hide other element or components, whatever.

<div
    :class="{
        'search--small': $eq.small
    }
>
    <span v-if="$eq.large">
        Yo. I only get rendered if the componenet is 900px or wider
    </span>
</div>

This is a sample of how $eq object looks like in the instance's context:

{
    contentRect: {
        x:0,
        y: 0,
        width:1300, 
        height: 2124, 
        top: 0,
        right: 1300,
        bottom: 2124,
        left:0
    },
    breakpoints: {
        large: { minWidth: 900 }
        medium: { maxWidth: 600 },
        small: { maxWidth: 460 }
    },
    resizeObserver: [object ResizeObserver],
    large: true
    medium: true,
    small: false
}

Options

This is default options:

{
    classNames: {
        sizes: {
            xsmall: 'xsmall',
            small: 'small',
            medium: 'medium',
            large: 'large',
            xlarge: 'xlarge'
        },
        prepend: ''
    },
    useBEM: true,
    utilityClassNamesRegex: /$^/,
    ignoredClasses: ['']
}

You can override these when registering the plugin:

Vue.use(VueContainerQuery, {
  classNames: {
    sizes: {
      xsmall: 'size:xsmall',
      small: 'size:small',
      medium: 'size:medium',
      large: 'size:large',
      xlarge: 'size:xlarge'
    }
  },
  useBEM: true,
  utilityClassNamesRegex: /u-/g,
});

All options are only useful when you are using v-cq directive. the core works fine without any provided option

useBEM

If this set as true, the classes will respect the BEM convention. Say your element has search class, then when small condition is on, a search--small class adds to element. VCQ is smart enough to ignore -- classes when generating new class names. But if your element has multiple classes like search header, you will get both search--small and header--small. so if you are using useBEM make sure you implement the true BEM. otherwise this plugin won't work that nice.

utilityClassNamesRegex

You can set a regex to ignore any sort of utility class that you don't want to consider as semantic class.

ignoredClasses

You can set an array to ignore any sort of class that you don't want to consider as semantic class.


Directive

This may be the best feature of thin package. There also is a handy v-cq directive available to automate the process of setting size classes. so, all you need to make the element to get size classes is like below:

<div
    v-cq
    class="card"
>
    ...
></div>

<!-- <div class="card card--small"><div> -->
<!-- <div class="card card--medium"><div> -->
<!-- <div class="card card--large"><div> -->

See there? no :class and checking for $cq.small or anything. size classes will automatically get calculated and attached to element. remember that size classes are based on what you did set in options, if not, default ones as fallback.


👨‍💻 ToDo

  • [ ] Add unit tests.
  • [x] Detect utility classes to prevent adding "size classes" to them.
  • [x] Add option to explicitly mention main class name. It's very useful if you're using utility first CSS classes.