모달 트리거 변경으로 수정 및 테이블 셀클릭 이벤트 파라미터추가(셀 head값)
This commit is contained in:
@@ -1,50 +1,29 @@
|
||||
import { Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTrigger } from "@common/components";
|
||||
import { useState } from "react";
|
||||
|
||||
type ModalType = {
|
||||
bodyClass: string;
|
||||
butNm: string;
|
||||
title: string | undefined;
|
||||
body: React.ReactNode;
|
||||
open?: boolean;
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
}
|
||||
|
||||
export function UiModal({ bodyClass, butNm, title, body, open, onOpenChange }: ModalType) {
|
||||
const dialogProps = open !== undefined && onOpenChange !== undefined && title !== undefined
|
||||
? { open, onOpenChange, title }
|
||||
: {};
|
||||
|
||||
export function UiModal({ bodyClass, body, open, onOpenChange }: ModalType) {
|
||||
|
||||
return (
|
||||
<>
|
||||
{!open && (
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button className="mr-4 rounded-lg">{butNm}</Button>
|
||||
</DialogTrigger>
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className={bodyClass}>
|
||||
<DialogHeader>
|
||||
<DialogDescription>
|
||||
</DialogDescription>
|
||||
|
||||
</DialogHeader>
|
||||
{body}
|
||||
{(open && body)}
|
||||
<DialogFooter className="sm:justify-start">
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
{open && (
|
||||
<Dialog {...dialogProps}>
|
||||
<DialogContent className={bodyClass}>
|
||||
<DialogHeader>
|
||||
<DialogDescription>
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{body}
|
||||
<DialogFooter className="sm:justify-start">
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ type UiTableProps = {
|
||||
pageSize: number;
|
||||
total: number;
|
||||
children: React.ReactNode | undefined;
|
||||
cellClick : ((index:number|undefined)=>void) | undefined;
|
||||
cellClick : ((index:number|undefined, headId:string)=>void )| undefined;
|
||||
onPageChange: (page: number) => void;
|
||||
className?: string;
|
||||
}
|
||||
@@ -26,20 +26,17 @@ export function UiTable({ tableData, headlist, pageSize, total, children, headNa
|
||||
setCur(page);
|
||||
onPageChange(page);
|
||||
}
|
||||
const handleCellClick = (index: number) => {
|
||||
|
||||
|
||||
const handleCellClick = (index: number,headId:string )=> {
|
||||
if (cellClick) {
|
||||
console.log("cellClick", index);
|
||||
cellClick(index);
|
||||
cellClick(index,headId);
|
||||
setIdx(index);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
console.log("idx", idx);
|
||||
console.log("idx", idx);
|
||||
|
||||
},[idx])
|
||||
return (
|
||||
<>
|
||||
{headName ? <div className="card-header">
|
||||
@@ -59,7 +56,7 @@ useEffect(() => {
|
||||
<TableRow key={index + "row"} >
|
||||
{headlist?.map((head) => (
|
||||
// <TableCell className={cellClick&&idx==index?"bg-black/10 cursor-pointer":cellClick?"cursor-pointer":""} onClick={()=>handleCellClick(index)} key={head.id + index}>{el[head.id]}</TableCell>
|
||||
<TableCell className={cellClick&&idx==index?"opacity-40 cursor-pointer":cellClick?"cursor-pointer":""} onClick={()=>handleCellClick(index)} key={head.id + index}>{el[head.id]}</TableCell>
|
||||
<TableCell className={cellClick&&idx==index?"opacity-40 cursor-pointer":cellClick?"cursor-pointer":""} onClick={(e)=>handleCellClick(index,head.id)} key={head.id + index}>{el[head.id]}</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user