File size: 2,538 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
import {Link} from "react-router-dom";
import {Card, CardContent, Grid, Typography} from "@mui/material";
import React from "react";
import examples from "../examples";
import { withStyles } from "tss-react/mui";
import TextField from '@mui/material/TextField';
const styles = {
container: {
flexGrow: 1,
justifyContent: 'center',
alignItems: 'center',
marginTop: 16,
},
card: {
'&:hover': {
background: 'lightgrey',
fontWeight: 500,
}
},
cardContent: {
'&:last-child': {
padding: 8,
}
},
link: {
textDecoration: 'none',
},
label: {
fontWeight: 'inherit'
}
};
class ExamplesGrid extends React.Component {
state = {
searchVal: ''
}
setSearchVal = (val) => {
this.setState({
searchVal: val
});
}
render() {
const {classes} = this.props;
// Sort Examples alphabetically
const examplesSorted = {};
Object.keys(examples).sort().forEach(function (key) {
examplesSorted[key] = examples[key];
});
const examplesSortedKeys = Object.keys(examplesSorted).filter((item) => {
if (this.state.searchVal === '') return true;
console.dir(item);
return item.toLowerCase().indexOf( this.state.searchVal.toLowerCase() ) !== -1 ? true : false;
});
return (
<React.Fragment>
<Typography variant="h5" align="center">Choose an Example</Typography>
<Typography variant="subtitle2" align="center">({examplesSortedKeys.length}) Examples</Typography>
<Typography variant="subtitle2" align="center" style={{margin:'10px'}}>
<TextField placeholder="Search Examples" value={this.state.searchVal} onChange={(e) => this.setSearchVal(e.target.value)} />
</Typography>
<Grid container className={classes.container} spacing={1}>
{examplesSortedKeys.map((label, index) => (
<Grid key={index} item md={2}>
<Link className={classes.link} to={`/${label.replace(/\s+/g, '-').toLowerCase()}`}>
<Card className={classes.card}>
<CardContent className={classes.cardContent}>
<Typography variant="subtitle1" className={classes.label} align="center">{label}</Typography>
</CardContent>
</Card>
</Link>
</Grid>
))}
</Grid>
</React.Fragment>
);
}
}
export default withStyles(ExamplesGrid, styles);
|