Skip to content

Commit ab9acac

Browse files
Add support for badges in ion-button
1 parent b7cfd97 commit ab9acac

26 files changed

+153
-4
lines changed

core/src/components/badge/badge.common.scss

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use "../../themes/ionic/ionic.globals.scss" as globals;
12
@use "../../themes/functions.color" as color;
23
@import "../../themes/mixins";
34
@import "./badge.common.vars";
@@ -48,6 +49,14 @@
4849
color: #{color.current-color(contrast)};
4950
}
5051

52+
:host(:not(.in-tab-button).badge-vertical-top) {
53+
top: 0;
54+
}
55+
56+
:host(:not(.in-tab-button).badge-vertical-bottom) {
57+
bottom: 0;
58+
}
59+
5160
// Badge Empty (hint)
5261
// --------------------------------------------------
5362

@@ -56,10 +65,24 @@
5665
position: absolute;
5766
}
5867

59-
:host(:not(.in-tab-button):empty.badge-vertical-top) {
60-
top: 0;
68+
// Badge in Button
69+
// --------------------------------------------------
70+
71+
:host([vertical]:not(.in-tab-button).in-button) {
72+
// stylelint-disable-next-line property-disallowed-list
73+
right: globals.$ion-space-050;
6174
}
6275

63-
:host(:not(.in-tab-button):empty.badge-vertical-bottom) {
64-
bottom: 0;
76+
:host(:not(:empty).in-button) {
77+
min-width: globals.$ion-scale-400;
78+
height: globals.$ion-scale-400;
79+
80+
font-size: globals.$ion-font-size-300;
81+
82+
line-height: globals.$ion-font-line-height-500;
83+
84+
::slotted(ion-icon) {
85+
width: globals.$ion-scale-300;
86+
height: globals.$ion-scale-300;
87+
}
6588
}

core/src/components/badge/badge.ionic.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,11 @@
190190

191191
transform: translate(-50%, -50%);
192192
}
193+
194+
// Badge in Button
195+
// --------------------------------------------------
196+
197+
:host([vertical]:not(.in-tab-button).in-button.badge-small) {
198+
// stylelint-disable-next-line property-disallowed-list
199+
right: calc(-1 * globals.$ion-space-050);
200+
}

core/src/components/badge/badge.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export class Badge implements ComponentInterface {
9999
[`badge-${shape}`]: shape !== undefined,
100100
[`badge-${size}`]: size !== undefined,
101101
[`badge-vertical-${this.vertical}`]: this.vertical !== undefined,
102+
'in-button': hostContext('ion-button', this.el),
102103
'in-tab-button': hostContext('ion-tab-button', this.el),
103104
})}
104105
>

core/src/components/badge/test/hint/badge.e2e.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,22 @@ configs({ directions: ['ltr'], modes: ['md', 'ios', 'ionic-md'] }).forEach(({ co
3939
await expect(container).toHaveScreenshot(screenshot(`badge-hint-tab-button-icon-bottom`));
4040
});
4141
});
42+
43+
test.describe(title('badge: hint inside button'), () => {
44+
test('should not have visual regressions when icon is on the top', async ({ page }) => {
45+
await page.goto('/src/components/badge/test/hint', config);
46+
47+
const container = page.locator('#button-top');
48+
49+
await expect(container).toHaveScreenshot(screenshot(`badge-hint-button-top`));
50+
});
51+
52+
test('should not have visual regressions when icon is at the bottom', async ({ page }) => {
53+
await page.goto('/src/components/badge/test/hint', config);
54+
55+
const container = page.locator('#button-bottom');
56+
57+
await expect(container).toHaveScreenshot(screenshot(`badge-hint-button-bottom`));
58+
});
59+
});
4260
});
4.51 KB
Loading
5.91 KB
Loading
5.85 KB
Loading
5.76 KB
Loading
8.58 KB
Loading
8.21 KB
Loading

0 commit comments

Comments
 (0)