phundrak.com/.vuepress/components/ResponsiveImage.vue
Lucien Cartier-Tilet 23f30a9cb3
feat: mostly reproduce old Nuxt website's content
Signed-off-by: Lucien Cartier-Tilet <lucien@phundrak.com>
2023-02-09 12:13:12 +01:00

26 lines
552 B
Vue

<template>
<img :srcset="srcset" :sizes="sizes" :alt="props.alt" :src="props.src" />
</template>
<script setup lang="ts">
const props = defineProps<{
src: string;
width: number;
preview: string;
previewWidth: number;
previewThreshold?: number;
alt?: string;
}>();
const srcset = [
`${props.preview} ${props.previewWidth}w`,
`${props.src} ${props.width}w`,
].join(', ');
const sizes = [
`(max-width: ${props.previewThreshold || props.previewWidth}px) ${
props.previewWidth
}px`,
`${props.width}px`,
].join(', ');
</script>