data-display/DSBadge

DSBadge

data-display
since v1.0

Compact label with 3 visual variants (filled, soft, outline), gradient support, and 3 size options.

iOS 17+macOS 14+watchOS 10+

Purpose

Status indicators, notification counts, and category labels with optional gradient styling.

Variants

Filled

.filled

Solid background. High contrast.

Soft

.soft

Tinted background with matching text. Default.

Outline

.outline

Border only. Lightest visual weight.

Props

PropTypeDefaultDescription
labelreqStringBadge text.
variantDSBadgeVariant.softVisual style.
colorColorDSColor.primarySemantic colour (used if gradient is nil).
gradientLinearGradient?nilOptional gradient (overrides color for filled variant).
iconString?nilOptional leading SF Symbol.
sizeDSBadgeSize.mdBadge size: .sm, .md, or .lg.

Examples

Status badges

Order statuses in a list.

swift
DSBadge("Active", color: DSColor.success)
DSBadge("Pending", color: DSColor.warning)
DSBadge("Cancelled", variant: .outline, color: DSColor.error)

Notification count

Badge with count on navigation item.

swift
HStack {
    Image(systemName: "bell")
    DSBadge("3", variant: .filled, color: DSColor.error, size: .sm)
}

Category badges with gradients

Use DSColor.Category for themed badges.

swift
HStack {
    DSBadge("Chest", category: .category1, icon: "figure.arms.open")
    DSBadge("Back", category: .category2, icon: "figure.walk")
    DSBadge("Legs", category: .category3, icon: "figure.run")
}

Different sizes

Small, medium, and large badges.

swift
VStack(alignment: .leading, spacing: 8) {
    DSBadge("Small", size: .sm)
    DSBadge("Medium", size: .md)
    DSBadge("Large", size: .lg, icon: "star.fill")
}

Composition: Card with badges

Product card with multiple status badges.

swift
DSCard {
    VStack(alignment: .leading, spacing: DSSpacing.sm) {
        HStack {
            Text(product.name)
                .font(.system(size: 16, weight: .semibold))
            Spacer()
            DSBadge("New", variant: .filled, color: DSColor.info)
        }
        
        HStack {
            DSBadge("In Stock", icon: "checkmark", color: DSColor.success)
            DSBadge("Sale", color: DSColor.accent)
        }
    }
}

When to Use

✓ Use DSBadge for:

  • Status indicators (Active, Pending, Completed)
  • Notification counts on icons or tabs
  • Category labels that are read-only
  • Version tags or feature flags

✗ Avoid using for:

  • Interactive filters (use DSChip instead)
  • Removable tags (use DSTag with onRemove)
  • Large text labels (use Text with background)
  • Status with icons and longer text (use DSStatusLabel)

Consider instead:

DSChip

For interactive, selectable filters

DSTag

For removable category tags

DSStatusLabel

For status with icon and more context

Accessibility

VoiceOver

Announces label and color context (e.g., 'Active, Badge, Success')

Keyboard

  • Not interactive - no keyboard controls

Dynamic Type

✓ Supported

Contrast

WCAG AA compliant for all variants

Traits

.isStaticTextColor conveyed via label when needed

Related Components