Skip to content

Commit 8c4bf8b

Browse files
feat(button): add support for badge (#30303)
Issue number: internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? The ion-badge is not currently supported when inside the ion-button. ## What is the new behavior? - The experience of the ion-badge inside the ion-button has been implemented according to our designs. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> --------- Co-authored-by: José Rio <[email protected]>
1 parent 69340bf commit 8c4bf8b

File tree

61 files changed

+169
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+169
-1
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,32 @@
198198

199199
transform: translate(-50%, -50%);
200200
}
201+
202+
// Badge in Button
203+
// --------------------------------------------------
204+
205+
:host([vertical]:not(.in-tab-button).in-button.badge-xxsmall),
206+
:host([vertical]:not(.in-tab-button).in-button.badge-xsmall),
207+
:host([vertical]:not(.in-tab-button).in-button.badge-small) {
208+
@include globals.position(null, calc(-1 * var(globals.$ion-space-050)));
209+
}
210+
211+
:host([vertical]:not(.in-tab-button).in-button.badge-medium),
212+
:host([vertical]:not(.in-tab-button).in-button.badge-large),
213+
:host([vertical]:not(.in-tab-button).in-button.badge-xlarge) {
214+
@include globals.position(null, globals.$ion-space-050);
215+
}
216+
217+
:host(:not(:empty).in-button) {
218+
min-width: globals.$ion-scale-400;
219+
height: globals.$ion-scale-400;
220+
221+
font-size: globals.$ion-font-size-300;
222+
223+
line-height: globals.$ion-font-line-height-500;
224+
225+
::slotted(ion-icon) {
226+
width: globals.$ion-scale-300;
227+
height: globals.$ion-scale-300;
228+
}
229+
}

core/src/components/badge/badge.native.scss

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414

1515
// TODO(ROU-10747): Review size styles when sizes are defined for native themes.
16-
:host([vertical]:not(.in-tab-button)),
16+
:host([vertical]:not(.in-button):not(.in-tab-button)),
1717
:host(:empty) {
1818
--padding-start: 0;
1919
--padding-end: 0;
@@ -29,3 +29,20 @@
2929

3030
line-height: 10px;
3131
}
32+
33+
// Badge in Button
34+
// --------------------------------------------------
35+
36+
:host(:not(:empty).in-button) {
37+
min-width: $badge-size-in-button;
38+
height: $badge-size-in-button;
39+
40+
font-size: $badge-font-size-in-button;
41+
42+
line-height: $badge-line-height-in-button;
43+
44+
::slotted(ion-icon) {
45+
width: $badge-icon-size-in-button;
46+
height: $badge-icon-size-in-button;
47+
}
48+
}

core/src/components/badge/badge.native.vars.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import "../../themes/functions.font";
2+
@import "../../themes/functions.sizes";
23

34
// Badge
45
// --------------------------------------------------
@@ -8,3 +9,15 @@ $badge-hint-baseline-font-size: 8px;
89

910
/// @prop - Font size of the badge hint
1011
$badge-hint-font-size: dynamic-font($badge-hint-baseline-font-size);
12+
13+
/// @prop - Size of the badge when inside button
14+
$badge-size-in-button: 16px;
15+
16+
/// @prop - Font size of the badge when inside button
17+
$badge-font-size-in-button: px-to-rem(12);
18+
19+
/// @prop - Line height of the badge when inside button
20+
$badge-line-height-in-button: 20px;
21+
22+
/// @prop - Size of of the badge icon when inside button
23+
$badge-icon-size-in-button: 12px;

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.52 KB
5.92 KB
5.84 KB
5.75 KB
8.47 KB

0 commit comments

Comments
 (0)