Skip to content

Commit

Permalink
Adjust scss and setToggle method structure
Browse files Browse the repository at this point in the history
  • Loading branch information
nathalia-84 committed Mar 15, 2024
1 parent b78459f commit 2b4cda0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
19 changes: 11 additions & 8 deletions src/components/Toggle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ const html = `
export default function Toggle({ checked = false } = {}) {
Component.call(this, { html, events });

this.setToggle(checked);
const id = generateID();
this.selected.get('toggle-input').setAttribute('id', id);
this.selected.get('toggle-label').setAttribute('for', id);

this.selected.get('toggle-input').addEventListener('change', () => {
this.emit('toggle', this.selected.get('toggle-input').checked);
});
this.setToggle(checked, false);

this.selected.get('toggle-input').addEventListener('change', () => this.emitToggle());
}

Toggle.prototype = Object.assign(Toggle.prototype, Component.prototype, {
setToggle(checked) {
const id = generateID();
this.selected.get('toggle-input').setAttribute('id', id);
this.selected.get('toggle-label').setAttribute('for', id);
emitToggle() {
this.emit('toggle', this.selected.get('toggle-input').checked);
},
setToggle(checked, emit = true) {
this.selected.get('toggle-input').checked = checked;
if (emit) this.emitToggle();
},
});
6 changes: 0 additions & 6 deletions src/components/Toggle/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@

align-items: center;

position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;

background-color: colors.$gray100;
border-radius: 3.4rem;

Expand Down

0 comments on commit 2b4cda0

Please sign in to comment.