Skip to content

Commit

Permalink
enbizcard
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuraghavb committed Feb 17, 2021
1 parent 9e462bf commit 865e4ad
Show file tree
Hide file tree
Showing 37 changed files with 678 additions and 462 deletions.
49 changes: 0 additions & 49 deletions assets/css/tailwind.css
Original file line number Diff line number Diff line change
@@ -1,52 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

.stepC {
margin-left: 0;
margin-right: 0;
}
.toggle-switch:checked {
@apply right-0;
right: 0;
}
#device {
border-radius: 1rem;
width: 100%;
}
.max-hd {
scrollbar-width: none;
-ms-overflow-style: none;
max-height: 100vh;
}
.max-hd::-webkit-scrollbar {
display: none;
}
.theme-one {
scrollbar-width: none;
-ms-overflow-style: none;
}
.theme-one::-webkit-scrollbar {
display: none;
}
.footer {
display: flex;
}
.stepC.actions {
display: grid;
grid-gap: 1.5rem;
justify-content: space-between;
grid-template-columns: repeat(auto-fill, minmax(3rem, auto));
}

@media (min-width: 640px) {
.stepC {
margin-left: 0.5rem;
margin-right: 0.5rem;
}
}
@media (min-width: 768px) {
.max-hd {
max-height: 38rem;
}
}
2 changes: 1 addition & 1 deletion assets/styles/T1.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion assets/styles/T1.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ header {
box-sizing: border-box;
}
#logo {
min-height: 6rem;
max-height: 6rem;
text-align: center;
color: gray;
Expand Down
74 changes: 50 additions & 24 deletions components/Attachment.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<template>
<div class="flex mt-6">
<transition name="list">
<Cropper
v-if="showCropper"
:src="tempURL"
@closeCropper="closeCropper"
:content="content"
:mime="mime"
:resizeImage="resizeImage"
/>
</transition>
<div class="flex flex-wrap items-center">
<img
class="w-12 h-12 rounded object-contain"
Expand All @@ -22,7 +32,7 @@
<input
:ref="`import${type}`"
type="file"
:accept="`.png,.jpg,.jpeg${type == 'logo' ? ',.svg' : ''}`"
:accept="`.png,.jpg,.jpeg,.gif,.webp${type == 'logo' ? ',.svg' : ''}`"
v-show="false"
@change="fileLoaded($event, type, false)"
@click="$event.target.files = null"
Expand Down Expand Up @@ -65,6 +75,9 @@ export default {
data() {
return {
dragOver: false,
showCropper: false,
tempURL: null,
mime: null,
}
},
computed: {
Expand All @@ -73,6 +86,9 @@ export default {
},
},
methods: {
closeCropper() {
this.showCropper = false
},
attachFile(e, type, dropped) {
dropped
? (this.fileLoaded(e, type, true), (this.dragOver = false))
Expand All @@ -84,40 +100,50 @@ export default {
(!dropped && e.target.files.length)
) {
let file = dropped ? e.dataTransfer.files[0] : e.target.files[0]
if (type == 'logo' && file.type.match(/image\/(svg\+xml|png|jpeg)/)) {
this.imageLoaded(file, type)
} else if (file.type.match(/image\/(png|jpeg)/)) {
this.imageLoaded(file, type)
let mime = file.type
if (
type == 'logo' &&
file.type.match(/image\/(svg\+xml|png|jpeg|gif|webp)/)
) {
this.imageLoaded(file, type, mime)
} else if (file.type.match(/image\/(png|jpeg|gif|webp)/)) {
this.imageLoaded(file, type, mime)
} else {
if (type == 'logo') {
this.showAlert(
'Unsupported file format.\nOnly jpeg, png, webp, gif and svg file can be attached.'
)
} else {
this.showAlert(
'Unsupported file format.\nOnly jpeg, png, webp and gif file can be attached.'
)
}
}
}
},
imageLoaded(file, type) {
imageLoaded(file, type, mime) {
let reader = new FileReader()
reader.onload = (f) => {
let dataURI = f.target.result
let format = dataURI
let ext = dataURI
.split(',')[0]
.split(':')[1]
.split('/')[1]
.match(/^\w+/g)[0]
if (type == 'photo') {
let img = new Image()
img.src = dataURI
img.onload = () => {
img.width != img.height
? this.showAlert(
'Looks like its not a square photo.\n\nPlease use an image editor to crop the photo to 1:1 and re-attach the same.'
)
: null
if (type == 'logo' || mime.match(/gif|webp/)) {
this.content[type] = {
url: dataURI,
blob: file,
ext,
mime,
resized: file,
}
}
this.content[type] = {
url: dataURI,
blob: file,
format,
}
if (this.content[type].format.match(/(png|jpg|jpeg)/)) {
this.resizeImage(type)
if (!mime.match(/svg|gif|webp/)) this.resizeImage(type, mime)
} else {
this.content.photo.ext = ext
this.mime = mime
this.tempURL = dataURI
this.showCropper = true
}
}
reader.readAsDataURL(file)
Expand Down
2 changes: 1 addition & 1 deletion components/Colour.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default {
<style lang="scss">
.palette-enter-active,
.palette-leave-active {
transition: transform 0.1s ease;
transition: transform 0.2s ease;
transform-origin: left top;
}
.palette-enter,
Expand Down
77 changes: 77 additions & 0 deletions components/Cropper.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<template>
<div
id="notificationContainer"
class="flex justify-center fixed top-0 left-0 right-0 bottom-0 items-center z-30 bg-black bg-opacity-80"
>
<div
class="flex flex-col items-center notification content bg-gray-800 text-gray-100 rounded relative z-50 max-w-sm mx-4 p-2"
>
<div class="mb-2 max-w-sm max-h-80">
<img ref="image" :src="src" />
</div>
<div class="flex">
<button
class="p-3 font-extrabold rounded tracking-wide focus:outline-none select-none bg-gray-700 mr-2 hover:bg-gray-600 focus:bg-gray-600 transition-colors duration-200"
@click="$emit('closeCropper')"
>
Cancel
</button>
<button
class="font-extrabold leading-none tracking-wide select-none flex-shrink-0 p-3 text-white bg-green-600 rounded hover:bg-green-500 focus:bg-green-500 transition-colors duration-200 focus:outline-none"
@click="cropPhoto"
>
Crop photo
</button>
</div>
</div>
</div>
</template>

<script>
import Cropper from 'cropperjs'
import 'cropperjs/dist/cropper.css'
export default {
props: ['src', 'mime', 'content', 'resizeImage'],
data() {
return {
cropper: {},
dataURL: null,
blobData: null,
image: {},
}
},
methods: {
cropPhoto() {
let vm = this
const canvas = this.cropper.getCroppedCanvas()
let url = canvas.toDataURL(this.mime)
this.content.photo.url = url
this.content.photo.mime = this.mime
canvas.toBlob(
(blob) => {
vm.content.photo.blob = new File([blob], 'photo', {
type: this.mime,
})
vm.resizeImage('photo', vm.mime)
vm.$emit('closeCropper')
},
this.mime,
0.8
)
},
},
mounted() {
this.image = this.$refs.image
this.cropper = new Cropper(this.image, {
zoomable: false,
scalable: true,
aspectRatio: 1,
autoCropArea: 1,
responsive: true,
viewMode: 2,
highlight: false,
rotatable: false,
})
},
}
</script>
Loading

0 comments on commit 865e4ad

Please sign in to comment.