Components
Badge

Badge

A small count and labeling component used to highlight an status.

Usage

Park UI
import { Badge, type BadgeProps } from '~/components/ui/badge'

export const Demo = (props: BadgeProps) => {
  return <Badge {...props}>Park UI</Badge>
}

Installation

1

Add Component

Insert code snippet into your project. Update import paths as needed.

import { ark } from '@ark-ui/react/factory'
import type { ComponentProps } from 'react'
import { styled } from 'styled-system/jsx'
import { badge } from 'styled-system/recipes'

export const Badge = styled(ark.div, badge)
export interface BadgeProps extends ComponentProps<typeof Badge> {}
2

Add Recipe

This step is necessary only if you do not use any of the Park UI plugins.

import { defineRecipe } from '@pandacss/dev'

export const badge = defineRecipe({
  className: 'badge',
  base: {
    alignItems: 'center',
    borderRadius: 'full',
    colorPalette: 'accent',
    display: 'inline-flex',
    fontWeight: 'medium',
    userSelect: 'none',
    whiteSpace: 'nowrap',
  },
  defaultVariants: {
    variant: 'subtle',
    size: 'md',
  },
  variants: {
    variant: {
      solid: {
        background: 'colorPalette.default',
        color: 'colorPalette.fg',
      },
      subtle: {
        background: 'bg.subtle',
        borderColor: 'border.subtle',
        borderWidth: '1px',
        color: 'fg.default',
        '& svg': {
          color: 'fg.muted',
        },
      },
      outline: {
        borderWidth: '2px',
        borderColor: 'border.default',
      },
    },
    size: {
      sm: {
        textStyle: 'xs',
        px: '2',
        h: '5',
        gap: '1',
        '& svg': {
          width: '3',
          height: '3',
        },
      },
      md: {
        textStyle: 'xs',
        px: '2.5',
        h: '6',
        gap: '1.5',
        '& svg': {
          width: '4',
          height: '4',
        },
      },
      lg: {
        textStyle: 'sm',
        px: '3',
        h: '7',
        gap: '1.5',
        '& svg': {
          width: '4',
          height: '4',
        },
      },
    },
  },
})

Previous

Avatar

On this page