3 Ext JS 4 has a brand new theming system to customize the look of your application while still supporting all browsers.
5 ## A Brief Introduction to SASS & Compass
7 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:
14 color: darken($blue, 9%);
23 And it will compile to:
26 border-color: #3bbfce;
33 border-color: #3bbfce;
36 To see the wide variety of other features available in SASS, please see [http://sass-lang.com/](http://sass-lang.com/). Compass extends SASS by adding a variety of CSS3 mixins and providing the extension system that Ext JS leverages. With Compass, one can include rules like:
41 @include border-radius($boxheight/4);
47 -webkit-border-radius: 2.5em;
48 -moz-border-radius: 2.5em;
49 -o-border-radius: 2.5em;
50 -ms-border-radius: 2.5em;
51 -khtml-border-radius: 2.5em;
55 You can learn more about the pre-included mixins with Compass and the other tools it provides here: [http://compass-style.org/docs/](http://compass-style.org/docs/).
63 XCode installs Ruby and all necessary dependencies to your Mac when installed.
65 Xcode can be found on the Apple Developer Website: [http://developer.apple.com/xcode/](http://developer.apple.com/xcode/)
69 Visit [http://rubyinstaller.org/](http://rubyinstaller.org/) and download the latest packaged version of Ruby (1.9.2 at the time of writing)
75 In `/Applications/Utilities/Terminal.app`, run the following code (you will be asked for your password):
77 sudo gem install compass
79 You can verify you have Compass and Sass installed by running the following in `Terminal.app`:
85 At the time of writing, the latest version of Compass is `0.11.1 (Antares)`. The latest version of Sass is `3.1.1 (Brainy Betty)`
89 Select **Start Command Prompt with Ruby** from the new Start Menu option.
95 You can verify you have Compass and Sass installed by running the following in **Terminal.app**:
100 At the time of writing, the latest version of Compass is `0.11.1 (Antares)`. The latest version of Sass is `3.1.1 (Brainy Betty)`
102 ## Directory Structure
104 The Ext JS SDK comes with a template which can be used as a base for your new theme. If you followed the [Getting Started](#/guide/getting_started) guide, you should have a directory for your application with a subfolder `extjs` containing the Ext JS SDK. It should look something like this:
111 Copy the template resources folder from `appname/extjs/resources/themes/templates/resource` to your root application folder:
115 appname/resources/css/
116 appname/resources/sass/
117 appname/resources/sass/config.rb
118 appname/resources/sass/my-ext-theme.sass
120 You will also need to copy the images from `appname/extjs/resources/themes/images/default` to `appname/resources/images`.
122 Ensure the path to your Ext JS folder is correct in `appname/resources/sass/config.rb`:
124 # $ext_path: This should be the path of the Ext JS SDK relative to this file
125 $ext_path = "../../extjs"
127 Due to a bug in Ext JS 4.0.2a you will also need to edit line 62 of `appname/extjs/resources/themes/lib/utils.rb` from this:
129 images_path = File.join($ext_path, 'resources', 'themes', 'images', theme)
133 images_path = relative_path
135 This ensures images will be served from `appname/resources/images` rather than `appname/extjs/resources/images`
137 ## Compiling your CSS
139 Compiling your CSS is a simple process using Compass.
141 First, change to your sass directory in `appname/resources/sass`, then run the following command in **Terminal.app on Mac OSX** or **Command Prompt on Windows**:
145 This should output the following:
147 > create ../css/my-ext-theme.css
149 Your minified css file should now be in `appname/resources/css/my-ext-theme.css`.
151 ## Changing global SASS variables
153 The Ext JS theming system comes with global SASS variables which you can use to change the look of your application with a few lines of code.
155 These SASS variables can be added to your `appname/resources/sass/my-ext-theme.scss` file, but they **must** be inserted before the call to `@import 'ext4/default/all'`. You can see an example commented out at the top of your `my-ext-theme.scss` file:
157 // Insert your custom variables here.
158 // $base-color: #aa0000;
160 Try uncommenting this line and changing the base-color to something else, perhaps the green #a1c148.
162 Now regenerate your theme by navigating to `appname/resources/sass` and running `compass compile`
164 ### Available Variables
166 Navigate to `appname/extjs/resources/themes/stylesheets/ext4/default/variables` directory. This directory contains all defined variables for each component in Ext JS 4.
168 The naming convention for variables follows CSS property names, prepends by the component name. For example:
170 - **Panel border radius**
171 - CSS Property: `border-radius`
172 - Variable: ``$panel-border-radius``
174 - **Panel body background color**
175 - CSS Property: `background-color`
176 - Variable: `$panel-body-background-color`
178 - **Toolbar background color**
179 - CSS Property: `background-color`
180 - Variable: `$toolbar-background-color`
182 You can copy any of these variables and add them to your `appname/resources/sass/my-ext-theme.scss` file **before** the `@import 'ext4/default/all'` line.
186 To view your new theme, lets overwrite `app.js` with the Theme example from the main SDK. This example shows most Ext JS components on a single page. Copy `appname/extjs/examples/themes/themes.js` to `appname/app.js`.
188 Update `appname/index.html` to the following:
192 <title>Ext Theme</title>
194 <link rel="stylesheet" type="text/css" href="resources/css/my-ext-theme.css">
195 <script type="text/javascript" src="extjs/ext-debug.js"></script>
196 <script type="text/javascript" src="app.js"></script>
201 Now open `index.html` in your browser and you should see your new theme in action. Try updating the base color in `my-ext-theme.sass` to something else, recompile your sass, and refresh your browser to see the change. Also try experimenting with other sass variables.
205 Every component in the Ext JS framework has a `ui` configuration (which defaults to `default`). This property can be changed to allow components in your application to have different styles.
207 The `ui` of any component can be changed at any time, even after render, by using the `setUI` method. An example of this can be found in `examples/panel/bubble-panel.html`.
209 ### Creating new Ext JS UIs
211 Some Ext JS 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`.
213 Creating these new UIs is simple. Simply call the associated `@mixin` (found in the documentation) for the component you want to create a new UI for.
215 Lets look at the Panel `@mixin` as an example (which can be found in `examples/panel/bubble-panel/sass/bubble-panel.scss`):
217 @include extjs-panel-ui(
220 $ui-header-font-size: 12px,
221 $ui-header-font-weight: bold,
222 $ui-header-color: #0D2A59,
223 $ui-header-background-color: #fff,
224 $ui-header-background-gradient: null,
226 $ui-border-color: #fff,
227 $ui-border-radius: 4px,
228 $ui-body-background-color: #fff,
229 $ui-body-font-size: 14px
232 The above code will create a new `ui` for any Ext.panel.Panel component, which you can then use in your application by specifying the `ui` configuration:
234 Ext.create('widget.panel', {
238 title: 'Panel with a bubble UI!'
241 ## Supporting Legacy Browsers
243 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, so we must use images instead.
245 With Ext JS 4, we have included a Slicing tool which does the hard work for 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.
249 The slicing tool creates a new browser instance, which loads Ext JS and a specified CSS file. Once loaded, it parses a JavaScript file which includes every Ext JS component that needs styling (panel, window, toolbar, etc.). It then analyzes each of those components and determines the size and location of each image that needs to be sliced. It then slices each of the images, sprites them together and saves them in the location defined in the manifest.
251 The slicer too itself can be run from the command line and is installed as part of the SDK Tools package. It can be run by calling `sencha slice theme`. Example usage (assuming you are in your application root directory):
253 sencha slice theme -d extjs -c resources/css/my-ext-theme.css -o resources/images -v
255 It accepts several arguments:
257 - **--css[=]value, -c[=]value**
258 > The path to your theme's complete CSS file, e.g., ext-all-access.css. Uses
259 > the default Ext JS 4 theme CSS if not provided.
261 - **--ext-dir[=]value, -d[=]value (required)**
262 > The path to the root of your Ext JS 4 SDK directory.
264 - **--manifest[=]value, -m[=]value**
265 > The path to your Theme Generator JSON manifest file, e.g., manifest.json.
266 > Uses the default packaged manifest if not provided.
268 - **--output-dir[=]value, -o[=]value**
269 > The destination path to save all generated theme images. This should be inside the `resources/themes/images/<themename>/` directory.
270 > Defaults to the current working directory.
273 > Display a message for every image that is generated.
277 1. **Compile your CSS**
279 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.
281 2. **Creating your manifest file (optional)**
283 The manifest file is a simple JavaScript file which tells the Slicing tool which custom UI's you would like to slice. This step is only necessary when you have created new UI's.
285 Let's look at the bubble panel example again:
287 Ext.onReady(function() {
291 xtype: 'widget.header',
295 xtype: 'widget.panel',
302 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 `ui` of the component you want to generate the images for.
304 **It is important that the `Ext.manifest` Object is defined inside the `Ext.onReady` method.**
306 3. **Generating your images**
308 Now all that is left is to run the command, including the arguments to the Ext JS SDK folder, your theme CSS file and the output directory of the sliced images.
310 sencha slice theme -d extjs -c resources/css/my-ext-theme.css -o resources/images -v
314 * **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?**
316 > This is because Compass cannot file the Ext JS 4 theme files. Ensure the `$ext_path` in the `sass/config.rb` file is correct.