Skip to content

Commit

Permalink
added checkbox-group behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonpecora committed Aug 21, 2015
1 parent 15bab91 commit aefe039
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
40 changes: 40 additions & 0 deletions behaviors/checkbox-group.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Checkbox-Group arguments:
{array} options each has name and value (strings)
*/

var dom = require('../services/dom');

function createOptions(name, options) {
return options.map(function (option) {
var optName = option.name,
optValue = option.value,
id = name + '-' + optValue + '-' + optName;

return `
<div class="checkbox-group-item">
<input name="${name}" rv-field="${name}" type="checkbox" id="${id}" rv-checked="${name}.data.${optValue}" value="${optValue}" />
<label for="${id}">${optName}</label>
</div>
`;
}).join('\n');
}

module.exports = function (result, args) {
var name = result.name,
options = args.options,
field;

field = dom.create(`
<div class="input-label">
<div class="checkbox-group">
${ createOptions(name, options) }
</div>
</div>
`);

result.el = field;

return result;
};
17 changes: 17 additions & 0 deletions behaviors/checkbox-group.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@import '../styleguide/inputs';
@import '../styleguide/typography';

.checkbox-group .checkbox-group-item {
margin: 0;
padding: 0;
width: 100%;
}

.checkbox-group input {
@include checkbox();
}

.checkbox-group label {
@include normal-text();
@include overlay-copy();
}
Empty file.
1 change: 1 addition & 0 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ behaviors.add('soft-maxlength', require('./behaviors/soft-maxlength'));
behaviors.add('radio', require('./behaviors/radio'));
behaviors.add('description', require('./behaviors/description'));
behaviors.add('checkbox', require('./behaviors/checkbox'));
behaviors.add('checkbox-group', require('./behaviors/checkbox-group'));
behaviors.add('textarea', require('./behaviors/textarea'));
behaviors.add('url', require('./behaviors/url'));
behaviors.add('select', require('./behaviors/select'));
Expand Down
8 changes: 8 additions & 0 deletions styleguide/_inputs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@
border: 1px solid $yellow;
}
}

@mixin checkbox {
height: 2.4rem;
margin: 0;
padding: 0;
vertical-align: middle;
width: 2.4rem;
}

0 comments on commit aefe039

Please sign in to comment.