@vuesimple/vs-switch 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +260 -0
- package/build/rollup.config.js +30 -0
- package/build/vite.config.js +33 -0
- package/package.json +48 -0
- package/src/index.js +10 -0
- package/src/vs-switch.vue +376 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ashwin Shenoy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# Vue Simple Switch
|
|
2
|
+
|
|
3
|
+
#### 🎚 A simple vue switch component. Toggle switch alternative to the checkbox.
|
|
4
|
+
|
|
5
|
+
A light weight vue plugin built from the ground up
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@vuesimple/vs-switch)
|
|
8
|
+
[](https://img.shields.io/npm/dt/@vuesimple/vs-switch.svg)
|
|
9
|
+
<br />
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+

|
|
13
|
+

|
|
14
|
+

|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
<br />
|
|
18
|
+
|
|
19
|
+
### 📺 Live Demo
|
|
20
|
+
|
|
21
|
+
Demo: [Link](https://vuesimple.netlify.app)
|
|
22
|
+
|
|
23
|
+
<br />
|
|
24
|
+
|
|
25
|
+
### 🛠 Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm i @vuesimple/vs-switch
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
<br />
|
|
32
|
+
|
|
33
|
+
### 🚀 Usage
|
|
34
|
+
|
|
35
|
+
```html
|
|
36
|
+
<template>
|
|
37
|
+
<vs-switch v-model="isEnabled" />
|
|
38
|
+
</template>
|
|
39
|
+
|
|
40
|
+
<script>
|
|
41
|
+
import VsSwitch from '@vuesimple/vs-switch';
|
|
42
|
+
|
|
43
|
+
export default {
|
|
44
|
+
components: {
|
|
45
|
+
VsSwitch,
|
|
46
|
+
},
|
|
47
|
+
data() {
|
|
48
|
+
return {
|
|
49
|
+
isEnabled: false,
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
</script>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
<br />
|
|
57
|
+
|
|
58
|
+
### 🌎 CDN
|
|
59
|
+
|
|
60
|
+
```html
|
|
61
|
+
<script src="https://unpkg.com/@vuesimple/vs-switch@<version>/dist/index.min.js"></script>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
// Main/Entry file
|
|
66
|
+
app.use(VsSwitch.plugin);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```html
|
|
70
|
+
<template>
|
|
71
|
+
<vs-switch v-model="isEnabled" />
|
|
72
|
+
</template>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
<br />
|
|
76
|
+
|
|
77
|
+
<h3>
|
|
78
|
+
<img src="https://i.imgur.com/MWynQNa.png" width="20px"> Nuxt.js
|
|
79
|
+
</h3>
|
|
80
|
+
|
|
81
|
+
Nuxt Code Snippet
|
|
82
|
+
|
|
83
|
+
After installation,
|
|
84
|
+
|
|
85
|
+
- Create a file `/plugins/vs-switch.js`
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
import Vue from 'vue';
|
|
89
|
+
import VsSwitch from '@vuesimple/vs-switch';
|
|
90
|
+
|
|
91
|
+
Vue.component('vs-switch', VsSwitch);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- Update `nuxt.config.js`
|
|
95
|
+
```javascript
|
|
96
|
+
module.exports = {
|
|
97
|
+
...
|
|
98
|
+
plugins: [
|
|
99
|
+
{ src: '~plugins/vs-switch', mode: 'client' }
|
|
100
|
+
...
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
- In the page/ component
|
|
105
|
+
|
|
106
|
+
```html
|
|
107
|
+
<template>
|
|
108
|
+
<vs-switch v-model="isEnabled" />
|
|
109
|
+
</template>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Note**
|
|
113
|
+
|
|
114
|
+
- For older Nuxt versions, use `<no-ssr>...</no-ssr>` tag.
|
|
115
|
+
- You can also do
|
|
116
|
+
`import VsSwitch from '@vuesimple/vs-switch'`
|
|
117
|
+
& add in `component:{VsSwitch}` and use it within component, without globally installing in plugin folder.
|
|
118
|
+
|
|
119
|
+
<br />
|
|
120
|
+
|
|
121
|
+
### ⚙ Props
|
|
122
|
+
|
|
123
|
+
| Name | Type | Default | Description |
|
|
124
|
+
| -------------- | ------- | --------- | ----------------------------------------------------------- |
|
|
125
|
+
| modelValue | Boolean | `false` | The checked state (supports v-model) |
|
|
126
|
+
| size | String | `medium` | Size of switch. (`small`, `medium`, `large`) |
|
|
127
|
+
| variant | String | `classic` | Visual variant. (`classic`, `surface`, `soft`) |
|
|
128
|
+
| color | String | `primary` | Color theme of the switch when checked |
|
|
129
|
+
| highContrast | Boolean | `false` | High contrast mode for better visibility |
|
|
130
|
+
| radius | String | `full` | Border radius. (`none`, `small`, `medium`, `large`, `full`) |
|
|
131
|
+
| disabled | Boolean | `false` | Disable the switch |
|
|
132
|
+
| ariaLabel | String | - | Aria label for accessibility |
|
|
133
|
+
| checkedBgColor | String | - | Custom background color when checked (hex/rgb/text color) |
|
|
134
|
+
|
|
135
|
+
<br />
|
|
136
|
+
|
|
137
|
+
### 🔥 Events
|
|
138
|
+
|
|
139
|
+
| Name | Description |
|
|
140
|
+
| ------- | ---------------------------------------------- |
|
|
141
|
+
| v-model | Emitted when the switch state changes |
|
|
142
|
+
| change | Emitted when the switch state changes (detail) |
|
|
143
|
+
|
|
144
|
+
<br />
|
|
145
|
+
|
|
146
|
+
### 📎 Slots
|
|
147
|
+
|
|
148
|
+
Currently, the switch component does not have slots. It renders as a simple toggle button.
|
|
149
|
+
|
|
150
|
+
<br />
|
|
151
|
+
|
|
152
|
+
### 🎨 Color Options
|
|
153
|
+
|
|
154
|
+
The switch supports various color themes when checked:
|
|
155
|
+
|
|
156
|
+
- `primary` (default blue)
|
|
157
|
+
- `success` (green)
|
|
158
|
+
- `danger` (red)
|
|
159
|
+
- `warning` (orange)
|
|
160
|
+
- `secondary` (dark gray)
|
|
161
|
+
- `indigo`
|
|
162
|
+
- `cyan`
|
|
163
|
+
- `orange`
|
|
164
|
+
- `crimson`
|
|
165
|
+
- `gray`
|
|
166
|
+
|
|
167
|
+
<br />
|
|
168
|
+
|
|
169
|
+
### 📝 Examples
|
|
170
|
+
|
|
171
|
+
#### Basic Switch
|
|
172
|
+
|
|
173
|
+
```html
|
|
174
|
+
<vs-switch v-model="isEnabled" />
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### Switch with Label
|
|
178
|
+
|
|
179
|
+
```html
|
|
180
|
+
<label>
|
|
181
|
+
<vs-switch v-model="isEnabled" />
|
|
182
|
+
Enable notifications
|
|
183
|
+
</label>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### Different Sizes
|
|
187
|
+
|
|
188
|
+
```html
|
|
189
|
+
<vs-switch v-model="isEnabled" size="small" />
|
|
190
|
+
<vs-switch v-model="isEnabled" size="medium" />
|
|
191
|
+
<vs-switch v-model="isEnabled" size="large" />
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### Different Variants
|
|
195
|
+
|
|
196
|
+
```html
|
|
197
|
+
<vs-switch v-model="isEnabled" variant="classic" />
|
|
198
|
+
<vs-switch v-model="isEnabled" variant="surface" />
|
|
199
|
+
<vs-switch v-model="isEnabled" variant="soft" />
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### Different Colors
|
|
203
|
+
|
|
204
|
+
```html
|
|
205
|
+
<vs-switch v-model="isEnabled" color="primary" />
|
|
206
|
+
<vs-switch v-model="isEnabled" color="success" />
|
|
207
|
+
<vs-switch v-model="isEnabled" color="danger" />
|
|
208
|
+
<vs-switch v-model="isEnabled" color="indigo" />
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
#### Disabled State
|
|
212
|
+
|
|
213
|
+
```html
|
|
214
|
+
<vs-switch v-model="isEnabled" disabled />
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
#### High Contrast
|
|
218
|
+
|
|
219
|
+
```html
|
|
220
|
+
<vs-switch v-model="isEnabled" highContrast color="indigo" />
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### Custom Color for Checked State
|
|
224
|
+
|
|
225
|
+
```html
|
|
226
|
+
<vs-switch v-model="isEnabled" checkedBgColor="#ff6b6b" />
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
<br />
|
|
230
|
+
|
|
231
|
+
### 🔔 Events Handling
|
|
232
|
+
|
|
233
|
+
```html
|
|
234
|
+
<template>
|
|
235
|
+
<vs-switch v-model="isEnabled" @change="handleChange" />
|
|
236
|
+
</template>
|
|
237
|
+
|
|
238
|
+
<script>
|
|
239
|
+
export default {
|
|
240
|
+
data() {
|
|
241
|
+
return {
|
|
242
|
+
isEnabled: false,
|
|
243
|
+
};
|
|
244
|
+
},
|
|
245
|
+
methods: {
|
|
246
|
+
handleChange(newValue) {
|
|
247
|
+
console.log('Switch is now:', newValue);
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
</script>
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
<br />
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
### License
|
|
259
|
+
|
|
260
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import vue from '@vitejs/plugin-vue';
|
|
2
|
+
import { defineConfig } from 'rollup';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
input: 'src/index.js',
|
|
6
|
+
output: [
|
|
7
|
+
{
|
|
8
|
+
file: 'dist/index.esm.js',
|
|
9
|
+
format: 'es',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
file: 'dist/index.umd.js',
|
|
13
|
+
format: 'umd',
|
|
14
|
+
name: 'VsSwitch',
|
|
15
|
+
globals: {
|
|
16
|
+
vue: 'Vue',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
file: 'dist/index.min.js',
|
|
21
|
+
format: 'iife',
|
|
22
|
+
name: 'VsSwitch',
|
|
23
|
+
globals: {
|
|
24
|
+
vue: 'Vue',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
external: ['vue'],
|
|
29
|
+
plugins: [vue()],
|
|
30
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import vue from '@vitejs/plugin-vue';
|
|
2
|
+
import VitePluginStyleInject from 'vite-plugin-style-inject';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
plugins: [vue(), VitePluginStyleInject()],
|
|
6
|
+
build: {
|
|
7
|
+
// separate css file or not
|
|
8
|
+
cssCodeSplit: false,
|
|
9
|
+
lib: {
|
|
10
|
+
entry: './src/index.js',
|
|
11
|
+
formats: ['es', 'umd', 'iife'],
|
|
12
|
+
name: 'VsSwitch',
|
|
13
|
+
fileName: format => {
|
|
14
|
+
if (format === 'es') {
|
|
15
|
+
return 'index.esm.js';
|
|
16
|
+
}
|
|
17
|
+
if (format === 'umd') {
|
|
18
|
+
return 'index.umd.js';
|
|
19
|
+
}
|
|
20
|
+
return 'index.min.js';
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
rollupOptions: {
|
|
24
|
+
// Not to bundle vue core in this plugin
|
|
25
|
+
external: ['vue'],
|
|
26
|
+
output: {
|
|
27
|
+
globals: {
|
|
28
|
+
vue: 'Vue',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vuesimple/vs-switch",
|
|
3
|
+
"version": "3.1.3",
|
|
4
|
+
"description": "A simple vue switch component. Toggle switch alternative to the checkbox.",
|
|
5
|
+
"main": "dist/index.umd.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"unpkg": "dist/index.min.js",
|
|
8
|
+
"jsdelivr": "dist/index.min.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rm -rfv dist && vite build --config build/vite.config.js"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@vitejs/plugin-vue": "^3.0.1",
|
|
14
|
+
"sass": "^1.54.4",
|
|
15
|
+
"vite": "^3.0.5",
|
|
16
|
+
"vite-plugin-style-inject": "0.0.1",
|
|
17
|
+
"vue": "^3.2.37"
|
|
18
|
+
},
|
|
19
|
+
"private": false,
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/ashwinkshenoy/vue-simple.git"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"registry": "https://registry.npmjs.org"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"vue",
|
|
29
|
+
"vuejs",
|
|
30
|
+
"switch",
|
|
31
|
+
"toggle",
|
|
32
|
+
"checkbox",
|
|
33
|
+
"form",
|
|
34
|
+
"front-end",
|
|
35
|
+
"web",
|
|
36
|
+
"vue-js",
|
|
37
|
+
"vue-js-switch",
|
|
38
|
+
"vue-switch",
|
|
39
|
+
"vs-switch"
|
|
40
|
+
],
|
|
41
|
+
"author": "Ashwin Shenoy <ashwinkshenoy@gmail.com>",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/ashwinkshenoy/vue-simple/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/ashwinkshenoy/vue-simple",
|
|
47
|
+
"gitHead": "dbda7c423a550ef9aa42b3f82f92bb38d76a6948"
|
|
48
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<button
|
|
3
|
+
:class="['vs-switch', classList]"
|
|
4
|
+
:style="isCssVars"
|
|
5
|
+
:aria-checked="isChecked"
|
|
6
|
+
:aria-label="ariaLabel"
|
|
7
|
+
role="switch"
|
|
8
|
+
type="button"
|
|
9
|
+
:disabled="disabled"
|
|
10
|
+
@click="toggle"
|
|
11
|
+
>
|
|
12
|
+
<span class="vs-switch__thumb"></span>
|
|
13
|
+
</button>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script>
|
|
17
|
+
export default {
|
|
18
|
+
name: 'VsSwitch',
|
|
19
|
+
|
|
20
|
+
props: {
|
|
21
|
+
// v-model support
|
|
22
|
+
modelValue: {
|
|
23
|
+
type: Boolean,
|
|
24
|
+
default: false,
|
|
25
|
+
},
|
|
26
|
+
// `small`, `medium`, `large`
|
|
27
|
+
size: {
|
|
28
|
+
type: String,
|
|
29
|
+
default: 'medium',
|
|
30
|
+
validator: val => ['small', 'medium', 'large'].includes(val),
|
|
31
|
+
},
|
|
32
|
+
// `classic`, `surface`, `soft`
|
|
33
|
+
variant: {
|
|
34
|
+
type: String,
|
|
35
|
+
default: 'classic',
|
|
36
|
+
validator: val => ['classic', 'surface', 'soft'].includes(val),
|
|
37
|
+
},
|
|
38
|
+
// Color theme
|
|
39
|
+
color: {
|
|
40
|
+
type: String,
|
|
41
|
+
default: 'primary',
|
|
42
|
+
},
|
|
43
|
+
// High contrast mode
|
|
44
|
+
highContrast: {
|
|
45
|
+
type: Boolean,
|
|
46
|
+
default: false,
|
|
47
|
+
},
|
|
48
|
+
// // Border radius: `none`, `small`, `medium`, `large`, `full`
|
|
49
|
+
// radius: {
|
|
50
|
+
// type: String,
|
|
51
|
+
// default: 'full',
|
|
52
|
+
// validator: val => ['none', 'small', 'medium', 'large', 'full'].includes(val),
|
|
53
|
+
// },
|
|
54
|
+
// Disabled state
|
|
55
|
+
disabled: {
|
|
56
|
+
type: Boolean,
|
|
57
|
+
default: false,
|
|
58
|
+
},
|
|
59
|
+
// Aria label for accessibility
|
|
60
|
+
ariaLabel: {
|
|
61
|
+
type: String,
|
|
62
|
+
},
|
|
63
|
+
// Custom background color for checked state
|
|
64
|
+
checkedBgColor: {
|
|
65
|
+
type: String,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
emits: ['update:modelValue', 'change'],
|
|
70
|
+
|
|
71
|
+
computed: {
|
|
72
|
+
isChecked() {
|
|
73
|
+
return this.modelValue;
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
classList() {
|
|
77
|
+
return [
|
|
78
|
+
`vs-switch__size-${this.size}`,
|
|
79
|
+
`vs-switch__variant-${this.variant}`,
|
|
80
|
+
`vs-switch__color-${this.color}`,
|
|
81
|
+
`vs-switch__radius-${this.radius}`,
|
|
82
|
+
{
|
|
83
|
+
'vs-switch--checked': this.isChecked,
|
|
84
|
+
'vs-switch--disabled': this.disabled,
|
|
85
|
+
'vs-switch--high-contrast': this.highContrast,
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
cssVars() {
|
|
91
|
+
return {
|
|
92
|
+
'--vs-switch-checked-bg-color': this.checkedBgColor,
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
isCssVars() {
|
|
97
|
+
return this.checkedBgColor ? this.cssVars : '';
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
methods: {
|
|
102
|
+
toggle() {
|
|
103
|
+
if (!this.disabled) {
|
|
104
|
+
const newValue = !this.isChecked;
|
|
105
|
+
this.$emit('update:modelValue', newValue);
|
|
106
|
+
this.$emit('change', newValue);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
</script>
|
|
112
|
+
|
|
113
|
+
<style lang="scss">
|
|
114
|
+
$el: '.vs-switch';
|
|
115
|
+
|
|
116
|
+
// Dark mode styles are handled globally
|
|
117
|
+
[data-theme='dark'],
|
|
118
|
+
.dark {
|
|
119
|
+
#{$el} {
|
|
120
|
+
--vs-switch-bg-unchecked: #3a3a3a;
|
|
121
|
+
--vs-switch-bg-checked: #1f73b7;
|
|
122
|
+
--vs-switch-thumb: #ffffff;
|
|
123
|
+
--vs-switch-border: #555555;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#{$el} {
|
|
128
|
+
--vs-switch-bg-unchecked: #e9ebed;
|
|
129
|
+
--vs-switch-bg-checked: #1f73b7;
|
|
130
|
+
--vs-switch-thumb: #ffffff;
|
|
131
|
+
--vs-switch-border: #d1d5db;
|
|
132
|
+
--vs-switch-primary: #1f73b7;
|
|
133
|
+
--vs-switch-success: #186146;
|
|
134
|
+
--vs-switch-danger: #cc3340;
|
|
135
|
+
--vs-switch-warning: #ffb057;
|
|
136
|
+
--vs-switch-secondary: #3a3a3a;
|
|
137
|
+
--vs-switch-indigo: #4f46e5;
|
|
138
|
+
--vs-switch-cyan: #06b6d4;
|
|
139
|
+
--vs-switch-orange: #f97316;
|
|
140
|
+
--vs-switch-crimson: #dc2626;
|
|
141
|
+
--vs-switch-gray: #6b7280;
|
|
142
|
+
|
|
143
|
+
position: relative;
|
|
144
|
+
display: inline-flex;
|
|
145
|
+
align-items: center;
|
|
146
|
+
justify-content: flex-start;
|
|
147
|
+
cursor: pointer;
|
|
148
|
+
border: none;
|
|
149
|
+
padding: 0;
|
|
150
|
+
background: none;
|
|
151
|
+
transition: all 0.2s ease;
|
|
152
|
+
border-radius: var(--vs-switch-border-radius);
|
|
153
|
+
|
|
154
|
+
&:focus-visible {
|
|
155
|
+
outline: none;
|
|
156
|
+
box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px var(--vs-switch-bg-checked);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
&:disabled {
|
|
160
|
+
cursor: not-allowed;
|
|
161
|
+
opacity: 0.5;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Sizes
|
|
165
|
+
&__size-small {
|
|
166
|
+
width: 36px;
|
|
167
|
+
height: 20px;
|
|
168
|
+
--vs-switch-border-radius: 10px;
|
|
169
|
+
|
|
170
|
+
.vs-switch__thumb {
|
|
171
|
+
width: 16px;
|
|
172
|
+
height: 16px;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
&.vs-switch--checked .vs-switch__thumb {
|
|
176
|
+
transform: translateX(16px);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
&__size-medium {
|
|
181
|
+
width: 44px;
|
|
182
|
+
height: 24px;
|
|
183
|
+
--vs-switch-border-radius: 12px;
|
|
184
|
+
|
|
185
|
+
.vs-switch__thumb {
|
|
186
|
+
width: 20px;
|
|
187
|
+
height: 20px;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
&.vs-switch--checked .vs-switch__thumb {
|
|
191
|
+
transform: translateX(20px);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
&__size-large {
|
|
196
|
+
width: 52px;
|
|
197
|
+
height: 28px;
|
|
198
|
+
--vs-switch-border-radius: 14px;
|
|
199
|
+
|
|
200
|
+
.vs-switch__thumb {
|
|
201
|
+
width: 24px;
|
|
202
|
+
height: 24px;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
&.vs-switch--checked .vs-switch__thumb {
|
|
206
|
+
transform: translateX(24px);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Radius
|
|
211
|
+
&__radius-none {
|
|
212
|
+
--vs-switch-border-radius: 0;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
&__radius-small {
|
|
216
|
+
--vs-switch-border-radius: 4px;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
&__radius-medium {
|
|
220
|
+
--vs-switch-border-radius: 6px;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
&__radius-large {
|
|
224
|
+
--vs-switch-border-radius: 8px;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
&__radius-full {
|
|
228
|
+
--vs-switch-border-radius: 100px;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Variants - classic (default, outlined)
|
|
232
|
+
&__variant-classic {
|
|
233
|
+
background: var(--vs-switch-bg-unchecked);
|
|
234
|
+
border: 1px solid var(--vs-switch-border);
|
|
235
|
+
|
|
236
|
+
&.vs-switch--checked {
|
|
237
|
+
background: var(--vs-switch-checked-bg-color, var(--vs-switch-bg-checked));
|
|
238
|
+
border-color: var(--vs-switch-checked-bg-color, var(--vs-switch-bg-checked));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Variant - surface (filled background)
|
|
243
|
+
&__variant-surface {
|
|
244
|
+
background: #f0f1f3;
|
|
245
|
+
border: 1px solid transparent;
|
|
246
|
+
|
|
247
|
+
&.vs-switch--checked {
|
|
248
|
+
background: var(--vs-switch-checked-bg-color, var(--vs-switch-bg-checked));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
[data-theme='dark'] &,
|
|
252
|
+
.dark & {
|
|
253
|
+
background: #4a5568;
|
|
254
|
+
|
|
255
|
+
&.vs-switch--checked {
|
|
256
|
+
background: var(--vs-switch-checked-bg-color, var(--vs-switch-bg-checked));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Variant - soft (subtle background)
|
|
262
|
+
&__variant-soft {
|
|
263
|
+
background: rgba(31, 115, 183, 0.1);
|
|
264
|
+
border: 1px solid transparent;
|
|
265
|
+
|
|
266
|
+
&.vs-switch--checked {
|
|
267
|
+
background: var(--vs-switch-checked-bg-color, var(--vs-switch-bg-checked));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
[data-theme='dark'] &,
|
|
271
|
+
.dark & {
|
|
272
|
+
background: rgba(31, 115, 183, 0.2);
|
|
273
|
+
|
|
274
|
+
&.vs-switch--checked {
|
|
275
|
+
background: var(--vs-switch-checked-bg-color, var(--vs-switch-bg-checked));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Colors
|
|
281
|
+
&__color-primary.vs-switch--checked {
|
|
282
|
+
background: var(--vs-switch-checked-bg-color, #1f73b7);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
&__color-success.vs-switch--checked {
|
|
286
|
+
background: var(--vs-switch-checked-bg-color, #186146);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
&__color-danger.vs-switch--checked {
|
|
290
|
+
background: var(--vs-switch-checked-bg-color, #cc3340);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
&__color-warning.vs-switch--checked {
|
|
294
|
+
background: var(--vs-switch-checked-bg-color, #ffb057);
|
|
295
|
+
|
|
296
|
+
.vs-switch__thumb {
|
|
297
|
+
background: #703815;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
&__color-secondary.vs-switch--checked {
|
|
302
|
+
background: var(--vs-switch-checked-bg-color, #3a3a3a);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
&__color-indigo.vs-switch--checked {
|
|
306
|
+
background: var(--vs-switch-checked-bg-color, #4f46e5);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
&__color-cyan.vs-switch--checked {
|
|
310
|
+
background: var(--vs-switch-checked-bg-color, #06b6d4);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
&__color-orange.vs-switch--checked {
|
|
314
|
+
background: var(--vs-switch-checked-bg-color, #f97316);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
&__color-crimson.vs-switch--checked {
|
|
318
|
+
background: var(--vs-switch-checked-bg-color, #dc2626);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
&__color-gray.vs-switch--checked {
|
|
322
|
+
background: var(--vs-switch-checked-bg-color, #6b7280);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// High contrast mode
|
|
326
|
+
&--high-contrast {
|
|
327
|
+
&.vs-switch__color-primary.vs-switch--checked {
|
|
328
|
+
background: var(--vs-switch-checked-bg-color, #0d47a1);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
&.vs-switch__color-indigo.vs-switch--checked {
|
|
332
|
+
background: var(--vs-switch-checked-bg-color, #3730a3);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
&.vs-switch__color-cyan.vs-switch--checked {
|
|
336
|
+
background: var(--vs-switch-checked-bg-color, #0369a1);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
&.vs-switch__color-orange.vs-switch--checked {
|
|
340
|
+
background: var(--vs-switch-checked-bg-color, #c2410c);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
&.vs-switch__color-crimson.vs-switch--checked {
|
|
344
|
+
background: var(--vs-switch-checked-bg-color, #7f1d1d);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
&.vs-switch__color-gray.vs-switch--checked {
|
|
348
|
+
background: var(--vs-switch-checked-bg-color, #374151);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Thumb styling
|
|
353
|
+
&__thumb {
|
|
354
|
+
position: absolute;
|
|
355
|
+
left: 2px;
|
|
356
|
+
width: 20px;
|
|
357
|
+
height: 20px;
|
|
358
|
+
background: var(--vs-switch-thumb);
|
|
359
|
+
border-radius: 50%;
|
|
360
|
+
transition: transform 0.2s ease;
|
|
361
|
+
pointer-events: none;
|
|
362
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Checked state
|
|
366
|
+
&--checked {
|
|
367
|
+
background: var(--vs-switch-checked-bg-color, var(--vs-switch-bg-checked));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Disabled state
|
|
371
|
+
&--disabled {
|
|
372
|
+
opacity: 0.5;
|
|
373
|
+
cursor: not-allowed;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
</style>
|