@vue-interface/btn-activity 4.0.1 → 4.0.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/package.json +4 -3
- package/src/BtnActivity.vue +102 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue-interface/btn-activity",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "A Vue activity button component.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/btn-activity.umd.cjs",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"homepage": "https://vue-interface.github.io/packages/btn-activity",
|
|
36
36
|
"readme": "README.md",
|
|
37
37
|
"files": [
|
|
38
|
+
"src",
|
|
38
39
|
"dist",
|
|
39
40
|
"index.css",
|
|
40
41
|
"README.md",
|
|
@@ -42,8 +43,8 @@
|
|
|
42
43
|
],
|
|
43
44
|
"peerDependencies": {
|
|
44
45
|
"vue": "^3.3.4",
|
|
45
|
-
"@vue-interface/activity-indicator": "3.0.
|
|
46
|
-
"@vue-interface/btn": "5.0.
|
|
46
|
+
"@vue-interface/activity-indicator": "3.0.3",
|
|
47
|
+
"@vue-interface/btn": "5.0.3"
|
|
47
48
|
},
|
|
48
49
|
"scripts": {
|
|
49
50
|
"dev": "vite",
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { ActivityIndicator } from '@vue-interface/activity-indicator';
|
|
3
|
+
import { ref, watch, watchEffect, type Component, type Ref } from 'vue';
|
|
4
|
+
import { ActivityIndicatorSize } from '../../activity-indicator/src/ActivityIndicator.vue';
|
|
5
|
+
|
|
6
|
+
export type BtnActivityProps = {
|
|
7
|
+
activity?: boolean;
|
|
8
|
+
indicator: Component;
|
|
9
|
+
indicatorSize?: ActivityIndicatorSize;
|
|
10
|
+
label?: string;
|
|
11
|
+
orientation?: 'top' | 'bottom' | 'left' | 'right';
|
|
12
|
+
variant?: string;
|
|
13
|
+
size?: string;
|
|
14
|
+
block?: boolean;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const props = withDefaults(defineProps<BtnActivityProps>(), {
|
|
19
|
+
indicatorSize: 'xs',
|
|
20
|
+
label: undefined,
|
|
21
|
+
orientation: 'right',
|
|
22
|
+
variant: 'btn-primary',
|
|
23
|
+
size: 'btn-md'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export type BtnActivityContext = {
|
|
27
|
+
status: Ref<boolean>;
|
|
28
|
+
toggle: () => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const emit = defineEmits<{
|
|
32
|
+
click: [event: MouseEvent, context: BtnActivityContext];
|
|
33
|
+
'hide-activity': [];
|
|
34
|
+
'show-activity': [];
|
|
35
|
+
}>();
|
|
36
|
+
|
|
37
|
+
const status = ref(props.activity);
|
|
38
|
+
|
|
39
|
+
watchEffect(() => {
|
|
40
|
+
status.value = props.activity;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
watch(status, (value) => {
|
|
44
|
+
if(value) {
|
|
45
|
+
emit('show-activity');
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
emit('hide-activity');
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function toggle() {
|
|
53
|
+
status.value = !status.value;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const context = {
|
|
57
|
+
status,
|
|
58
|
+
toggle,
|
|
59
|
+
};
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<template>
|
|
63
|
+
<button
|
|
64
|
+
type="button"
|
|
65
|
+
:disabled="disabled"
|
|
66
|
+
:class="[
|
|
67
|
+
'btn',
|
|
68
|
+
variant,
|
|
69
|
+
size,
|
|
70
|
+
{
|
|
71
|
+
'w-full': block,
|
|
72
|
+
'gap-1': ['xs', 'sm'].includes(indicatorSize),
|
|
73
|
+
'gap-2': ['md', 'lg', 'xl'].includes(indicatorSize),
|
|
74
|
+
'flex-col-reverse': orientation === 'top',
|
|
75
|
+
'flex-col': orientation === 'bottom',
|
|
76
|
+
'flex-row-reverse': orientation === 'left',
|
|
77
|
+
'inline-flex items-center justify-center': true,
|
|
78
|
+
'opacity-50 cursor-not-allowed': disabled,
|
|
79
|
+
}
|
|
80
|
+
]"
|
|
81
|
+
@click="emit('click', $event, context)">
|
|
82
|
+
<slot>{{ label }}</slot>
|
|
83
|
+
<Transition
|
|
84
|
+
enter-active-class="transition-all ease-out duration-250"
|
|
85
|
+
enter-from-class="opacity-0"
|
|
86
|
+
enter-to-class="opacity-100"
|
|
87
|
+
leave-active-class="transition-all ease-in duration-250"
|
|
88
|
+
leave-from-class="opacity-100"
|
|
89
|
+
leave-to-class="opacity-0">
|
|
90
|
+
<ActivityIndicator
|
|
91
|
+
v-if="status"
|
|
92
|
+
:type="indicator"
|
|
93
|
+
:size="indicatorSize"
|
|
94
|
+
:class="{
|
|
95
|
+
'pt-1': orientation === 'top',
|
|
96
|
+
'pb-1': orientation === 'bottom',
|
|
97
|
+
'pr-1': orientation === 'left',
|
|
98
|
+
'pl-1': orientation === 'right',
|
|
99
|
+
}" />
|
|
100
|
+
</Transition>
|
|
101
|
+
</button>
|
|
102
|
+
</template>
|