Skip to content

Commit b31e0ef

Browse files
feat(chip): add hue property for the ionic theme (#30308)
Issue number: internal --------- ## What is the current behavior? The chip component does not support the `hue` property. ## What is the new behavior? Adds support for the `bold` and `subtle` hue for the chip. Defaults to `subtle`. ## Does this introduce a breaking change? - [ ] Yes - [x] No
1 parent a9aa59b commit b31e0ef

26 files changed

+554
-71
lines changed

core/api.txt

+6
Original file line numberDiff line numberDiff line change
@@ -596,17 +596,23 @@ ion-checkbox,part,supporting-text
596596
ion-chip,shadow
597597
ion-chip,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
598598
ion-chip,prop,disabled,boolean,false,false,false
599+
ion-chip,prop,hue,"bold" | "subtle" | undefined,'subtle',false,false
599600
ion-chip,prop,mode,"ios" | "md",undefined,false,false
600601
ion-chip,prop,outline,boolean,false,false,false
601602
ion-chip,prop,shape,"rectangular" | "round" | "soft" | undefined,undefined,false,false
602603
ion-chip,prop,size,"large" | "small" | undefined,undefined,false,false
603604
ion-chip,prop,theme,"ios" | "md" | "ionic",undefined,false,false
605+
ion-chip,css-prop,--background,ionic
604606
ion-chip,css-prop,--background,ios
605607
ion-chip,css-prop,--background,md
608+
ion-chip,css-prop,--border-radius,ionic
606609
ion-chip,css-prop,--border-radius,ios
607610
ion-chip,css-prop,--border-radius,md
611+
ion-chip,css-prop,--color,ionic
608612
ion-chip,css-prop,--color,ios
609613
ion-chip,css-prop,--color,md
614+
ion-chip,css-prop,--focus-ring-color,ionic
615+
ion-chip,css-prop,--focus-ring-width,ionic
610616

611617
ion-col,shadow
612618
ion-col,prop,mode,"ios" | "md",undefined,false,false

core/src/components.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,10 @@ export namespace Components {
807807
* If `true`, the user cannot interact with the chip.
808808
*/
809809
"disabled": boolean;
810+
/**
811+
* Set to `"bold"` for a chip with vibrant, bold colors or to `"subtle"` for a chip with muted, subtle colors. Only applies to the `ionic` theme.
812+
*/
813+
"hue"?: 'bold' | 'subtle';
810814
/**
811815
* The mode determines the platform behaviors of the component.
812816
*/
@@ -6287,6 +6291,10 @@ declare namespace LocalJSX {
62876291
* If `true`, the user cannot interact with the chip.
62886292
*/
62896293
"disabled"?: boolean;
6294+
/**
6295+
* Set to `"bold"` for a chip with vibrant, bold colors or to `"subtle"` for a chip with muted, subtle colors. Only applies to the `ionic` theme.
6296+
*/
6297+
"hue"?: 'bold' | 'subtle';
62906298
/**
62916299
* The mode determines the platform behaviors of the component.
62926300
*/
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@import "../../themes/mixins";
2+
3+
// Chip: Common Styles
4+
// --------------------------------------------------
5+
6+
:host {
7+
/**
8+
* @prop --background: Background of the chip
9+
* @prop --color: Color of the chip
10+
* @prop --border-radius: Border radius of the chip
11+
*/
12+
@include font-smoothing();
13+
14+
display: inline-flex;
15+
16+
position: relative;
17+
18+
align-items: center;
19+
justify-content: center;
20+
21+
background: var(--background);
22+
color: var(--color);
23+
24+
cursor: pointer;
25+
26+
overflow: hidden;
27+
28+
box-sizing: border-box;
29+
30+
vertical-align: middle;
31+
}
32+
33+
:host(.chip-disabled) {
34+
cursor: default;
35+
pointer-events: none;
36+
}
+57-40
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
11
@use "../../themes/ionic/ionic.globals.scss" as globals;
2+
@use "./chip.common";
23

34
// Ionic Chip
45
// --------------------------------------------------
56

67
:host {
7-
--background: #{globals.$ion-primitives-neutral-100};
8-
--color: #{globals.$ion-primitives-neutral-900};
8+
/**
9+
* @prop --focus-ring-color: Color of the focus ring
10+
* @prop --focus-ring-width: Width of the focus ring
11+
*/
912
--focus-ring-color: #{globals.$ion-border-focus-default};
1013
--focus-ring-width: #{globals.$ion-border-size-050};
1114

12-
@include globals.font-smoothing;
1315
@include globals.padding(globals.$ion-space-150, globals.$ion-space-200);
1416
@include globals.border-radius(var(--border-radius));
1517

16-
display: inline-flex;
17-
18-
position: relative;
19-
20-
align-items: center;
21-
justify-content: center;
22-
2318
gap: globals.$ion-space-100;
2419

25-
background: var(--background);
26-
color: var(--color);
27-
2820
font-family: globals.$ion-font-family;
2921
font-weight: globals.$ion-font-weight-medium;
3022

3123
line-height: globals.$ion-font-line-height-full;
32-
33-
cursor: pointer;
34-
35-
overflow: hidden;
36-
37-
box-sizing: border-box;
38-
39-
vertical-align: middle;
4024
}
4125

4226
// Outline Chip
@@ -45,13 +29,6 @@
4529
:host(.chip-outline) {
4630
border-width: globals.$ion-border-size-025;
4731
border-style: globals.$ion-border-style-solid;
48-
border-color: globals.$ion-primitives-neutral-100;
49-
50-
background: transparent;
51-
}
52-
53-
:host(.chip-outline.ion-color) {
54-
border-color: globals.current-color(base, 0.32);
5532
}
5633

5734
// Chip: Focus
@@ -66,12 +43,20 @@
6643
// ---------------------------------------------
6744

6845
@media (any-hover: hover) {
69-
:host(:hover) {
46+
:host(.chip-subtle:hover) {
7047
--background: #{globals.$ion-primitives-neutral-200};
7148
}
7249

73-
:host(.ion-color:hover) {
74-
background: globals.current-color(base, 0.12);
50+
:host(.chip-bold:hover) {
51+
--background: #{globals.$ion-primitives-neutral-1100};
52+
}
53+
54+
:host(.chip-subtle.ion-color:hover) {
55+
background: globals.current-color(tint, $subtle: true);
56+
}
57+
58+
:host(.chip-bold.ion-color:hover) {
59+
background: globals.current-color(shade);
7560
}
7661
}
7762

@@ -80,7 +65,6 @@
8065

8166
:host(.chip-disabled) {
8267
opacity: 0.6;
83-
pointer-events: none;
8468
}
8569

8670
// Chip Shapes
@@ -110,7 +94,7 @@
11094
:host(.chip-small) {
11195
min-height: globals.$ion-scale-600;
11296

113-
font-size: #{globals.$ion-font-size-300};
97+
font-size: globals.$ion-font-size-300;
11498
}
11599

116100
:host(.chip-large) {
@@ -119,18 +103,51 @@
119103
font-size: globals.$ion-font-size-350;
120104
}
121105

106+
// Subtle Chip
107+
// ---------------------------------------------
108+
109+
:host(.chip-subtle) {
110+
--background: #{globals.$ion-primitives-neutral-100};
111+
--color: #{globals.$ion-primitives-neutral-800};
112+
}
113+
114+
:host(.chip-outline.chip-subtle) {
115+
border-color: globals.$ion-primitives-neutral-300;
116+
}
117+
118+
// Bold Chip
119+
// ---------------------------------------------
120+
121+
:host(.chip-bold) {
122+
--background: #{globals.$ion-bg-neutral-bold-default};
123+
--color: #{globals.$ion-primitives-base-white};
124+
}
125+
126+
:host(.chip-outline.chip-bold) {
127+
// TODO(FW-6450): this is a made up design choice based on a
128+
// darker shade of the background color
129+
border-color: globals.$ion-primitives-neutral-1200;
130+
}
131+
122132
// Chip Colors
123133
// ---------------------------------------------
124134

125-
:host(.ion-color) {
126-
background: globals.current-color(base, 0.08);
127-
color: globals.current-color(shade);
135+
// Subtle
136+
:host(.chip-subtle.ion-color) {
137+
background: globals.current-color(base, $subtle: true);
138+
color: globals.current-color(contrast, $subtle: true);
139+
}
140+
141+
:host(.chip-subtle.chip-outline.ion-color) {
142+
border-color: globals.current-color(shade, $subtle: true);
128143
}
129144

130-
:host(.ion-color:focus) {
131-
background: globals.current-color(base, 0.12);
145+
// Bold
146+
:host(.chip-bold.ion-color) {
147+
background: globals.current-color(base);
148+
color: globals.current-color(contrast);
132149
}
133150

134-
:host(.ion-color.ion-activated) {
135-
background: globals.current-color(base, 0.16);
151+
:host(.chip-bold.chip-outline.ion-color) {
152+
border-color: globals.current-color(shade);
136153
}

core/src/components/chip/chip.ios.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "./chip";
1+
@import "./chip.native";
22
@import "./chip.vars";
33

44
:host {

core/src/components/chip/chip.md.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "./chip";
1+
@import "./chip.native";
22
@import "./chip.vars";
33

44
:host {

core/src/components/chip/chip.scss core/src/components/chip/chip.native.scss

+10-24
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,22 @@
11
@import "../../themes/native/native.globals";
22
@import "./chip.vars";
3+
@import "./chip.common";
34

45
:host {
5-
/**
6-
* @prop --background: Background of the chip
7-
* @prop --color: Color of the chip
8-
* @prop --border-radius: Border radius of the chip
9-
*/
106
--background: #{rgba($text-color-rgb, 0.12)};
117
--color: #{rgba($text-color-rgb, 0.87)};
128

139
@include border-radius(var(--border-radius));
14-
@include font-smoothing();
1510
@include margin(4px);
1611
@include padding(6px, 12px);
1712

18-
display: inline-flex;
19-
20-
position: relative;
21-
22-
align-items: center;
23-
2413
min-height: 32px;
2514

26-
background: var(--background);
27-
color: var(--color);
28-
2915
font-family: $font-family-base;
30-
31-
cursor: pointer;
32-
33-
overflow: hidden;
34-
35-
vertical-align: middle;
36-
box-sizing: border-box;
3716
}
3817

3918
:host(.chip-disabled) {
40-
cursor: default;
4119
opacity: 0.4;
42-
pointer-events: none;
4320
}
4421

4522
// Chip Colors
@@ -58,6 +35,15 @@
5835
background: current-color(base, 0.16);
5936
}
6037

38+
// Chip: Hover
39+
// ---------------------------------------------
40+
41+
@media (any-hover: hover) {
42+
:host(.ion-color:hover) {
43+
background: current-color(base, 0.12);
44+
}
45+
}
46+
6147
// Outline Chip
6248
// ---------------------------------------------
6349

core/src/components/chip/chip.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ export class Chip implements ComponentInterface {
3737
*/
3838
@Prop() disabled = false;
3939

40+
/**
41+
* Set to `"bold"` for a chip with vibrant, bold colors or to `"subtle"` for
42+
* a chip with muted, subtle colors.
43+
*
44+
* Only applies to the `ionic` theme.
45+
*/
46+
@Prop() hue?: 'bold' | 'subtle' = 'subtle';
47+
4048
/**
4149
* Set to `"soft"` for a chip with slightly rounded corners, `"round"` for a chip with fully
4250
* rounded corners, or `"rectangular"` for a chip without rounded corners.
@@ -81,9 +89,9 @@ export class Chip implements ComponentInterface {
8189
}
8290

8391
render() {
92+
const { hue } = this;
8493
const theme = getIonTheme(this);
8594
const size = this.getSize();
86-
8795
const shape = this.getShape();
8896

8997
return (
@@ -97,6 +105,7 @@ export class Chip implements ComponentInterface {
97105
'ion-activatable': true,
98106
'ion-focusable': !this.disabled,
99107
[`chip-${size}`]: size !== undefined,
108+
[`chip-${hue}`]: hue !== undefined,
100109
})}
101110
>
102111
<slot></slot>

0 commit comments

Comments
 (0)