Skip to content

Commit

Permalink
feat: integrate typography api into all components (#4375)
Browse files Browse the repository at this point in the history
* feat: integrate typography api into all components

* Includes the base typography styles for headers, body text etc.
* Adds mixins for typography next to the theme and moves out all of the component typography styles into them.
* Switches all the hardcoded typography values to use the ones from the spec.
* Adjusts the letter spacing on some of the headers to align them to the spec.

**Note:** While going through the components, I haven't checked whether the styles are accurate in regards to the spec. I've left notes in the places where the font sizes weren't a part of the pre-defined ones.

* fix: address feedback

* fix: explicit toolbar header typography

* chore: add comments about letter spacing

* fix: theme error

* chore: re-add $mat-font-family

* fix: missing typography for mat-icon-button
  • Loading branch information
crisbeto authored and mmalerba committed May 31, 2017
1 parent 0c03946 commit e650b04
Show file tree
Hide file tree
Showing 56 changed files with 412 additions and 145 deletions.
2 changes: 2 additions & 0 deletions src/demo-app/demo-app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {StyleDemo} from './style/style-demo';
import {DataTableDemo} from './data-table/data-table-demo';
import {PeopleDatabase} from './data-table/people-database';
import {DatepickerDemo} from './datepicker/datepicker-demo';
import {TypographyDemo} from './typography/typography-demo';
import {
CdkDataTableModule,
FullscreenOverlayContainer,
Expand Down Expand Up @@ -168,6 +169,7 @@ export class DemoMaterialModule {}
RainyTabContent,
FoggyTabContent,
PlatformDemo,
TypographyDemo,
],
providers: [
{provide: OverlayContainer, useClass: FullscreenOverlayContainer},
Expand Down
7 changes: 4 additions & 3 deletions src/demo-app/demo-app/demo-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div>
<md-toolbar color="primary">
<button md-icon-button (click)="start.open()">
<md-icon class="md-24" >menu</md-icon>
<md-icon class="md-24">menu</md-icon>
</button>
<div class="demo-toolbar">
<h1>Angular Material Demos</h1>
Expand All @@ -30,9 +30,10 @@ <h1>Angular Material Demos</h1>
<button md-button (click)="toggleChangeDetection()" title="Toggle change detection">
Change detection: {{changeDetectionStrategy}}
</button>
<button md-button (click)="toggleFullscreen()" title="Toggle fullscreen">
Fullscreen
<button md-icon-button (click)="toggleFullscreen()" title="Toggle fullscreen">
<md-icon class="md-24">fullscreen</md-icon>
</button>
<button md-button (click)="dark = !dark">{{dark ? 'Light' : 'Dark'}} theme</button>
<button md-button (click)="root.dir = (root.dir == 'rtl' ? 'ltr' : 'rtl')" title="Toggle between RTL and LTR">
{{root.dir.toUpperCase()}}
</button>
Expand Down
3 changes: 2 additions & 1 deletion src/demo-app/demo-app/demo-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export class DemoApp {
{name: 'Toolbar', route: 'toolbar'},
{name: 'Tooltip', route: 'tooltip'},
{name: 'Platform', route: 'platform'},
{name: 'Style', route: 'style'}
{name: 'Style', route: 'style'},
{name: 'Typography', route: 'typography'}
];

constructor(private _element: ElementRef) {
Expand Down
2 changes: 2 additions & 0 deletions src/demo-app/demo-app/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {InputDemo} from '../input/input-demo';
import {StyleDemo} from '../style/style-demo';
import {DatepickerDemo} from '../datepicker/datepicker-demo';
import {DataTableDemo} from '../data-table/data-table-demo';
import {TypographyDemo} from '../typography/typography-demo';

export const DEMO_APP_ROUTES: Routes = [
{path: '', component: Home},
Expand Down Expand Up @@ -70,4 +71,5 @@ export const DEMO_APP_ROUTES: Routes = [
{path: 'snack-bar', component: SnackBarDemo},
{path: 'platform', component: PlatformDemo},
{path: 'style', component: StyleDemo},
{path: 'typography', component: TypographyDemo}
];
1 change: 1 addition & 0 deletions src/demo-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="theme.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">

<!-- FontAwesome for md-icon demo. -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
Expand Down
37 changes: 37 additions & 0 deletions src/demo-app/typography/typography-demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!-- via https://en.wikipedia.org/wiki/Pangram -->
<h1 class="mat-h0">How vexingly quick daft zebras jump!</h1>
<h1 class="mat-h1">Jackdaws love my big sphinx of quartz.</h1>
<h2 class="mat-h2">The five boxing wizards jump quickly.</h2>
<h3 class="mat-h3">Pack my box with five dozen liquor jugs.</h3>
<h4 class="mat-h4">Bright vixens jump; dozy fowl quack.</h4>
<h5 class="mat-h5">Sphinx of black quartz, judge my vow.</h5>
<h6 class="mat-h6">The quick brown fox jumps over the lazy dog.</h6>

<div class="mat-body">
<p>
Lucas ipsum dolor sit amet coruscant fisto hutt dantooine darth binks amidala kessel grievous
mara. Ackbar mandalore skywalker calamari. Calrissian binks tusken raider kit. Darth binks
chewbacca skywalker. Moff baba padmé antilles darth ponda twi'lek darth. Dagobah naboo mara
jawa dagobah ackbar ackbar darth. Mara mace r2-d2 mon naboo darth dantooine leia. Droid
chewbacca mace han. Wampa hutt qui-gon solo jango secura tusken raider yoda. Droid boba mon
mandalore jinn han binks. Maul darth kit wedge mace utapau darth darth fett.
</p>

<p>
Antilles antilles secura yavin. Leia luke owen hutt baba yoda hoth obi-wan. Moff thrawn solo
jango mon. Antilles lobot hutt tusken raider moff jade kessel binks. Moff ewok sidious naboo
darth ventress tusken raider. Bothan yavin moff fett organa binks jade binks. Mara moff darth
jade sidious. Darth binks obi-wan padmé dagobah hutt ponda antilles ackbar. Fett gamorrean
obi-wan sidious hutt maul. Organa darth k-3po kessel aayla. Hoth c-3po amidala biggs kenobi
twi'lek twi'lek ahsoka. Obi-wan ackbar windu wicket kit c-3po.
</p>

<p>
Hutt naboo greedo skywalker hutt luuke ben. Hutt chewbacca jabba solo calrissian jade yoda
amidala zabrak. Solo luke antilles c-3p0. Sith darth skywalker fett solo hutt skywalker c-3p0
skywalker. Skywalker skywalker solo kessel darth fett. Skywalker skywalker c-3po jango.
Alderaan darth boba calamari. Wicket alderaan darth darth chewbacca jango. Darth darth
chewbacca ponda solo grievous hutt calrissian lando. Darth mon watto vader chewbacca.
Lando mace luke yavin darth wookiee c-3po. Moff kessel skywalker yoda c-3po yavin.
</p>
</div>
3 changes: 3 additions & 0 deletions src/demo-app/typography/typography-demo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.mat-body {
max-width: 800px;
}
10 changes: 10 additions & 0 deletions src/demo-app/typography/typography-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {Component} from '@angular/core';


@Component({
moduleId: module.id,
selector: 'typography-demo',
templateUrl: 'typography-demo.html',
styleUrls: ['typography-demo.css'],
})
export class TypographyDemo { }
4 changes: 3 additions & 1 deletion src/lib/autocomplete/_autocomplete-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
}
}

}
}

