next-recomponents 2.0.56 → 2.0.57
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.js +363 -233
- package/dist/index.mjs +352 -222
- package/package.json +1 -1
- package/src/table-advanced/h.table.tsx +325 -267
- package/src/table-advanced/header.tsx +8 -6
- package/src/table-advanced/icons.tsx +37 -0
- package/src/table-advanced/searchable.tsx +1 -1
- package/src/table-advanced/use.pagination.tsx +59 -0
|
@@ -28,7 +28,7 @@ export function Header({
|
|
|
28
28
|
padding: string;
|
|
29
29
|
}) {
|
|
30
30
|
const [visible, setVisible] = useState(false);
|
|
31
|
-
|
|
31
|
+
const [hovered, setHovered] = useState(false);
|
|
32
32
|
const sortIndex = context.sort.findIndex((b) => b.field == header);
|
|
33
33
|
const [text, setText] = useState("");
|
|
34
34
|
const cellRef = useRef<HTMLDivElement>(null);
|
|
@@ -95,7 +95,7 @@ export function Header({
|
|
|
95
95
|
<div className="">
|
|
96
96
|
<div
|
|
97
97
|
className={
|
|
98
|
-
"
|
|
98
|
+
" flex items-center justify-center text-center relative "
|
|
99
99
|
}
|
|
100
100
|
style={{ zIndex: 10, height: `${padding}px`, maxHeight: "100px" }}
|
|
101
101
|
>
|
|
@@ -118,10 +118,12 @@ export function Header({
|
|
|
118
118
|
);
|
|
119
119
|
} else
|
|
120
120
|
return (
|
|
121
|
-
<div className="">
|
|
121
|
+
<div className=" ">
|
|
122
122
|
<div
|
|
123
123
|
ref={cellRef}
|
|
124
|
-
className={"
|
|
124
|
+
className={" border-r "}
|
|
125
|
+
onMouseEnter={(e) => setHovered(true)}
|
|
126
|
+
onMouseLeave={(e) => setHovered(false)}
|
|
125
127
|
style={{ zIndex: 10, height: `${padding}px`, maxHeight: "100px" }}
|
|
126
128
|
>
|
|
127
129
|
<div className="flex justify-between items-center ">
|
|
@@ -173,14 +175,14 @@ export function Header({
|
|
|
173
175
|
className="icon font-bold p-1 cursor-pointer pr-3 "
|
|
174
176
|
onClick={(e) => setVisible(true)}
|
|
175
177
|
>
|
|
176
|
-
<DropIcon />
|
|
178
|
+
{hovered ? <DropIcon /> : ""}
|
|
177
179
|
</div>
|
|
178
180
|
</div>
|
|
179
181
|
|
|
180
182
|
{context.currentHeader != header && (
|
|
181
183
|
<div
|
|
182
184
|
onMouseDown={(e) => drag.startDrag(e, header)}
|
|
183
|
-
className="absolute top-0 h-full cursor-col-resize hover:bg-blue-300
|
|
185
|
+
className="absolute top-0 h-full cursor-col-resize hover:bg-blue-300 "
|
|
184
186
|
style={{ right: -2, width: 6, zIndex: 20 }}
|
|
185
187
|
/>
|
|
186
188
|
)}
|
|
@@ -16,6 +16,43 @@ export default function DropIcon() {
|
|
|
16
16
|
</svg>
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
export function PrevIcon() {
|
|
21
|
+
return (
|
|
22
|
+
<svg
|
|
23
|
+
stroke="currentColor"
|
|
24
|
+
fill="currentColor"
|
|
25
|
+
strokeWidth="0"
|
|
26
|
+
viewBox="0 0 24 24"
|
|
27
|
+
height="1em"
|
|
28
|
+
width="1em"
|
|
29
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
30
|
+
>
|
|
31
|
+
<polyline
|
|
32
|
+
fill="none"
|
|
33
|
+
strokeWidth="2"
|
|
34
|
+
points="7 2 17 12 7 22"
|
|
35
|
+
transform="matrix(-1 0 0 1 24 0)"
|
|
36
|
+
></polyline>
|
|
37
|
+
</svg>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function NextIcon() {
|
|
42
|
+
return (
|
|
43
|
+
<svg
|
|
44
|
+
stroke="currentColor"
|
|
45
|
+
fill="currentColor"
|
|
46
|
+
strokeWidth="0"
|
|
47
|
+
viewBox="0 0 24 24"
|
|
48
|
+
height="1em"
|
|
49
|
+
width="1em"
|
|
50
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
51
|
+
>
|
|
52
|
+
<polyline fill="none" stroke-width="2" points="7 2 17 12 7 22"></polyline>
|
|
53
|
+
</svg>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
19
56
|
export function EditIcon() {
|
|
20
57
|
return (
|
|
21
58
|
<svg
|
|
@@ -8,7 +8,7 @@ export default function Searchable({
|
|
|
8
8
|
context: ContextType & Omit<TableProps, "data">;
|
|
9
9
|
}) {
|
|
10
10
|
return (
|
|
11
|
-
<div className="flex justify-start p-2 relative w-96">
|
|
11
|
+
<div className="flex justify-start p-2 relative w-96 text-xs">
|
|
12
12
|
<input
|
|
13
13
|
type="search"
|
|
14
14
|
placeholder="Buscar por ...."
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useState, useMemo, useCallback } from "react";
|
|
2
|
+
|
|
3
|
+
function usePaginacion({
|
|
4
|
+
total,
|
|
5
|
+
tamanioPagina = 100,
|
|
6
|
+
paginaInicial = 1,
|
|
7
|
+
}: {
|
|
8
|
+
total: number;
|
|
9
|
+
tamanioPagina?: number;
|
|
10
|
+
paginaInicial?: number;
|
|
11
|
+
}) {
|
|
12
|
+
const totalPaginas = Math.max(1, Math.ceil(total / tamanioPagina));
|
|
13
|
+
|
|
14
|
+
const [pagina, setPagina] = useState(
|
|
15
|
+
Math.min(Math.max(paginaInicial, 1), totalPaginas),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const inicio = total === 0 ? 0 : (pagina - 1) * tamanioPagina + 1;
|
|
19
|
+
const fin = Math.min(pagina * tamanioPagina, total);
|
|
20
|
+
|
|
21
|
+
const rango = useMemo(() => {
|
|
22
|
+
if (total === 0) return "0 a 0";
|
|
23
|
+
return `${inicio} a ${fin}`;
|
|
24
|
+
}, [inicio, fin, total]);
|
|
25
|
+
|
|
26
|
+
const hasNext = pagina < totalPaginas;
|
|
27
|
+
const hasPrev = pagina > 1;
|
|
28
|
+
|
|
29
|
+
const next = useCallback(() => {
|
|
30
|
+
setPagina((p) => Math.min(p + 1, totalPaginas));
|
|
31
|
+
}, [totalPaginas]);
|
|
32
|
+
|
|
33
|
+
const prev = useCallback(() => {
|
|
34
|
+
setPagina((p) => Math.max(p - 1, 1));
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
const irAPagina = useCallback<(n: number) => void>(
|
|
38
|
+
(n) => {
|
|
39
|
+
setPagina(Math.min(Math.max(n, 1), totalPaginas));
|
|
40
|
+
},
|
|
41
|
+
[totalPaginas],
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
rango,
|
|
46
|
+
inicio,
|
|
47
|
+
fin,
|
|
48
|
+
total,
|
|
49
|
+
pagina,
|
|
50
|
+
totalPaginas,
|
|
51
|
+
hasNext,
|
|
52
|
+
hasPrev,
|
|
53
|
+
next,
|
|
54
|
+
prev,
|
|
55
|
+
irAPagina,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default usePaginacion;
|