@veritree/ui 0.94.2 → 0.95.0
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/nuxt.js +1 -0
- package/package.json +1 -1
- package/src/components/Toast/README.md +263 -0
- package/src/components/Toast/VTToast.vue +150 -0
- package/src/components/Toast/VTToastAction.vue +25 -0
- package/src/components/Toast/VTToastClose.vue +52 -0
- package/src/components/Toast/VTToastContent.vue +25 -0
- package/src/components/Toast/VTToastDescription.vue +36 -0
- package/src/components/Toast/VTToastIcon.vue +72 -0
- package/src/components/Toast/VTToastItem.vue +180 -0
- package/src/components/Toast/VTToastTitle.vue +34 -0
- package/test/toast.test.js +575 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<transition
|
|
3
|
+
appear
|
|
4
|
+
:appear-class="enterClass"
|
|
5
|
+
appear-active-class="duration-300 ease-out"
|
|
6
|
+
appear-to-class="translate-y-0 opacity-100"
|
|
7
|
+
enter-active-class="duration-300 ease-out"
|
|
8
|
+
:enter-class="enterClass"
|
|
9
|
+
enter-to-class="translate-y-0 opacity-100"
|
|
10
|
+
leave-active-class="duration-300 ease-in"
|
|
11
|
+
:leave-to-class="leaveClass"
|
|
12
|
+
@after-leave="onAfterLeave"
|
|
13
|
+
>
|
|
14
|
+
<component
|
|
15
|
+
:is="as"
|
|
16
|
+
v-if="visible"
|
|
17
|
+
:id="id"
|
|
18
|
+
:class="[
|
|
19
|
+
headless
|
|
20
|
+
? 'toast-item'
|
|
21
|
+
: 'grid grid-cols-[auto_1fr_auto] items-center gap-3 rounded border border-solid pt-2 pb-2.5 px-3 shadow-lg bg-gray-800 ',
|
|
22
|
+
headless ? `toast-item--${variant}` : null,
|
|
23
|
+
]"
|
|
24
|
+
role="alert"
|
|
25
|
+
aria-live="polite"
|
|
26
|
+
@mouseenter="pauseTimer"
|
|
27
|
+
@mouseleave="resumeTimer"
|
|
28
|
+
>
|
|
29
|
+
<slot></slot>
|
|
30
|
+
</component>
|
|
31
|
+
</transition>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<script>
|
|
35
|
+
import { genId } from '../../utils/ids';
|
|
36
|
+
|
|
37
|
+
export default {
|
|
38
|
+
name: 'VTToastItem',
|
|
39
|
+
|
|
40
|
+
inject: ['apiToast'],
|
|
41
|
+
|
|
42
|
+
provide() {
|
|
43
|
+
return {
|
|
44
|
+
apiToastItem: () => {
|
|
45
|
+
return {
|
|
46
|
+
componentId: this.componentId,
|
|
47
|
+
variant: this.variant,
|
|
48
|
+
close: this.dismiss,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
props: {
|
|
55
|
+
headless: {
|
|
56
|
+
type: Boolean,
|
|
57
|
+
default: false,
|
|
58
|
+
},
|
|
59
|
+
variant: {
|
|
60
|
+
type: String,
|
|
61
|
+
default: 'default',
|
|
62
|
+
validator: (value) => {
|
|
63
|
+
return ['default', 'success', 'error', 'warning'].includes(value);
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
duration: {
|
|
67
|
+
type: Number,
|
|
68
|
+
default: 5000,
|
|
69
|
+
},
|
|
70
|
+
as: {
|
|
71
|
+
type: String,
|
|
72
|
+
default: 'div',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
data() {
|
|
77
|
+
return {
|
|
78
|
+
componentId: genId(),
|
|
79
|
+
visible: true,
|
|
80
|
+
timer: null,
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
computed: {
|
|
85
|
+
id() {
|
|
86
|
+
return `toast-item-${this.componentId}`;
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
isSuccess() {
|
|
90
|
+
return this.variant === 'success';
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
isError() {
|
|
94
|
+
return this.variant === 'error';
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
isWarning() {
|
|
98
|
+
return this.variant === 'warning';
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
position() {
|
|
102
|
+
return this.apiToast().position;
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
enterClass() {
|
|
106
|
+
// Slide from top/bottom edge based on position
|
|
107
|
+
if (this.position.includes('top')) {
|
|
108
|
+
return '-translate-y-full opacity-0';
|
|
109
|
+
} else if (this.position.includes('bottom')) {
|
|
110
|
+
return 'translate-y-full opacity-0';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return 'opacity-0';
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
leaveClass() {
|
|
117
|
+
// Slide to top/bottom edge based on position
|
|
118
|
+
if (this.position.includes('top')) {
|
|
119
|
+
return '-translate-y-full opacity-0';
|
|
120
|
+
} else if (this.position.includes('bottom')) {
|
|
121
|
+
return 'translate-y-full opacity-0';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return 'opacity-0';
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
mounted() {
|
|
129
|
+
this.apiToast().registerItem(this);
|
|
130
|
+
|
|
131
|
+
if (this.duration > 0) {
|
|
132
|
+
this.startTimer();
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
beforeDestroy() {
|
|
137
|
+
this.clearTimer();
|
|
138
|
+
|
|
139
|
+
// Only unregister if not already hidden (avoid double unregister)
|
|
140
|
+
if (this.visible) {
|
|
141
|
+
this.apiToast().unregisterItem(this);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
methods: {
|
|
146
|
+
startTimer() {
|
|
147
|
+
if (this.duration > 0) {
|
|
148
|
+
this.timer = setTimeout(() => {
|
|
149
|
+
this.dismiss();
|
|
150
|
+
}, this.duration);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
clearTimer() {
|
|
155
|
+
if (this.timer) {
|
|
156
|
+
clearTimeout(this.timer);
|
|
157
|
+
this.timer = null;
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
pauseTimer() {
|
|
162
|
+
this.clearTimer();
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
resumeTimer() {
|
|
166
|
+
this.startTimer();
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
dismiss() {
|
|
170
|
+
this.visible = false;
|
|
171
|
+
this.$emit('close');
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
onAfterLeave() {
|
|
175
|
+
// Unregister from parent after transition completes
|
|
176
|
+
this.apiToast().unregisterItem(this);
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
</script>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<component
|
|
3
|
+
:is="as"
|
|
4
|
+
:id="id"
|
|
5
|
+
:class="[headless ? 'toast-title' : 'text-sm font-semibold text-white']"
|
|
6
|
+
>
|
|
7
|
+
<slot></slot>
|
|
8
|
+
</component>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script>
|
|
12
|
+
export default {
|
|
13
|
+
name: 'VTToastTitle',
|
|
14
|
+
|
|
15
|
+
inject: ['apiToastItem'],
|
|
16
|
+
|
|
17
|
+
props: {
|
|
18
|
+
headless: {
|
|
19
|
+
type: Boolean,
|
|
20
|
+
default: false,
|
|
21
|
+
},
|
|
22
|
+
as: {
|
|
23
|
+
type: String,
|
|
24
|
+
default: 'div',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
computed: {
|
|
29
|
+
id() {
|
|
30
|
+
return `toast-title-${this.apiToastItem().componentId}`;
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
</script>
|