-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from ojvribeiro/feat-image-component
feat(core): create `Image` component
- Loading branch information
Showing
20 changed files
with
135 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `.vulmix/assets/img` | ||
|
||
All your images will be compiled here. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<template> | ||
<img | ||
:src="imgSrc" | ||
:width="width" | ||
:height="height" | ||
:alt="props.alt" | ||
:title="props.title" | ||
:loading="targetIsVisible ? 'eager' : 'lazy'" | ||
ref="imageEl" | ||
/> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, onMounted } from 'vue' | ||
import { useElementSize, useElementVisibility } from '@vueuse/core' | ||
const props = defineProps({ | ||
src: { | ||
type: String, | ||
default: '', | ||
}, | ||
width: { | ||
type: String, | ||
}, | ||
height: { | ||
type: String, | ||
}, | ||
alt: { | ||
type: String, | ||
default: 'Image', | ||
}, | ||
title: { | ||
type: String, | ||
default: '', | ||
}, | ||
webp: { | ||
type: String, | ||
default: 'true', | ||
}, | ||
}) | ||
const imageEl = ref(null) | ||
const imgSrc = ref(props.src) | ||
const { width, height } = useElementSize(imageEl) | ||
const targetIsVisible = useElementVisibility(imageEl) | ||
function replace(size) { | ||
imgSrc.value = props.src.replace( | ||
/\/assets\/img\/(|.*)([a-zA-Z0-9_-])\.(png|jpg|jpeg|gif)$/i, | ||
`/.vulmix/assets/img/$1$2@${size}.${ | ||
props.webp === 'true' ? 'webp' : '$3' | ||
}` | ||
) | ||
} | ||
onMounted(() => { | ||
if (imageEl.value.width < 300) { | ||
replace('300') | ||
} else if (imageEl.value.width >= 301 && imageEl.value.width < 600) { | ||
replace('600') | ||
} else if (imageEl.value.width >= 601 && imageEl.value.width < 900) { | ||
replace('900') | ||
} else if (imageEl.value.width >= 901 && imageEl.value.width < 1200) { | ||
replace('1200') | ||
} else { | ||
replace('1920') | ||
} | ||
}) | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
img { | ||
background-color: rgba(#000, 10%); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
<template> | ||
<div class="p-8 bg-slate-600 text-white rounded-xl w-fit"> | ||
<h2 class="text-3xl mb-6">My test component</h2> | ||
<div class="p-8 bg-slate-600 text-white rounded-xl w-fit max-w-full flex flex-col md:flex-row gap-6"> | ||
<Image | ||
class="w-[400px] max-w-full aspect-square object-cover object-bottom rounded-xl" | ||
src="/assets/img/sample.jpg" | ||
/> | ||
|
||
<p>Here's some paragraph for ya.</p> | ||
<div> | ||
<h2 class="text-3xl mb-6">My test component</h2> | ||
|
||
<p>Here's some paragraph for ya.</p> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const path = require('path') | ||
|
||
module.exports = { | ||
resolve: { | ||
extensions: ['.js', '.vue'], | ||
alias: { | ||
'@': path.resolve(__dirname, '.vulmix'), | ||
'@assets': path.resolve(__dirname, 'assets'), | ||
'@components': path.resolve(__dirname, 'components'), | ||
'@composables': path.resolve(__dirname, 'composables'), | ||
'@pages': path.resolve(__dirname, 'pages'), | ||
'@sass': path.resolve(__dirname, 'assets/sass'), | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,9 @@ | ||
const mix = require('laravel-mix') | ||
const path = require('path') | ||
|
||
require('./.vulmix/mix.js') | ||
|
||
mix | ||
.vueMix() | ||
|
||
.alias({ | ||
'@': path.join(__dirname, '.vulmix'), | ||
'@assets': path.join(__dirname, 'assets'), | ||
'@components': path.join(__dirname, 'components'), | ||
'@composables': path.join(__dirname, 'composables'), | ||
'@pages': path.join(__dirname, 'pages'), | ||
'@sass': path.join(__dirname, 'assets/sass'), | ||
}) | ||
|
||
.sass('assets/sass/main.scss', '.dist/css') | ||
|