diff --git a/exports/badge.d.ts b/exports/badge.d.ts
index ebd7f25de..12f6a2b7a 100644
--- a/exports/badge.d.ts
+++ b/exports/badge.d.ts
@@ -1 +1,2 @@
-export * from './components/badge/Badge';
\ No newline at end of file
+export * from './components/badge/Badge';
+export * from './components/badge/BadgeDirective';
\ No newline at end of file
diff --git a/exports/badge.js b/exports/badge.js
index 5cf477dda..8178606fd 100644
--- a/exports/badge.js
+++ b/exports/badge.js
@@ -1,2 +1,3 @@
'use strict';
-module.exports = require('./components/badge/Badge.vue');
\ No newline at end of file
+module.exports.Badge = require('./components/badge/Badge.vue');
+module.exports.BadgeDirective = require('./components/badge/BadgeDirective.js');
\ No newline at end of file
diff --git a/src/assets/styles/primevue.css b/src/assets/styles/primevue.css
index 6cbb2fcb6..ac544b3a0 100644
--- a/src/assets/styles/primevue.css
+++ b/src/assets/styles/primevue.css
@@ -1,4 +1,5 @@
@import '../../components/common/Common.css';
+@import '../../components/badge/Badge.css';
@import '../../components/button/Button.css';
@import '../../components/checkbox/Checkbox.css';
@import '../../components/colorpicker/ColorPicker.css';
diff --git a/src/components/badge/Badge.css b/src/components/badge/Badge.css
new file mode 100644
index 000000000..4a86ae80e
--- /dev/null
+++ b/src/components/badge/Badge.css
@@ -0,0 +1,33 @@
+.p-badge {
+ display: inline-block;
+ border-radius: 10px;
+ text-align: center;
+ padding: 0 .5rem;
+}
+
+.p-overlay-badge {
+ position: relative;
+ display: inline-block;
+}
+
+.p-overlay-badge .p-badge {
+ position: absolute;
+ top: 0;
+ right: 0;
+ transform: translate(50%,-50%);
+ transform-origin: 100% 0;
+ margin: 0;
+}
+
+.p-badge-dot {
+ width: .5rem;
+ min-width: .5rem;
+ height: .5rem;
+ border-radius: 50%;
+ padding: 0;
+}
+
+.p-badge-no-gutter {
+ padding: 0;
+ border-radius: 50%;
+}
\ No newline at end of file
diff --git a/src/components/badge/Badge.vue b/src/components/badge/Badge.vue
index da300cacb..021544ff8 100644
--- a/src/components/badge/Badge.vue
+++ b/src/components/badge/Badge.vue
@@ -22,6 +22,8 @@ export default {
},
badgeClass() {
return ['p-badge p-component', {
+ 'p-badge-no-gutter': this.value && String(this.value).length === 1,
+ 'p-badge-dot': !this.value,
'p-badge-lg': this.size === 'large',
'p-badge-xl': this.size === 'xlarge',
'p-badge-info': this.severity === 'info',
@@ -32,25 +34,4 @@ export default {
}
}
}
-
-
-
+
\ No newline at end of file
diff --git a/src/components/badge/BadgeDirective.d.ts b/src/components/badge/BadgeDirective.d.ts
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/components/badge/BadgeDirective.js b/src/components/badge/BadgeDirective.js
new file mode 100644
index 000000000..279bf2547
--- /dev/null
+++ b/src/components/badge/BadgeDirective.js
@@ -0,0 +1,55 @@
+import DomHandler from '../utils/DomHandler';
+import UniqueComponentId from '../utils/UniqueComponentId';
+
+const BadgeDirective = {
+ beforeMount(el, options) {
+ const id = UniqueComponentId() + '_badge';
+ el.$_pbadgeId = id;
+
+ let badge = document.createElement('span');
+ badge.id = id;
+ badge.className = 'p-badge p-component';
+
+ for (let modifier in options.modifiers) {
+ DomHandler.addClass(badge, 'p-badge-' + modifier);
+ }
+
+ if (options.value != null) {
+ badge.appendChild(document.createTextNode(options.value));
+
+ if (String(options.value).length === 1) {
+ DomHandler.addClass(badge, 'p-badge-no-gutter');
+ }
+ }
+ else {
+ DomHandler.addClass(badge, 'p-badge-dot');
+ }
+
+ DomHandler.addClass(el, 'p-overlay-badge');
+ el.appendChild(badge);
+ },
+ updated(el, options) {
+ DomHandler.addClass(el, 'p-overlay-badge');
+
+ if (options.oldValue !== options.value) {
+ let badge = document.getElementById(el.$_pbadgeId);
+
+ if (options.value && DomHandler.hasClass('p-badge-dot')) {
+ DomHandler.removeClass(badge, 'p-badge-dot');
+
+ if (String(options.value).length === 1)
+ DomHandler.addClass(badge, 'p-badge-no-gutter');
+ else
+ DomHandler.removeClass(badge, 'p-badge-no-gutter');
+ }
+ else if (!options.value && !DomHandler.hasClass('p-badge-dot')) {
+ DomHandler.addClass(badge, 'p-badge-dot');
+ }
+
+ badge.innerHTML = '';
+ badge.appendChild(document.createTextNode(options.value));
+ }
+ }
+};
+
+export default BadgeDirective;
diff --git a/src/components/button/Button.vue b/src/components/button/Button.vue
index ac3ddb215..b290f30a2 100755
--- a/src/components/button/Button.vue
+++ b/src/components/button/Button.vue
@@ -3,7 +3,7 @@
-import Badge from 'primevue/badge';
+import {Badge,BadgeDirective} from 'primevue/badge';
Badge can either be used as a standalone component or as a directive.
+ +Content of the badge is specified using the value property.
@@ -17,17 +20,26 @@ import Badge from 'primevue/badge';
- A badge can easily be positioned relative to another element by wrapping it.
-+Directive
+When used as a directive, badge needs to be configured at the application with a name of your choice.
++ +-<Badge value="2"> - <i class="pi pi-bell" style="font-size: 2rem"></i> -</Badge> +import {BadgeDirective} from 'primevue/badge'; + +Vue.directive('badge', BadgeDirective);
Next step is attaching it to an element.
++++<i class="pi pi-bell" v-badge="2"></i> + +
Severities
-Different color options are available as severity levels.
+Different color options are available as severity levels. When used as a component use the severity property + to apply a severity and use a modifier as the severity value in directive mode.
+
+<Badge value="2" severity="success"></Badge>
+
+<i class="pi pi-bell" v-badge.success="2"></i>
+
+
Buttons provide integrated badge support with the badge and badgeClass properties.
@@ -48,7 +67,8 @@ import Badge from 'primevue/badge';Badge sizes are adjusted with the size property that accepts "large" and "xlarge" as the possible alternatives to the default size.
+Badge sizes are adjusted with the size property that accepts "large" and "xlarge" as the possible alternatives to the default size. Currently + sizes only apply to component mode.
<Badge value="2"></Badge>
@@ -119,6 +139,26 @@ import Badge from 'primevue/badge';
p-overlay-badge
Wrapper of a badge and its target.
+
+ p-badge-dot
+ Badge element with no value.
+
+
+ p-badge-success
+ Badge element with success severity.
+
+
+ p-badge-info
+ Badge element with info severity.
+
+
+ p-badge-warning
+ Badge element with warning severity.
+
+
+ p-badge-danger
+ Badge element with danger severity.
+
p-badge-lg
Large badge element
@@ -148,10 +188,10 @@ import Badge from 'primevue/badge';
<Badge value="12" severity="warning" class="p-mr-2"></Badge>
<Badge value="3" severity="danger"></Badge>
-<h5>Positioned Badge</h5>
-<Badge value="2">
- <i class="pi pi-bell" style="font-size: 2rem"></i>
-</Badge>
+<h5 class="p-mb-4">Positioned Badge</h5>
+<i class="pi pi-bell p-mr-4 p-text-secondary" style="font-size: 2rem" v-badge="2"></i>
+<i class="pi pi-calendar p-mr-4 p-text-secondary" style="font-size: 2rem" v-badge.danger="'10+'"></i>
+<i class="pi pi-envelope p-text-secondary" style="font-size: 2rem" v-badge.danger></i>
<h5>Button Badge</h5>
<Button type="button" label="Emails" badge="8" class="p-mr-2" />
diff --git a/src/views/sidebar/SidebarDemo.vue b/src/views/sidebar/SidebarDemo.vue
index b844f168e..3266c78eb 100755
--- a/src/views/sidebar/SidebarDemo.vue
+++ b/src/views/sidebar/SidebarDemo.vue
@@ -17,6 +17,7 @@
Left Sidebar
+