Types and Styles in Button Control
19 Dec 20229 minutes to read
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. |
<ejs-button id="primarybtn" cssClass="e-primary" content="Primary"></ejs-button>
<ejs-button id="successbtn" cssClass="e-success" content="Success"></ejs-button>
<ejs-button id="infobtn" cssClass="e-info" content="Info"></ejs-button>
<ejs-button id="warningbtn" cssClass="e-warning" content="Warning"></ejs-button>
<ejs-button id="dangerbtn" cssClass="e-danger" content="Danger"></ejs-button>
<ejs-button id="linkbtn" cssClass="e-link" content="Link"></ejs-button>
<style>
button {
margin: 25px 5px 20px 20px;
}
</style>
NOTE
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 to their initial values. |
In the following sample, type
attribute of the Submit button is set using tag helper and Reset button is set using htmlAttribute
.
@{IDictionary<string, object> submit = new Dictionary<string, object>();
submit.Add("type", "submit");
}
@{IDictionary<string, object> reset = new Dictionary<string, object>();
reset.Add("type", "reset");
}
<ejs-button id="submit" content="Submit" htmlAttributes="submit"></ejs-button>
<ejs-button id="reset" content="Reset" htmlAttributes="reset"></ejs-button>
<style>
button {
margin: 25px 5px 20px 20px;
}
</style>
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
.
<ejs-button id="flat" cssClass="e-flat" content="Flat"></ejs-button>
<ejs-button id="outline" cssClass="e-outline" content="Outline"></ejs-button>
<ejs-button id="round" cssClass="e-round" iconCss="e-icons e-plus-icon" isPrimary="true"></ejs-button>
<style>
button {
margin: 25px 5px 20px 20px;
}
.e-plus-icon::before {
content: '\e823';
}
</style>
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.
<ejs-button id="togglebtn" onclick=clickHandler() cssClass="e-flat" iconCss="e-btn-sb-icons e-play-icon" content="Play" isToggle="true"></ejs-button>
<style>
@@font-face {
font-family: 'button-icons';
src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMj1uSf8AAAEoAAAAVmNtYXDOXM6wAAABtAAAAFRnbHlmcV/SKgAAAiQAAAJAaGVhZBNt0QcAAADQAAAANmhoZWEIUQQOAAAArAAAACRobXR4NAAAAAAAAYAAAAA0bG9jYQNWA+AAAAIIAAAAHG1heHABGQAZAAABCAAAACBuYW1lASvfhQAABGQAAAJhcG9zdFAouWkAAAbIAAAA2AABAAAEAAAAAFwEAAAAAAAD9AABAAAAAAAAAAAAAAAAAAAADQABAAAAAQAAYD3WXF8PPPUACwQAAAAAANgtxgsAAAAA2C3GCwAAAAAD9AP0AAAACAACAAAAAAAAAAEAAAANAA0AAgAAAAAAAgAAAAoACgAAAP8AAAAAAAAAAQQAAZAABQAAAokCzAAAAI8CiQLMAAAB6wAyAQgAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABA5wHnDQQAAAAAXAQAAAAAAAABAAAAAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAAAAAIAAAADAAAAFAADAAEAAAAUAAQAQAAAAAYABAABAALnCOcN//8AAOcB5wr//wAAAAAA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BAkABgAYAO8AAwABBAkACgBYAQcAAwABBAkACwAkAV8gYnV0dG9uLWljb25zUmVndWxhcmJ1dHRvbi1pY29uc2J1dHRvbi1pY29uc1ZlcnNpb24gMS4wYnV0dG9uLWljb25zRm9udCBnZW5lcmF0ZWQgdXNpbmcgU3luY2Z1c2lvbiBNZXRybyBTdHVkaW93d3cuc3luY2Z1c2lvbi5jb20AIABiAHUAdAB0AG8AbgAtAGkAYwBvAG4AcwBSAGUAZwB1AGwAYQByAGIAdQB0AHQAbwBuAC0AaQBjAG8AbgBzAGIAdQB0AHQAbwBuAC0AaQBjAG8AbgBzAFYAZQByAHMAaQBvAG4AIAAxAC4AMABiAHUAdAB0AG8AbgAtAGkAYwBvAG4AcwBGAG8AbgB0ACAAZwBlAG4AZQByAGEAdABlAGQAIAB1AHMAaQBuAGcAIABTAHkAbgBjAGYAdQBzAGkAbwBuACAATQBlAHQAcgBvACAAUwB0AHUAZABpAG8AdwB3AHcALgBzAHkAbgBjAGYAdQBzAGkAbwBuAC4AYwBvAG0AAAAAAgAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANAQIBAwEEAQUBBgEHAQgBCQEKAQsBDAENAQ4ACm1lZGlhLXBsYXkLbWVkaWEtcGF1c2UQLWRvd25sb2FkLTAyLXdmLQltZWRpYS1lbmQHYWRkLW5ldwtuZXctbWFpbC13ZhB1c2VyLWRvd25sb2FkLXdmDGV4cGFuZC0wMy13Zg5kb3dubG9hZC0wMi13ZgphZGQtbmV3XzAxC21lZGlhLWVqZWN0Dm1lZGlhLWVqZWN0LTAxAAA=) format('truetype');
font-weight: normal;
font-style: normal;
}
.e-btn-sb-icons {
font-family: 'button-icons';
line-height: 1;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.e-play-icon::before {
content: '\e701';
}
.e-pause-icon::before {
content: '\e705';
}
</style>
<script>
function clickHandler() {
var togglebtn = ej.base.getInstance(document.getElementById('togglebtn'), ej.buttons.Button);
if (document.getElementById('togglebtn').classList.contains('e-active')) {
togglebtn.content = 'Pause';
togglebtn.iconCss = 'e-btn-sb-icons e-pause-icon';
} else {
togglebtn.content = 'Play';
togglebtn.iconCss = 'e-btn-sb-icons e-play-icon';
}
};
</script>
Icons
Button with font 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.
<ejs-button id="iconbutton" iconCss="e-btn-sb-icon e-prev-icon" content="PREVIOUS"></ejs-button>
<ejs-button id="iconposbtn" iconCss="e-btn-sb-icon e-stop-icon" content="STOP"></ejs-button>
<style>
button {
margin: 25px 5px 20px 20px;
}
@@font-face {
font-family: 'btn-icon';
src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMj1tSfgAAAEoAAAAVmNtYXDnH+dzAAABoAAAAEJnbHlm1v48pAAAAfgAAAQYaGVhZBOPfZcAAADQAAAANmhoZWEIUQQJAAAArAAAACRobXR4IAAAAAAAAYAAAAAgbG9jYQN6ApQAAAHkAAAAEm1heHABFQCqAAABCAAAACBuYW1l07lFxAAABhAAAAIxcG9zdK9uovoAAAhEAAAAgAABAAAEAAAAAFwEAAAAAAAD9AABAAAAAAAAAAAAAAAAAAAACAABAAAAAQAAJ1LUzF8PPPUACwQAAAAAANg+nFMAAAAA2D6cUwAAAAAD9AP0AAAACAACAAAAAAAAAAEAAAAIAJ4AAwAAAAAAAgAAAAoACgAAAP8AAAAAAAAAAQQAAZAABQAAAokCzAAAAI8CiQLMAAAB6wAyAQgAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABA5wDnBgQAAAAAXAQAAAAAAAABAAAAAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAAAAACAAAAAwAAABQAAwABAAAAFAAEAC4AAAAEAAQAAQAA5wb//wAA5wD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uAHMAeQBuAGMAZgB1AHMAaQBvAG4ALgBjAG8AbQAAAAACAAAAAAAAAAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgBAgEDAQQBBQEGAQcBCAEJAAptZWRpYS1wbGF5C21lZGlhLXBhdXNlDmFycm93aGVhZC1sZWZ0BHN0b3AJbGlrZS0tLTAxBGNvcHkQLWRvd25sb2FkLTAyLXdmLQAA) format('truetype');
font-weight: normal;
font-style: normal;
}
.e-btn-sb-icon {
font-family: 'btn-icon' !important;
speak: none;
font-size: 55px;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.e-stop-icon::before {
content: '\e703';
}
.e-prev-icon::before {
content: '\e702';
}
</style>
NOTE
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 with SVG image
SVG image can be added to the Button using iconCss property.
In the following example, SVG image is added using the iconCss class e-search-icon
by setting height
and width
property.
<ejs-button id="iconbutton" iconCss="e-search-icon"></ejs-button>
<style>
button {
margin: 25px 5px 20px 20px;
}
.e-btn-icon.e-search-icon {
background: url('search_icon.svg');
height: 25px;
width: 25px;
}
</style>
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
.
<ejs-button id="smallbtn" cssClass="e-small" content="SMALL"></ejs-button>
<ejs-button id="normalbtn" content="NORMAL"></ejs-button>
<style>
button {
margin: 25px 5px 20px 20px;
}
</style>
NOTE