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.

{% tab template=‘button/default’, isDefaultActive=true %}

<template>
<div>
    <ejs-button cssClass='e-primary'>Primary</ejs-button>
    <ejs-button cssClass='e-success'>Success</ejs-button>
    <ejs-button cssClass='e-info'>Info</ejs-button>
    <ejs-button cssClass='e-warning'>Warning</ejs-button>
    <ejs-button cssClass='e-danger'>Danger</ejs-button>
    <ejs-button cssClass='e-link'>Link</ejs-button>
</div>
</template>

<script>
import Vue from 'vue';
import { ButtonPlugin } from '@syncfusion/ej2-vue-buttons';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);
Vue.use(ButtonPlugin);

export default {}
</script>

<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';

button {
  margin: 25px 5px 20px 20px;
}
</style>

{% endtab %}

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.

{% tab template=‘button/default’ %}

<template>
    <form>
        <ejs-button type='submit'>Submit</ejs-button>
        <ejs-button type='reset'>Reset</ejs-button>
    </form>
</template>

<script>
import Vue from 'vue';
import { ButtonPlugin } from '@syncfusion/ej2-vue-buttons';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);
Vue.use(ButtonPlugin);

export default {}
</script>

<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';

button {
  margin: 25px 5px 20px 20px;
}
</style>

{% endtab %}

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.

{% tab template=‘button/default’ %}

<template>
    <div>
        <ejs-button cssClass='e-flat'>Flat</ejs-button>
        <ejs-button cssClass='e-outline'>Outline</ejs-button>
        <ejs-button cssClass='e-round' iconCss='e-icons e-plus-icon' isPrimary=true></ejs-button>
    </div>
</template>

<script>
import Vue from 'vue';
import { ButtonPlugin } from '@syncfusion/ej2-vue-buttons';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);
Vue.use(ButtonPlugin);

export default {}
</script>

<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';

button {
  margin: 25px 5px 20px 20px;
}

.e-plus-icon::before {
  content: '\e823';
}
</style>

{% endtab %}

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 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.

{% tab template=‘button/default’ %}

<template>
    <ejs-button id='togglebtn' cssClass='e-flat' iconCss='e-icons e-play-icon' isToggle=true v-on:click.native='btnClick'>Play</ejs-button>
</template>

<script>
import Vue from 'vue';
import { ButtonPlugin } from '@syncfusion/ej2-vue-buttons';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);
Vue.use(ButtonPlugin);

export default {
  methods : {
    btnClick: function(event) {
      var toggleBtn = event.target.ej2_instances[0];
      if (toggleBtn.element.classList.contains('e-active')) {
        toggleBtn.content = 'Play';
        toggleBtn.iconCss = 'e-icons e-play-icon';
      } else {
        toggleBtn.content = 'Pause';
        toggleBtn.iconCss = 'e-icons e-pause-icon';
      }
    }
  }
}
</script>

<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';

button {
  margin: 25px 5px 20px 20px;
}

/* 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';
}
</style>

{% endtab %}

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.

{% tab template=‘button/default’ %}

<template>
    <div>
        <ejs-button iconCss='e-icons e-prev-icon'>Previous</ejs-button>
        <ejs-button iconCss='e-icons e-stop-icon' iconPosition='Right'>Stop</ejs-button>
    </div
</template>

<script>
import Vue from 'vue';
import { ButtonPlugin } from '@syncfusion/ej2-vue-buttons';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);
Vue.use(ButtonPlugin);

export default {}
</script>

<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';

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';
}
</style>

{% endtab %}

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.

{% tab template=‘button/default’ %}

<template>
    <div>
        <ejs-button cssClass='e-small'>Small</ejs-button>
        <ejs-button >Normal</ejs-button>
    </div
</template>

<script>
import Vue from 'vue';
import { ButtonPlugin } from '@syncfusion/ej2-vue-buttons';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);
Vue.use(ButtonPlugin);

export default {}
</script>

<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';

button {
  margin: 25px 5px 20px 20px;
}
</style>

{% endtab %}

See Also