X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/2e847cf21b8ab9d15fa167b315ca5b2fa92638fc..7a654f8d43fdb43d78b63d90528bed6e86b608cc:/docs/guide/theming.html diff --git a/docs/guide/theming.html b/docs/guide/theming.html new file mode 100644 index 00000000..2a0450fb --- /dev/null +++ b/docs/guide/theming.html @@ -0,0 +1,252 @@ +Sencha Documentation Project +
For up to date documentation and features, visit +http://docs.sencha.com/ext-js/4-0

Sencha Documentation

+ + + + + +

Custom ExtJS 4 Theme

+ +

ExtJS 4 has a brand new theming system to customize the look of you application whicn still supporting all browsers.

+ +

A Brief Introdocution to SASS & Compass

+ +

+ +

SASS is a pre-processor which adds new syntax to CSS allowing for things like variables, mixins, nesting, and math/color functions. For example, in SASS we can write:

+ +
$blue: #3bbfce;
+$margin: 16px;
+
+.content-navigation {
+    border-color: $blue;
+    color: darken($blue, 9%);
+}
+
+.border {
+    padding: $margin / 2;
+    margin: $margin / 2;
+    border-color: $blue;
+}
+ +

And it will compile to:

+ +
.content-navigation {
+    border-color: #3bbfce;
+    color: #2b9eab;
+}
+
+.border {
+    padding: 8px;
+    margin: 8px;
+    border-color: #3bbfce;
+}
+ +

To see the wide variety of other features available in SASS, please see http://sass-lang.com/. Compass extends SASS by adding a variety of CSS3 mixins and providing the extension system that Sencha Touch leverages. With Compass, one can include rules like:

+ +
$boxheight: 10em;
+
+.mybox {
+    @include border-radius($boxheight/4);
+}
+ +

Which compiles into:

+ +
.mybox {
+    -webkit-border-radius: 2.5em;
+    -moz-border-radius: 2.5em;
+    -o-border-radius: 2.5em;
+    -ms-border-radius: 2.5em;
+    -khtml-border-radius: 2.5em;
+    border-radius: 2.5em;
+}
+ +

You can learn more about the pre-included mixins with Compass and the other tools which it provides here: http://compass-style.org/docs/.

+ +

Requirements

+ +
  • Ruby

    Mac OSX

    > XCode installs Ruby and all nessecary dependancies onto your Mac when installed.

    Xcode can be found on the Apple Developer Website: http://developer.apple.com/xcode/

    ### Windows

    Visit http://rubyinstaller.org/ and download the latest packaged version of Ruby (1.9.2 at the time of writing this)

  • Compass/SASS gem

    Mac OSX

    > In /Applications/Utilities/Terminal.app, run the following code (you will be asked for your password):

    sudo gem install compass

    > ExtJS 4 takes advantages of the funcality in beta versions of Compass and SASS, so you must install them after running the above command:

    sudo gem install compass

    > You can verify you have Compass and Sass installed by running the following in Terminal.app:

    compass -v

    > sass -v

    At the time of writing this, the latest version of Compass is 0.11.0 (Antares). The latest version of Sass is 3.1.0.alpha.256

    ### Windows

    Select Start Command Prompt with Ruby from the new Start Menu option.

    > Type the following:

    gem install compass

    > ExtJS 4 takes advantages of the funcality in beta versions of Compass and SASS, so you must install them after running the above command:

    gem install compass

    > You can verify you have Compass and Sass installed by running the following in Terminal.app:

    compass -v

    > sass -v

    At the time of writing this, the latest version of Compass is 0.11.beta.7. The latest version of Sass is 3.1.0.alpha.256

+ +

Directory Structure

+ +

The ExtJS SDK comes with a template which can be used as a base for your new theme. You can find this in the /resources/themes/templates folder.

+ +

Everything in the included resources directory should be moved into your applications root folder:

+ +
/
+/resources/
+/resources/css/
+/resources/sass/
+/resources/sass/config.rb
+/resources/images/
+ +

You also must ensure the ExtJS SDK is in the correct location:

+ +
/lib/extjs
+/lib/extjs/ext-all.js
+/lib/extjs/resources/
+/lib/extjs/...
+ +

If for some reason the ExtJS SDK is located elsewhere, you must also change the path in resources/sass/config.rb:

+ +
# $ext_path: This should be the path of where the ExtJS SDK is installed
+# Generally this will be in a lib/extjs folder in your applications root
+# /lib/extjs
+$ext_path = "../../lib/extjs"
+ +

Compiling your CSS

+ +

Compiling your CSS is a very simple process using Compass.

+ +

From applications root directory, run the following command in Terminal.app on Mac OSX or Command Prompt on Windows:

+ +

compass compile resources/sass

+ +

This should output the following:

+ +

create resources/sass/../css/my-ext-theme.css

+ +

That is your CSS compiled! You can now view it in the resources/css folder.

+ +

You can also setup Compass to watch your SASS directory and compile the CSS when you make a change:

+ +

compass watch resources/sass

+ +

Changing global ExtJS variables

+ +

The ExtJS theming system comes with a few basic global SASS variables which you can use to change the whole look of your application with just a few lines of code.

+ +

Where

+ +

These SASS variables can be added in your .scss file, but they must be inserted before the call to @import the ExtJS4 framework is called. You can see an example of this in the my-ext-theme.scss file, in the templates/resources/sass folder:

+ +
// Unless you want to include all components, you must set $include-default to false
+// IF you set this to true, you can also remove lines 10 to 38 of this file
+$include-default: false;
+
+// Insert your custom variables here.
+$base-color: #aa0000;
+
+@import 'ext4/default/all';
+ +

