UNPKG

tdesign-vue

Version:
354 lines (350 loc) 14.8 kB
/** * tdesign v1.14.1 * (c) 2025 tdesign * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import _slicedToArray from '@babel/runtime/helpers/slicedToArray'; import { defineComponent, getCurrentInstance, toRefs, ref, computed } from '@vue/composition-api'; import { CloseCircleFilledIcon } from 'tdesign-icons-vue'; import { Input } from '../input/index.js'; import props from './props.js'; import { useVModel } from '../hooks/useVModel.js'; import { useGlobalIcon } from '../hooks/useGlobalIcon.js'; import { useCommonClassName, usePrefixClass } from '../hooks/useConfig.js'; import { useTNodeJSX } from '../hooks/tnode.js'; import '../input/input.js'; import '../_chunks/dep-6a4dc7bb.js'; import '@babel/runtime/helpers/toConsumableArray'; import '@babel/runtime/helpers/typeof'; import 'lodash-es'; import '../_common/js/utils/helper.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '../utils/helper.js'; import '../config-provider/config-receiver.js'; import 'vue'; import '../config-provider/context.js'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/zh_CN.js'; import '../_chunks/dep-ba613a02.js'; import '../_chunks/dep-fdb1b253.js'; import 'dayjs'; import '../_common/js/global-config/t.js'; import '../utils/mixins.js'; import '../utils/event.js'; import '../input/props.js'; import '../utils/render-tnode.js'; import '@babel/runtime/helpers/readOnlyError'; import '../_common/js/log/log.js'; import '../input/input-group.js'; import '../utils/map-props.js'; import '../utils/withInstall.js'; import '../config-provider/useConfig.js'; import '../hooks/render-tnode.js'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function calcArrayValue(value) { if (Array.isArray(value)) { return value; } return [value, value]; } var _RangeInput = defineComponent({ name: "TRangeInput", props: props, setup: function setup(props2) { var instance = getCurrentInstance(); var _toRefs = toRefs(props2), value = _toRefs.value; var _useCommonClassName = useCommonClassName(), STATUS = _useCommonClassName.STATUS, SIZE = _useCommonClassName.SIZE; var classPrefix = usePrefixClass(); var _useGlobalIcon = useGlobalIcon({ CloseCircleFilledIcon: CloseCircleFilledIcon }), CloseCircleFilledIcon$1 = _useGlobalIcon.CloseCircleFilledIcon; var COMPONENT_NAME = usePrefixClass("range-input"); var renderTNodeJSX = useTNodeJSX(); var focused = ref(false); var isHover = ref(false); var calcFormat = computed(function () { return calcArrayValue(props2.format); }); var calcInputProps = computed(function () { return calcArrayValue(props2.inputProps); }); var calcPlaceholder = computed(function () { return calcArrayValue(props2.placeholder); }); var _useVModel = useVModel(value, props2.defaultValue, props2.onChange, "change"), _useVModel2 = _slicedToArray(_useVModel, 2), innerValue = _useVModel2[0], setInnerValue = _useVModel2[1]; var isShowClearIcon = computed(function () { var _props2$value; return (props2.clearable && ((_props2$value = props2.value) === null || _props2$value === void 0 ? void 0 : _props2$value.length) && !props2.disabled || props2.showClearIconOnEmpty) && isHover.value; }); var inputRefs = { firstInputRef: ref(), secondInputRef: ref() }; function handleClear(context) { var _props2$onClear; (_props2$onClear = props2.onClear) === null || _props2$onClear === void 0 || _props2$onClear.call(props2, context); } function handleEnter(rangeValue, context) { var _props2$onEnter; (_props2$onEnter = props2.onEnter) === null || _props2$onEnter === void 0 || _props2$onEnter.call(props2, rangeValue, context); instance.emit("enter", rangeValue, context); } function handleFocus(rangeValue, context) { var _props2$onFocus; focused.value = true; (_props2$onFocus = props2.onFocus) === null || _props2$onFocus === void 0 || _props2$onFocus.call(props2, rangeValue, context); instance.emit("focus", rangeValue, context); } function handleBlur(rangeValue, context) { var _props2$onBlur; focused.value = false; (_props2$onBlur = props2.onBlur) === null || _props2$onBlur === void 0 || _props2$onBlur.call(props2, rangeValue, context); instance.emit("blur", rangeValue, context); } function handleMouseEnter(e) { var _props2$onMouseenter; isHover.value = true; props2 === null || props2 === void 0 || (_props2$onMouseenter = props2.onMouseenter) === null || _props2$onMouseenter === void 0 || _props2$onMouseenter.call(props2, { e: e }); instance.emit("monseenter", { e: e }); } function handleMouseLeave(e) { var _props2$onMouseleave; isHover.value = false; props2 === null || props2 === void 0 || (_props2$onMouseleave = props2.onMouseleave) === null || _props2$onMouseleave === void 0 || _props2$onMouseleave.call(props2, { e: e }); instance.emit("monseleave", { e: e }); } var exposeObj = { firstInputElement: inputRefs.firstInputRef.value, secondInputElement: inputRefs.secondInputRef.value, focus: function focus(options) { var _inputRefs$value; var _ref = options || {}, _ref$position = _ref.position, position = _ref$position === void 0 ? "first" : _ref$position; (_inputRefs$value = inputRefs["".concat(position, "InputRef")].value) === null || _inputRefs$value === void 0 || _inputRefs$value.focus(); }, blur: function blur(options) { var _inputRefs$value2; var _ref2 = options || {}, _ref2$position = _ref2.position, position = _ref2$position === void 0 ? "first" : _ref2$position; (_inputRefs$value2 = inputRefs["".concat(position, "InputRef")].value) === null || _inputRefs$value2 === void 0 || _inputRefs$value2.blur(); }, select: function select(options) { var _inputRefs$value3; var _ref3 = options || {}, _ref3$position = _ref3.position, position = _ref3$position === void 0 ? "first" : _ref3$position; (_inputRefs$value3 = inputRefs["".concat(position, "InputRef")].value) === null || _inputRefs$value3 === void 0 || _inputRefs$value3.select(); } }; return _objectSpread(_objectSpread({}, exposeObj), {}, { COMPONENT_NAME: COMPONENT_NAME, SIZE: SIZE, STATUS: STATUS, focused: focused, classPrefix: classPrefix, inputRefs: inputRefs, calcInputProps: calcInputProps, calcFormat: calcFormat, calcPlaceholder: calcPlaceholder, innerValue: innerValue, isShowClearIcon: isShowClearIcon, handleMouseEnter: handleMouseEnter, handleMouseLeave: handleMouseLeave, handleEnter: handleEnter, handleFocus: handleFocus, handleBlur: handleBlur, setInnerValue: setInnerValue, renderTNodeJSX: renderTNodeJSX, handleClear: handleClear, CloseCircleFilledIcon: CloseCircleFilledIcon$1 }); }, render: function render() { var _this = this; var h = arguments[0]; var COMPONENT_NAME = this.COMPONENT_NAME, SIZE = this.SIZE, STATUS = this.STATUS, focused = this.focused, handleMouseEnter = this.handleMouseEnter, handleMouseLeave = this.handleMouseLeave, handleEnter = this.handleEnter, handleFocus = this.handleFocus, handleBlur = this.handleBlur, setInnerValue = this.setInnerValue, renderTNodeJSX = this.renderTNodeJSX, handleClear = this.handleClear, classPrefix = this.classPrefix, inputRefs = this.inputRefs, calcInputProps = this.calcInputProps, calcFormat = this.calcFormat, calcPlaceholder = this.calcPlaceholder, innerValue = this.innerValue, isShowClearIcon = this.isShowClearIcon, CloseCircleFilledIcon = this.CloseCircleFilledIcon; var labelContent = renderTNodeJSX("label"); var prefixIconContent = renderTNodeJSX("prefixIcon"); var suffixContent = renderTNodeJSX("suffix"); var suffixIconContent = renderTNodeJSX("suffixIcon"); var tips = renderTNodeJSX("tips"); return h("div", { "class": [COMPONENT_NAME, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, SIZE[this.size], this.size !== "medium"), STATUS.disabled, this.disabled), STATUS.focused, focused), STATUS.success, this.status === "success"), STATUS.warning, this.status === "warning"), STATUS.error, this.status === "error"), "".concat(COMPONENT_NAME, "--prefix"), prefixIconContent || labelContent), "".concat(COMPONENT_NAME, "--suffix"), suffixIconContent || suffixContent), "".concat(COMPONENT_NAME, "--borderless"), this.borderless)], "on": { "mouseenter": handleMouseEnter, "mouseleave": handleMouseLeave } }, [h("div", { "class": "".concat(COMPONENT_NAME, "__inner") }, [prefixIconContent, labelContent ? h("div", { "class": "".concat(classPrefix, "-input__prefix") }, [labelContent]) : null, h(Input, { "ref": inputRefs.firstInputRef, "class": "".concat(COMPONENT_NAME, "__inner-left"), "attrs": { "inputClass": _defineProperty({}, "".concat(classPrefix, "-is-focused"), this.activeIndex === 0), "placeholder": calcPlaceholder[0], "disabled": this.disabled, "readonly": this.readonly, "format": calcFormat[0], "value": innerValue === null || innerValue === void 0 ? void 0 : innerValue[0] }, "on": { "click": function click(_ref6) { var _this$onClick; var e = _ref6.e; return (_this$onClick = _this.onClick) === null || _this$onClick === void 0 ? void 0 : _this$onClick.call(_this, { e: e, position: "first" }); }, "clear": function clear() { return setInnerValue([], { position: "first", trigger: "input" }); }, "enter": function enter(val, _ref7) { var e = _ref7.e; return handleEnter([val, innerValue === null || innerValue === void 0 ? void 0 : innerValue[1]], { e: e, position: "first" }); }, "focus": function focus(val, _ref8) { var e = _ref8.e; return handleFocus([val, innerValue === null || innerValue === void 0 ? void 0 : innerValue[1]], { e: e, position: "first" }); }, "blur": function blur(val, _ref9) { var e = _ref9.e; return handleBlur([val, innerValue === null || innerValue === void 0 ? void 0 : innerValue[1]], { e: e, position: "first" }); }, "change": function change(val, _ref0) { var e = _ref0.e; return setInnerValue([val, innerValue === null || innerValue === void 0 ? void 0 : innerValue[1]], { e: e, position: "first", trigger: "input" }); } }, "props": _objectSpread({}, calcInputProps[0]) }), h("div", { "class": "".concat(COMPONENT_NAME, "__inner-separator") }, [this.separator]), h(Input, { "ref": inputRefs.secondInputRef, "class": "".concat(COMPONENT_NAME, "__inner-right"), "attrs": { "inputClass": _defineProperty({}, "".concat(classPrefix, "-is-focused"), this.activeIndex === 1), "placeholder": calcPlaceholder[1], "disabled": this.disabled, "readonly": this.readonly, "format": calcFormat[1], "value": innerValue === null || innerValue === void 0 ? void 0 : innerValue[1] }, "on": { "click": function click(_ref10) { var _this$onClick2; var e = _ref10.e; return (_this$onClick2 = _this.onClick) === null || _this$onClick2 === void 0 ? void 0 : _this$onClick2.call(_this, { e: e, position: "second" }); }, "clear": function clear() { return setInnerValue([], { position: "second", trigger: "input" }); }, "enter": function enter(val, _ref11) { var e = _ref11.e; return handleEnter([innerValue === null || innerValue === void 0 ? void 0 : innerValue[0], val], { e: e, position: "second" }); }, "focus": function focus(val, _ref12) { var e = _ref12.e; return handleFocus([innerValue === null || innerValue === void 0 ? void 0 : innerValue[0], val], { e: e, position: "second" }); }, "blur": function blur(val, _ref13) { var e = _ref13.e; return handleBlur([innerValue === null || innerValue === void 0 ? void 0 : innerValue[0], val], { e: e, position: "second" }); }, "change": function change(val, _ref14) { var e = _ref14.e; return setInnerValue([innerValue === null || innerValue === void 0 ? void 0 : innerValue[0], val], { e: e, position: "second", trigger: "input" }); } }, "props": _objectSpread({}, calcInputProps[1]) }), suffixContent ? h("div", { "class": "".concat(COMPONENT_NAME, "__suffix") }, [suffixContent]) : null, suffixIconContent && h("span", { "class": "".concat(COMPONENT_NAME, "__suffix ").concat(COMPONENT_NAME, "__suffix-icon") }, [isShowClearIcon ? h(CloseCircleFilledIcon, { "class": "".concat(COMPONENT_NAME, "__suffix-clear"), "on": { "click": handleClear } }) : suffixIconContent])]), tips && h("div", { "class": "".concat(COMPONENT_NAME, "__tips") }, [tips])]); } }); export { _RangeInput as default }; //# sourceMappingURL=range-input.js.map