Css3 and gwt in perfect harmony

114
CSS3 and GWT in perfect harmony GWT.create 2015 JULIEN DRAMAIX

Transcript of Css3 and gwt in perfect harmony

Page 1: Css3 and gwt in perfect harmony

CSS3 and GWT in perfect harmony

GWT.create 2015

JULIEN DRAMAIX

Page 2: Css3 and gwt in perfect harmony

Julien DramaixSoftware Engineer

at Arcbees

+JulienDramaix@jDramaix

Page 3: Css3 and gwt in perfect harmony

What is this about?

Page 4: Css3 and gwt in perfect harmony

New syntax for CssResource based on GSS

What is this about ?

Page 5: Css3 and gwt in perfect harmony

Why?

Page 6: Css3 and gwt in perfect harmony

DRY principle is missing with CSS.

Why ?

Page 7: Css3 and gwt in perfect harmony

Missing CSS3 support.

Why ?

Page 8: Css3 and gwt in perfect harmony

What is Closure-stylesheets?

Page 9: Css3 and gwt in perfect harmony

What is Closure-stylesheets?

It’s an extension to CSS

Page 10: Css3 and gwt in perfect harmony

What is Closure-stylesheets?

Write gss and compile to CSS

It’s an extension to CSS

Page 11: Css3 and gwt in perfect harmony

Support variables, conditionals, mixing...

What is Closure-stylesheets?

Page 12: Css3 and gwt in perfect harmony

Support minification, linting, RTL flipping, renaming

What is Closure-stylesheets?

Page 13: Css3 and gwt in perfect harmony

Full CSS3 support!

What is Closure-stylesheets?

Page 14: Css3 and gwt in perfect harmony

Open Source project written and maintained by Google!

What is Closure-stylesheets?

Page 15: Css3 and gwt in perfect harmony

Example:

@def BG_COLOR rgb(235, 239, 249);

@defmixin size(WIDTH, HEIGHT) { width: WIDTH; height: HEIGHT;}

body { background-color: BG_COLOR;}

.logo { @mixin size(150px, 55px); background-image: url('http://www.google.com/images/logo_sm.gif');}

Page 16: Css3 and gwt in perfect harmony

Compile to:

