@imaginario27/air-ui-ds 1.2.4 → 1.2.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.
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- Overlay -->
|
|
3
|
+
<Transition
|
|
4
|
+
enter-active-class="transition-opacity duration-200 ease-out"
|
|
5
|
+
enter-from-class="opacity-0"
|
|
6
|
+
enter-to-class="opacity-100"
|
|
7
|
+
leave-active-class="transition-opacity duration-200 ease-in"
|
|
8
|
+
leave-from-class="opacity-100"
|
|
9
|
+
leave-to-class="opacity-0"
|
|
10
|
+
>
|
|
11
|
+
<div
|
|
12
|
+
v-if="isOpen && hasOverlay"
|
|
13
|
+
:class="[
|
|
14
|
+
'fixed',
|
|
15
|
+
'inset-0',
|
|
16
|
+
'bg-background-overlay',
|
|
17
|
+
'backdrop-blur-sm',
|
|
18
|
+
'z-[10000]',
|
|
19
|
+
overlayClass,
|
|
20
|
+
]"
|
|
21
|
+
@click="closeOnOverlayClick ? close() : null"
|
|
22
|
+
/>
|
|
23
|
+
</Transition>
|
|
24
|
+
|
|
25
|
+
<!-- Drawer -->
|
|
26
|
+
<Transition
|
|
27
|
+
:enter-active-class="transitionClasses.enterActive"
|
|
28
|
+
:enter-from-class="transitionClasses.enterFrom"
|
|
29
|
+
:enter-to-class="transitionClasses.enterTo"
|
|
30
|
+
:leave-active-class="transitionClasses.leaveActive"
|
|
31
|
+
:leave-from-class="transitionClasses.leaveFrom"
|
|
32
|
+
:leave-to-class="transitionClasses.leaveTo"
|
|
33
|
+
>
|
|
34
|
+
<aside
|
|
35
|
+
v-if="isOpen"
|
|
36
|
+
:class="[
|
|
37
|
+
'fixed',
|
|
38
|
+
'bg-background-container-surface',
|
|
39
|
+
'shadow-xl',
|
|
40
|
+
'z-[10000]',
|
|
41
|
+
'p-4',
|
|
42
|
+
'flex',
|
|
43
|
+
'flex-col',
|
|
44
|
+
'gap-4',
|
|
45
|
+
positionClasses,
|
|
46
|
+
sizeClasses,
|
|
47
|
+
drawerClass,
|
|
48
|
+
borderClass,
|
|
49
|
+
]"
|
|
50
|
+
:style="drawerInlineStyle"
|
|
51
|
+
>
|
|
52
|
+
<!-- Header -->
|
|
53
|
+
<div
|
|
54
|
+
v-if="hasHeader"
|
|
55
|
+
:class="[
|
|
56
|
+
'flex',
|
|
57
|
+
'items-center',
|
|
58
|
+
'justify-between',
|
|
59
|
+
'gap-3',
|
|
60
|
+
headerClass,
|
|
61
|
+
]"
|
|
62
|
+
>
|
|
63
|
+
<component
|
|
64
|
+
:is="titleHeadingTag"
|
|
65
|
+
:class="['text-lg', 'font-semibold', titleClass]"
|
|
66
|
+
>
|
|
67
|
+
{{ title }}
|
|
68
|
+
</component>
|
|
69
|
+
|
|
70
|
+
<ActionIconButton
|
|
71
|
+
v-if="hasCloseButton"
|
|
72
|
+
:icon="buttonCloseIcon"
|
|
73
|
+
:styleType="ButtonStyleType.NEUTRAL_TRANSPARENT"
|
|
74
|
+
@click="close"
|
|
75
|
+
/>
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
<!-- Content -->
|
|
79
|
+
<div :class="['flex-1', 'overflow-y-auto', drawerContentClass]">
|
|
80
|
+
<slot />
|
|
81
|
+
</div>
|
|
82
|
+
</aside>
|
|
83
|
+
</Transition>
|
|
84
|
+
</template>
|
|
85
|
+
|
|
86
|
+
<script setup lang="ts">
|
|
87
|
+
// Props
|
|
88
|
+
const props = defineProps({
|
|
89
|
+
modelValue: {
|
|
90
|
+
type: Boolean as PropType<boolean>,
|
|
91
|
+
required: true,
|
|
92
|
+
},
|
|
93
|
+
direction: {
|
|
94
|
+
type: String as PropType<Direction>,
|
|
95
|
+
default: Direction.RIGHT,
|
|
96
|
+
validator: (value: Direction) => Object.values(Direction).includes(value),
|
|
97
|
+
},
|
|
98
|
+
maxSize: {
|
|
99
|
+
type: Number as PropType<number>,
|
|
100
|
+
default: 320,
|
|
101
|
+
},
|
|
102
|
+
hasHeader: {
|
|
103
|
+
type: Boolean as PropType<boolean>,
|
|
104
|
+
default: true,
|
|
105
|
+
},
|
|
106
|
+
hasCloseButton: {
|
|
107
|
+
type: Boolean as PropType<boolean>,
|
|
108
|
+
default: true,
|
|
109
|
+
},
|
|
110
|
+
hasOverlay: {
|
|
111
|
+
type: Boolean as PropType<boolean>,
|
|
112
|
+
default: true,
|
|
113
|
+
},
|
|
114
|
+
closeOnOverlayClick: {
|
|
115
|
+
type: Boolean as PropType<boolean>,
|
|
116
|
+
default: true,
|
|
117
|
+
},
|
|
118
|
+
title: {
|
|
119
|
+
type: String as PropType<string>,
|
|
120
|
+
default: 'Drawer',
|
|
121
|
+
},
|
|
122
|
+
titleHeadingTag: {
|
|
123
|
+
type: String as PropType<'h2' | 'h3' | 'h4' | 'h5' | 'h6'>,
|
|
124
|
+
default: 'h2',
|
|
125
|
+
},
|
|
126
|
+
buttonCloseIcon: {
|
|
127
|
+
type: String as PropType<string>,
|
|
128
|
+
default: 'mdi:close',
|
|
129
|
+
},
|
|
130
|
+
hasBorder: {
|
|
131
|
+
type: Boolean as PropType<boolean>,
|
|
132
|
+
default: true,
|
|
133
|
+
},
|
|
134
|
+
drawerClass: String as PropType<string>,
|
|
135
|
+
drawerContentClass: String as PropType<string>,
|
|
136
|
+
overlayClass: String as PropType<string>,
|
|
137
|
+
headerClass: String as PropType<string>,
|
|
138
|
+
titleClass: String as PropType<string>,
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
// Emits
|
|
142
|
+
const emit = defineEmits(['update:modelValue'])
|
|
143
|
+
|
|
144
|
+
const isOpen = computed(() => props.modelValue)
|
|
145
|
+
|
|
146
|
+
// Computed classes
|
|
147
|
+
const positionClasses = computed(() => {
|
|
148
|
+
const map: Record<Direction, string[]> = {
|
|
149
|
+
[Direction.RIGHT]: ['top-0', 'right-0', 'h-full'],
|
|
150
|
+
[Direction.LEFT]: ['top-0', 'left-0', 'h-full'],
|
|
151
|
+
[Direction.TOP]: ['top-0', 'left-0', 'w-full'],
|
|
152
|
+
[Direction.BOTTOM]: ['bottom-0', 'left-0', 'w-full'],
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return map[props.direction]
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
const sizeClasses = computed(() => {
|
|
159
|
+
if (props.direction === Direction.LEFT || props.direction === Direction.RIGHT) {
|
|
160
|
+
return ['w-full']
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return []
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
const drawerInlineStyle = computed(() => {
|
|
167
|
+
if (props.direction === Direction.LEFT || props.direction === Direction.RIGHT) {
|
|
168
|
+
return { maxWidth: props.maxSize + 'px' }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return { maxHeight: props.maxSize + 'px' }
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
const transitionClasses = computed(() => {
|
|
175
|
+
const base = 'transform transition-transform duration-300 ease-out'
|
|
176
|
+
const leaveBase = 'transform transition-transform duration-300 ease-in'
|
|
177
|
+
|
|
178
|
+
const map: Record<
|
|
179
|
+
Direction,
|
|
180
|
+
{
|
|
181
|
+
enterActive: string
|
|
182
|
+
enterFrom: string
|
|
183
|
+
enterTo: string
|
|
184
|
+
leaveActive: string
|
|
185
|
+
leaveFrom: string
|
|
186
|
+
leaveTo: string
|
|
187
|
+
}
|
|
188
|
+
> = {
|
|
189
|
+
[Direction.RIGHT]: {
|
|
190
|
+
enterActive: base,
|
|
191
|
+
enterFrom: 'translate-x-full',
|
|
192
|
+
enterTo: 'translate-x-0',
|
|
193
|
+
leaveActive: leaveBase,
|
|
194
|
+
leaveFrom: 'translate-x-0',
|
|
195
|
+
leaveTo: 'translate-x-full',
|
|
196
|
+
},
|
|
197
|
+
[Direction.LEFT]: {
|
|
198
|
+
enterActive: base,
|
|
199
|
+
enterFrom: '-translate-x-full',
|
|
200
|
+
enterTo: 'translate-x-0',
|
|
201
|
+
leaveActive: leaveBase,
|
|
202
|
+
leaveFrom: 'translate-x-0',
|
|
203
|
+
leaveTo: '-translate-x-full',
|
|
204
|
+
},
|
|
205
|
+
[Direction.TOP]: {
|
|
206
|
+
enterActive: base,
|
|
207
|
+
enterFrom: '-translate-y-full',
|
|
208
|
+
enterTo: 'translate-y-0',
|
|
209
|
+
leaveActive: leaveBase,
|
|
210
|
+
leaveFrom: 'translate-y-0',
|
|
211
|
+
leaveTo: '-translate-y-full',
|
|
212
|
+
},
|
|
213
|
+
[Direction.BOTTOM]: {
|
|
214
|
+
enterActive: base,
|
|
215
|
+
enterFrom: 'translate-y-full',
|
|
216
|
+
enterTo: 'translate-y-0',
|
|
217
|
+
leaveActive: leaveBase,
|
|
218
|
+
leaveFrom: 'translate-y-0',
|
|
219
|
+
leaveTo: 'translate-y-full',
|
|
220
|
+
},
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return map[props.direction]
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
const borderClass = computed(() => {
|
|
227
|
+
if (!props.hasBorder) return ''
|
|
228
|
+
|
|
229
|
+
const colorClass = 'border-border-default'
|
|
230
|
+
|
|
231
|
+
switch (props.direction) {
|
|
232
|
+
case Direction.RIGHT:
|
|
233
|
+
return `border-l ${colorClass}`
|
|
234
|
+
case Direction.LEFT:
|
|
235
|
+
return `border-r ${colorClass}`
|
|
236
|
+
case Direction.TOP:
|
|
237
|
+
return `border-b ${colorClass}`
|
|
238
|
+
case Direction.BOTTOM:
|
|
239
|
+
return `border-t ${colorClass}`
|
|
240
|
+
default:
|
|
241
|
+
return ''
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
// Handlers
|
|
246
|
+
const close = () => {
|
|
247
|
+
emit('update:modelValue', false)
|
|
248
|
+
}
|
|
249
|
+
</script>
|