Skip to content

Commit d502c30

Browse files
feat(ProseImg): improve zoom transition (#4998)
Co-authored-by: Benjamin Canac <[email protected]>
1 parent 1fc55d2 commit d502c30

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/runtime/components/prose/Img.vue

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const props = withDefaults(defineProps<ProseImgProps>(), {
3939
const appConfig = useAppConfig() as ProseImg['AppConfig']
4040
4141
const [DefineImageTemplate, ReuseImageTemplate] = createReusableTemplate()
42+
const [DefineZoomedImageTemplate, ReuseZoomedImageTemplate] = createReusableTemplate()
4243
4344
const open = ref(false)
4445
@@ -79,9 +80,19 @@ if (props.zoom) {
7980
/>
8081
</DefineImageTemplate>
8182

83+
<DefineZoomedImageTemplate>
84+
<component
85+
:is="ImageComponent"
86+
:src="refinedSrc"
87+
:alt="alt"
88+
v-bind="$attrs"
89+
:class="ui.zoomedImage({ class: [props.ui?.zoomedImage] })"
90+
/>
91+
</DefineZoomedImageTemplate>
92+
8293
<DialogRoot v-if="zoom" v-slot="{ close }" v-model:open="open" :modal="false">
8394
<DialogTrigger as-child>
84-
<Motion :layout-id="layoutId" as-child :transition="{ type: 'spring', bounce: 0.2, duration: 0.4 }">
95+
<Motion :layout-id="layoutId" as-child :transition="{ type: 'spring', bounce: 0.15, duration: 0.5, ease: 'easeInOut' }">
8596
<ReuseImageTemplate />
8697
</Motion>
8798
</DialogTrigger>
@@ -91,8 +102,8 @@ if (props.zoom) {
91102
<Motion v-if="open" :initial="{ opacity: 0 }" :animate="{ opacity: 1 }" :exit="{ opacity: 0 }" :class="ui.overlay({ class: [props.ui?.overlay] })" />
92103

93104
<div v-if="open" :class="ui.content({ class: [props.ui?.content] })" @click="close">
94-
<Motion as-child :layout-id="layoutId" :transition="{ type: 'spring', bounce: 0.2, duration: 0.4 }">
95-
<ReuseImageTemplate />
105+
<Motion as-child :layout-id="layoutId" :transition="{ type: 'spring', bounce: 0.15, duration: 0.5, ease: 'easeInOut' }">
106+
<ReuseZoomedImageTemplate />
96107
</Motion>
97108
</div>
98109
</AnimatePresence>

src/theme/prose/img.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ export default {
22
slots: {
33
base: 'rounded-md w-full',
44
overlay: 'fixed inset-0 bg-default/75 backdrop-blur-sm will-change-opacity',
5-
content: 'fixed inset-0 flex items-center justify-center cursor-zoom-out focus:outline-none p-4 sm:p-8'
5+
content: 'fixed inset-0 flex items-center justify-center cursor-zoom-out focus:outline-none',
6+
zoomedImage: 'w-full h-auto max-w-[95vw] max-h-[95vh] object-contain rounded-md'
67
},
78
variants: {
89
zoom: {

0 commit comments

Comments
 (0)