Last active
November 17, 2016 16:33
-
-
Save AStoker/4bad8d87c5ed04e510ca60495936d86a to your computer and use it in GitHub Desktop.
Toggle Switch iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<require from="./switch"></require> | |
<span>${toggleState}</span><br /> | |
<label for="toggle">Toggle: </label> | |
<switch id="toggle" value.bind="toggleState" /> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class App { | |
toggleState = false; | |
toggle(){ | |
this.toggleState = !this.toggleState; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Aurelia</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> | |
<script> | |
require(['aurelia-bootstrapper']); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch .switch-container{ | |
position: relative; | |
border: none; | |
border-radius: 10px; | |
box-shadow: 0px 0px 0px 1px #e5e5e5; | |
height: 20px; | |
width: 35px; | |
background-color: white; | |
padding: 0; | |
cursor: pointer; | |
transition: background-color .1s ease-in-out; | |
} | |
switch .switch-container.on{ | |
background-color: #00b300; | |
box-shadow: 0px 0px 0px 1px #00b300; | |
} | |
switch .switch-container:focus{ | |
outline: none; | |
} | |
switch .indicator{ | |
box-sizing: content-box; | |
position: absolute; | |
left: 0; | |
top: 0; | |
bottom: 0; | |
width: 18px; | |
margin: 0 -1px; | |
background-color: white; | |
border: 1px solid #e5e5e5; | |
border-radius: 50%; | |
box-shadow: 0px 3px 4px -2px rgba(0, 0, 0, 0.28); | |
transition: left .1s ease-in-out, border-color .1s ease-in-out; | |
} | |
switch .switch-container.on .indicator{ | |
left: calc(100% - 18px); | |
border-color: #00b300; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<require from="./switch.css"></require> | |
<button click.trigger="toggle()" class="switch-container ${state}"> | |
<div class="indicator"></div> | |
</button> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {bindable, bindingMode, computedFrom} from 'aurelia-framework'; | |
export class SwitchCustomElement{ | |
@bindable({ defaultBindingMode: bindingMode.twoWay }) value; | |
toggle(){ | |
this.value = !!!this.value; //Double ! forces boolean, third ! toggles state | |
} | |
@computedFrom('value') | |
get state(){ | |
if(this.value){ | |
return 'on'; | |
} else { | |
return 'off'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment