Skip to content

Commit

Permalink
Feature/App image (#46)
Browse files Browse the repository at this point in the history
* added app-image with loader

* optimized app-image

---------

Co-authored-by: Yehor Podporinov <[email protected]>
  • Loading branch information
yehor-podporinov and Yehor Podporinov authored Oct 23, 2023
1 parent a958f04 commit 6992f76
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
54 changes: 54 additions & 0 deletions components/AppImage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<template>
<div class="app-image">
<div v-if="isLoading" class="app-image__loader-wrp">
<template v-if="$slots.loading">
<slot name="loading" /><!--THERE IS A SLOT HERE-->
</template>
<template v-else>
<app-loader />
</template>
</div>
<template v-else-if="error && $slots.error">
<slot name="error" :error="error" /><!--THERE IS A SLOT HERE-->
</template>
<template v-else>
<img v-bind="$attrs" class="app-image__img" :alt="alt" :src="src" />
</template>
</div>
</template>

<script lang="ts" setup>
import { AppLoader } from '#components'
import { useImage } from '@vueuse/core'
const props = withDefaults(
defineProps<{
src?: string
alt?: string
}>(),
{
src: '',
alt: '',
},
)
const { error, isLoading } = useImage(props)
</script>

<style lang="scss" scoped>
.app-image {
display: flex;
object-fit: cover;
overflow: hidden;
background: var(--background-primary-main);
border-radius: var(--border-radius-main);
}
.app-image__loader-wrp {
margin: auto;
}
.app-image__img {
all: inherit;
}
</style>
4 changes: 2 additions & 2 deletions components/AuditsCard.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="audits-card">
<img :src="audit.imgSrc" class="audits-card__img" alt="audit-image" />
<app-image :src="audit.imgSrc" class="audits-card__img" alt="audit-image" />
<div class="audits-card__content">
<div class="audits-card__title-wrp">
<h3 class="audits-card__title">
Expand All @@ -24,6 +24,7 @@
</template>

<script lang="ts" setup>
import { AppImage } from '#components'
import { Audit } from '@/types'
defineProps<{
Expand All @@ -42,7 +43,6 @@ defineProps<{
}
.audits-card__img {
display: block;
aspect-ratio: 600 / 318;
width: 100%;
object-fit: cover;
Expand Down

0 comments on commit 6992f76

Please sign in to comment.