diff --git a/src/app/table/page.tsx b/src/app/table/page.tsx index 5eec72e..6b70e07 100644 --- a/src/app/table/page.tsx +++ b/src/app/table/page.tsx @@ -1,22 +1,36 @@ "use client"; +import React, { useState } from "react"; import Table, { Header, TablaSkeleton } from "@/components/table"; -import React from "react"; +import VistaComponente from "@/components/vista-componente"; +import { tableBasicExample } from "@/snippets/table/table-basic"; export default function Page() { - const headers: Header<{ name: string; age: number; email: string; acciones?: null }>[] = [ + const headers: Header<{ + name: string; + age: number; + email: string; + acciones?: null; + }>[] = [ { key: "name", label: "Nombre", width: "30%" }, { key: "age", label: "Edad", width: "15%" }, { key: "email", label: "Correo", width: "40%" }, ]; - - const data = [ + + const baseData = [ { name: "Juan", age: 20, email: "juan@example.com" }, { name: "María", age: 25, email: "maria@example.com" }, { name: "Pedro", age: 30, email: "pedro@example.com" }, { name: "Luisa", age: 28, email: "luisa@example.com" }, ]; + const [currentPage, setCurrentPage] = useState(1); + const [search, setSearch] = useState(""); + + const filteredData = baseData.filter((item) => + item.name.toLowerCase().includes(search.toLowerCase()) + ); + return (

@@ -24,74 +38,188 @@ export default function Page() {

- El componente <Table /> permite mostrar datos - tabulares con soporte para ordenamiento, paginación, renderizado - personalizado, columnas clicables y estado de carga. + El componente <Table /> permite mostrar datos en + forma tabular, con funcionalidades como ordenamiento, paginación, + renderizado personalizado, clic en filas y un estado de carga esqueleto.


-

🔹 Uso básico

- + {/* USO BÁSICO */} + +
+ -
+ {/* FILAS CLICABLES */} + +
alert(`Seleccionaste a ${row.name}`)} + /> + -

🖱️ Filas clicables

-

- Usa la propiedad onRowClick para manejar interacciones por - fila. -

-
alert(`Seleccionaste a ${row.name}`)} - /> + {/* PAGINACIÓN */} + +
+ -
+ {/* CONTROL DE PÁGINA EXTERNO */} + +
+ -

📄 Paginación personalizada

-

- Usa rowsPerPage para definir cuántas filas mostrar por - página. -

-
+ {/* RENDER PERSONALIZADO */} + +
( + + ), + }, + ]} + data={baseData.map((d) => ({ ...d, acciones: null }))} + /> + -
+ {/* PERSONALIZACIÓN DE ANCHO */} + +
+ -

🎨 Render personalizado por celda

-

- Puedes usar la propiedad render dentro de cada{" "} - header para personalizar cómo se muestra una columna. -

-
( - - ), - }, - ]} - data={data.map((d) => ({ ...d, acciones: null as null }))} - /> + {/* ANCHO AUTOMÁTICO */} + +
+ -
+ {/* SKELETON */} + + + -

⏳ Tabla en estado de carga

-

- El componente TablaSkeleton muestra una tabla de ejemplo - mientras se cargan los datos. Puedes personalizar rows y{" "} - columns. -

- + {/* ROW KEY */} + +
({ ...item, id: index }))} + rowKey={(row) => row.email} + /> + + + {/* FILTRO */} + + setSearch(e.target.value)} + /> +
+ + + {/* PROPS */} +
+

⚙️ Props del componente

+ +
); } diff --git a/src/components/code-block.tsx b/src/components/code-block.tsx new file mode 100644 index 0000000..ddfa8dd --- /dev/null +++ b/src/components/code-block.tsx @@ -0,0 +1,13 @@ +export const CodeBlock = ({ code }: { code: string }) => ( +
+
+      {code}
+    
+ +
+); diff --git a/src/components/vista-componente.tsx b/src/components/vista-componente.tsx new file mode 100644 index 0000000..8afb9ea --- /dev/null +++ b/src/components/vista-componente.tsx @@ -0,0 +1,41 @@ +import React, { useState } from "react"; +import { CodeBlock } from "./code-block"; + +interface VistaComponenteProps { + title: string; + description?: string; + code?: string; + children: React.ReactNode; +} + +export default function VistaComponente({ + title, + description, + code, + children, +}: VistaComponenteProps) { + const [showCode, setShowCode] = useState(false); + + return ( +
+

{title}

+ {description &&

{description}

} + +
+ {children} + + {code && ( +
+ + {showCode && } +
+ )} +
+
+ ); +} diff --git a/src/snippets/table/table-basic.ts b/src/snippets/table/table-basic.ts new file mode 100644 index 0000000..857b439 --- /dev/null +++ b/src/snippets/table/table-basic.ts @@ -0,0 +1,4 @@ +// src/code-snippets/table-basic.ts +export const tableBasicExample = ` +
+`;