Skip to content

Commit 7c93bf2

Browse files
committed
feat(divider): move divider out of md-list
- Creates an independent md-divider component - Adds inset capability with special accomodations for md-list-item - Adds vertical option - Removed md-divider from MdListModule with temporary import to prevent breaking changes - Added styling for dividers in cards
1 parent 03c0087 commit 7c93bf2

File tree

14 files changed

+354
-38
lines changed

14 files changed

+354
-38
lines changed

src/demo-app/card/card-demo.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,26 @@
1313

1414
<md-card>
1515
<md-card-subtitle>Subtitle</md-card-subtitle>
16-
<md-card-title>Card with title and footer</md-card-title>
16+
<md-card-title>Card with title and full-bleed divider</md-card-title>
1717
<md-card-content>
1818
<p>This is supporting text.</p>
1919
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
2020
</md-card-content>
21+
<md-divider></md-divider>
22+
<md-card-actions>
23+
<button md-button>LIKE</button>
24+
<button md-button>SHARE</button>
25+
</md-card-actions>
26+
</md-card>
27+
28+
<md-card>
29+
<md-card-subtitle>Subtitle</md-card-subtitle>
30+
<md-card-title>Card with title, footer, and inset-divider</md-card-title>
31+
<md-card-content>
32+
<p>This is supporting text.</p>
33+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
34+
</md-card-content>
35+
<md-divider [inset]="true"></md-divider>
2136
<md-card-actions>
2237
<button md-button>LIKE</button>
2338
<button md-button>SHARE</button>

src/demo-app/list/list-demo.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ <h3 md-line>{{contact.name}}</h3>
2424

2525
<md-list>
2626
<h3 md-subheader>Today</h3>
27-
<md-list-item *ngFor="let message of messages">
27+
<md-list-item *ngFor="let message of messages; last as last">
2828
<img md-list-avatar [src]="message.image" alt="Image of {{message.from}}">
2929
<h4 md-line>{{message.from}}</h4>
3030
<p md-line>
3131
<span>{{message.subject}} -- </span>
3232
<span class="demo-secondary-text">{{message.message}}</span>
3333
</p>
34+
<md-divider [inset]="true" *ngIf="!last"></md-divider>
3435
</md-list-item>
3536
<md-divider></md-divider>
3637
<md-list-item *ngFor="let message of messages">

src/lib/core/theming/_all-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@import '../../table/table-theme';
1010
@import '../../datepicker/datepicker-theme';
1111
@import '../../dialog/dialog-theme';
12+
@import '../../divider/divider-theme';
1213
@import '../../expansion/expansion-theme';
1314
@import '../../grid-list/grid-list-theme';
1415
@import '../../icon/icon-theme';
@@ -41,6 +42,7 @@
4142
@include mat-table-theme($theme);
4243
@include mat-datepicker-theme($theme);
4344
@include mat-dialog-theme($theme);
45+
@include mat-divider-theme($theme);
4446
@include mat-expansion-panel-theme($theme);
4547
@include mat-grid-list-theme($theme);
4648
@include mat-icon-theme($theme);

src/lib/divider/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Please see the official documentation at https://material.angular.io/components/component/divider

src/lib/divider/_divider-theme.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@import '../core/theming/palette';
2+
@import '../core/theming/theming';
3+
4+
5+
@mixin mat-divider-theme($theme) {
6+
$foreground: map-get($theme, foreground);
7+
8+
.mat-divider {
9+
border-top-color: mat-color($foreground, divider);
10+
}
11+
12+
.mat-divider-vertical {
13+
border-right-color: mat-color($foreground, divider);
14+
}
15+
}

