Skip to content

Commit

Permalink
chore(checkbox): use ng-classe
Browse files Browse the repository at this point in the history
  • Loading branch information
matmkian committed Nov 6, 2019
1 parent 8c7ad84 commit 70b3bcb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
33 changes: 33 additions & 0 deletions components/checkbox/js/checkbox_directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ function CheckboxController(LxUtilsService) {
// //
/////////////////////////////

/**
* The default props.
*
* @type {Object}
* @constant
* @readonly
*/
const _DEFAULT_PROPS = {
theme: 'light',
};

/**
* The model controller.
*
Expand Down Expand Up @@ -81,6 +92,27 @@ function CheckboxController(LxUtilsService) {
// //
/////////////////////////////

/**
* Get checkbox classes.
*
* @return {Array} The list of checkbox classes.
*/
function getClasses() {
const classes = [];

const state = lx.viewValue ? 'checked' : 'unchecked';
const theme = lx.theme ? lx.theme : _DEFAULT_PROPS.theme;

classes.push(`${CSS_PREFIX}-checkbox--is-${state}`);
classes.push(`${CSS_PREFIX}-checkbox--theme-${theme}`);

if (lx.customColors) {
classes.push(`${CSS_PREFIX}-custom-colors`);
}

return classes;
}

/**
* Set the model controller.
*
Expand Down Expand Up @@ -110,6 +142,7 @@ function CheckboxController(LxUtilsService) {

/////////////////////////////

lx.getClasses = getClasses;
lx.setModelController = setModelController;
lx.updateViewValue = updateViewValue;
}
Expand Down
9 changes: 1 addition & 8 deletions components/checkbox/views/checkbox.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<div
class="lumx-checkbox"
ng-class="{ 'lumx-checkbox--is-checked': lx.viewValue,
'lumx-checkbox--is-unchecked': !lx.viewValue,
'lumx-checkbox--theme-light': !lx.theme || lx.theme === 'light',
'lumx-checkbox--theme-dark': lx.theme === 'dark',
'lumx-custom-colors': lx.customColors }"
>
<div class="lumx-checkbox" ng-class="lx.getClasses()">
<div class="lumx-checkbox__input-wrapper">
<input
type="checkbox"
Expand Down

0 comments on commit 70b3bcb

Please sign in to comment.