Skip to content

Float

把内容钉在父级的边上或角上。父级需要 relative,否则会贴到更外层。

Installation

pnpm dlx @weme-ui/weme-ui add float

Usage

Vueexamples/usage.vueExpand codeHide code
<script lang="ts" setup>
import Avatar from '../../avatar/avatar.vue'
import Button from '../../button/button.vue'
import Icon from '../../icon/icon.vue'
import Float from '../float.vue'
</script>

<template>
  <div class="flex flex-wrap gap-8 items-center">
    <Avatar>
      <template #extend>
        <Float placement="top-right" offset="2px">
          <Icon name="ri:vip-crown-2-fill" class="text-yellow-10 rotate-40" aria-label="VIP" />
        </Float>
      </template>
    </Avatar>

    <Button label="Click me" color="accent">
      <Float placement="top-right">
        <Icon name="ri:vip-crown-2-fill" class="text-yellow-10 rotate-40" aria-label="VIP" />
      </Float>
    </Button>
  </div>
</template>

Examples

Placements

Vueexamples/placements.vueExpand codeHide code
<script lang="ts" setup>
import Float from '../float.vue'

const placements = [
  'top-left',
  'top',
  'top-right',
  'left',
  'center',
  'right',
  'bottom-left',
  'bottom',
  'bottom-right',
] as const
</script>

<template>
  <div class="gap-6 grid grid-cols-3 justify-items-center">
    <div v-for="placement in placements" :key="placement" class="relative">
      <div class="rounded bg-muted size-12" />
      <Float :placement="placement">
        <span class="rounded-full bg-accent size-2.5 ring-2 ring-$docs-well" />
      </Float>
    </div>
  </div>
</template>

Offset

Vueexamples/offset.vueExpand codeHide code
<script lang="ts" setup>
import Avatar from '../../avatar/avatar.vue'
import Icon from '../../icon/icon.vue'
import Float from '../float.vue'
</script>

<template>
  <div class="flex flex-wrap gap-8 items-center">
    <div class="flex relative">
      <Avatar />
      <Float placement="top-right" offset="0">
        <Icon name="ri:vip-crown-2-fill" class="text-yellow-10 rotate-40" aria-label="VIP" />
      </Float>
    </div>

    <div class="flex relative">
      <Avatar src="https://github.com/moujinet.png" />
      <Float placement="top-right" offset="-2px">
        <Icon
          name="ri:ghost-3-fill"
          class="text-accent animate-bounce"
          aria-label="Ghost behind the avatar"
        />
      </Float>
    </div>
  </div>
</template>

Props

PropTypeDefault
asAsTag | Component'div'
渲染为的元素或组件(Reka UI Primitive)
AsTag | Component
'div'
asChildbooleanfalse
合并到子元素上渲染(Reka UI composition)
boolean
false
placement'top-left' | 'top' | 'top-right' | 'left' | 'center' | 'right' | 'bottom-left' | 'bottom' | 'bottom-right''top-right'
相对父级的位置
'top-left' | 'top' | 'top-right' | 'left' | 'center' | 'right' | 'bottom-left' | 'bottom' | 'bottom-right'
'top-right'
offsetstring'0'
两轴共用的偏移。写入 --offset,并作为 --offset-x / --offset-y 的回退
string
'0'
offsetXstring-
水平偏移,写入 --offset-x。未设时用 offset
string
-
offsetYstring-
垂直偏移,写入 --offset-y。未设时用 offset
string
-
classany-
根节点额外 class
any
-

Slots

SlotDescription
default浮在父级上的内容
浮在父级上的内容

Files

  • src/components/float/float.vue
  • src/components/float/float.props.ts
  • src/components/float/float.style.ts