Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit b1436c0

Browse files
committed
feat(grid): add CSS Grid directives and demo
* Add five demos from gridbyexample.com * Add testing for all components * Change `BaseFxDirective` to `BaseDirective`. `BaseFxDirective` will remain but is deprecated and will be removed in beta.17 * Bump testing for Edge to v16 due to Grid incompatability * Design doc: https://docs.google.com/document/d/1YjKHAV7-wh5UZd4snoyw6bVWe1X5JF-zDaUFa8-JDtE
1 parent 85aa013 commit b1436c0

File tree

78 files changed

+4841
-96
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4841
-96
lines changed

docs/documentation/API-Documentation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {BREAKPOINTS} from '@angular/flex-layout';
1717
providers: [{provide: BREAKPOINTS, useValue: MY_CUSTOM_BREAKPOINTS }]
1818
```
1919

20-
* **[BaseFxDirectiveAdapter](https://github.com/angular/flex-layout/wiki/BaseFxDirectiveAdapter)**:
20+
* **[BaseDirectiveAdapter](https://github.com/angular/flex-layout/wiki/BaseDirectiveAdapter)**:
2121
Adapter class useful to extend existing Directives with MediaQuery activation features.
2222
```typescript
2323
import {NgClass} from '@angular/core';

docs/documentation/Custom-Breakpoints.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Consider, for example, the
8181

8282
```typescript
8383
import {Directive} from '@angular/core';
84-
import {BaseFxDirective} from '@angular/flex-layout';
84+
import {BaseDirective} from '@angular/flex-layout';
8585

8686
@Directive({selector: `
8787
[fxLayout],
@@ -95,7 +95,7 @@ import {BaseFxDirective} from '@angular/flex-layout';
9595
[fxLayout.gt-lg],
9696
[fxLayout.xl]
9797
`})
98-
export class LayoutDirective extends BaseFxDirective {
98+
export class LayoutDirective extends BaseDirective {
9999
...
100100
}
101101
```

