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

View File

@ -1,11 +1,17 @@
<template> <template>
<DocSectionText v-bind="$attrs"> <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> </DocSectionText>
<div class="card flex flex-wrap justify-content-center gap-4"> <div class="card flex flex-wrap justify-content-center gap-4">
<i v-badge="2" class="pi pi-bell" style="font-size: 2rem" /> <span v-badge="2">
<i v-badge.danger="'5+'" class="pi pi-calendar" style="font-size: 2rem" /> <i class="pi pi-bell" style="font-size: 2rem" />
<i v-badge.danger class="pi pi-envelope" 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> </div>
<DocSectionCode :code="code" /> <DocSectionCode :code="code" />
</template> </template>
@ -16,16 +22,28 @@ export default {
return { return {
code: { code: {
basic: ` basic: `
<i v-badge="2" class="pi pi-bell" style="font-size: 2rem" /> <span v-badge="2">
<i v-badge.danger="'5+'" class="pi pi-calendar" style="font-size: 2rem" /> <i class="pi pi-bell" style="font-size: 2rem" />
<i v-badge.danger class="pi pi-envelope" 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: ` options: `
<template> <template>
<div class="card flex flex-wrap justify-content-center gap-4"> <div class="card flex flex-wrap justify-content-center gap-4">
<i v-badge="2" class="pi pi-bell" style="font-size: 2rem" /> <span v-badge="2">
<i v-badge.danger="'5+'" class="pi pi-calendar" style="font-size: 2rem" /> <i class="pi pi-bell" style="font-size: 2rem" />
<i v-badge.danger class="pi pi-envelope" 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> </div>
</template> </template>
@ -36,9 +54,15 @@ export default {
composition: ` composition: `
<template> <template>
<div class="card flex flex-wrap justify-content-center gap-4"> <div class="card flex flex-wrap justify-content-center gap-4">
<i v-badge="2" class="pi pi-bell" style="font-size: 2rem" /> <span v-badge="2">
<i v-badge.danger="'5+'" class="pi pi-calendar" style="font-size: 2rem" /> <i class="pi pi-bell" style="font-size: 2rem" />
<i v-badge.danger class="pi pi-envelope" 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> </div>
</template> </template>