MazBadge
MazBadge is a standalone component to show short text in colored container
Before use it, you should install the MazUi plugin in your project, follow instructions in Getting Started
Basic usage
<script lang="ts" setup>
import MazBadge from 'maz-ui/components/MazBadge'
</script>
<template>
<MazBadge>
Badge
</MazBadge>
</template>Options
See all options props here
Colors
<script lang="ts" setup>
import MazBadge from 'maz-ui/components/MazBadge'
const colors = [
'primary',
'secondary',
'info',
'success',
'warning',
'destructive',
'contrast',
'accent',
'surface',
'container',
'transparent',
]
</script>
<template>
<MazBadge v-for="color in color" :key="color" :color="color">
{{ color }}
</MazBadge>
</template>Outlined
<script lang="ts" setup>
import MazBadge from 'maz-ui/components/MazBadge'
const colors = [
'primary',
'secondary',
'info',
'success',
'warning',
'destructive',
'contrast',
'accent',
'surface',
'container',
'transparent',
]
</script>
<template>
<MazBadge v-for="color in color" :key="color" :color="color" outlined>
{{ color }}
</MazBadge>
</template>Pastel
<script lang="ts" setup>
import MazBadge from 'maz-ui/components/MazBadge'
const colors = [
'primary',
'secondary',
'info',
'success',
'warning',
'destructive',
'contrast',
'accent',
'surface',
'container',
'transparent',
]
</script>
<template>
<MazBadge v-for="color in color" :key="color" :color="color" pastel>
{{ color }}
</MazBadge>
</template>Size
The size prop accepts one of the standardized MazSize values ('mini' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'). The default is 'md'. Padding, line-height and dimensions all scale relative to the chosen font-size, so a single keyword controls the whole badge footprint.
<script lang="ts" setup>
import MazBadge from 'maz-ui/components/MazBadge'
const sizes = ['mini', 'xs', 'sm', 'md', 'lg', 'xl']
</script>
<template>
<MazBadge v-for="size in sizes" :key="size" :size="size">
{{ size }}
</MazBadge>
</template>Rounded sizes
<script lang="ts" setup>
import MazBadge from 'maz-ui/components/MazBadge'
const roundedSize = ['none', 'sm', 'md', 'lg', 'xl', 'full']
</script>
<template>
<MazBadge v-for="size in roundedSize" :key="size" :rounded-size="size">
{{ size }}
</MazBadge>
</template>Removable
Add removable to show a remove button at the end of the badge: it emits remove with the click event and has an accessible label ("Remove", translated), which you can change with remove-label. The button uses the color of the badge text and a visible focus ring, so it works with every color and with outlined and pastel.
Last removed: none
<script lang="ts" setup>
import MazBadge from 'maz-ui/components/MazBadge'
import { ref } from 'vue'
const tags = ref(['Vue', 'Nuxt', 'Vite'])
function removeTag(tag: string) {
tags.value = tags.value.filter(t => t !== tag)
}
</script>
<template>
<MazBadge v-for="tag in tags" :key="tag" removable @remove="removeTag(tag)">
{{ tag }}
</MazBadge>
</template>Props
| Name | Description | Type | Required | Default | Possible values |
|---|---|---|---|---|---|
| color | Color of the badge: surface and container are the neutral colors of the theme, with the foreground text | MazBadgeColor | No | "primary" | 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'destructive' | 'contrast' | 'transparent' | 'surface' | 'container' |
| size | Size of the badge - drives font-size; padding, line-height and dimensions scale relative to it via em units. | "xs" | "sm" | "md" | "lg" | "xl" | "mini" | No | md | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'mini' |
| nowrap | Will not wrap the text | boolean | No | true | - |
| outlined | Will add a border to the badge | boolean | No | false | - |
| pastel | Will add a pastel style to the badge | boolean | No | false | - |
| rounded-size | Size radius of the component's border | MazBadgeRoundedSize | No | md | 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full' |
| removable | Will add a remove button at the end of the badge, which emits remove | boolean | No | false | - |
| remove-label | Accessible label of the remove button (translated "Remove" by default) | string | No | - | - |
Events
| Event name | Payload | Description |
|---|---|---|
| remove | event: MouseEvent | Emitted when the remove button is clicked (removable only) |
Slots
| Name | Description | Bindings |
|---|---|---|
| default | Badge content | - |