In this case, both $include-default and $base-color are being changed - and then the ExtJS4 theming files are being imported.

+ +

Available Variables

+ +

Unfortunately at this time there is not a complete list of all available variables in the theme, however you can easily find variables that are available by navigating to the resources/themes/stylesheets/ext4/default/variables directory. This directory contains all defined variables for each component in ExtJS4.

+ +

The naming convention for variables follows CSS property names, prepends by the component name. For example:

+ +
  • Panel border radius

    CSS Property: border-radius

    Variable: $panel-border-radius

  • Panel body background color

    CSS Property: background-color

    Variable: $panel-body-background-color

  • Toolbar background color

    CSS Property: background-color

    Variable: $toolbar-background-color

+ +

Component UIs

+ +

Every component in the ExtJS framework has a ui configuration (which defaults to default). This property can be changed to allow components in your application to have different styles.

+ +

The ui of any component can be changed at anytime, even after render, by using the setUI method. An example of this can be found in examples/panel/bubble-panel.html.

+ +

Creating new ExtJS UIs

+ +

Some ExtJS components have SASS @mixin's which allow you to quickly generate new UIs. These include: Ext.panel.Panel, Ext.button.Button, Ext.Toolbar and Ext.window.Window.

+ +

To create these new UIs is extremely simple. Simple call the associated @mixin (found in the documentation) for the component you want to create a new UI for.

+ +

Lets look at the Panel @mixin as an example (example can be found in examples/panel/bubble-panel/sass/bubble-panel.scss):

+ +
@include extjs-panel-ui(
+    'bubble',
+
+    $ui-header-font-size: 12px,
+    $ui-header-font-weight: bold,
+    $ui-header-color: #0D2A59,
+    $ui-header-background-color: #fff,
+    $ui-header-background-gradient: null,
+
+    $ui-border-color: #fff,
+    $ui-border-radius: 4px,
+    $ui-body-background-color: #fff,
+    $ui-body-font-size: 14px
+);
+ +

The above code will create a new ui for any Ext.panel.Panel component, which you can then use in your application by specifiying the ui configuration:

+ +
Ext.create('widget.panel', {
+    ui: 'bubble',
+    width: 300,
+    height: 300,
+    title: 'Panel with a bubble UI!'
+});
+ +

Supporting Legacy Browsers

+ +

In most cases when creating new UI's, you will want to include background gradients or rounded corners. Unfortunately legacy browsers do not support the corresponding CSS3 properties to do this, so we must use images.

+ +

Fortunately with ExtJS 4, we have included a Slicing tool which does this for you. You simply pass it a manifest file of your new UI's (if you have created any) and run the tool from the command line - and you're done!

+ +

How it works

+ +

The slicing tool creates a new browser instance, which loads ExtJS and a specified CSS file. Once loaded, it parses a JavaScript file which includes every ExtJS component that needs styled (panel, window, toolbar, etc.). It then analyzes each of those components and determines the size and location of each image that needs sliced. It then slices each of the images and sprites them together, and saves them in the location defined in the manifest.

+ +

The slicer itself is a command line tool which is installed as part of the SDK Tools package, which can be run by calling sencha slice theme from the command line. Example usage:

+ +
sencha slice theme -d ~/Downloads/ext-4.0 -c mytheme.css -o mytheme -v
+ +

It accepts several arguments:

+ +
  • --css[=]value, -c[=]value +> The path to your theme's complete CSS file, e.g., ext-all-access.css. Uses +> the default Ext JS 4 theme CSS if not provided.

  • --ext-dir[=]value, -d[=]value (required) +> The path to the root of your Ext JS 4 SDK directory.

  • --manifest[=]value, -m[=]value +> The path to your Theme Generator JSON manifest file, e.g., manifest.json. +> Uses the default packaged manifest if not provided.

  • --output-dir[=]value, -o[=]value +> The destination path to save all generated theme images. This should be inside the resources/themes/images// directory. +> Defaults to the current working directory.

  • --verbose, -v +> Display a message for every image that is generated.

+ +

Usage

+ +
  1. Compile your CSS

    You must ensure your SASS theme file has been compiled as this is used for the slicer. Passing no CSS file would result in the slicer to revert to the default ext-all.css file, which would be pointless in most cases.

  2. Creating your manifest file (optional)

    The manifest file is a simple JavaScript file which tells the Slicing tool which custom UI's you want to slice. This step is only neseccary when you have created new UI's.

    Let's look at the bubble panel example again:

    Ext.onReady(function() {
    +    Ext.manifest = {
    +        widgets: [
    +            {
    +                xtype: 'widget.header',
    +                ui   : 'bubble'
    +            },
    +            {
    +                xtype: 'widget.panel',
    +                ui   : 'bubble'
    +            }
    +        ]
    +    };
    +});

    As you can see, you define an Object called Ext.manifest and give it an Array property called widgets. In this Array, you should insert an object containing the xtype and the ui of the component you want to generate the images for.

    It is important that the Ext.manifest Object is defined inside the Ext.onReady method.

  3. Generating your images

    Now all that is left is to run the command, including the arguments to the ExtJS SDK folder, your theme CSS file and the output directory of the sliced images.

    sencha slice theme -d ~/Downloads/ext-4.0 -c mytheme.css -o mytheme -v

+ +

FAQ

+ +
  • I am getting a 'error resources/sass/my-ext-theme.scss (Line 8: File to import not found or unreadable: ext4/default/all)' error when I compile?

    This is because Compass cannot file the ExtJS 4 theme files. Ensure the $ext_path in the sass/config.rb file is correct.

+ +

This guide is a work in progress.

+ +

Please check back soon

\ No newline at end of file