Skip to content

Commit 87a6166

Browse files
feat(avatar): add rounded shape (#12733)
* feat(avatar): add rounded shape --------- Co-authored-by: Simeon Simeonoff <[email protected]>
1 parent fe28167 commit 87a6166

File tree

8 files changed

+70
-14
lines changed

8 files changed

+70
-14
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ All notable changes for each version of this project will be documented in this
2424
- `IgxRadio`, `IgxRadioGroup`
2525
- Added component validation along with styles for invalid state
2626
- `IgxAvatar`
27-
- **Breaking Change** The `roundShape` property has been deprecated and will be removed in a future version. Users can control the shape of the avatar by the newly added `shape` attribute that can be either `square` or `rounded`. The default shape of the avatar is `square`.
27+
- **Breaking Change** The `roundShape` property has been deprecated and will be removed in a future version. Users can control the shape of the avatar by the newly added `shape` attribute that can be `square`, `rounded` or `circle`. The default shape of the avatar is `square`.
2828

2929
## 15.0.1
3030

projects/igniteui-angular/migrations/update-15_1_0/index.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe(`Update to ${version}`, () => {
134134

135135
expect(tree.readContent('/testSrc/appPrefix/component/test.component.html')).toEqual(
136136
`
137-
<igx-avatar initials="MS" shape="rounded" size="large"></igx-avatar>
137+
<igx-avatar initials="MS" shape="circle" size="large"></igx-avatar>
138138
`
139139
);
140140
});

projects/igniteui-angular/migrations/update-15_1_0/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ export default (options: Options): Rule => async (host: Tree, context: Schematic
1818

1919
switch (args.value) {
2020
case 'true':
21-
args.value = 'rounded';
21+
args.value = 'circle';
2222
break;
2323
case 'false':
2424
args.value = 'square';
2525
break;
2626
default:
27-
args.value += ` ? 'rounded' : 'square' `;
27+
args.value += ` ? 'circle' : 'square' `;
2828
}
2929
});
3030
update.applyChanges();

