Home

Awesome

<h1 align="center">Vue Toggles</h1> <p align="center"> A highly customizable and accessible toggle component for Vue 3. </p> <p align="center"> <a href="https://www.npmjs.com/package/vue-toggles"><img src="https://img.shields.io/npm/v/vue-toggles.svg?style=flat-square"/> <img src="https://img.shields.io/npm/dt/vue-toggles.svg?style=flat-square"/></a> <a href="https://vuejs.org/"><img src="https://img.shields.io/badge/vue-3.x-brightgreen.svg?style=flat-square"/></a> </p> <p align="center"> <img src="./public/vue-toggles.jpg" alt="Vue Toggles Logo"/> </p>

Introduction

Vue Toggles comes out of the box with accessibility support for:

Accessibility

What's left for you, when it comes to accessibility, is labeling the toggle correctly. This is either done by:

The focus-style is also left up to you — which you shouldn't remove. If you think the default is ugly, style it yourself!

Installation

npm i vue-toggles

Import component

import { VueToggles } from "vue-toggles";

Import types

import { type VueTogglesProps } from "vue-toggles";

Usage

The toggle is very easy to use out of the box. The bare minimum for it to work is a @click-function and a :value-prop.

<VueToggles :value="example" @click="example = !example" />

Or if you prefer the v-model-syntax:

<VueToggles v-model="example" />

Options

You can also add more props to customize things like color and width/height.

<VueToggles
  :value="value"
  :height="30"
  :width="90"
  checkedText="On"
  uncheckedText="Off"
  checkedBg="#b4d455"
  uncheckedBg="lightgrey"
  @click="value = !value"
/>

Properties

NameTypeDefaultDescription
valueBooleanfalseInitial state of the toggle button
disabledBooleanfalseToggle does not react on mouse or keyboard events
reverseBooleanfalseReverse toggle to Right to Left
height[String, Number]25Height of the toggle in px
width[String, Number]75Width of the toggle in px
dotColorString#ffffffColor of the toggle dot
uncheckedBgString#939393Background color when the toggle is unchecked
checkedBgString#5850ecBackground color when the toggle is checked
uncheckedTextColorString#ffffffText color when the toggle is unchecked
checkedTextColorString#ffffffText color when the toggle is checked
uncheckedTextString""Optional text when the toggle is unchecked
checkedTextString""Optional text when the toggle is checked
fontSizeString12Font size in px
fontWeightStringnormalFont weight

Vue 2 support

If you're looking for Vue 2 support, the 1.1.4version is available here.

License

MIT