Skip to content

Commit 5e5c33a

Browse files
brandyscarneyadamdbradley
authored andcommitted
fix(item): fix color input for item divider and list header
* fix(item): fix color input for item divider and list header - adds ItemDivider class to add color and mode css classes to item divider - adds e2e test for item divider colors - adds sass variables to improve control over list headers and item divider styles - fixes style for item divider so it will be styled regardless of being inside a list for md and wp modes references #8376 * refactor(popover): remove the background color styling from ion-content and item - change the default text color and background color to match the theme variables. This makes popover look better on dark theme and removes the nesting of styles that breaks list headers. fixes #8376
1 parent d3b0140 commit 5e5c33a

File tree

17 files changed

+219
-93
lines changed

17 files changed

+219
-93
lines changed

src/components/item/item.ios.scss

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ ion-item-group .item-wrapper:last-child .item-ios .item-inner {
215215
// iOS Item Divider
216216
// --------------------------------------------------
217217

218-
ion-item-divider.item-ios {
218+
.item-divider-ios {
219219
padding-left: $item-ios-padding-left;
220220

221221
color: $item-ios-divider-color;
222222
background-color: $item-ios-divider-background;
223223
}
224224

225225

226-
// Generate iOS Item Divider Colors
226+
// Generate iOS Item and Item Divider Colors
227227
// --------------------------------------------------
228228

229229
@each $color-name, $color-base, $color-contrast in get-colors($colors-ios) {
@@ -233,7 +233,8 @@ ion-item-divider.item-ios {
233233
color: $color-base;
234234
}
235235

236-
.item-ios-#{$color-name} {
236+
.item-ios-#{$color-name},
237+
.item-divider-ios-#{$color-name} {
237238
color: $color-contrast;
238239
background-color: $color-base;
239240

src/components/item/item.md.scss

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ $item-md-detail-push-color: $list-md-border-color !default;
3333
/// @prop - Icon for the detail arrow
3434
$item-md-detail-push-svg: "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 20'><path d='M2,20l-2-2l8-8L0,2l2-2l10,10L2,20z' fill='#{$item-md-detail-push-color}'/></svg>" !default;
3535

36+
/// @prop - Color for the divider
37+
$item-md-divider-color: #858585 !default;
38+
3639
/// @prop - Background for the divider
3740
$item-md-divider-background: #fff !default;
3841

39-
/// @prop - Color for the divider
40-
$item-md-divider-color: #222 !default;
42+
/// @prop - Font size for the divider
43+
$item-md-divider-font-size: $item-md-body-text-font-size !default;
44+
45+
/// @prop - Border bottom for the divider
46+
$item-md-divider-border-bottom: 1px solid $list-md-border-color !default;
4147

4248
/// @prop - Padding for the divider
4349
$item-md-divider-padding: 5px 15px !default;
@@ -218,15 +224,18 @@ ion-item-group .item-md .item-wrapper:last-child .item-inner {
218224
// Material Design Item Divider
219225
// --------------------------------------------------
220226

221-
ion-item-divider.item-md {
227+
.item-divider-md {
222228
padding-left: $item-md-padding-left;
223229

224230
color: $item-md-divider-color;
225231
background-color: $item-md-divider-background;
232+
233+
border-bottom: $item-md-divider-border-bottom;
234+
font-size: $item-md-divider-font-size;
226235
}
227236

228237

229-
// Generate Material Design Item Divider Colors
238+
// Generate Material Design Item and Item Divider Colors
230239
// --------------------------------------------------
231240

232241
@each $color-name, $color-base, $color-contrast in get-colors($colors-md) {
@@ -236,7 +245,8 @@ ion-item-divider.item-md {
236245
color: $color-base;
237246
}
238247

239-
.item-md-#{$color-name} {
248+
.item-md-#{$color-name},
249+
.item-divider-md-#{$color-name} {
240250
color: $color-contrast;
241251
background-color: $color-base;
242252

src/components/item/item.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export class Item extends Ion {
298298
_inputs: Array<string> = [];
299299
_label: Label;
300300
_viewLabel: boolean = true;
301+
_name: string = 'item';
301302
_shouldHaveReorder: boolean = false;
302303

303304
/**
@@ -315,7 +316,7 @@ export class Item extends Ion {
315316
*/
316317
@Input()
317318
set color(val: string) {
318-
this._updateColor(val);
319+
this._updateColor(val, this._name);
319320
}
320321

321322
/**
@@ -334,6 +335,8 @@ export class Item extends Ion {
334335
@Optional() reorder: ItemReorder
335336
) {
336337
super(config, elementRef, renderer);
338+
339+
this._setName(elementRef);
337340
this._shouldHaveReorder = !!reorder;
338341
this.mode = config.get('mode');
339342
this.id = form.nextId().toString();
@@ -361,11 +364,25 @@ export class Item extends Ion {
361364
}
362365
}
363366

367+
/**
368+
* @private
369+
*/
364370
_updateColor(newColor: string, colorClass?: string) {
365371
colorClass = colorClass || 'item'; // item-radio
366372
this._setColor(colorClass, newColor);
367373
}
368374

375+
/**
376+
* @private
377+
*/
378+
_setName(elementRef: ElementRef) {
379+
let nodeName = elementRef.nativeElement.nodeName.replace('ION-', '');
380+
381+
if (nodeName === 'LIST-HEADER' || nodeName === 'ITEM-DIVIDER') {
382+
this._name = nodeName;
383+
}
384+
}
385+
369386
/**
370387
* @private
371388
*/
@@ -419,6 +436,40 @@ export class Item extends Ion {
419436
icon.setElementClass('item-icon', true);
420437
});
421438
}
439+
}
440+
441+
/**
442+
* @private
443+
*/
444+
@Directive({
445+
selector: 'ion-item-divider',
446+
host: {
447+
'class': 'item-divider'
448+
}
449+
})
450+
export class ItemDivider extends Ion {
451+
452+
/**
453+
* @input {string} The predefined color to use. For example: `"primary"`, `"secondary"`, `"danger"`.
454+
*/
455+
@Input()
456+
set color(val: string) {
457+
this._setColor('item-divider', val);
458+
}
459+
460+
/**
461+
* @input {string} The mode to apply to this component.
462+
*/
463+
@Input()
464+
set mode(val: string) {
465+
this._setMode('item-divider', val);
466+
}
467+
468+
constructor(form: Form, config: Config, elementRef: ElementRef, renderer: Renderer) {
469+
super(config, elementRef, renderer);
470+
471+
this.mode = config.get('mode');
472+
}
422473

423474
}
424475

src/components/item/item.wp.scss

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@ $item-wp-detail-push-color: $input-wp-border-color !default;
3939
/// @prop - Icon for the detail arrow
4040
$item-wp-detail-push-svg: "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 20'><path d='M2,20l-2-2l8-8L0,2l2-2l10,10L2,20z' fill='#{$item-wp-detail-push-color}'/></svg>" !default;
4141

42+
/// @prop - Color for the divider
43+
$item-wp-divider-color: $list-wp-text-color !default;
44+
4245
/// @prop - Background for the divider
4346
$item-wp-divider-background: #fff !default;
4447

45-
/// @prop - Color for the divider
46-
$item-wp-divider-color: #222 !default;
48+
/// @prop - Bodrer bottom for the divider
49+
$item-wp-divider-border-bottom: 1px solid $list-wp-border-color !default;
50+
51+
/// @prop - Font size for the divider
52+
$item-wp-divider-font-size: 2rem !default;
4753

4854
/// @prop - Padding for the divider
4955
$item-wp-divider-padding: 5px 15px !default;
@@ -215,15 +221,18 @@ $item-wp-sliding-content-background: $list-wp-background-color !default;
215221
// Windows Item Divider
216222
// --------------------------------------------------
217223

218-
ion-item-divider.item-wp {
224+
.item-divider-wp {
219225
padding-left: $item-wp-padding-left;
220226

227+
border-bottom: $item-wp-divider-border-bottom;
228+
font-size: $item-wp-divider-font-size;
229+
221230
color: $item-wp-divider-color;
222231
background-color: $item-wp-divider-background;
223232
}
224233

225234

226-
// Generate Windows Item Divider Colors
235+
// Generate Windows Item and Item Divider Colors
227236
// --------------------------------------------------
228237

229238
@each $color-name, $color-base, $color-contrast in get-colors($colors-wp) {
@@ -233,7 +242,8 @@ ion-item-divider.item-wp {
233242
color: $color-base;
234243
}
235244

236-
.item-wp-#{$color-name} {
245+
.item-wp-#{$color-name},
246+
.item-divider-wp-#{$color-name} {
237247
color: $color-contrast;
238248
background-color: $color-base;
239249

src/components/item/test/dividers/e2e.ts

Whitespace-only changes.

src/components/item/test/dividers/main.html

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,42 @@
88

99

1010
<ion-content class="outer-content">
11+
<ion-item-divider>
12+
Divider by itself
13+
</ion-item-divider>
14+
15+
<ion-list>
16+
<ion-item-divider>
17+
Divider in List
18+
</ion-item-divider>
19+
<ion-item-divider color="danger">
20+
Danger Divider in List
21+
</ion-item-divider>
22+
</ion-list>
23+
24+
<ion-item-group>
25+
<ion-item-divider>
26+
Divider in Item Group
27+
</ion-item-divider>
28+
<ion-item-divider color="secondary">
29+
Secondary Divider in Item Group
30+
</ion-item-divider>
31+
</ion-item-group>
1132

1233
<ion-item-group>
1334
<ion-item>
35+
<h3 color="secondary">Secondary header</h3>
1436
Plain Ol' div with some text
1537
</ion-item>
1638
</ion-item-group>
1739

1840
<ion-item-group>
1941
<ion-item-divider>
20-
Item Divider
42+
Item Divider <span color="danger">Danger Span</span>
2143
<button ion-button item-right>button</button>
2244
</ion-item-divider>
2345

24-
<ion-item text-wrap>
46+
<ion-item text-wrap class="custom-item">
2547
Multiline text that should wrap when it is too long
2648
to fit on one line in the item. Attribute on .item
2749
</ion-item>
@@ -35,16 +57,12 @@
3557
<button ion-button item-left clear color="light">
3658
<ion-icon name="rainy"></ion-icon>
3759
</button>
38-
Dark
60+
Dark <h5 color="primary">Primary h5</h5>
3961
</ion-item-divider>
4062

4163
<ion-item text-wrap>
4264
<h1>H1 Title Text</h1>
4365
</ion-item>
44-
45-
<ion-item text-wrap>
46-
<h2>H2 Title Text</h2>
47-
</ion-item>
4866
</ion-item-group>
4967

5068
<ion-item-group>
@@ -58,22 +76,12 @@ <h2>H2 Title Text</h2>
5876
</button>
5977
</ion-item-divider>
6078

61-
<ion-item text-wrap>
62-
<h3>H3 Title Text</h3>
63-
</ion-item>
64-
</ion-item-group>
65-
66-
<ion-item-group>
6779
<ion-item-divider color="primary">
6880
Primary
6981
<ion-thumbnail item-right>
7082
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==">
7183
</ion-thumbnail>
7284
</ion-item-divider>
73-
74-
<ion-item text-wrap>
75-
<h4>H4 Title Text</h4>
76-
</ion-item>
7785
</ion-item-group>
7886

7987
<ion-item-group>

src/components/item/test/text/main.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99

1010
<ion-content class="outer-content">
1111

12+
<ion-list>
13+
<ion-list-header>
14+
List Header
15+
</ion-list-header>
16+
<ion-item>
17+
Item
18+
</ion-item>
19+
<ion-item-divider>
20+
Item Divider
21+
</ion-item-divider>
22+
<ion-item>
23+
Item
24+
</ion-item>
25+
</ion-list>
26+
1227
<ion-item>
1328
Plain Ol' div with some text
1429
</ion-item>
@@ -26,7 +41,7 @@
2641
to fit on one line in the item. Attribute on .item
2742
</ion-item>
2843

29-
<ion-item text-wrap>
44+
<ion-item text-wrap color="secondary">
3045
<h1>H1 Title Text</h1>
3146
<p>Paragraph line 1</p>
3247
</ion-item>

src/components/list/list-header.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Attribute, Directive, ElementRef, Renderer } from '@angular/core';
1+
import { Attribute, Directive, ElementRef, Input, Renderer } from '@angular/core';
22

33
import { Config } from '../../config/config';
44
import { Ion } from '../ion';
@@ -10,9 +10,27 @@ import { Ion } from '../ion';
1010
selector: 'ion-list-header'
1111
})
1212
export class ListHeader extends Ion {
13+
14+
/**
15+
* @input {string} The predefined color to use. For example: `"primary"`, `"secondary"`, `"danger"`.
16+
*/
17+
@Input()
18+
set color(val: string) {
19+
this._setColor('list-header', val);
20+
}
21+
22+
/**
23+
* @input {string} The mode to apply to this component.
24+
*/
25+
@Input()
26+
set mode(val: string) {
27+
this._setMode('list-header', val);
28+
}
29+
1330
constructor(config: Config, renderer: Renderer, elementRef: ElementRef, @Attribute('id') private _id: string) {
1431
super(config, elementRef, renderer);
15-
this._setMode('list-header', config.get('mode'));
32+
33+
this.mode = config.get('mode');
1634
}
1735

1836
get id(): string {

0 commit comments

Comments
 (0)