Skip to content

Commit

Permalink
Merge branch 'main' into fix/menu-items-request
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby authored Sep 18, 2023
2 parents c6cece2 + dd55a0f commit fa48171
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
17 changes: 8 additions & 9 deletions console/packages/components/src/components/dialog/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
IconForbidLine,
IconInformation,
} from "../../icons/icons";
import { computed, ref } from "vue";
import { ref, type Component, markRaw, type Raw } from "vue";
import type { Type } from "@/components/dialog/interface";
import type { Type as ButtonType } from "@/components/button/interface";
Expand Down Expand Up @@ -48,25 +48,24 @@ const emit = defineEmits<{
(event: "close"): void;
}>();
const icons = {
const icons: Record<Type, { icon: Raw<Component>; color: string }> = {
success: {
icon: IconCheckboxCircle,
icon: markRaw(IconCheckboxCircle),
color: "green",
},
info: {
icon: IconInformation,
icon: markRaw(IconInformation),
color: "blue",
},
warning: {
icon: IconErrorWarning,
icon: markRaw(IconErrorWarning),
color: "orange",
},
error: {
icon: IconForbidLine,
icon: markRaw(IconForbidLine),
color: "red",
},
};
const icon = computed(() => icons[props.type]);
const loading = ref(false);
Expand Down Expand Up @@ -108,8 +107,8 @@ const handleClose = () => {
<div class="flex justify-between items-start py-2 mb-2">
<div class="flex flex-row items-center gap-3">
<component
:is="icon.icon"
:class="`text-${icon.color}-500`"
:is="icons[type].icon"
:class="`text-${icons[type].color}-500`"
class="w-6 h-6"
></component>
<div class="text-base text-gray-900 font-bold">{{ title }}</div>
Expand Down
23 changes: 14 additions & 9 deletions console/packages/components/src/components/toast/Toast.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<script lang="ts" setup>
import type { Type } from "./interface";
import { computed, onMounted, ref, watchEffect } from "vue";
import {
onMounted,
ref,
watchEffect,
type Raw,
type Component,
markRaw,
} from "vue";
import {
IconCheckboxCircle,
IconErrorWarning,
Expand Down Expand Up @@ -36,27 +43,25 @@ const emit = defineEmits<{
(event: "close"): void;
}>();
const icons = {
const icons: Record<Type, { icon: Raw<Component>; color: string }> = {
success: {
icon: IconCheckboxCircle,
icon: markRaw(IconCheckboxCircle),
color: "text-green-500",
},
info: {
icon: IconInformation,
icon: markRaw(IconInformation),
color: "text-sky-500",
},
warning: {
icon: IconErrorWarning,
icon: markRaw(IconErrorWarning),
color: "text-orange-500",
},
error: {
icon: IconForbidLine,
icon: markRaw(IconForbidLine),
color: "text-red-500",
},
};
const icon = computed(() => icons[props.type]);
const createTimer = () => {
if (props.duration < 0) return;
timer.value = setTimeout(() => {
Expand Down Expand Up @@ -115,7 +120,7 @@ defineExpose({ close });
>
<div class="toast-body">
<div class="toast-icon">
<component :is="icon.icon" :class="[icon.color]" />
<component :is="icons[type].icon" :class="icons[type].color" />
</div>
<div class="toast-content">
<div class="toast-description">
Expand Down

0 comments on commit fa48171

Please sign in to comment.