import { __decorate } from "tslib";
import { html } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { live } from 'lit/directives/live.js';
import { createRef, ref } from 'lit/directives/ref.js';
import { when } from 'lit/directives/when.js';
import { msg } from '@lit/localize';
import { $ } from '@mdui/jq/$.js';
import '@mdui/jq/methods/css.js';
import { MduiElement } from '@mdui/shared/base/mdui-element.js';
import { FormController, formResets } from '@mdui/shared/controllers/form.js';
import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
import { defaultValue } from '@mdui/shared/decorators/default-value.js';
import { watch } from '@mdui/shared/decorators/watch.js';
import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
import { observeResize } from '@mdui/shared/helpers/observeResize.js';
import { nothingTemplate } from '@mdui/shared/helpers/template.js';
import '@mdui/shared/icons/cancel--outlined.js';
import '@mdui/shared/icons/error.js';
import '@mdui/shared/icons/visibility-off.js';
import '@mdui/shared/icons/visibility.js';
import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
import { FocusableMixin } from '@mdui/shared/mixins/focusable.js';
import { onLocaleReady, offLocaleReady } from '../../internal/localize.js';
import '../button-icon.js';
import '../icon.js';
import { style } from './style.js';
/**
* @summary 文本框组件
*
* ```html
*
* ```
*
* @event focus - 获得焦点时触发
* @event blur - 失去焦点时触发
* @event change - 在文本框的值变更,且失去焦点时触发
* @event input - 在文本框的值变更时触发
* @event invalid - 表单字段验证不通过时触发
* @event clear - 在点击由 `clearable` 属性生成的清空按钮时触发。可以通过调用 `event.preventDefault()` 阻止清空文本框
*
* @slot icon - 左侧图标
* @slot end-icon - 右侧图标
* @slot error-icon - 验证失败状态的右侧图标
* @slot prefix - 左侧文本
* @slot suffix - 右侧文本
* @slot clear-button - 清空按钮
* @slot clear-icon - 清空按钮中的图标
* @slot toggle-password-button - 密码显示状态切换按钮
* @slot show-password-icon - 显示密码状态下,密码显示状态切换按钮中的图标
* @slot hide-password-icon - 隐藏密码状态下,密码显示状态切换按钮中的图标
* @slot helper - 底部的帮助文本
*
* @csspart container - 文本框容器
* @csspart icon - 左侧图标
* @csspart end-icon - 右侧图标
* @csspart error-icon - 验证失败状态的右侧图标
* @csspart prefix - 左侧文本
* @csspart suffix - 右侧文本
* @csspart label - 上方的标签文本
* @csspart input - 内部的 `` 或 ``;
}
/**
* @param hasError 是否包含错误提示
* @param hasHelper 是否含 helper 属性或 helper slot
*/
renderHelper(hasError, hasHelper) {
return hasError
? html`
${this.error || this.inputRef.value.validationMessage}
`
: hasHelper
? html`${this.helper}`
: // 右边有 counter,需要占位
html``;
}
renderCounter(hasCounter) {
return hasCounter
? html`${this.value.length}/${this.maxlength}
`
: nothingTemplate;
}
};
TextField.styles = [componentStyle, style];
__decorate([
property({ reflect: true })
], TextField.prototype, "variant", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "type", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "name", void 0);
__decorate([
property()
], TextField.prototype, "value", void 0);
__decorate([
defaultValue()
], TextField.prototype, "defaultValue", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "label", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "placeholder", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "helper", void 0);
__decorate([
property({
type: Boolean,
reflect: true,
converter: booleanConverter,
attribute: 'helper-on-focus',
})
], TextField.prototype, "helperOnFocus", void 0);
__decorate([
property({
type: Boolean,
reflect: true,
converter: booleanConverter,
})
], TextField.prototype, "clearable", void 0);
__decorate([
property({ reflect: true, attribute: 'clear-icon' })
], TextField.prototype, "clearIcon", void 0);
__decorate([
property({
type: Boolean,
reflect: true,
converter: booleanConverter,
attribute: 'end-aligned',
})
], TextField.prototype, "endAligned", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "prefix", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "suffix", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "icon", void 0);
__decorate([
property({ reflect: true, attribute: 'end-icon' })
], TextField.prototype, "endIcon", void 0);
__decorate([
property({ reflect: true, attribute: 'error-icon' })
], TextField.prototype, "errorIcon", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "form", void 0);
__decorate([
property({
type: Boolean,
reflect: true,
converter: booleanConverter,
})
], TextField.prototype, "readonly", void 0);
__decorate([
property({
type: Boolean,
reflect: true,
converter: booleanConverter,
})
], TextField.prototype, "disabled", void 0);
__decorate([
property({
type: Boolean,
reflect: true,
converter: booleanConverter,
})
], TextField.prototype, "required", void 0);
__decorate([
property({ type: Number, reflect: true })
], TextField.prototype, "rows", void 0);
__decorate([
property({
type: Boolean,
reflect: true,
converter: booleanConverter,
})
], TextField.prototype, "autosize", void 0);
__decorate([
property({ type: Number, reflect: true, attribute: 'min-rows' })
], TextField.prototype, "minRows", void 0);
__decorate([
property({ type: Number, reflect: true, attribute: 'max-rows' })
], TextField.prototype, "maxRows", void 0);
__decorate([
property({ type: Number, reflect: true })
], TextField.prototype, "minlength", void 0);
__decorate([
property({ type: Number, reflect: true })
], TextField.prototype, "maxlength", void 0);
__decorate([
property({
type: Boolean,
reflect: true,
converter: booleanConverter,
})
], TextField.prototype, "counter", void 0);
__decorate([
property({ type: Number, reflect: true })
], TextField.prototype, "min", void 0);
__decorate([
property({ type: Number, reflect: true })
], TextField.prototype, "max", void 0);
__decorate([
property({ type: Number, reflect: true })
], TextField.prototype, "step", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "pattern", void 0);
__decorate([
property({
type: Boolean,
reflect: true,
converter: booleanConverter,
attribute: 'toggle-password',
})
], TextField.prototype, "togglePassword", void 0);
__decorate([
property({ reflect: true, attribute: 'show-password-icon' })
], TextField.prototype, "showPasswordIcon", void 0);
__decorate([
property({ reflect: true, attribute: 'hide-password-icon' })
], TextField.prototype, "hidePasswordIcon", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "autocapitalize", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "autocorrect", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "autocomplete", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "enterkeyhint", void 0);
__decorate([
property({ type: Boolean, reflect: true, converter: booleanConverter })
], TextField.prototype, "spellcheck", void 0);
__decorate([
property({ reflect: true })
], TextField.prototype, "inputmode", void 0);
__decorate([
state()
], TextField.prototype, "invalid", void 0);
__decorate([
state()
], TextField.prototype, "invalidStyle", void 0);
__decorate([
property({
type: Boolean,
reflect: true,
converter: booleanConverter,
attribute: 'focused-style',
})
], TextField.prototype, "focusedStyle", void 0);
__decorate([
state()
], TextField.prototype, "isPasswordVisible", void 0);
__decorate([
state()
], TextField.prototype, "hasValue", void 0);
__decorate([
state()
], TextField.prototype, "error", void 0);
__decorate([
watch('disabled', true)
], TextField.prototype, "onDisabledChange", null);
__decorate([
watch('value')
], TextField.prototype, "onValueChange", null);
__decorate([
watch('rows', true)
], TextField.prototype, "onRowsChange", null);
__decorate([
watch('maxRows')
], TextField.prototype, "onMaxRowsChange", null);
__decorate([
watch('minRows')
], TextField.prototype, "onMinRowsChange", null);
TextField = __decorate([
customElement('mdui-text-field')
], TextField);
export { TextField };