Animated Toggle Icon
两个图标来回切,进场出场缩一下。底下是 Icon 和 motion-v。没列出来的属性经 $attrs 传给 Motion。
Installation
pnpm dlx @weme-ui/weme-ui add animated-toggle-iconUsage
Vueexamples/usage.vueExpand codeHide code
<script lang="ts" setup>
import { ref } from 'vue'
import AnimatedToggleIcon from '../animated-toggle-icon.vue'
const active = ref(false)
</script>
<template>
<button type="button" class="text-sm inline-flex gap-2 items-center" @click="active = !active">
<AnimatedToggleIcon
icon="ri:heart-line"
active-icon="ri:heart-fill"
:active="active"
class="text-lg text-error"
/>
Toggle
</button>
</template>Examples
States
Vueexamples/states.vueExpand codeHide code
<script lang="ts" setup>
import AnimatedToggleIcon from '../animated-toggle-icon.vue'
</script>
<template>
<div class="text-lg flex flex-wrap gap-6 items-center">
<AnimatedToggleIcon
icon="ri:checkbox-blank-circle-line"
active-icon="ri:checkbox-circle-fill"
:active="false"
/>
<AnimatedToggleIcon
icon="ri:checkbox-blank-circle-line"
active-icon="ri:checkbox-circle-fill"
:active="true"
/>
</div>
</template>Fallback Icon
Vueexamples/fallback-icon.vueExpand codeHide code
<script lang="ts" setup>
import { ref } from 'vue'
import AnimatedToggleIcon from '../animated-toggle-icon.vue'
const active = ref(true)
</script>
<template>
<button
type="button"
class="inline-flex items-center"
aria-label="Toggle"
@click="active = !active"
>
<AnimatedToggleIcon icon="ri:star-line" :active="active" class="text-lg text-warning" />
</button>
</template>Props
PropTypeDefault
iconIconifyIconProps['icon']-
未激活态图标(Iconify);必填
IconifyIconProps['icon']-
activeIconIconifyIconProps['icon']-
激活态图标(Iconify);未传时激活态回退到
iconIconifyIconProps['icon']-
activeboolean-
是否为激活态;切换时触发进出场动画
boolean-classany-
根节点额外 class
any-Accessibility
经 Motion(as-child)画成 Icon,带着 data-slot="animated-toggle-icon" 和 data-active。根节点 pointer-events-none。没有自己的键盘操作。有含义就在旁边写字。
Files
src/components/animated-toggle-icon/animated-toggle-icon.vuesrc/components/animated-toggle-icon/animated-toggle-icon.props.ts