3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11 <link rel=
"import" href=
"../polymer/polymer.html">
12 <link rel=
"import" href=
"../paper-styles/color.html">
13 <link rel=
"import" href=
"../paper-styles/default-theme.html">
14 <link rel=
"import" href=
"../paper-ripple/paper-ripple.html">
15 <link rel=
"import" href=
"../paper-behaviors/paper-inky-focus-behavior.html">
18 `paper-toggle-button` provides a ON/OFF switch that user can toggle the state
19 by tapping or by dragging the switch.
23 <paper-toggle-button></paper-toggle-button>
27 The following custom properties and mixins are available for styling:
29 Custom property | Description | Default
30 ----------------|-------------|----------
31 `--paper-toggle-button-unchecked-bar-color` | Slider color when the input is not checked | `#000000`
32 `--paper-toggle-button-unchecked-button-color` | Button color when the input is not checked | `--paper-grey-50`
33 `--paper-toggle-button-unchecked-ink-color` | Selected/focus ripple color when the input is not checked | `--dark-primary-color`
34 `--paper-toggle-button-checked-bar-color` | Slider button color when the input is checked | `--google-green-500`
35 `--paper-toggle-button-checked-button-color` | Button color when the input is checked | `--google-green-500`
36 `--paper-toggle-button-checked-ink-color` | Selected/focus ripple color when the input is checked | `--google-green-500`
39 @element paper-toggle-button
44 <dom-module id=
"paper-toggle-button">
46 <link rel=
"import" type=
"css" href=
"paper-toggle-button.css">
50 <div id=
"toggleContainer">
51 <div id=
"toggleBar" class=
"toggle-bar"></div>
52 <div id=
"toggleButton" class=
"toggle-button">
53 <paper-ripple id=
"ink" class=
"toggle-ink circle" recenters
></paper-ripple>
61 is
: 'paper-toggle-button',
64 Polymer
.PaperInkyFocusBehavior
69 'aria-pressed': 'false',
75 * Fired when the checked state changes due to user interaction.
80 * Fired when the checked state changes.
85 * Gets or sets the state, `true` is checked and `false` is unchecked.
94 reflectToAttribute
: true,
96 observer
: '_checkedChanged'
100 * If true, the button toggles the active state with each tap or press
110 reflectToAttribute
: true
119 this._isReady
= true;
122 // button-behavior hook
123 _buttonStateChanged: function() {
128 this.checked
= this.active
;
132 _checkedChanged: function(checked
) {
133 this.active
= this.checked
;
134 this.fire('iron-change');
137 _ontrack: function(event
) {
138 var track
= event
.detail
;
139 if (track
.state
=== 'start') {
140 this._trackStart(track
);
141 } else if (track
.state
=== 'track') {
142 this._trackMove(track
);
143 } else if (track
.state
=== 'end') {
144 this._trackEnd(track
);
148 _trackStart: function(track
) {
149 this._width
= this.$.toggleBar
.offsetWidth
/ 2;
151 * keep an track-only check state to keep the dragging behavior smooth
152 * while toggling activations
154 this._trackChecked
= this.checked
;
155 this.$.toggleButton
.classList
.add('dragging');
158 _trackMove: function(track
) {
160 this._x
= Math
.min(this._width
,
161 Math
.max(0, this._trackChecked
? this._width
+ dx
: dx
));
162 this.translate3d(this._x
+ 'px', 0, 0, this.$.toggleButton
);
163 this._userActivate(this._x
> (this._width
/ 2));
166 _trackEnd: function(track
) {
167 this.$.toggleButton
.classList
.remove('dragging');
168 this.transform('', this.$.toggleButton
);