Skip to content

Commit 917ce22

Browse files
committed
feat(divider): move divider out of mat-list
- Creates an independent mat-divider component - Adds inset capability with special accomodations for mat-list-item - Adds vertical option - Removed mat-divider from MatListModule with temporary import to prevent breaking changes - Added styling for dividers in cards
1 parent 291a87c commit 917ce22

19 files changed

+398
-38
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@
2727
</mat-card-footer>
2828
</mat-card>
2929

30+
<mat-card>
31+
<mat-card-subtitle>Subtitle</mat-card-subtitle>
32+
<mat-card-title>Card with title, footer, and inset-divider</mat-card-title>
33+
<mat-card-content>
34+
<p>This is supporting text.</p>
35+
<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>
36+
</mat-card-content>
37+
<mat-divider [inset]="true"></mat-divider>
38+
<mat-card-actions>
39+
<button md-button>LIKE</button>
40+
<button md-button>SHARE</button>
41+
</mat-card-actions>
42+
<mat-card-footer>
43+
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
44+
</mat-card-footer>
45+
</mat-card>
46+
3047
<mat-card>
3148
<img mat-card-image src="https://material.angularjs.org/latest/img/washedout.png">
3249
<mat-card-title>Content Title</mat-card-title>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ <h4 mat-line>{{message.from}}</h4>
3131
<span>{{message.subject}} -- </span>
3232
<span class="demo-secondary-text">{{message.message}}</span>
3333
</p>
34+
<mat-divider [inset]="true" *ngIf="!last"></mat-divider>
3435
</mat-list-item>
3536
<mat-divider></mat-divider>
3637
<mat-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';
@@ -43,6 +44,7 @@
4344
@include mat-table-theme($theme);
4445
@include mat-datepicker-theme($theme);
4546
@include mat-dialog-theme($theme);
47+
@include mat-divider-theme($theme);
4648
@include mat-expansion-panel-theme($theme);
4749
@include mat-form-field-theme($theme);
4850
@include mat-grid-list-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-module.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC 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 {MatCommonModule} from '../core';
11+
import {
12+
MatDivider,
13+
MatDividerCssMatStyler,
14+
} from './divider';
15+
16+
17+
@NgModule({
18+
imports: [MatCommonModule],
19+
exports: [
20+
MatDivider,
21+
MatCommonModule,
22+
MatDividerCssMatStyler,
23+
],
24+
declarations: [
25+
MatDivider,
26+
MatDividerCssMatStyler,
27+
],
28+
})
29+
export class MatDividerModule {}

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 {MatDividerModule} from './divider-module';
5+
6+
7+
describe('MdDivider', () => {
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
imports: [MatDividerModule],
12+
declarations: [
13+
MatDividerBase,
14+
MatDividerVertical,
15+
MatDividerInset,
16+
MatDividerVerticalInset,
17+
MatDividerWithCssClass,
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(MatDividerBase);
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(MatDividerVertical);
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(MatDividerInset);
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(MatDividerVerticalInset);
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(MatDividerWithCssClass);
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(MatDividerBase);
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 MatDividerBase { }
80+
81+
@Component({
82+
template: `<md-divider [vertical]="true"></md-divider>`
83+
})
84+
class MatDividerVertical { }
85+
86+
@Component({
87+
template: `<md-divider [inset]="true"></md-divider>`
88+
})
89+
class MatDividerInset { }
90+
91+
@Component({
92+
template: `<md-divider [vertical]="true" [inset]="true"></md-divider>`
93+
})
94+
class MatDividerVerticalInset { }
95+
96+
@Component({
97+
template: `<md-divider class="test-class"></md-divider>`
98+
})
99+
class MatDividerWithCssClass { }

src/lib/divider/divider.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC 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 '@angular/cdk/coercion';
15+
16+
@Component({
17+
moduleId: module.id,
18+
selector: '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+
preserveWhitespaces: false,
30+
})
31+
export class MatDivider {
32+
/** Whether the divider is vertically aligned. */
33+
@Input() get vertical(): boolean { return this._vertical; }
34+
set vertical(value: boolean) {
35+
this._vertical = coerceBooleanProperty(value);
36+
}
37+
protected _vertical: boolean = false;
38+
39+
/** Whether the divider is an inset divider. */
40+
@Input() get inset(): boolean { return this._inset; }
41+
set inset(value: boolean) {
42+
this._inset = coerceBooleanProperty(value);
43+
}
44+
protected _inset: boolean = false;
45+
}
46+
47+
/**
48+
* Directive whose purpose is to add the mat- CSS styling to this selector.
49+
* @docs-private
50+
*/
51+
@Directive({
52+
selector: 'mat-divider',
53+
host: {'class': '"mat-divider"'}
54+
})
55+
export class MatDividerCssMatStyler {}

src/lib/divider/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC 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+
export * from './public-api';

0 commit comments

Comments
 (0)