All Components

Styling Overview

Kendo UI for React provides themes that can be used to style your application.

Currently, the suite ships the following themes:

Installation

To start using a theme, install it through NPM.

npm install --save @progress/kendo-theme-default

The Kendo UI Bootstrap theme depends on the Twitter Bootstrap framework. To install the theme:

  1. Run npm install --save @progress/kendo-theme-bootstrap.
  2. Install the version of the bootstrap framework specified as a peer dependency.

After the theme package is installed, reference it in your project.

Including Themes in Your Project

To include a theme in your application, either:

Using Precompiled CSS

Each Kendo UI theme for React includes an all.css file with precompiled styles that can be used as a ready solution for theming the available Kendo UI components for React.

To style your components by using the precompiled CSS options, either:

Including the Styles in the Application HTML

To include the theme with its precompiled CSS in the HTML which hosts your application, use a similar approach to the approach you use to any other HTML page.

<link rel="stylesheet" href="/node_modules/@progress/kendo-theme-default/dist/all.css" />

Loading the Styles along with the Component

When you include the theme with its precompiled CSS through the styleUrls property of the component, the styles will be loaded along with the component.

import '../../node_modules/@progress/kendo-theme-default/dist/all.css';

class App extends React.Component {
    render() {
        return (
            <h1>My First Kendo UI React App</h1>
            <Button primary={true}>
                My Kendo UI Button
            </Button>
        )
    }
}

ReactDOM.render(
    <App />,
    document.querySelector('my-app')
);

Customizing Themes

To customize a Kendo UI theme for React, either:

To build a custom theme by using the theme variables, either:

Using the Build Process of the Application

  1. Load the Kendo UI Default theme for React and import its SCSS sources into your project.

    import '../../node_modules/@progress/kendo-theme-default/dist/all.css';
    
    class App extends React.Component {
       render() {
           return (
               <h1>My First Kendo UI React App</h1>
               <Button primary={true}>
                   My Kendo UI Button
               </Button>
           )
       }
    }
    
    ReactDOM.render(
       <App />,
       document.querySelector('my-app')
    );
    // styles.scss
    @import "~@progress/kendo-theme-default/scss/all";
  2. The setup from the previous example enables you to add or remove theme variables directly in your application. The basic set of variables that you can use to customize your theme is located in the _variables.scss file.

    The following example demonstrates how to style the button in pink by changing the $accent variable before you import the theme.

    $accent: #ff69b4;
    
    @import "~@progress/kendo-theme-default/scss/all";

    To trim down the size of the generated CSS, build only the CSS for the components that you use in your application. To do this, include their source.

    // import only the PanelBar and Grid styles
    @import "~@progress/kendo-theme-default/scss/panelbar";
    @import "~@progress/kendo-theme-default/scss/grid";

Using the Build Process of the Themes

While each Kendo UI theme has a dedicated NPM package (for example, @progress/kendo-theme-default), the source code for all themes is located in the kendo-themes repository. This repository contains a build task that compiles the theme sources to CSS. To customize a theme, you can modify the source code of the theme and use the build task to produce a CSS file for your application. This approach avoid the need for a build configuration when compiling SCSS, but may be harder to maintain as the process has to be repeated for every update of the theme.

Previously, the themes were located in independent repositories. To improve the development process, these repositories are now merged in a single kendo-themes repository and the individual GitHub repositories for each theme are archived.

To create a custom theme by modifying the themes source code:

  1. Clone the kendo-themes GitHub repository.
  2. Install the dependencies for all themes with npm install && npx lerna bootstrap.
  3. Customize the theme variables in the packages/<THEME_NAME>/scss/_variables.scss files.
  4. Build the themes with the command npm run build to create the customized version of the themes in the packages/THEME_NAME/dist/all.css file.

    You might want to omit the styles for some components in the CSS output. To include only the styles that you need, run the COMPONENTS='component1,component2' npm run build command. For example, to create a CSS file that includes only the Grid and PanelBar styles, run COMPONENTS='panelbar,grid' npm run build. The command creates the dist/custom.css file which includes only the specified components.

  5. After the build completes, use the compiled CSS.

In this article