import * as React from 'react'; import clsx from 'clsx'; import FuzzySearch from 'fuzzy-search'; import ReactMarkdown from 'react-markdown'; import SearchBar from 'material-ui-search-bar'; import { Table, Paper, TableBody, TableCell, TableHead, TableRow, makeStyles, Typography, Grid, } from '@material-ui/core'; import PropTypesDoc from '../prop-types.json'; import Code from './Code'; const useStyles = makeStyles((theme) => ({ header: { marginTop: 24, }, tableWrapper: { overflowX: 'auto', }, required: { color: '#8bc34a', }, type: { minWidth: 240, maxWidth: 240, color: theme.palette.primary.main, }, defaultValue: { minWidth: 210, '& > span': { fontSize: 15, borderBottom: `1px dotted ${theme.palette.text.primary}`, }, }, description: { minWidth: 340, }, searchBar: { marginTop: 8, marginBottom: 8, [theme.breakpoints.up('sm')]: { marginTop: -8, }, }, })); interface PropTypesTableProps { disableHeader?: boolean; src: keyof typeof PropTypesDoc; } const PropTypesTableLazy: React.FC = ({ disableHeader, src }) => { const classes = useStyles(); const [searchString, setSearchString] = React.useState(''); const propsDoc = Object.values(PropTypesDoc[src]).sort((a, b) => { if (a.required && !b.required) { return -1; } if (!a.required && b.required) { return 1; } return a.name.localeCompare(b.name); }); const searcher = React.useMemo( () => new FuzzySearch(propsDoc, ['name', 'defaultValue', 'description', 'type.name'], { sort: true, caseSensitive: false, }), [propsDoc] ); const propsToShow = React.useMemo(() => { return searcher.search(searchString.trim()); }, [searchString, searcher]); return ( {!disableHeader && ( Props setSearchString('')} className={classes.searchBar} /> )} Name Type Default Description {propsToShow.map((prop) => ( {prop.required ? `${prop.name} *` : prop.name}{' '} {prop.type.name} {prop.defaultValue && prop.defaultValue.value} ))}
); }; export default React.memo(PropTypesTableLazy);