This commit is contained in:
David Arranz 2026-05-14 13:06:14 +02:00
parent 09905fc2d3
commit c98bc6cafc
5 changed files with 0 additions and 146 deletions

View File

@ -1,49 +0,0 @@
import { Checkbox } from "@repo/shadcn-ui/components";
import type { ColumnDef } from "@tanstack/react-table";
import * as React from "react";
// Columna estable (definida una vez)
const selectionCol: ColumnDef<any, unknown> = {
id: "select",
header: ({ table }) => (
<Checkbox
checked={table.getIsAllPageRowsSelected() || (table.getIsSomePageRowsSelected() && "indeterminate")}
onCheckedChange={(v) => table.toggleAllPageRowsSelected(!!v)}
aria-label="Select all"
className="translate-y-[2px]"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(v) => row.toggleSelected(!!v)}
aria-label="Select row"
className="translate-y-[2px]"
/>
),
enableSorting: false,
enableHiding: false,
size: 36, minSize: 36, maxSize: 36,
};
// Función pura (sin hooks)
export function withRowSelection<T>(
base: ColumnDef<T, unknown>[],
enabled: boolean
): ColumnDef<T, unknown>[] {
if (!enabled) return base; // misma referencia si está desactivado
// Evita duplicar si ya viene incluida
if (base.length > 0 && base[0].id === selectionCol.id) return base;
return [selectionCol as ColumnDef<T, unknown>, ...base];
}
// Custom hook ergonómico
export function useWithRowSelection<T>(
baseColumns: ColumnDef<T, unknown>[],
enabled: boolean
) {
return React.useMemo(
() => withRowSelection(baseColumns, enabled),
[baseColumns, enabled]
);
}

View File

@ -1,30 +0,0 @@
import { cn } from "@repo/shadcn-ui/lib/utils";
import type * as React from "react";
/** 112 spans por breakpoint */
export type Spans = Partial<{ base: number; sm: number; md: number; lg: number; xl: number }>;
function to12(n?: number) {
if (!n) return 12;
return n < 1 ? 1 : n > 12 ? 12 : n;
}
function spansToClasses(spans?: Spans) {
const s = spans ?? { base: 12 };
const parts: string[] = [];
if (s.base) parts.push(`col-span-${to12(s.base)}`);
if (s.sm) parts.push(`sm:col-span-${to12(s.sm)}`);
if (s.md) parts.push(`md:col-span-${to12(s.md)}`);
if (s.lg) parts.push(`lg:col-span-${to12(s.lg)}`);
if (s.xl) parts.push(`xl:col-span-${to12(s.xl)}`);
return parts.join(" ");
}
export interface CellProps extends React.HTMLAttributes<HTMLDivElement> {
/** 112 por breakpoint (p.ej. { base:12, sm:6, xl:3 }) */
span?: Spans;
}
export function Cell({ span, className, ...rest }: CellProps) {
return <div className={cn(spansToClasses(span), className)} {...rest} />;
}

View File

@ -1,64 +0,0 @@
import { cn } from "@repo/shadcn-ui/lib/utils";
import { type VariantProps, cva } from "class-variance-authority";
import type * as React from "react";
/** 112 columnas por breakpoint */
export type Cols = Partial<{ base: number; sm: number; md: number; lg: number; xl: number }>;
const gridBase = cva("grid", {
variants: {
gap: {
0: "gap-0",
1: "gap-1",
2: "gap-2",
3: "gap-3",
4: "gap-4",
5: "gap-5",
6: "gap-6",
8: "gap-8",
10: "gap-10",
},
align: {
start: "items-start",
center: "items-center",
end: "items-end",
stretch: "items-stretch",
},
},
defaultVariants: {
gap: 6,
align: "stretch",
},
});
function to12(n?: number) {
if (!n) return 12;
return n < 1 ? 1 : n > 12 ? 12 : n;
}
function colsToClasses(cols?: Cols) {
if (!cols) return "";
const c: string[] = [];
if (cols.base) c.push(`grid-cols-${to12(cols.base)}`);
if (cols.sm) c.push(`sm:grid-cols-${to12(cols.sm)}`);
if (cols.md) c.push(`md:grid-cols-${to12(cols.md)}`);
if (cols.lg) c.push(`lg:grid-cols-${to12(cols.lg)}`);
if (cols.xl) c.push(`xl:grid-cols-${to12(cols.xl)}`);
return c.join(" ");
}
export interface GridProps
extends Omit<React.HTMLAttributes<HTMLDivElement>, "children">,
VariantProps<typeof gridBase> {
cols?: Cols;
children?: React.ReactNode;
}
/** Grid genérico: controla columnas visibles por breakpoint */
export function Grid({ className, cols, gap, align, children, ...rest }: GridProps) {
return (
<div className={cn(gridBase({ gap, align }), colsToClasses(cols), className)} {...rest}>
{children}
</div>
);
}

View File

@ -1,2 +0,0 @@
export * from "./cell.tsx";
export * from "./grid.tsx";

View File

@ -6,7 +6,6 @@ export * from "./entity-sheet/index.ts";
export * from "./error-overlay.tsx"; export * from "./error-overlay.tsx";
export * from "./form/index.ts"; export * from "./form/index.ts";
export * from "./full-screen-modal.tsx"; export * from "./full-screen-modal.tsx";
export * from "./grid/index.ts";
export * from "./initials-avatar.tsx"; export * from "./initials-avatar.tsx";
export * from "./layout/index.ts"; export * from "./layout/index.ts";
export * from "./loading-overlay/index.ts"; export * from "./loading-overlay/index.ts";