Overview

Smart.ProgressBar represents a colored bar that displays the stage of the current process.

There are two types of Smart Progress bar element:

  • Linear – smart-progress-bar
  • Circular – smart-circular-progress-bar

To initialize a progress bar 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.progressbar.js – the JS file containing the element definition

The following code adds one linear and one circular progress bar 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.progressbar.js"></script>
</head>
<body>
 <smart-progress-bar></smart-progress-bar>
 <smart-circular-progress-bar></smart-circular-progress-bar>
</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

To set the value of the progress bar the user has to apply a value to the value property as an HTML attribute:

 <smart-progress-bar value="50"></smart-progress-bar>
 <smart-circular-progress-bar value="50"></smart-circular-progress-bar>

Demo

or using javascript:

<!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.progressbar.js"></script>
 <script>
     window.onload = function () {
         document.querySelector('smart-progress-bar').value = 25;
         document.querySelector('smart-circular-progress-bar').value = 25;
     }
 </script>
</head>
<body>
 <smart-progress-bar></smart-progress-bar>
 <smart-circular-progress-bar></smart-circular-progress-bar>
</body>
</html>

Demo

The direction of the progress can be inverted by applying the inverted property:

 <smart-progress-bar value="25" inverted></smart-progress-bar>
 <smart-circular-progress-bar value="25" inverted></smart-circular-progress-bar>

Demo

The linear progress bar has two orientation types:

  • Horizontal – the fill increases from left to right.
  • Vertical – the fill increases from top to bottom.

The orientation property is responsible for the orinetation of the element:

<smart-progress-bar value="25" orientation="vertical"></smart-progress-bar>

Demo

Behavior

By default the progress bar is used to visually display the progress of a process using it’s fill. However the element allows numeric indication of the progress as well. This can be enabled by setting the showProgressValue property:

<smart-progress-bar show-progress-value value="54"></smart-progress-bar>

Demo

The progress indicator is placed in the middle of the progress bar and can be customized. The formatFunction property allows the user to control what text is displayed. Here’s how to apply a custom formatting function:

<!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.progressbar.js"></script>
 <script>
     window.onload = function () {
         var progressBar = document.querySelector('smart-progress-bar');
         progressBar.formatFunction = function (value) {
            return value + ' ' + 'oz';
         }
     }
 </script>
</head>
<body>
 <smart-progress-bar show-progress-value value="54"></smart-progress-bar>
</body>
</html>

Demo

The start and end value of the element can be reconfigured using the min and max property:

<smart-progress-bar value="54" min="20" max="70"></smart-progress-bar>
<smart-circular-progress-bar value="54" min="20" max="70"></smart-circular-progress-bar>

Demo

Progress bars are often used as loading indicators. For this purpose the user can set the indeterminate property and the progress bar will start an indeterminate animation which can be stopped any time by removing the attribute:

<!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.progressbar.js"></script>
 <script>
     window.onload = function () {
         var progressBar = document.querySelector('smart-progress-bar');
         progressBar.indeterminate = false;
     }
 </script>
</head>
<body>
 <smart-progress-bar indeterminate></smart-progress-bar>
</body>
</html>

Demo

The user can also set the progress bar to indeterminate state by setting the value property to null.

<!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.progressbar.js"></script>
 <script>
     window.onload = function () {
         var progressBar = document.querySelector('smart-circular-progress-bar');
         progressBar.value = null;
     }
 </script>
</head>
<body>
 <smart-circular-progress-bar></smart-circular-progress-bar>
</body>
</html>

Demo

Styling

The progress bar is stylable through classes like the rest of the Smart custom elements. However it does have some specific CSS variables that are used as well:

  • –smart-progress-bar-default-width – used to set the default width of the Linear progress bar. Default is 200px.
  • –smart-progress-bar-default-height – used to set the default height of the Linear progress bar. Default is 30px.
  • –smart-circular-progress-bar-default-size – used to set the default width and height of the Circulcar progress bar. Default is 150px.
  • –smart-circular-progress-bar-fill-size – used to set the width of the fill of the Circular progress bar which is relative to the size of the inner container(the HTML container in the middle of the element). Default value is 20%.