Skip to content

Badge

Number or status mark that appears next to buttons or icons.

Component Type

Display Message Count

Display message count via value, supports number or text.

html
<wd-badge custom-class="badge" :value="12">
  <wd-button :round="false" type="info" size="small">Comments</wd-button>
</wd-badge>
<wd-badge custom-class="badge" :value="3" bg-color="green">
  <wd-button :round="false" type="info" size="small">Replies</wd-button>
</wd-badge>
<wd-badge custom-class="badge" :value="1" type="primary">
  <wd-button :round="false" type="info" size="small">Comments</wd-button>
</wd-badge>
<wd-badge custom-class="badge" :value="2" type="warning">
  <wd-button :round="false" type="info" size="small">Replies</wd-button>
</wd-badge>
<wd-badge custom-class="badge" :value="1" type="success">
  <wd-button :round="false" type="info" size="small">Comments</wd-button>
</wd-badge>
<wd-badge custom-class="badge" :value="2" type="info">
  <wd-button :round="false" type="danger" size="small">Replies</wd-button>
</wd-badge>

Component State

Dot Type

Set is-dot to mark with red dot.

html
<wd-badge custom-class="badge" is-dot>Data Query</wd-badge>
<wd-badge custom-class="badge" is-dot>
  <wd-button :round="false" type="info" size="small">Replies</wd-button>
</wd-badge>

Display Zero Value

Control whether to display when value=0 via show-zero. is-dot has higher priority than show-zero.

html
<wd-badge custom-class="badge" :value="0" show-zero>
  <wd-button :round="false" type="info" size="small">Comments</wd-button>
</wd-badge>
<wd-badge custom-class="badge" :value="0">
  <wd-button :round="false" type="info" size="small">Replies</wd-button>
</wd-badge>
<wd-badge custom-class="badge" :value="0" is-dot>
  <wd-button :round="false" type="info" size="small">Replies</wd-button>
</wd-badge>

Component Variant

Badge Shape

Switch badge shape via shape.

html
<wd-badge custom-class="badge" :value="12" shape="square">
  <wd-button :round="false" type="info" size="small">Square</wd-button>
</wd-badge>
<wd-badge custom-class="badge" :value="12" shape="bubble">
  <wd-button :round="false" type="info" size="small">Bubble</wd-button>
</wd-badge>

Component Style

Definable Max Value

Set max display value via max. Only effective when value is a number.

html
<wd-badge custom-class="badge" :value="200" :max="99">
  <wd-button :round="false" type="info" size="small">Comments</wd-button>
</wd-badge>
<wd-badge custom-class="badge" :value="200" :max="10">
  <wd-button :round="false" type="info" size="small">Replies</wd-button>
</wd-badge>

Special Style

Outlined Badge

Set border to display outlined badge.

html
<wd-badge custom-class="badge" :value="12" border>
  <wd-button :round="false" type="primary" size="small">Outline</wd-button>
</wd-badge>
<wd-badge custom-class="badge" :value="1" border type="primary">
  <wd-button :round="false" type="danger" size="small">Outline</wd-button>
</wd-badge>
<wd-badge custom-class="badge" :value="999" border type="warning">
  <wd-button :round="false" type="success" size="small">Outline</wd-button>
</wd-badge>

Content Form

Custom Content

Set string value to display text content other than numbers.

html
<wd-badge custom-class="badge" value="new">
  <wd-button :round="false" type="info" size="small">Comments</wd-button>
</wd-badge>
<wd-badge custom-class="badge" value="hot">
  <wd-button :round="false" type="info" size="small">Replies</wd-button>
</wd-badge>
scss
:deep(.badge) {
  margin: 0 30px 20px 0;
  display: inline-block;
}

Attributes

ParameterDescriptionTypeDefault Value
valueDisplay valuestring | number-
maxMaximum value, displays {max}+ when exceeded, only effective when value is numbernumber-
topWhen positive, badge offsets downward by corresponding pixelsstring | number-
rightWhen positive, badge offsets leftward by corresponding pixelsstring | number-
is-dotRed dot markbooleanfalse
hiddenHide badgebooleanfalse
typeType, supports primary / success / warning / danger / infostring-
bg-colorBackground colorstring-
show-zeroWhether to display 0booleanfalse
shapeBadge shape, supports circle / square / bubblestringcircle
borderWhether to display white outlinebooleanfalse
custom-classRoot node custom class namestring-
custom-styleRoot node custom stylestring-

Slots

NameDescription
defaultContent wrapped by badge

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-badge-height$n-16徽标高度
--wot-badge-min-width$n-16徽标最小宽度
--wot-badge-padding$padding-zero $padding-super-tight徽标内边距
--wot-badge-danger-bg$danger-main危险类型背景色
--wot-badge-success-bg$success-main成功类型背景色
--wot-badge-warning-bg$warning-main警告类型背景色
--wot-badge-info-bg$filled-content信息类型背景色
--wot-badge-primary-bg$primary-6主类型背景色
--wot-badge-color$text-white徽标文本颜色
--wot-badge-info-color$text-secondary信息类型文本颜色
--wot-badge-font-size$typography-label-size-extra-small徽标文本字号
--wot-badge-line-height$typography-label-line--height-size-extra-small徽标文本行高
--wot-badge-border-radius$radius-radius-full默认圆角
--wot-badge-square-border-radius$radius-main方形圆角
--wot-badge-bubble-border-radius$radius-large $radius-large $radius-large $radius-zero气泡圆角
--wot-badge-dot-size$n-6圆点尺寸
--wot-badge-font-weight$font-weight-medium徽标文本字重
--wot-badge-transformtranslateY(-50%) translateX(50%)固定定位偏移
--wot-badge-border-color$border-white徽标边框颜色

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.