@vuesax-alpha/nightly
Version:
A Component Library for Vue 3
90 lines (85 loc) • 2.14 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
require('../../../../constants/index.js');
var useInputEvent = require('./use-input-event.js');
var useInputClearable = require('./use-input-clearable.js');
var event = require('../../../../constants/event.js');
const useInput = (props, emit) => {
const model = vue.computed({
get: () => props.modelValue,
set: (value) => {
if (props.disabled || props.loading)
return;
emit(event.UPDATE_MODEL_EVENT, value);
}
});
const hovering = vue.ref(false);
const inputRef = vue.shallowRef();
const isVisiblePassword = vue.ref(false);
const {
blur,
handleBlur,
handleInput,
handleChange,
focused,
focus,
handleFocus,
select,
handleKeydown
} = useInputEvent.useInputEvent({ inputRef });
const { clear, showClear } = useInputClearable.useInputClearable(props, { hovering, focused });
const handleMouseLeave = (evt) => {
hovering.value = false;
emit("mouseleave", evt);
};
const handleMouseEnter = (evt) => {
hovering.value = true;
emit("mouseenter", evt);
};
const inputType = vue.computed(() => {
if (props.showPassword) {
if (!isVisiblePassword.value)
return "password";
return "text";
}
return props.type;
});
const clickIcon = (evs) => {
focus();
emit("clickIcon", evs);
};
const isShowPassword = vue.computed(
() => props.showPassword && !props.disabled && !props.loading && String(props.modelValue)
);
const handleShowPassword = () => {
if (props.disabled || props.loading)
return;
isVisiblePassword.value = !isVisiblePassword.value;
};
return {
model,
inputType,
isVisiblePassword,
inputRef,
isShowPassword,
focused,
hovering,
handleInput,
focus,
handleFocus,
handleKeydown,
blur,
handleBlur,
handleChange,
select,
clickIcon,
handleShowPassword,
handleMouseLeave,
handleMouseEnter,
clear,
showClear
};
};
exports.useInput = useInput;
//# sourceMappingURL=use-input.js.map