@mixin mat-autocomplete-typography($config) { }
7 changes: 7 additions & 0 deletions src/lib/button-toggle/_button-toggle-theme.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import '../core/theming/palette';
@import '../core/theming/theming';
@import '../core/typography/typography-utils';

// Applies a focus style to an md-button-toggle element for each of the supported palettes.
@mixin _mat-button-toggle-focus-color($theme) {
Expand Down Expand Up @@ -36,3 +37,9 @@
}
}
}

@mixin mat-button-toggle-typography($config) {
.mat-button-toggle {
font-family: mat-font-family($config);
}
}
5 changes: 2 additions & 3 deletions src/lib/button-toggle/button-toggle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@import '../core/style/layout-common';

$mat-button-toggle-padding: 0 16px !default;
$mat-button-toggle-line-height: 36px !default;
$mat-button-toggle-height: 36px !default;
$mat-button-toggle-border-radius: 2px !default;

.mat-button-toggle-group {
Expand Down Expand Up @@ -36,7 +36,6 @@ $mat-button-toggle-border-radius: 2px !default;

.mat-button-toggle {
white-space: nowrap;
font-family: $mat-font-family;
position: relative;
}

Expand All @@ -47,7 +46,7 @@ $mat-button-toggle-border-radius: 2px !default;
.mat-button-toggle-label-content {
@include user-select(none);
display: inline-block;
line-height: $mat-button-toggle-line-height;
line-height: $mat-button-toggle-height;
padding: $mat-button-toggle-padding;
cursor: pointer;
}
Expand Down
5 changes: 0 additions & 5 deletions src/lib/button/_button-base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ $mat-mini-fab-padding: 8px !default;
white-space: nowrap;
text-decoration: none;
vertical-align: baseline;

// Typography.
font-size: $mat-body-font-size-base;
font-family: $mat-font-family;
font-weight: 500;
text-align: center;

// Sizing.
Expand Down
7 changes: 6 additions & 1 deletion src/lib/button/_button-theme.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import '../core/theming/theming';
@import '../core/typography/typography-utils';

// Applies a focus style to an md-button element for each of the supported palettes.
@mixin _mat-button-focus-color($theme) {
Expand Down Expand Up @@ -117,4 +118,8 @@
}
}


