3.0.6 • Published 12 months ago

vuejs-toggle-switch v3.0.6

Weekly downloads
1,261
License
MIT
Repository
github
Last release
12 months ago

vuejs-toggle-switch

Toggle switch for vue.js v3.0.6

Live demo

Tested OK v3.0.6 for Vue 3.2.47 16.05.2023 :white_check_mark:

Do you have questions or want a new feature? Use the "Issues" section :point_left:

Setup

install:

npm install vuejs-toggle-switch --save

Import:

import { ToggleSwitch } from 'vuejs-toggle-switch'

Usage

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

<toggle-switch
  :options="myOptions"
  :disabled="false" // optional, can use here on top level or in config 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)
  :modelValue="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
  /> 

<!-- Options struct: -->
myOptions: {
  layout: {
    color: 'black',
    backgroundColor: 'lightgray',
    selectedColor: 'white',
    selectedBackgroundColor: 'green',
    borderColor: 'black',
    fontFamily: 'Arial',
    fontWeight: 'normal',
    fontWeightSelected: 'bold',
    squareCorners: false,
    noBorder: false
  },
  size: {
    height: 2,
    width: 16,
    padding: 0.4,
    fontSize: 1
  },
  config: {
    preSelected: 'On',
    disabled: false,
    items: [
        { name: 'Off', value: 'Off', color: 'white', backgroundColor: 'red' },
        { name: 'On', value: 'On', color: 'white', backgroundColor: 'green' }
    ]
  }
},

Properties

NameTypeDefaultDescription
widthNumber10Width of labels
heightNumber3.25Height
paddingNumber0.5Adjust text location in item with this
backgroundColorStringlightgrayBackground color (not selected)
colorStringblackText color (not selected)
borderColorStringgrayborder color
selectedColorStringwhiteText color selected item
selectedBackgroundColorStringgreenSelected item background color
fontFamilyStringArialFont of item text
fontWeightStringnormalFont weight item (not selected)
fontWeightSelectedStringboldFont weight selected item
fontSizeNumber1.5Text size
disabledBooleanfalseDisable switch
preSelectedStringOnSet (pre) selected item
itemsArrayOff/OnItems for switch, name and value (string) mandatory
modelValueStringn/aValue, ie: v-model="selectedMapOption"
squareCornersBooleanfalseRounded corners of switch
noBorderBooleanfalseRemove border
groupString''Switch key/group name (optional)
nameString''Name for input field (optional) can be used as ref for forms etc
disabled (prop)BooleanfalseDisable 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

NameDescription
changeTriggered on toggle, user selects switch option, returns current value. @change="vmValueItem = $event.value"
selectedTriggered whenever user select switch item
inputTriggered on mount if preSelected is set or value is set, and on toggle/change
3.0.4

12 months ago

3.0.3

12 months ago

3.0.2

12 months ago

3.0.1

12 months ago

3.0.6

12 months ago

3.0.5

12 months ago

3.0.0

12 months ago

2.0.0

2 years ago

1.3.4

2 years ago

1.3.3

3 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

5 years ago

1.2.40

5 years ago

1.2.38

5 years ago

1.2.37

5 years ago

1.2.36

5 years ago

1.2.35

5 years ago

1.2.34

5 years ago

1.2.33

5 years ago

1.2.32

5 years ago

1.1.32

5 years ago

1.1.31

5 years ago

1.1.30

5 years ago

1.1.29

6 years ago

1.1.28

6 years ago

1.1.27

6 years ago

1.1.26

6 years ago

1.1.25

6 years ago

1.1.24

6 years ago

1.1.23

6 years ago

1.1.22

6 years ago

1.1.21

6 years ago

1.1.20

6 years ago

1.1.19

6 years ago

1.1.18

6 years ago

1.1.17

6 years ago

1.1.16

6 years ago

1.1.15

6 years ago

1.1.14

6 years ago

1.1.13

6 years ago

1.1.12

6 years ago

1.1.11

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago