next-recomponents 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -127,6 +127,6 @@ declare function Select({ label, placeholder, children, strictMode, ...props }:
127
127
  interface Props extends React$1.DetailedHTMLProps<React$1.DialogHTMLAttributes<HTMLDialogElement>, HTMLDialogElement> {
128
128
  button: React$1.ReactElement;
129
129
  }
130
- declare function Modal({ button, children }: Props): react_jsx_runtime.JSX.Element;
130
+ declare function Modal({ button, children, ref }: Props): react_jsx_runtime.JSX.Element;
131
131
 
132
132
  export { Alert, Button, Container, Form, Input, Modal, Select, Table, TextArea, regularExpresions, useResources };
package/dist/index.d.ts CHANGED
@@ -127,6 +127,6 @@ declare function Select({ label, placeholder, children, strictMode, ...props }:
127
127
  interface Props extends React$1.DetailedHTMLProps<React$1.DialogHTMLAttributes<HTMLDialogElement>, HTMLDialogElement> {
128
128
  button: React$1.ReactElement;
129
129
  }
130
- declare function Modal({ button, children }: Props): react_jsx_runtime.JSX.Element;
130
+ declare function Modal({ button, children, ref }: Props): react_jsx_runtime.JSX.Element;
131
131
 
132
132
  export { Alert, Button, Container, Form, Input, Modal, Select, Table, TextArea, regularExpresions, useResources };
package/dist/index.js CHANGED
@@ -32690,32 +32690,20 @@ function Select(_a) {
32690
32690
  }
32691
32691
 
32692
32692
  // src/modal/index.tsx
32693
- var import_react31 = __toESM(require("react"));
32693
+ var import_react31 = require("react");
32694
32694
  var import_jsx_runtime18 = require("react/jsx-runtime");
32695
- function Modal({ button, children }) {
32696
- const modalRef = (0, import_react31.useRef)(null);
32695
+ function Modal({ button, children, ref }) {
32696
+ const modalRef = ref || (0, import_react31.useRef)(null);
32697
32697
  function show() {
32698
32698
  var _a;
32699
- (_a = modalRef.current) == null ? void 0 : _a.showModal();
32699
+ typeof modalRef == "object" && ((_a = modalRef.current) == null ? void 0 : _a.showModal());
32700
32700
  }
32701
32701
  function hide() {
32702
32702
  var _a;
32703
- (_a = modalRef.current) == null ? void 0 : _a.close();
32703
+ typeof modalRef == "object" && ((_a = modalRef.current) == null ? void 0 : _a.close());
32704
32704
  }
32705
- const newChildren = (0, import_react31.useMemo)(() => {
32706
- return children && import_react31.default.cloneElement(children, { hide });
32707
- }, [children]);
32708
- const newButton = (0, import_react31.useMemo)(() => {
32709
- return button && import_react31.default.cloneElement(button, {
32710
- onClick: (e) => {
32711
- var _a, _b;
32712
- show();
32713
- (_b = (_a = button.props).onClick) == null ? void 0 : _b.call(_a, e);
32714
- }
32715
- });
32716
- }, [button]);
32717
32705
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
32718
- newButton,
32706
+ button,
32719
32707
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("dialog", { ref: modalRef, className: "p-5 border shadow rounded", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "relative", children: [
32720
32708
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
32721
32709
  "button",
@@ -32725,7 +32713,7 @@ function Modal({ button, children }) {
32725
32713
  children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CloseIcon, {})
32726
32714
  }
32727
32715
  ),
32728
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "flex flex-col gap-3 pt-6", children: newChildren })
32716
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "flex flex-col gap-3 pt-6", children })
32729
32717
  ] }) })
32730
32718
  ] });
32731
32719
  }
package/dist/index.mjs CHANGED
@@ -32687,32 +32687,20 @@ function Select(_a) {
32687
32687
  }
32688
32688
 
32689
32689
  // src/modal/index.tsx
32690
- import React6, { useMemo as useMemo10, useRef as useRef6 } from "react";
32690
+ import { useRef as useRef6 } from "react";
32691
32691
  import { Fragment as Fragment4, jsx as jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
32692
- function Modal({ button, children }) {
32693
- const modalRef = useRef6(null);
32692
+ function Modal({ button, children, ref }) {
32693
+ const modalRef = ref || useRef6(null);
32694
32694
  function show() {
32695
32695
  var _a;
32696
- (_a = modalRef.current) == null ? void 0 : _a.showModal();
32696
+ typeof modalRef == "object" && ((_a = modalRef.current) == null ? void 0 : _a.showModal());
32697
32697
  }
32698
32698
  function hide() {
32699
32699
  var _a;
32700
- (_a = modalRef.current) == null ? void 0 : _a.close();
32700
+ typeof modalRef == "object" && ((_a = modalRef.current) == null ? void 0 : _a.close());
32701
32701
  }
32702
- const newChildren = useMemo10(() => {
32703
- return children && React6.cloneElement(children, { hide });
32704
- }, [children]);
32705
- const newButton = useMemo10(() => {
32706
- return button && React6.cloneElement(button, {
32707
- onClick: (e) => {
32708
- var _a, _b;
32709
- show();
32710
- (_b = (_a = button.props).onClick) == null ? void 0 : _b.call(_a, e);
32711
- }
32712
- });
32713
- }, [button]);
32714
32702
  return /* @__PURE__ */ jsxs12(Fragment4, { children: [
32715
- newButton,
32703
+ button,
32716
32704
  /* @__PURE__ */ jsx17("dialog", { ref: modalRef, className: "p-5 border shadow rounded", children: /* @__PURE__ */ jsxs12("div", { className: "relative", children: [
32717
32705
  /* @__PURE__ */ jsx17(
32718
32706
  "button",
@@ -32722,7 +32710,7 @@ function Modal({ button, children }) {
32722
32710
  children: /* @__PURE__ */ jsx17(CloseIcon, {})
32723
32711
  }
32724
32712
  ),
32725
- /* @__PURE__ */ jsx17("div", { className: "flex flex-col gap-3 pt-6", children: newChildren })
32713
+ /* @__PURE__ */ jsx17("div", { className: "flex flex-col gap-3 pt-6", children })
32726
32714
  ] }) })
32727
32715
  ] });
32728
32716
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recomponents",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -7,34 +7,18 @@ interface Props
7
7
  > {
8
8
  button: React.ReactElement;
9
9
  }
10
- export default function Modal({ button, children }: Props) {
11
- const modalRef = useRef<HTMLDialogElement>(null);
10
+ export default function Modal({ button, children, ref }: Props) {
11
+ const modalRef = ref || useRef<HTMLDialogElement>(null);
12
12
  function show() {
13
- modalRef.current?.showModal();
13
+ typeof modalRef == "object" && modalRef.current?.showModal();
14
14
  }
15
15
  function hide() {
16
- modalRef.current?.close();
16
+ typeof modalRef == "object" && modalRef.current?.close();
17
17
  }
18
- const newChildren = useMemo(() => {
19
- return (
20
- children && React.cloneElement(children as React.ReactElement, { hide })
21
- );
22
- }, [children]);
23
- const newButton = useMemo(() => {
24
- return (
25
- button &&
26
- React.cloneElement(button, {
27
- onClick: (e: any) => {
28
- show();
29
- button.props.onClick?.(e);
30
- },
31
- })
32
- );
33
- }, [button]);
34
18
 
35
19
  return (
36
20
  <>
37
- {newButton}
21
+ {button}
38
22
  <dialog ref={modalRef} className="p-5 border shadow rounded">
39
23
  <div className="relative">
40
24
  {/* Botón de cerrar en la esquina superior derecha */}
@@ -44,7 +28,7 @@ export default function Modal({ button, children }: Props) {
44
28
  >
45
29
  <CloseIcon />
46
30
  </button>
47
- <div className="flex flex-col gap-3 pt-6">{newChildren}</div>
31
+ <div className="flex flex-col gap-3 pt-6">{children}</div>
48
32
  </div>
49
33
  </dialog>
50
34
  </>