Overview

This element is a clickable toggle button with two states: checked and unchecked. The state can be changed by clicking on the button or by setting the checked property.

To initialize a Power Button, the user has to include the following files to the head of the page:

  • smart.base.css - the CSS file containing the styles for element
  • smart.element.js - the base class
  • smart.button.js - the JS file containing the base class about all button elements
  • smart.powerbutton.js - the JS file containing the element definition

The following code adds a Power Button to the page.

<!DOCTYPE html>
<html lang="en">
<head>
 <link rel="stylesheet" href="../../source/styles/smart.base.css" type="text/css" />
 <script type="text/javascript" src="webcomponents-lite.js">
</script> <script type="text/javascript" src="../../source/smart.element.js"></script> <script type="text/javascript" src="../../source/smart.button.js"></script> <script type="text/javascript" src="../../source/smart.powerbutton.js"></script> </head> <body> <smart-power-button></smart-power-button> </body> </html>

Demo

Note how smart.element.js and webcomponents.min.js are declared before everything else. This is mandatory for all custom elements.

Appearance

If the user wants to change the check state of the power button, this can be accomplished by setting the checked property of the element, like so:

<!DOCTYPE html>
<html lang="en">
<head>
 <link rel="stylesheet" href="../../source/styles/smart.base.css" type="text/css" />
 <script type="text/javascript" src="webcomponents-lite.js">
</script> <script type="text/javascript" src="../../source/smart.element.js"></script> <script type="text/javascript" src="../../source/smart.button.js"></script> <script type="text/javascript" src="../../source/smart.powerbutton.js"></script> <script> window.onload = function () { document.querySelector('smart-power-button').checked = true; } </script> </head> <body> <smart-power-button></smart-power-button> </body> </html>

Demo

Behavior

Using the checked property the user can change the check state of the element dynamically as well.

By default the checked of the check box is set to false. It could be set to true or false

The element offers multiple click modes:

  • press
  • release
  • pressAndRelease

clickMode is a property of the button that can be changed either from the HTML tag by setting the attribute click-mode and assigning a new value to it or by following the earlier approach and change it dynamically via javascript during the onload stage of the window object or later

Here's how to set a new clickMode on element initialiation:

<!DOCTYPE html>
<html lang="en">
<head>
 <link rel="stylesheet" href="../../source/styles/smart.base.css" type="text/css" />
 <script type="text/javascript" src="webcomponents-lite.js">
</script> <script type="text/javascript" src="../../source/smart.element.js"></script> <script type="text/javascript" src="../../source/smart.button.js"></script> <script type="text/javascript" src="../../source/smart.powerbutton.js"></script> </head> <body> <smart-power-button click-mode="press"></smart-power-button> </body> </html>

Keyboard Support

Smart.PowerButton check state could be changed via Space. Space should change the state only to Checked or Unchecked. The element is focusable and can be focused using the Tab button.