Skip to content

Commit 8855618

Browse files
BenOsodracIonitronthetaPC
authored
feat(badge): add support for number and icons with vertical prop (#30305)
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? <!-- Please describe the current behavior that you are modifying. --> Currently the vertical prop only works for empty badges. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Added styles for badge with numbers or icons to be used as hint (vertical prop) - Added new tests for these scenarios and updated snapshots. - Added best effort styles for ios/md to look decent (not on the scope of this task and no UI from figma). ## 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. --> [Badge Ionic Hint](https://ionic-framework-git-rou-11750-ionic1.vercel.app/src/components/badge/test/hint?ionic:theme=ionic) --------- Co-authored-by: ionitron <[email protected]> Co-authored-by: Maria Hutt <[email protected]>
1 parent 8f05689 commit 8855618

20 files changed

+231
-15
lines changed

core/src/components/avatar/avatar.ionic.scss

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,77 @@
153153
height: globals.$ion-scale-1000;
154154
}
155155

156-
// Avatar Empty Badge (hint)
156+
// Avatar Badge Empty (hint)
157157
// --------------------------------------------------
158158

159159
:host ::slotted(ion-badge.badge-vertical-top:empty) {
160-
transform: translate(globals.$ion-scale-050, calc(globals.$ion-scale-050 * -1));
160+
@include globals.transform(translate(globals.$ion-scale-050, calc(globals.$ion-scale-050 * -1)));
161161
}
162162

163163
:host(.avatar-xxsmall) ::slotted(ion-badge.badge-vertical-top:empty) {
164-
transform: translate(globals.$ion-scale-100, calc(globals.$ion-scale-100 * -1));
164+
@include globals.transform(translate(globals.$ion-scale-100, calc(globals.$ion-scale-100 * -1)));
165165
}
166166

167167
:host ::slotted(ion-badge.badge-vertical-bottom:empty) {
168-
transform: translate(0, globals.$ion-scale-100);
168+
@include globals.transform(translate(0, globals.$ion-scale-100));
169169
}
170170

171171
:host(.avatar-xxsmall) ::slotted(ion-badge.badge-vertical-bottom:empty) {
172-
transform: translate(globals.$ion-scale-100, calc(globals.$ion-scale-100));
172+
@include globals.transform(translate(globals.$ion-scale-100, globals.$ion-scale-100));
173+
}
174+
175+
// Avatar Badge Bottom (hint)
176+
// --------------------------------------------------
177+
178+
:host ::slotted(ion-badge.badge-vertical-bottom:not(:empty)) {
179+
@include globals.transform(translate(50%, 50%));
180+
}
181+
182+
:host(.avatar-xxsmall) ::slotted(ion-badge.badge-vertical-bottom:not(:empty)) {
183+
@include globals.position(null, globals.$ion-scale-100, globals.$ion-scale-100, null);
184+
@include globals.transform(translate(100%, 100%));
185+
}
186+
187+
:host(.avatar-xsmall) ::slotted(ion-badge.badge-vertical-bottom:not(:empty)) {
188+
@include globals.position(null, calc(globals.$ion-scale-050 * -1), calc(globals.$ion-scale-050 * -1), null);
189+
}
190+
191+
:host(.avatar-small) ::slotted(ion-badge.badge-vertical-bottom:not(:empty)),
192+
:host(.avatar-medium) ::slotted(ion-badge.badge-vertical-bottom:not(:empty)),
193+
:host(.avatar-large) ::slotted(ion-badge.badge-vertical-bottom:not(:empty)) {
194+
@include globals.position(null, globals.$ion-scale-050, globals.$ion-scale-050, null);
195+
}
196+
197+
:host(.avatar-xlarge) ::slotted(ion-badge.badge-vertical-bottom:not(:empty)) {
198+
@include globals.position(null, globals.$ion-scale-150, globals.$ion-scale-150, null);
199+
}
200+
201+
// Avatar Badge Top (hint)
202+
// --------------------------------------------------
203+
204+
:host ::slotted(ion-badge.badge-vertical-top:not(:empty)) {
205+
@include globals.transform(translate(50%, -50%));
206+
}
207+
208+
:host(.avatar-xxsmall) ::slotted(ion-badge.badge-vertical-top:not(:empty)) {
209+
@include globals.position(globals.$ion-scale-050, 0, null, null);
210+
}
211+
212+
:host(.avatar-xsmall) ::slotted(ion-badge.badge-vertical-top:not(:empty)) {
213+
@include globals.position(globals.$ion-scale-100, calc(globals.$ion-scale-050 * -1), null, null);
214+
}
215+
216+
:host(.avatar-small) ::slotted(ion-badge.badge-vertical-top:not(:empty)),
217+
:host(.avatar-medium) ::slotted(ion-badge.badge-vertical-top:not(:empty)) {
218+
@include globals.position(globals.$ion-scale-150, 0, null, null);
219+
}
220+
221+
:host(.avatar-large) ::slotted(ion-badge.badge-vertical-top:not(:empty)) {
222+
@include globals.position(globals.$ion-scale-150, globals.$ion-scale-050, null, null);
223+
}
224+
225+
:host(.avatar-xlarge) ::slotted(ion-badge.badge-vertical-top:not(:empty)) {
226+
@include globals.position(globals.$ion-scale-150, globals.$ion-scale-150, null, null);
173227
}
174228

