Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 19 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +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,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: 8 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ export namespace Components {
* The mode determines the platform behaviors of the component.
*/
"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.
*/
"size"?: 'small' | 'medium' | 'large';
/**
* The theme determines the visual appearance of the component.
*/
Expand Down Expand Up @@ -5563,6 +5567,10 @@ declare namespace LocalJSX {
* The mode determines the platform behaviors of the component.
*/
"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.
*/
"size"?: 'small' | 'medium' | 'large';
/**
* The theme determines the visual appearance of the component.
*/
Expand Down
59 changes: 59 additions & 0 deletions core/src/components/avatar/avatar.ionic.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@use "../../themes/ionic/ionic.globals.scss" as globals;
@import "./avatar";

// Ionic Avatar
// --------------------------------------------------

:host {
--padding-top: #{globals.$ionic-space-0};
--padding-bottom: #{globals.$ionic-space-0};

display: flex;

align-items: center;
justify-content: center;

background: globals.$ionic-color-neutral-100;
color: globals.$ionic-color-neutral-800;

font-weight: globals.$ionic-font-weight-regular;

line-height: globals.$ionic-line-height-600;
}

:host(:not(.avatar-image)) {
border: globals.$ionic-border-size-025 solid globals.$ionic-color-neutral-800;
}

// Avatar Sizes
// --------------------------------------------------

:host(.avatar-small) {
--padding-end: #{globals.$ionic-space-150};
--padding-start: #{globals.$ionic-space-150};

width: globals.$ionic-scale-800;
height: globals.$ionic-scale-800;

font-size: globals.$ionic-font-size-350;
}

:host(.avatar-medium) {
--padding-end: #{globals.$ionic-space-200};
--padding-start: #{globals.$ionic-space-200};

width: globals.$ionic-scale-1000;
height: globals.$ionic-scale-1000;

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;
}
38 changes: 36 additions & 2 deletions core/src/components/avatar/avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ComponentInterface } from '@stencil/core';
import { Component, Host, h } from '@stencil/core';
import { Component, Element, Host, Prop, h } from '@stencil/core';

import { getIonTheme } from '../../global/ionic-global';

Expand All @@ -12,17 +12,51 @@ import { getIonTheme } from '../../global/ionic-global';
styleUrls: {
ios: 'avatar.ios.scss',
md: 'avatar.md.scss',
ionic: 'avatar.md.scss',
ionic: 'avatar.ionic.scss',
},
shadow: true,
})
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.
*
* Defaults to `"medium"` for the `ionic` theme, undefined for all other themes.
*/
@Prop() size?: 'small' | 'medium' | 'large';

get hasImage() {
return !!this.el.querySelector('ion-img') || !!this.el.querySelector('img');
}

private getSize(): string | undefined {
const theme = getIonTheme(this);
const { size } = this;

// TODO(ROU-10752): Remove theme check when sizes are defined for all themes.
if (theme !== 'ionic') {
return undefined;
}

if (size === undefined) {
return 'medium';
}

return size;
}

render() {
const theme = getIonTheme(this);
const size = this.getSize();

return (
<Host
class={{
[theme]: true,
[`avatar-${size}`]: size !== undefined,
[`avatar-image`]: this.hasImage,
}}
>
<slot></slot>
Expand Down
144 changes: 144 additions & 0 deletions core/src/components/avatar/test/size/avatar.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';

/**
* This behavior does not vary across directions.
*/
configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screenshot, title }) => {
test.describe(title('avatar: size'), () => {
test.describe('small', () => {
test('should not have visual regressions when containing text', async ({ page }) => {
await page.setContent(
`
<ion-avatar size="small">AB</ion-avatar>
`,
config
);

const avatar = page.locator('ion-avatar');

await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-small-text`));
});

test('should not have visual regressions when containing an icon', async ({ page }) => {
await page.setContent(
`
<ion-avatar size="small">
<ion-icon name="person-outline"></ion-icon>
</ion-avatar>
`,
config
);

const avatar = page.locator('ion-avatar');

await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-small-icon`));
});

test('should not have visual regressions when containing an image', async ({ page }) => {
await page.setContent(
`
<ion-avatar size="small">
<img src="/src/components/avatar/test/avatar.svg"/>
</ion-avatar>
`,
config
);

const avatar = page.locator('ion-avatar');

await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-small-image`));
});
});

test.describe('medium', () => {
test('should not have visual regressions when containing text', async ({ page }) => {
await page.setContent(
`
<ion-avatar size="medium">AB</ion-avatar>
`,
config
);

const avatar = page.locator('ion-avatar');

await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-medium-text`));
});

test('should not have visual regressions when containing an icon', async ({ page }) => {
await page.setContent(
`
<ion-avatar size="medium">
<ion-icon name="person-outline"></ion-icon>
</ion-avatar>
`,
config
);

const avatar = page.locator('ion-avatar');

await expect(avatar).toHaveScreenshot(screenshot(`avatar-size-medium-icon`));
});

test('should not have visual regressions when containing an image', async ({ page }) => {
await page.setContent(
`
<ion-avatar size="medium">
<img src="/src/components/avatar/test/avatar.svg"/>
</ion-avatar>
`,
config
);

const avatar = page.locator('ion-avatar');

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`));
});
});
});
});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions core/src/components/avatar/test/size/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8" />
<title>Avatar - Size</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
<script src="../../../../../scripts/testing/scripts.js"></script>
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>

<style>
.container {
display: flex;
gap: 10px;
}
</style>
</head>

<body>
<ion-app>
<ion-header>
<ion-toolbar>
<ion-title>Avatar - Size</ion-title>
</ion-toolbar>
</ion-header>

<ion-content class="ion-padding" id="content" no-bounce>
<h2>Default</h2>
<div class="container">
<ion-avatar>AB</ion-avatar>
<ion-avatar>
<ion-icon name="person-outline"></ion-icon>
</ion-avatar>
<ion-avatar>
<img src="/src/components/avatar/test/avatar.svg" />
</ion-avatar>
</div>

<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>
<div class="container">
<ion-avatar size="small">
<ion-icon name="person-outline"></ion-icon>
</ion-avatar>
<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>
<div class="container">
<ion-avatar size="small">
<img src="/src/components/avatar/test/avatar.svg" />
</ion-avatar>
<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>
</body>
</html>
4 changes: 2 additions & 2 deletions packages/angular/src/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ export declare interface IonApp extends Components.IonApp {}


@ProxyCmp({
inputs: ['mode', 'theme']
inputs: ['mode', 'size', 'theme']
})
@Component({
selector: 'ion-avatar',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['mode', 'theme'],
inputs: ['mode', 'size', 'theme'],
})
export class IonAvatar {
protected el: HTMLElement;
Expand Down