Ant Design Svelte

Badge

Numeric indicators, dots, statuses and ribbons: overflow, offset, topics and notifications.

When to use

Badge shows low quantity, updates or status near the item. It is suitable for unread messages, tasks and service status. BadgeRibbon adds a ribbon to a card. Color should be accompanied by text if it makes sense.

Number, point and status

count accepts a number, string or snippet. The number is limited by overflowCount, default is 99; displaying 99+ does not change the original quantity. Zero is hidden until showZero is enabled.

Problem Setting Example
Show number and explicit zero count, showZero Main counter
Print a number without an object without children Separate indicator
Limit long number overflowCount Display limit
Mark new events dot Dot
Sign State status, text Statuses
Add feed BadgeRibbon Card strips

dot replaces a number with a dot; numeric count=0 also hides it. status selects success/processing/default/error/warning, color sets its own color. text explains the meaning of the state. size changes the normal or small indicator.

Content Linking and Accessibility

With children, the indicator is located near the nested object; without children participates in the normal flow. offset shifts the indicator itself in X/Y, maintaining the position of the content. String values ​​have parsing features described in the API; for a simple offset, use a number pair.

Children-snippet receives count and descriptionId. count remains a number for numeric input only: string and snippet are not automatically converted. descriptionId allows you to associate a button with a quantity description via aria-describedby, as in dynamic example.

For your own count-snippet, apply the resulting class and style to its root. Otherwise, the offset and semantic design will be lost. title specifies a native tooltip; null/false remove it. The tooltip does not replace the available button name or text explanation of the status.

Badge by itself does not create a link: the interactivity is in children. Keep the href and keyboard of the nested control.

Ribbon and theme

BadgeRibbon is exported separately. text is the content of the feed, children is the card being designed, placement:start/end follows the direction of the interface. class/style refers to the feed, semantic root refers to the outer wrapper of the content.

ConfigProvider.badge and ConfigProvider.ribbon are configured independently. classNames/styles support root/indicator for Badge and root/content/indicator for ribbon; styles contains CSS strings. Badge component design tokens control counter height, point, and typography. Native refs are available via bind:nativeElement.

A non-empty local prefixCls changes Badge classes; the empty string and undefined inherit ConfigProvider.prefixCls with the -badge suffix. ScrollNumber separately enables scrollNumberPrefixCls, otherwise it uses a common prefix with the suffix -scroll-number. Local Badge.prefixCls does not rename numbers. CSS ScrollNumber is bound to the global prefix, not the local scrollNumberPrefixCls. BadgeRibbon inherits the -ribbon suffix; its local prefixCls changes DOM classes, and the CSS geometry follows the global prefix. Example ConfigProvider shows inheritance and local Badge exception.

Examples

Count: 5 Count: 0

Counter and zero value

Zero is hidden by default; showZero leaves it visible. Snippet defines its own indicator.

Count: 11 Count: 25 Count: 100

Self Badge

Without children, the counter is in the normal page flow.

Count: 99 Count: 100 Count: 11 Count: 1000

Limit value

The number above overflowCount is displayed with a plus; the original value is retained in the description.

Updates available New version Updates available

Dot instead of number

dot indicates the presence of updates. The numeric count=0 hides the point.

Count: 5

Quantity: 5. Open: 0.

Changing the counter

Buttons change the quantity, Switch replaces the number with a dot. The available description is attached to the button via children Snippet.

Count: 5

Indicator offset

offset sets the X and Y offset without changing the position of the content.

Count: 5 Count: 5 Count: 25 Count: 25

Indicator dimensions

Regular and small meters, including independent ones.

Success Готово Processing В работе Default status Не запущено Error Ошибка Warning Требует внимания

States

Five statuses; the text explains the meaning of the color.

Updates available pink Updates available red Updates available yellow Updates available orange Updates available cyan Updates available green Updates available blue Updates available purple Updates available geekblue Updates available magenta Updates available volcano Updates available gold Updates available lime Updates available#23734aUpdates availablergb(173,78,0)

Palette and custom colors

Named colors and custom CSS colors with explanatory text.

Tape at the end of the line.

Recommended

Tape at the beginning of the line.

New

Start of line on the right.

RTL

Tapes

BadgeRibbon places a ribbon on the Card; start and end follow the direction of the text.

Count: 12
Feed content.
Own style

Semantic DOM

styles for root/indicator and root/content/indicator; CSS values ​​are given by strings.

