Skip to content

Commit c2d6b21

Browse files
feat(avatar): use correct styles for icons in ionic theme (#29581)
Issue number: internal --------- ## What is the current behavior? Avatar icon styles use `1em` width/height which makes them change size based on the `font-size` ## What is the new behavior? Updates the `ionic` theme only to: - Set the `width` / `height` of icons in `ion-avatar` to use the scale tokens based on the Figma design - Removes the padding for avatars containing an icon - Updates the existing screenshots to show the new icon sizes ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information [Preview](https://ionic-framework-git-rou-10732-ionic1.vercel.app/src/components/avatar/test/size?ionic:theme=ionic)
1 parent 02f3ad0 commit c2d6b21

File tree

26 files changed

+37
-0
lines changed

26 files changed

+37
-0
lines changed

core/src/components/avatar/avatar.ionic.scss

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,35 @@
103103
:host(.avatar-rectangular) {
104104
--border-radius: #{globals.$ionic-border-radius-0};
105105
}
106+
107+
// Avatar Icon
108+
// --------------------------------------------------
109+
110+
:host(.avatar-icon) {
111+
@include padding(0);
112+
}
113+
114+
:host(.avatar-xsmall) ::slotted(ion-icon) {
115+
width: globals.$ionic-scale-400;
116+
height: globals.$ionic-scale-400;
117+
}
118+
119+
:host(.avatar-small) ::slotted(ion-icon) {
120+
width: globals.$ionic-scale-500;
121+
height: globals.$ionic-scale-500;
122+
}
123+
124+
:host(.avatar-medium) ::slotted(ion-icon) {
125+
width: globals.$ionic-scale-600;
126+
height: globals.$ionic-scale-600;
127+
}
128+
129+
:host(.avatar-large) ::slotted(ion-icon) {
130+
width: globals.$ionic-scale-800;
131+
height: globals.$ionic-scale-800;
132+
}
133+
134+
:host(.avatar-xlarge) ::slotted(ion-icon) {
135+
width: globals.$ionic-scale-1000;
136+
height: globals.$ionic-scale-1000;
137+
}

core/src/components/avatar/avatar.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class Avatar implements ComponentInterface {
4141
return !!this.el.querySelector('ion-img') || !!this.el.querySelector('img');
4242
}
4343

44+
get hasIcon() {
45+
return !!this.el.querySelector('ion-icon');
46+
}
47+
4448
private getSize(): string | undefined {
4549
const theme = getIonTheme(this);
4650
const { size } = this;
@@ -85,6 +89,7 @@ export class Avatar implements ComponentInterface {
8589
[`avatar-${size}`]: size !== undefined,
8690
[`avatar-${shape}`]: shape !== undefined,
8791
[`avatar-image`]: this.hasImage,
92+
[`avatar-icon`]: this.hasIcon,
8893
}}
8994
>
9095
<slot></slot>

0 commit comments

Comments
 (0)