mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 03:00:58 +08:00
feat(badge): add small/default size for ionic theme (#29526)
This commit is contained in:
@ -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,"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
|
||||
|
8
core/src/components.d.ts
vendored
8
core/src/components.d.ts
vendored
@ -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. Defaults to `"small"` for the `ionic` theme, undefined for all other themes.
|
||||
*/
|
||||
"size"?: 'small';
|
||||
/**
|
||||
* The theme determines the visual appearance of the component.
|
||||
*/
|
||||
@ -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. Defaults to `"small"` for the `ionic` theme, undefined for all other themes.
|
||||
*/
|
||||
"size"?: 'small';
|
||||
/**
|
||||
* The theme determines the visual appearance of the component.
|
||||
*/
|
||||
|
32
core/src/components/badge/badge.ionic.scss
Normal file
32
core/src/components/badge/badge.ionic.scss
Normal file
@ -0,0 +1,32 @@
|
||||
@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-weight: globals.$ionic-font-weight-medium;
|
||||
}
|
||||
|
||||
// Badge Sizes
|
||||
// --------------------------------------------------
|
||||
|
||||
/* Small Badge */
|
||||
:host(.badge-small) {
|
||||
min-width: globals.$ionic-scale-800;
|
||||
height: globals.$ionic-scale-800;
|
||||
|
||||
font-size: globals.$ionic-font-size-400;
|
||||
|
||||
line-height: globals.$ionic-line-height-600;
|
||||
}
|
@ -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,
|
||||
})
|
||||
@ -26,12 +26,36 @@ export class Badge implements ComponentInterface {
|
||||
*/
|
||||
@Prop({ reflect: true }) color?: Color;
|
||||
|
||||
/**
|
||||
* Set to `"small"` for less height and width.
|
||||
* Defaults to `"small"` for the `ionic` theme, undefined for all other themes.
|
||||
*/
|
||||
@Prop() size?: 'small';
|
||||
|
||||
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>
|
||||
|
22
core/src/components/badge/test/size/badge.e2e.ts
Normal file
22
core/src/components/badge/test/size/badge.e2e.ts
Normal file
@ -0,0 +1,22 @@
|
||||
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`));
|
||||
});
|
||||
});
|
||||
});
|
Binary file not shown.
After Width: | Height: | Size: 459 B |
Binary file not shown.
After Width: | Height: | Size: 536 B |
Binary file not shown.
After Width: | Height: | Size: 440 B |
39
core/src/components/badge/test/size/index.html
Normal file
39
core/src/components/badge/test/size/index.html
Normal file
@ -0,0 +1,39 @@
|
||||
<!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-list>
|
||||
</ion-content>
|
||||
</ion-app>
|
||||
</body>
|
||||
</html>
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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'
|
||||
]);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user