@boxyhq/react-ui
Version:
React UI components from BoxyHQ
154 lines (153 loc) • 4.01 kB
JavaScript
import { j as s, s as c, E as j, B as I, c as f } from "./index-CL4_ByuK.js";
import { useState as b } from "react";
function g(e) {
return /* @__PURE__ */ s.jsx(
"svg",
{
fill: "none",
viewBox: "0 0 24 24",
"stroke-width": "1.5",
stroke: "currentColor",
...e.svgAttrs,
children: /* @__PURE__ */ s.jsx(
"path",
{
"stroke-linecap": "round",
"stroke-linejoin": "round",
d: "M6 18 18 6M6 6l12 12"
}
)
}
);
}
const N = "_rowContainer_1fe97_1", w = "_error_1fe97_8", y = "_row_1fe97_1", C = "_input_1fe97_24", D = "_add_1fe97_29", k = "_svg_1fe97_33", a = {
rowContainer: N,
error: w,
row: y,
input: C,
add: D,
svg: k
};
function A(e) {
return /* @__PURE__ */ s.jsxs("div", { className: a.row, children: [
/* @__PURE__ */ s.jsx(
"input",
{
name: "item",
type: e.inputType || "text",
className: `${e.classNames.input} ${c["input-sm"]} ${a.input}`,
value: e.item,
onChange: (i) => e.handleItemUpdate(i.target.value, e.index),
onBlur: (i) => e.handleBlur(e.index),
required: !0,
disabled: e.disabled
}
),
/* @__PURE__ */ s.jsx(
"button",
{
type: "button",
onClick: (i) => e.handleItemDelete(e.index),
disabled: e.disableDelete,
children: /* @__PURE__ */ s.jsx(
g,
{
svgAttrs: {
class: a.svg
}
}
)
}
)
] });
}
function U(e) {
var o;
const [i, d] = b(
() => {
}
);
function l() {
return Array.isArray(e.currentlist) ? e.currentlist : [e.currentlist];
}
function v() {
e.handleItemListUpdate(e.fieldName, [...l(), ""]);
}
function h(t, n) {
const r = [...l()];
r[n] = t, e.handleItemListUpdate(e.fieldName, r);
}
function _(t) {
const n = l()[t];
if (l().indexOf(n) !== t) {
d(t);
return;
} else i === t && d(void 0);
l().slice(t + 1).indexOf(n) !== -1 ? d(t) : i === t && d(void 0);
}
function x(t) {
const n = l()[t];
i !== void 0 && (i === t || n === l()[i]) && d(void 0), e.handleItemListUpdate(
e.fieldName,
l().filter((r, m) => m !== t)
);
}
function u() {
var t, n;
return {
label: f((t = e.classNames) == null ? void 0 : t.label, c.label),
input: f((n = e.classNames) == null ? void 0 : n.input, c.input)
};
}
return /* @__PURE__ */ s.jsxs("fieldset", { className: c.fieldset, children: [
/* @__PURE__ */ s.jsx("legend", { className: u().label, children: e.label }),
/* @__PURE__ */ s.jsxs("div", { className: a.rowContainer, children: [
(o = l()) == null ? void 0 : o.map((t, n) => /* @__PURE__ */ s.jsxs("div", { children: [
/* @__PURE__ */ s.jsx(
A,
{
inputType: e.inputType,
item: t,
index: n,
isDuplicateItem: i === n,
handleItemUpdate: h,
handleItemDelete: x,
disableDelete: n === 0 && l().length === 1,
handleBlur: _,
disabled: i !== void 0 && i !== n,
classNames: {
input: u().input
}
}
),
i === n ? /* @__PURE__ */ s.jsxs("span", { className: a.error, children: [
/* @__PURE__ */ s.jsx(
j,
{
svgAttrs: {
class: a.svg,
"aria-hidden": !0
}
}
),
"Duplicate entries not allowed."
] }) : null
] }, n)),
/* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsx(
I,
{
type: "button",
variant: "outline",
name: "Add URL",
classNames: a.add,
onClick: (t) => v(),
disabled: i !== void 0
}
) })
] })
] });
}
export {
U as I
};
//# sourceMappingURL=index-Ct6iuh8S.js.map