dk-plus
Version:
104 lines (103 loc) • 3.07 kB
JavaScript
import { defineComponent as _, shallowRef as F, reactive as L, ref as i, watch as p } from "vue";
import { dkInputNumberProps as P } from "./index3.js";
import { DK_INPUT_NUMBER_POSITION as I } from "../../_tokens/component/index3.js";
import { getInputNumber as S } from "../../_hooks/get-input-number/index.js";
import "../../_icon/index.js";
const E = _({
name: "DkInputNumber",
props: P,
emits: ["update:modelValue", "change"],
setup(n, { emit: d }) {
const h = F(), b = {
large: 24,
medium: 20,
small: 16,
mini: 12
}, e = L({
step: Number(n.step),
min: n.min,
max: n.max,
size: n.size,
iconSize: b[n.size],
strict: n.strict,
precision: Number(n.precision),
readonly: n.readonly,
placeholder: n.placeholder,
position: n.position
}), V = () => !!e.position && I.includes(e.position) || typeof e.position == "string" ? (e.iconSize -= 2, "IconArrowBottom") : "IconReduce1", g = () => !!e.position && I.includes(e.position) || typeof e.position == "string" ? "IconArrowTop" : "IconAdd1", N = (a) => {
const u = Number(a).toFixed(e.precision);
return parseFloat(u);
}, l = i(n.modelValue), s = i(""), v = i(n.disabled), r = i(l.value <= e.min), c = i(l.value >= e.max), x = () => {
if (e.readonly)
return;
const a = l.value - e.step;
a < e.min ? l.value = e.min : l.value = a;
}, w = () => {
if (e.readonly)
return;
const a = l.value + e.step;
a > e.max ? l.value = e.max : l.value = a;
}, T = (a) => {
const t = a.target, u = Number(t.value);
if (e.strict) {
const D = Math.ceil(u / e.step) * e.step;
l.value = D;
} else
l.value = u;
};
p(
() => n.modelValue,
(a) => {
let t = Number(a);
l.value = t, s.value = a, e.precision > 0 && (s.value = t.toFixed(e.precision));
},
{
immediate: !0
}
), p(
() => l.value,
(a) => {
if (v.value)
return;
let t = a;
r.value = t <= e.min, c.value = t >= e.max, r.value && (t = e.min), c.value && (t = e.max), e.precision && (t = N(t)), d("update:modelValue", t), d("change", t);
}
);
const { classList: y, styleList: M } = S(n);
let m = i(), o = i();
const z = (a, t) => {
t()(), o.value = setTimeout(() => {
o.value && clearTimeout(o.value), m.value = setInterval(() => {
t()();
}, 70);
}, 700);
}, f = () => {
m.value && clearInterval(m.value), o.value && clearTimeout(o.value);
};
return {
...e,
reduce: x,
plus: w,
value: s,
input: h,
classList: y,
styleList: M,
plusDisabled: c,
reduceDisabled: r,
disabled: v,
handleInputChange: T,
handleMouseDown: z,
handleMouseLeave: () => {
f();
},
handleMouseUp: () => {
f();
},
reduceIcon: V(),
plusIcon: g()
};
}
});
export {
E as default
};