Skip to content

Instantly share code, notes, and snippets.

@davelowensohn
Last active June 7, 2016 23:28
Show Gist options
  • Save davelowensohn/137fafddc3f5e0865ae0da71ea5f69c9 to your computer and use it in GitHub Desktop.
Save davelowensohn/137fafddc3f5e0865ae0da71ea5f69c9 to your computer and use it in GitHub Desktop.
Styled Ember checkboxes
isSomething: Ember.computed.alias('model.something'), // boolean
actions: {
checkSomething() {
this.toggleProperty('model.something');
},
}
<input type="checkbox" checked={{isSomething}} onclick={{action "checkSomething"}} id="{{concat 'check-something-' model.id}}" />
<label class="{{if isSomething 'selected'}}" for="{{concat 'check-something-' model.id}}"><span>Label!</span></label>
input[type="checkbox"] {
display: none;
}
input[type="checkbox"] + label {
cursor: pointer;
position: relative; // so absolute positioning of :before & :after elements works
padding-right: 10px;
span {
padding-left: 20px; // to get out from under :before & :after
}
}
input[type="checkbox"] + label:before {
position: absolute;
content: '\00a0'; // ASCII empty checkbox
display: inline-block;
width: 13px;
height: 12px;
font-size: 13px;
font-family: 'Arial Unicode MS'; // for access to extended characters
background-color: #ccc;
border: 1px solid #333;
border-radius: 2px;
text-align: center;
cursor: pointer;
top: 1px;
}
input[type="checkbox"]:checked + label:after {
position: absolute;
content: '\2715'; // nice mathy 'x'
color: #333;
left: 2px;
font-size: 13px;
top: 1px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment