next-recomponents 1.1.8 → 1.2.0

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
@@ -1,18 +1,18 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1, { DetailedHTMLProps, ButtonHTMLAttributes, Dispatch, SetStateAction, InputHTMLAttributes, ReactNode, TextareaHTMLAttributes } from 'react';
3
3
 
4
- interface Props$4 {
4
+ interface Props$5 {
5
5
  color?: "white" | "primary" | "secondary" | "info" | "danger" | "warning" | "success";
6
6
  children: React.ReactNode;
7
7
  }
8
- declare function Alert({ color, children, ...props }: Props$4): react_jsx_runtime.JSX.Element;
8
+ declare function Alert({ color, children, ...props }: Props$5): react_jsx_runtime.JSX.Element;
9
9
 
10
- interface Props$3 extends DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement> {
10
+ interface Props$4 extends DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement> {
11
11
  icon?: React.ReactNode;
12
12
  size?: "full" | "small";
13
13
  color?: "white" | "primary" | "secondary" | "info" | "danger" | "warning" | "success";
14
14
  }
15
- declare function Button({ className, size, color, children, icon, disabled, ...props }: Props$3): react_jsx_runtime.JSX.Element;
15
+ declare function Button({ className, size, color, children, icon, disabled, ...props }: Props$4): react_jsx_runtime.JSX.Element;
16
16
 
17
17
  type LocationItem = {
18
18
  location: string;
@@ -33,14 +33,14 @@ declare function Container({ children, appName, menuList, navItems, leftPanel, f
33
33
  interface OnSubmitProps extends React$1.FormEvent<HTMLFormElement> {
34
34
  values: Record<string, any>;
35
35
  }
36
- interface Props$2 {
36
+ interface Props$3 {
37
37
  onSubmit: (e: OnSubmitProps) => void | Promise<void>;
38
38
  children: React$1.ReactNode;
39
39
  state?: [any, Dispatch<SetStateAction<any>>];
40
40
  invalidMessage?: string;
41
41
  loader?: React$1.ReactNode;
42
42
  }
43
- declare function Form({ onSubmit, state, invalidMessage, children, loader, }: Props$2): react_jsx_runtime.JSX.Element;
43
+ declare function Form({ onSubmit, state, invalidMessage, children, loader, }: Props$3): react_jsx_runtime.JSX.Element;
44
44
 
45
45
  interface InputProps extends DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
46
46
  label: React.ReactNode;
@@ -66,16 +66,16 @@ interface TableProps extends React.DetailedHTMLProps<React.TableHTMLAttributes<H
66
66
  }
67
67
  declare function Table(props: TableProps): react_jsx_runtime.JSX.Element;
68
68
 
69
- interface Props$1 extends DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement> {
69
+ interface Props$2 extends DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement> {
70
70
  label?: React$1.ReactNode;
71
71
  maxLength?: number;
72
72
  }
73
- declare function TextArea({ label, className, maxLength, onChange, children, ...props }: Props$1): react_jsx_runtime.JSX.Element;
73
+ declare function TextArea({ label, className, maxLength, onChange, children, ...props }: Props$2): react_jsx_runtime.JSX.Element;
74
74
 
75
75
  interface ItemsRecord {
76
76
  typeof: Object;
77
77
  }
78
- interface Props {
78
+ interface Props$1 {
79
79
  baseURI: string;
80
80
  authURI?: string;
81
81
  endpoints: Record<string, Partial<ItemsRecord>>;
@@ -110,7 +110,7 @@ type EnhancedEndpoints<T extends Record<string, ItemsRecord>> = {
110
110
  };
111
111
  };
112
112
 
113
- declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, authURI, endpoints, onError, }: Props): EnhancedEndpoints<T>;
113
+ declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, authURI, endpoints, onError, }: Props$1): EnhancedEndpoints<T>;
114
114
 
115
115
  interface CustomSelectProps extends React$1.DetailedHTMLProps<React$1.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
116
116
  label?: string;
@@ -124,9 +124,9 @@ interface CustomSelectProps extends React$1.DetailedHTMLProps<React$1.InputHTMLA
124
124
  }
125
125
  declare function Select({ label, placeholder, children, strictMode, ...props }: CustomSelectProps): react_jsx_runtime.JSX.Element;
126
126
 
127
- declare function Modal({ button, children, }: {
128
- button: any;
129
- children?: React$1.ReactNode;
130
- }): react_jsx_runtime.JSX.Element;
127
+ interface Props extends React$1.DetailedHTMLProps<React$1.DialogHTMLAttributes<HTMLDialogElement>, HTMLDialogElement> {
128
+ button: React$1.ReactElement;
129
+ }
130
+ declare function Modal({ button, children }: 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
@@ -1,18 +1,18 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1, { DetailedHTMLProps, ButtonHTMLAttributes, Dispatch, SetStateAction, InputHTMLAttributes, ReactNode, TextareaHTMLAttributes } from 'react';
3
3
 
4
- interface Props$4 {
4
+ interface Props$5 {
5
5
  color?: "white" | "primary" | "secondary" | "info" | "danger" | "warning" | "success";
6
6
  children: React.ReactNode;
7
7
  }
8
- declare function Alert({ color, children, ...props }: Props$4): react_jsx_runtime.JSX.Element;
8
+ declare function Alert({ color, children, ...props }: Props$5): react_jsx_runtime.JSX.Element;
9
9
 
10
- interface Props$3 extends DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement> {
10
+ interface Props$4 extends DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement> {
11
11
  icon?: React.ReactNode;
12
12
  size?: "full" | "small";
13
13
  color?: "white" | "primary" | "secondary" | "info" | "danger" | "warning" | "success";
14
14
  }
15
- declare function Button({ className, size, color, children, icon, disabled, ...props }: Props$3): react_jsx_runtime.JSX.Element;
15
+ declare function Button({ className, size, color, children, icon, disabled, ...props }: Props$4): react_jsx_runtime.JSX.Element;
16
16
 
17
17
  type LocationItem = {
18
18
  location: string;
@@ -33,14 +33,14 @@ declare function Container({ children, appName, menuList, navItems, leftPanel, f
33
33
  interface OnSubmitProps extends React$1.FormEvent<HTMLFormElement> {
34
34
  values: Record<string, any>;
35
35
  }
36
- interface Props$2 {
36
+ interface Props$3 {
37
37
  onSubmit: (e: OnSubmitProps) => void | Promise<void>;
38
38
  children: React$1.ReactNode;
39
39
  state?: [any, Dispatch<SetStateAction<any>>];
40
40
  invalidMessage?: string;
41
41
  loader?: React$1.ReactNode;
42
42
  }
43
- declare function Form({ onSubmit, state, invalidMessage, children, loader, }: Props$2): react_jsx_runtime.JSX.Element;
43
+ declare function Form({ onSubmit, state, invalidMessage, children, loader, }: Props$3): react_jsx_runtime.JSX.Element;
44
44
 
45
45
  interface InputProps extends DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
46
46
  label: React.ReactNode;
@@ -66,16 +66,16 @@ interface TableProps extends React.DetailedHTMLProps<React.TableHTMLAttributes<H
66
66
  }
67
67
  declare function Table(props: TableProps): react_jsx_runtime.JSX.Element;
68
68
 
69
- interface Props$1 extends DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement> {
69
+ interface Props$2 extends DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement> {
70
70
  label?: React$1.ReactNode;
71
71
  maxLength?: number;
72
72
  }
73
- declare function TextArea({ label, className, maxLength, onChange, children, ...props }: Props$1): react_jsx_runtime.JSX.Element;
73
+ declare function TextArea({ label, className, maxLength, onChange, children, ...props }: Props$2): react_jsx_runtime.JSX.Element;
74
74
 
75
75
  interface ItemsRecord {
76
76
  typeof: Object;
77
77
  }
78
- interface Props {
78
+ interface Props$1 {
79
79
  baseURI: string;
80
80
  authURI?: string;
81
81
  endpoints: Record<string, Partial<ItemsRecord>>;
@@ -110,7 +110,7 @@ type EnhancedEndpoints<T extends Record<string, ItemsRecord>> = {
110
110
  };
111
111
  };
112
112
 
113
- declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, authURI, endpoints, onError, }: Props): EnhancedEndpoints<T>;
113
+ declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, authURI, endpoints, onError, }: Props$1): EnhancedEndpoints<T>;
114
114
 
115
115
  interface CustomSelectProps extends React$1.DetailedHTMLProps<React$1.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
116
116
  label?: string;
@@ -124,9 +124,9 @@ interface CustomSelectProps extends React$1.DetailedHTMLProps<React$1.InputHTMLA
124
124
  }
125
125
  declare function Select({ label, placeholder, children, strictMode, ...props }: CustomSelectProps): react_jsx_runtime.JSX.Element;
126
126
 
127
- declare function Modal({ button, children, }: {
128
- button: any;
129
- children?: React$1.ReactNode;
130
- }): react_jsx_runtime.JSX.Element;
127
+ interface Props extends React$1.DetailedHTMLProps<React$1.DialogHTMLAttributes<HTMLDialogElement>, HTMLDialogElement> {
128
+ button: React$1.ReactElement;
129
+ }
130
+ declare function Modal({ button, children }: 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
@@ -32692,10 +32692,7 @@ function Select(_a) {
32692
32692
  // src/modal/index.tsx
32693
32693
  var import_react31 = __toESM(require("react"));
32694
32694
  var import_jsx_runtime18 = require("react/jsx-runtime");
32695
- function Modal({
32696
- button,
32697
- children
32698
- }) {
32695
+ function Modal({ button, children }) {
32699
32696
  const modalRef = (0, import_react31.useRef)(null);
32700
32697
  function show() {
32701
32698
  var _a;
@@ -32705,25 +32702,30 @@ function Modal({
32705
32702
  var _a;
32706
32703
  (_a = modalRef.current) == null ? void 0 : _a.close();
32707
32704
  }
32708
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
32709
- import_react31.default.cloneElement(button, {
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
32710
  onClick: (e) => {
32711
32711
  var _a, _b;
32712
32712
  show();
32713
32713
  (_b = (_a = button.props).onClick) == null ? void 0 : _b.call(_a, e);
32714
32714
  }
32715
- }),
32715
+ });
32716
+ }, [button]);
32717
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
32718
+ newButton,
32716
32719
  /* @__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: [
32717
32720
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
32718
- Button,
32721
+ "button",
32719
32722
  {
32720
32723
  onClick: hide,
32721
- color: "danger",
32722
- className: "absolute top-0 right-0 ",
32724
+ className: "absolute top-0 right-0 text-red-500 ",
32723
32725
  children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CloseIcon, {})
32724
32726
  }
32725
32727
  ),
32726
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "flex flex-col gap-3 pt-6", children })
32728
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "flex flex-col gap-3 pt-6", children: newChildren })
32727
32729
  ] }) })
32728
32730
  ] });
32729
32731
  }
package/dist/index.mjs CHANGED
@@ -32687,12 +32687,9 @@ function Select(_a) {
32687
32687
  }
32688
32688
 
32689
32689
  // src/modal/index.tsx
32690
- import React6, { useRef as useRef6 } from "react";
32690
+ import React6, { useMemo as useMemo10, useRef as useRef6 } from "react";
32691
32691
  import { Fragment as Fragment4, jsx as jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
32692
- function Modal({
32693
- button,
32694
- children
32695
- }) {
32692
+ function Modal({ button, children }) {
32696
32693
  const modalRef = useRef6(null);
32697
32694
  function show() {
32698
32695
  var _a;
@@ -32702,25 +32699,30 @@ function Modal({
32702
32699
  var _a;
32703
32700
  (_a = modalRef.current) == null ? void 0 : _a.close();
32704
32701
  }
32705
- return /* @__PURE__ */ jsxs12(Fragment4, { children: [
32706
- React6.cloneElement(button, {
32702
+ const newChildren = useMemo10(() => {
32703
+ return children && React6.cloneElement(children, { hide });
32704
+ }, [children]);
32705
+ const newButton = useMemo10(() => {
32706
+ return button && React6.cloneElement(button, {
32707
32707
  onClick: (e) => {
32708
32708
  var _a, _b;
32709
32709
  show();
32710
32710
  (_b = (_a = button.props).onClick) == null ? void 0 : _b.call(_a, e);
32711
32711
  }
32712
- }),
32712
+ });
32713
+ }, [button]);
32714
+ return /* @__PURE__ */ jsxs12(Fragment4, { children: [
32715
+ newButton,
32713
32716
  /* @__PURE__ */ jsx17("dialog", { ref: modalRef, className: "p-5 border shadow rounded", children: /* @__PURE__ */ jsxs12("div", { className: "relative", children: [
32714
32717
  /* @__PURE__ */ jsx17(
32715
- Button,
32718
+ "button",
32716
32719
  {
32717
32720
  onClick: hide,
32718
- color: "danger",
32719
- className: "absolute top-0 right-0 ",
32721
+ className: "absolute top-0 right-0 text-red-500 ",
32720
32722
  children: /* @__PURE__ */ jsx17(CloseIcon, {})
32721
32723
  }
32722
32724
  ),
32723
- /* @__PURE__ */ jsx17("div", { className: "flex flex-col gap-3 pt-6", children })
32725
+ /* @__PURE__ */ jsx17("div", { className: "flex flex-col gap-3 pt-6", children: newChildren })
32724
32726
  ] }) })
32725
32727
  ] });
32726
32728
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recomponents",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,14 +1,13 @@
1
- import React, { useRef } from "react";
1
+ import React, { useMemo, useRef } from "react";
2
2
  import CloseIcon from "../select/close";
3
- import { Button } from "..";
4
-
5
- export default function Modal({
6
- button,
7
- children,
8
- }: {
9
- button: any;
10
- children?: React.ReactNode;
11
- }) {
3
+ interface Props
4
+ extends React.DetailedHTMLProps<
5
+ React.DialogHTMLAttributes<HTMLDialogElement>,
6
+ HTMLDialogElement
7
+ > {
8
+ button: React.ReactElement;
9
+ }
10
+ export default function Modal({ button, children }: Props) {
12
11
  const modalRef = useRef<HTMLDialogElement>(null);
13
12
  function show() {
14
13
  modalRef.current?.showModal();
@@ -16,27 +15,36 @@ export default function Modal({
16
15
  function hide() {
17
16
  modalRef.current?.close();
18
17
  }
19
-
20
- return (
21
- <>
22
- {React.cloneElement(button, {
23
- onClick: (e) => {
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) => {
24
28
  show();
25
29
  button.props.onClick?.(e);
26
30
  },
27
- })}
31
+ })
32
+ );
33
+ }, [button]);
34
+
35
+ return (
36
+ <>
37
+ {newButton}
28
38
  <dialog ref={modalRef} className="p-5 border shadow rounded">
29
39
  <div className="relative">
30
40
  {/* Botón de cerrar en la esquina superior derecha */}
31
- <Button
41
+ <button
32
42
  onClick={hide}
33
- color="danger"
34
- className="absolute top-0 right-0 "
43
+ className="absolute top-0 right-0 text-red-500 "
35
44
  >
36
45
  <CloseIcon />
37
- </Button>
38
-
39
- <div className="flex flex-col gap-3 pt-6">{children}</div>
46
+ </button>
47
+ <div className="flex flex-col gap-3 pt-6">{newChildren}</div>
40
48
  </div>
41
49
  </dialog>
42
50
  </>