Skip to content

Commit

Permalink
feat(avatar): add styles for large size in ionic theme (#29541)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
brandyscarney authored May 23, 2024
1 parent fea59b7 commit 7f8be3e
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ ion-app,prop,theme,"ios" | "md" | "ionic",undefined,false,false

ion-avatar,shadow
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,css-prop,--border-radius,ionic
ion-avatar,css-prop,--border-radius,ios
Expand Down
8 changes: 4 additions & 4 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ export namespace Components {
*/
"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.
*/
Expand Down Expand Up @@ -5568,9 +5568,9 @@ declare namespace LocalJSX {
*/
"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.
*/
Expand Down
10 changes: 10 additions & 0 deletions core/src/components/avatar/avatar.ionic.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@

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;
}
5 changes: 3 additions & 2 deletions core/src/components/avatar/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ export class Avatar implements ComponentInterface {
@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.
*/
@Prop() size?: 'small' | 'medium';
@Prop() size?: 'small' | 'medium' | 'large';

get hasImage() {
return !!this.el.querySelector('ion-img') || !!this.el.querySelector('img');
Expand Down
45 changes: 45 additions & 0 deletions core/src/components/avatar/test/size/avatar.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,50 @@ configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screens
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`));
});
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions core/src/components/avatar/test/size/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ <h2>Text</h2>
<div class="container">
<ion-avatar size="small">AB</ion-avatar>
<ion-avatar size="medium">AB</ion-avatar>
<ion-avatar size="large">AB</ion-avatar>
</div>

<h2>Icons</h2>
Expand All @@ -55,6 +56,9 @@ <h2>Icons</h2>
<ion-avatar size="medium">
<ion-icon name="person-outline"></ion-icon>
</ion-avatar>
<ion-avatar size="large">
<ion-icon name="person-outline"></ion-icon>
</ion-avatar>
</div>

<h2>Images</h2>
Expand All @@ -65,6 +69,9 @@ <h2>Images</h2>
<ion-avatar size="medium">
<img src="/src/components/avatar/test/avatar.svg" />
</ion-avatar>
<ion-avatar size="large">
<img src="/src/components/avatar/test/avatar.svg" />
</ion-avatar>
</div>
</ion-content>
</ion-app>
Expand Down

0 comments on commit 7f8be3e

Please sign in to comment.