homebox/frontend/components/Location/Card.vue

56 lines
1.5 KiB
Vue
Raw Normal View History

2022-09-03 09:17:57 +00:00
<template>
<NuxtLink
ref="card"
:to="`/location/${location.id}`"
class="card bg-primary text-primary-content transition duration-300"
>
2022-09-06 18:32:13 +00:00
<div
class="card-body"
:class="{
'p-4': !dense,
'py-2 px-3': dense,
}"
>
2022-09-03 09:17:57 +00:00
<h2 class="flex items-center gap-2">
<label class="swap swap-rotate" :class="isActive ? 'swap-active' : ''">
<Icon name="heroicons-arrow-right" class="swap-on" />
<Icon name="heroicons-map-pin" class="swap-off" />
</label>
{{ location.name }}
<span v-if="hasCount" class="badge badge-secondary badge-lg ml-auto text-secondary-content"> {{ count }}</span>
2022-09-03 09:17:57 +00:00
</h2>
</div>
</NuxtLink>
</template>
<script lang="ts" setup>
import { LocationOut, LocationOutCount, LocationSummary } from "~~/lib/api/types/data-contracts";
2022-09-03 09:17:57 +00:00
const props = defineProps({
2022-09-03 09:17:57 +00:00
location: {
type: Object as () => LocationOutCount | LocationOut | LocationSummary,
2022-09-03 09:17:57 +00:00
required: true,
},
2022-09-06 18:32:13 +00:00
dense: {
type: Boolean,
default: false,
},
2022-09-03 09:17:57 +00:00
});
const hasCount = computed(() => {
return !!(props.location as LocationOutCount).itemCount;
});
const count = computed(() => {
if (hasCount.value) {
return (props.location as LocationOutCount).itemCount;
}
});
2022-09-03 09:17:57 +00:00
const card = ref(null);
const isHover = useElementHover(card);
const { focused } = useFocus(card);
const isActive = computed(() => isHover.value || focused.value);
</script>