-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 - Add demos for use in list, card, and menu
- Loading branch information
1 parent
a626c8f
commit f00650c
Showing
32 changed files
with
378 additions
and
41 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Please see the official documentation at https://material.angular.io/components/component/divider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@import '../core/theming/palette'; | ||
@import '../core/theming/theming'; | ||
|
||
|
||
@mixin mat-divider-theme($theme) { | ||
$foreground: map-get($theme, foreground); | ||
|
||
.mat-divider { | ||
border-top-color: mat-color($foreground, divider); | ||
} | ||
|
||
.mat-divider-vertical { | ||
border-right-color: mat-color($foreground, divider); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {NgModule} from '@angular/core'; | ||
import {CommonModule} from '@angular/common'; | ||
import {MatCommonModule} from '@angular/material/core'; | ||
import {MatDivider} from './divider'; | ||
|
||
|
||
@NgModule({ | ||
imports: [MatCommonModule, CommonModule], | ||
exports: [ | ||
MatDivider, | ||
MatCommonModule, | ||
], | ||
declarations: [ | ||
MatDivider, | ||
], | ||
}) | ||
export class MatDividerModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
`<mat-divider>` is a component that allows for Material styling of a line separator with various orientation options. | ||
|
||
<!-- example(divider-overview) --> | ||
|
||
|
||
### Simple divider | ||
|
||
A `<mat-divider>` element can be used on its own to create a horizontal or vertical line styled with a Material theme | ||
|
||
```html | ||
<mat-divider></mat-divider> | ||
``` | ||
|
||
### Inset divider | ||
|
||
Add the `inset` attribute in order to set whether or not the divider is an inset divider. | ||
|
||
```html | ||
<mat-divider [inset]="true"></mat-divider> | ||
``` | ||
|
||
### Vertical divider | ||
|
||
Add the `vertical` attribute in order to set whether or not the divider is vertically-oriented. | ||
|
||
```html | ||
<mat-divider [vertical]="true"></mat-divider> | ||
``` | ||
|
||
|
||
### Lists with inset dividers | ||
|
||
Dividers can be added to lists as a means of separating content into distinct sections. | ||
Inset dividers can also be added to provide the appearance of distinct elements in a list without cluttering content | ||
like avatar images or icons. Make sure to avoid adding an inset divider to the last element | ||
in a list, because it will overlap with the section divider. | ||
|
||
```html | ||
<mat-list> | ||
<h3 mat-subheader>Folders</h3> | ||
<mat-list-item *ngFor="let folder of folders; last as last"> | ||
<mat-icon mat-list-icon>folder</mat-icon> | ||
<h4 mat-line>{{folder.name}}</h4> | ||
<p mat-line class="demo-2"> {{folder.updated}} </p> | ||
<mat-divider [inset]="true" *ngIf="!last"></mat-divider> | ||
</mat-list-item> | ||
<mat-divider></mat-divider> | ||
<h3 md-subheader>Notes</h3> | ||
<mat-list-item *ngFor="let note of notes"> | ||
<mat-icon md-list-icon>note</mat-icon> | ||
<h4 md-line>{{note.name}}</h4> | ||
<p md-line class="demo-2"> {{note.updated}} </p> | ||
</mat-list-item> | ||
</mat-list> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
$mat-divider-width: 1px; | ||
$mat-divider-inset-margin: 80px; | ||
|
||
.mat-divider { | ||
display: block; | ||
margin: 0; | ||
border-top-width: $mat-divider-width; | ||
border-top-style: solid; | ||
|
||
&.mat-divider-vertical { | ||
border-top: 0; | ||
border-right-width: $mat-divider-width; | ||
border-right-style: solid; | ||
} | ||
|
||
&.mat-divider-inset { | ||
margin-left: $mat-divider-inset-margin; | ||
[dir='rtl'] & { | ||
margin-left: auto; | ||
margin-right: $mat-divider-inset-margin; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import {async, ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {Component} from '@angular/core'; | ||
import {By} from '@angular/platform-browser'; | ||
import {MatDividerModule} from './divider-module'; | ||
|
||
|
||
describe('MatDivider', () => { | ||
|
||
let fixture: ComponentFixture<MatDividerTestComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MatDividerModule], | ||
declarations: [ | ||
MatDividerTestComponent | ||
], | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
fixture = TestBed.createComponent(MatDividerTestComponent); | ||
})); | ||
|
||
it('should apply vertical class to vertical divider', () => { | ||
fixture.componentInstance.vertical = true; | ||
fixture.detectChanges(); | ||
|
||
const divider = fixture.debugElement.query(By.css('mat-divider')); | ||
expect(divider.nativeElement.className).toContain('mat-divider'); | ||
expect(divider.nativeElement.className).toContain('mat-divider-vertical'); | ||
}); | ||
|
||
it('should apply inset class to inset divider', () => { | ||
fixture.componentInstance.inset = true; | ||
fixture.detectChanges(); | ||
|
||
const divider = fixture.debugElement.query(By.css('mat-divider')); | ||
expect(divider.nativeElement.className).toContain('mat-divider'); | ||
expect(divider.nativeElement.className).toContain('mat-divider-inset'); | ||
}); | ||
|
||
it('should apply inset and vertical classes to vertical inset divider', () => { | ||
fixture.componentInstance.vertical = true; | ||
fixture.componentInstance.inset = true; | ||
fixture.detectChanges(); | ||
|
||
const divider = fixture.debugElement.query(By.css('mat-divider')); | ||
expect(divider.nativeElement.className).toContain('mat-divider'); | ||
expect(divider.nativeElement.className).toContain('mat-divider-inset'); | ||
expect(divider.nativeElement.className).toContain('mat-divider-vertical'); | ||
}); | ||
|
||
it('should add aria roles properly', () => { | ||
fixture.detectChanges(); | ||
|
||
const divider = fixture.debugElement.query(By.css('mat-divider')); | ||
expect(divider.nativeElement.getAttribute('role')).toBe('separator'); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
template: `<mat-divider [vertical]="vertical" [inset]="inset"></mat-divider>` | ||
}) | ||
class MatDividerTestComponent { | ||
vertical: boolean; | ||
inset: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {ChangeDetectionStrategy, Component, Input, ViewEncapsulation} from '@angular/core'; | ||
import {coerceBooleanProperty} from '@angular/cdk/coercion'; | ||
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: 'mat-divider', | ||
host: { | ||
'role': 'separator', | ||
'[attr.aria-orientation]': 'vertical ? "vertical" : "horizontal"', | ||
'[class.mat-divider-vertical]': 'vertical', | ||
'[class.mat-divider-inset]': 'inset', | ||
'class': 'mat-divider' | ||
}, | ||
template: '', | ||
styleUrls: ['divider.css'], | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
preserveWhitespaces: false, | ||
}) | ||
export class MatDivider { | ||
/** Whether the divider is vertically aligned. */ | ||
@Input() get vertical(): boolean { return this._vertical; } | ||
set vertical(value: boolean) { this._vertical = coerceBooleanProperty(value); } | ||
private _vertical: boolean = false; | ||
|
||
/** Whether the divider is an inset divider. */ | ||
@Input() get inset(): boolean { return this._inset; } | ||
set inset(value: boolean) { this._inset = coerceBooleanProperty(value); } | ||
private _inset: boolean = false; | ||
} |
Oops, something went wrong.