Polymer - Paper Toggle Button



Paper-toggle button is an ON/OFF switch using which the user can toggle the state by clicking or dragging the switch. You can use this element in your application, by running the following command to install it in your project directory.

bower install --save PolymerElements/paper-toggle-button

Example

The following example specifies the use of paper-toggle button element in Polymer.js. Create an index.html file and add the following code in it.

<!doctype html>
<html>
   <head>
      <link rel = 'import' href = 'my-app.html'>
   </head>
   
   <body>    
      <my-app></my-app>
   </body>
</html>

Now, open the my-app.html file and include the following code in it.

<link rel = 'import' href = 'bower_components/polymer/polymer.html'>
<link rel = "import" href = "bower_components/paper-tabs/paper-tabs.html">
<link rel = "import" href = "bower_components/iron-pages/iron-pages.html">

<dom-module id = 'my-app'>
   <template>
      <style>
         paper-tabs {
            background-color: black;
            width: 50%;
            margin-bottom: 1px;
            color: #fff;
         }
      </style>
      
      <h3>Paper-Tabs Example</h3>
      <paper-tabs selected = "0">
         <paper-tab>Tab One</paper-tab>
         <paper-tab>Tab Two</paper-tab>
      </paper-tabs>
   </template>
   
   <script>
      Polymer ({
         is: 'my-app', ready: function() {
            this.async(function() {         
            });
         }
      });
   </script>
</dom-module>

Output

To run the application, navigate to the created project directory and run the following command.

polymer serve

Now open the browser and navigate to http://127.0.0.1:8081/. Following will be the output.

Polymer Paper-Toggle-Button
polymer_elements.htm
Advertisements