Looking for documentation on gluestack-ui v2 with NativeWind? Refer to this link.
This is an illustration of a Themed Badge component with default configuration.
size
variant
borderRadius
action
<Badge size="md" variant="solid" borderRadius="$none" action="success">
<BadgeText>New feature</BadgeText>
<BadgeIcon as={GlobeIcon} ml="$2" />
</Badge>

API Reference

Import

To use this component in your project, include the following import statement in your file.
import { Badge } from "@gluestack-ui/themed"

Anatomy

The structure provided below can help you identify and understand a badge component's various parts.
export default () => (
<Badge>
<BadgeText />
<BadgeIcon />
</Badge>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

Badge

It inherits all the properties of React Native's View component.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_text
Prop to style BadgeText Component
_icon
Prop to style BadgeIcon Component

BadgeText

It inherits all the properties of React Native's Text component.

BadgeIcon

Contains all Icon related layout style props and actions. It inherits all the properties of gluestack Style's AsForwarder component.

Themed

The themed version of the component is a pre-styled version of the component, which allows you to quickly integrate the component into your project. The component's design and functionality are fully defined, allowing you to focus on the more important aspects of your project. To know more about Themed Library please visit this link.

Props

Badge component is created using View component from react-native. It extends all the props supported by React Native View, utility props and the props mentioned below.

Badge

Name
Value
Default
action
error | warning | success | info | muted
success
variant
solid | outline
solid
size
sm | md | lg
md
Note: These props are exclusively applicable when utilizing the default configuration of gluestack-ui/config. If you are using a custom theme, these props may not be available.

Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

Badge with Avatar

An example of the Badge component being used with the Avatar component to display badges alongside user avatars for enhanced visual representation or identification.
<VStack space="2xl">
<HStack space="md">
<Avatar>
<AvatarFallbackText>SS</AvatarFallbackText>
<AvatarImage
source={{
uri: "https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8dXNlcnxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800&q=60",
}}
/>
</Avatar>
<VStack>
<HStack>
<Heading size="sm">Ronald Richards</Heading>
<Badge size="sm" variant="solid" action="success" ml="$1">
<BadgeText>Verified</BadgeText>
<BadgeIcon as={BadgeCheckIcon} ml="$1" />
</Badge>
</HStack>
<Text size="sm">Nursing Assistant</Text>
</VStack>
</HStack>
</VStack>

Badge in Menu

A Badge component used with a menu adds a visual indicator, such as a badge, to highlight specific items or provide additional information within the menu, enhancing user interaction and improving the visibility of important elements.
<Menu
placement={"top"}
trigger={({ ...triggerProps }) => {
return (
<Button {...triggerProps}>
<ButtonText>Menu</ButtonText>
</Button>
)
}}
>
<MenuItem key="Community" textValue="Community">
<HStack space="sm" alignItems="center">
<Icon as={GlobeIcon} size="sm" />
<Text fontSize="$sm" lineHeight="$md">
Community
</Text>
</HStack>
</MenuItem>
<MenuItem key="Plugins" textValue="Plugins">
<HStack space="sm" alignItems="center">
<Icon as={PuzzleIcon} size="sm" />
<Text fontSize="$sm" lineHeight="$md">
Plugins
</Text>
</HStack>
</MenuItem>
<MenuItem key="Theme" textValue="Theme">
<HStack space="sm" alignItems="center">
<Icon as={PaintBucket} size="sm" />
<Text fontSize="$sm" lineHeight="$md">
Theme
</Text>
<Badge bg="$backgroundLight600">
<BadgeText color="$textLight50">New</BadgeText>
</Badge>
</HStack>
</MenuItem>
<MenuItem key="Settings" textValue="Settings">
<HStack space="sm" alignItems="center">
<Icon as={SettingsIcon} size="sm" />
<Text fontSize="$sm" lineHeight="$md">
Settings
</Text>
</HStack>
</MenuItem>
<MenuItem key="Add account" textValue="Add account">
<HStack space="sm" alignItems="center">
<Icon as={AddIcon} size="sm" />
<Text fontSize="$sm" lineHeight="$md">
Add account
</Text>
</HStack>
</MenuItem>
</Menu>

Badge Composition

An example of the Badge component being used with the Composition component, allowing for the display of badges within a composition of other UI elements.
<Box alignItems="center">
<VStack>
<Badge
h={22}
w={22}
bg="$red600"
borderRadius="$full"
mb={-14}
mr={-14}
zIndex={1}
variant="solid"
alignSelf="flex-end"
>
<BadgeText color="$white">2</BadgeText>
</Badge>
<Button>
<ButtonText>Notifications</ButtonText>
</Button>
</VStack>
</Box>

Unstyled

All the components in gluestack-ui are unstyled by default. To customize your UI using the extendedTheme, please refer to this link. The import names of components serve as keys to customize each component.

Spec Doc

Explore the comprehensive details of the Badge in this document, including its implementation details, checklist, and potential future additions. Dive into the thought process behind the component and gain insights into its development journey.