forked from styleguidist/react-styleguidist
/
TableOfContentsRenderer.tsx
79 lines (74 loc) · 1.9 KB
/
TableOfContentsRenderer.tsx
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
import React from 'react';
import PropTypes from 'prop-types';
import { Styles } from 'jss';
import Styled, { JssInjectedProps } from 'rsg-components/Styled';
import * as Rsg from '../../../typings';
const styles = ({ space, color, fontFamily, fontSize, borderRadius }: Rsg.Theme): Styles => ({
root: {
fontFamily: fontFamily.base,
},
search: {
padding: space[2],
},
input: {
display: 'block',
width: '100%',
padding: space[1],
color: color.base,
backgroundColor: color.baseBackground,
fontFamily: fontFamily.base,
fontSize: fontSize.base,
border: [[1, color.border, 'solid']],
borderRadius,
transition: 'all ease-in-out .1s',
'&:focus': {
isolate: false,
borderColor: color.link,
boxShadow: [[0, 0, 0, 2, color.focus]],
outline: 0,
},
'&::placeholder': {
isolate: false,
fontFamily: fontFamily.base,
fontSize: fontSize.base,
color: color.light,
},
},
});
interface TableOfContentsRendererProps extends JssInjectedProps {
children?: React.ReactNode;
searchTerm: string;
onSearchTermChange(term: string): void;
}
export const TableOfContentsRenderer: React.FunctionComponent<TableOfContentsRendererProps> = ({
classes,
children,
searchTerm,
onSearchTermChange,
}) => {
return (
<div>
<div className={classes.root}>
<nav>
<div className={classes.search}>
<input
value={searchTerm}
className={classes.input}
placeholder="Filter by name"
aria-label="Filter by name"
onChange={(event) => onSearchTermChange(event.target.value)}
/>
</div>
{children}
</nav>
</div>
</div>
);
};
TableOfContentsRenderer.propTypes = {
classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired,
children: PropTypes.node,
searchTerm: PropTypes.string.isRequired,
onSearchTermChange: PropTypes.func.isRequired,
};
export default Styled<TableOfContentsRendererProps>(styles)(TableOfContentsRenderer);