|  | 
|  | 1 | +<div align="center"> | 
|  | 2 | + <img alt="CircleCI" src="https://img.shields.io/circleci/build/github/vueform/toggle"> | 
|  | 3 | + | 
|  | 4 | + <a href="https://codecov.io/gh/vueform/toggle" target="_blank"> | 
|  | 5 | + <img src="https://img.shields.io/codecov/c/github/vueform/toggle"/> | 
|  | 6 | + </a> | 
|  | 7 | + | 
|  | 8 | + <a href="https://www.npmjs.com/package/@vueform/toggle" target="_blank"> | 
|  | 9 | + <img alt="npm bundle size (scoped version)" src="https://img.shields.io/bundlephobia/minzip/@vueform/toggle?color=53ca2f"> | 
|  | 10 | + </a> | 
|  | 11 | + | 
|  | 12 | + <a href="https://github.com/vueform/toggle/blob/main/LICENSE.md" target="_blank"> | 
|  | 13 | + <img alt="GitHub" src="https://img.shields.io/github/license/vueform/toggle?color=53ca2f"> | 
|  | 14 | + </a> | 
|  | 15 | + | 
|  | 16 | + <a href="https://discord.gg/WhX2nG6GTQ" target="_blank"> | 
|  | 17 | + <img alt="Discord" src="https://img.shields.io/discord/787237947635793940"> | 
|  | 18 | + </a> | 
|  | 19 | + | 
|  | 20 | + <a href="https://www.npmjs.com/package/@vueform/toggle" target="_blank"> | 
|  | 21 | + <img alt="npm" src="https://img.shields.io/npm/v/@vueform/toggle"> | 
|  | 22 | + </a> | 
|  | 23 | + | 
|  | 24 | + <h1>Vue 3 Toggle</h1> | 
|  | 25 | +  | 
|  | 26 | + <a href="https://vueform.com?ref=github" target="_blank"> | 
|  | 27 | + <br> | 
|  | 28 | + <img align="center" src="https://github.com/vueform/toggle/raw/main/assets/logo.svg" width="110"> | 
|  | 29 | + <br> | 
|  | 30 | + </a> | 
|  | 31 | + | 
|  | 32 | + <br> | 
|  | 33 | + <br> | 
|  | 34 | + | 
|  | 35 | + <a href="https://www.npmjs.com/package/@vueform/toggle" target="_blank"> | 
|  | 36 | + <img align="center" src="https://github.com/vueform/toggle/raw/main/assets/screenshot-1.png"> | 
|  | 37 | + </a> | 
|  | 38 | + <br> | 
|  | 39 | + | 
|  | 40 | +</div> | 
|  | 41 | + | 
|  | 42 | +## Sponsors | 
|  | 43 | + | 
|  | 44 | +<div align="center"><br> | 
|  | 45 | + <a href="https://vueform.com?ref=github"><img src="https://github.com/vueform/toggle/raw/main/assets/logo-horizontal.svg" width="200"></a> | 
|  | 46 | +</div> | 
|  | 47 | + | 
|  | 48 | +## Toggle features | 
|  | 49 | + | 
|  | 50 | +* Vue 2 & 3 support | 
|  | 51 | +* No dependencies | 
|  | 52 | +* Lightweight (~1 kB gzipped) | 
|  | 53 | +* 100% coverage | 
|  | 54 | +* ESM support | 
|  | 55 | +* Fully configurable | 
|  | 56 | +* Dynamic styles | 
|  | 57 | +* On / Off labels | 
|  | 58 | + | 
|  | 59 | +## Demo  | 
|  | 60 | + | 
|  | 61 | +Check out our [demo](https://jsfiddle.net/p60t2bs4/). | 
|  | 62 | + | 
|  | 63 | +## Installation | 
|  | 64 | + | 
|  | 65 | +``` | 
|  | 66 | +npm install @vueform/toggle | 
|  | 67 | +``` | 
|  | 68 | + | 
|  | 69 | +## Usage with Vue 3 | 
|  | 70 | + | 
|  | 71 | +``` vue | 
|  | 72 | +<template> | 
|  | 73 | + <div> | 
|  | 74 | + <Toggle v-model="value" /> | 
|  | 75 | + </div> | 
|  | 76 | +</template> | 
|  | 77 | +
 | 
|  | 78 | +<script> | 
|  | 79 | + import Toggle from '@vueform/toggle' | 
|  | 80 | +
 | 
|  | 81 | + export default { | 
|  | 82 | + components: { | 
|  | 83 | + Toggle, | 
|  | 84 | + }, | 
|  | 85 | + data() { | 
|  | 86 | + return { | 
|  | 87 | + value: true | 
|  | 88 | + } | 
|  | 89 | + } | 
|  | 90 | + } | 
|  | 91 | +</script> | 
|  | 92 | +
 | 
|  | 93 | +<style src="@vueform/toggle/themes/default.css"></style> | 
|  | 94 | +``` | 
|  | 95 | + | 
|  | 96 | +## Usage with Vue 2 | 
|  | 97 | + | 
|  | 98 | +When using with Vue 2 make sure to install [@vue/composition-api](https://github.com/vuejs/composition-api#npm) first and change the imported module to: | 
|  | 99 | + | 
|  | 100 | +``` js | 
|  | 101 | +import Toggle from '@vueform/toggle/dist/toggle.vue2.js' | 
|  | 102 | +``` | 
|  | 103 | + | 
|  | 104 | +## Support | 
|  | 105 | + | 
|  | 106 | +Join our [Discord channel](https://discord.gg/WhX2nG6GTQ) or [open an issue](https://github.com/vueform/toggle/issues). | 
|  | 107 | + | 
|  | 108 | +## Basic props | 
|  | 109 | + | 
|  | 110 | +| Name | Type | Default | Description | | 
|  | 111 | +| --- | --- | --- | --- | | 
|  | 112 | +| **id** | `string` | `toggle` | The `id` attribute of input field. Make sure to customize when using more toggles on a single page. | | 
|  | 113 | +| **name** | `string` | `toggle` | The `name` attribute of input field. | | 
|  | 114 | +| **falseValue** | `string\|number\|boolean` | `false` | The value when the toggle is `off`. | | 
|  | 115 | +| **trueValue** | `string\|number\|boolean` | `true` | The value when toggle is `on`. | | 
|  | 116 | +| **offLabel** | `string` | | The label when toggle is `off`. | | 
|  | 117 | +| **onLabel** | `string` | | The label when toggle is `on`. | | 
|  | 118 | +| **width** | `number` | `54` | The width of the toggle in `px`. | | 
|  | 119 | +| **height** | `number` | `24` | The height of the toggle in `px`. | | 
|  | 120 | +| **speed** | `number` | `300` | The speed of toggle switch in `milliseconds`. | | 
|  | 121 | +| **offBackground** | `string` | `#d4e0e7` | The color of background when toggle is `off`. | | 
|  | 122 | +| **onBackground** | `string` | `#41b883` | The color of background when toggle is `on`. | | 
|  | 123 | +| **offTextColor** | `string` | `#888888` | The color of text when toggle is `off`. | | 
|  | 124 | +| **onTextColor** | `string` | `#ffffff` | The color of text when toggle is `on`. | | 
|  | 125 | +| **handleColor** | `string` | `#ffffff` | The background color of toggle handle. | | 
|  | 126 | +| **fontSize** | `string` | `13px` | The font size of toggle labels. | | 
|  | 127 | + | 
|  | 128 | +## Events | 
|  | 129 | + | 
|  | 130 | +| Event | Attributes | Description | | 
|  | 131 | +| --- | --- | --- | | 
|  | 132 | +| **@change** | `value` | Emitted when the toggle changes. | | 
|  | 133 | + | 
|  | 134 | +## Slots | 
|  | 135 | + | 
|  | 136 | +| Slot | Attributes | Description | | 
|  | 137 | +| --- | --- | --- | | 
|  | 138 | +| **off** | | Rendered when the toggle is `off` (by default `offLabel`). | | 
|  | 139 | +| **on** | | Rendered when the toggle is `on` (by default `onLabel`). | | 
|  | 140 | + | 
|  | 141 | +## Examples | 
|  | 142 | + | 
|  | 143 | +* [Default toggle](#default-toggle) | 
|  | 144 | +* [Toggle with labels](#toggle-with-labels) | 
|  | 145 | +* [Toggle with custom styles](#toggle-with-custom-style) | 
|  | 146 | + | 
|  | 147 | +### Default toggle | 
|  | 148 | + | 
|  | 149 | +``` vue | 
|  | 150 | +<Toggle | 
|  | 151 | + v-model="value" | 
|  | 152 | +/> | 
|  | 153 | +``` | 
|  | 154 | + | 
|  | 155 | +[JSFiddle - Example #1](https://jsfiddle.net/p60t2bs4/) | 
|  | 156 | + | 
|  | 157 | +### Toggle with labels | 
|  | 158 | + | 
|  | 159 | +``` vue | 
|  | 160 | +<Toggle | 
|  | 161 | + v-model="value" | 
|  | 162 | + on-label="On" | 
|  | 163 | + off-label="Off" | 
|  | 164 | + id="example2" | 
|  | 165 | +/> | 
|  | 166 | +``` | 
|  | 167 | + | 
|  | 168 | +[JSFiddle - Example #2](https://jsfiddle.net/p60t2bs4/) | 
|  | 169 | + | 
|  | 170 | +### Toggle with custom stylesg | 
|  | 171 | + | 
|  | 172 | +``` vue | 
|  | 173 | +<Toggle | 
|  | 174 | + v-model="value" | 
|  | 175 | + font-size="15px" | 
|  | 176 | + on-background="#35495e" | 
|  | 177 | + id="example3" | 
|  | 178 | + :width="80" | 
|  | 179 | + :height="30" | 
|  | 180 | + :speed="500" | 
|  | 181 | +/> | 
|  | 182 | +``` | 
|  | 183 | + | 
|  | 184 | +[JSFiddle - Example #3](https://jsfiddle.net/p60t2bs4/) | 
|  | 185 | + | 
|  | 186 | +## About Vueform | 
|  | 187 | + | 
|  | 188 | +[Vueform](https://vueform.com?ref=github) streamlines the entire form building process in Vue 2 & 3. It comes with 30+ elements, file uploads, element nesting, 50+ validators, conditions, form steps, i18n including reactive configuration, API access, ESM modules and many more. Check out our [live demos](https://vueform.com?ref=github#demo) or see [all the features](https://vueform.com?ref=github#features) and [sign up for beta](https://vueform.com?ref=github#beta) to get early access. | 
|  | 189 | + | 
|  | 190 | + | 
|  | 191 | +## License | 
|  | 192 | + | 
|  | 193 | +[MIT](https://github.com/vueform/toggle/blob/main/LICENSE.md) | 
0 commit comments