-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Schematic improvements #11191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schematic improvements #11191
Changes from 7 commits
111826c
e35554b
08174db
cf0fc06
46bddb4
320c2ec
eace06d
1eca79b
2acce79
366f42d
2f7c1aa
5237987
5fe8986
c9296c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,27 +9,26 @@ | |
"schema": "./shell/schema.json", | ||
"aliases": ["material-shell"] | ||
}, | ||
|
||
// Create a dashboard component | ||
"materialDashboard": { | ||
"dashboard": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should keep the old name as an alias |
||
"description": "Create a card-based dashboard component", | ||
"factory": "./dashboard/index", | ||
"schema": "./dashboard/schema.json", | ||
"aliases": [ "material-dashboard" ] | ||
"aliases": [] | ||
}, | ||
// Creates a table component | ||
"materialTable": { | ||
"table": { | ||
"description": "Create a component that displays data with a data-table", | ||
"factory": "./table/index", | ||
"schema": "./table/schema.json", | ||
"aliases": [ "material-table" ] | ||
"aliases": [] | ||
}, | ||
// Creates toolbar and navigation components | ||
"materialNav": { | ||
"nav": { | ||
"description": "Create a component with a responsive sidenav for navigation", | ||
"factory": "./nav/index", | ||
"schema": "./nav/schema.json", | ||
"aliases": [ "material-nav" ] | ||
"aliases": [] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Dashboard | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why create a separate file for each one? |
||
Creates a responive card grid list component . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra space before the dot. |
||
|
||
Command: `ng g @angular/material:materialDashboard --name dashboard` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it be |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core'; | ||
import { map } from 'rxjs/operators'; | ||
import { Breakpoints, BreakpointState, BreakpointObserver } from '@angular/cdk/layout'; | ||
|
||
@Component({ | ||
selector: '<%= selector %>',<% if(inlineTemplate) { %> | ||
|
@@ -59,10 +61,26 @@ import { Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if( | |
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %> | ||
}) | ||
export class <%= classify(name) %>Component { | ||
cards = [ | ||
{ title: 'Card 1', cols: 2, rows: 1 }, | ||
{ title: 'Card 2', cols: 1, rows: 1 }, | ||
{ title: 'Card 3', cols: 1, rows: 2 }, | ||
{ title: 'Card 4', cols: 1, rows: 1 } | ||
]; | ||
/** Based on the screen size, switch from standard to one column per row */ | ||
cards = this.breakpointObserver.observe(Breakpoints.Handset).pipe( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
map(({ matches }) => { | ||
if (matches) { | ||
return [ | ||
{ title: 'Card 1', cols: 2, rows: 1 }, | ||
{ title: 'Card 2', cols: 2, rows: 1 }, | ||
{ title: 'Card 3', cols: 2, rows: 1 }, | ||
{ title: 'Card 4', cols: 2, rows: 1 } | ||
]; | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need the |
||
return [ | ||
{ title: 'Card 1', cols: 2, rows: 1 }, | ||
{ title: 'Card 2', cols: 1, rows: 1 }, | ||
{ title: 'Card 3', cols: 1, rows: 2 }, | ||
{ title: 'Card 4', cols: 1, rows: 1 } | ||
]; | ||
} | ||
}) | ||
); | ||
|
||
constructor(private breakpointObserver: BreakpointObserver) {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Nav | ||
Creates a navigation component with responsive sidenav. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "with responsive" -> "with a responsive" |
||
|
||
Command: `ng g @angular/material:materialNav --name nav` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,9 @@ | |
|
||
.sidenav { | ||
width: 200px; | ||
box-shadow: 3px 0 6px rgba(0,0,0,.24); | ||
} | ||
|
||
.mat-toolbar.mat-primary { | ||
position: sticky; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we really be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We actually use position sticky on the material docs site. Supports seems decent just missing IE11. |
||
top: 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import {addModuleImportToRootModule, getStylesPath} from '../utils/ast'; | |
import {InsertChange} from '../utils/devkit-utils/change'; | ||
import {getProjectFromWorkspace, getWorkspace} from '../utils/devkit-utils/config'; | ||
import {addHeadLink} from '../utils/html'; | ||
import {angularVersion, cdkVersion, materialVersion} from '../utils/lib-versions'; | ||
import {angularVersion, materialVersion} from '../utils/lib-versions'; | ||
import {addPackageToPackageJson} from '../utils/package'; | ||
import {Schema} from './schema'; | ||
import {addThemeToAppStyles} from './theming'; | ||
|
@@ -28,7 +28,7 @@ export default function(options: Schema): Rule { | |
/** Add material, cdk, annimations to package.json if not already present. */ | ||
function addMaterialToPackageJson() { | ||
return (host: Tree) => { | ||
addPackageToPackageJson(host, 'dependencies', '@angular/cdk', cdkVersion); | ||
addPackageToPackageJson(host, 'dependencies', '@angular/cdk', materialVersion); | ||
addPackageToPackageJson(host, 'dependencies', '@angular/material', materialVersion); | ||
addPackageToPackageJson(host, 'dependencies', '@angular/animations', angularVersion); | ||
return host; | ||
|
@@ -78,7 +78,7 @@ function addBodyMarginToStyles(options: Schema) { | |
const buffer = host.read(stylesPath); | ||
if (buffer) { | ||
const src = buffer.toString(); | ||
const insertion = new InsertChange(stylesPath, src.length, `\nbody { margin: 0; }\n`); | ||
const insertion = new InsertChange(stylesPath, src.length, `\nbody { margin: 0; font-family: 'Roboto', sans-serif; }\n`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this should happen by default. The install schematic currently makes things available without changing the existing app, and I think it's best to preserve that. We can add something like a @crisbeto would setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jelbourn - You told me to add this in the original issue.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha, I'm apparently fickle. Today I'm on board with it being there by default, but think we should do it with a css class rather than adding a new style on the body directly. I'm fine with that being in a follow-up PR, though. |
||
const recorder = host.beginUpdate(stylesPath); | ||
recorder.insertLeft(insertion.pos, insertion.toAdd); | ||
host.commitUpdate(recorder); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# Table | ||
Creates a table component with sorting and paginator. | ||
# Table | ||
Creates a table component with sorting and paginator. | ||
|
||
Command: `ng generate material-table --collection=material-schematics` | ||
|
||
Command: `ng g @angular/material:materialTable --name table` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it be |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
<div class="mat-elevation-z8"> | ||
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements"> | ||
|
||
<table mat-table #table [dataSource]="dataSource" matSort aria-label="Elements"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't @andrewseguin already change this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. He changed the one in the component, not the one in the html file. |
||
<!-- Id Column --> | ||
<ng-container matColumnDef="id"> | ||
<mat-header-cell *matHeaderCellDef mat-sort-header>Id</mat-header-cell> | ||
<mat-cell *matCellDef="let row">{{row.id}}</mat-cell> | ||
<th mat-header-cell *matHeaderCellDef mat-sort-header>Id</th> | ||
<td mat-cell *matCellDef="let row">{{row.id}}</td> | ||
</ng-container> | ||
|
||
<!-- Name Column --> | ||
<ng-container matColumnDef="name"> | ||
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell> | ||
<mat-cell *matCellDef="let row">{{row.name}}</mat-cell> | ||
<th mat-header-cell *matHeaderCellDef mat-sort-header>Name</th> | ||
<td mat-cell *matCellDef="let row">{{row.name}}</td> | ||
</ng-container> | ||
|
||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row> | ||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row> | ||
</mat-table> | ||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr> | ||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> | ||
</table> | ||
|
||
<mat-paginator #paginator | ||
[length]="dataSource.data.length" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export const materialVersion = '^6.0.0'; | ||
export const cdkVersion = '^6.0.0'; | ||
export const angularVersion = '^6.0.0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change "Shell" to "Install"?