Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(ui/image-preview): add class and call #387

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 15 additions & 24 deletions packages/varlet-ui/src/image-preview/ImagePreview.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<var-popup
class="var-image-preview__popup"
:class="n('popup')"
var-image-preview-cover
transition="var-fade"
:show="popupShow"
Expand All @@ -15,7 +15,7 @@
@route-change="onRouteChange"
>
<var-swipe
class="var-image-preview__swipe"
:class="n('swipe')"
var-image-preview-cover
:touchable="canSwipe"
:indicator="indicator && images.length > 1"
Expand All @@ -25,14 +25,9 @@
v-bind="$attrs"
>
<template #default>
<var-swipe-item
class="var-image-preview__swipe-item"
var-image-preview-cover
v-for="image in images"
:key="image"
>
<var-swipe-item :class="n('swipe-item')" var-image-preview-cover v-for="image in images" :key="image">
<div
class="var-image-preview__zoom-container"
:class="n('zoom-container')"
:style="{
transform: `scale(${scale}) translate(${translateX}px, ${translateY}px)`,
transitionTimingFunction,
Expand All @@ -42,31 +37,23 @@
@touchmove="handleTouchmove"
@touchend="handleTouchend"
>
<img class="var-image-preview__image" :src="image" :alt="image" />
<img :class="n('image')" :src="image" :alt="image" />
</div>
</var-swipe-item>
</template>

<template #indicator="{ index, length }">
<slot name="indicator" :index="index" :length="length">
<div class="var-image-preview__indicators" v-if="indicator && images.length > 1">
{{ index + 1 }} / {{ length }}
</div>
<div :class="n('indicators')" v-if="indicator && images.length > 1">{{ index + 1 }} / {{ length }}</div>
</slot>
</template>
</var-swipe>

<slot name="close-icon">
<var-icon
class="var-image-preview__close-icon"
name="close-circle"
var-image-preview-cover
v-if="closeable"
@click="close"
/>
<var-icon :class="n('close-icon')" name="close-circle" var-image-preview-cover v-if="closeable" @click="close" />
</slot>

<div class="var-image-preview__extra">
<div :class="n('extra')">
<slot name="extra" />
</div>
</var-popup>
Expand All @@ -81,6 +68,9 @@ import { defineComponent, ref, computed, watch } from 'vue'
import { props } from './props'
import { toNumber } from '../utils/shared'
import type { Ref, ComputedRef } from 'vue'
import { call, createNamespace } from '../utils/components'

const { n, classes } = createNamespace('image-preview')

type VarTouch = {
clientX: number
Expand Down Expand Up @@ -270,11 +260,10 @@ export default defineComponent({
const close = () => {
if (scale.value > 1) {
zoomOut()
setTimeout(() => props['onUpdate:show']?.(false), ANIMATION_DURATION)
setTimeout(() => call(props['onUpdate:show'], false), ANIMATION_DURATION)
return
}

props['onUpdate:show']?.(false)
call(props['onUpdate:show'], false)
}

watch(
Expand All @@ -286,6 +275,8 @@ export default defineComponent({
)

return {
n,
classes,
initialIndex,
popupShow,
scale,
Expand Down