-
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
- Loading branch information
1 parent
291a87c
commit 06dd188
Showing
25 changed files
with
408 additions
and
39 deletions.
There are no files selected for viewing
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,30 @@ | ||
/** | ||
* @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 {MatCommonModule} from '@angular/material/core'; | ||
import { | ||
MatDivider, | ||
MatDividerCssMatStyler, | ||
} from './divider'; | ||
import {CommonModule} from '@angular/common'; | ||
|
||
|
||
@NgModule({ | ||
imports: [MatCommonModule, CommonModule], | ||
exports: [ | ||
MatDivider, | ||
MatDividerCssMatStyler, | ||
MatCommonModule, | ||
], | ||
declarations: [ | ||
MatDivider, | ||
MatDividerCssMatStyler, | ||
], | ||
}) | ||
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,64 @@ | ||
`<md-divider>` is a container component that wraps and formats a series of line items. As the base | ||
list component, it provides Material Design styling, but no behavior of its own. | ||
|
||
<!-- example(divider-overview) --> | ||
|
||
|
||
### Simple divider | ||
|
||
An `<md-divider>` element can be used on its own to create a vertical line styled with a Material theme | ||
|
||
```html | ||
<md-divider></md-divider> | ||
``` | ||
|
||
Here are the available global options: | ||
|
||
| Name | Type | Values | Description | | ||
| --------------- | ------- | ----------- | ----------------------------------------- | | ||
| inset | boolean | true, false | Whether the divider is an inset divider | | ||
| vertical | boolean | true, false | Whether the divider is a vertical divider | | ||
|
||
|
||
### Inset divider | ||
|
||
Add the `inset` attribute in order to set whether or not the divider is an inset divider. | ||
|
||
```html | ||
<md-divider [inset]="true"></md-divider> | ||
``` | ||
|
||
### Vertical divider | ||
|
||
Add the `vertical` attribute in order to set whether or not the divider is vertically-oriented. | ||
|
||
```html | ||
<md-divider [vertical]="true"></md-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. If combining both, please make sure to avoid adding an inset divider to the last element | ||
in a list, because it will overlap with the section divider. | ||
|
||
```html | ||
<md-list> | ||
<h3 md-subheader>Folders</h3> | ||
<md-list-item *ngFor="let folder of folders; last as last"> | ||
<md-icon md-list-icon>folder</md-icon> | ||
<h4 md-line>{{folder.name}}</h4> | ||
<p md-line class="demo-2"> {{folder.updated}} </p> | ||
<md-divider [inset]="true" *ngIf="!last"></md-divider> | ||
</md-list-item> | ||
<md-divider></md-divider> | ||
<h3 md-subheader>Notes</h3> | ||
<md-list-item *ngFor="let note of notes"> | ||
<md-icon md-list-icon>note</md-icon> | ||
<h4 md-line>{{note.name}}</h4> | ||
<p md-line class="demo-2"> {{note.updated}} </p> | ||
</md-list-item> | ||
</md-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,66 @@ | ||
.mat-divider { | ||
display: block; | ||
margin: 0; | ||
border-top-width: 1px; | ||
border-top-style: solid; | ||
|
||
&.mat-divider-vertical { | ||
border-top: 0; | ||
border-right-width: 1px; | ||
border-right-style: solid; | ||
position: static !important; | ||
width: auto !important; | ||
} | ||
|
||
&.mat-divider-inset { | ||
margin-left: 80px; | ||
[dir='rtl'] & { | ||
margin-left: auto; | ||
margin-right: 80px; | ||
} | ||
} | ||
} | ||
|
||
.mat-list-item { | ||
.mat-divider { | ||
position: absolute; | ||
bottom: 0; | ||
|
||
left: 0; | ||
[dir='rtl'] & { | ||
left: auto; | ||
right: 0; | ||
} | ||
|
||
width: 100%; | ||
&.mat-divider-inset { | ||
left: 72px; | ||
[dir='rtl'] & { | ||
left: auto; | ||
right: 72px; | ||
} | ||
|
||
width: calc(100% - 72px); | ||
margin: 0 !important; | ||
} | ||
} | ||
} | ||
|
||
.mat-card { | ||
.mat-divider { | ||
position: absolute; | ||
|
||
left: 0; | ||
[dir='rtl'] & { | ||
left: auto; | ||
right: 0; | ||
} | ||
|
||
width: 100%; | ||
|
||
&.mat-divider-inset { | ||
position: static; | ||
margin: 0 !important; | ||
} | ||
} | ||
} |
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,99 @@ | ||
import {async, TestBed} from '@angular/core/testing'; | ||
import {Component} from '@angular/core'; | ||
import {By} from '@angular/platform-browser'; | ||
import {MatDividerModule} from './divider-module'; | ||
|
||
|
||
describe('MatDivider', () => { | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MatDividerModule], | ||
declarations: [ | ||
MatDividerBase, | ||
MatDividerVertical, | ||
MatDividerInset, | ||
MatDividerVerticalInset, | ||
MatDividerWithCssClass, | ||
], | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
})); | ||
|
||
it('should not apply any additional class to a list without lines', () => { | ||
let fixture = TestBed.createComponent(MatDividerBase); | ||
let divider = fixture.debugElement.query(By.css('mat-divider')); | ||
fixture.detectChanges(); | ||
expect(divider.nativeElement.className).toBe('mat-divider'); | ||
}); | ||
|
||
it('should apply vertical class to vertical divider', () => { | ||
let fixture = TestBed.createComponent(MatDividerVertical); | ||
fixture.detectChanges(); | ||
|
||
let 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', () => { | ||
let fixture = TestBed.createComponent(MatDividerInset); | ||
fixture.detectChanges(); | ||
|
||
let 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', () => { | ||
let fixture = TestBed.createComponent(MatDividerVerticalInset); | ||
fixture.detectChanges(); | ||
|
||
let 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 not clear custom classes provided by user', () => { | ||
let fixture = TestBed.createComponent(MatDividerWithCssClass); | ||
fixture.detectChanges(); | ||
|
||
let divider = fixture.debugElement.query(By.css('mat-divider')); | ||
expect(divider.nativeElement.classList.contains('test-class')).toBe(true); | ||
}); | ||
|
||
it('should add aria roles properly', () => { | ||
let fixture = TestBed.createComponent(MatDividerBase); | ||
fixture.detectChanges(); | ||
|
||
let divider = fixture.debugElement.query(By.css('mat-divider')); | ||
expect(divider.nativeElement.getAttribute('role')).toBe('separator'); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
template: `<mat-divider></mat-divider>` | ||
}) | ||
class MatDividerBase { } | ||
|
||
@Component({ | ||
template: `<mat-divider [vertical]="true"></mat-divider>` | ||
}) | ||
class MatDividerVertical { } | ||
|
||
@Component({ | ||
template: `<mat-divider [inset]="true"></mat-divider>` | ||
}) | ||
class MatDividerInset { } | ||
|
||
@Component({ | ||
template: `<mat-divider [vertical]="true" [inset]="true"></mat-divider>` | ||
}) | ||
class MatDividerVerticalInset { } | ||
|
||
@Component({ | ||
template: `<mat-divider class="test-class"></mat-divider>` | ||
}) | ||
class MatDividerWithCssClass { } |
Oops, something went wrong.