@mixin mat-button-typography($config) {
.mat-button, .mat-raised-button, .mat-icon-button {
@include mat-typography-level-to-styles($config, button);
}
}
20 changes: 20 additions & 0 deletions src/lib/card/_card-theme.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import '../core/theming/palette';
@import '../core/theming/theming';
@import '../core/typography/typography-utils';


@mixin mat-card-theme($theme) {
Expand All @@ -15,3 +16,22 @@
color: mat-color($foreground, secondary-text);
}
}

@mixin mat-card-typography($config) {
.mat-card {
font-family: mat-font-family($config);
}

.mat-card-title {
font: {
size: mat-font-size($config, headline);
weight: mat-font-weight($config, headline);
}
}

.mat-card-subtitle,
.mat-card-content,
.mat-card-header .mat-card-title {
font-size: mat-font-size($config, body-1);
}
}
19 changes: 1 addition & 18 deletions src/lib/card/card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ $mat-card-header-size: 40px !default;
position: relative;
padding: $mat-card-default-padding;
border-radius: $mat-card-border-radius;
font-family: $mat-font-family;

&:not([class*='mat-elevation-z']) {
@include mat-elevation(2);
Expand All @@ -35,20 +34,8 @@ $mat-card-header-size: 40px !default;
margin-bottom: 16px;
}

.mat-card-title {
.mat-card-title, .mat-card-subtitle, .mat-card-content {
@extend %mat-card-section-base;
font-size: 24px;
font-weight: 400;
}

.mat-card-subtitle {
@extend %mat-card-section-base;
font-size: $mat-body-font-size-base;
}

.mat-card-content {
@extend %mat-card-section-base;
font-size: $mat-body-font-size-base;
}

.mat-card-actions {
Expand Down Expand Up @@ -106,10 +93,6 @@ $mat-card-header-size: 40px !default;
flex-shrink: 0;
}

.mat-card-header .mat-card-title {
font-size: $mat-body-font-size-base;
}

// TITLE-GROUP STYLES

// images grouped with title in title-group layout
Expand Down
12 changes: 12 additions & 0 deletions src/lib/checkbox/_checkbox-theme.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import '../core/theming/theming';
@import '../core/typography/typography-utils';


@mixin mat-checkbox-theme($theme) {
Expand Down Expand Up @@ -83,3 +84,14 @@
}
}
}

