Thomas Burleson PRO
FE Architect, Technical Lead, and Engineering Coach. Delivering web solutions using React, NextJS, Angular, and TypeScript.
Presented by:
Thomas Burleson
@ThomasBurleson
http://linkedin.com/in/ThomasBurleson
ThomasBurleson@gmail.com
Team Lead, AngularJS Material
~3400 Forks
~15.5K Stars
~1K Watches
Thanks to Brad Green, Naomi Black, and Google.
Angular-Master-Class Trainer + Angular Consultant
40+ articles on blog.thoughtram.io
v2.0.0-beta.8
~1K Stars
Before What...
sample layout
Box model optimized for user interfaces
How to Think about FlexBox ?
Flows = horizontal or vertical
Sizes = fixed or ratios
FlexBox === Containers + Children
FlexBox Layout Flows ?
FlexBox Layout Flows !
... start outside containers to inside.
FlexBox Layout Flows !
FlexBox Layout Flows !
FlexBox Layout Flows !
FlexBox Layout Flows !
... consider flows as outside - in
FlexBox Child Sizes
retrospective
Using HTML Tables
Using FlexBox CSS
Using FlexBox CSS
Using AngularJS Material
Layout CSS
Using AngularJS Material
Layout CSS
www.github.com/angular/flex-layout
Using
Angular Flex-Layout
Browser Support
http://caniuse.com/#feat=flexbox
npm install --save @angular/flex-layout@latest
import { FlexLayoutModule }
from '@angular/flex-layout';
...
@NgModule({
imports: [FlexLayoutModule],
...
})
export class AppModule { }
Import Angular Flex-Layout NgModule
Install Angular Flex-Layout components
v2.0.0-beta.14
@angular/flex-layout
Static API
fxLayout |
|
---|---|
fxLayoutWrap |
|
fxLayoutGap |
|
fxLayoutAlign |
<div fxLayout="row"
fxLayout.xs="column"> </div>
<div fxLayoutWrap> </div>
<div fxLayoutGap="10px"> </div>
<div fxLayoutAlign="start stretch">
</div>
@angular/flex-layout
Static API
@angular/flex-layout
Static API
fxFlex |
|
---|---|
fxFlexOrder |
|
fxFlexOffset |
|
fxFlexAlign |
|
fxFlexFill |
<div fxFlex="1 2
calc(15em + 20px)"></div>
<div fxFlexOrder="2"></div>
<div fxFlexOffset="20px"></div>
<div fxFlexAlign="center"></div>
<div fxFlexFill></div>
+
Source
@angular/flex-layout
Static API
What do modern web apps need?
Containers & elements adjust sizes & positions based on changes in window sizes
Containers & elements adapt sizes & positions based on device display sizes
UX adapts to device viewports.
Assertions for
Desktop Layout
Mobile Layout
Sample
"You don't just make a Responsive UX !
You will need..."
Flexbox CSS + MediaQuery
Sample
" Please tell me there is a better way! "
@angular/flex-layout
@angular/flex-layout
Published industry specs for ranges of viewport sizes. The transition between ranges are a known as BreakPoints.
Breakpoint Alias | mediaQuery |
---|
xs | 'screen and (max-width: 599px)' |
---|---|
sm | 'screen and (min-width: 600px) and (max-width: 959px)' |
md | 'screen and (min-width: 960px) and (max-width: 1279px)' |
lg | 'screen and (min-width: 1280px) and (max-width: 1919px)' |
xl | 'screen and (min-width: 1920px) and (max-width: 5000px)' |
Breakpoint Alias | mediaQuery |
---|
lt-sm | 'screen and (max-width: 599px)' |
---|---|
lt-md | 'screen and (max-width: 959px)' |
lt-lg | 'screen and (max-width: 1279px)' |
lt-xl | 'screen and (max-width: 1919px)' |
xs | 'screen and (max-width: 599px)' |
---|---|
sm | 'screen and (min-width: 600px) and (max-width: 959px)' |
md | 'screen and (min-width: 960px) and (max-width: 1279px)' |
lg | 'screen and (min-width: 1280px) and (max-width: 1919px)' |
xl | 'screen and (min-width: 1920px) and (max-width: 5000px)' |
Breakpoint Alias | mediaQuery |
---|
lt-sm | 'screen and (max-width: 599px)' |
---|---|
lt-md | 'screen and (max-width: 959px)' |
lt-lg | 'screen and (max-width: 1279px)' |
lt-xl | 'screen and (max-width: 1919px)' |
gt-xs | 'screen and (min-width: 600px)' |
---|---|
gt-sm | 'screen and (min-width: 960px)' |
gt-md | 'screen and (min-width: 1280px)' |
gt-lg | 'screen and (min-width: 1920px)' |
xs | 'screen and (max-width: 599px)' |
---|---|
sm | 'screen and (min-width: 600px) and (max-width: 959px)' |
md | 'screen and (min-width: 960px) and (max-width: 1279px)' |
lg | 'screen and (min-width: 1280px) and (max-width: 1919px)' |
xl | 'screen and (min-width: 1920px) and (max-width: 5000px)' |
Using MediaQuery + Alias, we can easily create Adaptive UX Layout ....
@angular/flex-layout
Responsive HTML API
with the
@angular/flex-layout
Simply append the mediaQuery alias to the API:
fxLayout.sm = "..."
fxLayoutAlign.md = "..."
fxHide.gt-sm = "..."
Called a Declarative API since this is used in the HTML
To build this desktop Adaptive Layout:
1
<div>
<header>header</header>
<div>
<nav>nav</nav>
<article>article</article>
<aside>aside</aside>
</div>
<footer>footer</footer>
</div>
We start with boring HTML:
2
<div fxLayout="column" >
<header>header</header>
<div fxLayout="row" fxFlex >
<nav fxFlex="1 6 20%" >nav</nav>
<article fxFlex="3 1 60%" >article</article>
<aside fxFlex="1 6 20%" >aside</aside>
</div>
<footer>footer</footer>
</div>
Spice it up with
Flex-Layout, Declarative Static API
3
To get this mobile adaptive layout:
4
<div fxLayout="column">
<header>header</header>
<div fxLayout="row" fxLayout.xs="column" fxFlex>
<nav fxFlex="1 6 20%" fxFlexOrder
fxFlexOrder.xs="2" >nav</nav>
<article fxFlex="3 1 60%" fxFlexOrder
fxFlexOrder.xs="1" >article</article>
<aside fxFlex="1 6 20%" fxFlexOrder
fxFlexOrder.xs="3" >aside</aside>
</div>
<footer>footer</footer>
</div>
created by Katerine Orlova
Make it sizzle with Flex-Layout Responsive API
5
@angular/flex-layout
@angular/flex-layout
Responsive HTML API
@angular/flex-layout
bit.ly/angular-flex-layout
<div fxShow fxHide.xs="false" fxHide.lg="true"></div>
<div fxFlex="50%" fxFlex.gt-sm="100%"></div>
fxShow |
|
---|---|
fxHide |
|
ngClass |
|
ngStyle |
<div fxShow
[fxShow.xs]="isVisibleOnMobile()"></div>
<div fxHide
[fxHide.gt-sm]="isVisibleOnDesktop()"></div>
<div
[ngClass.sm]="{'fxClass-sm': hasStyle}"></div>
<div
[ngStyle.xs]="{color: 'blue'}"></div>
ObservableMedia |
|
---|---|
BREAKPOINTS |
|
BaseFxDirectiveAdapter |
constructor(public
media:ObservableMedia ) {}
providers: [{provide: BREAKPOINTS,
useValue: MY_CUSTOM_BREAKPOINTS }]
export class ClassDirective
extends NgClass {}
import {Subscription} from "rxjs/Subscription";
import {MediaChange, ObservableMedia} from "@angular/flex-layout";
constructor(media: ObservableMedia) {
this.watcher = media.subscribe( (change: MediaChange) => {
if ( change.mqAlias == 'xs') {
this.loadMobileContent();
}
});
}
github.com/
twitter.com/
http://bit.ly/thoughtram_houston
Go to:
Note: the 3-day training may not include all these topics. Additional days may be required.
By Thomas Burleson
Use @angular/flex-layout to easily create responsive, adaptive Angular applications... without having to be a Flexbox CSS expert.
FE Architect, Technical Lead, and Engineering Coach. Delivering web solutions using React, NextJS, Angular, and TypeScript.