Badge

GitHub
A short text to represent a status or a category.

Usage

Use the default slot to set the label of the Badge.

Badge
<template>
  <PBadge>Badge</PBadge>
</template>

Label

Use the label prop to set the label of the Badge.

Badge
<template>
  <PBadge label="Badge" />
</template>

Color

Use the color prop to change the color of the Badge.

Badge
<template>
  <PBadge color="neutral">Badge</PBadge>
</template>

Variant

Use the variant props to change the variant of the Badge.

Badge
<template>
  <PBadge color="neutral" variant="outline">Badge</PBadge>
</template>

Size

Use the size prop to change the size of the Badge.

Badge
<template>
  <PBadge size="xl">Badge</PBadge>
</template>

Icon

Use the icon prop to show an Icon inside the Badge.

Badge
<template>
  <PBadge icon="i-lucide:rocket" size="md" color="primary" variant="solid">Badge</PBadge>
</template>

Use the leading and trailing props to set the icon position or the leading-icon and trailing-icon props to set a different icon for each position.

Badge
<template>
  <PBadge trailing-icon="i-lucide:arrow-right" size="md">Badge</PBadge>
</template>

Avatar

Use the avatar prop to show an Avatar inside the Badge.

Badge
<template>
  <PBadge
    :avatar="{
      src: 'https://github.com/nuxt.png'
    }"
    size="md"
    color="neutral"
    variant="outline"
  >
    Badge
  </PBadge>
</template>

Examples

class prop

Use the class prop to override the base styles of the Badge.

Badge
<template>
  <PBadge class="font-bold rounded-full">Badge</PBadge>
</template>

API

Props

Prop Default Type

Slots

Slot Type

Theme

We use unocss-variants to customize the theme. Read more about it in the theming guide.

Below is the theme configuration skeleton for the PBadge. Since the component is provided unstyled by default, you will need to fill in these values to apply your own custom look and feel. If you prefer to use our pre-built, opinionated styling, you can instead use our UnoCSS preset, this docs is using it as well.

app.config.ts
export default defineAppConfig({
  pohon: {
    badge: {
      slots: {
        base: '',
        label: '',
        leadingIcon: '',
        leadingAvatar: '',
        leadingAvatarSize: '',
        trailingIcon: ''
      },
      variants: {
        fieldGroup: {
          horizontal: '',
          vertical: ''
        },
        color: {
          primary: '',
          secondary: '',
          success: '',
          info: '',
          warning: '',
          error: '',
          neutral: ''
        },
        variant: {
          solid: '',
          outline: '',
          soft: '',
          subtle: ''
        },
        size: {
          xs: {
            base: '',
            leadingIcon: '',
            leadingAvatarSize: '',
            trailingIcon: ''
          },
          sm: {
            base: '',
            leadingIcon: '',
            leadingAvatarSize: '',
            trailingIcon: ''
          },
          md: {
            base: '',
            leadingIcon: '',
            leadingAvatarSize: '',
            trailingIcon: ''
          },
          lg: {
            base: '',
            leadingIcon: '',
            leadingAvatarSize: '',
            trailingIcon: ''
          },
          xl: {
            base: '',
            leadingIcon: '',
            leadingAvatarSize: '',
            trailingIcon: ''
          }
        },
        square: {
          true: ''
        }
      },
      compoundVariants: [],
      defaultVariants: {
        color: 'primary',
        variant: 'solid',
        size: 'md'
      }
    }
  }
};
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import pohon from 'pohon-ui/vite'

export default defineAppConfig({
  pohon: {
    badge: {
      slots: {
        base: '',
        label: '',
        leadingIcon: '',
        leadingAvatar: '',
        leadingAvatarSize: '',
        trailingIcon: ''
      },
      variants: {
        fieldGroup: {
          horizontal: '',
          vertical: ''
        },
        color: {
          primary: '',
          secondary: '',
          success: '',
          info: '',
          warning: '',
          error: '',
          neutral: ''
        },
        variant: {
          solid: '',
          outline: '',
          soft: '',
          subtle: ''
        },
        size: {
          xs: {
            base: '',
            leadingIcon: '',
            leadingAvatarSize: '',
            trailingIcon: ''
          },
          sm: {
            base: '',
            leadingIcon: '',
            leadingAvatarSize: '',
            trailingIcon: ''
          },
          md: {
            base: '',
            leadingIcon: '',
            leadingAvatarSize: '',
            trailingIcon: ''
          },
          lg: {
            base: '',
            leadingIcon: '',
            leadingAvatarSize: '',
            trailingIcon: ''
          },
          xl: {
            base: '',
            leadingIcon: '',
            leadingAvatarSize: '',
            trailingIcon: ''
          }
        },
        square: {
          true: ''
        }
      },
      compoundVariants: [],
      defaultVariants: {
        color: 'primary',
        variant: 'solid',
        size: 'md'
      }
    }
  }
};

Changelog

No recent changes