UNPKG

@shopware-ag/meteor-component-library

Version:

The meteor component library is a Vue component library developed by Shopware. It is based on the [Meteor Design System](https://shopware.design/).

159 lines (158 loc) 6.54 kB
import '../mt-password-field.css'; import { defineComponent, mergeModels, useModel, ref, openBlock, createBlock, withCtx, createTextVNode, toDisplayString, renderSlot, createElementVNode, withModifiers, withKeys, createElementBlock, unref, createVNode, createCommentVNode } from "vue"; import { M as MtBaseField } from "../mt-base-field-7a978dcf.mjs"; import MtFieldError from "./MtFieldError.js"; import { _ as _sfc_main$1 } from "../mt-icon.vue_vue_type_style_index_0_lang-2cc5f73e.mjs"; import { useI18n } from "vue-i18n"; import { _ as _export_sfc } from "../_plugin-vue_export-helper-cc2b3d55.mjs"; import "./MtInheritanceSwitch.js"; import "./MtTooltip.js"; import "../floating-ui.vue-fe27ebef.mjs"; import "../floating-ui.dom-f450fda4.mjs"; import "../useIsInsideTooltip-0c3bd290.mjs"; import "../index-221bad05.mjs"; import "./MtFieldCopyable.js"; import "../tooltip.directive-a5042569.mjs"; import "../id-1e5b8276.mjs"; import "./MtHelpText.js"; import "../useFutureFlags-2be3e179.mjs"; import "./MtText.js"; const _hoisted_1 = ["id", "type", "name", "placeholder", "disabled", "value", "aria-label"]; const _hoisted_2 = ["aria-label", "disabled"]; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "mt-password-field", props: /* @__PURE__ */ mergeModels({ label: { default: null }, placeholder: { default: "" }, disabled: { type: Boolean }, error: { default: null }, hint: { default: null }, toggable: { type: Boolean, default: true }, name: { default: void 0 }, required: { type: Boolean, default: false }, helpText: { default: "" }, size: { default: "default" }, isInherited: { type: Boolean, default: false }, isInheritanceField: { type: Boolean, default: false }, disableInheritanceToggle: { type: Boolean, default: false }, idSuffix: { default: "" } }, { "modelValue": {}, "modelModifiers": {} }), emits: /* @__PURE__ */ mergeModels(["change", "submit", "inheritance-restore", "inheritance-remove", "update:modelValue"], ["update:modelValue"]), setup(__props, { emit: __emit }) { const model = useModel(__props, "modelValue"); const props = __props; const emit = __emit; const showPassword = ref(false); const hasFocus = ref(false); function onInput(event) { const target = event.target; emit("update:modelValue", target == null ? void 0 : target.value); } function onChange(event) { const target = event.target; emit("change", target == null ? void 0 : target.value); } function setFocus() { hasFocus.value = true; } function removeFocus() { hasFocus.value = false; } function createInputId(identification) { if (!props.idSuffix || props.idSuffix.length <= 0) { return identification; } return `${identification}-${props.idSuffix}`; } const { t } = useI18n({ messages: { en: { showPassword: "Show password", hidePassword: "Hide password" }, de: { showPassword: "Passwort anzeigen", hidePassword: "Passwort verbergen" } } }); return (_ctx, _cache) => { return openBlock(), createBlock(MtBaseField, { class: "mt-password-field", disabled: _ctx.disabled, required: _ctx.required, "is-inherited": _ctx.isInherited, "is-inheritance-field": _ctx.isInheritanceField, "disable-inheritance-toggle": _ctx.disableInheritanceToggle, "has-focus": hasFocus.value, "help-text": _ctx.helpText, name: _ctx.name, size: _ctx.size, onInheritanceRestore: _cache[2] || (_cache[2] = ($event) => _ctx.$emit("inheritance-restore", $event)), onInheritanceRemove: _cache[3] || (_cache[3] = ($event) => _ctx.$emit("inheritance-remove", $event)) }, { label: withCtx(() => [ createTextVNode(toDisplayString(_ctx.label), 1) ]), "field-prefix": withCtx(() => [ renderSlot(_ctx.$slots, "prefix", {}, void 0, true) ]), element: withCtx(({ identification }) => [ createElementVNode("input", { id: createInputId(identification), type: showPassword.value ? "text" : "password", name: identification, placeholder: _ctx.placeholder, disabled: _ctx.disabled || _ctx.isInherited, value: model.value ?? "", "aria-label": _ctx.label || void 0, class: "mt-password-field__input", onInput, onChange: withModifiers(onChange, ["stop"]), onKeyup: _cache[0] || (_cache[0] = withKeys(($event) => _ctx.$emit("submit"), ["enter"])), onFocus: setFocus, onBlur: removeFocus }, null, 40, _hoisted_1), _ctx.toggable ? (openBlock(), createElementBlock("button", { key: 0, type: "button", class: "mt-password-field__visibility-toggle", "aria-label": showPassword.value ? unref(t)("hidePassword") : unref(t)("showPassword"), disabled: _ctx.disabled || _ctx.isInherited, onClick: _cache[1] || (_cache[1] = withModifiers(($event) => showPassword.value = !showPassword.value, ["prevent"])) }, [ createVNode(_sfc_main$1, { name: showPassword.value ? "solid-eye-slash" : "solid-eye", size: "1.125rem", "aria-hidden": "true" }, null, 8, ["name"]) ], 8, _hoisted_2)) : createCommentVNode("", true) ]), "field-suffix": withCtx(() => [ renderSlot(_ctx.$slots, "suffix", {}, void 0, true) ]), error: withCtx(() => [ !!_ctx.error ? (openBlock(), createBlock(MtFieldError, { key: 0, error: _ctx.error }, null, 8, ["error"])) : createCommentVNode("", true) ]), "field-hint": withCtx(() => [ renderSlot(_ctx.$slots, "hint", {}, () => [ createTextVNode(toDisplayString(_ctx.hint), 1) ], true) ]), _: 3 }, 8, ["disabled", "required", "is-inherited", "is-inheritance-field", "disable-inheritance-toggle", "has-focus", "help-text", "name", "size"]); }; } }); const mtPasswordField_vue_vue_type_style_index_0_scoped_4c5260c9_lang = ""; const mtPasswordField = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-4c5260c9"]]); export { mtPasswordField as default }; //# sourceMappingURL=MtPasswordField.js.map