-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme-default): add built-in component
VPBadge
, registerd as g…
…lobal component `Badge`.
- Loading branch information
1 parent
70da5f2
commit e62a100
Showing
6 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Badge | ||
|
||
The badge is like the one with same name in [vuepress](https://vuepress.vuejs.org/guide/using-vue.html#built-in-components), but for vitepress. | ||
|
||
## Usage | ||
|
||
You can use this component in a header to add some status for an API | ||
|
||
```js | ||
### Title <Badge text="info" type="info" /> | ||
### Title <Badge text="tip" type="tip" /> | ||
### Title <Badge text="warning" type="warning" /> | ||
### Title <Badge text="error" type="error" /> | ||
``` | ||
|
||
Code above renders like: | ||
|
||
### Title <Badge text="info" type="info" /> | ||
### Title <Badge text="tip" type="tip" /> | ||
### Title <Badge text="warning" type="warning" /> | ||
### Title <Badge text="error" type="error" /> | ||
|
||
## Custom Children | ||
|
||
`<Badge>` accept `children`, which will be displayed in the badge. | ||
|
||
Give Code like this: | ||
|
||
```js | ||
<script setup> | ||
import { Badge } from 'vitepress/theme' | ||
</script> | ||
|
||
### Title <Badge type="info"><span>custom element</span></Badge> | ||
``` | ||
|
||
You will see | ||
|
||
### Title <Badge type="info"><span>custom element</span></Badge> | ||
|
||
## `<Badge>` | ||
|
||
`<Badge />` accept props: | ||
|
||
- `text`: string | ||
- `type`: string, optional value: `"tip" | "info" | "warning"| "error"`, defaults to `"tip"`. | ||
- `vertical`: string, optional value: `"top"| "middle"`, defaults to `"top"`. | ||
|
||
**P.S** `props.text` would not be used if children given, Actually, the `props.text` is passed as default slot children. | ||
|
||
## Customize Type Color | ||
|
||
The background color of `<Badge />` is determined by css vars. | ||
|
||
```jsx | ||
/* background-color by var(--vp-c-badge-type-warning); */ | ||
<Badge type="warning" /> | ||
|
||
/* background-color by var(--vp-c-badge-type-tip); */ | ||
<Badge type="tip" /> | ||
|
||
/* background-color by var(--vp-c-badge-type-error); */ | ||
<Badge type="error" /> | ||
|
||
/* background-color by var(--vp-c-badge-type-info); */ | ||
<Badge type="info" /> | ||
``` | ||
|
||
you can customize `background-color` of typed `<Badge />` by override css vars. | ||
|
||
```css | ||
:root { | ||
--vp-c-badge-type-error: red; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script setup lang="ts"> | ||
const props = withDefaults( | ||
defineProps<{ | ||
text?: string, | ||
type?: 'warning' | 'tip' | 'error' | 'info' | ||
vertical?: 'top' | 'middle' | ||
}>(), { | ||
text: '', | ||
type: 'tip', | ||
vertical: 'top', | ||
} | ||
); | ||
</script> | ||
|
||
<template> | ||
<span | ||
class='VPBadge' | ||
:class="[ `VPBadge-type-${props.type}` ]" | ||
:style="{ 'vertical-align': props.vertical }" | ||
> | ||
<slot>{{ props.text }}</slot> | ||
</span> | ||
</template> | ||
|
||
<style scoped> | ||
.VPBadge { | ||
display: inline-block; | ||
font-size: 14px; | ||
height: 18px; | ||
line-height: 18px; | ||
border-radius: 3px; | ||
padding: 0 6px; | ||
color: #fff; | ||
} | ||
.VPBadge.VPBadge-type-warning { | ||
background-color: var(--vp-c-badge-type-warning); | ||
} | ||
.VPBadge.VPBadge-type-tip { | ||
background-color: var(--vp-c-badge-type-tip); | ||
} | ||
.VPBadge.VPBadge-type-error { | ||
background-color: var(--vp-c-badge-type-error); | ||
} | ||
.VPBadge.VPBadge-type-info { | ||
background-color: var(--vp-c-badge-type-info); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters