@lanaco/lnc-react-ui
Version:
React component library
679 lines (671 loc) • 25.5 kB
JavaScript
import { jsxs as ae, jsx as U } from "react/jsx-runtime";
import O, { forwardRef as ie, useState as oe, useCallback as ne } from "react";
import { d as se } from "./index-Dt62UGku.js";
import { s as G } from "./emotion-styled.browser.esm-DfbrHHed.js";
import { e as k, c as N, b as fe, f as ue, i as W, d as le } from "./utils-BUdHa0nB.js";
import { u as ce } from "./emotion-element-f0de968e.browser.esm-CkCiQliQ.js";
function R() {
}
function pe() {
return !0;
}
function V(r) {
return !!(r || "").match(/\d/);
}
function z(r) {
return r == null;
}
function Z(r) {
return r.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&");
}
function de(r) {
switch (r) {
case "lakh":
return /(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/g;
case "wan":
return /(\d)(?=(\d{4})+(?!\d))/g;
case "thousand":
default:
return /(\d)(?=(\d{3})+(?!\d))/g;
}
}
function me(r, s, l) {
var e = de(l), t = r.search(/[1-9]/);
return t = t === -1 ? r.length : t, r.substring(0, t) + r.substring(t, r.length).replace(e, "$1" + s);
}
function K(r, s) {
s === void 0 && (s = !0);
var l = r[0] === "-", e = l && s;
r = r.replace("-", "");
var t = r.split("."), a = t[0], o = t[1] || "";
return {
beforeDecimal: a,
afterDecimal: o,
hasNagation: l,
addNegation: e
};
}
function he(r) {
if (!r)
return r;
var s = r[0] === "-";
s && (r = r.substring(1, r.length));
var l = r.split("."), e = l[0].replace(/^0+/, "") || "0", t = l[1] || "";
return (s ? "-" : "") + e + (t ? "." + t : "");
}
function J(r, s, l) {
for (var e = "", t = l ? "0" : "", a = 0; a <= s - 1; a++)
e += r[a] || t;
return e;
}
function _(r, s) {
return Array(s + 1).join(r);
}
function ve(r) {
r += "";
var s = r[0] === "-" ? "-" : "";
s && (r = r.substring(1));
var l = r.split(/[eE]/g), e = l[0], t = l[1];
if (t = Number(t), !t)
return s + e;
e = e.replace(".", "");
var a = 1 + t, o = e.length;
return a < 0 ? e = "0." + _("0", Math.abs(a)) + e : a >= o ? e = e + _("0", a - o) : e = (e.substring(0, a) || "0") + "." + e.substring(a), s + e;
}
function ge(r, s, l) {
if (["", "-"].indexOf(r) !== -1)
return r;
var e = r.indexOf(".") !== -1 && s, t = K(r), a = t.beforeDecimal, o = t.afterDecimal, f = t.hasNagation, i = parseFloat("0." + (o || "0")), n = o.length <= s ? "0." + o : i.toFixed(s), u = n.split("."), p = a.split("").reverse().reduce(function(m, g, x) {
return m.length > x ? (Number(m[0]) + Number(g)).toString() + m.substring(1, m.length) : g + m;
}, u[0]), c = J(
u[1] || "",
Math.min(s, o.length),
l
), d = f ? "-" : "", h = e ? "." : "";
return "" + d + p + h + c;
}
function q(r, s) {
if (r.value = r.value, r !== null) {
if (r.createTextRange) {
var l = r.createTextRange();
return l.move("character", s), l.select(), !0;
}
return r.selectionStart || r.selectionStart === 0 ? (r.focus(), r.setSelectionRange(s, s), !0) : (r.focus(), !1);
}
}
function Se(r, s) {
for (var l = 0, e = 0, t = r.length, a = s.length; r[l] === s[l] && l < t; )
l++;
for (; r[t - 1 - e] === s[a - 1 - e] && a - e > l && t - e > l; )
e++;
return { start: l, end: t - e };
}
function L(r, s, l) {
return Math.min(Math.max(r, s), l);
}
function H(r) {
return Math.max(r.selectionStart, r.selectionEnd);
}
function xe(r) {
return r || typeof navigator < "u" && !(navigator.platform && /iPhone|iPod/.test(navigator.platform));
}
function ye(r, s) {
var l = {};
for (var e in r) Object.prototype.hasOwnProperty.call(r, e) && s.indexOf(e) === -1 && (l[e] = r[e]);
return l;
}
var be = {
displayType: "input",
decimalSeparator: ".",
thousandsGroupStyle: "thousand",
fixedDecimalScale: !1,
prefix: "",
suffix: "",
allowNegative: !0,
allowEmptyFormatting: !1,
allowLeadingZeros: !1,
isNumericString: !1,
type: "text",
onValueChange: R,
onChange: R,
onKeyDown: R,
onMouseUp: R,
onFocus: R,
onBlur: R,
isAllowed: pe
}, Q = /* @__PURE__ */ function(r) {
function s(l) {
r.call(this, l);
var e = l.defaultValue;
this.validateProps();
var t = this.formatValueProp(e);
this.state = {
value: t,
numAsString: this.removeFormatting(t),
mounted: !1
}, this.selectionBeforeInput = {
selectionStart: 0,
selectionEnd: 0
}, this.onChange = this.onChange.bind(this), this.onKeyDown = this.onKeyDown.bind(this), this.onMouseUp = this.onMouseUp.bind(this), this.onFocus = this.onFocus.bind(this), this.onBlur = this.onBlur.bind(this);
}
return r && (s.__proto__ = r), s.prototype = Object.create(r && r.prototype), s.prototype.constructor = s, s.prototype.componentDidMount = function() {
this.setState({
mounted: !0
});
}, s.prototype.componentDidUpdate = function(e) {
this.updateValueIfRequired(e);
}, s.prototype.componentWillUnmount = function() {
clearTimeout(this.focusTimeout), clearTimeout(this.caretPositionTimeout);
}, s.prototype.updateValueIfRequired = function(e) {
var t = this, a = t.props, o = t.state, f = t.focusedElm, i = o.value, n = o.numAsString;
if (n === void 0 && (n = ""), e !== a) {
this.validateProps();
var u = this.formatNumString(n), p = z(a.value) ? u : this.formatValueProp(), c = this.removeFormatting(p), d = parseFloat(c), h = parseFloat(n);
//while typing set state only when float value changes
((!isNaN(d) || !isNaN(h)) && d !== h || //can also set state when float value is same and the format props changes
u !== i || //set state always when not in focus and formatted value is changed
f === null && p !== i) && this.updateValue({
formattedValue: p,
numAsString: c,
input: f,
source: "prop",
event: null
});
}
}, s.prototype.getFloatString = function(e) {
e === void 0 && (e = "");
var t = this.props, a = t.decimalScale, o = this.getSeparators(), f = o.decimalSeparator, i = this.getNumberRegex(!0), n = e[0] === "-";
n && (e = e.replace("-", "")), f && a === 0 && (e = e.split(f)[0]), e = (e.match(i) || []).join("").replace(f, ".");
var u = e.indexOf(".");
return u !== -1 && (e = e.substring(0, u) + "." + e.substring(u + 1, e.length).replace(new RegExp(Z(f), "g"), "")), n && (e = "-" + e), e;
}, s.prototype.getNumberRegex = function(e, t) {
var a = this.props, o = a.format, f = a.decimalScale, i = a.customNumerals, n = this.getSeparators(), u = n.decimalSeparator;
return new RegExp(
"[0-9" + (i ? i.join("") : "") + "]" + (u && f !== 0 && !t && !o ? "|" + Z(u) : ""),
e ? "g" : void 0
);
}, s.prototype.getSeparators = function() {
var e = this.props, t = e.decimalSeparator, a = this.props, o = a.thousandSeparator, f = a.allowedDecimalSeparators;
return o === !0 && (o = ","), f || (f = [t, "."]), {
decimalSeparator: t,
thousandSeparator: o,
allowedDecimalSeparators: f
};
}, s.prototype.getMaskAtIndex = function(e) {
var t = this.props, a = t.mask;
return a === void 0 && (a = " "), typeof a == "string" ? a : a[e] || " ";
}, s.prototype.getValueObject = function(e, t) {
var a = parseFloat(t);
return {
formattedValue: e,
value: t,
floatValue: isNaN(a) ? void 0 : a
};
}, s.prototype.validateProps = function() {
var e = this.props, t = e.mask, a = this.getSeparators(), o = a.decimalSeparator, f = a.thousandSeparator;
if (o === f)
throw new Error(`
Decimal separator can't be same as thousand separator.
thousandSeparator: ` + f + ` (thousandSeparator = {true} is same as thousandSeparator = ",")
decimalSeparator: ` + o + ` (default value for decimalSeparator is .)
`);
if (t) {
var i = t === "string" ? t : t.toString();
if (i.match(/\d/g))
throw new Error(`
Mask ` + t + ` should not contain numeric character;
`);
}
}, s.prototype.setPatchedCaretPosition = function(e, t, a) {
q(e, t), this.caretPositionTimeout = setTimeout(function() {
e.value === a && q(e, t);
}, 0);
}, s.prototype.correctCaretPosition = function(e, t, a) {
var o = this.props, f = o.prefix, i = o.suffix, n = o.format;
if (e === "")
return 0;
if (t = L(t, 0, e.length), !n) {
var u = e[0] === "-";
return L(t, f.length + (u ? 1 : 0), e.length - i.length);
}
if (typeof n == "function" || n[t] === "#" && V(e[t]) || n[t - 1] === "#" && V(e[t - 1]))
return t;
var p = n.indexOf("#"), c = n.lastIndexOf("#");
t = L(t, p, c + 1);
for (var d = n.substring(t, n.length).indexOf("#"), h = t, m = t + (d === -1 ? 0 : d); h > p && (n[h] !== "#" || !V(e[h])); )
h -= 1;
var g = !V(e[m]) || a === "left" && t !== p || t - h < m - t;
return g ? V(e[h]) ? h + 1 : h : m;
}, s.prototype.getCaretPosition = function(e, t, a) {
var o = this.props, f = o.format, i = this.state.value, n = this.getNumberRegex(!0), u = (e.match(n) || []).join(""), p = (t.match(n) || []).join(""), c, d;
for (c = 0, d = 0; d < a; d++) {
var h = e[d] || "", m = t[c] || "";
if (!(!h.match(n) && h !== m) && !(h === "0" && m.match(n) && m !== "0" && u.length !== p.length)) {
for (; h !== t[c] && c < t.length; )
c++;
c++;
}
}
return typeof f == "string" && !i && (c = t.length), c = this.correctCaretPosition(t, c), c;
}, s.prototype.removePrefixAndSuffix = function(e) {
var t = this.props, a = t.format, o = t.prefix, f = t.suffix;
if (!a && e) {
var i = e[0] === "-";
i && (e = e.substring(1, e.length)), e = o && e.indexOf(o) === 0 ? e.substring(o.length, e.length) : e;
var n = e.lastIndexOf(f);
e = f && n !== -1 && n === e.length - f.length ? e.substring(0, n) : e, i && (e = "-" + e);
}
return e;
}, s.prototype.removePatternFormatting = function(e) {
for (var t = this.props, a = t.format, o = a.split("#").filter(function(d) {
return d !== "";
}), f = 0, i = "", n = 0, u = o.length; n <= u; n++) {
var p = o[n] || "", c = n === u ? e.length : e.indexOf(p, f);
if (c === -1) {
i = e;
break;
} else
i += e.substring(f, c), f = c + p.length;
}
return (i.match(this.getNumberRegex(!0)) || []).join("");
}, s.prototype.removeFormatting = function(e) {
var t = this.props, a = t.format, o = t.removeFormatting;
return e && (a ? typeof a == "string" ? e = this.removePatternFormatting(e) : typeof o == "function" ? e = o(e) : e = (e.match(this.getNumberRegex(!0)) || []).join("") : (e = this.removePrefixAndSuffix(e), e = this.getFloatString(e)), e);
}, s.prototype.formatWithPattern = function(e) {
for (var t = this.props, a = t.format, o = 0, f = a.split(""), i = 0, n = a.length; i < n; i++)
a[i] === "#" && (f[i] = e[o] || this.getMaskAtIndex(o), o += 1);
return f.join("");
}, s.prototype.formatAsNumber = function(e) {
var t = this.props, a = t.decimalScale, o = t.fixedDecimalScale, f = t.prefix, i = t.suffix, n = t.allowNegative, u = t.thousandsGroupStyle, p = this.getSeparators(), c = p.thousandSeparator, d = p.decimalSeparator, h = e.indexOf(".") !== -1 || a && o, m = K(e, n), g = m.beforeDecimal, x = m.afterDecimal, y = m.addNegation;
return a !== void 0 && (x = J(x, a, o)), c && (g = me(g, c, u)), f && (g = f + g), i && (x = x + i), y && (g = "-" + g), e = g + (h && d || "") + x, e;
}, s.prototype.formatNumString = function(e) {
e === void 0 && (e = "");
var t = this.props, a = t.format, o = t.allowEmptyFormatting, f = t.customNumerals, i = e;
if (f && f.length === 10) {
var n = new RegExp("[" + f.join("") + "]", "g");
i = e.replace(
n,
function(u) {
return f.indexOf(u).toString();
}
);
}
return e === "" && !o ? i = "" : e === "-" && !a ? i = "-" : typeof a == "string" ? i = this.formatWithPattern(i) : typeof a == "function" ? i = a(i) : i = this.formatAsNumber(i), i;
}, s.prototype.formatValueProp = function(e) {
var t = this.props, a = t.format, o = t.decimalScale, f = t.fixedDecimalScale, i = t.allowEmptyFormatting, n = this.props, u = n.value, p = n.isNumericString;
u = z(u) ? e : u;
var c = !u && u !== 0;
if (c && i && (u = ""), c && !i)
return "";
typeof u == "number" && (u = ve(u), p = !0), u === "Infinity" && p && (u = ""), p && !a && typeof o == "number" && (u = ge(u, o, f));
var d = p ? this.formatNumString(u) : this.formatInput(u);
return d;
}, s.prototype.formatNegation = function(e) {
e === void 0 && (e = "");
var t = this.props, a = t.allowNegative, o = new RegExp("(-)"), f = new RegExp("(-)(.)*(-)"), i = o.test(e), n = f.test(e);
return e = e.replace(/-/g, ""), i && !n && a && (e = "-" + e), e;
}, s.prototype.formatInput = function(e) {
e === void 0 && (e = "");
var t = this.props, a = t.format;
return a || (e = this.removePrefixAndSuffix(e), e = this.formatNegation(e)), e = this.removeFormatting(e), this.formatNumString(e);
}, s.prototype.isCharacterAFormat = function(e, t) {
var a = this.props, o = a.format, f = a.prefix, i = a.suffix, n = a.decimalScale, u = a.fixedDecimalScale, p = this.getSeparators(), c = p.decimalSeparator;
return !!(typeof o == "string" && o[e] !== "#" || !o && (e < f.length || e >= t.length - i.length || n && u && t[e] === c));
}, s.prototype.correctInputValue = function(e, t, a) {
var o = this, f = this.props, i = f.format, n = f.allowNegative, u = f.prefix, p = f.suffix, c = f.decimalScale, d = this.getSeparators(), h = d.allowedDecimalSeparators, m = d.decimalSeparator, g = this.state.numAsString || "", x = this.selectionBeforeInput, y = x.selectionStart, w = x.selectionEnd, F = Se(t, a), v = F.start, b = F.end;
if (!i && v === b && h.indexOf(a[y]) !== -1) {
var P = c === 0 ? "" : m;
return a.substr(0, y) + P + a.substr(y + 1, a.length);
}
var A = i ? 0 : u.length, E = t.length - (i ? 0 : p.length);
if (
// don't do anything if something got added
a.length > t.length || // or if the new value is an empty string
!a.length || // or if nothing has changed, in which case start will be same as end
v === b || // or in case if whole input is selected and new value is typed
y === 0 && w === t.length || // or in case if the whole content is replaced by browser, example (autocomplete)
v === 0 && b === t.length || // or if charcters between prefix and suffix is selected.
// For numeric inputs we apply the format so, prefix and suffix can be ignored
y === A && w === E
)
return a;
var T = t.substr(v, b - v), B = !![].concat(T).find(
function(C, I) {
return o.isCharacterAFormat(I + v, t);
}
);
if (B) {
var M = t.substr(v), $ = {}, S = [];
[].concat(M).forEach(function(C, I) {
o.isCharacterAFormat(I + v, t) ? $[I] = C : I > T.length - 1 && S.push(C);
}), Object.keys($).forEach(function(C) {
S.length > C ? S.splice(C, 0, $[C]) : S.push($[C]);
}), a = t.substr(0, v) + S.join("");
}
if (!i) {
var D = this.removeFormatting(a), j = K(
D,
n
), Y = j.beforeDecimal, ee = j.afterDecimal, te = j.addNegation, re = e < a.indexOf(m) + 1;
if (D.length < g.length && re && Y === "" && !parseFloat(ee))
return te ? "-" : "";
}
return a;
}, s.prototype.updateValue = function(e) {
var t = e.formattedValue, a = e.input, o = e.setCaretPosition;
o === void 0 && (o = !0);
var f = e.source, i = e.event, n = e.numAsString, u = e.caretPos, p = this.props, c = p.onValueChange, d = this.state, h = d.value;
if (a) {
if (u === void 0 && o) {
var m = e.inputValue || a.value, g = H(a);
a.value = t, u = this.getCaretPosition(m, t, g);
}
a.value = t, o && this.setPatchedCaretPosition(a, u, t);
}
n === void 0 && (n = this.removeFormatting(t)), t !== h && (this.setState({ value: t, numAsString: n }), c(this.getValueObject(t, n), { event: i, source: f }));
}, s.prototype.onChange = function(e) {
var t = e.target, a = t.value, o = this, f = o.state, i = o.props, n = i.isAllowed, u = f.value || "", p = H(t);
a = this.correctInputValue(p, u, a);
var c = this.formatInput(a) || "", d = this.removeFormatting(c), h = this.getValueObject(c, d), m = n(h);
m || (c = u), this.updateValue({
formattedValue: c,
numAsString: d,
inputValue: a,
input: t,
event: e,
source: "event"
}), m && i.onChange(e);
}, s.prototype.onBlur = function(e) {
var t = this, a = t.props, o = t.state, f = a.format, i = a.onBlur, n = a.allowLeadingZeros, u = o.numAsString, p = o.value;
if (this.focusedElm = null, clearTimeout(this.focusTimeout), clearTimeout(this.caretPositionTimeout), !f) {
isNaN(parseFloat(u)) && (u = ""), n || (u = he(u));
var c = this.formatNumString(u);
if (c !== p) {
this.updateValue({
formattedValue: c,
numAsString: u,
input: e.target,
setCaretPosition: !1,
event: e,
source: "event"
}), i(e);
return;
}
}
i(e);
}, s.prototype.onKeyDown = function(e) {
var t = e.target, a = e.key, o = t.selectionStart, f = t.selectionEnd, i = t.value;
i === void 0 && (i = "");
var n, u = this.props, p = u.decimalScale, c = u.fixedDecimalScale, d = u.prefix, h = u.suffix, m = u.format, g = u.onKeyDown, x = p !== void 0 && c, y = this.getNumberRegex(!1, x), w = new RegExp("-"), F = typeof m == "string";
if (this.selectionBeforeInput = {
selectionStart: o,
selectionEnd: f
}, a === "ArrowLeft" || a === "Backspace" ? n = o - 1 : a === "ArrowRight" ? n = o + 1 : a === "Delete" && (n = o), n === void 0 || o !== f) {
g(e);
return;
}
var v = n, b = F ? m.indexOf("#") : d.length, P = F ? m.lastIndexOf("#") + 1 : i.length - h.length;
if (a === "ArrowLeft" || a === "ArrowRight") {
var A = a === "ArrowLeft" ? "left" : "right";
v = this.correctCaretPosition(i, n, A);
} else if (a === "Delete" && !y.test(i[n]) && !w.test(i[n]))
for (; !y.test(i[v]) && v < P; )
v++;
else if (a === "Backspace" && !y.test(i[n])) {
if (o <= b + 1 && i[0] === "-" && typeof m > "u") {
var E = i.substring(1);
this.updateValue({
formattedValue: E,
caretPos: v,
input: t,
event: e,
source: "event"
});
} else if (!w.test(i[n])) {
for (; !y.test(i[v - 1]) && v > b; )
v--;
v = this.correctCaretPosition(i, v, "left");
}
}
(v !== n || n < b || n > P) && (e.preventDefault(), this.setPatchedCaretPosition(t, v, i)), e.isUnitTestRun && this.setPatchedCaretPosition(t, v, i), g(e);
}, s.prototype.onMouseUp = function(e) {
var t = e.target, a = t.selectionStart, o = t.selectionEnd, f = t.value;
if (f === void 0 && (f = ""), a === o) {
var i = this.correctCaretPosition(f, a);
i !== a && this.setPatchedCaretPosition(t, i, f);
}
this.props.onMouseUp(e);
}, s.prototype.onFocus = function(e) {
var t = this;
e.persist(), this.focusedElm = e.target, this.focusTimeout = setTimeout(function() {
var a = e.target, o = a.selectionStart, f = a.selectionEnd, i = a.value;
i === void 0 && (i = "");
var n = t.correctCaretPosition(i, o);
n !== o && !(o === 0 && f === i.length) && t.setPatchedCaretPosition(a, n, i), t.props.onFocus(e);
}, 0);
}, s.prototype.render = function() {
var e = this.props, t = e.type, a = e.displayType, o = e.customInput, f = e.renderText, i = e.getInputRef, n = e.format;
e.thousandSeparator, e.decimalSeparator, e.allowedDecimalSeparators, e.thousandsGroupStyle, e.decimalScale, e.fixedDecimalScale, e.prefix, e.suffix, e.removeFormatting, e.mask, e.defaultValue, e.isNumericString, e.allowNegative, e.allowEmptyFormatting, e.allowLeadingZeros, e.onValueChange, e.isAllowed, e.customNumerals, e.onChange, e.onKeyDown, e.onMouseUp, e.onFocus, e.onBlur, e.value;
var u = ye(e, ["type", "displayType", "customInput", "renderText", "getInputRef", "format", "thousandSeparator", "decimalSeparator", "allowedDecimalSeparators", "thousandsGroupStyle", "decimalScale", "fixedDecimalScale", "prefix", "suffix", "removeFormatting", "mask", "defaultValue", "isNumericString", "allowNegative", "allowEmptyFormatting", "allowLeadingZeros", "onValueChange", "isAllowed", "customNumerals", "onChange", "onKeyDown", "onMouseUp", "onFocus", "onBlur", "value"]), p = u, c = this.state, d = c.value, h = c.mounted, m = h && xe(n) ? "numeric" : void 0, g = Object.assign({ inputMode: m }, p, {
type: t,
value: d,
onChange: this.onChange,
onKeyDown: this.onKeyDown,
onMouseUp: this.onMouseUp,
onFocus: this.onFocus,
onBlur: this.onBlur
});
if (a === "text")
return f ? f(d, p) || null : O.createElement(
"span",
Object.assign({}, p, { ref: i }),
d
);
if (o) {
var x = o;
return O.createElement(x, Object.assign({}, g, { ref: i }));
}
return O.createElement("input", Object.assign({}, g, { ref: i }));
}, s;
}(O.Component);
Q.defaultProps = be;
const Ne = G.div`
display: flex;
align-items: center;
min-height: ${(r) => k(r.theme, r.size)};
max-height: ${(r) => k(r.theme, r.size)};
background-color: ${(r) => N(
r.theme,
"Input",
r.color,
"enabled",
"background"
)};
border: 1px solid
${(r) => N(
r.theme,
"Input",
r.focused === !0 ? "primary" : r.color,
"enabled",
"border"
)};
border-radius: ${(r) => fe(r.theme, "regular")};
${(r) => r.focused === !0 && r.readOnly !== !0 ? ue(r.theme) : ""}
/* ${(r) => r.isDisabled === !0 ? W(r.theme) : ""} */
${(r) => r.isDisabled === !0 && `background-color: ${N(
r.theme,
"Input",
r.color,
"disabled",
"background",
"backgroundOpacity"
)};
color: ${(s) => N(
s.theme,
"Input",
s.color,
"disabled",
"text"
)};`}
${(r) => r.isDisabled === !0 ? "border: 1px solid " + N(
r.theme,
"Input",
r.color,
"disabled",
"border"
) : ""}
& input {
background: none;
border: none;
outline: none;
padding-top: 0.625rem;
padding-bottom: 0.625rem;
width: 100%;
${(r) => le(r.theme, "Input", r.size, "enabled")}
min-height: ${(r) => k(r.theme, r.size)};
max-height: ${(r) => k(r.theme, r.size)};
color: ${(r) => N(
r.theme,
"Input",
r.focused === !0 ? "primary" : r.color,
"enabled",
"text"
)};
caret-color: ${(r) => N(r.theme, "Input", r.color, "enabled", "caret")};
padding-right: ${(r) => r.suffix ? "0" : "0.75rem"};
padding-left: ${(r) => r.prefix ? "0" : "0.75rem"};
}
& input:disabled {
/* ${(r) => W(r.theme)} */
${(r) => `background-color: ${N(
r.theme,
"Input",
r.color,
"disabled",
"background",
"backgroundOpacity"
)};
color: ${(s) => N(
s.theme,
"Input",
s.color,
"disabled",
"text"
)};`}
background: none;
}
& input:read-only {
cursor: default;
}
& input::placeholder {
color: ${(r) => N(
r.theme,
"Input",
r.color,
"enabled",
"placeholder"
)};
}
`, X = G.span`
padding: 0 12px;
color: ${(r) => N(
r.theme,
"Input",
r.focused === !0 ? "primary" : r.color,
"enabled",
"prefix"
)};
`, we = G(X)``, Ae = ie((r, s) => {
const {
disabled: l,
readOnly: e,
debounceTime: t = 0,
prefix: a,
suffix: o,
thousandSeparator: f = ".",
decimalSeparator: i = ",",
decimalScale: n = 2,
fixedDecimalScale: u = !0,
allowNegative: p = !0,
//----------------
onChange: c,
onBlur: d,
onFocus: h,
onInputChange: m,
//----------------
className: g = "",
style: x = {},
size: y = "small",
color: w = "primary",
...F
} = r, v = ce(), [b, P] = oe(!1), A = ne(
se((S, D) => E(S, D), t),
[c]
), E = (S, D) => {
c && (c == null || c(S, D)), m == null || m(S, D);
}, T = (S, D) => {
A(D.event, S == null ? void 0 : S.floatValue);
}, B = () => n < 0 ? 0 : n > 17 ? 17 : n, M = (S) => {
P(!0), h == null || h(S);
}, $ = (S) => {
P(!1), d == null || d(S);
};
return /* @__PURE__ */ ae(
Ne,
{
style: x,
className: g,
theme: v,
color: w,
size: y,
prefix: a,
suffix: o,
focused: b,
disabled: l,
readOnly: e,
children: [
a && /* @__PURE__ */ U(
X,
{
theme: v,
color: w,
focused: b,
className: "lnc-input-prefix",
children: a
}
),
/* @__PURE__ */ U(
Q,
{
getInputRef: s,
className: "lnc-decimal-input",
disabled: l,
readOnly: e,
thousandSeparator: f,
decimalSeparator: i,
decimalScale: B(),
fixedDecimalScale: u,
allowNegative: p,
onFocus: M,
onBlur: $,
onValueChange: T,
...F
}
),
o && /* @__PURE__ */ U(
we,
{
theme: v,
color: w,
focused: b,
className: "lnc-input-suffix",
children: o
}
)
]
}
);
});
export {
Ae as default
};