Skip to content

Commit

Permalink
feat(Badge): add support within button groups (#3224)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <[email protected]>
  • Loading branch information
jduartea and benjamincanac authored Feb 3, 2025
1 parent deddc7c commit 10fb843
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<UButtonGroup>
<UBadge color="neutral" variant="outline" size="lg" label="https://" />

<UInput color="neutral" variant="outline" placeholder="www.example.com" />
</UButtonGroup>
</template>
10 changes: 8 additions & 2 deletions docs/content/3.components/button-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,22 @@ slots:

### With tooltip

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

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

### With dropdown

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

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

### With badge

You can use a [Badge](/components/badge) within a button group.

:component-example{name="button-group-badge-example"}

## API

### Props
Expand Down
5 changes: 5 additions & 0 deletions playground/app/pages/components/button-group.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ const sizes = Object.keys(theme.variants.size) as Array<keyof typeof theme.varia
Button
</UButton>
</UButtonGroup>

<UButtonGroup>
<UBadge color="neutral" variant="outline" size="lg" label="https://" />
<UInput color="neutral" variant="outline" placeholder="www.example.com" />
</UButtonGroup>
</div>

<div class="flex gap-4 items-center justify-center">
Expand Down
5 changes: 4 additions & 1 deletion src/runtime/components/Badge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface BadgeSlots {
<script setup lang="ts">
import { computed } from 'vue'
import { Primitive } from 'reka-ui'
import { useButtonGroup } from '../composables/useButtonGroup'
import { useComponentIcons } from '../composables/useComponentIcons'
import UIcon from './Icon.vue'
import UAvatar from './Avatar.vue'
Expand All @@ -47,12 +48,14 @@ const props = withDefaults(defineProps<BadgeProps>(), {
})
defineSlots<BadgeSlots>()
const { orientation, size: buttonGroupSize } = useButtonGroup<BadgeProps>(props)
const { isLeading, isTrailing, leadingIconName, trailingIconName } = useComponentIcons(props)
const ui = computed(() => badge({
color: props.color,
variant: props.variant,
size: props.size
size: buttonGroupSize.value || props.size,
buttonGroup: orientation.value
}))
extendDevtoolsMeta({ defaultProps: { label: 'Badge' } })
Expand Down
2 changes: 2 additions & 0 deletions src/theme/badge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ModuleOptions } from '../module'
import { buttonGroupVariant } from './button-group'

export default (options: Required<ModuleOptions>) => ({
slots: {
Expand All @@ -10,6 +11,7 @@ export default (options: Required<ModuleOptions>) => ({
trailingIcon: 'shrink-0'
},
variants: {
...buttonGroupVariant,
color: {
...Object.fromEntries((options.theme.colors || []).map((color: string) => [color, ''])),
neutral: ''
Expand Down

0 comments on commit 10fb843

Please sign in to comment.