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-theme-manager

v1.1.3

Published

A vuejs plugin for Managing theme(s) colors in the whole of your Vue web app. It has support for Vue 2x, Vue 3x and Nuxt

Downloads

6

Readme

vue-theme-manager

A vuejs plugin for Managing theme(s) colors in the whole of your Vue web app. It has support for Vue 2 and Vue 3 npm

Installation

npm i vue-theme-manager

Guide

For Vue 2x and Vue 3x

//main.js
...
import VueThemeManager from 'vue-theme-manager'
...
let themeOptions = {
activate:'light',
styles:{
     light:{
           backgroundColor:'#ededed',
           textColor:'#101010'
            },
     dark:{
           backgroundColor:'#1111',
           textColor:'#ededed'
            }
      }
}

Vue.use(VueThemeManager,themeOptions);

...

For Nuxt

//plugins/vue_theme_manager.js
import Vue from 'vue'
import VueThemeManager from 'vue-theme-manager'
     
   let themeOptions =  { 
       activate:'light', 
       styles:{ 
            light:{ 
                 backgroundColor:'#ededed', 
                 textColor:'#101010'  
                  }, 
             dark:{ 
                  backgroundColor:'#1111', 
                  textColor:'#ededed' 
                   }  
               }  
        } 

Vue.use(VueThemeManager,themeOptions);
//nuxt.config.js
plugins:[
  ...

  {src:'@plugins/vue_theme_manager',mode:'client'}
  
  ...
]

Plugin Options

Plugin accepts object or jsonstring during initialization with props [This is Optional]:

 Vue.use(VueThemeManager,{activate:,styles})
  1. activate:'string' ---this will be the activated theme when plugin is initialized. Note default theme is default[This is optional]
  2. styles:object ---this is an object containig theme options that will be available during plugin initialization. Note "default" theme option is always added to this object [This is Optional]

Template Usage

For Vue2x and Vue3x

App.vue <!-- root app !-->

<!-- register theme-manager-plugin-globally for all component template  !-->
   <div id="app" :style="VueThemeManager">
   ...
   <router>
   </router>
   ...
   </div>
   <style>
   ...
   </style>

For Nuxt

/layout/default.vue <!-- root app !-->

<!-- register theme-manager-plugin-globally for all component template  !-->
 <nuxt :style="VueThemeManager" />

Now use in Any Component Like this Both in Nuxt and Vue Projects

anycomponent.vue 


<template>
<div class="wrapper">
Hello World

 <span :style="textColor:'var(--accent-color)'">
 I am using accent color
 </span>

 <!--this access the currently  selected theme option !-->
 <span :style="textColor:$AppTheme.theme.accentColor">
 I am using accent color
 </span>

<span :style="textColor:$AppTheme.theme['themeName'].accentColor">
 I am using accent color
 </span>
 
</div>
</template>
  <style>
    .wrapper{
         ...
          background-color:var(--background-color);
          text-color:var(--text-color);
          ...
       }
    </style>
<!-- as you can see here theme options are generally dynamic !-->

Methods

//this returns object
this.console.log(JSON.stringify(this.$AppTheme.theme,null,2));



//this returns object
let themeName = 'light' 
this.console.log(JSON.stringify(this.$AppTheme.theme[themeName],null,2))
/*result 
 {
  textColor:'#ededed,
  backgroundColor:'#101010'
 }
 */
 
 
 
// we can still go further
let themeName = 'light' 
this.console.log(JSON.stringify(this.$AppTheme.theme[themeName].textColor,null,2))
//returns '#ededed' 

this.console.log(this.$AppTheme.textColor)
//returns currently selected theme textColor '#ededed' 





/*This will be called once Theme Plugin has been initialized
This can be used in your App.vue or default.vue file or any other component
you wish to use it in
*/
 this.$AppTheme.onReady((themeExistInDeviceDB)=>{
 if(themeExistInDeviceDB){
    this.$AppTheme.setThemeFromStorage();//this is to set theme from db
   }
 });
 




//This will be called when New Theme has been Selected
this.$AppTheme.onThemeChanged((themeName,themeOptions)=>{
...
//do what ever you want with the results
})





this.$AppTheme.addTheme({textColor:'red',backgroundColor:'gold'},"splash",true);
//this.$AppTheme.addTheme({options},themeName,activate)

/*
*options = "object" or "json-string" @required
*themeName = "String" intended name for theme @optional default  is "default"
*activate = boolean --activate theme or not
*/




this.$AppTheme.saveTheme(); //save theme to db 

//this can also be changed like this
this.$AppTheme.addTheme(...).saveTheme();



this.$AppTheme.activateTheme(themeName);
//where themeName is a `String` which is already contained in the themeOptions





this.$AppTheme.getTheme(themeName,array);
//returns object of themeOptions

//themeName = name of theme to get options from @required
array = themeoptions to be gotten like ['textColor','backgroundColor'] @optional

///generally data can be accessed like this
this.$AppTheme.getTheme('splash',['textColor']).texColor 
//result 'red'

Points to Note

  1. camel case textColor are changed to kebal case text-color only for css variables
  2. css variables are dynamic and should be accessed like this var(--text-color)
  3. Try as much as possible to name your theme options with camel case textColor, accentColor, backgroundColor
  4. css variables acess only the currently selected theme