koel/resources/assets/js/components/utils/ImageCropper.vue

49 lines
1.2 KiB
Vue
Raw Normal View History

<template>
2024-04-04 22:20:42 +00:00
<div class="w-full h-full fixed top-0 left-0 flex items-center justify-center z-[99] bg-black/70">
<div class="relative max-w-full max-h-full rounded-md flex">
<Cropper
ref="cropper"
2024-04-23 21:01:27 +00:00
:max-width="config.maxWidth"
:min-width="config.minWidth"
:src="source"
:stencil-props="{ aspectRatio: 1 }"
/>
2024-04-04 22:20:42 +00:00
<div class="fixed top-6 right-6 flex flex-1 gap-2">
<Btn success @click.prevent="crop">Crop</Btn>
<Btn transparent @click.prevent="emits('cancel')">Cancel</Btn>
</div>
</div>
</div>
</template>
2024-04-23 21:01:27 +00:00
<script lang="ts" setup>
import { ref, toRefs } from 'vue'
import { Cropper } from 'vue-advanced-cropper'
import 'vue-advanced-cropper/dist/style.css'
2024-04-04 22:20:42 +00:00
import Btn from '@/components/ui/form/Btn.vue'
const props = withDefaults(defineProps<{
source?: string | null
config?: {
minWidth: number
2024-03-30 16:49:25 +00:00
maxWidth?: number
}
}>(), {
source: null,
config: () => ({
2024-03-30 16:49:25 +00:00
minWidth: 192
})
})
const { source, config } = toRefs(props)
const cropper = ref<typeof Cropper>()
const emits = defineEmits<{
(e: 'crop', result: string): void
(e: 'cancel'): void
}>()
const crop = () => emits('crop', cropper.value?.getResult().canvas.toDataURL())
</script>