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