-
Notifications
You must be signed in to change notification settings - Fork 2
/
LuiButton.vue
104 lines (101 loc) · 2.72 KB
/
LuiButton.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
<script lang="ts">
export default {
name: 'LuiButton',
inheritAttrs: false
}
</script>
<script setup lang="ts">
import { toRefs, useSlots } from 'vue'
import { useButtonClasses } from './composables'
import type { PropType } from 'vue'
import type { ButtonTag } from './button-types'
import type { Variant, Filter, Rounded, Block, Color, Size } from '@/globals/types'
import type { TwClassInterface } from '@/globals/interfaces'
const props = defineProps({
tag: {
type: String as PropType<ButtonTag>,
default: 'button'
},
variant: {
type: String as PropType<Variant>,
default: 'solid'
},
color: {
type: String as PropType<Color>,
default: 'primary'
},
filter: {
type: String as PropType<Filter>,
default: 'none'
},
size: {
type: String as PropType<Size>,
default: 'md'
},
rounded: {
type: [Boolean, String] as PropType<Rounded>,
default: false
},
block: {
type: Boolean as PropType<Block>,
default: false
}
// loading: {
// type: Boolean as PropType<Loading>,
// default: false,
// },
// loaderPosition: {
// type: String as PropType<loaderPosition>,
// default: "right",
// },
})
const { buttonClasses, computedIconSize } = useButtonClasses(toRefs(props))
const slots = useSlots()
function dynamicSlotClasses() {
// We move this classes from composable, because of slots reactivity issue
// more details: https://github.com/LUI-UI/lui-vue/issues/33
const hasAnyIcon = slots.prepend || slots.append || slots.icon
const classes: TwClassInterface = {
display: {
flex: hasAnyIcon,
'inline-block': !hasAnyIcon && props.tag !== 'button'
},
alignItems: {
'items-center': hasAnyIcon
},
justifyContent: {
'justify-center': hasAnyIcon
},
space:
!!slots.prepend || !!slots.append
? {
'space-x-1': props.size === 'xs' || props.size === 'sm',
'space-x-1.5': props.size === 'md',
'space-x-2': props.size === 'lg' || props.size === 'xl'
}
: ''
}
return Object.values({ ...classes })
}
</script>
<template>
<component
:is="tag"
v-bind="$attrs"
:class="[buttonClasses, dynamicSlotClasses()]"
class="lui-button"
>
<span v-if="!!slots.icon" :class="computedIconSize" class="leading-none flex items-center">
<slot name="icon" />
</span>
<template v-else>
<span v-if="!!slots.prepend" :class="computedIconSize" class="leading-none flex items-center">
<slot name="prepend" />
</span>
<span><slot></slot></span>
<span v-if="!!slots.append" :class="computedIconSize" class="leading-none flex items-center">
<slot name="append" />
</span>
</template>
</component>
</template>