@proj-airi/ui 0.8.0-beta.5 → 0.8.0-beta.6
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
CHANGED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, watch } from 'vue'
|
|
3
|
+
|
|
4
|
+
import Button from './Button.vue'
|
|
5
|
+
|
|
6
|
+
type ButtonVariant = 'primary' | 'secondary' | 'secondary-muted' | 'danger' | 'caution'
|
|
7
|
+
type ButtonSize = 'sm' | 'md' | 'lg'
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(defineProps<{
|
|
10
|
+
variant?: ButtonVariant
|
|
11
|
+
cancelVariant?: ButtonVariant
|
|
12
|
+
size?: ButtonSize
|
|
13
|
+
block?: boolean
|
|
14
|
+
disabled?: boolean
|
|
15
|
+
loading?: boolean
|
|
16
|
+
}>(), {
|
|
17
|
+
variant: 'danger',
|
|
18
|
+
cancelVariant: 'secondary',
|
|
19
|
+
size: 'md',
|
|
20
|
+
block: false,
|
|
21
|
+
disabled: false,
|
|
22
|
+
loading: false,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const emit = defineEmits<{
|
|
26
|
+
(event: 'confirm'): void
|
|
27
|
+
(event: 'cancel'): void
|
|
28
|
+
}>()
|
|
29
|
+
|
|
30
|
+
const slots = defineSlots<{
|
|
31
|
+
'default': (props: Record<string, unknown>) => unknown
|
|
32
|
+
'confirm': (props: Record<string, unknown>) => unknown
|
|
33
|
+
'cancel': (props: Record<string, unknown>) => unknown
|
|
34
|
+
'cancel-botton-icon': (props: Record<string, unknown>) => unknown
|
|
35
|
+
}>()
|
|
36
|
+
|
|
37
|
+
const confirming = ref(false)
|
|
38
|
+
|
|
39
|
+
const wrapperClasses = computed(() => [
|
|
40
|
+
'inline-flex flex-col gap-2',
|
|
41
|
+
props.block ? 'w-full' : '',
|
|
42
|
+
])
|
|
43
|
+
|
|
44
|
+
watch(() => props.disabled, (disabled) => {
|
|
45
|
+
if (disabled)
|
|
46
|
+
confirming.value = false
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
function handlePrimaryClick() {
|
|
50
|
+
if (!confirming.value) {
|
|
51
|
+
confirming.value = true
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
emit('confirm')
|
|
56
|
+
confirming.value = false
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function handleCancel() {
|
|
60
|
+
confirming.value = false
|
|
61
|
+
emit('cancel')
|
|
62
|
+
}
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<template>
|
|
66
|
+
<div :class="wrapperClasses">
|
|
67
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
68
|
+
<Transition name="double-check-slide">
|
|
69
|
+
<Button
|
|
70
|
+
v-if="confirming"
|
|
71
|
+
key="cancel"
|
|
72
|
+
:variant="cancelVariant"
|
|
73
|
+
:size="size"
|
|
74
|
+
:block="block"
|
|
75
|
+
class="whitespace-nowrap"
|
|
76
|
+
@click="handleCancel"
|
|
77
|
+
>
|
|
78
|
+
<div class="flex items-center gap-2">
|
|
79
|
+
<slot
|
|
80
|
+
v-if="slots['cancel-botton-icon']"
|
|
81
|
+
name="cancel-botton-icon"
|
|
82
|
+
/>
|
|
83
|
+
<span><slot name="cancel">Cancel</slot></span>
|
|
84
|
+
</div>
|
|
85
|
+
</Button>
|
|
86
|
+
</Transition>
|
|
87
|
+
|
|
88
|
+
<Button
|
|
89
|
+
:variant="variant"
|
|
90
|
+
:size="size"
|
|
91
|
+
:block="block"
|
|
92
|
+
:disabled="disabled"
|
|
93
|
+
:loading="loading"
|
|
94
|
+
:class="[
|
|
95
|
+
'double-check-primary whitespace-nowrap',
|
|
96
|
+
'transition-width duration-150 ease-in-out',
|
|
97
|
+
confirming ? 'double-check-primary--confirming' : 'double-check-primary--default',
|
|
98
|
+
]"
|
|
99
|
+
@click="handlePrimaryClick"
|
|
100
|
+
>
|
|
101
|
+
<span v-if="!confirming">
|
|
102
|
+
<slot />
|
|
103
|
+
</span>
|
|
104
|
+
<span v-else>
|
|
105
|
+
<slot name="confirm">
|
|
106
|
+
<slot />
|
|
107
|
+
</slot>
|
|
108
|
+
</span>
|
|
109
|
+
</Button>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
</template>
|
|
113
|
+
|
|
114
|
+
<style scoped>
|
|
115
|
+
.double-check-slide-enter-active,
|
|
116
|
+
.double-check-slide-leave-active {
|
|
117
|
+
transition: opacity 160ms ease, transform 160ms ease;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.double-check-slide-enter-from,
|
|
121
|
+
.double-check-slide-leave-to {
|
|
122
|
+
opacity: 0;
|
|
123
|
+
transform: translateX(-10px);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.double-check-primary {
|
|
127
|
+
transition: min-width 180ms ease, padding 180ms ease;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.double-check-primary--default {
|
|
131
|
+
min-width: 7rem;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.double-check-primary--confirming {
|
|
135
|
+
min-width: 9rem;
|
|
136
|
+
}
|
|
137
|
+
</style>
|