Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion projects/igniteui-angular/src/lib/badge/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# igx-badge

The **igx-badge** component is an absolutely positioned element that can be used in tandem with other components such as avatars, navigation menus, or anywhere else in an app where some active indication is required.
With the igx-badge you can display active count or an icon in several different predefined styles.
With the igx-badge you can display active count or an icon in several different predefined styles and sizes.
A walkthrough of how to get started can be found [here](https://www.infragistics.com/products/ignite-ui-angular/angular/components/badge.html)

# Usage
Expand All @@ -14,9 +14,12 @@ A walkthrough of how to get started can be found [here](https://www.infragistics
|:----------|:-------------:|:------|
| `id` | string | Unique identifier of the component. If not provided it will be automatically generated.|
| `type` | string | Set the type of the badge to either `primary`, `info`, `success`, `warning`, or `error`. This will change the background color of the badge according to the values set in the default theme. |
| `dot` | boolean | Set whether the badge is displayed as a minimal dot indicator without any content. Default is `false`. |
| `position` | string | Set the position of the badge relative to its parent container to either `top-right`, `top-left`, `bottom-right`, or `bottom-left`. |
| `value` | string | Set the value to be displayed inside the badge. |
| `icon` | string | Set an icon for the badge from the material icons set. Will not be displayed if `value` for the badge is already set. |
| `outlined` | boolean | Set whether the badge should have an outline. Default is `false`. |
| `shape` | string | Set the shape of the badge to either `rounded` or `square`. Default is `rounded`. |

# Examples

Expand All @@ -26,3 +29,18 @@ Using `igx-badge` with the `igx-avatar` component to show active status.
<igx-badge type="info" value="8"></igx-badge>
</igx-avatar>
```

Using `igx-badge` as a dot indicator for notifications.
```html
<igx-badge dot type="success"></igx-badge>
<igx-badge dot outlined type="error"></igx-badge>
```

Using different badge types.
```html
<igx-badge type="primary" value="1"></igx-badge>
<igx-badge type="info" value="2"></igx-badge>
<igx-badge type="success" value="3"></igx-badge>
<igx-badge type="warning" value="4"></igx-badge>
<igx-badge type="error" value="5"></igx-badge>
```
31 changes: 30 additions & 1 deletion projects/igniteui-angular/src/lib/badge/badge.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ describe('Badge', () => {
InitBadgeWithDefaultsComponent,
InitBadgeWithIconComponent,
IgxBadgeComponent,
InitBadgeWithIconARIAComponent
InitBadgeWithIconARIAComponent,
InitBadgeWithDotComponent
]
}).compileComponents();
}));
Expand Down Expand Up @@ -87,6 +88,26 @@ describe('Badge', () => {
const container = fixture.nativeElement.querySelectorAll('.igx-badge')[0];
expect(container.getAttribute('aria-roledescription')).toMatch(expectedDescription);
});

it('Initializes badge with dot property', () => {
const fixture = TestBed.createComponent(InitBadgeWithDotComponent);
fixture.detectChanges();
const badge = fixture.componentInstance.badge;

expect(badge.dot).toBeTruthy();
expect(fixture.debugElement.query(By.css('.igx-badge--dot'))).toBeTruthy();
});

it('Initializes success badge as dot', () => {
const fixture = TestBed.createComponent(InitBadgeWithDotComponent);
fixture.detectChanges();
const badge = fixture.componentInstance.badge;

expect(badge.type).toBe(IgxBadgeType.SUCCESS);
expect(badge.dot).toBeTruthy();
expect(fixture.debugElement.query(By.css('.igx-badge--dot'))).toBeTruthy();
expect(fixture.debugElement.query(By.css('.igx-badge--success'))).toBeTruthy();
});
});

@Component({
Expand Down Expand Up @@ -120,3 +141,11 @@ class InitBadgeWithIconComponent {
class InitBadgeWithIconARIAComponent {
@ViewChild(IgxBadgeComponent, { static: true }) public badge: IgxBadgeComponent;
}

@Component({
template: `<igx-badge dot type="success"></igx-badge>`,
imports: [IgxBadgeComponent]
})
class InitBadgeWithDotComponent {
@ViewChild(IgxBadgeComponent, { static: true }) public badge: IgxBadgeComponent;
}
14 changes: 14 additions & 0 deletions projects/igniteui-angular/src/lib/badge/badge.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ export class IgxBadgeComponent {
@HostBinding('class.igx-badge--outlined')
public outlined = false;

/**
* Sets/gets whether the badge is displayed as a dot.
* When true, the badge will be rendered as a minimal 8px indicator without any content.
* Default value is `false`.
*
* @example
* ```html
* <igx-badge dot type="success"></igx-badge>
* ```
*/
@Input({transform: booleanAttribute})
@HostBinding('class.igx-badge--dot')
public dot = false;

/**
* Defines a human-readable, accessor, author-localized description for
* the `type` and the `icon` or `value` of the element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
@extend %igx-badge--error !optional;
}

@include m(dot) {
@extend %igx-badge--dot !optional;
}

@include m(outlined) {
@extend %igx-badge--outlined !optional;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$variant: map.get($theme, '_meta', 'theme');

%igx-badge-display {
--size: #{rem(22px)};
--size: var(--ig-size, #{rem(22px)});
--_badge-size: var(--size);

display: inline-flex;
Expand Down Expand Up @@ -45,7 +45,8 @@
}

%igx-badge--outlined {
box-shadow: inset 0 0 0 rem(if($variant != 'bootstrap', 2px, 1px)) var-get($theme, 'border-color');
outline: rem(if($variant != 'bootstrap', 2px, 1px)) solid var-get($theme, 'border-color');
outline-offset: rem(-2px);
}

%igx-badge--square {
Expand All @@ -59,18 +60,50 @@

%igx-badge--success {
background: color($color: 'success');
color: white;

igx-icon {
color: white;
}
}

%igx-badge--info {
background: color($color: 'info');
color: white;

igx-icon {
color: white;
}
}

%igx-badge--warn {
background: color($color: 'warn');
color: white;

igx-icon {
color: white;
}
}

%igx-badge--error {
background: color($color: 'error');
color: white;

igx-icon {
color: white;
}
}

%igx-badge--dot {
--size: #{rem(8px)};
min-width: var(--size);
min-height: var(--size);
padding: 0;

.igx-badge__value,
igx-icon {
display: none;
}
}

%igx-badge--hidden {
Expand Down
108 changes: 92 additions & 16 deletions src/app/badge/badge.sample.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,97 @@
<div class="wrapper">
<div class="badges">
<h3 class="sample-title">Angular Badge</h3>
<igx-badge
[type]="properties.variant"
value="8"
[shape]="properties.shape"
[outlined]="properties.outlined"
></igx-badge>
<div class="avatar-sample">
<igx-avatar icon="face" shape="rounded"></igx-avatar>
<igx-badge
[type]="properties.variant"
[shape]="properties.shape"
[outlined]="properties.outlined"
>
<igx-icon>bluetooth</igx-icon>
</igx-badge>
<h3 class="sample-title">Angular Badge - Interactive</h3>
<div class="badge-examples">
<div class="badge-item">
<igx-badge
[type]="properties.variant"
value="8"
[shape]="properties.shape"
[outlined]="properties.outlined"
[dot]="properties.dot"
></igx-badge>
<span>With Value</span>
</div>
<div class="badge-item">
<igx-badge
[type]="properties.variant"
[shape]="properties.shape"
[outlined]="properties.outlined"
[dot]="properties.dot"
>
<igx-icon>bluetooth</igx-icon>
</igx-badge>
<span>With Icon</span>
</div>
<div class="badge-item avatar-sample">
<igx-avatar icon="face" shape="rounded"></igx-avatar>
<igx-badge
[type]="properties.variant"
[shape]="properties.shape"
[outlined]="properties.outlined"
[dot]="properties.dot"
>
<igx-icon>bluetooth</igx-icon>
</igx-badge>
<span>On Avatar</span>
</div>
</div>

<h3 class="sample-title">Dot Badges</h3>
<div class="badge-examples">
<div class="badge-item">
<igx-badge dot type="primary"></igx-badge>
<span>Primary Dot</span>
</div>
<div class="badge-item">
<igx-badge dot type="info"></igx-badge>
<span>Info Dot</span>
</div>
<div class="badge-item">
<igx-badge dot type="success"></igx-badge>
<span>Success Dot</span>
</div>
<div class="badge-item">
<igx-badge dot type="warning"></igx-badge>
<span>Warning Dot</span>
</div>
<div class="badge-item">
<igx-badge dot type="error"></igx-badge>
<span>Error Dot</span>
</div>
<div class="badge-item">
<igx-badge dot outlined type="success"></igx-badge>
<span>Outlined Dot</span>
</div>
<div class="badge-item avatar-sample">
<igx-avatar icon="face" shape="rounded"></igx-avatar>
<igx-badge dot type="success"></igx-badge>
<span>Dot on Avatar</span>
</div>
</div>

<h3 class="sample-title">Type Variants</h3>
<div class="badge-examples">
<div class="badge-item">
<igx-badge type="primary" value="1"></igx-badge>
<span>Primary</span>
</div>
<div class="badge-item">
<igx-badge type="info" value="2"></igx-badge>
<span>Info</span>
</div>
<div class="badge-item">
<igx-badge type="success" value="3"></igx-badge>
<span>Success</span>
</div>
<div class="badge-item">
<igx-badge type="warning" value="4"></igx-badge>
<span>Warning</span>
</div>
<div class="badge-item">
<igx-badge type="error" value="5"></igx-badge>
<span>Error</span>
</div>
</div>
</div>

Expand Down
42 changes: 39 additions & 3 deletions src/app/badge/badge.sample.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,52 @@
.wrapper {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 48px;
padding: 24px;
}

.badges {
place-items: center;
display: grid;
grid-template-columns: subgrid;
place-items: start;
display: flex;
flex-direction: column;
gap: 24px;
}

.sample-title {
margin: 16px 0 8px 0;
font-size: 18px;
font-weight: 600;
}

.badge-examples {
display: flex;
flex-wrap: wrap;
gap: 32px;
align-items: center;
}

.badge-item {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
position: relative;

span {
font-size: 12px;
color: #666;
margin-top: 4px;
}
}

.avatar-sample {
display: flex;
align-items: center;
position: relative;

igx-badge {
position: absolute;
top: -4px;
right: -4px;
}
}
8 changes: 7 additions & 1 deletion src/app/badge/badge.sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export class BadgeSampleComponent {
type: 'boolean',
defaultValue: false
}
},
dot: {
control: {
type: 'boolean',
defaultValue: false
}
}
};

Expand Down Expand Up @@ -83,7 +89,7 @@ export class BadgeSampleComponent {
info: 'info',
success: 'success',
warning: 'warning',
error: 'danger',
error: 'danger'
})
);

Expand Down