Skip to content

create switch size option #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
bower_components
.DS_Store
.idea/
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,46 @@ You can completely change the design. All the magic is hidden inside two CSS cla
}
```

## Sizes

You can change the sizes of the switch element via size. Giving it a value of small or large will result in adding switchery-small or switchery-large classes respectively, which will change the switch size.

Not using this property will render the default sized switch element.

```html
<form>
<switch id="enabled" name="enabled" ng-model="enabled" size="small" class="green"></switch>
<br>{{ enabled }}
</form>
```

```html
<form>
<switch id="enabled" name="enabled" ng-model="enabled" size="small" class="green"></switch>
<br>{{ enabled }}
</form>
```

Alternatively you could just use a class attribute of `class="sm"` or `class="lg"`, which will change the switch size.

Again, not using size element or class attributes property will render the default sized switch element.

```html
<form>
<switch class="sm" id="enabled" name="enabled" ng-model="enabled"></switch>
<br>{{ enabled }}
</form>
```

```html
<form>
<switch class="lg" id="enabled" name="enabled" ng-model="enabled"></switch>
<br>{{ enabled }}
</form>
```

![YoomJS](https://raw.githubusercontent.com/EskoCruz/angular-ui-switch/master/switch-size.png)

## Publishing

1. Update version in `package.json` and `bower.json`.
Expand Down
34 changes: 34 additions & 0 deletions angular-ui-switch.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,37 @@
opacity: .50;
cursor: not-allowed;
}


/* Switchery sizes. */
/* Switchery size shorthand classes */

.switchery-small, .sm {
border-radius: 20px;
height: 20px;
width: 33px;
}

.switchery-small > small, .sm > small {
height: 20px;
width: 20px;
}

.switch.switchery-small.checked small, .switch.sm.checked small {
left: 13px;
}

.switchery-large, .lg {
border-radius: 40px;
height: 40px;
width: 66px;
}

.switchery-large > small, .lg > small {
height: 40px;
width: 40px;
}

.switch.switchery-large.checked small, .switch.lg.checked small {
left: 26px;
}
4 changes: 3 additions & 1 deletion angular-ui-switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ angular.module('uiSwitch', [])
, template: function(element, attrs) {
var html = '';
html += '<span';
html += ' class="switch' + (attrs.class ? ' ' + attrs.class : '') + '"';
html += ' class="switch' + (attrs.class ? ' ' + attrs.class : '');
html += attrs.size ? ' switchery-' + attrs.size : ''; /*switch size from small to large*/
html += '"';
html += attrs.ngModel ? ' ng-click="' + attrs.disabled + ' ? ' + attrs.ngModel + ' : ' + attrs.ngModel + '=!' + attrs.ngModel + (attrs.ngChange ? '; ' + attrs.ngChange + '()"' : '"') : '';
html += ' ng-class="{ checked:' + attrs.ngModel + ', disabled:' + attrs.disabled + ' }"';
html += '>';
Expand Down
2 changes: 1 addition & 1 deletion angular-ui-switch.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion angular-ui-switch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ angular.module('app', ['uiSwitch'])
$scope.onOff = true;
$scope.yesNo = true;
$scope.disabled = true;
$scope.sizeSmall = true;
$scope.sizeLarge = true;
$scope.sizeClassSmall = true;
$scope.sizeClassLarge = true;


$scope.changeCallback = function() {
Expand Down
32 changes: 32 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,38 @@
<p>
Enabled: {{ disabled }}
</p>
<!--Examples of using switch small. -->
<switch size="small" name="sizeSmall" ng-model="sizeSmall" ></switch>
<p>
<button ng-click="sizeSmall=!sizeSmall">Toggle</button>
</p>
<p>
Enabled: {{ sizeSmall }}
</p>
<!--Examples of using switch large. -->
<switch size="large" name="sizeLarge" ng-model="sizeLarge"></switch>
<p>
<button ng-click="sizeLarge=!sizeLarge">Toggle</button>
</p>
<p>
Enabled: {{ sizeLarge }}
</p>
<!--Examples of using switch class sm for small. -->
<switch class="sm" name="sizeClassSmall" ng-model="sizeClassSmall"></switch>
<p>
<button ng-click="sizeClassSmall=!sizeClassSmall">Toggle</button>
</p>
<p>
Enabled: {{ sizeClassSmall }}
</p>
<!--Examples of using switch class lg for large. -->
<switch class="lg" name="sizeClassLarge" ng-model="sizeClassLarge"></switch>
<p>
<button ng-click="sizeClassLarge=!sizeClassLarge">Toggle</button>
</p>
<p>
Enabled: {{ sizeClassLarge }}
</p>
</form>

</body>
Expand Down
Binary file added switch-size.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.