dk-plus
Version:
169 lines (168 loc) • 5.78 kB
JavaScript
import { toRaw as H, useSlots as J, computed as y, reactive as k } from "vue";
import { DK_INPUT_STATUS as $, DK_INPUT_PERSONALITY_TYPE as Q } from "../../_tokens/component/index.js";
import { getColor as c } from "../public/get-color/index.js";
import { getStyleList as I } from "../public/get-StyleList/index.js";
import { setSize as f } from "../public/set-size/index.js";
import "../../_icon/index.js";
const ae = (e) => {
let n = ["type", "size", "personality", "personalityType"];
const t = { ...H(e) }, s = J(), l = e.prependText || e.prependIcon || s.prepend, r = e.appendText || e.appendIcon || s.append;
!t.personality && r && l ? (t.appendText = "wrapper-pend_text", t.prependText = "") : (!t.personality && r && (t.appendText = "wrapper-append_text"), !t.personality && l && (t.prependText = "wrapper-prepend_text"));
const i = t;
y(() => t.disabled).value && (n = [...n, "disabled"]);
let g = "input";
t.personality && Q.includes(t.personalityType) && (g = "input-personality");
const { classes: L } = I(i, g), R = L([...n], "dk-" + g), E = y(() => {
const {
width: d,
height: h,
fontSize: w,
borderRadius: T,
textColor: C,
iconSize: S,
align: W,
borderColor: j,
focusBorderColor: q,
border: v,
labelText: F
} = t;
let p = j, P = q;
const B = {
warning: "#faad14",
error: "#ff4d4f"
};
t.status && $.includes(t.status) && (p = B[t.status], P = B[t.status]);
let _ = "transparent", z = "transparent", A = "transparent";
((G) => {
G !== "none" && (_ = p ? c(p).getDodge(0) : null, z = p ? c(p).getDodge(0.4) : null, A = P ? c(P).getDodge(0) : null);
})(v);
const o = {
"--input-align": W || "left"
};
return F && (o["--input-margin-top"] = w ? f(w) : "18px"), P && (o["--input-focus-border"] = A), p && (o["--input-border"] = _, o["--input-hover-border"] = z), d && (o["--input-width"] = f(d)), h && (o["--input-height"] = f(h)), w && (o["--input-font-size"] = f(w)), T && (o["--input-border-radius"] = f(T)), C && (o["--input-text-color"] = c(C).getDeepen(0)), S && (o["--input-icon-size"] = f(S)), o;
});
let b = ["appendText", "prependText", "readonly"];
t.status && $.includes(t.status) && (b = [...b, "status"]);
const N = L(
[...b],
`dk-${g}-wrapper`
), O = I(i, "input").classes, U = O(
[...[]],
`dk-${g}_inner`
), K = ["clearable"], V = I(i, "input").classes, Y = V([...K], "dk-input"), M = y(() => {
const { appendBackground: d, appendColor: h } = t;
return {
"--pend-background": d ? c(d).getDeepen(0) : null,
"--pend-hover-background": d ? c(d).getDeepen(0.4) : null,
"--pend-color": h ? c(h).getDeepen(0) : null
};
});
return {
classList: R,
styleList: E,
wrapperClassList: N,
innerClassList: U,
clearableClassList: Y,
pendStyleList: M
};
}, a = (e) => e.length == 0 ? !1 : e.find((t) => !t) === void 0, u = (e) => e.length == 0 ? !1 : e.find((t) => t) !== void 0, x = (e) => {
if (!e)
return !1;
if (Array.isArray(e)) {
if (e.length === 0)
return !1;
} else if (e = e.toString().trim(), typeof e == "string" && e.length === 0)
return !1;
return !0;
}, de = (e, n) => {
let t = e;
return e === "password" ? n ? t = "text" : t = "password" : t = e, t;
}, X = (e, n, t) => {
const s = u([x(e), x(n)]);
return a([s, !t]);
}, Z = (e, n, t) => a([!n, t !== "textarea", t !== "password", e]), ce = (e, n, t, s, l) => {
typeof e == "number" && (e = e.toString());
let r = e;
if (n && !t) {
const i = new RegExp(`^${n}`);
r = r.replace(i, "");
}
if (s && !l) {
const i = new RegExp(`${s}$`);
r = r.replace(i, "");
}
return r;
}, pe = (e, n, t, s, l) => {
typeof e == "number" && (e = e.toString());
let r = e;
return n && !t && (new RegExp(`^${n}`).test(e) || (r = n + e)), s && !l && (new RegExp(`${s}$`).test(e) || (r = r + s)), r;
}, D = (e, n) => {
if (!e.showLengthProp)
return !1;
let s = !1;
const i = u([n === "textarea", n === "text"]), m = !e.maxlengthProp;
return s = a([i, m]), s;
}, fe = (e, n, t) => k({
isPrepend: u([
!!n.prepend,
x(e.prependText),
!!e.prependIcon
]),
isPrependIcon: a([x(e.prependIcon), !n.prepend]),
isAppendIcon: a([!n.append, !!e.appendIcon]),
isAppend: u([
!!n.append,
x(e.appendText),
!!e.appendIcon
]),
isPrefixIcon: a([!!e.prefixIcon, !n.prefix]),
isAppendTextLen: x(e.appendText),
isPrefix: u([!!n.prefix, !!e.prefixIcon]),
isClear: Z(e.clearable, e.disabledProp, t),
inputmode: t === "number" ? "numeric" : "text",
isSuffix: u([!!n.suffix, !!e.suffixIcon]),
isSuffixIcon: a([!!e.suffixIcon, !n.suffix]),
isShowPassword: a([t === "password", e.showPassword]),
isLength: X(
e.maxlengthProp,
e.minlengthProp,
e.disabledProp
),
rows: e.rowsProp || 2,
showLength: D(e, t),
labelText: e.labelTextProp,
personality: e.personalityProp
}), ue = (e) => k({
prependText: e.prependText,
appendText: e.appendText,
placeholder: e.placeholder,
clearable: e.clearable,
showPassword: e.showPassword,
prependIcon: e.prependIcon,
appendIcon: e.appendIcon,
disabledProp: e.disabled,
typeProp: e.type,
prefixIcon: e.prefixIcon,
suffixIcon: e.suffixIcon,
maxlengthProp: e.maxlength,
minlengthProp: e.minlength,
autosizeProp: e.autosize,
rowsProp: e.rows,
readonlyProp: e.readonly,
showLengthProp: e.showLength,
labelTextProp: e.labelText,
personalityProp: e.personality
});
export {
a as getBooleanAnd,
u as getBooleanOr,
ae as getInput,
Z as getIsClear,
x as getNull,
pe as getPendValue,
ce as getValue,
X as isShowLength,
fe as setData,
ue as setPropData,
de as verifyInputType
};