Skip to content

Commit

Permalink
feat(divider): move divider out of md-list
Browse files Browse the repository at this point in the history
- 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
CaerusKaru committed Jul 19, 2017
1 parent 03c0087 commit e7d1a42
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 38 deletions.
17 changes: 16 additions & 1 deletion src/demo-app/card/card-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,26 @@

<md-card>
<md-card-subtitle>Subtitle</md-card-subtitle>
<md-card-title>Card with title and footer</md-card-title>
<md-card-title>Card with title and full-bleed divider</md-card-title>
<md-card-content>
<p>This is supporting text.</p>
<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>
</md-card-content>
<md-divider></md-divider>
<md-card-actions>
<button md-button>LIKE</button>
<button md-button>SHARE</button>
</md-card-actions>
</md-card>

<md-card>
<md-card-subtitle>Subtitle</md-card-subtitle>
<md-card-title>Card with title, footer, and inset-divider</md-card-title>
<md-card-content>
<p>This is supporting text.</p>
<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>
</md-card-content>
<md-divider [inset]="true"></md-divider>
<md-card-actions>
<button md-button>LIKE</button>
<button md-button>SHARE</button>
Expand Down
3 changes: 2 additions & 1 deletion src/demo-app/list/list-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ <h3 md-line>{{contact.name}}</h3>

<md-list>
<h3 md-subheader>Today</h3>
<md-list-item *ngFor="let message of messages">
<md-list-item *ngFor="let message of messages; last as last">
<img md-list-avatar [src]="message.image" alt="Image of {{message.from}}">
<h4 md-line>{{message.from}}</h4>
<p md-line>
<span>{{message.subject}} -- </span>
<span class="demo-secondary-text">{{message.message}}</span>
</p>
<md-divider [inset]="true" *ngIf="!last"></md-divider>
</md-list-item>
<md-divider></md-divider>
<md-list-item *ngFor="let message of messages">
Expand Down
2 changes: 2 additions & 0 deletions src/lib/core/theming/_all-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@import '../../table/table-theme';
@import '../../datepicker/datepicker-theme';
@import '../../dialog/dialog-theme';
@import '../../divider/divider-theme';
@import '../../expansion/expansion-theme';
@import '../../grid-list/grid-list-theme';
@import '../../icon/icon-theme';
Expand Down Expand Up @@ -41,6 +42,7 @@
@include mat-table-theme($theme);
@include mat-datepicker-theme($theme);
@include mat-dialog-theme($theme);
@include mat-divider-theme($theme);
@include mat-expansion-panel-theme($theme);
@include mat-grid-list-theme($theme);
@include mat-icon-theme($theme);
Expand Down
1 change: 1 addition & 0 deletions src/lib/divider/README.md
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
15 changes: 15 additions & 0 deletions src/lib/divider/_divider-theme.scss
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);
}
}
64 changes: 64 additions & 0 deletions src/lib/divider/divider.md
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>
```
66 changes: 66 additions & 0 deletions src/lib/divider/divider.scss
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;
}
}
}
99 changes: 99 additions & 0 deletions src/lib/divider/divider.spec.ts
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 { }
54 changes: 54 additions & 0 deletions src/lib/divider/divider.ts
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 {}
32 changes: 32 additions & 0 deletions src/lib/divider/index.ts
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';
Loading

0 comments on commit e7d1a42

Please sign in to comment.