Skip to content

Commit

Permalink
feat(divider): move divider out of mat-list (#5862)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaerusKaru authored and josephperrott committed Dec 21, 2017
1 parent d773102 commit bd0ec64
Show file tree
Hide file tree
Showing 32 changed files with 378 additions and 41 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/src/lib/chips/** @tinayuangao
/src/lib/datepicker/** @mmalerba
/src/lib/dialog/** @jelbourn @crisbeto
/src/lib/divider/** @jelbourn @crisbeto
/src/lib/expansion/** @josephperrott @jelbourn
/src/lib/form-field/** @mmalerba
/src/lib/grid-list/** @kara @jelbourn
Expand Down
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 mat-button>LIKE</button>
<button mat-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
2 changes: 2 additions & 0 deletions src/demo-app/demo-material-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
MatChipsModule,
MatDatepickerModule,
MatDialogModule,
MatDividerModule,
MatExpansionModule,
MatFormFieldModule,
MatGridListModule,
Expand Down Expand Up @@ -63,6 +64,7 @@ import {PortalModule} from '@angular/cdk/portal';
MatTableModule,
MatDatepickerModule,
MatDialogModule,
MatDividerModule,
MatExpansionModule,
MatFormFieldModule,
MatGridListModule,
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 mat-line>{{contact.name}}</h3>

<mat-list>
<h3 mat-subheader>Today</h3>
<mat-list-item *ngFor="let message of messages">
<mat-list-item *ngFor="let message of messages; last as last">
<img mat-list-avatar [src]="message.image" alt="Image of {{message.from}}">
<h4 mat-line>{{message.from}}</h4>
<p mat-line>
<span>{{message.subject}} -- </span>
<span class="demo-secondary-text">{{message.message}}</span>
</p>
<mat-divider [inset]="true" *ngIf="!last"></mat-divider>
</mat-list-item>
<mat-divider></mat-divider>
<mat-list-item *ngFor="let message of messages">
Expand Down
18 changes: 18 additions & 0 deletions src/demo-app/menu/menu-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@
</button>
</mat-menu>
</div>
<div class="menu-section">
<p>Menu with divider</p>

<mat-toolbar>
<button mat-icon-button [matMenuTriggerFor]="divider" aria-label="Open basic menu">
<mat-icon>more_vert</mat-icon>
</button>
</mat-toolbar>

<mat-menu #divider="matMenu">
<ng-container *ngFor="let item of items; last as last">
<button mat-menu-item [disabled]="item.disabled">
{{ item.text }}
</button>
<mat-divider *ngIf="!last"></mat-divider>
</ng-container>
</mat-menu>
</div>
<div class="menu-section">
<p>Nested menu</p>

Expand Down
1 change: 1 addition & 0 deletions src/demo-app/system-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ System.config({
'@angular/material/core': 'dist/packages/material/core/index.js',
'@angular/material/datepicker': 'dist/packages/material/datepicker/index.js',
'@angular/material/dialog': 'dist/packages/material/dialog/index.js',
'@angular/material/divider': 'dist/packages/material/divider/index.js',
'@angular/material/expansion': 'dist/packages/material/expansion/index.js',
'@angular/material/form-field': 'dist/packages/material/form-field/index.js',
'@angular/material/grid-list': 'dist/packages/material/grid-list/index.js',
Expand Down
2 changes: 2 additions & 0 deletions src/e2e-app/e2e-app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
MatButtonModule,
MatCheckboxModule,
MatDialogModule,
MatDividerModule,
MatFormFieldModule,
MatGridListModule,
MatIconModule,
Expand Down Expand Up @@ -50,6 +51,7 @@ import {ReactiveFormsModule} from '@angular/forms';
MatButtonModule,
MatCheckboxModule,
MatDialogModule,
MatDividerModule,
MatFormFieldModule,
MatGridListModule,
MatIconModule,
Expand Down
1 change: 1 addition & 0 deletions src/e2e-app/system-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ System.config({
'@angular/material/core': 'dist/bundles/material-core.umd.js',
'@angular/material/datepicker': 'dist/bundles/material-datepicker.umd.js',
'@angular/material/dialog': 'dist/bundles/material-dialog.umd.js',
'@angular/material/divider': 'dist/bundles/material-divider.umd.js',
'@angular/material/expansion': 'dist/bundles/material-expansion.umd.js',
'@angular/material/form-field': 'dist/bundles/material-form-field.umd.js',
'@angular/material/grid-list': 'dist/bundles/material-grid-list.umd.js',
Expand Down
16 changes: 16 additions & 0 deletions src/lib/card/card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ $mat-card-header-size: 40px !default;
padding: $mat-card-default-padding;
border-radius: $mat-card-border-radius;

.mat-divider {
position: absolute;
left: 0;
width: 100%;

[dir='rtl'] & {
left: auto;
right: 0;
}

&.mat-divider-inset {
position: static;
margin: 0;
}
}

@include cdk-high-contrast {
outline: solid 1px;
}
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);
}
}
25 changes: 25 additions & 0 deletions src/lib/divider/divider-module.ts
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 {}
55 changes: 55 additions & 0 deletions src/lib/divider/divider.md
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>
```
23 changes: 23 additions & 0 deletions src/lib/divider/divider.scss
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;
}
}
}
66 changes: 66 additions & 0 deletions src/lib/divider/divider.spec.ts
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;
}
38 changes: 38 additions & 0 deletions src/lib/divider/divider.ts
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;
}
Loading

0 comments on commit bd0ec64

Please sign in to comment.