feat(avatar): add styles for large size in ionic theme (#29541)

Issue number: internal

---------

## What is the current behavior?
Avatar does not have styles for the `"large"` size in the ionic theme.

## What is the new behavior?
- Adds the styles for the large size (width, height, padding, font size)
- Adds e2e test for large size to the existing avatar test for sizes

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

## Other information

[Preview](https://ionic-framework-git-rou-10736-ionic1.vercel.app/src/components/avatar/test/size?ionic:theme=ionic)
This commit is contained in:
Brandy Carney
2024-05-23 12:44:35 -04:00
committed by GitHub
parent fea59b73aa
commit 7f8be3e18c
15 changed files with 70 additions and 7 deletions

View File

@ -184,7 +184,7 @@ ion-app,prop,theme,"ios" | "md" | "ionic",undefined,false,false
ion-avatar,shadow ion-avatar,shadow
ion-avatar,prop,mode,"ios" | "md",undefined,false,false ion-avatar,prop,mode,"ios" | "md",undefined,false,false
ion-avatar,prop,size,"medium" | "small" | undefined,undefined,false,false ion-avatar,prop,size,"large" | "medium" | "small" | undefined,undefined,false,false
ion-avatar,prop,theme,"ios" | "md" | "ionic",undefined,false,false ion-avatar,prop,theme,"ios" | "md" | "ionic",undefined,false,false
ion-avatar,css-prop,--border-radius,ionic ion-avatar,css-prop,--border-radius,ionic
ion-avatar,css-prop,--border-radius,ios ion-avatar,css-prop,--border-radius,ios

View File

@ -336,9 +336,9 @@ export namespace Components {
*/ */
"mode"?: "ios" | "md"; "mode"?: "ios" | "md";
/** /**
* Set to `"small"` for a compact size, or to `"medium"` for the default height and width. Defaults to `"medium"` for the `ionic` theme, undefined for all other themes. * Set to `"small"` for a compact size, `"medium"` for the default height and width, or to `"large"` for a larger size. Defaults to `"medium"` for the `ionic` theme, undefined for all other themes.
*/ */
"size"?: 'small' | 'medium'; "size"?: 'small' | 'medium' | 'large';
/** /**
* The theme determines the visual appearance of the component. * The theme determines the visual appearance of the component.
*/ */
@ -5568,9 +5568,9 @@ declare namespace LocalJSX {
*/ */
"mode"?: "ios" | "md"; "mode"?: "ios" | "md";
/** /**
* Set to `"small"` for a compact size, or to `"medium"` for the default height and width. Defaults to `"medium"` for the `ionic` theme, undefined for all other themes. * Set to `"small"` for a compact size, `"medium"` for the default height and width, or to `"large"` for a larger size. Defaults to `"medium"` for the `ionic` theme, undefined for all other themes.
*/ */
"size"?: 'small' | 'medium'; "size"?: 'small' | 'medium' | 'large';
/** /**
* The theme determines the visual appearance of the component. * The theme determines the visual appearance of the component.
*/ */

View File

@ -47,3 +47,13 @@
font-size: globals.$ionic-font-size-400; font-size: globals.$ionic-font-size-400;
} }
:host(.avatar-large) {
--padding-end: #{globals.$ionic-space-250};
--padding-start: #{globals.$ionic-space-250};
width: globals.$ionic-scale-1200;
height: globals.$ionic-scale-1200;
font-size: globals.$ionic-font-size-450;
}

View File

@ -20,11 +20,12 @@ export class Avatar implements ComponentInterface {
@Element() el!: HTMLElement; @Element() el!: HTMLElement;
/** /**
* Set to `"small"` for a compact size, or to `"medium"` for the default height and width. * Set to `"small"` for a compact size, `"medium"` for the default height and width, or to
* `"large"` for a larger size.
* *
* Defaults to `"medium"` for the `ionic` theme, undefined for all other themes. * Defaults to `"medium"` for the `ionic` theme, undefined for all other themes.
*/ */
@Prop() size?: 'small' | 'medium'; @Prop() size?: 'small' | 'medium' | 'large';
get hasImage() { get hasImage() {
return !!this.el.querySelector('ion-img') || !!this.el.querySelector('img'); return !!this.el.querySelector('ion-img') || !!this.el.querySelector('img');

View File

@ -95,5 +95,50 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-medium-image`)); await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-medium-image`));
}); });
}); });
test.describe('large', () => {
test('should not have visual regressions when containing text', async ({ page }) => {
await page.setContent(
`
<ion-avatar size="large">AB</ion-avatar>
`,
config
);
const avatar = page.locator('ion-avatar');
await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-large-text`));
});
test('should not have visual regressions when containing an icon', async ({ page }) => {
await page.setContent(
`
<ion-avatar size="large">
<ion-icon name="person-outline"></ion-icon>
</ion-avatar>
`,
config
);
const avatar = page.locator('ion-avatar');
await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-large-icon`));
});
test('should not have visual regressions when containing an image', async ({ page }) => {
await page.setContent(
`
<ion-avatar size="large">
<img src="/src/components/avatar/test/avatar.svg"/>
</ion-avatar>
`,
config
);
const avatar = page.locator('ion-avatar');
await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-large-image`));
});
});
}); });
}); });

View File

@ -45,6 +45,7 @@
<div class="container"> <div class="container">
<ion-avatar size="small">AB</ion-avatar> <ion-avatar size="small">AB</ion-avatar>
<ion-avatar size="medium">AB</ion-avatar> <ion-avatar size="medium">AB</ion-avatar>
<ion-avatar size="large">AB</ion-avatar>
</div> </div>
<h2>Icons</h2> <h2>Icons</h2>
@ -55,6 +56,9 @@
<ion-avatar size="medium"> <ion-avatar size="medium">
<ion-icon name="person-outline"></ion-icon> <ion-icon name="person-outline"></ion-icon>
</ion-avatar> </ion-avatar>
<ion-avatar size="large">
<ion-icon name="person-outline"></ion-icon>
</ion-avatar>
</div> </div>
<h2>Images</h2> <h2>Images</h2>
@ -65,6 +69,9 @@
<ion-avatar size="medium"> <ion-avatar size="medium">
<img src="/src/components/avatar/test/avatar.svg" /> <img src="/src/components/avatar/test/avatar.svg" />
</ion-avatar> </ion-avatar>
<ion-avatar size="large">
<img src="/src/components/avatar/test/avatar.svg" />
</ion-avatar>
</div> </div>
</ion-content> </ion-content>
</ion-app> </ion-app>