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(badge): add medium size for ionic theme #29528

Merged
merged 20 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -310,6 +310,7 @@ ion-backdrop,event,ionBackdropTap,void,true
ion-badge,shadow
ion-badge,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
ion-badge,prop,mode,"ios" | "md",undefined,false,false
ion-badge,prop,size,"medium" | "small" | undefined,undefined,false,false
ion-badge,prop,theme,"ios" | "md" | "ionic",undefined,false,false
ion-badge,css-prop,--background,ionic
ion-badge,css-prop,--background,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 @@ -409,6 +409,10 @@ export namespace Components {
* The mode determines the platform behaviors of the component.
*/
"mode"?: "ios" | "md";
/**
* Set to `"small"` for less height and width. Set to "medium" for slightly larger dimensions. Defaults to `"small"` for the `ionic` theme, undefined for all other themes.
*/
"size"?: 'small' | 'medium';
/**
* The theme determines the visual appearance of the component.
*/
Expand Down Expand Up @@ -5637,6 +5641,10 @@ declare namespace LocalJSX {
* The mode determines the platform behaviors of the component.
*/
"mode"?: "ios" | "md";
/**
* Set to `"small"` for less height and width. Set to "medium" for slightly larger dimensions. Defaults to `"small"` for the `ionic` theme, undefined for all other themes.
*/
"size"?: 'small' | 'medium';
/**
* The theme determines the visual appearance of the component.
*/
Expand Down
38 changes: 38 additions & 0 deletions core/src/components/badge/badge.ionic.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@use "../../themes/ionic/ionic.globals.scss" as globals;
@import "./badge";

// Ionic Badge
// --------------------------------------------------

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

display: inline-flex;

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

font-size: globals.$ionic-font-size-400;
font-weight: globals.$ionic-font-weight-medium;

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

// Badge Sizes
// --------------------------------------------------
:host(.badge-small) {
min-width: globals.$ionic-scale-800;
height: globals.$ionic-scale-800;
}

:host(.badge-medium) {
min-width: globals.$ionic-scale-1000;
height: globals.$ionic-scale-1000;

font-size: globals.$ionic-font-size-450;

line-height: globals.$ionic-line-height-700;
}
26 changes: 25 additions & 1 deletion core/src/components/badge/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { Color } from '../../interface';
styleUrls: {
ios: 'badge.ios.scss',
md: 'badge.md.scss',
ionic: 'badge.md.scss',
ionic: 'badge.ionic.scss',
},
shadow: true,
})
Expand All @@ -26,12 +26,36 @@ export class Badge implements ComponentInterface {
*/
@Prop({ reflect: true }) color?: Color;

/**
* Set to `"small"` for less height and width. Set to "medium" for slightly larger dimensions.
* Defaults to `"small"` for the `ionic` theme, undefined for all other themes.
*/
@Prop() size?: 'small' | 'medium';

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

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

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

return size;
}

render() {
const size = this.getSize();
const theme = getIonTheme(this);
return (
<Host
class={createColorClasses(this.color, {
[theme]: true,
[`badge-${size}`]: size !== undefined,
})}
>
<slot></slot>
Expand Down
35 changes: 35 additions & 0 deletions core/src/components/badge/test/size/badge.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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('badge: size'), () => {
test('should render small badges', async ({ page }) => {
await page.setContent(
`
<ion-badge size="small">00</ion-badge>
`,
config
);

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

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

test('should render medium badges', async ({ page }) => {
await page.setContent(
`
<ion-badge size="medium">00</ion-badge>
`,
config
);

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

await expect(badge).toHaveScreenshot(screenshot(`badge-size-medium`));
});
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker but we should consider adding screenshots for the designs in Figma where there is a badge containing "1" and another containing "99+" to show how the badge looks as a circle and then wider.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that in a separate PR.

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.
43 changes: 43 additions & 0 deletions core/src/components/badge/test/size/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8" />
<title>Badge - 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>
</head>

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

<ion-content class="ion-padding" id="content" no-bounce>
<ion-list>
<ion-item>
<ion-label>Default Badge</ion-label>
<ion-badge slot="end">00</ion-badge>
</ion-item>
<ion-item>
<ion-label>Small Badge</ion-label>
<ion-badge slot="end" size="small">00</ion-badge>
</ion-item>
<ion-item>
<ion-label>Medium Badge</ion-label>
<ion-badge slot="end" size="medium">00</ion-badge>
</ion-item>
</ion-list>
</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 @@ -260,14 +260,14 @@ export declare interface IonBackdrop extends Components.IonBackdrop {


@ProxyCmp({
inputs: ['color', 'mode', 'theme']
inputs: ['color', 'mode', 'size', 'theme']
})
@Component({
selector: 'ion-badge',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['color', 'mode', 'theme'],
inputs: ['color', 'mode', 'size', 'theme'],
})
export class IonBadge {
protected el: HTMLElement;
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/standalone/src/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,14 @@ export declare interface IonBackdrop extends Components.IonBackdrop {

@ProxyCmp({
defineCustomElementFn: defineIonBadge,
inputs: ['color', 'mode', 'theme']
inputs: ['color', 'mode', 'size', 'theme']
})
@Component({
selector: 'ion-badge',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['color', 'mode', 'theme'],
inputs: ['color', 'mode', 'size', 'theme'],
standalone: true
})
export class IonBadge {
Expand Down
3 changes: 2 additions & 1 deletion packages/vue/src/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ export const IonBackdrop = /*@__PURE__*/ defineContainer<JSX.IonBackdrop>('ion-b


export const IonBadge = /*@__PURE__*/ defineContainer<JSX.IonBadge>('ion-badge', defineIonBadge, [
'color'
'color',
'size'
]);


Expand Down
Loading