Skip to content

Commit 10fb843

Browse files
feat(Badge): add support within button groups (#3224)
Co-authored-by: Benjamin Canac <[email protected]>
1 parent deddc7c commit 10fb843

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<UButtonGroup>
3+
<UBadge color="neutral" variant="outline" size="lg" label="https://" />
4+
5+
<UInput color="neutral" variant="outline" placeholder="www.example.com" />
6+
</UButtonGroup>
7+
</template>

docs/content/3.components/button-group.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,22 @@ slots:
8484

8585
### With tooltip
8686

87-
You can use a tooltip within a button group.
87+
You can use a [Tooltip](/components/tooltip) within a button group.
8888

8989
:component-example{name="button-group-tooltip-example"}
9090

9191
### With dropdown
9292

93-
You can use a dropdown menu within a button group.
93+
You can use a [DropdownMenu](/components/dropdown-menu) within a button group.
9494

9595
:component-example{name="button-group-dropdown-example"}
9696

97+
### With badge
98+
99+
You can use a [Badge](/components/badge) within a button group.
100+
101+
:component-example{name="button-group-badge-example"}
102+
97103
## API
98104

99105
### Props

playground/app/pages/components/button-group.vue

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ const sizes = Object.keys(theme.variants.size) as Array<keyof typeof theme.varia
4747
Button
4848
</UButton>
4949
</UButtonGroup>
50+
51+
<UButtonGroup>
52+
<UBadge color="neutral" variant="outline" size="lg" label="https://" />
53+
<UInput color="neutral" variant="outline" placeholder="www.example.com" />
54+
</UButtonGroup>
5055
</div>
5156

5257
<div class="flex gap-4 items-center justify-center">

src/runtime/components/Badge.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface BadgeSlots {
3838
<script setup lang="ts">
3939
import { computed } from 'vue'
4040
import { Primitive } from 'reka-ui'
41+
import { useButtonGroup } from '../composables/useButtonGroup'
4142
import { useComponentIcons } from '../composables/useComponentIcons'
4243
import UIcon from './Icon.vue'
4344
import UAvatar from './Avatar.vue'
@@ -47,12 +48,14 @@ const props = withDefaults(defineProps<BadgeProps>(), {
4748
})
4849
defineSlots<BadgeSlots>()
4950
51+
const { orientation, size: buttonGroupSize } = useButtonGroup<BadgeProps>(props)
5052
const { isLeading, isTrailing, leadingIconName, trailingIconName } = useComponentIcons(props)
5153
5254
const ui = computed(() => badge({
5355
color: props.color,
5456
variant: props.variant,
55-
size: props.size
57+
size: buttonGroupSize.value || props.size,
58+
buttonGroup: orientation.value
5659
}))
5760
5861
extendDevtoolsMeta({ defaultProps: { label: 'Badge' } })

src/theme/badge.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ModuleOptions } from '../module'
2+
import { buttonGroupVariant } from './button-group'
23

34
export default (options: Required<ModuleOptions>) => ({
45
slots: {
@@ -10,6 +11,7 @@ export default (options: Required<ModuleOptions>) => ({
1011
trailingIcon: 'shrink-0'
1112
},
1213
variants: {
14+
...buttonGroupVariant,
1315
color: {
1416
...Object.fromEntries((options.theme.colors || []).map((color: string) => [color, ''])),
1517
neutral: ''

0 commit comments

Comments
 (0)