Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
docs(): add documentation for switch
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed Aug 28, 2014
1 parent 4975c74 commit 7841d67
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/animate/_effects.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ material-ink-bar {
}

canvas.material-ink-ripple {
pointer-events: none;
pointer-events: none !important;
position: absolute;
top: 0;
left: 0;
Expand Down
4 changes: 2 additions & 2 deletions src/components/checkbox/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ angular.module('material.components.checkbox', [
* @restrict E
*
* @description
* The checkbox directive is used like the normal [angular checkbox](https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D)
* The checkbox directive is used like the normal [angular checkbox](https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D).
*
* @param {string} ngModel Assignable angular expression to data-bind to.
* @param {string=} name Property name of the form under which the control is published.
* @param {expression=} ngTrueValue The value to which the expression should be set when selected.
* @param {expression=} ngFalseValue The value to which the expression should be set when not selected.
* @param {string=} ngChange Angular expression to be executed when input changes due to user interaction with the input element.
* @param {boolean=} noink Use of attribute indicates use of ripple ink effects
* @param {boolean=} disabled Use of attribute indicates the tab is disabled: no ink effects and not selectable
* @param {boolean=} disabled Use of attribute indicates the switch is disabled: no ink effects and not selectable
* @param {string=} ariaLabel Publish the button label used by screen-readers for accessibility. Defaults to the checkbox's text.
*
* @usage
Expand Down
1 change: 1 addition & 0 deletions src/components/radioButton/_radio-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ material-radio-button,
vertical-align: middle;
white-space: normal;
pointer-events: none;
width: auto;
}

.circle {
Expand Down
1 change: 1 addition & 0 deletions src/components/switch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The switch component is similar to a checkbox, except it creates a draggable switch.
33 changes: 21 additions & 12 deletions src/components/switch/_switch.scss
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
material-switch {
display: block;
position: relative;
width: $switch-width;
height: $baseline-grid * 3;
height: $baseline-grid * 4;

@include flex-display();
@include flex-justify-content(center);
@include flex-align-items(center);
*{
outline: none !important;
}

.material-switch-bar {
width: 32px;
position: absolute;
left: $baseline-grid * 2;
top: $baseline-grid * 1.5;
width: $baseline-grid * 4;
height: 1px;
background-color: #5a5a5a;
pointer-events: none;
}

/* check _radio-button.scss */
/* used also in _radio-button.scss */
.material-switch-thumb {
position: absolute;
margin: 0;
left: 0;
top: 0;
outline: none;

-webkit-transition: -webkit-transform 0.2s linear;
transition: transform 0.2s linear;
@include transform-translate3d(0,0,0);

&.material-checked {
.material-container {
-webkit-transition: -webkit-transform 0.2s linear;
transition: transform 0.2s linear;
@include transform-translate3d(0,0,0);
}
&.material-checked .material-container {
@include transform-translate3d($switch-width - 16,0,0);
}

.material-label {
margin-left: $baseline-grid * 7;
}
}
}
23 changes: 20 additions & 3 deletions src/components/switch/demo1/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
<div ng-app="myApp">
<material-switch ng-model="val"></material-switch>
<br/>
Value: {{val}}
<material-switch ng-model="data.cb1" aria-label="Switch 1">
Switch 1: {{ data.cb1 }}
</material-switch>

<material-switch ng-model="data.cb2" aria-label="Switch 2" ng-true-value="yup" ng-false-value="nope">
Switch 2: {{ data.cb2 }}
</material-switch>

<material-switch disabled aria-label="Disabled switch">
Switch (Disabled)
</material-switch>

<material-switch disabled aria-label="Disabled active switch" ng-model="data.cb4" ng-init="data.cb4=true">
Switch (Disabled, Active)
</material-switch>

<material-switch noink aria-label="Switch No Ink">
Switch (No Ink)
</material-switch>

</div>
38 changes: 38 additions & 0 deletions src/components/switch/switch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @ngdoc module
* @name material.components.switch
*/

angular.module('material.components.switch', [
'material.components.checkbox',
'material.components.radioButton',
Expand All @@ -9,6 +14,39 @@ angular.module('material.components.switch', [
MaterialSwitch
]);

/**
* @ngdoc directive
* @module material.components.switch
* @name materialSwitch
* @restrict E
*
* The switch directive is used very much like the normal [angular checkbox](https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D).
*
* @param {string} ngModel Assignable angular expression to data-bind to.
* @param {string=} name Property name of the form under which the control is published.
* @param {expression=} ngTrueValue The value to which the expression should be set when selected.
* @param {expression=} ngFalseValue The value to which the expression should be set when not selected.
* @param {string=} ngChange Angular expression to be executed when input changes due to user interaction with the input element.
* @param {boolean=} noink Use of attribute indicates use of ripple ink effects.
* @param {boolean=} disabled Use of attribute indicates the switch is disabled: no ink effects and not selectable
* @param {string=} ariaLabel Publish the button label used by screen-readers for accessibility. Defaults to the switch's text.
*
* @usage
* <hljs lang="html">
* <material-switch ng-model="isActive" aria-label="Finished?">
* Finished ?
* </material-switch>
*
* <material-switch noink ng-model="hasInk" aria-label="No Ink Effects">
* No Ink Effects
* </material-switch>
*
* <material-switch disabled ng-model="isDisabled" aria-label="Disabled">
* Disabled
* </material-switch>
*
* </hljs>
*/
function MaterialSwitch(checkboxDirectives, radioButtonDirectives) {
var checkboxDirective = checkboxDirectives[0];
var radioButtonDirective = radioButtonDirectives[0];
Expand Down

0 comments on commit 7841d67

Please sign in to comment.