Components
Badge

Badge

The Badge component is a versatile UI element designed to display notifications, counts, or statuses. It is highly customizable through a variety of props, allowing for different appearances and behaviors. Below is a detailed description of each prop and its usage.

Import

import { VKBadge } from "@vivakits/react-components";

Variant

The variant prop determines the overall style and appearance of the badge. The variant prop allows to choose from 2 predefined styles, square and circular, which can provide different visual effects and suit various design requirements.

Size

The size prop controls the size of the badge. It accepts 6 predefined sizes such as xs sm md lg xl and 2xl. This allows precise control over the badge's dimensions to fit different UI elements.

Color

The color prop sets the background color of the badge. There are 7 predefined colors offered for the background of the badge to match applications theme or usage of the badge.

With border

Determines whether the badge has a border. When withBorder is set to true, the badge will display a border whose color can be customized using the borderColor prop. This can help the badge stand out more prominently against its background.

Border color

borderColor defines the color of the badge's border. This prop is particularly useful when withBorder is set to true, as it allows to specify a distinct color for the border, enhancing the visual distinction of the badge.

Placement

The placement pecifies the position of the badge relative to its container element. The placement prop enables you to place the badge at various positions, such as "top-right" or "bottom-left", ensuring it appears exactly where you need it within the UI layout. There are 4 predefined varieties available.

Invisible

invisible controls the visibility of the badge. When invisible is set to true, the badge will not be rendered visually but will remain in the DOM. This is useful for scenarios where you want to hide the badge temporarily without removing it from the layout. By default the value is set to false.

Content

The content to be displayed inside the badge. The content prop can include text, icons, or any other React elements, allowing for versatile and dynamic badge contents that can convey various types of information.

9

Show Zero

The showZero prop determines whether to display the badge when the content value is zero. When set to false, the badge will be hidden for zero values.

0

Show Plus Symbol

The showPlusSymbol prop adds a plus symbol after the numeric content. This is useful for indicating additional items beyond the displayed number. When combined with numbers greater than 99, it will show as "99+" regardless of the showPlusSymbol value

5+
99+

Style

The badgeStyle prop allows to apply inline CSS styles directly to the badge element. This provides granular control over the badge's appearance.

Example

Here are some examples of how Badge component can be used with the different props.

9
person with camera
100
5

API Reference

AttributeTypeDescriptionDefault
childrenReactNodeDisplays badge content -
variantcircularsquareChanges badge appreancesquare
colorprimarysecondarysuccessdangerwarningdarklightChanges badge colorsuccess
borderColorprimarysecondarysuccessdangerwarningdarklightChanges badge bordercolordefault
sizexssmmdlgxl2xlChanges button sizemd
onClickfunctionDefines functionality on clicking the badge -
invisiblebooleanChanges visibility of the badge false
withBorderbooleanChanges visibility of border of badge false
showZerobooleanControls visibility of badge content when content is zerotrue
showPlusSymbolbooleanAdds plus symbol after numeric contentfalse
containerRefRefObject | nullUsed to pass a reference to the container element that the badge component should be appended to -
containerPropObjectUsed to specify additional properties to be applied to the container element of the badge component -
classNameCSSAdditional CSS class(es) to apply to the components -
badgeStyleReact.CSSPropertiesApplies custom inline styles to the badge component -