Skip to content

Commit 349e8d9

Browse files
author
hywax
committed
chore: add animation status toggle
1 parent d2a59b8 commit 349e8d9

4 files changed

Lines changed: 19 additions & 11 deletions

File tree

‎src/components/service/base/Index.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{{ title }}
1515
</slot>
1616
<slot v-if="status && status.enabled" name="status" :data="data">
17-
<ServiceBaseStatus :ping="data?.ping" />
17+
<ServiceBaseStatus :ping="{ ...data?.ping, animation: status?.animation }" />
1818
</slot>
1919
</h3>
2020

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
<template>
2-
<span class="relative inline-flex z-1 h-2.5 w-2.5 rounded-full bg-green-400" :class="color">
3-
<span class="absolute -z-1 inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75" :class="color" />
2+
<span class="relative inline-flex z-1 h-2.5 w-2.5 rounded-full bg-green-400" :class="colorClasses">
3+
<span v-if="!ping || ping.animation !== false" class="absolute -z-1 inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75" :class="colorClasses" />
44
</span>
55
</template>
66

77
<script setup lang="ts">
88
export interface Props {
99
ping?: {
10-
status: boolean
10+
status?: boolean
11+
animation?: boolean
1112
time: number
1213
}
1314
}
1415
15-
const props = defineProps<Props>()
16-
const color = computed(() => {
17-
if (!props.ping) {
18-
return 'bg-neutral-400'
19-
}
20-
21-
return props.ping.status ? 'bg-green-400' : 'bg-red-400'
16+
const props = withDefaults(defineProps<Props>(), {
17+
ping: () => ({
18+
status: undefined,
19+
animation: true,
20+
time: 0,
21+
}),
2222
})
23+
24+
const colorClasses = computed(() => [
25+
{ 'bg-green-400': props.ping.status },
26+
{ 'bg-red-400': props.ping.status === false },
27+
{ 'bg-neutral-400': props.ping.status === undefined },
28+
])
2329
</script>

‎src/server/validations/service.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { z } from 'zod'
33
export const statusSchema = z.object({
44
enabled: z.boolean().optional(),
55
interval: z.number().optional(),
6+
animation: z.boolean().optional(),
67
})
78

89
export const iconSchema = z.object({

‎src/types/services.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Tag } from '~/types/config'
33
export interface ServiceStatus {
44
enabled?: boolean
55
interval?: number
6+
animation?: boolean
67
}
78

89
export interface ServiceIcon {

0 commit comments

Comments
 (0)