All Projects → nainemom → vue-component-style

nainemom / vue-component-style

Licence: MIT license
A Vue mixin to add style section to components.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vue-component-style

glamor-jss
Use glamor flavored CSS with jss under the hood…
Stars: ✭ 19 (+18.75%)
Mutual labels:  cssinjs, jss
gloss
a powerful style system for building ui kits
Stars: ✭ 16 (+0%)
Mutual labels:  cssinjs, jss
Jss
JSS is an authoring tool for CSS which uses JavaScript as a host language.
Stars: ✭ 6,576 (+41000%)
Mutual labels:  cssinjs, jss
jss-material-ui
A enhanced styling engine for material-ui
Stars: ✭ 15 (-6.25%)
Mutual labels:  style, jss
csstox
Convert CSS text to a React Native/JSS stylesheet object with ease.
Stars: ✭ 72 (+350%)
Mutual labels:  cssinjs, jss
tsstyled
A small, fast, and simple CSS-in-JS solution for React.
Stars: ✭ 52 (+225%)
Mutual labels:  style, jss
portfolio-2018
My personal portfolio / resume online
Stars: ✭ 18 (+12.5%)
Mutual labels:  nuxt
mtpThemeManager
An iOS theme manager with all the features. Everything you expect from a theme manager, contains apply theme to whole app, multiple themes, night mode, styles , ...
Stars: ✭ 13 (-18.75%)
Mutual labels:  style
nuxt-ghost
Easy Ghost content API integration with Nuxt.js.
Stars: ✭ 27 (+68.75%)
Mutual labels:  nuxt
nuxt-vite
Nuxt + Vite!! HMR so fast it'll make your head spin! Plus all the benefits of Nuxt
Stars: ✭ 54 (+237.5%)
Mutual labels:  nuxt
strapi-starter-nuxt-e-commerce
Strapi Starter Nuxt.js E-commerce
Stars: ✭ 170 (+962.5%)
Mutual labels:  nuxt
homepage-nuxtjs
Here we're trying to ship the front of homepage of KNIT
Stars: ✭ 13 (-18.75%)
Mutual labels:  nuxt
nuxtjs-sample
Nuxtjs sample! Typescript + Vuetify + Jest! (rails api server: https://github.com/walkersumida/rails-api-for-front)
Stars: ✭ 28 (+75%)
Mutual labels:  nuxt
aphrodite-jss
Aphrodite-like API on top of JSS.
Stars: ✭ 92 (+475%)
Mutual labels:  jss
nuxt-modules
AX2's Nuxt modules
Stars: ✭ 30 (+87.5%)
Mutual labels:  nuxt
nuxtwebsite
A simple Nuxt.js setup to create websites with blog feature using Storyblok as CMS and Netlify to deploy it.
Stars: ✭ 29 (+81.25%)
Mutual labels:  nuxt
nuxt-seomatic-meta
A module for connecting Nuxt.js to the Craft CMS SEOmatic plugin via GraphQL. Nuxt-o-matic!
Stars: ✭ 28 (+75%)
Mutual labels:  nuxt
nuxt-fundamentals
Source code for the Nuxt.js Fundamentals course
Stars: ✭ 40 (+150%)
Mutual labels:  nuxt
nuxt-modules-cli
Browse Nuxt.js modules from the terminal
Stars: ✭ 25 (+56.25%)
Mutual labels:  nuxt
enlite-starter
Enlite Starter - React Dashboard Starter Template with Firebase Auth
Stars: ✭ 28 (+75%)
Mutual labels:  jss

Vue Component Style

npm npm NPM

A Vue mixin to add style section to components.

Features

  • Zero Dependency
  • Tiny (~1kb gzipped)
  • Simple Setup and Usage
  • Nested Support
  • Pseudo Selector Support
  • SSR Support
  • Scoped to Component

Install

npm i vue-component-style

Setup

Vue App

import Vue from 'vue';
import VueComponentStyle from 'vue-component-style';

Vue.use(VueComponentStyle);

Nuxt App

nuxt.config.js:

module.exports = {
  modules: [
    'vue-component-style/nuxt'
  ],
}

Note that You don't need to do anything else with your webpack config or whatever.

Usage

component.vue:

<template>
  <div>
    <h1 :class="$style.title"> Title </h1>
    <div :class="$style.content">
      Content <a> Link </a>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    size: {
      type: Number,
      default: 8
    },
    color: {
      type: String,
      default: 'red'
    }
  },
  style({ className }) {
    return [
      className('title', {
        color: this.color,
        fontWeight: 'bold',
      }),
      className('content', {
        color: 'gray',
        marginBottom: `${this.size}px`,
        '& > a': {
          color: this.color,
          '&:visited': {
            textDecoration: 'underline',
          },
        },
      }),
    ];
  }
}
</script>

API Documentions

1 - Define Style

Function this.style(helper)

After activating VueComponentStyle, all components can have their js style section. Just like data section, you have to pass normal function that returning an Array. This function will invoke automatically with helper util object as first argument.

2 - Use Defined Styles

Object this.$style

After you defining style prop in your component, all your classes defined by style()s are accessable with $style computed object inside your component instance.

3 - Notice When Styles Updated

VueEvent 'styleChange'

styleChange event fires when your style changes and applied to DOM.


Helper

You can use helper() object from first parameter of style() function to defining your stylesheet. Helper object has these functions

Class Name

Function helper.className(name, content)

To define your scopped css class styles, use this helper function.

Param Type Default Description
name String Name of your class. All of your defined names will be accessable via $style Object later.
content Object {} Your sass-style class properties. You can also style nested.
Example
style({ className }) {
  return [
    className('customClass', {
      color: 'red',
      fontWeight: 'bold',
      borderRadius: `${this.size}px`,
      '& > div': {
        color: 'blue',
      },
    }),
  ];
}

Media Query

Function helper.mediaQuery(mediaFeature, content)

To define your customized style to different screen sizes, use this helper function.

Param Type Default Description
mediaFeature Object Media features. Common keys on this object are 'minWidth' and 'maxWidth'.
content Array [] List of className()s that you need to redefine.
Example
style({ mediaQuery, className }) {
  return [
    className('responsiveClass', {
      width: '50%',
    }),
    mediaQuery({ maxWidth: '320px' }, [
      className('responsiveClass', {
        width: '100%',
      }),     
    ]),
  ];
}

Key Frames

Function helper.keyFrames(name, content)

To define your scopped keyframes animation with specefic name, use this helper function.

Param Type Default Description
name String Keyframes name.
content Object Keyframes properties. If you don't pass this prop, calculated hash name of already generated keyframes will be returns.
Example
style({ keyFrames, className }) {
  return [
    className('animatedThing', {
      color: 'blue',
      animationName: keyFrames('myAnimation'),
      animationDuration: '2s',
    }),
    keyFrames('myAnimation', {
      from: {
        color: 'blue',
      },
      to: {
        color: 'red',
      },
    ]),
  ];
}

Custom

Function helper.custom(rule, content)

To define your custom css style sections, use this helper function. Note that styles generated by this helper function are not scopped!

Param Type Default Description
rule String Rule name.
content Object Style properties.
Example
style({ custom }) {
  return [
    custom('@font-face', {
      fontFamily: 'globalFont',
      src: 'url(global_font.woff)',
    }),
  ];
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].