-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(animate): move to script setup (#2947)
- Loading branch information
Showing
12 changed files
with
218 additions
and
170 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
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,75 @@ | ||
<template> | ||
<view class="nut-animate"> | ||
<view | ||
:class="classes" | ||
:style="{ | ||
animationDuration: duration ? `${duration}ms` : undefined | ||
}" | ||
@click="handleClick" | ||
> | ||
<slot></slot> | ||
</view> | ||
</view> | ||
</template> | ||
<script setup lang="ts"> | ||
import { ref, computed, watch } from 'vue'; | ||
import type { AnimateType, AnimateAction } from './types'; | ||
defineOptions({ | ||
name: 'NutAnimate' | ||
}); | ||
export type AnimateProps = Partial<{ | ||
type: AnimateType; | ||
show: boolean; | ||
action: AnimateAction; | ||
loop: boolean; | ||
duration: string | number; | ||
}>; | ||
const props = withDefaults(defineProps<AnimateProps>(), { | ||
show: false, | ||
action: '', | ||
loop: false, | ||
duration: 500 | ||
}); | ||
const emit = defineEmits(['click', 'animate']); | ||
const animated = ref(props.action === 'initial' || props.show === true || props.loop); | ||
const classes = computed(() => { | ||
const prefixCls = 'nut-animate'; | ||
return { | ||
'nut-animate__container': true, | ||
[`${prefixCls}-${props.type}`]: animated.value, | ||
loop: props.loop | ||
}; | ||
}); | ||
const animate = () => { | ||
animated.value = false; | ||
requestAnimationFrame(() => { | ||
requestAnimationFrame(() => { | ||
animated.value = true; | ||
}); | ||
}); | ||
}; | ||
const handleClick = (event: Event) => { | ||
if (props.action === 'click') { | ||
animate(); | ||
emit('click', event); | ||
emit('animate'); | ||
} | ||
}; | ||
watch( | ||
() => props.show, | ||
(val) => { | ||
if (val) { | ||
animate(); | ||
emit('animate'); | ||
} | ||
} | ||
); | ||
</script> |
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,75 @@ | ||
<template> | ||
<view class="nut-animate"> | ||
<view | ||
:class="classes" | ||
:style="{ | ||
animationDuration: duration ? `${duration}ms` : undefined | ||
}" | ||
@click="handleClick" | ||
> | ||
<slot></slot> | ||
</view> | ||
</view> | ||
</template> | ||
<script setup lang="ts"> | ||
import { ref, computed, watch } from 'vue'; | ||
import type { AnimateType, AnimateAction } from './types'; | ||
defineOptions({ | ||
name: 'NutAnimate' | ||
}); | ||
export type AnimateProps = Partial<{ | ||
type: AnimateType; | ||
show: boolean; | ||
action: AnimateAction; | ||
loop: boolean; | ||
duration: string | number; | ||
}>; | ||
const props = withDefaults(defineProps<AnimateProps>(), { | ||
show: false, | ||
action: '', | ||
loop: false, | ||
duration: 500 | ||
}); | ||
const emit = defineEmits(['click', 'animate']); | ||
const animated = ref(props.action === 'initial' || props.show === true || props.loop); | ||
const classes = computed(() => { | ||
const prefixCls = 'nut-animate'; | ||
return { | ||
'nut-animate__container': true, | ||
[`${prefixCls}-${props.type}`]: animated.value, | ||
loop: props.loop | ||
}; | ||
}); | ||
const animate = () => { | ||
animated.value = false; | ||
requestAnimationFrame(() => { | ||
requestAnimationFrame(() => { | ||
animated.value = true; | ||
}); | ||
}); | ||
}; | ||
const handleClick = (event: Event) => { | ||
if (props.action === 'click') { | ||
animate(); | ||
emit('click', event); | ||
emit('animate'); | ||
} | ||
}; | ||
watch( | ||
() => props.show, | ||
(val) => { | ||
if (val) { | ||
animate(); | ||
emit('animate'); | ||
} | ||
} | ||
); | ||
</script> |
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
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,13 @@ | ||
import Animate from './animate.taro.vue'; | ||
import type { ComponentPublicInstance } from 'vue'; | ||
import { withInstall } from '@/packages/utils'; | ||
|
||
withInstall(Animate); | ||
|
||
export type { AnimateProps } from './animate.taro.vue'; | ||
|
||
export type { AnimateType, AnimateAction } from './types'; | ||
|
||
export type AnimateInstance = ComponentPublicInstance & InstanceType<typeof Animate>; | ||
|
||
export { Animate, Animate as default }; |
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
import Animate from './animate.vue'; | ||
import type { ComponentPublicInstance } from 'vue'; | ||
import { withInstall } from '@/packages/utils'; | ||
|
||
withInstall(Animate); | ||
|
||
export type { AnimateProps } from './animate.vue'; | ||
|
||
export type { AnimateType, AnimateAction } from './types'; | ||
|
||
export type AnimateInstance = ComponentPublicInstance & InstanceType<typeof Animate>; | ||
|
||
export { Animate, Animate as default }; |
Oops, something went wrong.