Skip to content

Commit 61876a5

Browse files
feat(segment): add default styles for ionic theme (#29897)
Issue number: internal --------- ## What is the current behavior? The segment component does not have styles for the `"ionic"` theme and uses `"md"` styles. ## What is the new behavior? - Adds styles for both `<ion-segment>` and `<ion-segment-button>` styles for the `"ionic"` theme - Adds screenshot tests for the different icon layouts ## Does this introduce a breaking change? - [ ] Yes - [x] No
1 parent 9fc0d62 commit 61876a5

File tree

69 files changed

+437
-95
lines changed

Some content is hidden

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

69 files changed

+437
-95
lines changed

core/api.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,16 +1958,12 @@ ion-segment-button,css-prop,--background,md
19581958
ion-segment-button,css-prop,--background-checked,ionic
19591959
ion-segment-button,css-prop,--background-checked,ios
19601960
ion-segment-button,css-prop,--background-checked,md
1961-
ion-segment-button,css-prop,--background-focused,ionic
19621961
ion-segment-button,css-prop,--background-focused,ios
19631962
ion-segment-button,css-prop,--background-focused,md
1964-
ion-segment-button,css-prop,--background-focused-opacity,ionic
19651963
ion-segment-button,css-prop,--background-focused-opacity,ios
19661964
ion-segment-button,css-prop,--background-focused-opacity,md
1967-
ion-segment-button,css-prop,--background-hover,ionic
19681965
ion-segment-button,css-prop,--background-hover,ios
19691966
ion-segment-button,css-prop,--background-hover,md
1970-
ion-segment-button,css-prop,--background-hover-opacity,ionic
19711967
ion-segment-button,css-prop,--background-hover-opacity,ios
19721968
ion-segment-button,css-prop,--background-hover-opacity,md
19731969
ion-segment-button,css-prop,--border-color,ionic
@@ -1988,10 +1984,9 @@ ion-segment-button,css-prop,--color,md
19881984
ion-segment-button,css-prop,--color-checked,ionic
19891985
ion-segment-button,css-prop,--color-checked,ios
19901986
ion-segment-button,css-prop,--color-checked,md
1991-
ion-segment-button,css-prop,--color-focused,ionic
1987+
ion-segment-button,css-prop,--color-disabled,ionic
19921988
ion-segment-button,css-prop,--color-focused,ios
19931989
ion-segment-button,css-prop,--color-focused,md
1994-
ion-segment-button,css-prop,--color-hover,ionic
19951990
ion-segment-button,css-prop,--color-hover,ios
19961991
ion-segment-button,css-prop,--color-hover,md
19971992
ion-segment-button,css-prop,--indicator-box-shadow,ionic

core/src/components/segment-button/segment-button.scss renamed to core/src/components/segment-button/segment-button.common.scss

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
@import "../../themes/native/native.globals";
1+
@import "../../themes/functions.string";
2+
@import "../../themes/mixins";
23

3-
// Segment Button
4+
// Segment Button: Common
45
// --------------------------------------------------
56

67
:host {
78
/**
89
* @prop --background: Background of the segment button
910
* @prop --background-checked: Background of the checked segment button
1011
*
11-
* @prop --background-hover: Background of the segment button on hover
12-
* @prop --background-focused: Background of the segment button when focused with the tab key
13-
*
14-
* @prop --background-hover-opacity: Opacity of the segment button background on hover
15-
* @prop --background-focused-opacity: Opacity of the segment button background when focused with the tab key
16-
*
1712
* @prop --color: Color of the segment button
1813
* @prop --color-checked: Color of the checked segment button
19-
* @prop --color-hover: Color of the segment button on hover
20-
* @prop --color-focused: Color of the segment button when focused with the tab key
2114
*
2215
* @prop --border-radius: Radius of the segment button border
2316
* @prop --border-color: Color of the segment button border
@@ -42,14 +35,6 @@
4235
* @prop --indicator-transition: Transition of the indicator for the checked segment button
4336
* @prop --indicator-transform: Transform of the indicator for the checked segment button
4437
*/
45-
--color: initial;
46-
--color-hover: var(--color);
47-
--color-checked: var(--color);
48-
--color-disabled: var(--color);
49-
--padding-start: 0;
50-
--padding-end: 0;
51-
--padding-top: 0;
52-
--padding-bottom: 0;
5338

5439
@include border-radius(var(--border-radius));
5540

@@ -79,7 +64,6 @@
7964

8065
.button-native {
8166
@include border-radius(0);
82-
@include text-inherit();
8367
@include margin(var(--margin-top), var(--margin-end), var(--margin-bottom), var(--margin-start));
8468
@include padding(var(--padding-top), var(--padding-end), var(--padding-bottom), var(--padding-start));
8569
@include transform(translate3d(0, 0, 0));
@@ -117,10 +101,6 @@
117101
z-index: 2;
118102
}
119103

120-
.button-native::after {
121-
@include button-state();
122-
}
123-
124104
.button-inner {
125105
display: flex;
126106
position: relative;
@@ -151,42 +131,6 @@
151131
pointer-events: none;
152132
}
153133

154-
// Segment Button: Focused
155-
// --------------------------------------------------
156-
157-
:host(.ion-focused) .button-native {
158-
color: var(--color-focused);
159-
160-
&::after {
161-
background: var(--background-focused);
162-
163-
opacity: var(--background-focused-opacity);
164-
}
165-
}
166-
167-
:host(:focus) {
168-
outline: none;
169-
}
170-
171-
// Segment Button: Hover
172-
// --------------------------------------------------
173-
174-
@media (any-hover: hover) {
175-
:host(:hover) .button-native {
176-
color: var(--color-hover);
177-
178-
&::after {
179-
background: var(--background-hover);
180-
181-
opacity: var(--background-hover-opacity);
182-
}
183-
}
184-
185-
:host(.segment-button-checked:hover) .button-native {
186-
color: var(--color-checked);
187-
}
188-
}
189-
190134
// Segment Button Icon
191135
// --------------------------------------------------
192136

@@ -208,8 +152,6 @@
208152

209153
max-width: 100%;
210154

211-
line-height: 22px;
212-
213155
text-overflow: ellipsis;
214156

215157
white-space: nowrap;
@@ -254,13 +196,6 @@
254196
display: none;
255197
}
256198

257-
// Segment Button Ripple
258-
// --------------------------------------------------
259-
260-
ion-ripple-effect {
261-
color: var(--ripple-color, var(--color-checked));
262-
}
263-
264199
// Segment Button: Indicator
265200
// --------------------------------------------------
266201

@@ -284,6 +219,8 @@ ion-ripple-effect {
284219

285220
transform: var(--indicator-transform);
286221

222+
background: var(--indicator-color);
223+
287224
box-shadow: var(--indicator-box-shadow);
288225

289226
pointer-events: none;
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
@use "../../themes/ionic/ionic.globals.scss" as globals;
2+
@use "./segment-button.common";
3+
4+
// Ionic Segment Button
5+
// --------------------------------------------------
6+
7+
:host {
8+
/**
9+
* @prop --color-disabled: Color of the disabled segment button
10+
*/
11+
--background: none;
12+
--background-checked: var(--background);
13+
--color: #{globals.$ionic-color-neutral-1000};
14+
--color-checked: #{globals.$ionic-color-primary-base};
15+
--color-disabled: #{globals.$ionic-color-neutral-500};
16+
--border-width: #{globals.$ionic-border-size-025};
17+
--border-color: #{globals.$ionic-color-neutral-300};
18+
--border-style: #{globals.$ionic-border-style-solid};
19+
--indicator-box-shadow: none;
20+
--indicator-color: var(--color-checked);
21+
--indicator-height: #{globals.$ionic-border-size-025};
22+
--indicator-transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
23+
--indicator-transform: none;
24+
--padding-top: #{globals.$ionic-space-200};
25+
--padding-end: #{globals.$ionic-space-200};
26+
--padding-bottom: #{globals.$ionic-space-200};
27+
--padding-start: #{globals.$ionic-space-200};
28+
--transition: color 0.15s linear 0s, opacity 0.15s linear 0s;
29+
30+
min-width: globals.$ionic-scale-1200;
31+
min-height: globals.$ionic-scale-1200;
32+
}
33+
34+
.button-native {
35+
border-bottom: var(--border-width) var(--border-style) var(--border-color);
36+
37+
// Ensures the indicator moves correctly between segment buttons
38+
z-index: 1;
39+
}
40+
41+
.button-inner {
42+
@include globals.padding(globals.$ionic-space-100, null, globals.$ionic-space-100, null);
43+
44+
gap: globals.$ionic-space-100;
45+
}
46+
47+
// Segment Button Label
48+
// --------------------------------------------------
49+
50+
::slotted(ion-label) {
51+
@include globals.typography(globals.$ionic-action-md);
52+
53+
color: var(--color);
54+
}
55+
56+
// Segment Button Icon
57+
// --------------------------------------------------
58+
59+
::slotted(ion-icon) {
60+
width: globals.$ionic-scale-600;
61+
height: globals.$ionic-scale-600;
62+
63+
color: var(--color);
64+
}
65+
66+
// Segment Button: Checked
67+
// --------------------------------------------------
68+
69+
:host(.segment-button-checked) ::slotted(ion-label),
70+
:host(.segment-button-checked) ::slotted(ion-icon) {
71+
color: var(--color-checked);
72+
}
73+
74+
// Segment Button: Disabled
75+
// --------------------------------------------------
76+
77+
:host(.segment-button-disabled) ::slotted(ion-label),
78+
:host(.segment-button-disabled) ::slotted(ion-icon) {
79+
color: var(--color-disabled);
80+
}
81+
82+
// Segment Button: Indicator
83+
// --------------------------------------------------
84+
85+
.segment-button-indicator {
86+
@include globals.position(null, 0, 0, 0);
87+
88+
// Ensures the indicator displays correctly above the border
89+
z-index: 2;
90+
}
91+
92+
// Segment Button Layout
93+
// --------------------------------------------------
94+
95+
// Segments with icons above or below the label
96+
// should have a fixed height of 72px
97+
:host(.segment-button-layout-icon-top),
98+
:host(.segment-button-layout-icon-bottom) {
99+
height: globals.$ionic-scale-1800;
100+
}
101+
102+
// Segments with icons at the start or end, or with only
103+
// icons or labels, should have a fixed height of 48px
104+
:host(.segment-button-has-label-only),
105+
:host(.segment-button-has-icon-only),
106+
:host(.segment-button-layout-icon-start),
107+
:host(.segment-button-layout-icon-end) {
108+
height: globals.$ionic-scale-1200;
109+
}
110+
111+
:host(.segment-button-layout-icon-start) .button-inner,
112+
:host(.segment-button-layout-icon-end) .button-inner {
113+
gap: globals.$ionic-space-200;
114+
}

core/src/components/segment-button/segment-button.ios.scss

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "./segment-button";
1+
@import "./segment-button.native";
22
@import "./segment-button.ios.vars";
33

44
// iOS Segment Button
@@ -95,7 +95,7 @@
9595
@include margin-horizontal(0, 2px);
9696
}
9797

98-
// Segment Button: Checked Indicator
98+
// Segment Button: Indicator
9999
// --------------------------------------------------
100100

101101
.segment-button-indicator {
@@ -106,10 +106,6 @@
106106
.segment-button-indicator-background {
107107
@include border-radius(var(--border-radius));
108108

109-
background: var(--indicator-color);
110-
}
111-
112-
.segment-button-indicator-background {
113109
transition: var(--indicator-transition);
114110
}
115111

core/src/components/segment-button/segment-button.md.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "./segment-button";
1+
@import "./segment-button.native";
22
@import "./segment-button.md.vars";
33

44
// Material Design Segment Button
@@ -181,10 +181,6 @@
181181
@include position(null, 0, 0, 0);
182182
}
183183

184-
.segment-button-indicator-background {
185-
background: var(--indicator-color);
186-
}
187-
188184
// Segment button indicator color should use the background checked variable with
189185
// a fallback to the default value of --indicator-color
190186
:host(.in-toolbar:not(.in-segment-color)) .segment-button-indicator-background {

0 commit comments

Comments
 (0)