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

vuejs-three-state-switch

v1.3.4

Published

A toggle switch component for Vue.js

Downloads

152

Readme

vuejs-three-state-switch

Toggle switch for vue.js v1.3.0

Setup

install:

npm install vuejs-three-state-switch --save

Import: (in your main.js)

import ToggleSwitch from 'vuejs-three-state-switch'
Vue.use(ToggleSwitch)

Usage

Use: (in your local .vue file/component, html section)

Simple:
<toggle-switch group="a" :options="myOptions" @change="log($event.value)" v-model="value1"/>
<toggle-switch group="b" :options="myOptions" @change="log($event.value)" v-model="value2"/>
<!-- Options struct: -->
myOptions: {
    items: {
        preSelected: 'unknown',
        labels: [
        { name: 'Off', color: 'white', backgroundColor: 'red' },
        { name: 'unknown', color: 'white', backgroundColor: 'grey' },
        { name: 'On', color: 'white', backgroundColor: 'green' }
        ]
    }
}

Detailed:
<toggle-switch
  :options="myOptions"
  :disabled="false" // optional, can use here on top level or in items section
  @change="updateMap($event.value)" // This is optional
  @selected="selectedMethod()" // This is optional
  v-model="selectedMapOption" // This is optional 2-way binding (try not to use both 1-way and 2-way)
  :value="selectedMapOption" // This is optional 1-way binding (try not to use both 1-way and 2-way)
  :name="name" // This is optional for input block
  :group="switchGroup" // This is optional, use if multiple toggle-switch on same page with same label names
  /> 

myOptions: {
  layout: {
    color: 'black',
    backgroundColor: 'lightgray',
    selectedColor: 'white',
    selectedBackgroundColor: 'green',
    borderColor: 'black',
    fontFamily: 'Arial',
    fontWeight: 'normal',
    fontWeightSelected: 'bold',
    squareCorners: false,
    noBorder: false
  },
  size: {
    fontSize: 14,
    height: 34,
    padding: 7,
    width: 100
  },
  items: {
    delay: .4,
    preSelected: 'unknown',
    disabled: false,
    labels: [
      {name: 'Off', color: 'white', backgroundColor: 'red'}, 
      {name: 'On', color: 'white', backgroundColor: 'green'}
    ]
  }
}

Properties

| Name | Type | Default | Description | | --- | --- | --- | --- | | width | Number | 10 | Width of labels | | height | Number | 3.25 | Height | | padding | Number | 0.5 | Adjust text location in label with this | | backgroundColor | String | lightgray | Background color (not selected) | | color | String | black | Text color (not selected)| | borderColor | String | gray | border color | | selectedColor | String | white | Text color selected label | | selectedBackgroundColor | String | green | Selected label background color | | fontFamily | String | Arial | Font of label text | | fontWeight | String | normal | Font weight item (not selected) | | fontWeightSelected | String | bold | Font weight selected item | | fontSize | Number | 1.5 | Text size | | disabled | Boolean | false | Disable switch | | preSelected | String | On | Set (pre) selected label | | labels | Array | Off/On | Labels for switch, name property is mandatory| | value | String | n/a | Value, ie: v-model="selectedMapOption" | | delay | Number | .4 | Transition delay between labels is seconds | | squareCorners | Boolean | false | Rounded corners of switch | | noBorder | Boolean | false | Remove border | | group | String | '' | Switch key/group name (optional) | | name | String | '' | Name for input field (optional) can be used as ref for forms etc | | disabled (prop) | Boolean | false | Disable switch on top level (prop) |

Labels prop can be used with or without color and backgroundColor attr, if not used the common prop: selectedColor and selectedBackgroundColor will be used for all labels.

Events

| Name | Description | | --- | --- | | change | Triggered on toggle, user selects switch option, returns current value. @change="vmValueItem = $event.value" | | selected | Triggered whenever user select switch item | | input | Triggered on mount if preSelected is set or value is set, and on toggle/change |

Todo 📌

  • Pass class name to switch
  • Option to use id for labels not only name
  • ~~Add disabled to top level~~
  • ~~Add coditional class "slected" to label if selected~~