theming and sass

78

Upload: james-pearce

Post on 28-Jan-2015

134 views

Category:

Technology


2 download

DESCRIPTION

In introduction to using CSS3, Sass, and Compass to theme mobile (and desktop) web applications built with Sencha Touch and Ext JS 4.

TRANSCRIPT

Page 1: Theming and Sass
Page 2: Theming and Sass

James Pearce Sr Director, Developer Relations @ jamespearce [email protected]

Page 3: Theming and Sass

Theming & Sass

Page 4: Theming and Sass

It’s easy to forgetit’s all in a browser

Page 5: Theming and Sass
Page 6: Theming and Sass

CSS hopefullyneeds no introduction

Page 7: Theming and Sass

<!DOCTYPE html><html> <head> <script src="sencha-touch.js" type="text/javascript"> </script> <link href="sencha-touch.css" type="text/css" rel="stylesheet" /> ...

Page 8: Theming and Sass

div { background: #cc66ff;}

Page 9: Theming and Sass

But CSS3 really rocks

Page 10: Theming and Sass

div { background: rgba( 204, 102, 255, 0.5 );}

Page 11: Theming and Sass

div { -webkit-border-radius: 10px;}

Page 12: Theming and Sass

div { -webkit-box-shadow: 4px 4px 3px #000;}

Page 13: Theming and Sass

div { text-shadow: 1px 1px 0px #fff;}

Page 14: Theming and Sass

div { background-image: -webkit-gradient( linear, 0 0, 0 100%, from(#f77), to(#77f) );}

Page 15: Theming and Sass

@font-­‐face  {    font-­‐family:  'Consolas';    src:  url('consolas.woff');}

div  {    font-­‐family:  'Consolas';}  

Page 16: Theming and Sass

Useful tools

Page 17: Theming and Sass

http://sencha.com/x/bb

Page 18: Theming and Sass

http://westciv.com/tools/gradients/

Page 19: Theming and Sass

https://github.com/bluesmoon/pngtocss

Page 20: Theming and Sass

http://www.google.com/webfonts

Page 21: Theming and Sass

Sass and Compass

Page 22: Theming and Sass

http://sass-lang.com/

Page 23: Theming and Sass

/* SCSS */

$blue: #3bbfce;$margin: 16px;

.content-navigation { border-color: $blue; color: darken($blue, 9%);}

.border { padding: $margin / 2; margin: $margin / 2; border-color: $blue;}

/* CSS */

.content-navigation { border-color: #3bbfce; color: #2b9eab;}

.border { padding: 8px; margin: 8px; border-color: #3bbfce;}

Variables

Page 24: Theming and Sass

rgb($red, $green, $blue)lighten($color, $amount)complement($color)transparentize($color, $amount)...

ceil($value)...

if($condition, $if-true, $if-false)...

Functions

Page 25: Theming and Sass

/* SCSS */

table.hl { margin: 2em 0; td.ln { text-align: right; }}

li { font: { family: serif; weight: bold; size: 1.2em; }}

/* CSS */

table.hl { margin: 2em 0;}table.hl td.ln { text-align: right;}

li { font-family: serif; font-weight: bold; font-size: 1.2em;}

Nesting

Page 26: Theming and Sass

/* SCSS */

@mixin table-base { th { text-align: center; font-weight: bold; } td, th {padding: 2px}}

@mixin left($dist) { float: left; margin-left: $dist;}

#data { @include left(10px); @include table-base;}

/* CSS */

#data { float: left; margin-left: 10px;}#data th { text-align: center; font-weight: bold;}#data td, #data th { padding: 2px;}

Mixins

Page 27: Theming and Sass

/* SCSS */

.error { border: 1px #f00; background: #fdd;}.error.intrusion { font-size: 1.3em; font-weight: bold;}

.badError { @extend .error; border-width: 3px;}

/* CSS */

.error, .badError { border: 1px #f00; background: #fdd;}

.error.intrusion,

.badError.intrusion { font-size: 1.3em; font-weight: bold;}

.badError { border-width: 3px;}

Selector Inheritance

Page 28: Theming and Sass

http://compass-style.org/

Page 29: Theming and Sass

CSS3 Modules

AppearanceBackground Clip

Background OriginBackground Size

Border RadiusBox

Box ShadowBox SizingColumns

Font Face GradientImages

Inline BlockOpacity

Text ShadowTransformTransition

Page 30: Theming and Sass

/* SCSS */div { @include border-radius(4px, 4px);}

/* CSS */div { -webkit-border-radius: 4px 4px; -moz-border-radius: 4px / 4px; -o-border-radius: 4px / 4px; -ms-border-radius: 4px / 4px; -khtml-border-radius: 4px / 4px; border-radius: 4px / 4px;}

For example

Page 31: Theming and Sass

TypographyLinksLists

TextVertical Rhythm

UtilitiesColor

GeneralSpritesTables

...

Page 32: Theming and Sass

$> sudo gem install compass

http://rubyinstaller.org/

Page 33: Theming and Sass

$> compass -v

Compass 0.11.1 (Antares)Copyright (c) 2008-2011 Chris EppsteinReleased under the MIT License.

$> sass -v

Sass 3.1.1 (Brainy Betty)

Page 34: Theming and Sass

$> compass create .

directory sass/directory stylesheets/ create config.rb create sass/screen.scss create sass/print.scss create sass/ie.scss

Page 35: Theming and Sass

$> compass compile sass/*

Page 36: Theming and Sass

# Compass configurationssass_dir = "sass"css_dir = "stylesheets"output_style = :compressed

# or :nested :expanded :compact

config.rb

Page 37: Theming and Sass

ThemingSencha Touch

Page 38: Theming and Sass
Page 39: Theming and Sass
Page 40: Theming and Sass

# Get the directory that this# configuration file exists indir = File.dirname(__FILE__)

# Load the sencha-touch framework# automatically.load File.join(dir, '..', 'themes')

# Compass configurationssass_path = dircss_path = File.join(dir, "..", "css")environment = :productionoutput_style = :compressed

config.rb

Page 41: Theming and Sass

@import 'sencha-touch/default/all';

@include sencha-panel;@include sencha-buttons;@include sencha-sheet;@include sencha-picker;@include sencha-tabs;@include sencha-toolbar;@include sencha-toolbar-forms;@include sencha-carousel;@include sencha-indexbar;@include sencha-list;@include sencha-list-paging;@include sencha-list-pullrefresh;@include sencha-layout;@include sencha-form;@include sencha-msgbox;@include sencha-loading-spinner;

sencha-touch.scss

Page 42: Theming and Sass

@import 'sencha-touch/default/all';

@import 'widgets';

@import 'widgets/toolbar';

...@mixin sencha-toolbar { .x-toolbar { overflow: hidden; position: relative; ...

@include sencha-toolbar;...

Page 43: Theming and Sass

An easy way to optimize

Page 44: Theming and Sass

@import 'sencha-touch/default/all';

@include sencha-panel;@include sencha-buttons;@include sencha-sheet;@include sencha-picker;@include sencha-tabs;@include sencha-toolbar;@include sencha-toolbar-forms;@include sencha-carousel;@include sencha-indexbar;@include sencha-list;@include sencha-list-paging;@include sencha-list-pullrefresh;@include sencha-layout;@include sencha-form;@include sencha-msgbox;@include sencha-loading-spinner;

sencha-touch.scss

Page 45: Theming and Sass

147433

118233(-20%)

Page 46: Theming and Sass

$include-default-icons: false;

@import 'sencha-touch/default/all';

@include sencha-panel;@include sencha-buttons;@include sencha-sheet;@include sencha-picker;...

sencha-touch.scss

Page 47: Theming and Sass

147433

64017(-57%)

Page 48: Theming and Sass

$include-default-icons: false;

@import 'sencha-touch/default/all';

@include pictos-iconmask('action');

@include sencha-panel;@include sencha-buttons;@include sencha-sheet;@include sencha-picker;...

sencha-touch.scss

Page 49: Theming and Sass
Page 50: Theming and Sass

Variables

Page 51: Theming and Sass

$base-color: #7c92ae;$base-gradient: 'glossy';

$list-active-gradient: 'bevel';$list-header-bg-color: transparentize( saturate($base-color, 10%), .25);$list-header-gradient: 'matte';

$tabs-dark: #111;

@import 'sencha-touch/default/all';

@include sencha-panel;@include sencha-buttons;...

apple.scss

Page 52: Theming and Sass

_variables.scss

$include-html-style: true;

$include-default-icons: true;

$include-form-sliders: true;

$include-floating-panels: true;

$include-default-uis: true;

$include-highlights: true;

$include-border-radius: true;

$basic-slider: false;

$base-color: #354F6E;

$base-gradient: 'matte';

$alert-color: red;

$confirm-color: #92cf00;

$page-bg-color: #eee;

$global-row-height: 2.6em;

$active-color: darken( saturate($base-color, 55%), 10%);

Page 53: Theming and Sass

http://dev.sencha.com/deploy/touch/docs/theme/

Page 54: Theming and Sass

$> compass watch .

>>> Change detected to: seattlebars.scssoverwrite ./seattlebars.css

>>> Compass is watching for changes. Press Ctrl-C to Stop.

Page 55: Theming and Sass

$base-color: #99ccaa;

Page 56: Theming and Sass

@mixin color-by-background( $bg-color, $contrast: 100%) { @if (lightness($bg-color) > 50) { color: darken($bg-color, $contrast) } @else { color: lighten($bg-color, $contrast) }}

Page 57: Theming and Sass

In action

Page 58: Theming and Sass
Page 59: Theming and Sass

https://github.com/senchalearn/seattlebars

Page 60: Theming and Sass
Page 61: Theming and Sass
Page 62: Theming and Sass
Page 63: Theming and Sass

ThemingExt JS 4

Page 64: Theming and Sass

On the wayto Sass nirvana

Page 65: Theming and Sass
Page 66: Theming and Sass
Page 67: Theming and Sass

@import 'compass';@import 'ext4/default/all';

ext-all.scss

Page 68: Theming and Sass

@import 'functions';@import 'variables';@import 'mixins';

@import 'core';

@import 'layout/layout';

@import 'util/tool';@import 'util/messagebox';@import 'util/splitter';@import 'util/resizable';@import 'util/dragdrop';@import 'util/scroller';@import 'util/focus';...

_all.scss

Page 69: Theming and Sass

Variables

Page 70: Theming and Sass

...

$color: #000;$font-family: tahoma,arial,verdana,sans-serif;

$font-size : 12px !default;

$base-gradient: 'matte';$base-color : #C0D4ED;$neutral-color: #eeeeee;

...

variables/_core.scss

Page 71: Theming and Sass

$base-color: #FF8000;

$panel-header-font-size: 15px;

@import 'compass';@import 'ext4/default/all';

test.scss

Page 72: Theming and Sass
Page 73: Theming and Sass

Slicer

$> sencha slice theme -d . -c resources/css/test.css -o ./test-images

Page 74: Theming and Sass

Add these to your theme’s images directory

Page 75: Theming and Sass

Chart theming

Page 76: Theming and Sass

var chart = Ext.create( 'Ext.chart.Chart', { theme: 'Blue', ... });

// Base, Green, Sky, Red,// Purple, Blue, Yellow...// or {}

Page 77: Theming and Sass

CSS3Sass & Compass

Sencha TouchExt JS 4

Page 78: Theming and Sass

James Pearce Sr Director, Developer Relations @ jamespearce [email protected]