Skip to content

Commit

Permalink
feat(divider): move divider out of mat-list
Browse files Browse the repository at this point in the history
- 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
CaerusKaru committed Oct 11, 2017
1 parent 291a87c commit 70c9d4d
Show file tree
Hide file tree
Showing 19 changed files with 417 additions and 38 deletions.
17 changes: 17 additions & 0 deletions src/demo-app/card/card-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@
</mat-card-footer>
</mat-card>

<mat-card>
<mat-card-subtitle>Subtitle</mat-card-subtitle>
<mat-card-title>Card with title, footer, and inset-divider</mat-card-title>
<mat-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>
</mat-card-content>
<mat-divider [inset]="true"></mat-divider>
<mat-card-actions>
<button md-button>LIKE</button>
<button md-button>SHARE</button>
</mat-card-actions>
<mat-card-footer>
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</mat-card-footer>
</mat-card>

<mat-card>
<img mat-card-image src="https://material.angularjs.org/latest/img/washedout.png">
<mat-card-title>Content Title</mat-card-title>
Expand Down
21 changes: 21 additions & 0 deletions src/demo-app/list/list-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ <h3 mat-line>{{contact.name}}</h3>
</mat-list-item>
</mat-list>

<<<<<<< HEAD
<mat-list>
<h3 mat-subheader>Today</h3>
<mat-list-item *ngFor="let message of messages">
Expand All @@ -39,6 +40,26 @@ <h4 mat-line>{{message.from}}</h4>
<p mat-line class="demo-secondary-text">{{message.message}} </p>
</mat-list-item>
</mat-list>
=======
<md-list>
<h3 md-subheader>Today</h3>
<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">
<h4 md-line>{{message.from}}</h4>
<p md-line> {{message.subject}} </p>
<p md-line class="demo-secondary-text">{{message.message}} </p>
</md-list-item>
</md-list>
>>>>>>> feat(divider): move divider out of md-list
</div>

<div>
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 @@ -43,6 +44,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-form-field-theme($theme);
@include mat-grid-list-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);
}
}
29 changes: 29 additions & 0 deletions src/lib/divider/divider-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @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 '../core';
import {
MatDivider,
MatDividerCssMatStyler,
} from './divider';


@NgModule({
imports: [MatCommonModule],
exports: [
MatDivider,
MatCommonModule,
MatDividerCssMatStyler,
],
declarations: [
MatDivider,
MatDividerCssMatStyler,
],
})
export class MatDividerModule {}
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"></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>
```
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 {MatDividerModule} from './divider-module';


describe('MdDivider', () => {

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('md-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('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(MatDividerInset);
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(MatDividerVerticalInset);
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(MatDividerWithCssClass);
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(MatDividerBase);
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 MatDividerBase { }

@Component({
template: `<md-divider [vertical]="true"></md-divider>`
})
class MatDividerVertical { }

@Component({
template: `<md-divider [inset]="true"></md-divider>`
})
class MatDividerInset { }

@Component({
template: `<md-divider [vertical]="true" [inset]="true"></md-divider>`
})
class MatDividerVerticalInset { }

@Component({
template: `<md-divider class="test-class"></md-divider>`
})
class MatDividerWithCssClass { }
Loading

0 comments on commit 70c9d4d

Please sign in to comment.