Count: 7Updates available
General ribbon settings.
Local topic

Local topic

Badge tokens change height and point only inside the ConfigProvider. The ribbon setting is responsible for ribbons.

Count: 5
Success success Processing processing Default status default Error error Warning warning
Presses: 0.

Notifications

Count: 2

Unread: 2. Total messages: 3.

Project Notifications

Saved example: settings, adding messages, reading and Drawer.

API

Examples are checked against the current ant.design page and the public API of the installed package. Full definitions of Props are in @woodger/antd.

Topics of official examples
ThemeExample or limitation
BasicNumber, showZero and an arbitrary indicator.
StandaloneNo child content.
Overflow CountDifferent overflow thresholds.
Red badgePoint and zero value.
DynamicControlled counter and dot switching.
ClickableThis link with description.
OffsetVariable X/Y.
Sizemedium/small.
StatusAll five statuses.
Colorful BadgeNamed palette and CSS colors.
RibbonTape, placement and RTL.
Custom semantic dom stylingBadge and BadgeRibbon.
Basic parameters Badge
PropertyDescriptionTypeDefault
scrollNumberPrefixClsClasses ScrollNumber and its digits, independent of Badge.prefixCls. The empty string inherits the common prefix. CSS ScrollNumber follows a global prefix, not this local prop.stringConfigProvider + -scroll-number
prefixClsFull local CSS prefix for root and Badge indicator; ScrollNumber is resolved separately. The empty string and undefined inherit ConfigProvider.prefixCls; default ant-badge.stringConfigProvider + -badge
countNumber, string or Snippet with class/style for the indicator root.BadgeCount—
overflowCountDisplay threshold N+.number99
showZeroShow zero counter.booleanfalse
dotDot instead of number.booleanfalse
statussuccess, processing, default, error, warning.BadgeStatus—
colorNamed or custom CSS color.string—
textLabel of status or colored dot.BadgeText—
sizeSize of the numeric indicator.medium | smallmedium
offsetShift of the indicator along X/Y.[number | string, number | string]—
titleNative tooltip; false/null disables it.string | false | nullnumber
childrendescriptionId associates interactive content with the counter.Snippet<[BadgeContext]>—
stylesCSS lines for root/indicator, record or callback.BadgeSemantic—
classNamesClasses for root/indicator.BadgeSemantic—
nativeElementbind:nativeElement instead of ref.HTMLSpanElement—

BadgeRibbon

text and children accept a string, number or Snippet. color sets the color of the ribbon; placement - start/end, end by default. styles and classNames support record or callback with props.

prefixCls changes Ribbon DOM classes. The empty string and undefined inherit ConfigProvider.prefixCls + -ribbon, default ant-ribbon. Ribbon geometry CSS follows the general provider prefix, regardless of the local prop; For point-by-point styling, use semantic styles.

Semantic DOM

Badge contains root and indicator. BadgeRibbon: root - content wrapper, indicator - tape, content - its text. Ribbon's regular class/style refers to the ribbon, not the entire card.

For a button or link use children Snippet with descriptionId and aria-describedby. Color and dot alone do not explain the condition; add text. Badge does not turn the content into a button.

Registration tokens

theme.components.Badge customizes indicator sizes and typography. ConfigProvider.badge and ConfigProvider.ribbon define local classes and semantic styles; The component's own settings take precedence.

Component tokens
TokenPurpose
dotSizePoint diameter.
indicatorHeightHeight of a conventional counter.
indicatorHeightSMHeight of small counter.
indicatorZIndexIndicator layer.
paddingInlineHorizontal text indents.
statusSizeDiameter of status point.
textFontSizeText size.
textFontSizeSMSmall indicator text.
textFontWeightText saturation.
Common tokens of the current topic
TokenCurrent value
colorError#ff4d4f
colorSuccess#52c41a
colorWarning#faad14
colorTextrgba(0,0,0,0.88)
colorTextLightSolid#fff
colorBorderBg#ffffff
fontSize14
lineHeight1.5714285714285714

FAQ

Why is zero visible?

Zero is hidden by default. Add showZero. dot with numeric count=0 is also hidden.

How to replace an indicator with your own content?

Pass count-snippet and transfer the resulting class/style to its root. The number of children contexts from such a snippet is not calculated.

How to use Badge.Ribbon in Svelte?

Import BadgeRibbon. The content is specified by values ​​or snippets, semantic styles - by CSS strings.