suiss/uim · React Native Component

Badge

A small label for a status, count or category, with an optional icon.

Badge is an open-source mobile component from suiss/uim for React Native and Expo, with SwiftUI and Jetpack Compose versions built from the same design tokens. The @esuiss/uim CLI copies its source into your project, so you own the code.

iOS
Badge on iOS in light mode

Badge is a compact pill View that passes a small, bold text style and a 12-point icon size to its children. Six variants are available. default, secondary, destructive and link show colored text with no background, while outline adds a hairline border and ghost adds horizontal padding.

Use default for highlighted labels, secondary for neutral metadata, destructive for errors and outline when the badge needs a visible edge.

Installation

$ pnpm dlx @esuiss/uim@latest add badge

The CLI also adds what it builds on: Icon, Text.

Manual

  1. Install the dependencies:
npx expo install class-variance-authority cn
  1. Add the pieces it builds on: Icon, Text, and the primitives components/primitives/types.tsx, components/primitives/use-render.tsx.

  2. Copy the source into components/ui/badge.tsx:

uniwind/components/ui/badge.tsx
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
import { View } from "react-native"
import type { RenderProp } from "@/components/primitives/types"
import { useRender } from "@/components/primitives/use-render"
import { IconClassContext } from "@/components/ui/icon"
import { TextClassContext } from "@/components/ui/text"

const badgeVariants = cva(
  "h-5 shrink-0 flex-row items-center justify-center gap-1 self-start overflow-hidden rounded-full border border-transparent",
  {
    variants: {
      variant: {
        default: "",
        secondary: "",
        destructive: "",
  1. Update the import paths to match your project.

Usage

import { Badge } from "@/components/ui/badge"
<View className="flex-row">
  <Badge>
    <Text>Badge</Text>
  </Badge>
</View>

Put the label in a Text and icons in an Icon. Use render to render the badge as a different component, such as a Pressable, while keeping its styles.

badgeVariants and badgeTextVariants are also exported if you need the classes on another element.

Examples

Variants

All six variants side by side.

iOS
Badge (variants) on iOS in light mode

With icon

Badges with a leading icon.

iOS
Badge (with icon) on iOS in light mode

API Reference

Badge

ExtendsBadgeProps

Accessibility

  • The badge adds no role; it is read as plain text.
  • If you render it as a pressable element, give that element a role and label.

Notes

  • Text colors come from text-link, text-label-secondary, text-danger and text-label; light and dark follow the system appearance.