Skip to content

Commit d42014a

Browse files
committed
Add StatusIcon component
1 parent 66b73a3 commit d42014a

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<script setup lang="ts">
2+
import FAIcon from "@/components/FAIcon.vue";
3+
import { IconDefinition, faCheck, faTimes, faExclamationTriangle, faInfoCircle } from "@fortawesome/free-solid-svg-icons";
4+
5+
export type StatusType = "success" | "error" | "warning" | "info";
6+
7+
interface Props {
8+
status: StatusType;
9+
message?: string;
10+
icon?: IconDefinition;
11+
size?: "2xs" | "xs" | "sm" | "lg" | "xl" | "2xl" | "1x" | "2x" | "3x" | "4x" | "5x" | "6x" | "7x" | "8x" | "9x" | "10x";
12+
showMessage?: boolean;
13+
customClass?: string;
14+
}
15+
16+
const props = withDefaults(defineProps<Props>(), {
17+
message: "",
18+
size: "1x",
19+
showMessage: true,
20+
customClass: "",
21+
});
22+
23+
const statusConfig = {
24+
success: {
25+
icon: faCheck,
26+
class: "text-success",
27+
defaultMessage: "Success",
28+
},
29+
error: {
30+
icon: faTimes,
31+
class: "text-danger",
32+
defaultMessage: "Error",
33+
},
34+
warning: {
35+
icon: faExclamationTriangle,
36+
class: "text-warning",
37+
defaultMessage: "Warning",
38+
},
39+
info: {
40+
icon: faInfoCircle,
41+
class: "text-info",
42+
defaultMessage: "Info",
43+
},
44+
};
45+
46+
const currentConfig = statusConfig[props.status];
47+
const displayIcon = props.icon || currentConfig.icon;
48+
const displayMessage = props.message || currentConfig.defaultMessage;
49+
const cssClass = props.customClass || currentConfig.class;
50+
</script>
51+
52+
<template>
53+
<span :class="['status-icon', cssClass]">
54+
<FAIcon :icon="displayIcon" :size="size" :title="showMessage ? displayMessage : undefined" />
55+
<span v-if="showMessage && message" class="status-message">{{ displayMessage }}</span>
56+
</span>
57+
</template>
58+
59+
<style scoped>
60+
.status-icon {
61+
display: inline-flex;
62+
align-items: center;
63+
gap: 0.25rem;
64+
}
65+
66+
.text-success {
67+
color: #28a745;
68+
}
69+
70+
.text-danger {
71+
color: #dc3545;
72+
}
73+
74+
.text-warning {
75+
color: #ffc107;
76+
}
77+
78+
.text-info {
79+
color: #17a2b8;
80+
}
81+
82+
.info-color {
83+
color: #17a2b8;
84+
}
85+
86+
.error-color {
87+
color: #dc3545;
88+
}
89+
90+
.status-message {
91+
margin-left: 0.25rem;
92+
}
93+
</style>

0 commit comments

Comments
 (0)