Introducing React ReExt – Sencha Ext JS Components in React! LEARN MORE

Material and CSS Variables in Ext JS 6.2

September 15, 2016 112 Views
Show

The days of waiting years for browser updates are numbered, and the web as a platform is becoming much more agile. With the release of Ext JS 6.2, you’ll be able to take advantage of a new feature for your apps, CSS Variables.

CSS Variables, also known as Custom Properties, do exactly what their name implies: they allow you to declare and use variables in your CSS. This simple concept opens up a whole new world of possibilities for styling your web content. Variables not only allow you to change the look of your application dynamically at runtime, but they can also change how you structure your styles as you develop. According to our customers, Ext JS is one of the Best Javascript Frameworks. Continue reading to learn about material themes, build-time, runtime, and much more.

What is the Material Theme?

Material Theme

The Material theme (“theme-material”) for the Modern Toolkit is the first to take advantage of CSS variables. The specification makes it an ideal candidate for simple customization as margins, paddings, and font sizes all have exact recommendations but colors are provided as a palette.

The first release of theme-material allows for name-based color customization. This can be done at build-time or at runtime by setting the variables ‘$base-color-name’ and ‘$accent-color-name’. A full list of color names can be found on the Material Design site. All names are lowercase, and if there are multiple words, they should be connected by a ‘-’; for example, ‘Deep Purple’ is ‘deep-purple’.

What about at Build-Time?

Build-time theme configuration is done by adding variables to a SCSS file. You can learn the basics of styling your application by reading our Setup & Getting Started Guide. To change the colors for the Material Design theme, just enter the names of the colors you want from the guideline.

    $base-color-name: dynamic('blue');
    $accent-color-name: dynamic('orange');

What about at Runtime?

Runtime theme changing really shows the power of CSS variables. This allows you to customize your application in the browser as it is running, and it can even allow your users to change the look of the application and personalize it.

Fashion handles updating variables via the ‘setVariables’ method, and it helps fill in gaps where CSS variables are lacking. It’s able to quickly evaluate relationships between variables from the original theme source code and apply those values to CSS variables. For example, by setting ‘base-color-name’, Fashion is able to find all other variables that derive from this variable and update them accordingly. This allows us to simply set the name of the base and accent color and see the rest of the application change.

    Fashion.css.setVariables({
        "base-color-name": "blue", 
        "accent-color-name": "orange"
    });

Runtime Theme Changing

What about Dark Mode?

The Ext JS 6.2 Material Theme also features a dark mode. This quick toggle will change the application from light backgrounds and dark text to dark backgrounds and light text. This can be done simply by setting the ‘dark-mode’ variable.

    Fashion.css.setVariables({
        "dark-mode": "true"
    });

Dark Mode

What about Chrome for Android?

With the release of Chrome 39 and Android Lollipop (5.0), Google announced the theme-color meta-data tag. This allowed developers to customize the chrome of the browser to better fit their application and provide a more harmonious experience for their users.

To begin, add a meta tag inside the head tag of your application’s index.html file.

    

You can now get the hex of a color and weight from the Material Theme singleton and update the metadata tags content attribute;

    var colors = Ext.theme.Material.getColors(),
        meta = Ext.getHead().first('meta[name=theme-color]'),
        color = colors['red']['500'];

    meta.dom.setAttribute('content', color);

Is there a Chameleon Example?

In this example, we take dynamic color generation in a different direction by using color analysis. We are using VibrantJS to analyze the active image in a carousel and extract the vibrant colors on the fly. We then determine the closest Material color and change the UI to match.

You can try this example yourself by downloading the project from GitHub.

Chameleon Example

What is the current Support?

Currently CSS Variables are supported in Chrome, Safari, Firefox, Opera, iOS Safari, and Chrome on Android. Microsoft Edge support is also in the works, and it recently gained a status of “in development”.

Support for CSS Variables

How can I get started with the Next Steps?

We’re very excited about CSS variables and the possibilities they open for dynamic theming. Look for updates and enhancements in future versions that expand on this functionality and give you more control over the look of your application. If you are new to Ext JS, please head over to the 30-day free trial page to download Ext JS and try it out for yourself. Existing customers can just upgrade to 6.2 from the Support portal and start using the Material Theme and CSS variables today!

Show
Start building with Ext JS today

Build 10x web apps faster with 140+ pre-build components and tools.

Latest Content
Discover the Top 07 Architecture Patterns used in Modern Enterprise Software Development
Discover the Top 07 Architecture Patterns used in Modern Enterprise Software Development

Developing software without an architecture pattern may have been an option back then. However, that’s…

JavaScript Design Patterns: A Hands-On Guide with Real-world Examples
JavaScript Design Patterns: A Hands-On Guide with Real-world Examples

As a web developer, you know how popular JavaScript is in the web app development…

Virtual JS Days 2024のハイライト
Virtual JS Days 2024のハイライト

2024年2月20日~22日、第3回目となる「Virtual JavaScript Days」が開催されました。JavaScript の幅広いトピックを採り上げた数多くのセッションを実施。その内容は、Senchaの最新製品、ReExt、Rapid Ext JSまで多岐にわたり、JavaScriptの最新のサンプルも含まれます。 このカンファレンスでは多くのトピックをカバーしています。Senchaでセールスエンジニアを務めるMarc Gusmano氏は、注目すべきセッションを主催しました。Marc は Sencha の最新製品「ReExt」について、詳細なプレゼンテーションを実施。その機能とメリットを、参加者に理解してもらうべく詳細に説明しました。 カンファレンスは、Senchaのジェネラルマネージャを務めるStephen Strake氏によるキーノートでスタートしました。キーノートでは、会社の将来のビジョンについての洞察を共有しています。世界中から JavaScript 開発者、エンジニア、愛好家が集まるとてもエキサイティングなイベントとなりました。これは、JavaScript…

See More