Skip to content

Commit df432ed

Browse files
committed
refactor(badge): design enhancement
1 parent 353b4b8 commit df432ed

File tree

9 files changed

+74
-79
lines changed

9 files changed

+74
-79
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ export class IgxBadgeComponent {
153153
/** @hidden @internal */
154154
@HostBinding('class.igx-badge--square')
155155
public get _squareShape(): boolean {
156-
return this.shape === 'square';
156+
if (!this.dot) {
157+
return this.shape === 'square';
158+
}
157159
}
158160

159161
/**

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

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

1212
%igx-badge-display {
13-
--size: var(--ig-size, #{rem(22px)});
14-
--_badge-size: var(--size);
13+
@include sizable();
14+
15+
--component-size: var(--ig-size, #{var-get($theme, 'default-size')});
16+
--badge-size: var(--component-size);
17+
--_badge-size: #{var-get($theme, 'size')};
1518

1619
display: inline-flex;
1720
justify-content: center;
@@ -25,18 +28,18 @@
2528
overflow: hidden;
2629

2730
igx-icon {
28-
--size: var(--igx-icon-size, calc(var(--_badge-size) / 2));
31+
--size: var(--igx-icon-size, #{sizable(rem(12px), rem(14px), rem(16px))});
32+
--component-size: var(--badge-size);
2933

3034
display: inline-flex;
3135
justify-content: center;
3236
align-items: center;
33-
font-weight: 400;
3437
color: var-get($theme, 'icon-color');
3538
}
3639

3740
@if $variant == 'indigo' {
3841
igx-icon {
39-
$icon-size: rem(12px);
42+
$icon-size: sizable(rem(8px), rem(10px), rem(12px));
4043

4144
--ig-icon-size: #{$icon-size};
4245
--igx-icon-size: #{$icon-size};
@@ -45,8 +48,7 @@
4548
}
4649

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

5254
%igx-badge--square {
@@ -55,53 +57,36 @@
5557

5658
%igx-badge-value {
5759
white-space: nowrap;
58-
padding-inline: pad-inline(rem(4px));
60+
padding-inline: pad-inline(rem(4px), rem(6px), if($variant == 'indigo', rem(6px), rem(8px)));
5961
}
6062

6163
%igx-badge--success {
62-
background: color($color: 'success');
63-
color: white;
64-
65-
igx-icon {
66-
color: white;
67-
}
64+
background: color($color: 'success', $variant: if($variant != 'material', if($variant == 'indigo', 700, 500), 900));
6865
}
6966

7067
%igx-badge--info {
71-
background: color($color: 'info');
72-
color: white;
73-
74-
igx-icon {
75-
color: white;
76-
}
68+
background: color($color: 'info', $variant: if($variant != 'material', if($variant == 'fluent', 700, 500), 800));
7769
}
7870

7971
%igx-badge--warn {
8072
background: color($color: 'warn');
81-
color: white;
82-
83-
igx-icon {
84-
color: white;
85-
}
73+
color: contrast-color($color: 'warn', $variant: 500);
8674
}
8775

8876
%igx-badge--error {
89-
background: color($color: 'error');
90-
color: white;
91-
92-
igx-icon {
93-
color: white;
94-
}
77+
background: color($color: 'error', $variant: if($variant == 'material', 700, 500));
78+
color: contrast-color($color: 'error', $variant: if($variant == 'bootstrap', 100, 900));
9579
}
9680

9781
%igx-badge--dot {
98-
--size: #{rem(8px)};
99-
min-width: var(--size);
100-
min-height: var(--size);
82+
--_dot-size: #{var-get($theme, 'dot-size')};
83+
84+
min-width: var(--_dot-size);
85+
min-height: var(--_dot-size);
10186
padding: 0;
10287

103-
.igx-badge__value,
104-
igx-icon {
88+
igx-icon,
89+
> * {
10590
display: none;
10691
}
10792
}
@@ -112,15 +97,28 @@
11297
}
11398

11499
/// Adds typography styles for the igx-badge component.
115-
/// Uses the 'caption' category from the typographic scale.
100+
/// Uses 'caption' and 'body-2' categories from the typographic scale.
116101
/// @group typography
117102
/// @param {Map} $categories [(text: 'caption')] - The categories from the typographic scale used for type styles.
118-
@mixin badge-typography($categories: (text: 'caption')) {
103+
@mixin badge-typography($categories: (text: null), $theme: null) {
119104
$text: map.get($categories, 'text');
120105

121106
%igx-badge-display {
122-
@include type-style($text) {
123-
margin: 0;
107+
@if $text {
108+
@include type-style($text);
109+
} @else {
110+
@if $theme == 'indigo' {
111+
@include type-style('button', false) {
112+
font-size: sizable(rem(9px), rem(10px), var(--ig-button-font-size));
113+
line-height: sizable(rem(12px), rem(14px), var(--ig-button-line-height));
114+
}
115+
} @else {
116+
font-size: sizable(var(--ig-caption-font-size), var(--ig-body-2-font-size), var(--ig-body-2-font-size));
117+
font-weight: sizable(var(--ig-caption-font-weight), var(--ig-body-2-font-weight), var(--ig-body-2-font-weight));
118+
line-height: sizable(var(--ig-caption-line-height), var(--ig-body-2-line-height), var(--ig-body-2-line-height));
119+
letter-spacing: sizable(var(--ig-caption-letter-spacing), var(--ig-body-2-letter-spacing), var(--ig-body-2-letter-spacing));
120+
text-transform: sizable(var(--ig-caption-text-transform), var(--ig-body-2-text-transform), var(--ig-body-2-text-transform));
121+
}
124122
}
125123
}
126124
}

projects/igniteui-angular/src/lib/core/styles/typography/_bootstrap.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
@use '../components/input/file-input-theme' as *;
3737

3838
@mixin typography($type-scale) {
39-
@include badge-typography();
39+
@include badge-typography($theme: 'bootstrap');
4040
@include banner-typography();
4141
@include bottom-nav-typography();
4242
@include button-typography();

projects/igniteui-angular/src/lib/core/styles/typography/_fluent.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
@use '../components/input/file-input-theme' as *;
3636

3737
@mixin typography() {
38-
@include badge-typography();
38+
@include badge-typography($theme: 'fluent');
3939
@include banner-typography($categories: (
4040
message: 'caption'
4141
));

projects/igniteui-angular/src/lib/core/styles/typography/_indigo.scss

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535
@use '../components/input/file-input-theme' as *;
3636

3737
@mixin typography($type-scale) {
38-
@include badge-typography($categories: (
39-
text: 'button',
40-
));
38+
@include badge-typography($theme: 'indigo');
4139
@include banner-typography();
4240
@include bottom-nav-typography();
4341
@include button-typography();

projects/igniteui-angular/src/lib/core/styles/typography/_material.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
@use '../components/input/file-input-theme' as *;
3636

3737
@mixin typography() {
38-
@include badge-typography();
38+
@include badge-typography($theme: 'material');
3939
@include banner-typography();
4040
@include bottom-nav-typography();
4141
@include button-typography();

src/app/badge/badge.sample.html

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<div class="wrapper">
22
<div class="badges">
3-
<h3 class="sample-title">Angular Badge - Interactive</h3>
4-
<div class="badge-examples">
3+
<h3 class="sample-title">Angular Badge</h3>
4+
<div class="badge-examples" [igSize]="properties.size">
55
<div class="badge-item">
66
<igx-badge
77
[type]="properties.variant"
88
value="8"
99
[shape]="properties.shape"
1010
[outlined]="properties.outlined"
11-
[dot]="properties.dot"
1211
></igx-badge>
1312
<span>With Value</span>
1413
</div>
@@ -17,7 +16,6 @@ <h3 class="sample-title">Angular Badge - Interactive</h3>
1716
[type]="properties.variant"
1817
[shape]="properties.shape"
1918
[outlined]="properties.outlined"
20-
[dot]="properties.dot"
2119
>
2220
<igx-icon>bluetooth</igx-icon>
2321
</igx-badge>
@@ -29,67 +27,62 @@ <h3 class="sample-title">Angular Badge - Interactive</h3>
2927
[type]="properties.variant"
3028
[shape]="properties.shape"
3129
[outlined]="properties.outlined"
32-
[dot]="properties.dot"
3330
>
3431
<igx-icon>bluetooth</igx-icon>
3532
</igx-badge>
3633
<span>On Avatar</span>
3734
</div>
3835
</div>
3936

40-
<h3 class="sample-title">Dot Badges</h3>
41-
<div class="badge-examples">
37+
<h3 class="sample-title">Dot Type Badges</h3>
38+
<div class="badge-examples" [igSize]="properties.size">
4239
<div class="badge-item">
43-
<igx-badge dot type="primary"></igx-badge>
40+
<igx-badge dot type="primary" [outlined]="properties.outlined" [shape]="properties.shape"></igx-badge>
4441
<span>Primary Dot</span>
4542
</div>
4643
<div class="badge-item">
47-
<igx-badge dot type="info"></igx-badge>
44+
<igx-badge dot type="info" [outlined]="properties.outlined"></igx-badge>
4845
<span>Info Dot</span>
4946
</div>
5047
<div class="badge-item">
51-
<igx-badge dot type="success"></igx-badge>
48+
<igx-badge dot type="success" [outlined]="properties.outlined"></igx-badge>
5249
<span>Success Dot</span>
5350
</div>
5451
<div class="badge-item">
55-
<igx-badge dot type="warning"></igx-badge>
52+
<igx-badge dot type="warning" [outlined]="properties.outlined"></igx-badge>
5653
<span>Warning Dot</span>
5754
</div>
5855
<div class="badge-item">
59-
<igx-badge dot type="error"></igx-badge>
56+
<igx-badge dot type="error" [outlined]="properties.outlined"></igx-badge>
6057
<span>Error Dot</span>
6158
</div>
62-
<div class="badge-item">
63-
<igx-badge dot outlined type="success"></igx-badge>
64-
<span>Outlined Dot</span>
65-
</div>
6659
<div class="badge-item avatar-sample">
6760
<igx-avatar icon="face" shape="rounded"></igx-avatar>
68-
<igx-badge dot type="success"></igx-badge>
61+
<igx-badge dot type="success" [outlined]="properties.outlined"></igx-badge>
6962
<span>Dot on Avatar</span>
7063
</div>
7164
</div>
7265

7366
<h3 class="sample-title">Type Variants</h3>
7467
<div class="badge-examples">
7568
<div class="badge-item">
76-
<igx-badge type="primary" value="1"></igx-badge>
69+
<igx-badge type="primary" value="1" [outlined]="properties.outlined" [shape]="properties.shape"></igx-badge>
7770
<span>Primary</span>
7871
</div>
7972
<div class="badge-item">
80-
<igx-badge type="info" value="2"></igx-badge>
73+
<igx-badge type="info" value="2" [outlined]="properties.outlined" [shape]="properties.shape"></igx-badge>
8174
<span>Info</span>
8275
</div>
8376
<div class="badge-item">
84-
<igx-badge type="success" value="3"></igx-badge>
77+
<igx-badge type="success" value="3" [outlined]="properties.outlined" [shape]="properties.shape"></igx-badge>
8578
<span>Success</span>
8679
</div>
8780
<div class="badge-item">
88-
<igx-badge type="warning" value="4"></igx-badge>
81+
<igx-badge type="warning" value="4" [outlined]="properties.outlined" [shape]="properties.shape"></igx-badge>
8982
<span>Warning</span>
9083
</div>
9184
<div class="badge-item">
92-
<igx-badge type="error" value="5"></igx-badge>
85+
<igx-badge type="error" value="5" [outlined]="properties.outlined" [shape]="properties.shape"></igx-badge>
9386
<span>Error</span>
9487
</div>
9588
</div>

src/app/badge/badge.sample.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use '../../../projects/igniteui-angular/src/lib/core/styles/themes/utilities' as *;
2+
13
.wrapper {
24
display: grid;
35
grid-template-columns: repeat(2, 1fr);
@@ -23,6 +25,8 @@
2325
flex-wrap: wrap;
2426
gap: 32px;
2527
align-items: center;
28+
padding: 16px;
29+
background: color($color: 'surface', $variant: 700);
2630
}
2731

2832
.badge-item {
@@ -33,9 +37,7 @@
3337
position: relative;
3438

3539
span {
36-
font-size: 12px;
37-
color: #666;
38-
margin-top: 4px;
40+
font-size: 14px;
3941
}
4042
}
4143

src/app/badge/badge.sample.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
IgxBadgeComponent,
44
IgxAvatarComponent,
55
IgxIconComponent,
6+
IgSizeDirective,
67
} from 'igniteui-angular';
78
import {
89
defineComponents,
@@ -32,11 +33,18 @@ registerIconFromText('bluetooth', bluetooth);
3233
styleUrls: ['badge.sample.scss'],
3334
templateUrl: 'badge.sample.html',
3435
schemas: [CUSTOM_ELEMENTS_SCHEMA],
35-
imports: [IgxBadgeComponent, IgxAvatarComponent, IgxIconComponent]
36+
imports: [IgxBadgeComponent, IgxAvatarComponent, IgxIconComponent, IgSizeDirective]
3637
})
3738

3839
export class BadgeSampleComponent {
3940
public panelConfig: PropertyPanelConfig = {
41+
size: {
42+
control: {
43+
type: 'button-group',
44+
options: ['small', 'medium', 'large'],
45+
defaultValue: 'medium'
46+
}
47+
},
4048
shape: {
4149
control: {
4250
type: 'button-group',
@@ -56,12 +64,6 @@ export class BadgeSampleComponent {
5664
type: 'boolean',
5765
defaultValue: false
5866
}
59-
},
60-
dot: {
61-
control: {
62-
type: 'boolean',
63-
defaultValue: false
64-
}
6567
}
6668
};
6769

0 commit comments

Comments
 (0)