|
| 1 | +import React from 'react' |
| 2 | +import { StyleSheet, View, Text } from 'react-native' |
| 3 | +import { MDXStyles, MDXComponents } from '@bacons/mdx' |
| 4 | +import { Link } from '../navigation/Link' |
| 5 | +import './markdown.theme.css' // Duplicate of the React-Native styles from this file |
| 6 | + |
| 7 | +/* --- Types -------------------------------------------------------------------------------------- */ |
| 8 | + |
| 9 | +type MarkdownScreenProps = { |
| 10 | + children: React.ReactNode |
| 11 | +} |
| 12 | + |
| 13 | +/* --- <MarkdownTheme/> --------------------------------------------------------------------------- */ |
| 14 | + |
| 15 | +const MarkdownTheme = ({ children }: MarkdownScreenProps) => { |
| 16 | + return ( |
| 17 | + <View nativeID="markdown-theme"> |
| 18 | + <MDXStyles |
| 19 | + h1={styles.h1} |
| 20 | + h2={styles.h2} |
| 21 | + p={styles.p} |
| 22 | + ul={styles.ul} |
| 23 | + li={styles.li} |
| 24 | + blockquote={styles.blockquote} |
| 25 | + a={styles.link} |
| 26 | + > |
| 27 | + <MDXComponents |
| 28 | + h1={(props) => <Text {...props} style={{ ...styles.h1 }} />} |
| 29 | + h2={(props) => <Text {...props} style={{ ...styles.h2 }} />} |
| 30 | + p={(props) => <Text {...props} style={{ ...styles.p }} />} |
| 31 | + ul={(props) => <View {...props} style={{ ...styles.ul }} />} |
| 32 | + li={(props) => <Text {...props} style={{ ...styles.li }} />} |
| 33 | + blockquote={(props) => <View {...props} style={{ ...styles.blockquote }} />} // prettier-ignore |
| 34 | + a={(props) => <Link {...props} style={{ ...styles.link }} />} |
| 35 | + > |
| 36 | + {children} |
| 37 | + </MDXComponents> |
| 38 | + </MDXStyles> |
| 39 | + </View> |
| 40 | + ) |
| 41 | +} |
| 42 | + |
| 43 | +/* --- Styles ---------------------------------------------------------------------------------- */ |
| 44 | +// -i- These styles won't work in Next.js for some reason, duplicate them in markdown.theme.css |
| 45 | + |
| 46 | +const styles = StyleSheet.create({ |
| 47 | + h1: { |
| 48 | + fontSize: 24, |
| 49 | + fontWeight: 'bold', |
| 50 | + marginBottom: 16, |
| 51 | + }, |
| 52 | + h2: { |
| 53 | + fontSize: 20, |
| 54 | + fontWeight: 'bold', |
| 55 | + marginBottom: 16, |
| 56 | + }, |
| 57 | + p: { |
| 58 | + fontSize: 16, |
| 59 | + marginBottom: 16, |
| 60 | + lineHeight: 22, |
| 61 | + }, |
| 62 | + ul: { |
| 63 | + padding: 0, |
| 64 | + }, |
| 65 | + li: { |
| 66 | + fontSize: 16, |
| 67 | + marginBottom: 16, |
| 68 | + lineHeight: 22, |
| 69 | + }, |
| 70 | + blockquote: { |
| 71 | + borderLeftColor: 'lightgray', |
| 72 | + borderStyle: 'solid', |
| 73 | + borderLeftWidth: 6, |
| 74 | + fontSize: 16, |
| 75 | + paddingLeft: 16, |
| 76 | + paddingTop: 4, |
| 77 | + lineHeight: 22, |
| 78 | + }, |
| 79 | + link: { |
| 80 | + marginTop: 16, |
| 81 | + fontSize: 16, |
| 82 | + color: 'blue', |
| 83 | + textAlign: 'center', |
| 84 | + textDecorationLine: 'underline', |
| 85 | + }, |
| 86 | +}) |
| 87 | + |
| 88 | +/* --- Exports --------------------------------------------------------------------------------- */ |
| 89 | + |
| 90 | +export default MarkdownTheme |
0 commit comments