vue-toggles 1.1.4 → 2.0.0

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.
@@ -1,361 +0,0 @@
1
- //
2
- //
3
- //
4
- //
5
- //
6
- //
7
- //
8
- //
9
- //
10
- //
11
- //
12
- //
13
- //
14
- //
15
- //
16
- //
17
- //
18
- //
19
- //
20
- //
21
- //
22
- //
23
- //
24
- //
25
-
26
- var script = {
27
- name: 'VueToggles',
28
- props: {
29
- value: {
30
- type: Boolean,
31
- default: false,
32
- },
33
- disabled: {
34
- type: Boolean,
35
- default: false,
36
- },
37
- reverse: {
38
- type: Boolean,
39
- default: false,
40
- },
41
- checkedText: {
42
- type: String,
43
- default: null,
44
- },
45
- uncheckedText: {
46
- type: String,
47
- default: null,
48
- },
49
- width: {
50
- type: [Number, String],
51
- default: 75,
52
- },
53
- height: {
54
- type: [Number, String],
55
- default: 25,
56
- },
57
- uncheckedBg: {
58
- type: String,
59
- default: '#939393',
60
- },
61
- checkedBg: {
62
- type: String,
63
- default: '#5850ec',
64
- },
65
- dotColor: {
66
- type: String,
67
- default: '#fff',
68
- },
69
- fontSize: {
70
- type: [Number, String],
71
- default: '12',
72
- },
73
- checkedColor: {
74
- type: String,
75
- default: '#fff',
76
- },
77
- uncheckedColor: {
78
- type: String,
79
- default: '#fff',
80
- },
81
- fontWeight: {
82
- type: [Number, String],
83
- default: 'normal',
84
- },
85
- },
86
- computed: {
87
- bgStyle: function bgStyle() {
88
- var styles = {
89
- width: ((this.width) + "px"),
90
- height: ((this.height) + "px"),
91
- background: this.value ? this.checkedBg : this.uncheckedBg,
92
- opacity: this.disabled ? '0.5' : '1',
93
- cursor: !this.disabled ? 'pointer' : 'not-allowed',
94
- };
95
-
96
- return styles;
97
- },
98
- dotStyle: function dotStyle() {
99
- var styles = {
100
- background: this.dotColor,
101
- width: ((this.height - 8) + "px"),
102
- height: ((this.height - 8) + "px"),
103
- 'min-width': ((this.height - 8) + "px"),
104
- 'min-height': ((this.height - 8) + "px"),
105
- 'margin-left': this.value ? ((this.width - (this.height - 3)) + "px") : '5px',
106
- };
107
-
108
- if ((!this.value && this.reverse) || (this.value && !this.reverse)) {
109
- styles.marginLeft = (this.width - (this.height - 3)) + "px";
110
- } else if ((this.value && this.reverse) || (!this.value && !this.reverse)) {
111
- styles.marginLeft = '5px';
112
- }
113
-
114
- return styles;
115
- },
116
- textStyle: function textStyle() {
117
- var styles = {
118
- 'font-weight': this.fontWeight,
119
- 'font-size': ((this.fontSize) + "px"),
120
- color: this.value && !this.disabled ? this.checkedColor : this.uncheckedColor,
121
- right: this.value ? ((this.height - 3) + "px") : 'auto',
122
- left: this.value ? 'auto' : ((this.height - 3) + "px"),
123
- };
124
-
125
- if (!this.value && this.reverse) {
126
- styles.right = (this.height - 3) + "px";
127
- styles.left = 'auto';
128
- } else if (this.value && this.reverse) {
129
- styles.left = (this.height - 3) + "px";
130
- styles.right = 'auto';
131
- }
132
-
133
- return styles;
134
- },
135
- },
136
- };
137
-
138
- function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
139
- if (typeof shadowMode !== 'boolean') {
140
- createInjectorSSR = createInjector;
141
- createInjector = shadowMode;
142
- shadowMode = false;
143
- }
144
- // Vue.extend constructor export interop.
145
- var options = typeof script === 'function' ? script.options : script;
146
- // render functions
147
- if (template && template.render) {
148
- options.render = template.render;
149
- options.staticRenderFns = template.staticRenderFns;
150
- options._compiled = true;
151
- // functional template
152
- if (isFunctionalTemplate) {
153
- options.functional = true;
154
- }
155
- }
156
- // scopedId
157
- if (scopeId) {
158
- options._scopeId = scopeId;
159
- }
160
- var hook;
161
- if (moduleIdentifier) {
162
- // server build
163
- hook = function (context) {
164
- // 2.3 injection
165
- context =
166
- context || // cached call
167
- (this.$vnode && this.$vnode.ssrContext) || // stateful
168
- (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext); // functional
169
- // 2.2 with runInNewContext: true
170
- if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
171
- context = __VUE_SSR_CONTEXT__;
172
- }
173
- // inject component styles
174
- if (style) {
175
- style.call(this, createInjectorSSR(context));
176
- }
177
- // register component module identifier for async chunk inference
178
- if (context && context._registeredComponents) {
179
- context._registeredComponents.add(moduleIdentifier);
180
- }
181
- };
182
- // used by ssr in case component is cached and beforeCreate
183
- // never gets called
184
- options._ssrRegister = hook;
185
- }
186
- else if (style) {
187
- hook = shadowMode
188
- ? function (context) {
189
- style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));
190
- }
191
- : function (context) {
192
- style.call(this, createInjector(context));
193
- };
194
- }
195
- if (hook) {
196
- if (options.functional) {
197
- // register for functional component in vue file
198
- var originalRender = options.render;
199
- options.render = function renderWithStyleInjection(h, context) {
200
- hook.call(context);
201
- return originalRender(h, context);
202
- };
203
- }
204
- else {
205
- // inject component registration as beforeCreate hook
206
- var existing = options.beforeCreate;
207
- options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
208
- }
209
- }
210
- return script;
211
- }
212
-
213
- /* script */
214
- var __vue_script__ = script;
215
- /* template */
216
- var __vue_render__ = function() {
217
- var _vm = this;
218
- var _h = _vm.$createElement;
219
- var _c = _vm._self._c || _h;
220
- return _c(
221
- "span",
222
- {
223
- staticClass: "vue-toggles",
224
- style: _vm.bgStyle,
225
- attrs: {
226
- role: "switch",
227
- tabindex: "0",
228
- "aria-checked": _vm.value ? "true" : "false",
229
- "aria-readonly": _vm.disabled ? "true" : "false"
230
- },
231
- on: {
232
- click: function($event) {
233
- !_vm.disabled ? _vm.$emit("click", _vm.value) : null;
234
- },
235
- keyup: [
236
- function($event) {
237
- if (
238
- !$event.type.indexOf("key") &&
239
- _vm._k($event.keyCode, "enter", 13, $event.key, "Enter")
240
- ) {
241
- return null
242
- }
243
- $event.preventDefault();
244
- !_vm.disabled ? _vm.$emit("click", _vm.value) : null;
245
- },
246
- function($event) {
247
- if (
248
- !$event.type.indexOf("key") &&
249
- _vm._k($event.keyCode, "space", 32, $event.key, [" ", "Spacebar"])
250
- ) {
251
- return null
252
- }
253
- $event.preventDefault();
254
- !_vm.disabled ? _vm.$emit("click", _vm.value) : null;
255
- }
256
- ]
257
- }
258
- },
259
- [
260
- _c(
261
- "span",
262
- {
263
- staticClass: "dot",
264
- style: _vm.dotStyle,
265
- attrs: { "aria-hidden": "true" }
266
- },
267
- [
268
- _c(
269
- "span",
270
- {
271
- directives: [
272
- {
273
- name: "show",
274
- rawName: "v-show",
275
- value: _vm.checkedText && _vm.value,
276
- expression: "checkedText && value"
277
- }
278
- ],
279
- staticClass: "text",
280
- style: _vm.textStyle
281
- },
282
- [_vm._v("\n " + _vm._s(_vm.checkedText) + "\n ")]
283
- ),
284
- _vm._v(" "),
285
- _c(
286
- "span",
287
- {
288
- directives: [
289
- {
290
- name: "show",
291
- rawName: "v-show",
292
- value: _vm.uncheckedText && !_vm.value,
293
- expression: "uncheckedText && !value"
294
- }
295
- ],
296
- staticClass: "text",
297
- style: _vm.textStyle
298
- },
299
- [_vm._v("\n " + _vm._s(_vm.uncheckedText) + "\n ")]
300
- )
301
- ]
302
- )
303
- ]
304
- )
305
- };
306
- var __vue_staticRenderFns__ = [];
307
- __vue_render__._withStripped = true;
308
-
309
- /* style */
310
- var __vue_inject_styles__ = undefined;
311
- /* scoped */
312
- var __vue_scope_id__ = undefined;
313
- /* module identifier */
314
- var __vue_module_identifier__ = undefined;
315
- /* functional template */
316
- var __vue_is_functional_template__ = false;
317
- /* style inject */
318
-
319
- /* style inject SSR */
320
-
321
- /* style inject shadow dom */
322
-
323
-
324
-
325
- var __vue_component__ = /*#__PURE__*/normalizeComponent(
326
- { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
327
- __vue_inject_styles__,
328
- __vue_script__,
329
- __vue_scope_id__,
330
- __vue_is_functional_template__,
331
- __vue_module_identifier__,
332
- false,
333
- undefined,
334
- undefined,
335
- undefined
336
- );
337
-
338
- // Declare install function executed by Vue.use()
339
- function install(Vue) {
340
- if (install.installed) { return; }
341
- install.installed = true;
342
- Vue.component('VueToggles', __vue_component__);
343
- }
344
-
345
- // Create module definition for Vue.use()
346
- var plugin = {
347
- install: install,
348
- };
349
-
350
- // Auto-install when vue is found (eg. in browser via <script> tag)
351
- var GlobalVue = null;
352
- if (typeof window !== 'undefined') {
353
- GlobalVue = window.Vue;
354
- } else if (typeof global !== 'undefined') {
355
- GlobalVue = global.Vue;
356
- }
357
- if (GlobalVue) {
358
- GlobalVue.use(plugin);
359
- }
360
-
361
- export { __vue_component__ as default, install };
@@ -1,183 +0,0 @@
1
- <template>
2
- <span
3
- class="vue-toggles"
4
- :style="bgStyle"
5
- role="switch"
6
- tabindex="0"
7
- :aria-checked="value ? 'true' : 'false'"
8
- :aria-readonly="disabled ? 'true' : 'false'"
9
- @click="!disabled ? $emit('click', value) : null"
10
- @keyup.enter.prevent="!disabled ? $emit('click', value) : null"
11
- @keyup.space.prevent="!disabled ? $emit('click', value) : null"
12
- >
13
- <span aria-hidden="true" :style="dotStyle" class="dot">
14
- <span v-show="checkedText && value" :style="textStyle" class="text">
15
- {{ checkedText }}
16
- </span>
17
-
18
- <span v-show="uncheckedText && !value" :style="textStyle" class="text">
19
- {{ uncheckedText }}
20
- </span>
21
- </span>
22
- </span>
23
- </template>
24
-
25
- <script>
26
- export default {
27
- name: 'VueToggles',
28
- props: {
29
- value: {
30
- type: Boolean,
31
- default: false,
32
- },
33
- disabled: {
34
- type: Boolean,
35
- default: false,
36
- },
37
- reverse: {
38
- type: Boolean,
39
- default: false,
40
- },
41
- checkedText: {
42
- type: String,
43
- default: null,
44
- },
45
- uncheckedText: {
46
- type: String,
47
- default: null,
48
- },
49
- width: {
50
- type: [Number, String],
51
- default: 75,
52
- },
53
- height: {
54
- type: [Number, String],
55
- default: 25,
56
- },
57
- uncheckedBg: {
58
- type: String,
59
- default: '#939393',
60
- },
61
- checkedBg: {
62
- type: String,
63
- default: '#5850ec',
64
- },
65
- dotColor: {
66
- type: String,
67
- default: '#fff',
68
- },
69
- fontSize: {
70
- type: [Number, String],
71
- default: '12',
72
- },
73
- checkedColor: {
74
- type: String,
75
- default: '#fff',
76
- },
77
- uncheckedColor: {
78
- type: String,
79
- default: '#fff',
80
- },
81
- fontWeight: {
82
- type: [Number, String],
83
- default: 'normal',
84
- },
85
- },
86
- computed: {
87
- bgStyle() {
88
- const styles = {
89
- width: `${this.width}px`,
90
- height: `${this.height}px`,
91
- background: this.value ? this.checkedBg : this.uncheckedBg,
92
- opacity: this.disabled ? '0.5' : '1',
93
- cursor: !this.disabled ? 'pointer' : 'not-allowed',
94
- };
95
-
96
- return styles;
97
- },
98
- dotStyle() {
99
- const styles = {
100
- background: this.dotColor,
101
- width: `${this.height - 8}px`,
102
- height: `${this.height - 8}px`,
103
- 'min-width': `${this.height - 8}px`,
104
- 'min-height': `${this.height - 8}px`,
105
- 'margin-left': this.value ? `${this.width - (this.height - 3)}px` : '5px',
106
- };
107
-
108
- if ((!this.value && this.reverse) || (this.value && !this.reverse)) {
109
- styles.marginLeft = `${this.width - (this.height - 3)}px`;
110
- } else if ((this.value && this.reverse) || (!this.value && !this.reverse)) {
111
- styles.marginLeft = '5px';
112
- }
113
-
114
- return styles;
115
- },
116
- textStyle() {
117
- const styles = {
118
- 'font-weight': this.fontWeight,
119
- 'font-size': `${this.fontSize}px`,
120
- color: this.value && !this.disabled ? this.checkedColor : this.uncheckedColor,
121
- right: this.value ? `${this.height - 3}px` : 'auto',
122
- left: this.value ? 'auto' : `${this.height - 3}px`,
123
- };
124
-
125
- if (!this.value && this.reverse) {
126
- styles.right = `${this.height - 3}px`;
127
- styles.left = 'auto';
128
- } else if (this.value && this.reverse) {
129
- styles.left = `${this.height - 3}px`;
130
- styles.right = 'auto';
131
- }
132
-
133
- return styles;
134
- },
135
- },
136
- };
137
- </script>
138
-
139
- <style>
140
- .vue-toggles {
141
- display: flex;
142
- align-items: center;
143
- border-radius: 9999px;
144
- overflow: hidden;
145
- transition: background-color ease 0.2s, width ease 0.2s, height ease 0.2s;
146
- }
147
-
148
- .vue-toggles .dot {
149
- position: relative;
150
- display: flex;
151
- align-items: center;
152
- border-radius: 9999px;
153
- box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
154
- transition: margin ease 0.2s;
155
- }
156
-
157
- .vue-toggles .text {
158
- position: absolute;
159
- font-family: inherit;
160
- user-select: none;
161
- white-space: nowrap;
162
- }
163
-
164
- @media all and (-ms-high-contrast: none) {
165
- .vue-toggles .text {
166
- /* IE11 fix */
167
- top: 50%;
168
- transform: translateY(-50%);
169
- }
170
- }
171
-
172
- @media (prefers-reduced-motion) {
173
- /* disable animations if user have a reduced motion setting */
174
- .vue-toggles,
175
- .vue-toggles *,
176
- .vue-toggles *::before,
177
- .vue-toggles *::after {
178
- animation: none !important;
179
- transition: none !important;
180
- transition-duration: none !important;
181
- }
182
- }
183
- </style>
package/src/index.d.ts DELETED
@@ -1 +0,0 @@
1
- declare module 'vue-toggles';
package/src/wrapper.js DELETED
@@ -1,27 +0,0 @@
1
- import VueToggles from './VueToggles.vue';
2
-
3
- // Declare install function executed by Vue.use()
4
- export function install(Vue) {
5
- if (install.installed) return;
6
- install.installed = true;
7
- Vue.component('VueToggles', VueToggles);
8
- }
9
-
10
- // Create module definition for Vue.use()
11
- const plugin = {
12
- install,
13
- };
14
-
15
- // Auto-install when vue is found (eg. in browser via <script> tag)
16
- let GlobalVue = null;
17
- if (typeof window !== 'undefined') {
18
- GlobalVue = window.Vue;
19
- } else if (typeof global !== 'undefined') {
20
- GlobalVue = global.Vue;
21
- }
22
- if (GlobalVue) {
23
- GlobalVue.use(plugin);
24
- }
25
-
26
- // To allow use as module (npm/webpack/etc.) export component
27
- export default VueToggles;