-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
ButtonElement.vue
113 lines (105 loc) · 2.94 KB
/
ButtonElement.vue
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<template>
<component :is="elementLayout" ref="container">
<template #element>
<!-- Use `button` tag -->
<template v-if="buttonType === 'button'">
<!-- Use it as a component -->
<button
v-if="buttonLabel && isButtonLabelComponent"
v-bind="{
...button,
...aria,
}"
:tabindex="isDisabled || isLoading ? -1 : undefined"
:disabled="isDisabled"
:class="classes.button"
@click.prevent="handleClick"
>
<component :is="buttonLabel"/>
</button>
<!-- Use it as HTML -->
<button
v-else-if="buttonLabel"
v-bind="{
...button,
...aria,
}"
v-html="resolvedButtonLabel"
:tabindex="isDisabled || isLoading ? -1 : undefined"
:class="classes.button"
:disabled="isDisabled"
@click.prevent="handleClick"
></button>
<!-- Use it as slot -->
<button
v-else
v-bind="{
...button,
...aria,
}"
:tabindex="isDisabled || isLoading ? -1 : undefined"
:class="classes.button"
:disabled="isDisabled"
@click.prevent="handleClick"
><slot :el$="el$"><component :is="fieldSlots.default" :el$="el$"/></slot></button>
</template>
<!-- Use `anchor` tag -->
<template v-else>
<!-- Use it as a component -->
<a
v-if="buttonLabel && isButtonLabelComponent"
v-bind="{
...button,
...aria,
}"
:tabindex="isDisabled || isLoading ? -1 : undefined"
:class="classes.button"
@click="handleClick"
>
<component :is="buttonLabel"/>
</a>
<!-- Use it as HTML -->
<a
v-else-if="buttonLabel"
v-bind="{
...button,
...aria,
}"
v-html="resolvedButtonLabel"
:tabindex="isDisabled || isLoading ? -1 : undefined"
:class="classes.button"
@click="handleClick"
/>
<!-- Use it as slot -->
<a
v-else
v-bind="{
...button,
...aria,
}"
:tabindex="isDisabled || isLoading ? -1 : undefined"
:class="classes.button"
@click="handleClick"
><slot :el$="el$"><component :is="fieldSlots.default" :el$="el$"/></slot></a>
</template>
</template>
<!-- Default element slots -->
<template v-for="(component, slot) in elementSlots" #[slot]><slot :name="slot" :el$="el$"><component :is="component" :el$="el$"/></slot></template>
</component>
</template>
<script>
export default {
name: 'ButtonElement',
data() {
return {
merge: true,
defaultClasses: {
container: '',
button: '',
},
}
}
}
</script>
<style lang="scss">
</style>