feat(avatar): add styles for xsmall size in ionic theme (#29548)

Issue number: internal

---------

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

## What is the new behavior?
- Adds the styles for the xsmall size (width, height, padding, font
size, font weight and line height)
- Adds e2e test for xsmall 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-10733-ionic1.vercel.app/src/components/avatar/test/size?ionic:theme=ionic)
This commit is contained in:
Brandy Carney
2024-05-28 09:48:02 -04:00
committed by GitHub
parent 7f8be3e18c
commit b4ce7129b2
15 changed files with 74 additions and 8 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,size,"large" | "medium" | "small" | undefined,undefined,false,false
ion-avatar,prop,size,"large" | "medium" | "small" | "xsmall" | 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

View File

@ -336,9 +336,9 @@ export namespace Components {
*/
"mode"?: "ios" | "md";
/**
* 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.
* Set to `"xsmall"` for the smallest size, `"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' | 'large';
"size"?: `xsmall` | 'small' | 'medium' | 'large';
/**
* The theme determines the visual appearance of the component.
*/
@ -5568,9 +5568,9 @@ declare namespace LocalJSX {
*/
"mode"?: "ios" | "md";
/**
* 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.
* Set to `"xsmall"` for the smallest size, `"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' | 'large';
"size"?: `xsmall` | 'small' | 'medium' | 'large';
/**
* The theme determines the visual appearance of the component.
*/

View File

@ -28,6 +28,20 @@
// Avatar Sizes
// --------------------------------------------------
:host(.avatar-xsmall) {
--padding-end: #{globals.$ionic-space-050};
--padding-start: #{globals.$ionic-space-050};
width: globals.$ionic-scale-600;
height: globals.$ionic-scale-600;
font-size: globals.$ionic-font-size-300;
font-weight: globals.$ionic-font-weight-medium;
line-height: globals.$ionic-line-height-500;
}
:host(.avatar-small) {
--padding-end: #{globals.$ionic-space-150};
--padding-start: #{globals.$ionic-space-150};

View File

@ -20,12 +20,12 @@ export class Avatar implements ComponentInterface {
@Element() el!: HTMLElement;
/**
* Set to `"small"` for a compact size, `"medium"` for the default height and width, or to
* `"large"` for a larger size.
* Set to `"xsmall"` for the smallest size, `"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' | 'large';
@Prop() size?: `xsmall` | 'small' | 'medium' | 'large';
get hasImage() {
return !!this.el.querySelector('ion-img') || !!this.el.querySelector('img');

View File

@ -6,6 +6,51 @@ import { configs, test } from '@utils/test/playwright';
*/
configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screenshot, title }) => {
test.describe(title('avatar: size'), () => {
test.describe('xsmall', () => {
test('should not have visual regressions when containing text', async ({ page }) => {
await page.setContent(
`
<ion-avatar size="xsmall">AB</ion-avatar>
`,
config
);
const avatar = page.locator('ion-avatar');
await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-xsmall-text`));
});
test('should not have visual regressions when containing an icon', async ({ page }) => {
await page.setContent(
`
<ion-avatar size="xsmall">
<ion-icon name="person-outline"></ion-icon>
</ion-avatar>
`,
config
);
const avatar = page.locator('ion-avatar');
await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-xsmall-icon`));
});
test('should not have visual regressions when containing an image', async ({ page }) => {
await page.setContent(
`
<ion-avatar size="xsmall">
<img src="/src/components/avatar/test/avatar.svg"/>
</ion-avatar>
`,
config
);
const avatar = page.locator('ion-avatar');
await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-xsmall-image`));
});
});
test.describe('small', () => {
test('should not have visual regressions when containing text', async ({ page }) => {
await page.setContent(

View File

@ -43,6 +43,7 @@
<h2>Text</h2>
<div class="container">
<ion-avatar size="xsmall">AB</ion-avatar>
<ion-avatar size="small">AB</ion-avatar>
<ion-avatar size="medium">AB</ion-avatar>
<ion-avatar size="large">AB</ion-avatar>
@ -50,6 +51,9 @@
<h2>Icons</h2>
<div class="container">
<ion-avatar size="xsmall">
<ion-icon name="person-outline"></ion-icon>
</ion-avatar>
<ion-avatar size="small">
<ion-icon name="person-outline"></ion-icon>
</ion-avatar>
@ -63,6 +67,9 @@
<h2>Images</h2>
<div class="container">
<ion-avatar size="xsmall">
<img src="/src/components/avatar/test/avatar.svg" />
</ion-avatar>
<ion-avatar size="small">
<img src="/src/components/avatar/test/avatar.svg" />
</ion-avatar>