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-css-custom-property

v1.0.6

Published

CSS custom properties in Vue components and global usage

Downloads

8

Readme

Installation / 설치

npm install --save vue-css-custom-property
// plugins/vue-css-custom-property.js
import Vue from 'vue'
import customProperty from 'vue-css-custom-property'
Vue.use(customProperty)
// Vue.use(customProperty, readyKey) or Vue.use(customProperty, { readyKey: 'readyKeyTest' }) to use custom property ready event key. If empty, default is 'customPropertiesReady'

Nuxt.js

// nuxt.config.js
module.exports = {
  plugins: [
    { src: '~plugins/vue-css-custom-property.js', ssr: false }
  ]
}

Basic Usage / 기본 사용법

Defining customProperties options in your components. It only works in this component. And data is being observed.
컴포넌트의 customProperties 옵션을 지정하여 해당 컴포넌트에서 css custom property를 사용할 수 있습니다. 데이터는 옵저빙되어 변할때 마다 즉시 적용됩니다.

<script>
export default {
  data() {
    return {
      a: '10px',
      b: 10
    }
  }
...
  customProperties: {
    '--test-a': 'a',
    '--test-b'() {
      return this.b + 'px'
    }
  }
...
}
</script>

<style>
.element-a {
  font-size: var(--test-a)
}
.element-b {
  font-size: var(--test-b)
}
</style>

You can use this plugin programmatically as well. It runs only once and can also be used as an event
이 플러그인은 전역 함수로도 사용할 수 있습니다. 메소드를 통해 이벤트처럼 사용할 수 있습니다.

<script>
export default {
  ...
  methods: {
    test(val) {
      this.$customProperty('--global-property', val + 'px') // It will works on top of html elements
      this.$customProperty('--local-property', val + 'px', this)  // It only works on 'this' vue instance
    }
  }
  ...
}
</script>

Custom Properties Ready event hook

Use customPropertiesReady hook in your component
customProperty가 준비되었을 때 customPropertiesReady 이벤트 훅을 사용할 수 있습니다.

<template>
...
  <div class="element-a" v-if="ready">Hello world!<div>
...
</template>

<script>
export default {
  data() {
    return {
      ready: false
    }
  },
  ...
  customPropertiesReady() {
    this.ready = true
  }
  ...
}
</script>

Or put ready key to check whether css custom property is ready. 미리 준비된 customPropertiesReady 키를 데이터에 추가하여 즉시 바인딩 할 수도 있습니다.

<script>
export default {
  data() {
    return {
      customPropertiesReady: false  // If css custom properties is ready, change customPropertiesReady to true without using event hook
      // You can change this variable name by setting readyKey of this plugin options on vue.use
    }
  }
}
</script>