-
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 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
- Loading branch information
1 parent
03c0087
commit e7d1a42
Showing
14 changed files
with
356 additions
and
38 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
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,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"></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-nav-list> | ||
``` | ||
|
||
|
||
### 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 {MdDividerModule} from './index'; | ||
|
||
|
||
describe('MdDivider', () => { | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MdDividerModule], | ||
declarations: [ | ||
MdDividerBase, | ||
MdDividerVertical, | ||
MdDividerInset, | ||
MdDividerVerticalInset, | ||
MdDividerWithCssClass, | ||
], | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
})); | ||
|
||
it('should not apply any additional class to a list without lines', () => { | ||
let fixture = TestBed.createComponent(MdDividerBase); | ||
let divider = fixture.debugElement.query(By.css('md-divider')); | ||
fixture.detectChanges(); | ||
expect(divider.nativeElement.className).toBe('mat-divider'); | ||
}); | ||
|
||
it('should apply vertical class to vertical divider', () => { | ||
let fixture = TestBed.createComponent(MdDividerVertical); | ||
fixture.detectChanges(); | ||
|
||
let divider = fixture.debugElement.query(By.css('md-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(MdDividerInset); | ||
fixture.detectChanges(); | ||
|
||
let divider = fixture.debugElement.query(By.css('md-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(MdDividerVerticalInset); | ||
fixture.detectChanges(); | ||
|
||
let divider = fixture.debugElement.query(By.css('md-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(MdDividerWithCssClass); | ||
fixture.detectChanges(); | ||
|
||
let divider = fixture.debugElement.query(By.css('md-divider')); | ||
expect(divider.nativeElement.classList.contains('test-class')).toBe(true); | ||
}); | ||
|
||
it('should add aria roles properly', () => { | ||
let fixture = TestBed.createComponent(MdDividerBase); | ||
fixture.detectChanges(); | ||
|
||
let divider = fixture.debugElement.query(By.css('md-divider')); | ||
expect(divider.nativeElement.getAttribute('role')).toBe('separator'); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
template: `<md-divider></md-divider>` | ||
}) | ||
class MdDividerBase { } | ||
|
||
@Component({ | ||
template: `<md-divider [vertical]="true"></md-divider>` | ||
}) | ||
class MdDividerVertical { } | ||
|
||
@Component({ | ||
template: `<md-divider [inset]="true"></md-divider>` | ||
}) | ||
class MdDividerInset { } | ||
|
||
@Component({ | ||
template: `<md-divider [vertical]="true" [inset]="true"></md-divider>` | ||
}) | ||
class MdDividerVerticalInset { } | ||
|
||
@Component({ | ||
template: `<md-divider class="test-class"></md-divider>` | ||
}) | ||
class MdDividerWithCssClass { } |
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,54 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. 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, | ||
Directive, | ||
Input, ViewEncapsulation, | ||
} from '@angular/core'; | ||
import {coerceBooleanProperty} from '../core'; | ||
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: 'md-divider, mat-divider', | ||
host: { | ||
'role': 'separator', | ||
'[attr.aria-orientation]': 'vertical ? "vertical" : "horizontal"', | ||
'[class.mat-divider-vertical]': 'vertical', | ||
'[class.mat-divider-inset]': 'inset', | ||
}, | ||
template: '<ng-content></ng-content>', | ||
styleUrls: ['divider.css'], | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class MdDivider { | ||
/** Whether the divider is vertically aligned. */ | ||
@Input() get vertical(): boolean { return this._vertical; } | ||
set vertical(value: boolean) { | ||
this._vertical = coerceBooleanProperty(value); | ||
} | ||
protected _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); | ||
} | ||
protected _inset: boolean = false; | ||
} | ||
|
||
/** | ||
* Directive whose purpose is to add the mat- CSS styling to this selector. | ||
* @docs-private | ||
*/ | ||
@Directive({ | ||
selector: 'md-divider, mat-divider', | ||
host: {'class': 'mat-divider'} | ||
}) | ||
export class MdDividerCssMatStyler {} |
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,32 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. 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 {MdLineModule, MdRippleModule, MdCommonModule} from '../core'; | ||
import { | ||
MdDivider, | ||
MdDividerCssMatStyler, | ||
} from './divider'; | ||
|
||
|
||
@NgModule({ | ||
imports: [MdLineModule, MdRippleModule, MdCommonModule], | ||
exports: [ | ||
MdDivider, | ||
MdCommonModule, | ||
MdDividerCssMatStyler, | ||
], | ||
declarations: [ | ||
MdDivider, | ||
MdDividerCssMatStyler, | ||
], | ||
}) | ||
export class MdDividerModule {} | ||
|
||
|
||
export * from './divider'; |
Oops, something went wrong.