-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: adjusting components to match patterns
- Loading branch information
1 parent
fd78150
commit 4095cbc
Showing
17 changed files
with
523 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Component } from 'pet-dex-utilities'; | ||
import './index.scss'; | ||
|
||
const events = [ | ||
'label:changed', | ||
'error:message', | ||
'content:changed', | ||
'error:visible', | ||
'error:resolved', | ||
]; | ||
|
||
const html = ` | ||
<div class="field" data-select="field"> | ||
<label class="field__label" data-select="field-label"></label> | ||
<div class="field__input" data-select="field-input"></div> | ||
<span class="field__error" data-select="field-error"></span> | ||
</div> | ||
`; | ||
|
||
export default function Field({ label = '', error = '', content } = {}) { | ||
Component.call(this, { html, events }); | ||
this.content = null; | ||
this.setLabel(label); | ||
this.setError(error); | ||
this.setContent(content); | ||
} | ||
|
||
Field.prototype = Object.assign(Field.prototype, Component.prototype, { | ||
getLabel() { | ||
return this.selected.get('field-label').innerText; | ||
}, | ||
|
||
setLabel(label = '') { | ||
this.selected.get('field-label').innerText = label; | ||
this.emit('label:changed', label); | ||
}, | ||
|
||
getError() { | ||
return this.selected.get('field-error').innerText; | ||
}, | ||
|
||
setError(error = '') { | ||
this.selected.get('field-error').innerText = error; | ||
this.emit('error:message', error); | ||
}, | ||
|
||
showError(error) { | ||
this.selected.get('field-error').classList.add('show-error'); | ||
this.emit('error:visible', error); | ||
}, | ||
|
||
resError(error) { | ||
this.selected.get('field-error').classList.remove('show-error'); | ||
this.emit('error:resolved', error); | ||
}, | ||
|
||
getContent() { | ||
return this.content; | ||
}, | ||
|
||
setContent(content) { | ||
if (content?.mount == null) { | ||
return; | ||
} | ||
|
||
this.content = content; | ||
this.content.mount(this.selected.get('field-input')); | ||
this.emit('content:changed', this.content); | ||
}, | ||
}); |
Oops, something went wrong.