src/lib/divider/divider.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
`<md-divider>` is a container component that wraps and formats a series of line items. As the base
2+
list component, it provides Material Design styling, but no behavior of its own.
3+
4+
<!-- example(divider-overview) -->
5+
6+
7+
### Simple divider
8+
9+
An `<md-divider>` element can be used on its own to create a vertical line styled with a Material theme
10+
11+
```html
12+
<md-divider></md-divider>
13+
```
14+
15+
Here are the available global options:
16+
17+
| Name | Type | Values | Description |
18+
| --------------- | ------- | ----------- | ----------------------------------------- |
19+
| inset | boolean | true, false | Whether the divider is an inset divider |
20+
| vertical | boolean | true, false | Whether the divider is a vertical divider |
21+
22+
23+
### Inset divider
24+
25+
Add the `inset` attribute in order to set whether or not the divider is an inset divider.
26+
27+
```html
28+
<md-divider [inset]="true"></md-divider>
29+
```
30+
31+
### Vertical divider
32+
33+
Add the `vertical` attribute in order to set whether or not the divider is vertically-oriented.
34+
35+
```html
36+
<md-divider [vertical]="true"></md-divider>
37+
```
38+
39+
40+
### Lists with inset dividers
41+
42+
Dividers can be added to lists as a means of separating content into distinct sections.
43+
Inset dividers can also be added to provide the appearance of distinct elements in a list without cluttering content
44+
like avatar images or icons. If combining both, please make sure to avoid adding an inset divider to the last element
45+
in a list, because it will overlap with the section divider.
46+
47+
```html
48+
<md-list>
49+
<h3 md-subheader>Folders</h3>
50+
<md-list-item *ngFor="let folder of folders; last as last">
51+
<md-icon md-list-icon>folder</md-icon>
52+
<h4 md-line>{{folder.name}}</h4>
53+
<p md-line class="demo-2"> {{folder.updated}} </p>
54+
<md-divider [inset]="true" *ngIf="!last"></md-divider>
55+
</md-list-item>
56+
<md-divider></md-divider>
57+
<h3 md-subheader>Notes</h3>
58+
<md-list-item *ngFor="let note of notes">
59+
<md-icon md-list-icon>note</md-icon>
60+
<h4 md-line>{{note.name}}</h4>
61+
<p md-line class="demo-2"> {{note.updated}} </p>
62+
</md-list-item>
63+
</md-list>
64+
```

src/lib/divider/divider.scss

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
.mat-divider {
2+
display: block;
3+
margin: 0;
4+
border-top-width: 1px;
5+
border-top-style: solid;
6+
7+
&.mat-divider-vertical {
8+
border-top: 0;
9+
border-right-width: 1px;
10+
border-right-style: solid;
11+
position: static !important;
12+
width: auto !important;
13+
}
14+
15+
&.mat-divider-inset {
16+
margin-left: 80px;
17+
[dir='rtl'] & {
18+
margin-left: auto;
19+
margin-right: 80px;
20+
}
21+
}
22+
}
23+
24+
.mat-list-item {
25+
.mat-divider {
26+
position: absolute;
27+
bottom: 0;
28+
29+
left: 0;
30+
[dir='rtl'] & {
31+
left: auto;
32+
right: 0;
33+
}
34+
35+
width: 100%;
36+
&.mat-divider-inset {
37+
left: 72px;
38+
[dir='rtl'] & {
39+
left: auto;
40+
right: 72px;
41+
}
42+
43+
width: calc(100% - 72px);
44+
margin: 0 !important;
45+
}
46+
}
47+
}
48+
49+
.mat-card {
50+
.mat-divider {
51+
position: absolute;
52+
53+
left: 0;
54+
[dir='rtl'] & {
55+
left: auto;
56+
right: 0;
57+
}
58+
59+
width: 100%;
60+
61+
&.mat-divider-inset {
62+
position: static;
63+
margin: 0 !important;
64+
}
65+
}
66+
}

