tav-ui
Version:
76 lines (73 loc) • 2.9 kB
JavaScript
import { defineComponent, ref, computed, unref, watchEffect, watch, resolveComponent, openBlock, createElementBlock, normalizeClass, createBlock, mergeProps, createSlots, renderList, withCtx, renderSlot, normalizeProps, guardReactiveProps, createCommentVNode, createElementVNode } from 'vue';
import { zxcvbn } from '@zxcvbn-ts/core';
import { Input } from 'ant-design-vue';
import { strengthMeterProps } from './types2.mjs';
import _export_sfc from '../../../../_virtual/plugin-vue_export-helper.mjs';
const _sfc_main = defineComponent({
name: "TaStrengthMeter",
components: { InputPassword: Input.Password },
props: strengthMeterProps,
emits: ["score-change", "change"],
setup(props, { emit }) {
const innerValueRef = ref("");
const prefixCls = "ta-strength-meter";
const getPasswordStrength = computed(() => {
const { disabled } = props;
if (disabled)
return -1;
const innerValue = unref(innerValueRef);
const score = innerValue ? zxcvbn(unref(innerValueRef)).score : -1;
emit("score-change", score);
return score;
});
function handleChange(e) {
innerValueRef.value = e.target.value;
}
watchEffect(() => {
innerValueRef.value = props.value || "";
});
watch(() => unref(innerValueRef), (val) => {
emit("change", val);
});
return {
getPasswordStrength,
handleChange,
prefixCls,
innerValueRef
};
}
});
const _hoisted_1 = ["data-score"];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_InputPassword = resolveComponent("InputPassword");
return openBlock(), createElementBlock("div", {
class: normalizeClass([_ctx.prefixCls, "relative"])
}, [
_ctx.showInput ? (openBlock(), createBlock(_component_InputPassword, mergeProps({ key: 0 }, _ctx.$attrs, {
"allow-clear": "",
value: _ctx.innerValueRef,
disabled: _ctx.disabled,
onChange: _ctx.handleChange
}), createSlots({ _: 2 }, [
renderList(Object.keys(_ctx.$slots), (item) => {
return {
name: item,
fn: withCtx((data) => [
renderSlot(_ctx.$slots, item, normalizeProps(guardReactiveProps(data || {})))
])
};
})
]), 1040, ["value", "disabled", "onChange"])) : createCommentVNode("v-if", true),
createElementVNode("div", {
class: normalizeClass(`${_ctx.prefixCls}-bar`)
}, [
createElementVNode("div", {
class: normalizeClass(`${_ctx.prefixCls}-bar--fill`),
"data-score": _ctx.getPasswordStrength
}, null, 10, _hoisted_1)
], 2)
], 2);
}
var StrengthMeter = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/home/runner/work/tav-ui/tav-ui/packages/components/strength-meter/src/strength-meter.vue"]]);
export { StrengthMeter as default };
//# sourceMappingURL=strength-meter2.mjs.map