@konstructio/ui
Version:
A set of reusable and customizable React components built for konstruct.io
193 lines (192 loc) • 6.03 kB
JavaScript
import { jsxs as m, jsx as s } from "react/jsx-runtime";
import l, { forwardRef as v, useId as k, useState as z } from "react";
import { cn as d } from "../../utils/index.js";
import { inputVariants as _ } from "./Input.variants.js";
import { SearchIcon as I } from "../../assets/icons/components/Search.js";
import { Warning as W } from "../../assets/icons/components/Warning.js";
import { P as i } from "../../index-h-Ul0anl.js";
function h() {
return h = Object.assign || function(t) {
for (var r = 1; r < arguments.length; r++) {
var o = arguments[r];
for (var e in o)
Object.prototype.hasOwnProperty.call(o, e) && (t[e] = o[e]);
}
return t;
}, h.apply(this, arguments);
}
function $(t, r) {
if (t == null) return {};
var o = L(t, r), e, n;
if (Object.getOwnPropertySymbols) {
var a = Object.getOwnPropertySymbols(t);
for (n = 0; n < a.length; n++)
e = a[n], !(r.indexOf(e) >= 0) && Object.prototype.propertyIsEnumerable.call(t, e) && (o[e] = t[e]);
}
return o;
}
function L(t, r) {
if (t == null) return {};
var o = {}, e = Object.keys(t), n, a;
for (a = 0; a < e.length; a++)
n = e[a], !(r.indexOf(n) >= 0) && (o[n] = t[n]);
return o;
}
var y = v(function(t, r) {
var o = t.color, e = o === void 0 ? "currentColor" : o, n = t.size, a = n === void 0 ? 24 : n, c = $(t, ["color", "size"]);
return /* @__PURE__ */ l.createElement("svg", h({
ref: r,
xmlns: "http://www.w3.org/2000/svg",
width: a,
height: a,
viewBox: "0 0 24 24",
fill: "none",
stroke: e,
strokeWidth: "2",
strokeLinecap: "round",
strokeLinejoin: "round"
}, c), /* @__PURE__ */ l.createElement("path", {
d: "M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"
}), /* @__PURE__ */ l.createElement("line", {
x1: "1",
y1: "1",
x2: "23",
y2: "23"
}));
});
y.propTypes = {
color: i.string,
size: i.oneOfType([i.string, i.number])
};
y.displayName = "EyeOff";
function g() {
return g = Object.assign || function(t) {
for (var r = 1; r < arguments.length; r++) {
var o = arguments[r];
for (var e in o)
Object.prototype.hasOwnProperty.call(o, e) && (t[e] = o[e]);
}
return t;
}, g.apply(this, arguments);
}
function S(t, r) {
if (t == null) return {};
var o = T(t, r), e, n;
if (Object.getOwnPropertySymbols) {
var a = Object.getOwnPropertySymbols(t);
for (n = 0; n < a.length; n++)
e = a[n], !(r.indexOf(e) >= 0) && Object.prototype.propertyIsEnumerable.call(t, e) && (o[e] = t[e]);
}
return o;
}
function T(t, r) {
if (t == null) return {};
var o = {}, e = Object.keys(t), n, a;
for (a = 0; a < e.length; a++)
n = e[a], !(r.indexOf(n) >= 0) && (o[n] = t[n]);
return o;
}
var x = v(function(t, r) {
var o = t.color, e = o === void 0 ? "currentColor" : o, n = t.size, a = n === void 0 ? 24 : n, c = S(t, ["color", "size"]);
return /* @__PURE__ */ l.createElement("svg", g({
ref: r,
xmlns: "http://www.w3.org/2000/svg",
width: a,
height: a,
viewBox: "0 0 24 24",
fill: "none",
stroke: e,
strokeWidth: "2",
strokeLinecap: "round",
strokeLinejoin: "round"
}, c), /* @__PURE__ */ l.createElement("path", {
d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"
}), /* @__PURE__ */ l.createElement("circle", {
cx: "12",
cy: "12",
r: "3"
}));
});
x.propTypes = {
color: i.string,
size: i.oneOfType([i.string, i.number])
};
x.displayName = "Eye";
const C = v(
({
className: t,
error: r,
isRequired: o = !1,
isSearch: e = !1,
label: n,
labelClassName: a,
name: c,
theme: b,
type: p = "text",
helperText: w,
...j
}, N) => {
const O = k(), [u, E] = z(() => p !== "password"), f = typeof r == "string" && r.length >= 0, P = u ? x : y;
return /* @__PURE__ */ m("div", { className: "flex flex-col gap-2 w-full relative", "data-theme": b, children: [
n ? /* @__PURE__ */ m(
"label",
{
htmlFor: O,
className: d(
"cursor-pointer text-slate-500 flex gap-1 text-sm font-medium",
a
),
children: [
n,
" ",
o ? /* @__PURE__ */ s("span", { className: "text-red-600 text-xs mt-0.5", children: "*" }) : null
]
}
) : null,
/* @__PURE__ */ m("div", { className: "relative", children: [
e ? /* @__PURE__ */ s(
"i",
{
className: d(
"absolute left-2.5 top-1/2 -translate-y-[50%] text-slate-400",
f && "text-red-600"
),
children: /* @__PURE__ */ s(I, { className: "w-5 h-5" })
}
) : null,
/* @__PURE__ */ s(
"input",
{
id: O,
ref: N,
name: c,
type: u ? p : "password",
className: d(
_({
className: t,
variant: f ? "error" : "default"
}),
(p === "password" || f) && "pr-10",
e && "pl-8"
),
...j
}
),
f ? /* @__PURE__ */ s("i", { className: "absolute right-3 text-red-600 top-1/2 -translate-y-[50%]", children: /* @__PURE__ */ s(W, { className: "w-5 h-5" }) }) : null,
p === "password" && !r ? /* @__PURE__ */ s("i", { className: "absolute right-3 text-slate-400 top-1/2 -translate-y-[50%]", children: /* @__PURE__ */ s(
P,
{
className: "w-5 h-5 cursor-pointer",
onClick: () => E(!u)
}
) }) : null
] }),
r ? /* @__PURE__ */ s("span", { className: "text-xs text-red-600", children: r }) : null,
!r && w ? /* @__PURE__ */ s("span", { className: "text-xs text-slate-600", children: w }) : null
] });
}
);
C.displayName = "Input";
export {
C as Input
};