Skip to content

Commit 9beca98

Browse files
committed
fix(badge): add custom properties and make sure color works properly
references #14850
1 parent 8fef263 commit 9beca98

File tree

3 files changed

+78
-6
lines changed

3 files changed

+78
-6
lines changed

core/src/components/badge/badge.scss

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,31 @@
44
// --------------------------------------------------
55

66
:host {
7-
--ion-color-base: #{ion-color(primary, base)};
8-
--ion-color-contrast: #{ion-color(primary, contrast)};
7+
/**
8+
* @prop --background: Background of the badge
9+
* @prop --color: Text color of the badge
10+
*
11+
* @prop --padding-top: Padding top of the badge
12+
* @prop --padding-end: Padding end of the badge
13+
* @prop --padding-bottom: Padding bottom of the badge
14+
* @prop --padding-start: Padding start of the badge
15+
*/
16+
--background: #{ion-color(primary, base)};
17+
--color: #{ion-color(primary, contrast)};
18+
--padding-top: #{$badge-padding-top};
19+
--padding-end: #{$badge-padding-end};
20+
--padding-bottom: #{$badge-padding-bottom};
21+
--padding-start: #{$badge-padding-start};
922

1023
@include font-smoothing();
11-
@include padding($badge-padding-top, $badge-padding-end, $badge-padding-bottom, $badge-padding-start);
24+
@include padding(var(--padding-top), var(--padding-end), var(--padding-bottom), var(--padding-start));
1225

1326
display: inline-block;
1427

1528
min-width: $badge-min-width;
1629

17-
background-color: #{current-color(base)};
18-
color: #{current-color(contrast)};
30+
background: var(--background);
31+
color: var(--color);
1932

2033
font-size: $badge-font-size;
2134
font-weight: $badge-font-weight;
@@ -30,6 +43,11 @@
3043
vertical-align: baseline;
3144
}
3245

46+
:host(.ion-color) {
47+
background: #{current-color(base)};
48+
color: #{current-color(contrast)};
49+
}
50+
3351
:host(:empty) {
3452
display: none;
3553
}

core/src/components/badge/readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ The mode determines which platform styles to use.
4444
Possible values are: `"ios"` or `"md"`.
4545

4646

47+
## CSS Custom Properties
48+
49+
| Name | Description |
50+
| ------------------ | --------------------------- |
51+
| `--background` | Background of the badge |
52+
| `--color` | Text color of the badge |
53+
| `--padding-bottom` | Padding bottom of the badge |
54+
| `--padding-end` | Padding end of the badge |
55+
| `--padding-start` | Padding start of the badge |
56+
| `--padding-top` | Padding top of the badge |
57+
4758

4859
----------------------------------------------
4960

core/src/components/badge/test/standalone/index.html

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
<link rel="stylesheet" type="text/css" href="/css/ionic.min.css">
1010
</head>
1111

12-
<body>
12+
<body padding>
13+
<h1>Default</h1>
14+
1315
<!-- Default -->
1416
<ion-badge>99</ion-badge>
1517

18+
<hr>
19+
1620
<!-- Colors -->
1721
<ion-badge color="primary">11</ion-badge>
1822
<ion-badge color="secondary">22</ion-badge>
@@ -23,5 +27,44 @@
2327
<ion-badge color="light">77</ion-badge>
2428
<ion-badge color="medium">88</ion-badge>
2529
<ion-badge color="dark">99</ion-badge>
30+
31+
<h1>Custom</h1>
32+
33+
<!-- Custom Font -->
34+
<ion-badge class="wide">wide</ion-badge>
35+
<ion-badge class="large">large</ion-badge>
36+
<ion-badge class="round">round</ion-badge>
37+
38+
<!-- Custom Colors -->
39+
<ion-badge class="custom">custom</ion-badge>
40+
<ion-badge color="secondary" class="custom">custom w/ secondary</ion-badge>
41+
42+
<style>
43+
ion-badge {
44+
--background: blue;
45+
}
46+
47+
.wide {
48+
min-width: 80px;
49+
}
50+
51+
.large {
52+
font-weight: normal;
53+
font-size: 24px;
54+
}
55+
56+
.round {
57+
width: 60px;
58+
height: 60px;
59+
border-radius: 50%;
60+
vertical-align: middle;
61+
line-height: 50px;
62+
}
63+
64+
.custom {
65+
--background: lightpink;
66+
--color: #222;
67+
}
68+
</style>
2669
</body>
2770
</html>

0 commit comments

Comments
 (0)