123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- /*!
- * (C) Ionic http://ionicframework.com - MIT License
- */
- import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
- import { a as printIonWarning } from './index4.js';
- import { c as createColorClasses } from './theme.js';
- import { l as eye, m as eyeOff } from './index7.js';
- import { b as getIonMode } from './ionic-global.js';
- import { d as defineCustomElement$4 } from './button.js';
- import { d as defineCustomElement$3 } from './icon.js';
- import { d as defineCustomElement$2 } from './ripple-effect.js';
- const iosInputPasswordToggleCss = "";
- const IonInputPasswordToggleIosStyle0 = iosInputPasswordToggleCss;
- const mdInputPasswordToggleCss = "";
- const IonInputPasswordToggleMdStyle0 = mdInputPasswordToggleCss;
- const InputPasswordToggle = /*@__PURE__*/ proxyCustomElement(class InputPasswordToggle extends HTMLElement {
- constructor() {
- super();
- this.__registerHost();
- this.__attachShadow();
- this.togglePasswordVisibility = () => {
- const { inputElRef } = this;
- if (!inputElRef) {
- return;
- }
- inputElRef.type = inputElRef.type === 'text' ? 'password' : 'text';
- };
- this.color = undefined;
- this.showIcon = undefined;
- this.hideIcon = undefined;
- this.type = 'password';
- }
- /**
- * Whenever the input type changes we need to re-run validation to ensure the password
- * toggle is being used with the correct input type. If the application changes the type
- * outside of this component we also need to re-render so the correct icon is shown.
- */
- onTypeChange(newValue) {
- if (newValue !== 'text' && newValue !== 'password') {
- printIonWarning(`[ion-input-password-toggle] - Only inputs of type "text" or "password" are supported. Input of type "${newValue}" is not compatible.`, this.el);
- return;
- }
- }
- connectedCallback() {
- const { el } = this;
- const inputElRef = (this.inputElRef = el.closest('ion-input'));
- if (!inputElRef) {
- printIonWarning('[ion-input-password-toggle] - No ancestor ion-input found. This component must be slotted inside of an ion-input.', el);
- return;
- }
- /**
- * Important: Set the type in connectedCallback because the default value
- * of this.type may not always be accurate. Usually inputs have the "password" type
- * but it is possible to have the input to initially have the "text" type. In that scenario
- * the wrong icon will show briefly before switching to the correct icon. Setting the
- * type here allows us to avoid that flicker.
- */
- this.type = inputElRef.type;
- }
- disconnectedCallback() {
- this.inputElRef = null;
- }
- render() {
- var _a, _b;
- const { color, type } = this;
- const mode = getIonMode(this);
- const showPasswordIcon = (_a = this.showIcon) !== null && _a !== void 0 ? _a : eye;
- const hidePasswordIcon = (_b = this.hideIcon) !== null && _b !== void 0 ? _b : eyeOff;
- const isPasswordVisible = type === 'text';
- return (h(Host, { key: '1a28e078c83e74c72d8bb8189ece93ec2e3fa3d0', class: createColorClasses(color, {
- [mode]: true,
- }) }, h("ion-button", { key: '039d1bab764093bb6fe4a34299b0872abda087fd', mode: mode, color: color, fill: "clear", shape: "round", "aria-checked": isPasswordVisible ? 'true' : 'false', "aria-label": "show password", role: "switch", type: "button", onPointerDown: (ev) => {
- /**
- * This prevents mobile browsers from
- * blurring the input when the password toggle
- * button is activated.
- */
- ev.preventDefault();
- }, onClick: this.togglePasswordVisibility }, h("ion-icon", { key: '26477ee97b808c3d79944bf5e33d4e05f1ae0b3f', slot: "icon-only", "aria-hidden": "true", icon: isPasswordVisible ? hidePasswordIcon : showPasswordIcon }))));
- }
- get el() { return this; }
- static get watchers() { return {
- "type": ["onTypeChange"]
- }; }
- static get style() { return {
- ios: IonInputPasswordToggleIosStyle0,
- md: IonInputPasswordToggleMdStyle0
- }; }
- }, [33, "ion-input-password-toggle", {
- "color": [513],
- "showIcon": [1, "show-icon"],
- "hideIcon": [1, "hide-icon"],
- "type": [1025]
- }, undefined, {
- "type": ["onTypeChange"]
- }]);
- function defineCustomElement$1() {
- if (typeof customElements === "undefined") {
- return;
- }
- const components = ["ion-input-password-toggle", "ion-button", "ion-icon", "ion-ripple-effect"];
- components.forEach(tagName => { switch (tagName) {
- case "ion-input-password-toggle":
- if (!customElements.get(tagName)) {
- customElements.define(tagName, InputPasswordToggle);
- }
- break;
- case "ion-button":
- if (!customElements.get(tagName)) {
- defineCustomElement$4();
- }
- break;
- case "ion-icon":
- if (!customElements.get(tagName)) {
- defineCustomElement$3();
- }
- break;
- case "ion-ripple-effect":
- if (!customElements.get(tagName)) {
- defineCustomElement$2();
- }
- break;
- } });
- }
- const IonInputPasswordToggle = InputPasswordToggle;
- const defineCustomElement = defineCustomElement$1;
- export { IonInputPasswordToggle, defineCustomElement };
|