Badge
A small label for a status, a count or a tag.
import { Badge } from 'patine-ui';
<List title="Recent orders" style={{ maxWidth: 440, width: '100%' }}> {ORDERS.map((order) => ( <ListItem key={order.id} title={`${order.id} · ${order.customer}`} description={order.total} trailing={<Badge variant={VARIANT[order.status]}>{order.status}</Badge>} onPress={() => {}} /> ))} </List>
Try the props
variantdesign<Badge>In stock</Badge>
Example: a support queue
A help desk's ticket list: the filter shows how many tickets each view holds, and each ticket carries its priority and whether it breached its reply time.
<VStack gap="md" style={{ width: '100%', maxWidth: 480 }}> <SegmentedControl value={view} onValueChange={setView} items={VIEWS.map((v) => ({ value: v, label: `${v[0].toUpperCase()}${v.slice(1)} (${count(v)})` }))} /> <List> {TICKETS.filter((t) => t.status === view).map((t) => ( <ListItem key={t.id} title={t.subject} description={`#${t.id} · ${t.customer}`} trailing={ <HStack gap="xs"> {t.late ? <Badge variant="outline">Overdue</Badge> : null} <Badge variant={PRIORITY[t.priority]}>{t.priority}</Badge> </HStack> } onPress={() => {}} /> ))} </List> </VStack>
Variants
default is the theme's primary color. secondary and outline are quiet, for tags and versions. success, warning and destructive are for status.
<HStack gap="sm" wrap> <Badge>New</Badge> <Badge variant="secondary">Draft</Badge> <Badge variant="outline">v2.4.0</Badge> <Badge variant="success">Paid</Badge> <Badge variant="warning">Pending</Badge> <Badge variant="destructive">Overdue</Badge> </HStack>
Counts
A badge can hold a number, such as unread messages. Pin it to a corner with a wrapping View, and cap big numbers ("99+").
<HStack gap="xl" align="center" style={{ paddingTop: 10 }}> {[ { icon: 'bell', label: 'Notifications', n: 3 }, { icon: 'messageSquare', label: 'Messages', n: 128 }, { icon: 'cart', label: 'Cart', n: 0 }, ].map(({ icon, label, n }) => ( <View key={label}> <Button size="icon" variant="outline" accessibilityLabel={n ? `${label}, ${n} new` : label}> <Icon name={icon} /> </Button> {n ? ( <Badge variant="destructive" style={{ position: 'absolute', top: -8, right: -10 }} accessibilityElementsHidden importantForAccessibility="no-hide-descendants"> {count(n)} </Badge> ) : null} </View> ))} </HStack>
With an icon
children can be any node, so a badge can carry an icon or a dot before its label.
<HStack gap="sm" wrap> <Badge variant="outline"> <HStack gap="xs" align="center"> <Dot color="#22C55E" /> <Text size="xs" weight="medium">All systems operational</Text> </HStack> </Badge> <Badge variant="secondary"> <HStack gap="xs" align="center"> <Icon name="star" size={12} /> <Text size="xs" weight="medium">Featured</Text> </HStack> </Badge> <Badge variant="success"> <HStack gap="xs" align="center"> <Icon name="check" size={12} color="success" /> <Text size="xs" weight="medium">Verified</Text> </HStack> </Badge> </HStack>
Tags
A row of outline or secondary badges tags a post or a product. For tags people can pick, use a ChipGroup instead: a badge isn't pressable.
<Card style={{ maxWidth: 380, width: '100%' }}> <CardHeader> <HStack gap="sm" align="center"> <CardTitle>Building a design system in React Native</CardTitle> </HStack> <CardDescription>8 min read · March 12</CardDescription> </CardHeader> <CardContent> <HStack gap="xs" wrap> {['React Native', 'Design systems', 'Accessibility', 'Expo'].map((tag) => ( <Badge key={tag} variant="outline">{tag}</Badge> ))} </HStack> </CardContent> </Card>
Custom colors
theme recolors a variant, and style and labelStyle reach the box and the text, for a brand color or a bigger badge.
<HStack gap="sm" wrap align="center"> <Badge theme={{ colors: { primary: '#7C3AED' } }}>Pro</Badge> <Badge style={{ backgroundColor: '#0EA5E9', borderColor: '#0EA5E9' }} labelStyle={{ color: '#fff' }}>Beta</Badge> <Badge variant="outline" style={{ paddingHorizontal: 12, paddingVertical: 4 }} labelStyle={{ fontSize: 14 }}>Large</Badge> </HStack>
Accessibility
- A badge is text, read where it sits, after the content around it.
- Don't rely on its color alone: the label should say the status ("Overdue", not just a red dot).
- A count pinned to a button belongs in the button's
accessibilityLabel("Messages, 128 new"); hide the badge itself from screen readers so it isn't read twice, as in Counts. - A badge isn't pressable. For something people tap, use a Button or a ChipGroup.
Props
Badge also takes View props.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | The label. A string is drawn in the variant's color. |
variant | 'default' | 'secondary' | 'outline' | 'success' | 'warning' | 'destructive' | 'default' | The look. |
labelStyle | StyleProp<TextStyle> | — | The label's text. |
theme | DeepPartial<Theme> | — | Theme override. |
design | 'brand' | 'ios' | 'material' | 'web' | 'native' | from PatineProvider | The look to follow: brand, iOS, Material or web, or 'native' for the platform's own. |