175229
// Avatar Disabled

core/src/components/avatar/avatar.md.scss

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use "../../themes/native/native.globals.md" as globals;
12
@import "./avatar.common";
23
@import "./avatar.md.vars";
34

@@ -15,9 +16,17 @@
1516
// --------------------------------------------------
1617

1718
::slotted(ion-badge.badge-vertical-top:empty) {
18-
transform: translate(-50%, 50%);
19+
@include globals.transform(translate(-50%, 50%));
1920
}
2021

2122
::slotted(ion-badge.badge-vertical-bottom:empty) {
22-
transform: translateX(-100%);
23+
@include globals.transform(translateX(-100%));
24+
}
25+
26+
:host ::slotted(ion-badge.badge-vertical-top:not(:empty)) {
27+
@include globals.transform(translate(0, 100%));
28+
}
29+
30+
:host ::slotted(ion-badge.badge-vertical-bottom:not(:empty)) {
31+
@include globals.transform(translate(0, -100%));
2332
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@
4848
color: #{color.current-color(contrast)};
4949
}
5050

51-
// Badge Empty (hint)
51+
// Badge (hint)
5252
// --------------------------------------------------
5353

5454
:host([vertical]:not(.in-tab-button)) {
5555
@include position(null, 0, null, null);
5656
position: absolute;
5757
}
5858

59-
:host(:not(.in-tab-button):empty.badge-vertical-top) {
59+
:host(:not(.in-tab-button)[vertical].badge-vertical-top) {
6060
top: 0;
6161
}
6262

63-
:host(:not(.in-tab-button):empty.badge-vertical-bottom) {
63+
:host(:not(.in-tab-button)[vertical].badge-vertical-bottom) {
6464
bottom: 0;
6565
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,22 @@
146146
height: globals.$ion-scale-1000;
147147
}
148148

149-
// Badge Empty
149+
// Badge (hint)
150150
// --------------------------------------------------
151151

152152
:host(:empty) {
153153
--padding-start: 0;
154154
--padding-end: 0;
155155
}
156156

157-
// Badge Sizes Empty
157+
:host([vertical]:not(:empty)) {
158+
--padding-start: #{globals.$ion-scale-100};
159+
--padding-end: #{globals.$ion-scale-100};
160+
--padding-top: #{globals.$ion-scale-100};
161+
--padding-bottom: #{globals.$ion-scale-100};
162+
}
163+
164+
// Badge (hint) Sizes
158165
// --------------------------------------------------
159166

160167
/* sm */
@@ -182,8 +189,9 @@
182189
position: relative;
183190
}
184191

185-
// Badge Icon when Inside Tab Button
186-
:host([vertical].in-tab-button) ::slotted(ion-icon) {
192+
// Icon Inside Badge Hint
193+
// --------------------------------------------------
194+
:host([vertical]) ::slotted(ion-icon) {
187195
@include globals.position(50%, null, null, 50%);
188196

189197
position: absolute;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import "../../themes/native/native.globals.md";
22
@import "./badge.common";
3-
@import "./badge.common.vars";
3+
@import "./badge.native.vars";
44

55
// Badge
66
// --------------------------------------------------
@@ -13,6 +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)),
1617
:host(:empty) {
1718
--padding-start: 0;
1819
--padding-end: 0;
@@ -23,4 +24,8 @@
2324

2425
width: $badge-min-width;
2526
height: $badge-min-width;
27+
28+
font-size: $badge-hint-font-size;
29+
30+
line-height: 10px;
2631
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@import "../../themes/functions.font";
2+
3+
// Badge
4+
// --------------------------------------------------
5+
6+
/// @prop - Font size of the badge hint
7+
$badge-hint-baseline-font-size: 8px;
8+
9+
/// @prop - Font size of the badge hint
10+
$badge-hint-font-size: dynamic-font($badge-hint-baseline-font-size);
24.9 KB
Loading
27.2 KB
Loading
29.9 KB
Loading
8.38 KB
Loading

0 commit comments

Comments
 (0)