Menu

Change language

GitHub repo

Fab

fabui

Floating action button — a fixed or absolute positioned circular button for the primary screen action. Supports an icon (default), an extended label variant, mini/large sizes, four color variants, six anchor positions, and a disabled state.

Installation

$npx shadcn-vue@latest add https://uipkge.dev/r/vue/fab.json
Named registry:npx shadcn-vue@latest add @uipkge/fabInstalls to:app/components/ui/fab/

Examples

Loading interactive previews…

Props

NameType / ValuesDefaultRequired
label

Label text — renders an extended FAB. Use the default slot for an icon.

string—optional
asstring'button'optional
asChildboolean—optional
variant
'default''secondary''destructive''outline'
'default'optional
size
'mini''default''large''extended'
'default'optional
position
'bottom-right''bottom-left''top-right''top-left''bottom-center''inline'
'bottom-right'optional
absolute

Use absolute instead of fixed positioning (for contained FABs).

booleanfalseoptional
disabledboolean—optional
ariaLabel

Accessible label. Defaults to the label prop or 'Floating action'.

string—optional
classHTMLAttributes['class']—optional

Used by

Files installed (3)

  • app/components/ui/fab/Fab.vue1.8 kB
    <script setup lang="ts">
    import type { HTMLAttributes } from 'vue'
    import { Primitive } from 'reka-ui'
    import { cn } from '@/lib/utils'
    import { fabVariants } from './fab.variants'
    
    type Variant = 'default' | 'secondary' | 'destructive' | 'outline'
    type Size = 'mini' | 'default' | 'large' | 'extended'
    type Position = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' | 'bottom-center' | 'inline'
    
    interface Props {
      /** Label text — renders an extended FAB. Use the default slot for an icon. */
      label?: string
      as?: string
      asChild?: boolean
      variant?: Variant
      size?: Size
      position?: Position
      /** Use absolute instead of fixed positioning (for contained FABs). */
      absolute?: boolean
      disabled?: boolean
      /** Accessible label. Defaults to the label prop or 'Floating action'. */
      ariaLabel?: string
      class?: HTMLAttributes['class']
    }
    
    const props = withDefaults(defineProps<Props>(), {
      as: 'button',
      variant: 'default',
      size: 'default',
      position: 'bottom-right',
      absolute: false,
    })
    
    const emit = defineEmits<{ (e: 'click', event: MouseEvent): void }>()
    
    function onClick(e: MouseEvent) {
      if (props.disabled) return
      emit('click', e)
    }
    
    const resolvedSize = () => (props.label ? 'extended' : props.size)
    </script>
    
    <template>
      <Primitive
        data-uipkge
        data-slot="fab"
        :data-variant="variant"
        :data-size="resolvedSize()"
        :data-position="position"
        :as="as"
        :as-child="asChild"
        :disabled="disabled"
        :aria-label="ariaLabel || label || 'Floating action'"
        :class="
          cn(
            fabVariants({ variant, size: resolvedSize(), position }),
            absolute && position !== 'inline' && 'absolute',
            props.class,
          )
        "
        @click="onClick"
      >
        <slot />
        <span v-if="label" class="pr-1">{{ label }}</span>
      </Primitive>
    </template>
    
  • app/components/ui/fab/fab.variants.ts1.6 kB
  • app/components/ui/fab/index.ts0.1 kB

Raw manifest:https://uipkge.dev/r/vue/fab.json