Skip to content

A self-hosted media server and file management system

1.8 KB
Raw Blame
<script setup lang="ts">
import { computed, useSlots } from 'vue';
import { RouterLink } from 'vue-router';
import { cn } from '@aminnausin/cedar-ui';

const props = defineProps<{
    to?: string;
    href?: string;
    class?: string;
    target?: string;
    disabled?: boolean;
}>();

const wrapper = computed(() => {
    if (props.disabled || (!props.to && !props.href)) return 'div';
    return props.to ? RouterLink : 'a';
});

const wrapperProps = computed(() => {
    if (props.disabled) return { disabled: props.disabled };
    if (props.href) return { href: props.href };
    if (props.to) return { to: props.to };
    return {};
});

const slots = useSlots();
const isCompleteElement = computed(() => !!slots.header && !!slots.body);
</script>

<template>
    <component
        ref="el"
        :is="wrapper"
        :class="
            cn(
                'flex shrink-0 flex-col flex-wrap sm:flex-row',
                'group w-full cursor-pointer rounded-lg p-3 shadow-sm',
                'data-card',
                'transition-input hover:ring-primary-muted hover:dark:ring-primary/60 ring-1 ring-transparent ease-in-out ring-inset hover:ring-2',
                { 'gap-4 lg:gap-2': isCompleteElement },
                { 'button-disabled': disabled },
                props.class,
            )
        "
        :target="target"
        :aria-disabled="disabled ?? false"
        v-bind="wrapperProps"
    >
        <slot>
            <section class="flex w-full items-center justify-between gap-4">
                <slot name="header"> </slot>
            </section>
            <section class="text-foreground-1 flex w-full flex-wrap justify-between gap-2 text-sm">
                <slot name="body"> </slot>
            </section>
        </slot>
    </component>
</template>