projects/igniteui-angular/src/lib/avatar/avatar.component.spec.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('Avatar', () => {
1212

1313
const classes = {
1414
round: `${baseClass}--rounded`,
15+
circle: `${baseClass}--circle`,
1516
small: `${baseClass}--small`,
1617
medium: `${baseClass}--medium`,
1718
large: `${baseClass}--large`,
@@ -57,15 +58,25 @@ describe('Avatar', () => {
5758
const hostEl = fixture.debugElement.query(By.css(baseClass)).nativeElement;
5859

5960
expect(instance.roundShape).toBeTruthy();
60-
expect(instance.shape).toEqual('rounded');
61-
expect(hostEl.classList).toContain(classes.round);
61+
expect(instance.shape).toEqual('circle');
62+
expect(hostEl.classList).toContain(classes.circle);
63+
expect(hostEl.classList).not.toContain(classes.round);
6264

6365
instance.shape = "square";
6466

6567
fixture.detectChanges();
6668
expect(instance.roundShape).toBeFalsy();
6769
expect(instance.shape).toEqual('square');
6870
expect(hostEl.classList).not.toContain(classes.round);
71+
expect(hostEl.classList).not.toContain(classes.circle);
72+
73+
instance.shape = "rounded";
74+
75+
fixture.detectChanges();
76+
expect(instance.roundShape).toBeFalsy();
77+
expect(instance.shape).toEqual('rounded');
78+
expect(hostEl.classList).toContain(classes.round);
79+
expect(hostEl.classList).not.toContain(classes.circle);
6980
});
7081

7182
it('Can change its size', () => {
@@ -103,6 +114,7 @@ describe('Avatar', () => {
103114
expect(instance.initials).toBeUndefined();
104115
expect(instance.src).toBeUndefined();
105116
expect(instance.icon).toBeUndefined();
117+
expect(instance.shape).toEqual('square');
106118

107119
expect(hostEl.textContent).toEqual('TEST');
108120
});

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,27 @@ export class IgxAvatarComponent implements OnInit {
117117

118118
/**
119119
* @deprecated in version 15.1.0.
120-
* Sets a round shape to the avatar, if `[roundShape]` is set to `true`.
120+
* Sets a circular shape to the avatar, if `[roundShape]` is set to `true`.
121121
* By default the shape of the avatar is a square.
122122
*
123123
* @example
124124
* ```html
125125
* <igx-avatar [roundShape]="true" ></igx-avatar>
126126
* ```
127127
*/
128+
/** @hidden @internal */
128129
@Input()
129-
@HostBinding('class.igx-avatar--rounded')
130+
@HostBinding('class.igx-avatar--circle')
130131
public get roundShape() {
131-
return this.shape === 'rounded';
132+
return this.shape === 'circle';
132133
}
133134

134135
public set roundShape(value: boolean) {
135-
this.shape = value === true ? 'rounded' : 'square';
136+
this.shape = value === true ? 'circle' : 'square';
136137
}
137138

138139
/**
139-
* Sets a rounded shape to the avatar, if `shape` is set to `rounded`.
140+
* Sets square, rounded or circular shape to the avatar.
140141
* By default the shape of the avatar is square.
141142
*
142143
* @example
@@ -145,7 +146,13 @@ export class IgxAvatarComponent implements OnInit {
145146
* ```
146147
*/
147148
@Input()
148-
public shape: 'square' | 'rounded' = 'square';
149+
public shape: 'square' | 'rounded' | 'circle' = 'square';
150+
151+
/** @hidden @internal */
152+
@HostBinding('class.igx-avatar--rounded')
153+
public get isRounded(): boolean {
154+
return this.shape === 'rounded';
155+
}
149156

150157
/**
151158
* Sets the color of the avatar's initials or icon.

projects/igniteui-angular/src/lib/core/styles/components/avatar/_avatar-component.scss

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
@extend %igx-avatar-image !optional;
2121
}
2222

23+
@include m(circle) {
24+
@extend %igx-avatar--circle !optional;
25+
}
26+
2327
@include m(rounded) {
2428
@extend %igx-avatar--rounded !optional;
2529
}

projects/igniteui-angular/src/lib/core/styles/components/avatar/_avatar-theme.scss

+10-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
@mixin avatar($theme) {
6262
@include css-vars($theme);
6363

64+
$variant: map.get($theme, variant);
6465
$size: map.get($theme, 'size');
6566
$small-size: rem(40px);
6667
$medium-size: rem(64px);
@@ -120,10 +121,18 @@
120121
background-position: center;
121122
}
122123

123-
%igx-avatar--rounded {
124+
%igx-avatar--circle {
124125
--igx-avatar-border-radius: #{rem(44px)};
125126
}
126127

128+
%igx-avatar--rounded {
129+
--igx-avatar-border-radius: #{rem(8px)};
130+
131+
@if $variant == 'bootstrap' {
132+
--igx-avatar-border-radius: #{rem(4px)};
133+
}
134+
}
135+
127136
%igx-avatar--initials {
128137
text-transform: uppercase;
129138
}

src/app/avatar/avatar.sample.html

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
11
<div class="sample-content">
2-
<!--Round Avatars-->
2+
<!--Circular Avatars-->
33
<section class="sample-column">
44
<h4 class="sample-title">Circular Avatars</h4>
55
<article class="avatars">
66
<igx-avatar class="avatar-theme" icon="tag_faces" [roundShape]="true"></igx-avatar>
77

8+
<igx-avatar igxDrag icon="tag_faces" size="medium" shape="circle"></igx-avatar>
9+
10+
<igx-avatar icon="tag_faces" size="large" shape="circle"></igx-avatar>
11+
12+
<igx-avatar initials="AZ" shape="circle"></igx-avatar>
13+
14+
<igx-avatar initials="AZ" size="medium" shape="circle"></igx-avatar>
15+
16+
<igx-avatar initials="AZ" size="large" shape="circle"></igx-avatar>
17+
18+
<igx-avatar color="red" bgColor="black" src="https://images.unsplash.com/photo-1514041790697-53f1f86214d2?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=b7ac79503fbe78855a346c8d814f95ba&auto=format&fit=crop&w=1650&q=80" shape="circle"></igx-avatar>
19+
20+
<igx-avatar src="assets/images/avatar/17.jpg" size="medium" shape="circle"></igx-avatar>
21+
22+
<igx-avatar src="https://images.unsplash.com/photo-1506804880640-f3205deb1b8b?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=2f8dd0c16478825034602dce63d9aaca&auto=format&fit=crop&w=1350&q=80" size="large" shape="circle"></igx-avatar>
23+
</article>
24+
</section>
25+
26+
<!--Round Avatars-->
27+
<section class="sample-column">
28+
<h4 class="sample-title">Rounded Avatars</h4>
29+
<article class="avatars">
30+
<igx-avatar class="avatar-theme" icon="tag_faces" shape="rounded"></igx-avatar>
31+
832
<igx-avatar igxDrag icon="tag_faces" size="medium" shape="rounded"></igx-avatar>
933

1034
<igx-avatar icon="tag_faces" size="large" shape="rounded"></igx-avatar>

0 commit comments

Comments
 (0)