3
import { Box, Circle, Float } from "@chakra-ui/react"
export const FloatBasic = () => (
  <Box position="relative" w="80px" h="80px" bg="bg.emphasized">
    <Float>
      <Circle size="5" bg="red" color="white">
        3
      </Circle>
    </Float>
  </Box>
)
Float requires a parent element with position: relative style applied.
import { Box, Float } from "@chakra-ui/react"<Box position="relative">
  <Float>
    <div />
  </Float>
</Box>Use the placement prop to position the element along the edges of the
container.
bottom-end
3
bottom-start
3
top-end
3
top-start
3
bottom-center
3
top-center
3
middle-center
3
middle-end
3
middle-start
3
import { Box, Circle, Float, HStack, Stack } from "@chakra-ui/react"
export const FloatWithPlacements = () => (
  <HStack gap="14" wrap="wrap">
    {placements.map((placement) => (
      <Stack key={placement} gap="3">
        <p>{placement}</p>
        <Box position="relative" width="80px" height="80px" bg="bg.emphasized">
          <Float placement={placement}>
            <Circle size="5" bg="red" color="white">
              3
            </Circle>
          </Float>
        </Box>
      </Stack>
    ))}
  </HStack>
)
const placements = [
  "bottom-end",
  "bottom-start",
  "top-end",
  "top-start",
  "bottom-center",
  "top-center",
  "middle-center",
  "middle-end",
  "middle-start",
] as const
Use the offsetX prop to offset the element along the x-axis.
3
import { Box, Circle, Float } from "@chakra-ui/react"
export const FloatWithOffsetX = () => (
  <Box position="relative" w="80px" h="80px" bg="bg.emphasized">
    <Float offsetX="-4">
      <Circle size="5" bg="red" color="white">
        3
      </Circle>
    </Float>
  </Box>
)
Use the offsetY prop to offset the element along the y-axis.
3
import { Box, Circle, Float } from "@chakra-ui/react"
export const FloatWithOffsetY = () => (
  <Box position="relative" w="80px" h="80px" bg="bg.emphasized">
    <Float offsetY="-4">
      <Circle size="5" bg="red" color="white">
        3
      </Circle>
    </Float>
  </Box>
)
Use the offset prop to offset the element along both axes.
3
import { Box, Circle, Float } from "@chakra-ui/react"
export const FloatWithOffset = () => (
  <Box position="relative" w="80px" h="80px" bg="bg.emphasized">
    <Float offset="4">
      <Circle size="5" bg="red" color="white">
        3
      </Circle>
    </Float>
  </Box>
)
Here's an example of composing a Float component with an Avatar component.
New
'use client'
import { Box, Float } from '@chakra-ui/react'
import { Avatar, Badge } from '@saas-ui/react'
export const FloatWithAvatar = () => {
  return (
    <Box display="inline-block" pos="relative">
      <Avatar size="lg" shape="rounded" src="https://bit.ly/dan-abramov" />
      <Float placement="bottom-end">
        <Badge size="sm" variant="solid" colorPalette="teal">
          New
        </Badge>
      </Float>
    </Box>
  )
}
| Prop | Default | Type | 
|---|---|---|
| placement  | 'top-end' | ConditionalValue<
    | 'bottom-end'
    | 'bottom-start'
    | 'top-end'
    | 'top-start'
    | 'bottom-center'
    | 'top-center'
    | 'middle-center'
    | 'middle-end'
    | 'middle-start'
  >The placement of the indicator | 
| offsetX  | SystemStyleObject['left']The x offset of the indicator | |
| offsetY  | SystemStyleObject['top']The y offset of the indicator | |
| offset  | SystemStyleObject['top']The x and y offset of the indicator |