igniteui-webcomponents
Version:
Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.
182 lines • 6.09 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { html, nothing } from 'lit';
import { property } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { live } from 'lit/directives/live.js';
import { registerComponent } from '../common/definitions/register.js';
import { createFormValueState, } from '../common/mixins/forms/form-value.js';
import { isEmpty, partNameMap } from '../common/util.js';
import IgcValidationContainerComponent from '../validation-container/validation-container.js';
import { IgcInputBaseComponent } from './input-base.js';
import { numberValidators, stringValidators } from './validators.js';
class IgcInputComponent extends IgcInputBaseComponent {
static register() {
registerComponent(IgcInputComponent, IgcValidationContainerComponent);
}
get __validators() {
return this.type !== 'number' ? stringValidators : numberValidators;
}
set value(value) {
this._formValue.setValueAndFormState(value);
this._validate();
}
get value() {
return this._formValue.value;
}
set pattern(value) {
this._pattern = value;
this._validate();
}
get pattern() {
return this._pattern;
}
set minLength(value) {
this._minLength = value;
this._validate();
}
get minLength() {
return this._minLength;
}
set maxLength(value) {
this._maxLength = value;
this._validate();
}
get maxLength() {
return this._maxLength;
}
set min(value) {
this._min = value;
this._validate();
}
get min() {
return this._min;
}
set max(value) {
this._max = value;
this._validate();
}
get max() {
return this._max;
}
set step(value) {
this._step = value;
this._validate();
}
get step() {
return this._step;
}
constructor() {
super();
this.type = 'text';
this.validateOnly = false;
this.tabIndex = 0;
this._formValue = createFormValueState(this, { initialValue: '' });
}
setRangeText(replacement, start, end, selectMode = 'preserve') {
super.setRangeText(replacement, start, end, selectMode);
this.value = this.input.value;
}
select() {
return this.input.select();
}
stepUp(n) {
this.input.stepUp(n);
this.value = this.input.value;
}
stepDown(n) {
this.input.stepDown(n);
this.value = this.input.value;
}
handleInput() {
this.value = this.input.value;
this.emitEvent('igcInput', { detail: this.value });
}
handleChange() {
this.value = this.input.value;
this.emitEvent('igcChange', { detail: this.value });
}
handleFocus() {
this._dirty = true;
}
handleBlur() {
this._validate();
}
renderInput() {
return html `
<input
id=${this.inputId}
part=${partNameMap(this.resolvePartNames('input'))}
name=${ifDefined(this.name)}
type=${ifDefined(this.type)}
pattern=${ifDefined(this.pattern)}
placeholder=${ifDefined(this.placeholder)}
.value=${live(this.value)}
?readonly=${this.readOnly}
?disabled=${this.disabled}
?required=${this.required}
?autofocus=${this.autofocus}
tabindex=${this.tabIndex}
autocomplete=${ifDefined(this.autocomplete)}
inputmode=${ifDefined(this.inputMode)}
min=${ifDefined(this.validateOnly ? undefined : this.min)}
max=${ifDefined(this.validateOnly ? undefined : this.max)}
minlength=${ifDefined(this.minLength)}
maxlength=${ifDefined(this.validateOnly ? undefined : this.maxLength)}
step=${ifDefined(this.step)}
aria-invalid=${this.invalid ? 'true' : 'false'}
aria-describedby=${ifDefined(isEmpty(this._helperText) ? nothing : 'helper-text')}
=${this.handleChange}
=${this.handleInput}
=${this.handleFocus}
=${this.handleBlur}
/>
`;
}
}
IgcInputComponent.tagName = 'igc-input';
export default IgcInputComponent;
__decorate([
property()
], IgcInputComponent.prototype, "value", null);
__decorate([
property({ reflect: true })
], IgcInputComponent.prototype, "type", void 0);
__decorate([
property({ attribute: 'inputmode' })
], IgcInputComponent.prototype, "inputMode", void 0);
__decorate([
property()
], IgcInputComponent.prototype, "pattern", null);
__decorate([
property({ type: Number, attribute: 'minlength' })
], IgcInputComponent.prototype, "minLength", null);
__decorate([
property({ type: Number, attribute: 'maxlength' })
], IgcInputComponent.prototype, "maxLength", null);
__decorate([
property({ type: Number })
], IgcInputComponent.prototype, "min", null);
__decorate([
property({ type: Number })
], IgcInputComponent.prototype, "max", null);
__decorate([
property({ type: Number })
], IgcInputComponent.prototype, "step", null);
__decorate([
property({ type: Boolean })
], IgcInputComponent.prototype, "autofocus", void 0);
__decorate([
property()
], IgcInputComponent.prototype, "autocomplete", void 0);
__decorate([
property({ type: Boolean, reflect: true, attribute: 'validate-only' })
], IgcInputComponent.prototype, "validateOnly", void 0);
__decorate([
property({ type: Number })
], IgcInputComponent.prototype, "tabIndex", void 0);
//# sourceMappingURL=input.js.map