-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAlert.vue
More file actions
99 lines (85 loc) · 1.82 KB
/
Alert.vue
File metadata and controls
99 lines (85 loc) · 1.82 KB
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
<template>
<div
ref="el"
:class="[
$style.alert,
$style['alert--' + props.type]
]"
:theme-base="computedTheme"
>
<Icon
v-show="icon"
:name="icon"
/>
<div>{{ props.message }}</div>
</div>
</template>
<script setup lang="ts">
import { defineProps, computed, withDefaults, ref } from 'vue';
import Icon from '../icon/Icon.vue';
import type { AlertOptions, AlertTheme } from './Alert.types';
const el = ref<HTMLElement>();
const props = withDefaults(defineProps<AlertOptions>(), {
id: `alert-' ${Math.random()}`,
position: 'bottom-center',
message: '',
icon: '',
type: 'default',
timeout: 5000,
});
/**
*
* computed theme
*/
const computedTheme = computed((): AlertTheme => {
switch (props.type) {
case 'success':
return 'grass';
case 'error':
return 'red';
case 'warning':
return 'amber';
case 'info':
return 'graphite';
default:
return '';
}
});
</script>
<style module lang="postcss">
.alert {
position: relative;
box-sizing: border-box;
display: flex;
align-items: center;
gap: var(--v-padding);
border: 0;
margin-block-start: 0.4rem;
outline: 0;
font-family: inherit;
pointer-events: auto;
background-color: var(--base-text);
overflow: hidden;
word-break: keep-all;
transform: translateZ(0);
direction: ltr;
padding: var(--v-padding) var(--h-padding) var(--v-padding) var(--h-padding);
border-radius: var(--radius-field);
color: var(--accent--text-solid-foreground);
&--success {
background-color: var(--base--solid);
}
&--error {
background-color: var(--base--solid);
}
&--warning {
background-color: var(--base--solid);
}
&--info {
background-color: var(--base--solid);
}
&--default {
background-color: var(--base--bg-secondary);
}
}
</style>