UNPKG

@lanaco/lnc-react-ui

Version:

React component library

228 lines (221 loc) 4.97 kB
import { jsxs as W, jsx as b } from "react/jsx-runtime"; import { P as t } from "./index-S5Cd7WrG.js"; import { forwardRef as U, useState as C, useEffect as D, useCallback as E } from "react"; import { d as q } from "./index-CkWvbrVT.js"; import { n as u } from "./emotion-styled.browser.esm-CjCaF13H.js"; import { d as s, b as a, a as A, e as G, h as O, c as H } from "./utils-DtRLzzTZ.js"; import { u as J } from "./emotion-element-f0de968e.browser.esm-CkCiQliQ.js"; const K = u.div` display: flex; align-items: center; min-height: ${(e) => s(e.theme, e.size)}; max-height: ${(e) => s(e.theme, e.size)}; background-color: ${(e) => a( e.theme, "Input", e.color, "enabled", "background" )}; border: 1px solid ${(e) => a( e.theme, "Input", e.focused === !0 ? "primary" : e.color, e.disabled === !0 ? "disabled" : "enabled", "border" )}; border-radius: ${(e) => A(e.theme, "regular")}; ${(e) => e.focused && e.readOnly !== !0 ? G(e.theme) : ""} ${(e) => e.disabled === !0 ? O(e.theme) : ""} `, S = u.span` padding: 0 12px; color: ${(e) => a( e.theme, "Input", e.focused === !0 ? "primary" : e.color, "enabled", "prefix" )}; `, L = u(S)``, M = u.input` background: none; border: none; outline: none; padding-top: 0.625rem; padding-bottom: 0.625rem; width: 100%; ${(e) => H(e.theme, "Input", e.size, "enabled")} min-height: ${(e) => s(e.theme, e.size)}; max-height: ${(e) => s(e.theme, e.size)}; color: ${(e) => a( e.theme, "Input", e.focused === !0 ? "primary" : e.color, "enabled", "text" )}; caret-color: ${(e) => a(e.theme, "Input", e.color, "enabled", "caret")}; padding-right: ${(e) => e.suffix ? "0" : "0.75rem"}; padding-left: ${(e) => e.prefix ? "0" : "0.75rem"}; &::placeholder { color: ${(e) => a( e.theme, "Input", e.color, "enabled", "placeholder" )}; } &:read-only { cursor: default; } &:disabled { ${(e) => O(e.theme)} background: none; } `, Q = U((e, T) => { const { disabled: y, readOnly: x, defaultValue: V, value: l, debounceTime: z = 0, type: v = "text", placeholder: k, tabIndex: w, prefix: c, suffix: m, //---------------- onChange: r, onBlur: f, onFocus: h, //---------------- className: B = "", style: F = {}, size: p = "small", color: o = "primary", ...N } = e, d = J(), [j, $] = C(l || V || ""), [i, I] = C(!1); D(() => { l != null && $(l); }, [l]); const P = E( q((n, g) => R(n, g), z), [r] ), R = (n, g) => { r && (r == null || r(n, g)); }; return /* @__PURE__ */ W( K, { style: F, className: B, theme: d, color: o, size: p, focused: i, disabled: y, readOnly: x, children: [ c && /* @__PURE__ */ b( S, { theme: d, color: o, focused: i, className: "lnc-input-prefix", children: c } ), /* @__PURE__ */ b( M, { ref: T, type: v, theme: d, color: o, size: p, placeholder: k, prefix: c, suffix: m, disabled: y, readOnly: x, focused: i, onFocus: (n) => { I(!0), h == null || h(n); }, onBlur: (n) => { I(!1), f == null || f(n); }, onChange: (n) => { $(n.target.value), P(n, n.target.value); }, tabIndex: w, value: j, ...N } ), m && /* @__PURE__ */ b( L, { theme: d, color: o, focused: i, className: "lnc-input-suffix", children: m } ) ] } ); }); Q.propTypes = { id: t.string, defaultValue: t.string, value: t.string, disabled: t.bool, readOnly: t.bool, /** * Time in miliseconds before onChange event fires after it has been triggered. */ debounceTime: t.number, placeholder: t.string, type: t.oneOf(["text", "email"]), tabIndex: t.number, /** * Reserved space before input. Intented to be used with plain text or `Icon` component. */ prefix: t.oneOfType([t.string, t.element]), /** * Reserved space after input. Intented to be used with plain text or `Icon` component. */ suffix: t.oneOfType([t.string, t.element]), /** * `(event, value) => void` */ onChange: t.func, /** * `(event) => void` */ onBlur: t.func, /** * `(event) => void` */ onFocus: t.func, className: t.string, style: t.object, size: t.oneOf(["small", "medium", "large"]), color: t.oneOf([ "primary", "secondary", "success", "danger", "warning", "information", "neutral", "gray" ]) }; export { Q as default };