@mixin mat-checkbox-typography($config) {
.mat-checkbox {
font-family: mat-font-family($config);
}

// TODO(kara): Remove this style when fixing vertical baseline
.mat-checkbox-layout .mat-checkbox-label {
line-height: mat-line-height($config, body-2);
}
}
7 changes: 0 additions & 7 deletions src/lib/checkbox/checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
}

.mat-checkbox {
font-family: $mat-font-family;

// Animation
transition: background $swift-ease-out-duration $swift-ease-out-timing-function,
mat-elevation-transition-property-value();
Expand Down Expand Up @@ -233,11 +231,6 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
}
}

// TODO(kara): Remove this style when fixing vertical baseline
.mat-checkbox-layout .mat-checkbox-label {
line-height: 24px;
}

.mat-checkbox-frame {
@extend %mat-checkbox-outer-box;

Expand Down
13 changes: 13 additions & 0 deletions src/lib/chips/_chips-theme.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
@import '../core/theming/palette';
@import '../core/theming/theming';
@import '../core/typography/typography-utils';

// TODO(crisbeto): these values don't correspond to any of the typography breakpoints.
$mat-chip-font-size: 13px;
$mat-chip-line-height: 16px;


@mixin mat-chips-theme($theme) {
$is-dark-theme: map-get($theme, is-dark);
Expand Down Expand Up @@ -47,3 +53,10 @@
}
}
}

@mixin mat-chips-typography($config) {

This comment has been minimized.

Copy link
@e-cloud

e-cloud Jun 20, 2017

Contributor

the config param is useless, shouldn't use the font size inside config?

.mat-chip:not(.mat-basic-chip) {
font-size: $mat-chip-font-size;
line-height: $mat-chip-line-height;
}
}
5 changes: 0 additions & 5 deletions src/lib/chips/chips.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
$mat-chip-vertical-padding: 8px;
$mat-chip-horizontal-padding: 12px;
$mat-chip-font-size: 13px;
$mat-chip-line-height: 16px;

$mat-chips-chip-margin: $mat-chip-horizontal-padding / 4;

Expand All @@ -17,9 +15,6 @@ $mat-chips-chip-margin: $mat-chip-horizontal-padding / 4;
padding: $mat-chip-vertical-padding $mat-chip-horizontal-padding $mat-chip-vertical-padding $mat-chip-horizontal-padding;
border-radius: $mat-chip-horizontal-padding * 2;

font-size: $mat-chip-font-size;
line-height: $mat-chip-line-height;

// Apply a margin to adjacent sibling chips.
& + & {
margin: 0 0 0 $mat-chips-chip-margin;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/core/_core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@import 'option/option';
@import 'option/option-theme';
@import 'selection/pseudo-checkbox/pseudo-checkbox-theme';
@import 'typography/all-typography';

// Mixin that renders all of the core styles that are not theme-dependent.
@mixin mat-core() {
Expand All @@ -18,6 +19,7 @@
}
}

@include angular-material-typography();
@include mat-ripple();
@include mat-option();
@include cdk-a11y();
Expand Down
10 changes: 10 additions & 0 deletions src/lib/core/option/_option-theme.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import '../theming/palette';
@import '../theming/theming';
@import '../typography/typography-utils';

@mixin mat-option-theme($theme) {
$foreground: map-get($theme, foreground);
Expand Down Expand Up @@ -42,3 +43,12 @@
}
}
}

@mixin mat-option-typography($config) {
.mat-option {
font: {
family: mat-font-family($config);
size: mat-font-size($config, subheading);
}
}
}
Loading

0 comments on commit e650b04

Please sign in to comment.