forked from aravindballa/gatsby-theme-andy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BrainNote.js
41 lines (33 loc) · 1.12 KB
/
BrainNote.js
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
/** @jsx jsx */
import React from 'react';
import { MDXRenderer } from 'gatsby-plugin-mdx';
import { Styled, ThemeProvider, jsx } from 'theme-ui';
import useWindowWidth from '../utils/useWindowWidth';
import components from './MdxComponents';
import Footer from './Footer';
import Popover from './Popover';
import theme from '../theme';
const BrainNote = ({ note }) => {
const [width] = useWindowWidth();
const popups = {};
if (note.outboundReferenceNotes) {
note.outboundReferenceNotes
.filter((reference) => !!reference.childMdx.excerpt)
.forEach((ln, i) => {
popups[ln.slug] = <Popover reference={ln} />;
});
}
const AnchorTagWithPopups = (props) => (
<components.a {...props} popups={popups} noPopups={width < 768} />
);
return (
<ThemeProvider theme={theme} components={{ ...components, a: AnchorTagWithPopups }}>
<div sx={{ flex: '1' }}>
<Styled.h1 sx={{ my: 3 }}>{note.title}</Styled.h1>
<MDXRenderer>{note.childMdx.body}</MDXRenderer>
</div>
<Footer references={note.inboundReferenceNotes} />
</ThemeProvider>
);
};
export default BrainNote;