UNPKG

@konstructio/ui

Version:

A set of reusable and customizable React components built for konstruct.io

180 lines (179 loc) 5.2 kB
import { jsxs as m, jsx as u } from "react/jsx-runtime"; import { R as O } from "../../index--EmNlyHx.js"; import p, { forwardRef as d, useId as N, useCallback as w } from "react"; import { cn as y } from "../../utils/index.js"; import { labelVariants as z, buttonVariants as j, numberInputVariants as _ } from "./NumberInput.variants.js"; import { P as s } from "../../index-h-Ul0anl.js"; function v() { return v = Object.assign || function(t) { for (var i = 1; i < arguments.length; i++) { var r = arguments[i]; for (var e in r) Object.prototype.hasOwnProperty.call(r, e) && (t[e] = r[e]); } return t; }, v.apply(this, arguments); } function E(t, i) { if (t == null) return {}; var r = $(t, i), e, n; if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(t); for (n = 0; n < o.length; n++) e = o[n], !(i.indexOf(e) >= 0) && Object.prototype.propertyIsEnumerable.call(t, e) && (r[e] = t[e]); } return r; } function $(t, i) { if (t == null) return {}; var r = {}, e = Object.keys(t), n, o; for (o = 0; o < e.length; o++) n = e[o], !(i.indexOf(n) >= 0) && (r[n] = t[n]); return r; } var h = d(function(t, i) { var r = t.color, e = r === void 0 ? "currentColor" : r, n = t.size, o = n === void 0 ? 24 : n, f = E(t, ["color", "size"]); return /* @__PURE__ */ p.createElement("svg", v({ ref: i, xmlns: "http://www.w3.org/2000/svg", width: o, height: o, viewBox: "0 0 24 24", fill: "none", stroke: e, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, f), /* @__PURE__ */ p.createElement("line", { x1: "5", y1: "12", x2: "19", y2: "12" })); }); h.propTypes = { color: s.string, size: s.oneOfType([s.string, s.number]) }; h.displayName = "Minus"; function b() { return b = Object.assign || function(t) { for (var i = 1; i < arguments.length; i++) { var r = arguments[i]; for (var e in r) Object.prototype.hasOwnProperty.call(r, e) && (t[e] = r[e]); } return t; }, b.apply(this, arguments); } function L(t, i) { if (t == null) return {}; var r = W(t, i), e, n; if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(t); for (n = 0; n < o.length; n++) e = o[n], !(i.indexOf(e) >= 0) && Object.prototype.propertyIsEnumerable.call(t, e) && (r[e] = t[e]); } return r; } function W(t, i) { if (t == null) return {}; var r = {}, e = Object.keys(t), n, o; for (o = 0; o < e.length; o++) n = e[o], !(i.indexOf(n) >= 0) && (r[n] = t[n]); return r; } var g = d(function(t, i) { var r = t.color, e = r === void 0 ? "currentColor" : r, n = t.size, o = n === void 0 ? 24 : n, f = L(t, ["color", "size"]); return /* @__PURE__ */ p.createElement("svg", b({ ref: i, xmlns: "http://www.w3.org/2000/svg", width: o, height: o, viewBox: "0 0 24 24", fill: "none", stroke: e, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, f), /* @__PURE__ */ p.createElement("line", { x1: "12", y1: "5", x2: "12", y2: "19" }), /* @__PURE__ */ p.createElement("line", { x1: "5", y1: "12", x2: "19", y2: "12" })); }); g.propTypes = { color: s.string, size: s.oneOfType([s.string, s.number]) }; g.displayName = "Plus"; const S = d( ({ className: t, label: i, max: r = -1 / 0, min: e = 1 / 0, name: n, theme: o, value: f, onChange: l }, x) => { const P = N(), a = f ?? 0, k = w(() => { let c = 0; e === 1 / 0 ? c = a - 1 : c = Math.max(e, a - 1), l == null || l({ target: { value: c } }); }, [a, e, l]), I = w(() => { let c = 0; r === -1 / 0 ? c = a + 1 : c = Math.min(r, a + 1), l == null || l({ target: { value: c } }); }, [a, r, l]); return /* @__PURE__ */ m("div", { className: "flex flex-col gap-1", "data-theme": o, children: [ i ? /* @__PURE__ */ u("label", { htmlFor: n ?? P, className: y(z()), children: i }) : null, /* @__PURE__ */ m("div", { className: "flex items-center", role: "presentation", children: [ /* @__PURE__ */ m( "button", { type: "button", onClick: k, className: y(j({ button: "rigth" })), children: [ /* @__PURE__ */ u(h, { className: "w-4 h-4" }), /* @__PURE__ */ u(O, { children: "Decrement" }) ] } ), /* @__PURE__ */ u( "input", { ref: x, type: "number", value: a, name: n, className: y(_({ className: t })), readOnly: !0, "aria-label": typeof i == "string" ? i : "number input" } ), /* @__PURE__ */ m( "button", { type: "button", onClick: I, className: y(j({ button: "left" })), children: [ /* @__PURE__ */ u(g, { className: "w-4 h-4" }), /* @__PURE__ */ u(O, { children: "Increment" }) ] } ) ] }) ] }); } ); export { S as NumberInput };