Search results

Types and Styles

This section explains the different styles and types of Buttons.

Button styles

The Essential JS 2 Button has the following predefined styles that can be defined using the cssClass property.

Class Description
e-primary Used to represent a primary action.
e-success Used to represent a positive action.
e-info Used to represent an informative action.
e-warning Used to represent an action with caution.
e-danger Used to represent a negative action.
e-link Changes the appearance of the Button like a hyperlink.
Source
Preview
app.component.ts
app.module.ts
main.ts
styles.css
import { Component, ViewEncapsulation } from '@angular/core';

@Component({
    selector: 'app-container',
    styleUrls: ['styles.css'],
    template:  `<!-- Primary Button - Used to represent a primary action. -->
                <button ejs-button cssClass="e-primary">Primary</button>

                <!-- Success Button - Used to represent a positive action. -->
                <button ejs-button cssClass="e-success">Success</button>

                <!-- Info Button - Used to represent an informative action -->
                <button ejs-button cssClass="e-info">Info</button>

                <!-- Warning Button - Used to represent an action with caution. -->
                <button ejs-button cssClass="e-warning">Warning</button>

                <!-- Danger Button - Used to represent a negative action. -->
                <button ejs-button cssClass="e-danger">Danger</button>

                <!-- Link Button - Changes the appearance of the Button like a hyperlink. -->
                <button ejs-button cssClass="e-link">Link</button>`,
    encapsulation: ViewEncapsulation.None
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
button {
  margin: 25px 5px 20px 20px;
}

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  font-family:  'Helvetica Neue','calibiri';
  font-size:16px;
  top: 45%;
  left: 45%;
}

Predefined Button styles provide only the visual indication. So, Button content should define the Button style for the users of assistive technologies such as screen readers.

Button types

The types of Essential JS 2 Button are as follows:

  • Basic types
  • Flat Button
  • Outline Button
  • Round Button
  • Toggle Button

Basic types

The basic Button types are explained below.

Type Description
Button Defines a click Button.
Submit This Button submits the form data to the server.
Reset This Button resets all the controls in the form elements to their initial values.
Source
Preview
app.component.ts
app.module.ts
main.ts
styles.css
import { Component, ViewEncapsulation } from '@angular/core';

@Component({
    selector: 'app-container',
    styleUrls: ['styles.css'],
    template:   `<form>
                <!-- Submit. -->
                <button type="submit" ejs-button>Submit</button>

                <!-- Reset. -->
                <button type="reset" ejs-button>Reset</button>
                </form>`,
    encapsulation: ViewEncapsulation.None
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
button {
  margin: 25px 5px 20px 20px;
}

#loader {
  color: #008cff;
  font-family:   'Helvetica Neue','calibiri';
  font-size:16px;
  height: 40px;
  left: 45%;
  position: absolute;
  top: 45%;
  width: 30%;
}

Flat Button

The Flat Button is styled with no background color. To create a flat Button, set the cssClass property to e-flat.

Outline Button

An outline Button has a border with transparent background. To create an outline Button, set the cssClass property to e-outline.

Round Button

A round Button is shaped like a circle. Usually, it contains an icon representing its action. To create a round Button, set the cssClass property to e-round.

Source
Preview
app.component.ts
app.module.ts
main.ts
styles.css
import { Component, ViewEncapsulation } from '@angular/core';

@Component({
    selector: 'app-container',
    styleUrls: ['styles.css'],
    template:   `<!-- Flat Button. -->
                <button ejs-button cssClass="e-flat">Flat</button>

                <!-- Outline Button. -->
                <button ejs-button cssClass="e-outline">Outline</button>

                <!-- Round Button - Icon can be loaded by setting "e-icons e-plus-icon" in "iconCss" property.-->
                <!-- Use "e-icons" class name to load Essential JS 2 built-in icons.-->
                <!-- Use "e-plus-icon" class name to load plus icon that you can refer in "styles.css -->
                <button ejs-button cssClass="e-round" iconCss="e-icons e-plus-icon" [isPrimary]="true"></button>`,
    encapsulation: ViewEncapsulation.None
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
button {
  margin: 25px 5px 20px 20px;
}

/* For Round Button*/
.e-plus-icon::before {
  content: '\e823';
}

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  font-family:  'Helvetica Neue','calibiri';
  font-size:16px;
  top: 45%;
  left: 45%;
}

Toggle Button

A toggle Button allows you to change between the two states. The Button is active in toggled state and can be recognized through the e-active class. The functionality of the toggle Button is handled by by click event. To create a toggle Button, set the isToggle property to true. In the following code snippet, the toggle Button text changes to play/pause based on the state of the Button with the use of click event.

Source
Preview
app.component.ts
app.module.ts
main.ts
styles.css
import { Component, ViewEncapsulation, ViewChild, HostListener } from '@angular/core';
import { ButtonComponent } from '@syncfusion/ej2-angular-buttons';

@Component({
    selector: 'app-container',
    styleUrls: ['styles.css'],
    template: ` <!-- Button is active in toggled state. -->
                <button #togglebtn ejs-button cssClass="e-flat" iconCss = "e-icons e-play-icon" [isToggle]="true" content="Play" ></button>`,
    encapsulation: ViewEncapsulation.None
})
//Click Event.
export class AppComponent {
    @ViewChild('togglebtn') togglebtn: ButtonComponent;
    @HostListener('click', [this.togglebtn])
    btnClick(){
        if(this.togglebtn.element.classList.contains('e-active')){
            this.togglebtn.content = 'Pause';
            this.togglebtn.iconCss = 'e-icons e-pause-icon';
        }
        else{
            this.togglebtn.content = 'Play';
            this.togglebtn.iconCss = 'e-icons e-play-icon';
        }
    }
 }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
/* Added when toggle button is in active state*/
.e-play-icon::before {
    content: '\e798';
}

/* Added when toggle button is not in active state*/
.e-pause-icon::before {
    content: '\e753';
}

#loader {
    color: #008cff;
    height: 40px;
    width: 30%;
    position: absolute;
    font-family:  'Helvetica Neue','calibiri';
    font-size:16px;
    top: 45%;
    left: 45%;
  }

Icons

The Button can have an icon to provide the visual representation of the action. To place the icon on a Button, set the iconCss property to e-icons with the required icon CSS. By default, the icon is positioned to the left side of the Button. You can customize the icon’s position by using the iconPosition property.

Source
Preview
app.component.ts
app.module.ts
main.ts
styles.css
import { Component, ViewEncapsulation } from '@angular/core';

@Component({
    selector: 'app-container',
    styleUrls: ['styles.css'],
    template:  `<!-- To position the icon to the left of the text on a Button. -->
                <button ejs-button iconCss="e-icons e-prev-icon">Previous</button>

                <!-- To position the icon to the right of the text on a Button. -->
                <button ejs-button iconCss= "e-icons e-stop-icon" iconPosition="Right">Stop</button>`,
    encapsulation: ViewEncapsulation.None
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
button {
  margin: 25px 5px 20px 20px;
}

/*For Right Icon Button*/
.e-stop-icon::before {
  content: '\e790';
}

/*For Left Icon Button*/
.e-prev-icon::before {
  content: '\e716';
}

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  font-family:  'Helvetica Neue','calibiri';
  font-size:16px;
  top: 45%;
  left: 45%;
}

The Essential JS 2 provides a set of icons that can be loaded by applying e-icons class name to the element. You can also use third party icons on the Button using the iconCss property.

Button size

The two types of Button sizes are default and small. To change the size of the default Button to small Button, set the cssClass property to e-small.

Source
Preview
app.component.ts
app.module.ts
main.ts
styles.css
import { Component, ViewEncapsulation } from '@angular/core';

@Component({
    selector:  'app-container',
    styleUrls: ['styles.css'],
    template:  `<!-- Small Button. -->
                <button ejs-button cssClass="e-small">Small</button>

                <!-- Normal Button. -->
                <button ejs-button>Normal</button>`,
    encapsulation: ViewEncapsulation.None
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
button {
  margin: 25px 5px 20px 20px;
}

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  font-family:  'Helvetica Neue','calibiri';
  font-size:16px;
  top: 45%;
  left: 45%;
}

See Also