guides/Grid.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# CSS Grid with Angular Layout
2+
3+
### Introduction
4+
5+
CSS Grid is a relatively new, powerful layout library available in all evergreen browsers. It provides
6+
an extra level of dimensionality for constructing web layouts compared to Flexbox. We have added 11 new
7+
directives with responsive functionality to the Angular Layout library to enable developers to easily add
8+
the new engine to their apps.
9+
10+
### Usage
11+
12+
The new suite of directives is extensive, and covers the majority of CSS Grid functionality. The
13+
following table shows the parity between directives and CSS properties:
14+
15+
| Grid Directive | CSS Property(s) | Extra Inputs |
16+
| ---------------- |:-----------------------------------------:| --------------------------:|
17+
| `gdAlignColumns` | `align-content` and `align-items` | `gdInline` for inline-grid |
18+
| `gdAlignRows` | `justify-content` and `justify-items` | `gdInline` for inline-grid |
19+
| `gdArea` | `grid-area` | none |
20+
| `gdAreas` | `grid-areas` | `gdInline` for inline-grid |
21+
| `gdAuto` | `grid-auto-flow` | `gdInline` for inline-grid |
22+
| `gdColumn` | `grid-column` | none |
23+
| `gdColumns` | `grid-template-columns` | `gdInline` for inline-grid<br>`!` at the end means `grid-auto-columns` |
24+
| `gdGap` | `grid-gap` | `gdInline` for inline-grid |
25+
| `gdGridAlign` | `justify-self` and `align-self` | none |
26+
| `gdRow` | `grid-row` | none |
27+
| `gdRows` | `grid-template-rows` | `gdInline` for inline-grid<br>`!` at the end means `grid-auto-rows` |
28+
29+
Note: unless otherwise specified, the above table represents exact parity. The inputs for the
30+
directives will be mapped verbatim to the CSS property without sanitization
31+
32+
### Limitations
33+
34+
While CSS Grid has excellent cross-browser and mobile support, it is currently unsupported in IE11
35+
due to an outdated spec implementation
36+
37+
### Using with Flexbox
38+
39+
The new CSS Grid directives can be used in concert with the existing Flexbox directives seamlessly.
40+
Simply import the top-level `FlexLayoutModule`, or both `FlexModule` and `GridModule` as follows:
41+
42+
```typescript
43+
import {FlexLayoutModule} from '@angular/flex-layout';
44+
```
45+
46+
```typescript
47+
import {FlexModule} from '@angular/flex-layout/flex';
48+
import {GridModule} from '@angular/flex-layout/grid';
49+
```
50+
51+
This allows you to use, for example, Flexbox inside a CSS Grid as follows:
52+
53+
```html
54+
<div gdAuto>
55+
<div fxLayout="row">
56+
<div fxFlex></div>
57+
</div>
58+
</div>
59+
```
60+
61+
### References
62+
63+
The design doc for this part of the library can be found
64+
[here](https://docs.google.com/document/d/1YjKHAV7-wh5UZd4snoyw6bVWe1X5JF-zDaUFa8-JDtE)

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@angular/core": "^6.0.0-rc.0",
3434
"@angular/platform-browser": "^6.0.0-rc.0",
3535
"core-js": "^2.4.1",
36-
"rxjs": "^6.0.0-beta.4",
36+
"rxjs": "^6.0.0-rc.0",
3737
"systemjs": "0.19.43",
3838
"tsickle": "^0.27.0",
3939
"tslib": "^1.8.0",

src/apps/demo-app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"devDependencies": {
3333
"@angular/cli": "1.7.2",
3434
"@angular/compiler-cli": "file:../../../node_modules/@angular/compiler-cli",
35-
"@angular/language-service": "^6.0.0-rc.0",
35+
"@angular/language-service": "^6.0.0-rc.1",
3636
"@types/jasmine": "~2.8.3",
3737
"@types/jasminewd2": "~2.0.2",
3838
"@types/node": "~6.0.60",

src/apps/demo-app/src/app/app.component.html

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ <h2>Layout Demos: </h2>
99
<div fxFlex fxLayout="column"
1010
fxLayoutAlign="left top"
1111
style="font-size: 0.85em; margin-top: 10px; padding-bottom:20px; white-space:normal">
12-
These Layout demos are curated from the Angular Material v1.x documentation, GitHub Issues,
13-
StackOverflow,
14-
and CodePen.
12+
These Layout demos are curated from the AngularJS Material documentation, GitHub Issues, StackOverflow, and CodePen.
1513
<span class="title" style="font-size: 0.7em; font-weight:normal;">
16-
Hint: Click on any of the samples below to toggle the layout direction(s).
17-
</span>
14+
Hint: Click on any of the samples below to toggle the layout direction(s).
15+
</span>
1816
</div>
1917
<div fxLayout="row"
2018
fxLayoutAlign="start center"
@@ -23,6 +21,7 @@ <h2>Layout Demos: </h2>
2321
<button mat-raised-button color="primary" [routerLink]="['']">
2422
Static
2523
</button>
24+
<button mat-raised-button color="primary" [routerLink]="['grid']"> Grids</button>
2625
<button mat-raised-button color="primary" [routerLink]="['responsive']"> Responsive
2726
</button>
2827
<button mat-raised-button color="primary" [routerLink]="['issues']"> Github</button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { DocsLayoutComponent } from './docs-grid.component';
4+
5+
describe('DocsLayoutComponent', () => {
6+
let component: DocsLayoutComponent;
7+
let fixture: ComponentFixture<DocsLayoutComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ DocsLayoutComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(DocsLayoutComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
selector: 'demo-docs-grid',
5+
template: `
6+
<demo-grid-layout class="small-demo"></demo-grid-layout>
7+
<demo-grid-nested class="small-demo"></demo-grid-nested>
8+
<demo-grid-minmax class="small-demo"></demo-grid-minmax>
9+
<demo-grid-position class="small-demo"></demo-grid-position>
10+
<demo-grid-overlay class="small-demo"></demo-grid-overlay>
11+
`
12+
})
13+
export class DocsGridComponent {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { FlexOffsetValuesComponent } from './grid-layout.component';
4+
5+
describe('FlexOffsetValuesComponent', () => {
6+
let component: FlexOffsetValuesComponent;
7+
let fixture: ComponentFixture<FlexOffsetValuesComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ FlexOffsetValuesComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(FlexOffsetValuesComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {Component} from '@angular/core';
2+
3+
// Example taken from https://gridbyexample.com/examples/example13/
4+
/* tslint:disable */
5+
@Component({
6+
selector: 'demo-grid-layout',
7+
template: `
8+
<mat-card class="card-demo">
9+
<mat-card-title>Basic Responsive Grid App</mat-card-title>
10+
<mat-card-content class="containerX">
11+
<div class="colorNested box" style="height: auto;">
12+
<div gdAreas.xs="header | sidebar | content | sidebar2 | footer" gdGap="1em"
13+
gdColumns.xs="none"
14+
gdAreas.sm="header header | sidebar content | sidebar2 sidebar2 | footer footer"
15+
gdColumns.sm="20%!"
16+
gdAreas.gt-sm="header header header | sidebar content sidebar2 | footer footer footer"
17+
gdColumns.gt-sm="120px auto 120px" gdGap.gt-sm="20px" [ngStyle]="{'max-width': 'auto'}"
18+
[ngStyle.gt-sm]="{'max-width': '600px'}">
19+
<div class="blocks one" gdArea="header">Header</div>
20+
<div class="blocks two" gdArea="sidebar">Sidebar</div>
21+
<div class="blocks three" gdArea="sidebar2">Sidebar 2</div>
22+
<div class="blocks four" gdArea="content">Content
23+
<br /> More content than we had before so this column is now quite tall.</div>
24+
<div class="blocks five" gdArea="footer">Footer</div>
25+
</div>
26+
</div>
27+
</mat-card-content>
28+
</mat-card>
29+
`
30+
})
31+
export class GridLayoutComponent {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { GridMinmaxComponent } from './grid-minmax.component';
4+
5+
describe('GridMinmaxComponent', () => {
6+
let component: GridMinmaxComponent;
7+
let fixture: ComponentFixture<GridMinmaxComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ GridMinmaxComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(GridMinmaxComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Component } from '@angular/core';
2+
3+
// Example taken from https://gridbyexample.com/examples/example29/
4+
@Component({
5+
selector: 'demo-grid-minmax',
6+
template: `
7+
<mat-card class="card-demo">
8+
<mat-card-title>Grid with Minmax</mat-card-title>
9+
<mat-card-content class="containerX">
10+
<div class="colorNested" style="height: auto;">
11+
<div gdGap="10px" gdColumns="repeat(auto-fill, minmax(200px, 1fr))">
12+
<div class="box" gdColumn="auto / span 2">A</div>
13+
<div class="box">B</div>
14+
<div class="box">C</div>
15+
<div class="box">D</div>
16+
<div class="box">E</div>
17+
<div class="box">F</div>
18+
<div class="box" gdColumn="auto / span 2" gdRow="auto / span 2">G</div>
19+
<div class="box">H</div>
20+
<div class="box">I</div>
21+
<div class="box">J</div>
22+
<div class="box" gdColumn="auto / span 3">K</div>
23+
<div class="box">L</div>
24+
<div class="box">M</div>
25+
</div>
26+
</div>
27+
</mat-card-content>
28+
</mat-card>
29+
`,
30+
styles: [`.box {
31+
/*background-color: #444;*/
32+
/*color: #fff;*/
33+
border-radius: 5px;
34+
padding: 20px;
35+
font-size: 150%;
36+
37+
}`]
38+
})
39+
export class GridMinmaxComponent {
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { GridNestedComponent } from './grid-nested.component';
4+
5+
describe('GridNestedComponent', () => {
6+
let component: GridNestedComponent;
7+
let fixture: ComponentFixture<GridNestedComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ GridNestedComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(GridNestedComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Component } from '@angular/core';
2+
3+
// Example taken from https://gridbyexample.com/examples/example21/
4+
@Component({
5+
selector: 'demo-grid-nested',
6+
template: `
7+
<mat-card class="card-demo">
8+
<mat-card-title>Nested Grid</mat-card-title>
9+
<mat-card-content class="containerX">
10+
<div class="colorNested" style="height: auto;">
11+
<div gdGap="20px" gdColumns="repeat(4, [col] 150px)" gdRows="repeat(2, [row] auto)">
12+
<div class="box" gdColumn="col / span 2" gdRow="row">A</div>
13+
<div class="box" gdColumn="col 3 / span 2" gdRow="row">B</div>
14+
<div class="box" gdColumn="col / span 2" gdRow="row 2">C</div>
15+
<div class="box" gdColumn="col 3 / span 2" gdRow="row 2" gdGap="10px"
16+
gdColumns="1fr 1fr">
17+
<div class="box one" gdColumn="1 / 3" gdRow="1">E</div>
18+
<div class="box two" gdColumn="1" gdRow="2">F</div>
19+
<div class="box three" gdColumn="2" gdRow="2">G</div>
20+
</div>
21+
</div>
22+
</div>
23+
</mat-card-content>
24+
</mat-card>
25+
`,
26+
styles: [`.box {
27+
border-radius: 5px;
28+
padding: 20px;
29+
font-size: 150%;
30+
}`]
31+
})
32+
export class GridNestedComponent {
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { GridOverlayComponent } from './grid-overlay.component';
4+
5+
describe('GridOverlayComponent', () => {
6+
let component: GridOverlayComponent;
7+
let fixture: ComponentFixture<GridOverlayComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ GridOverlayComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(GridOverlayComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});

0 commit comments

Comments
 (0)