UNPKG

@konstructio/ui

Version:

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

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