@vue-interface/btn-activity 2.0.0-beta.1 → 2.0.0-beta.10

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,369 +0,0 @@
1
- <template>
2
- <btn
3
- :active="active"
4
- :block="block"
5
- :disabled="disabled"
6
- :size="size"
7
- :tag="tag"
8
- :variant="variant"
9
- :class="classes"
10
- @click="(e) => !disabled && $emit('click', e, this)">
11
- <slot>{{ label }}</slot>
12
- <activity-indicator v-bind="indicatorProps" />
13
- </btn>
14
- </template>
15
-
16
- <script>
17
- import { ActivityIndicator } from '@vue-interface/activity-indicator';
18
- import { Btn } from '@vue-interface/btn';
19
-
20
- const convertAnimationDelayToInt = function(delay) {
21
- const num = parseFloat(delay || 0, 10);
22
- const matches = delay && delay.match(/m?s/);
23
- const unit = matches ? matches[0] : false;
24
-
25
- let milliseconds;
26
-
27
- switch (unit) {
28
- case 's': // seconds
29
- milliseconds = num * 1000;
30
- break;
31
- case 'ms':
32
- default:
33
- milliseconds = num;
34
- break;
35
- }
36
-
37
- return milliseconds || 0;
38
- };
39
-
40
- const animated = function(el, callback) {
41
- const defaultView = (el.ownerDocument || document).defaultView;
42
-
43
- setTimeout(() => {
44
- callback.apply();
45
- }, convertAnimationDelayToInt(defaultView.getComputedStyle(el).animationDuration));
46
- };
47
-
48
- export default {
49
-
50
- name: 'BtnActivity',
51
-
52
- components: {
53
- ActivityIndicator,
54
- Btn
55
- },
56
-
57
- props: {
58
-
59
- /**
60
- * Make the button appear with the active state.
61
- *
62
- * @property {Boolean}
63
- */
64
- active: Boolean,
65
-
66
- /**
67
- * Show the activity indicator inside the button.
68
- *
69
- * @property {Boolean}
70
- */
71
- activity: Boolean,
72
-
73
- /**
74
- * Display the button as block width.
75
- *
76
- * @property {Boolean}
77
- */
78
- block: Boolean,
79
-
80
- /**
81
- * Disable the button.
82
- *
83
- * @property {Boolean}
84
- */
85
- disabled: Boolean,
86
-
87
- /**
88
- * The type of activity indicator inside the button.
89
- *
90
- * @property {String}
91
- */
92
- indicator: {
93
- type: [Object, String],
94
- default: 'spinner'
95
- },
96
-
97
- /**
98
- * The button label.
99
- *
100
- * @property {String}
101
- */
102
- label: String,
103
-
104
- /**
105
- * The orientation of the activity button inside the button.
106
- *
107
- * @property {String}
108
- */
109
- orientation: {
110
- type: String,
111
- default: 'right'
112
- },
113
-
114
- /**
115
- * The size of the button.
116
- *
117
- * @property {String}
118
- */
119
- size: {
120
- type: String,
121
- default: 'md'
122
- },
123
-
124
- /**
125
- * The HTML tag.
126
- *
127
- * @property {String}
128
- */
129
- tag: String,
130
-
131
- /**
132
- * The variant of the button.
133
- *
134
- * @property {String}
135
- */
136
- variant: {
137
- type: String,
138
- default: 'primary'
139
- }
140
- },
141
-
142
- data() {
143
- return {
144
- currentActivity: this.activity
145
- };
146
- },
147
-
148
- computed: {
149
-
150
- /**
151
- * An object of classes to append to the button.
152
- *
153
- * @return void
154
- */
155
- classes() {
156
- const classes = {
157
- 'disabled': this.disabled,
158
- 'active': this.active,
159
- 'btn-activity': this.activity
160
- };
161
-
162
- classes['btn-activity-' + this.orientation.replace('btn-activity-', '')] = !!this.orientation;
163
- classes['btn-activity-indicator-' + this.indicatorProps.type.replace('btn-activity-indicator-', '')] = !!this.indicatorProps.type;
164
-
165
- return classes;
166
- },
167
-
168
- indicatorProps() {
169
- return Object.assign({
170
- type: 'spinner'
171
- }, (typeof this.indicator === 'string' ? {
172
- type: this.indicator
173
- } : this.indicator) || {});
174
- }
175
-
176
- },
177
-
178
- watch: {
179
-
180
- activity(value) {
181
- if(value) {
182
- this.showActivity();
183
- }
184
- else {
185
- this.hideActivity();
186
- }
187
- }
188
-
189
- },
190
-
191
- mounted() {
192
- if(this.activity) {
193
- this.showActivity();
194
- }
195
- },
196
-
197
- methods: {
198
-
199
- /**
200
- * Disable the button.
201
- *
202
- * @return void
203
- */
204
- disable() {
205
- this.$el.disabled = true;
206
- this.$el.classList.add('disabled');
207
- },
208
-
209
- /**
210
- * Enable the button.
211
- *
212
- * @return void
213
- */
214
- enable() {
215
- this.$el.disabled = false;
216
- this.$el.classList.remove('disabled');
217
- },
218
-
219
- /**
220
- * Hide the activity indicator inside the button.
221
- *
222
- * @return void
223
- */
224
- hideActivity() {
225
- this.$el.classList.add('btn-hide-activity');
226
-
227
- animated(this.$el, () => {
228
- this.enable();
229
- this.currentActivity = false;
230
- this.$el.classList.remove('btn-activity', 'btn-hide-activity');
231
- this.$emit('hide-activity');
232
- });
233
- },
234
-
235
- /**
236
- * Show the activity indicator inside the button.
237
- *
238
- * @return void
239
- */
240
- showActivity() {
241
- this.currentActivity = true;
242
- this.disable();
243
-
244
- animated(this.$el, () => {
245
- this.$el.classList.add('btn-activity');
246
- this.$emit('show-activity');
247
- });
248
- },
249
-
250
- /**
251
- * Show the activity indicator inside the button.
252
- *
253
- * @return void
254
- */
255
- toggle() {
256
- if(!this.currentActivity) {
257
- this.showActivity();
258
- }
259
- else {
260
- this.hideActivity();
261
- }
262
- }
263
-
264
- }
265
-
266
- };
267
- </script>
268
-
269
- <style>
270
- @keyframes btn-activity-in {
271
- 0%, 100% {
272
- transform: scale(1);
273
- } 30% {
274
- transform: scale(.98);
275
- }
276
- }
277
-
278
- @keyframes btn-activity-out {
279
- 0%, 100% {
280
- transform: scale(1);
281
- } 70% {
282
- transform: scale(.98);
283
- }
284
- }
285
-
286
- .btn-activity-top,
287
- .btn.btn-activity-top,
288
- .btn-activity-bottom,
289
- .btn.btn-activity-bottom,
290
- .btn-activity-left,
291
- .btn.btn-activity-left,
292
- .btn-activity-right,
293
- .btn.btn-activity-right {
294
- display: inline-flex;
295
- position: relative;
296
- transition: all calc(333ms / 2) ease-in;
297
- }
298
-
299
- .btn-activity-top .activity-indicator,
300
- .btn-activity-bottom .activity-indicator,
301
- .btn-activity-left .activity-indicator,
302
- .btn-activity-right .activity-indicator {
303
- opacity: 0;
304
- position: absolute;
305
- visibility: hidden;
306
- transition: opacity 333ms ease-in;
307
- }
308
-
309
- .btn-activity-top,
310
- .btn-activity-bottom {
311
- flex-direction: column;
312
- align-items: center;
313
- }
314
-
315
- .btn-activity-top .activity-indicator,
316
- .btn-activity-bottom .activity-indicator {
317
- margin-left: auto;
318
- margin-right: auto;
319
- }
320
-
321
- .btn-activity-top {
322
- flex-direction: column-reverse;
323
- }
324
-
325
- .btn-activity-top .activity-indicator {
326
- padding-bottom: 1em;
327
- }
328
-
329
- .btn-activity-bottom .activity-indicator {
330
- padding-top: 1em;
331
- }
332
-
333
- .btn-activity-left,
334
- .btn-activity-right {
335
- align-items: center;
336
- justify-content: center;
337
- }
338
-
339
- .btn-activity-left {
340
- flex-direction: row-reverse;
341
- }
342
-
343
- .btn-activity-left .activity-indicator {
344
- padding-right: 1em;
345
- }
346
-
347
- .btn-activity-right .activity-indicator {
348
- padding-left: 1em;
349
- }
350
-
351
- .btn-activity:not(.btn-link) {
352
- animation: btn-activity-in 333ms;
353
- }
354
-
355
- .btn-hide-activity:not(.btn-link) {
356
- animation: btn-activity-out 333ms;
357
- }
358
-
359
- .btn-activity.btn-hide-activity .activity-indicator {
360
- opacity: 0;
361
- }
362
-
363
- .btn-activity .activity-indicator {
364
- opacity: 1;
365
- visibility: visible;
366
- position: relative;
367
- font-size: .55em;
368
- }
369
- </style>