import React from 'react'; import { styled } from '@mui/material/styles'; import Card from '@mui/material/Card'; import { CardActionArea } from '@mui/material'; import Paper from '@mui/material/Paper'; import List from '@mui/material/List'; import ListItem from '@mui/material/ListItem'; import EditIcon from '@mui/icons-material/Edit'; import ListItemText from '@mui/material/ListItemText'; import IconButton from '@mui/material/IconButton'; import Grid from '@mui/material/Grid'; import Typography from '@mui/material/Typography'; import DeleteIcon from '@mui/icons-material/Delete'; import AddIcon from '@mui/icons-material/Add'; import TextField from '@mui/material/TextField'; import FormDialog from '../../components/alert/FormDialog'; import styledComponent from "styled-components"; const StyledDiv = styledComponent.div` .text-item.active { background-color: #676767; } `; function generate(items, element, onClickListner,nameKey, idKey) { return items.map((value, index) => React.cloneElement(element, { key: value[nameKey], }, {onClickListner(e, index);}}> ), ); } const Demo = styled('div')(({ theme }) => ({ backgroundColor: theme.palette.background.paper, })); const Item = styled(Paper)(({ theme }) => ({ backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff', ...theme.typography.body2, padding: theme.spacing(1), textAlign: 'center', color: theme.palette.text.secondary, })); function ListCreateUpdateDelete(props) { const [dense, setDense] = React.useState(false); const [open, setOpen] = React.useState(false); const handleClickOpen = () => { setOpen(true); }; const handleClose = () => { setOpen(false); }; const onClickItem = (e, index) => { // 기존 active를 모두 해제 한다. let siblingEle = e.currentTarget.parentNode.parentNode.firstChild; do { siblingEle.firstChild.classList.remove('active'); } while (siblingEle = siblingEle.nextSibling); // 선택된 것만 active로 지정한다. if( Number(e.currentTarget.getAttribute('data-index')) === index ) { e.currentTarget.classList.add('active'); } props.setItemIndex(index); }; return ( {props.title} {generate( props.items, } > , onClickItem, props.nameKey, props.idKey )} ); } export default ListCreateUpdateDelete;