Merge branch 'iipbs/sn/dev'

This commit is contained in:
dongsilove
2026-01-30 21:38:13 +09:00
18 changed files with 425 additions and 220 deletions
@@ -16,14 +16,16 @@ export type ChkClass = {
chk: boolean;
readonly: boolean;
};
type UiTableProps = {
type UiTableProps<T extends object> = {
headName: React.ReactNode | undefined;
tableData: { [key: string]: any }[];
tableData: T[];
headlist: UiHeadProps[];
pageSize: number;
total: number;
cellClick: ((index: number | undefined, headId: string) => void) | undefined;
onPageChange: (page: number) => void;
cellClassName?: (row: T, headId: string, rowIndex: number) => string;
rowClassName?: (row: T, rowIndex: number) => string;
className?: string;
resetPageNo?: boolean;
children?: React.ReactNode | undefined;
@@ -46,7 +48,7 @@ type UiHeadProps = {
colSpan?: number;
};
export function UiTable({
export function UiTable<T extends object = Record<string, unknown>>({
tableData,
headlist,
pageSize,
@@ -55,6 +57,8 @@ export function UiTable({
children,
cellClick,
onPageChange,
cellClassName,
rowClassName,
className = "",
resetPageNo = false,
boldArray = [],
@@ -63,7 +67,7 @@ export function UiTable({
curPage = 1,
headButton = undefined,
widthFixed = false
}: UiTableProps) {
}: UiTableProps<T>) {
const [cur, setCur] = useState<number>(curPage);
const [idx, setIdx] = useState<number>(index);
const [headerHeight, setHeaderHeight] = useState<number>(0);
@@ -148,8 +152,8 @@ export function UiTable({
</TableHeader>
<TableBody className="text-center">
{tableData.length > 0 ? (
tableData?.map((el: Record<string, unknown>, index) => (
<TableRow key={`row-${index}`}>
tableData?.map((el: T, index) => (
<TableRow key={`row-${index}`} className={rowClassName ? rowClassName(el, index) : ""}>
{headlist
.filter((item) => item.visible != false)
.map(
@@ -163,29 +167,32 @@ export function UiTable({
: cellClick
? "cursor-pointer"
: ""
} sticky top-20 z-40 bg-secondary !font-bold whitespace-pre-line`}
} ${cellClassName ? cellClassName(el, head.id, index) : ""} sticky top-20 z-40 bg-secondary !font-bold whitespace-pre-line`}
style={{ top: `${headerHeight + index * 32 - 4}px` }}
onClick={() => handleCellClick(index, head.id)}
key={`cell-${head.id}-${index}`}
>
{typeof el[head.id] !== "number"
? String(el[head.id] ?? "")
: String(el[head.id]).includes(".")
? String(el[head.id])
.split(".")
.map((part, index) =>
index === 0
? part.replace(
/\B(?=(\d{3})+(?!\d))/g,
",",
)
: part,
)
.join(".")
: String(el[head.id] ?? "").replace(
/\B(?=(\d{3})+(?!\d))/g,
",",
)}
{(() => {
const cellValue = (el as Record<string, unknown>)[head.id];
return typeof cellValue !== "number"
? String(cellValue ?? "")
: String(cellValue).includes(".")
? String(cellValue)
.split(".")
.map((part, index) =>
index === 0
? part.replace(
/\B(?=(\d{3})+(?!\d))/g,
",",
)
: part,
)
.join(".")
: String(cellValue ?? "").replace(
/\B(?=(\d{3})+(?!\d))/g,
",",
);
})()}
</TableCell>
) : (
<TableCell
@@ -194,47 +201,49 @@ export function UiTable({
: cellClick
? "cursor-pointer"
: ""
} mt-[${boldArray.length * 40}px] whitespace-pre-line`}
} ${cellClassName ? cellClassName(el, head.id, index) : ""} mt-[${boldArray.length * 40}px] whitespace-pre-line`}
onClick={() => handleCellClick(index, head.id)}
key={`cell-${head.id}-${index}`}
>
{
//체크박스 유형애서 readOnly가 필요한 경우를 위해서 ChkClass 를 사용해서 readOnly 처리함.
typeof el[head.id] === "object" &&
el[head.id] !== null &&
"chk" in (el[head.id] as object) &&
"readonly" in (el[head.id] as object) ? (
(() => {
const cellValue = (el as Record<string, unknown>)[head.id];
return typeof cellValue === "object" &&
cellValue !== null &&
"chk" in (cellValue as object) &&
"readonly" in (cellValue as object) ? (
<Checkbox
checked={
(el[head.id] as ChkClass)?.chk === true
(cellValue as ChkClass)?.chk === true
}
onCheckedChange={(checked) => {
{
console.log(el[head.id]);
console.log(cellValue);
}
if (
(el[head.id] as ChkClass).readonly == true
(cellValue as ChkClass).readonly == true
)
return;
(el[head.id] as ChkClass).chk =
(cellValue as ChkClass).chk =
Boolean(checked);
}}
>
<Check className="h-6 w-6 text-primary" />
</Checkbox>
) : typeof el[head.id] === "boolean" ? (
) : typeof cellValue === "boolean" ? (
<Checkbox
checked={el[head.id] === true}
checked={cellValue === true}
onCheckedChange={(checked) => {
el[head.id] = checked;
(el as Record<string, unknown>)[head.id] = checked;
}}
>
<Check className="h-6 w-6 text-primary" />
</Checkbox>
) : typeof el[head.id] !== "number" ? (
String(el[head.id] ?? "")
) : String(el[head.id]).includes(".") ? (
String(el[head.id])
) : typeof cellValue !== "number" ? (
String(cellValue ?? "")
) : String(cellValue).includes(".") ? (
String(cellValue)
.split(".")
.map((part, index) =>
index === 0
@@ -246,11 +255,12 @@ export function UiTable({
)
.join(".")
) : (
String(el[head.id] ?? "").replace(
String(cellValue ?? "").replace(
/\B(?=(\d{3})+(?!\d))/g,
",",
)
)
);
})()
}
</TableCell>
)),