Fixed overlay badge visuals

pull/5756/head
Cagatay Civici 2024-05-13 18:20:54 +03:00
parent 97081aa039
commit f16d9eaac9
3 changed files with 42 additions and 18 deletions

View File

@ -72,9 +72,9 @@ export interface BadgeProps {
*/
severity?: HintedString<'secondary' | 'info' | 'success' | 'warn' | 'danger' | 'contrast'> | null | undefined;
/**
* Size of the badge, valid options are 'large' and 'xlarge'.
* Size of the badge, valid options are 'small', 'large', and 'xlarge'.
*/
size?: 'large' | 'xlarge' | null | undefined;
size?: 'small' | 'large' | 'xlarge' | null | undefined;
/**
* It generates scoped CSS variables using design tokens for the component.
*/

View File

@ -30,7 +30,7 @@ const BadgeDirective = BaseBadgeDirective.extend('badge', {
badge.appendChild(document.createTextNode(el.$_badgeValue));
if (String(el.$_badgeValue).length === 1 && !this.isUnstyled()) {
!this.isUnstyled() && DomHandler.addClass(badge, 'p-badge-no-gutter');
!this.isUnstyled() && DomHandler.addClass(badge, 'p-badge-circle');
}
} else {
!this.isUnstyled() && DomHandler.addClass(badge, 'p-badge-dot');
@ -57,8 +57,8 @@ const BadgeDirective = BaseBadgeDirective.extend('badge', {
if (el.$_badgeValue) {
if (DomHandler.hasClass(badge, 'p-badge-dot')) DomHandler.removeClass(badge, 'p-badge-dot');
if (el.$_badgeValue.length === 1) DomHandler.addClass(badge, 'p-badge-no-gutter');
else DomHandler.removeClass(badge, 'p-badge-no-gutter');
if (el.$_badgeValue.length === 1) DomHandler.addClass(badge, 'p-badge-circle');
else DomHandler.removeClass(badge, 'p-badge-circle');
} else if (!el.$_badgeValue && !DomHandler.hasClass(badge, 'p-badge-dot')) {
DomHandler.addClass(badge, 'p-badge-dot');
}

View File

@ -1,11 +1,17 @@
<template>
<DocSectionText v-bind="$attrs">
<p>A Badge can be positioned at the top right corner of an element by adding <i>p-overlay-badge</i> style class to the element and embedding the badge inside.</p>
<p>A Badge can be added to any element using the directive.</p>
</DocSectionText>
<div class="card flex flex-wrap justify-content-center gap-4">
<i v-badge="2" class="pi pi-bell" style="font-size: 2rem" />
<i v-badge.danger="'5+'" class="pi pi-calendar" style="font-size: 2rem" />
<i v-badge.danger class="pi pi-envelope" style="font-size: 2rem" />
<span v-badge="2">
<i class="pi pi-bell" style="font-size: 2rem" />
</span>
<span v-badge.danger="'5+'">
<i class="pi pi-calendar" style="font-size: 2rem" />
</span>
<span v-badge.danger>
<i class="pi pi-envelope" style="font-size: 2rem" />
</span>
</div>
<DocSectionCode :code="code" />
</template>
@ -16,16 +22,28 @@ export default {
return {
code: {
basic: `
<i v-badge="2" class="pi pi-bell" style="font-size: 2rem" />
<i v-badge.danger="'5+'" class="pi pi-calendar" style="font-size: 2rem" />
<i v-badge.danger class="pi pi-envelope" style="font-size: 2rem" />
<span v-badge="2">
<i class="pi pi-bell" style="font-size: 2rem" />
</span>
<span v-badge.danger="'5+'">
<i class="pi pi-calendar" style="font-size: 2rem" />
</span>
<span v-badge.danger>
<i class="pi pi-envelope" style="font-size: 2rem" />
</span>
`,
options: `
<template>
<div class="card flex flex-wrap justify-content-center gap-4">
<i v-badge="2" class="pi pi-bell" style="font-size: 2rem" />
<i v-badge.danger="'5+'" class="pi pi-calendar" style="font-size: 2rem" />
<i v-badge.danger class="pi pi-envelope" style="font-size: 2rem" />
<span v-badge="2">
<i class="pi pi-bell" style="font-size: 2rem" />
</span>
<span v-badge.danger="'5+'">
<i class="pi pi-calendar" style="font-size: 2rem" />
</span>
<span v-badge.danger>
<i class="pi pi-envelope" style="font-size: 2rem" />
</span>
</div>
</template>
@ -36,9 +54,15 @@ export default {
composition: `
<template>
<div class="card flex flex-wrap justify-content-center gap-4">
<i v-badge="2" class="pi pi-bell" style="font-size: 2rem" />
<i v-badge.danger="'5+'" class="pi pi-calendar" style="font-size: 2rem" />
<i v-badge.danger class="pi pi-envelope" style="font-size: 2rem" />
<span v-badge="2">
<i class="pi pi-bell" style="font-size: 2rem" />
</span>
<span v-badge.danger="'5+'">
<i class="pi pi-calendar" style="font-size: 2rem" />
</span>
<span v-badge.danger>
<i class="pi pi-envelope" style="font-size: 2rem" />
</span>
</div>
</template>