main-site/src/lib/components/ServiceCard.svelte

139 lines
3.7 KiB
Svelte
Raw Normal View History

<svelte:options runes={true} />
<script lang="ts">
2024-01-02 02:39:22 +01:00
import { OpenInNewWindow } from 'radix-icons-svelte';
import { quintInOut } from 'svelte/easing';
import { slide } from 'svelte/transition';
import { IconType, type Service } from '$lib/types/data-types';
import { Skeleton } from '$lib/components/ui/skeleton';
2024-01-03 20:40:52 +01:00
import type { Heartbeat } from '$lib/types/uptime-kuma-types';
2024-01-01 18:40:02 +01:00
2024-01-03 20:40:52 +01:00
let { service, icons, monitor } = $props<{
service: Service;
icons: Array<string>;
monitor: Heartbeat;
}>();
let status = $state(4);
2024-01-01 18:40:02 +01:00
2024-01-01 20:00:35 +01:00
let hover = $state({
title: false,
link: false,
ext: false
});
2024-01-02 02:39:22 +01:00
let img_source: string = $state('');
function checkForImage(service: Service) {
const rootSplit = service.icon.split('/');
2024-01-02 02:39:22 +01:00
const root = rootSplit[rootSplit.length - 1];
if (icons.includes(`${root}.${service.iconType}`)) {
2024-01-02 02:39:22 +01:00
img_source = `${service.icon}.${service.iconType}`;
} else {
img_source = '';
}
}
$effect(() => {
2024-01-03 20:40:52 +01:00
if (typeof monitor !== 'undefined') {
status = monitor.status;
}
if (icons.length != 0) {
const rootSplit = service.icon.split('/');
2024-01-02 02:39:22 +01:00
const root = rootSplit[rootSplit.length - 1];
if (service.iconType === IconType.SVG) {
2024-01-02 02:39:22 +01:00
checkForImage(service);
} else {
if (icons.includes(`${root}-36.${service.iconType}`)) {
2024-01-02 02:39:22 +01:00
img_source = `${service.icon}-36.${service.iconType}`;
} else {
checkForImage(service);
}
}
}
});
</script>
2024-01-01 20:00:35 +01:00
<div
2025-04-04 22:12:23 +02:00
class="z-0 flex h-48 w-[28rem] flex-col gap-y-3 rounded-xl border-t-4 border-secondary bg-black/55 p-4 backdrop-blur-sm"
2024-01-01 20:00:35 +01:00
>
<div class="flex flex-row justify-between">
2024-01-01 20:00:35 +01:00
<div
class="flex flex-row items-center gap-1"
on:mouseover={() => (hover.title = true)}
on:mouseleave={() => (hover.title = false)}
>
{#if service.icon}
2024-01-02 02:39:22 +01:00
{#if img_source != ''}
<img
2024-01-02 02:39:22 +01:00
width="24px"
class="h-6 w-6 cursor-pointer"
src={img_source}
alt="{service.name} Logo"
/>
{:else}
<Skeleton class="h-6 w-6 rounded-full" />
{/if}
2024-01-02 02:39:22 +01:00
{:else}{/if}
2024-01-04 01:36:35 +01:00
<a href={service.href} class="font-bold {!hover.title || 'text-secondary'}">{service.name}</a>
2024-01-01 20:00:35 +01:00
{#if hover.title}
<div
transition:slide={{ delay: 100, duration: 200, easing: quintInOut, axis: 'x' }}
class="grid items-center"
>
<OpenInNewWindow
2024-01-04 00:51:27 +01:00
color={hover.title ? 'hsl(var(--secondary))' : 'hsl(var(--primary)'}
2024-01-01 20:00:35 +01:00
class="self-center"
/>
</div>
{/if}
</div>
</div>
2024-01-04 00:51:27 +01:00
<p class="text-wrap text-center text-sm">{service.desc}</p>
2024-01-01 20:00:35 +01:00
<p class="text-center text-sm font-bold text-destructive">{service.warn}</p>
<div class="grid {service.extLink ? 'grid-cols-2' : 'grid-cols-1'} mt-auto justify-items-center">
<a
2024-01-04 00:51:27 +01:00
class="flex flex-row rounded-md border-x-2 px-2 text-sm hover:border-secondary hover:text-secondary"
2024-01-01 20:00:35 +01:00
href={service.href}
on:mouseover={() => (hover.link = true)}
on:mouseleave={() => (hover.link = false)}
>
Open
{#if hover.link}
<div
transition:slide={{ delay: 100, duration: 200, easing: quintInOut, axis: 'x' }}
class="grid items-center pl-1 pr-0"
>
<OpenInNewWindow
2024-01-04 00:51:27 +01:00
color={hover.link ? 'hsl(var(--secondary))' : 'hsl(var(--primary)'}
2024-01-01 20:00:35 +01:00
class="self-center"
/>
</div>
{/if}
</a>
{#if service.extLink}
<a
2024-01-04 00:51:27 +01:00
class="flex flex-row rounded-md border-x-2 px-2 text-sm hover:border-secondary hover:text-secondary"
2024-01-01 20:00:35 +01:00
href={service.extLink}
on:mouseover={() => (hover.ext = true)}
on:mouseleave={() => (hover.ext = false)}
>
Official Site
{#if hover.ext}
<div
transition:slide={{ delay: 100, duration: 200, easing: quintInOut, axis: 'x' }}
class="grid items-center pl-1 pr-0"
>
<OpenInNewWindow
2024-01-04 00:51:27 +01:00
color={hover.ext ? 'hsl(var(--secondary))' : 'hsl(var(--primary)'}
2024-01-01 20:00:35 +01:00
class="self-center"
/>
</div>
{/if}
</a>
{/if}
</div>
</div>