小沐沐吖 a2282f51c6
feat(theme): add custom color support for badge components, close #453 (#455)
* feat(theme): add custom color support for badge components

* feat(theme): add custom color support for badge components

* feat(theme): add custom color support for badge components

* feat(theme): add custom color support for badge components

* feat(theme): add custom color support for badge components
2025-02-07 10:48:33 +08:00

2.6 KiB
Raw Blame History

title, author, icon, createTime, permalink
title author icon createTime permalink
徽章 pengzhanbo iconamoon:badge-light 2024/08/18 22:45:50 /guide/components/badge/

概述

使用 <Badge> 组件来显示 行内信息,如状态或标签。

将你想显示的内容传递给 <Badge> 组件的 text 属性。

Props

名称 类型 默认值 说明
type string 'tip' 类型,内置值: 'info' | 'tip' | 'warning' | 'danger',允许自定义
text string '' 文本
color string '' 文本颜色
bg-color string '' 背景颜色
border-color string 'transparent' 边框颜色

示例

输入:

- VuePress - <Badge type="info" text="v2" />
- VuePress - <Badge type="tip" text="v2" />
- VuePress - <Badge type="warning" text="v2" />
- VuePress - <Badge type="danger" text="v2" />
- VuePress - <Badge text="v2" color="red" bg-color="#008c8c" />

输出:

  • VuePress -
  • VuePress -
  • VuePress -
  • VuePress -
  • VuePress -

使用自定义type,可以实现更丰富的表现。

输入:

  1. 在主题任意样式文件中,添加预定的样式:
/* 浅色主题 */
.vp-badge.important {
  color: #cccccc;
  background-color: #f40f40;
  border-color: transparent;
}

/* 深色主题 */
[data-theme="dark"] .vp-badge.important {
  color: #f40f40;
  background-color: #ffffff;
  border-color: transparent;
}

/**
 important 为自定义 type 类型
*/
  1. 使用自定义type
- VuePress - <Badge type="important" text="v2" />

输出:

  • VuePress -