Skip to content

Commit

Permalink
fix: add selection count badge
Browse files Browse the repository at this point in the history
  • Loading branch information
andre8244 committed Aug 7, 2024
1 parent 0bebe8c commit 604f377
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/components/NeFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { library } from '@fortawesome/fontawesome-svg-core'
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue'
import { isEqual } from 'lodash-es'
import { v4 as uuid } from '@lukeed/uuid'
import { NeBadge } from '@nethesis/vue-components'

export type ButtonSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
export type FilterKind = 'radio' | 'checkbox'
Expand All @@ -33,14 +34,17 @@ export interface Props {
label: string
options: FilterOption[]
kind: FilterKind
allLabel: string
openMenuAriaLabel: string
showSelectionCount?: boolean
alignToRight?: boolean
size?: ButtonSize
disabled?: boolean
id?: string
}

const props = withDefaults(defineProps<Props>(), {
showSelectionCount: true,
alignToRight: true,
size: 'md',
disabled: false,
Expand All @@ -59,6 +63,12 @@ const buttonRef = ref()

const componentId = computed(() => (props.id ? props.id : uuid()))

const badgeText = computed(() =>
checkboxModel.value.length == props.options.length
? props.allLabel
: checkboxModel.value.length.toString()
)

watch(
() => props.alignToRight,
() => {
Expand Down Expand Up @@ -134,6 +144,12 @@ function calculatePosition() {
<div class="flex items-center justify-center">
<slot v-if="$slots.label" name="label"></slot>
<span v-else>{{ label }}</span>
<NeBadge
v-if="kind === 'checkbox' && showSelectionCount"
:text="badgeText"
size="xs"
class="ml-2"
/>
<font-awesome-icon
:icon="['fas', 'chevron-down']"
class="ml-2 h-3 w-3"
Expand Down

0 comments on commit 604f377

Please sign in to comment.