src/lib/divider/divider.spec.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import {async, TestBed} from '@angular/core/testing';
2+
import {Component} from '@angular/core';
3+
import {By} from '@angular/platform-browser';
4+
import {MdDividerModule} from './index';
5+
6+
7+
describe('MdDivider', () => {
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
imports: [MdDividerModule],
12+
declarations: [
13+
MdDividerBase,
14+
MdDividerVertical,
15+
MdDividerInset,
16+
MdDividerVerticalInset,
17+
MdDividerWithCssClass,
18+
],
19+
});
20+
21+
TestBed.compileComponents();
22+
}));
23+
24+
it('should not apply any additional class to a list without lines', () => {
25+
let fixture = TestBed.createComponent(MdDividerBase);
26+
let divider = fixture.debugElement.query(By.css('md-divider'));
27+
fixture.detectChanges();
28+
expect(divider.nativeElement.className).toBe('mat-divider');
29+
});
30+
31+
it('should apply vertical class to vertical divider', () => {
32+
let fixture = TestBed.createComponent(MdDividerVertical);
33+
fixture.detectChanges();
34+
35+
let divider = fixture.debugElement.query(By.css('md-divider'));
36+
expect(divider.nativeElement.className).toContain('mat-divider');
37+
expect(divider.nativeElement.className).toContain('mat-divider-vertical');
38+
});
39+
40+
it('should apply inset class to inset divider', () => {
41+
let fixture = TestBed.createComponent(MdDividerInset);
42+
fixture.detectChanges();
43+
44+
let divider = fixture.debugElement.query(By.css('md-divider'));
45+
expect(divider.nativeElement.className).toContain('mat-divider');
46+
expect(divider.nativeElement.className).toContain('mat-divider-inset');
47+
});
48+
49+
it('should apply inset and vertical classes to vertical inset divider', () => {
50+
let fixture = TestBed.createComponent(MdDividerVerticalInset);
51+
fixture.detectChanges();
52+
53+
let divider = fixture.debugElement.query(By.css('md-divider'));
54+
expect(divider.nativeElement.className).toContain('mat-divider');
55+
expect(divider.nativeElement.className).toContain('mat-divider-inset');
56+
expect(divider.nativeElement.className).toContain('mat-divider-vertical');
57+
});
58+
59+
it('should not clear custom classes provided by user', () => {
60+
let fixture = TestBed.createComponent(MdDividerWithCssClass);
61+
fixture.detectChanges();
62+
63+
let divider = fixture.debugElement.query(By.css('md-divider'));
64+
expect(divider.nativeElement.classList.contains('test-class')).toBe(true);
65+
});
66+
67+
it('should add aria roles properly', () => {
68+
let fixture = TestBed.createComponent(MdDividerBase);
69+
fixture.detectChanges();
70+
71+
let divider = fixture.debugElement.query(By.css('md-divider'));
72+
expect(divider.nativeElement.getAttribute('role')).toBe('separator');
73+
});
74+
});
75+
76+
@Component({
77+
template: `<md-divider></md-divider>`
78+
})
79+
class MdDividerBase { }
80+
81+
@Component({
82+
template: `<md-divider [vertical]="true"></md-divider>`
83+
})
84+
class MdDividerVertical { }
85+
86+
@Component({
87+
template: `<md-divider [inset]="true"></md-divider>`
88+
})
89+
class MdDividerInset { }
90+
91+
@Component({
92+
template: `<md-divider [vertical]="true" [inset]="true"></md-divider>`
93+
})
94+
class MdDividerVerticalInset { }
95+
96+
@Component({
97+
template: `<md-divider class="test-class"></md-divider>`
98+
})
99+
class MdDividerWithCssClass { }

src/lib/divider/divider.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {
10+
ChangeDetectionStrategy, Component,
11+
Directive,
12+
Input, ViewEncapsulation,
13+
} from '@angular/core';
14+
import {coerceBooleanProperty} from '../core';
15+
16+
@Component({
17+
moduleId: module.id,
18+
selector: 'md-divider, mat-divider',
19+
host: {
20+
'role': 'separator',
21+
'[attr.aria-orientation]': 'vertical ? "vertical" : "horizontal"',
22+
'[class.mat-divider-vertical]': 'vertical',
23+
'[class.mat-divider-inset]': 'inset',
24+
},
25+
template: '<ng-content></ng-content>',
26+
styleUrls: ['divider.css'],
27+
encapsulation: ViewEncapsulation.None,
28+
changeDetection: ChangeDetectionStrategy.OnPush,
29+
})
30+
export class MdDivider {
31+
/** Whether the divider is vertically aligned. */
32+
@Input() get vertical(): boolean { return this._vertical; }
33+
set vertical(value: boolean) {
34+
this._vertical = coerceBooleanProperty(value);
35+
}
36+
protected _vertical: boolean = false;
37+
38+
/** Whether the divider is an inset divider. */
39+
@Input() get inset(): boolean { return this._inset; }
40+
set inset(value: boolean) {
41+
this._inset = coerceBooleanProperty(value);
42+
}
43+
protected _inset: boolean = false;
44+
}
45+
46+
/**
47+
* Directive whose purpose is to add the mat- CSS styling to this selector.
48+
* @docs-private
49+
*/
50+
@Directive({
51+
selector: 'md-divider, mat-divider',
52+
host: {'class': 'mat-divider'}
53+
})
54+
export class MdDividerCssMatStyler {}

src/lib/divider/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {NgModule} from '@angular/core';
10+
import {MdCommonModule} from '../core';
11+
import {
12+
MdDivider,
13+
MdDividerCssMatStyler,
14+
} from './divider';
15+
16+
17+
@NgModule({
18+
imports: [MdCommonModule],
19+
exports: [
20+
MdDivider,
21+
MdCommonModule,
22+
MdDividerCssMatStyler,
23+
],
24+
declarations: [
25+
MdDivider,
26+
MdDividerCssMatStyler,
27+
],
28+
})
29+
export class MdDividerModule {}
30+
31+
32+
export * from './divider';

0 commit comments

Comments
 (0)