React
HTML
<script
crossorigin
src="https://unpkg.com/react@18/umd/react.development.js"
></script>
<script
crossorigin
src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
></script>
<!--<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">-->
<!--<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js" integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqruptLy" crossorigin="anonymous"></script>-->
<script
src="https://unpkg.com/@material-ui/core/umd/material-ui.production.min.js"
crossorigin="anonymous"
></script>
<div id="app"></div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
.table-container {
margin-top: 25px;
width: 200px;
}
.table-container .MuiTableCell-head {
width: 100%;
}
.list-container {
margin-top: 25px;
}
React
const {useState, useEffect} = React;
const {
Alert, Button, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper, List, ListItem, ListItemText, ListItemAvatar, Avatar, ImageIcon, WorkIcon, BeachAccessIcon, Card, CardContent, Typography, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle
} = MaterialUI;
const HelloWorld = ({name}) => {
const [showAlert, setShowAlert] = useState(false);
onHello = () => {
setShowAlert(true);
}
onCloseHello = () => {
setShowAlert(false);
}
return (
<div className="hello-world-container">
<div className="hello-text">
<Button variant="contained" color="primary" onClick={onHello}>
Hello, {name}
</Button>
{ showAlert && <AlertDialog title="Hello World" text={`Hello, ${name}`} open={showAlert} onClose={onCloseHello}></AlertDialog> }
</div>
<MyTable />
<MyList items={['Alice', 'Bob', 'Cathy']} />
</div>
)
};
const MyList = ({items}) => {
return (
<div className="list-container">
{ !items ?
<Card>
<CardContent>
<Typography gutterBottom sx={{ color: 'text.secondary', fontSize: 14 }}>
No items found.
</Typography>
<Typography variant="body2">
Set the items in the property of the MyList element.
</Typography>
</CardContent>
</Card>
:
<List sx={{ width: '100%', maxWidth: 360, bgcolor: 'background.paper' }} component={Card}>
{ items.map((item, i) => {
return (
<ListItem key={i + 1}>
<ListItemAvatar>
<Avatar>
</Avatar>
</ListItemAvatar>
<ListItemText primary={item} secondary={i + 1} />
</ListItem>
)
})}
</List>
}
</div>
);
}
const MyTable = () => {
const [entries, setEntries] = useState([]);
...