body { background-color: #ebeff9;}

.logo { width: 150px; height: 55px; background-image: url('http://www.google.com/images/logo_sm.gif');}

Page 17: Css3 and gwt in perfect harmony

How to use it?

Page 18: Css3 and gwt in perfect harmony

1. Create a GSS file.

How to use it ?

Page 19: Css3 and gwt in perfect harmony

myFirstGss.gss:

@def BG_COLOR rgb(235, 239, 249);

@defmixin size(WIDTH, HEIGHT) { width: WIDTH; height: HEIGHT;}

body { background-color: BG_COLOR;}

.logo { @mixin size(150px, 55px); background-image: url('http://www.google.com/images/logo_sm.gif');}

Page 20: Css3 and gwt in perfect harmony

2. Create your CssResource interface as usual.

How to use it ?

Page 21: Css3 and gwt in perfect harmony

public interface MyFirstGss extends CssResource { String foo();}

public interface Resources extends ClientBundle { MyFirstGss myFirstGss();}

Page 22: Css3 and gwt in perfect harmony

public interface MyFirstGss extends CssResource { String foo();}

public interface Resources extends ClientBundle { @Source("myFirstGss.gss") MyFirstGss css();}

Page 23: Css3 and gwt in perfect harmony

3. Enable GSS in your GWT module file.

How to use it ?

Page 24: Css3 and gwt in perfect harmony

<set-configuration-property name="CssResource.enableGss" value="true"/>

Page 25: Css3 and gwt in perfect harmony

4. For UiBinder, use the attribute GSS in your inline style.

How to use it ?

Page 26: Css3 and gwt in perfect harmony

<ui:style gss="true">/* Constants*/@def PADDING_RIGHT 50px;@def PADDING_LEFT 50px;

/*mixin */@defmixin size(WIDTH, HEIGHT) { width: WIDTH; height: HEIGHT;}/* … */

</ui:style>

Page 27: Css3 and gwt in perfect harmony

GSS will be the default syntax in GWT 2.8.

How to use it ?

Page 28: Css3 and gwt in perfect harmony

Features and syntax.

Page 29: Css3 and gwt in perfect harmony

Constants.

Features and syntax

Page 30: Css3 and gwt in perfect harmony

@def BG_COLOR rgb(235, 239, 249);@def PADDING_RIGHT 15px;@def CONTAINER_COLOR BG_COLOR;

Page 31: Css3 and gwt in perfect harmony

@def BG_COLOR rgb(235, 239, 249);@def PADDING_RIGHT 15px;@def CONTAINER_COLOR BG_COLOR;

Constant name in UPPERCASE !

Page 32: Css3 and gwt in perfect harmony

Runtime evaluation.

Features and syntax

Page 33: Css3 and gwt in perfect harmony

@def BLUE eval("com.foo.bar.client.resource.Colors.BLUE");

.red { color: eval("com.foo.bar.client.resource.Colors.RED");}

Page 34: Css3 and gwt in perfect harmony

@def BLUE eval("com.foo.bar.client.resource.Colors.BLUE");

.red { color: eval("com.foo.bar.client.resource.Colors.RED");}

Any valid Java expression

Page 35: Css3 and gwt in perfect harmony

Functions.

Features and syntax

Page 36: Css3 and gwt in perfect harmony

.content { position: absolute; margin-left: add(LEFT_PADDING, /* padding left */ LEFT_HAND_NAV_WIDTH, RIGHT_PADDING); /* padding right */}

Page 37: Css3 and gwt in perfect harmony

➔ add()➔ sub()➔ mult()➔ divide()➔ min()➔ max()

FUNCTIONS

Built-in arithmetic functions

Page 38: Css3 and gwt in perfect harmony

➔ blendColorsHsb(startColor, endColor)➔ blendColorsRgb(startColor, endColor)➔ makeMutedColor(backgroundColor,

foregroundColor [, saturationLoss])➔ addHsbToCssColor(baseColor, hueToAdd,

saturationToAdd, brightnessToAdd)➔ makeContrastingColor(color,

similarityIndex)➔ adjustBrightness(color, brightness)

FUNCTIONS

Built-in color manipulation function

Page 39: Css3 and gwt in perfect harmony

FUNCTIONS

You can define your own function...

Page 40: Css3 and gwt in perfect harmony

FUNCTIONS

… or not.

Page 41: Css3 and gwt in perfect harmony

FUNCTIONS

… or not.

Should be available in GWT 2.8

Stay tuned!

Page 42: Css3 and gwt in perfect harmony

Mixins.

Features and syntax

Page 43: Css3 and gwt in perfect harmony

@defmixin size(WIDTH, HEIGHT) { width: WIDTH; height: HEIGHT;}

.container { @mixin size(550px, 500px);}

Page 44: Css3 and gwt in perfect harmony

Compile to:

.container { width: 550px; height: 500px;}

Page 45: Css3 and gwt in perfect harmony

@defmixin borderradius(TOP_RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT, TOP_LEFT) { -webkit-border-top-right-radius: TOP_RIGHT; -webkit-border-bottom-right-radius: BOTTOM_RIGHT; -webkit-border-bottom-left-radius: BOTTOM_LEFT; -webkit-border-top-left-radius: TOP_LEFT; -moz-border-radius-topright: TOP_RIGHT; -moz-border-radius-bottomright: BOTTOM_RIGHT; -moz-border-radius-bottomleft: BOTTOM_LEFT; -moz-border-radius-topleft: TOP_LEFT; border-top-right-radius: TOP_RIGHT; border-bottom-right-radius: BOTTOM_RIGHT; border-bottom-left-radius: BOTTOM_LEFT; border-top-left-radius: TOP_LEFT;

}

.foo { @mixin borderradius(5px, 0, 5px, 0)}

Page 47: Css3 and gwt in perfect harmony

Css animations done with GSSS:visit http://www.arcbees.com

Page 48: Css3 and gwt in perfect harmony

Conditional CSS.

Features and syntax

Page 49: Css3 and gwt in perfect harmony

CONDITIONAL CSS

Compile time conditional versus Runtime conditional.

Page 50: Css3 and gwt in perfect harmony

CONDITIONAL CSS

Conditional evaluated at compile time.

Page 51: Css3 and gwt in perfect harmony

CONDITIONAL CSS

Conditional evaluated at compile time.

Based on permutations or properties you define in your module file.

Page 52: Css3 and gwt in perfect harmony

@if (is("ie8") || is("ie9") && !is("locale", "en")) { .foo{ /* … */ }}@elseif (is("safari")) { .foo{ /* … */ }}@elseif is("customProperty", "customValue") { .foo{ /* … */ }} @else { .foo{ /* … */ }}

Page 53: Css3 and gwt in perfect harmony

CONDITIONAL CSS

Special case: single boolean value configuration property defined in uppercase.

Page 54: Css3 and gwt in perfect harmony

<define-configuration-property name="USE_EXTERNAL" is-multi-valued="false"/><set-configuration-property name="USE_EXTERNAL" value="false" />

Page 55: Css3 and gwt in perfect harmony

@if (USE_EXTERNAL) { @external '*';}

Page 56: Css3 and gwt in perfect harmony

CONDITIONAL CSS

Conditional evaluated at runtime.

Page 57: Css3 and gwt in perfect harmony

@if (eval("com.foo.Bar.FOO")) { /* ... */}@elseif (eval('com.foo.Bar.foo("foo")')) { /* ... */}

Page 58: Css3 and gwt in perfect harmony

@if (eval("com.foo.Bar.FOO")) { /* ... */}@elseif (eval('com.foo.Bar.foo("foo")')) { /* ... */}

Any valid Java expression returning a boolean.

Page 59: Css3 and gwt in perfect harmony

CONDITIONAL CSS

Differences between runtime and compile-time conditionals.

Page 60: Css3 and gwt in perfect harmony

This is valid

@if (is("ie8") || is("ie9")) { @def PADDING 15px;}@else { @def PADDING 0;}

Page 61: Css3 and gwt in perfect harmony

This is not

@if (eval("com.foo.Bar.useLargePadding()")) { @def PADDING 15px;}@else { @def PADDING 0;}

Page 62: Css3 and gwt in perfect harmony

This is valid

@if (USE_EXTERNAL) { @external '*';}

Page 63: Css3 and gwt in perfect harmony

This is not

@if (eval("com.foo.Bar.useExternal()")) { @external '*';'}

Page 64: Css3 and gwt in perfect harmony

CONDITIONAL CSS

Runtime conditionals can only contain CSS rules.

Page 65: Css3 and gwt in perfect harmony

Resources Url

Features and syntax

Page 66: Css3 and gwt in perfect harmony

public interface Resources extends ClientBundle { ImageResource iconPrintWhite();

ImageResource logout();

DataResource iconsEot();

// ...}

Page 67: Css3 and gwt in perfect harmony

@def ICONS_EOT resourceUrl("iconsEot");@def ICON_PRINT_WHITE resourceUrl("iconPrintWhite");

@font-face { font-family: 'icons'; src: ICONS_EOT; /* ... */}

.print { background-image: ICON_PRINT_WHITE;}

.logout { background-image: resourceUrl("logout");}

Page 68: Css3 and gwt in perfect harmony

/*@altenate*/

Features and syntax

Page 69: Css3 and gwt in perfect harmony

.logo { width: 150px; height: 55px; border-color: #DCDCDC; border-color: rgba(0, 0, 0, 0.1);}

Page 70: Css3 and gwt in perfect harmony

.logo { width: 150px; height: 55px; border-color: #DCDCDC; border-color: rgba(0, 0, 0, 0.1);}

Page 71: Css3 and gwt in perfect harmony

.logo { width: 150px; height: 55px; border-color: #DCDCDC; /* @alternate */ border-color: rgba(0, 0, 0, 0.1);}

Page 72: Css3 and gwt in perfect harmony

Disable RTL Flipping.

Features and syntax

Page 73: Css3 and gwt in perfect harmony

RTL:

.logo { margin-right: 10px; border-left: 2px solid #ccc;

padding: 0 4px 0 2px;}

Page 74: Css3 and gwt in perfect harmony

LTR:

.logo { margin-left: 10px; border-right: 2px solid #ccc;

padding: 0 2px 0 4px;}

Page 75: Css3 and gwt in perfect harmony

.logo { /* @noflip */ margin-right: 10px; border-left: 2px solid #ccc;

padding: 0 4px 0 2px;}

Page 76: Css3 and gwt in perfect harmony

Sprite support.

Features and syntax

Page 77: Css3 and gwt in perfect harmony

.logout { gwt-sprite: "iconLogin"; display: block; cursor: pointer;}

Page 78: Css3 and gwt in perfect harmony

External classes

Features and syntax

Page 79: Css3 and gwt in perfect harmony

@external myLegacyClass 'gwt-*'

Page 80: Css3 and gwt in perfect harmony

➔ Don’t use ‘.’ in front of your classes➔ Use quotes if you use the star suffix

@external myLegacyClass 'gwt-*'

Page 81: Css3 and gwt in perfect harmony

How to migrate

Page 82: Css3 and gwt in perfect harmony

The converter: Css2Gss.java

How to migrate

Page 83: Css3 and gwt in perfect harmony

Usage :java com.google.gwt.resources.converter.Css2Gss [Options] [file or directory]

Options:➔ -r > Recursively convert all css files on the given

directory(leaves .css files in place)

➔ -condition list_of_condition > Specify a comma-separated list of variables that are used in conditionals and that will be mapped to configuration properties. The converter will not use the is() function when it will convert these conditions

➔ -scope list_of_files > Specify a comma-separated list of css files to be used in this conversion to determine all defined variables

Page 84: Css3 and gwt in perfect harmony

THE CONVERTER

Single file conversion.

Page 85: Css3 and gwt in perfect harmony

$ CONVERTER_CLASS_PATH="/path/to/gwt-user.jar:/path/to/gwt-dev.jar"

$ java -cp $CONVERTER_CLASS_PATH \ com.google.gwt.resources.converter.Css2Gss /path/to/cssFileToconvert.css

Page 86: Css3 and gwt in perfect harmony

THE CONVERTER

Batch conversion.

Page 87: Css3 and gwt in perfect harmony

$ CONVERTER_CLASS_PATH="/path/to/gwt-user.jar:/path/to/gwt-dev.jar"

$ java -cp $CONVERTER_CLASS_PATH \ com.google.gwt.resources.converter.Css2Gss -r /path/to/project

Page 88: Css3 and gwt in perfect harmony

THE CONVERTER

Converter Web Application:http://css2gss.appspot.com

Page 89: Css3 and gwt in perfect harmony

Support of legacy?

How to migrate

Page 90: Css3 and gwt in perfect harmony

<set-configuration-property name="CssResource.conversionMode" value="strict"/>

Page 91: Css3 and gwt in perfect harmony

SUPPORT OF LEGACY

Two conversion modes: strict or lenient

Page 92: Css3 and gwt in perfect harmony

SUPPORT OF LEGACY

Two conversion mode: strict or lenient=> Use strict only

Page 93: Css3 and gwt in perfect harmony

Migration path.

How to migrate

Page 94: Css3 and gwt in perfect harmony

MIGRATION PATH

➔ Enable GSS and the auto-conversion in strict mode.

➔ Fix issues.➔ Use the converter

and convert all your css files➔ Set back auto-conversion to off.

Page 95: Css3 and gwt in perfect harmony

Configuration

Page 96: Css3 and gwt in perfect harmony

CssResource.obfuscationPrefix

CONFIGURATION

Page 97: Css3 and gwt in perfect harmony

<define-configuration-property name="CssResource.obfuscationPrefix" is-multi-valued="false" /><set-configuration-property name="CssResource.obfuscationPrefix" value="default" />

Page 98: Css3 and gwt in perfect harmony

CssResource.obfuscationPrefix

Disable the obfuscation prefix if your page contains only one GWT application.

Page 99: Css3 and gwt in perfect harmony

<set-configuration-property name="CssResource.obfuscationPrefix" value="empty" />

Page 100: Css3 and gwt in perfect harmony

CssResource.allowedAtRules

CONFIGURATION

Page 101: Css3 and gwt in perfect harmony

<!-- A multi-valued configuration property that defines the list of allowed non standard --><!-- at-rules in the css files -->

<define-configuration-property name="CssResource.allowedAtRules" is-multi-valued="true" />

Page 102: Css3 and gwt in perfect harmony

<!-- A multi-valued configuration property that defines the list of allowed non standard --><!-- at-rules in the css files →

<define-configuration-property name="CssResource.allowedAtRules" is-multi-valued="true" /><extend-configuration-property name="CssResource.allowedAtRules" value="-moz-document" /><extend-configuration-property name="CssResource.allowedAtRules" value="supports" />

Page 103: Css3 and gwt in perfect harmony

CssResource.allowedFunctions

CONFIGURATION

Page 104: Css3 and gwt in perfect harmony

<!-- A multi-valued configuration property that defines the list of allowed non standard --><!-- functions in the css files →

<define-configuration-property name="CssResource.allowedFunctions" is-multi-valued="true" />

Page 105: Css3 and gwt in perfect harmony

<extend-configuration-property name="CssResource.allowedFunctions" value="-webkit-sin" /><extend-configuration-property name="CssResource.allowedFunctions" value="-webkit-cos" />

Page 106: Css3 and gwt in perfect harmony

Roadmap

Page 107: Css3 and gwt in perfect harmony

GWT 2.7: GSS flagged as experimental and disabled by default

ROADMAP

Page 108: Css3 and gwt in perfect harmony

GWT 2.8: Enable by default. Old syntax deprecated.

ROADMAP

Page 109: Css3 and gwt in perfect harmony

GWT 3.0: Remove the support for the old syntax and the auto converter.

ROADMAP

Page 110: Css3 and gwt in perfect harmony

Don't wait! It's time to migrate to GSS!!

ROADMAP

Page 111: Css3 and gwt in perfect harmony

Most of the Google GWT application have migrated to GSS with success!

ROADMAP

Page 112: Css3 and gwt in perfect harmony

THANK YOU

Page 113: Css3 and gwt in perfect harmony

Julien DramaixSoftware Engineer

at Arcbees

+JulienDramaix@jDramaix

Page 114: Css3 and gwt in perfect harmony

QUESTIONS ?