feat(avatar): add styles for rectangular shape in ionic theme (#29551)

Issue number: internal

---------

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

## What is the new behavior?
- Adds the styles for the rectangular shape (border radius)
- Adds e2e test for the rectangular shape

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

## Other information

[Preview](https://ionic-framework-git-rou-10740-ionic1.vercel.app/src/components/avatar/test/shape?ionic:theme=ionic)
This commit is contained in:
Brandy Carney
2024-05-28 13:46:06 -04:00
committed by GitHub
parent d4971581cc
commit 8ebece3e30
15 changed files with 66 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,prop,mode,"ios" | "md",undefined,false,false
ion-avatar,prop,shape,"round" | undefined,undefined,false,false
ion-avatar,prop,shape,"rectangular" | "round" | undefined,undefined,false,false
ion-avatar,prop,size,"large" | "medium" | "small" | "xlarge" | "xsmall" | undefined,undefined,false,false
ion-avatar,prop,theme,"ios" | "md" | "ionic",undefined,false,false
ion-avatar,css-prop,--border-radius,ionic

View File

@@ -336,9 +336,9 @@ export namespace Components {
*/
"mode"?: "ios" | "md";
/**
* Set to `"round"` for an avatar with fully rounded corners. Defaults to `"round"` for the `ionic` theme, undefined for all other themes.
* Set to `"round"` for an avatar with fully rounded corners, or `"rectangular"` for an avatar without rounded corners. Defaults to `"round"` for the `ionic` theme, undefined for all other themes.
*/
"shape"?: 'round';
"shape"?: 'round' | 'rectangular';
/**
* Set to `"xsmall"` for the smallest size, `"small"` for a compact size, `"medium"` for the default height and width, `"large"` for a larger size, or `"xlarge"` for the largest dimensions. Defaults to `"medium"` for the `ionic` theme, undefined for all other themes.
*/
@@ -5572,9 +5572,9 @@ declare namespace LocalJSX {
*/
"mode"?: "ios" | "md";
/**
* Set to `"round"` for an avatar with fully rounded corners. Defaults to `"round"` for the `ionic` theme, undefined for all other themes.
* Set to `"round"` for an avatar with fully rounded corners, or `"rectangular"` for an avatar without rounded corners. Defaults to `"round"` for the `ionic` theme, undefined for all other themes.
*/
"shape"?: 'round';
"shape"?: 'round' | 'rectangular';
/**
* Set to `"xsmall"` for the smallest size, `"small"` for a compact size, `"medium"` for the default height and width, `"large"` for a larger size, or `"xlarge"` for the largest dimensions. Defaults to `"medium"` for the `ionic` theme, undefined for all other themes.
*/

View File

@@ -92,3 +92,7 @@
:host(.avatar-round) {
--border-radius: #{globals.$ionic-border-radius-full};
}
:host(.avatar-rectangular) {
--border-radius: #{globals.$ionic-border-radius-0};
}

View File

@@ -29,11 +29,12 @@ export class Avatar implements ComponentInterface {
@Prop() size?: `xsmall` | 'small' | 'medium' | 'large' | 'xlarge';
/**
* Set to `"round"` for an avatar with fully rounded corners.
* Set to `"round"` for an avatar with fully rounded corners, or `"rectangular"`
* for an avatar without rounded corners.
*
* Defaults to `"round"` for the `ionic` theme, undefined for all other themes.
*/
@Prop() shape?: 'round';
@Prop() shape?: 'round' | 'rectangular';
get hasImage() {
return !!this.el.querySelector('ion-img') || !!this.el.querySelector('img');

View File

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

View File

@@ -49,6 +49,15 @@
<ion-avatar shape="round" size="large">AB</ion-avatar>
<ion-avatar shape="round" size="xlarge">AB</ion-avatar>
</div>
<h2>Rectangular</h2>
<div class="container">
<ion-avatar shape="rectangular" size="xsmall">AB</ion-avatar>
<ion-avatar shape="rectangular" size="small">AB</ion-avatar>
<ion-avatar shape="rectangular" size="medium">AB</ion-avatar>
<ion-avatar shape="rectangular" size="large">AB</ion-avatar>
<ion-avatar shape="rectangular" size="xlarge">AB</ion-avatar>
</div>
</ion-content>
</ion-app>
</body>