2020-10-08 15:02:31 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { tracked } from '@glimmer/tracking';
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
|
|
|
|
export default class Element extends Component {
|
|
|
|
@tracked el;
|
|
|
|
|
|
|
|
@tracked touched = false;
|
|
|
|
|
|
|
|
get type() {
|
|
|
|
if (typeof this.el !== 'undefined') {
|
|
|
|
return this.el.dataset.type || this.el.getAttribute('type') || this.el.getAttribute('role');
|
|
|
|
}
|
|
|
|
return this.args.type;
|
|
|
|
}
|
|
|
|
get name() {
|
|
|
|
if (typeof this.args.group !== 'undefined') {
|
|
|
|
return `${this.args.group.name}[${this.args.name}]`;
|
|
|
|
} else {
|
|
|
|
return this.args.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
get prop() {
|
2022-09-15 08:43:17 +00:00
|
|
|
return `${this.args.name.toLowerCase().split('.').join('-')}`;
|
2020-10-08 15:02:31 +00:00
|
|
|
}
|
|
|
|
get state() {
|
|
|
|
const error = this.touched && this.args.error;
|
|
|
|
return {
|
2022-09-15 08:43:17 +00:00
|
|
|
matches: (name) => name === 'error' && error,
|
2020-10-08 15:02:31 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
connect($el) {
|
|
|
|
this.el = $el;
|
|
|
|
}
|
|
|
|
}
|