Skip to content

Commit

Permalink
Write modifiers according to BEM
Browse files Browse the repository at this point in the history
  • Loading branch information
nathalia-84 committed Feb 27, 2024
1 parent f903132 commit deb777b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/components/Toggle/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './index.scss';
import { Component, createIDFactory } from 'pet-dex-utilities';
const generateID = createIDFactory("toggle");

const generateID = createIDFactory('toggle');

const events = ['toggle'];

Expand All @@ -19,17 +20,19 @@ export default function Toggle(checked) {
this.selected.get('toggle-label').setAttribute('for', id);

this.toggle(checked);
this.selected.get('toggle-input').addEventListener('change', (e) => {
this.selected.get('toggle-input').addEventListener('change', () => {
checked = !checked;
this.toggle(checked);
});
}

Toggle.prototype = Object.assign(Toggle.prototype, Component.prototype, {
toggle(checked) {
if (checked) this.selected.get('toggle-label').classList.add('checked');
if (!checked) this.selected.get('toggle-label').classList.remove('checked');

if (checked) {
this.selected.get('toggle-label').classList.add('toggle-container__label--checked');
} else {
this.selected.get('toggle-label').classList.remove('toggle-container__label--checked');
}
this.emit('toggle');
}
},
});
4 changes: 2 additions & 2 deletions src/components/Toggle/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
content: '';
}

&.checked {
&--checked {
background-color: colors.$blue500;
}

&.checked::after {
&--checked::after {
transform: translateX(100%);
}
}
Expand Down

0 comments on commit deb777b

Please sign in to comment.