Skip to content

Instantly share code, notes, and snippets.

@dandehavilland
Last active August 29, 2015 13:56
Show Gist options
  • Save dandehavilland/9323706 to your computer and use it in GitHub Desktop.
Save dandehavilland/9323706 to your computer and use it in GitHub Desktop.
On/Off switch for Ember (Flip Switch)
.flip-switch {
position: relative; width: 68px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.flip-switch-checkbox {
display: none;
}
.flip-switch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
.flip-switch-inner {
width: 200%; margin-left: -100%;
-moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}
.flip-switch-inner:before, .flip-switch-inner:after {
float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.flip-switch-inner:before {
content: "ON";
padding-left: 10px;
background-color: #77A680; color: #FFFFFF;
}
.flip-switch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
.flip-switch-switch {
width: 28px; margin: 1px;
background: #FFFFFF;
border: 2px solid #999999; border-radius: 20px;
position: absolute; top: 0; bottom: 0; right: 34px;
-moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
}
.flip-switch-checkbox:checked + .flip-switch-label .flip-switch-inner {
margin-left: 0;
}
.flip-switch-checkbox:checked + .flip-switch-label .flip-switch-switch {
right: 0px;
}
FlipSwitch = Em.ContainerView.extend {
classNames: ['flip-switch']
childViews: ['checkbox', 'label']
checked: Em.computed.alias('checkbox.checked')
disabled: Em.computed.alias('checkbox.disabled')
indeterminate: Em.computed.alias('checkbox.indeterminate')
checkbox: Em.Checkbox.create({
classNames: ['flip-switch-checkbox']
})
label: Em.ContainerView.create({
tagName: 'label'
classNames: ['flip-switch-label']
attributeBindings: 'for'
forBinding: 'parentView.checkbox.elementId'
childViews: [
Em.View.create(classNames: 'flip-switch-inner'),
Em.View.create(classNames: 'flip-switch-switch')
]
})
}
`export default FlipSwitch`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment