Skip to content

Commit 5c52168

Browse files
Copilotkdinev
andcommitted
Add badge sizes, dot type, and improved outline implementation
Co-authored-by: kdinev <1472513+kdinev@users.noreply.github.com>
1 parent 163e16f commit 5c52168

File tree

5 files changed

+70
-5
lines changed

5 files changed

+70
-5
lines changed

projects/igniteui-angular/src/lib/badge/badge.component.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,20 @@ export const IgxBadgeType = {
1111
INFO: 'info',
1212
SUCCESS: 'success',
1313
WARNING: 'warning',
14-
ERROR: 'error'
14+
ERROR: 'error',
15+
DOT: 'dot'
1516
} as const;
1617
export type IgxBadgeType = (typeof IgxBadgeType)[keyof typeof IgxBadgeType];
18+
19+
/**
20+
* Determines the igxBadge size
21+
*/
22+
export const IgxBadgeSize = {
23+
SMALL: 'small',
24+
MEDIUM: 'medium',
25+
LARGE: 'large'
26+
} as const;
27+
export type IgxBadgeSize = (typeof IgxBadgeSize)[keyof typeof IgxBadgeSize];
1728
/**
1829
* Badge provides visual notifications used to decorate avatars, menus, etc.
1930
*
@@ -62,7 +73,7 @@ export class IgxBadgeComponent {
6273
* Sets/gets the type of the badge.
6374
*
6475
* @remarks
65-
* Allowed values are `primary`, `info`, `success`, `warning`, `error`.
76+
* Allowed values are `primary`, `info`, `success`, `warning`, `error`, `dot`.
6677
* Providing an invalid value won't display a badge.
6778
*
6879
* @example
@@ -73,6 +84,21 @@ export class IgxBadgeComponent {
7384
@Input()
7485
public type: string | IgxBadgeType = IgxBadgeType.PRIMARY;
7586

87+
/**
88+
* Sets/gets the size of the badge.
89+
*
90+
* @remarks
91+
* Allowed values are `small`, `medium`, `large`.
92+
* Default value is `medium`.
93+
*
94+
* @example
95+
* ```html
96+
* <igx-badge size="large"></igx-badge>
97+
* ```
98+
*/
99+
@Input()
100+
public size: string | IgxBadgeSize = IgxBadgeSize.MEDIUM;
101+
76102
/**
77103
* Sets/gets the value to be displayed inside the badge.
78104
*
@@ -219,4 +245,16 @@ export class IgxBadgeComponent {
219245
public get errorClass() {
220246
return this.type === IgxBadgeType.ERROR;
221247
}
248+
249+
@HostBinding('class.igx-badge--dot')
250+
public get dotClass() {
251+
return this.type === IgxBadgeType.DOT;
252+
}
253+
254+
@HostBinding('style.--component-size')
255+
protected get componentSize() {
256+
if (this.size) {
257+
return `var(--ig-size-${this.size})`;
258+
}
259+
}
222260
}

projects/igniteui-angular/src/lib/core/styles/components/badge/_badge-component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
@extend %igx-badge--error !optional;
3636
}
3737

38+
@include m(dot) {
39+
@extend %igx-badge--dot !optional;
40+
}
41+
3842
@include m(outlined) {
3943
@extend %igx-badge--outlined !optional;
4044
}

projects/igniteui-angular/src/lib/core/styles/components/badge/_badge-theme.scss

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
$variant: map.get($theme, '_meta', 'theme');
1111

1212
%igx-badge-display {
13-
--size: #{rem(22px)};
13+
--size: var(--component-size, #{rem(22px)});
1414
--_badge-size: var(--size);
1515

1616
display: inline-flex;
@@ -45,7 +45,8 @@
4545
}
4646

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

5152
%igx-badge--square {
@@ -73,6 +74,18 @@
7374
background: color($color: 'error');
7475
}
7576

77+
%igx-badge--dot {
78+
--size: #{rem(8px)};
79+
min-width: var(--size);
80+
min-height: var(--size);
81+
padding: 0;
82+
83+
.igx-badge__value,
84+
igx-icon {
85+
display: none;
86+
}
87+
}
88+
7689
%igx-badge--hidden {
7790
visibility: hidden;
7891
}

src/app/badge/badge.sample.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ <h3 class="sample-title">Angular Badge</h3>
55
[type]="properties.variant"
66
value="8"
77
[shape]="properties.shape"
8+
[size]="properties.size"
89
[outlined]="properties.outlined"
910
></igx-badge>
1011
<div class="avatar-sample">
1112
<igx-avatar icon="face" shape="rounded"></igx-avatar>
1213
<igx-badge
1314
[type]="properties.variant"
1415
[shape]="properties.shape"
16+
[size]="properties.size"
1517
[outlined]="properties.outlined"
1618
>
1719
<igx-icon>bluetooth</igx-icon>

src/app/badge/badge.sample.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,17 @@ export class BadgeSampleComponent {
4747
variant: {
4848
control: {
4949
type: 'select',
50-
options: ['default', 'info', 'success', 'warning', 'error'],
50+
options: ['default', 'info', 'success', 'warning', 'error', 'dot'],
5151
defaultValue: 'default'
5252
}
5353
},
54+
size: {
55+
control: {
56+
type: 'button-group',
57+
options: ['small', 'medium', 'large'],
58+
defaultValue: 'medium'
59+
}
60+
},
5461
outlined: {
5562
control: {
5663
type: 'boolean',
@@ -84,6 +91,7 @@ export class BadgeSampleComponent {
8491
success: 'success',
8592
warning: 'warning',
8693
error: 'danger',
94+
dot: 'primary',
8795
})
8896
);
8997

0 commit comments

Comments
 (0)