155058f92SEvan Baconimport React, { ComponentType, forwardRef } from 'react'; 2600afe4bSEvan Baconimport { StyleSheet, Platform } from 'react-native'; 355058f92SEvan Bacon 4*8a424bebSJames Ideimport { BlockQuoteProps, QuoteProps, TimeProps } from './Text.types'; 555058f92SEvan Baconimport { em } from '../css/units'; 655058f92SEvan Baconimport Text, { TextProps } from '../primitives/Text'; 755058f92SEvan Baconimport View, { ViewProps } from '../primitives/View'; 855058f92SEvan Bacon 955058f92SEvan Baconexport const P = forwardRef(({ style, ...props }: TextProps, ref) => { 1055058f92SEvan Bacon return <Text {...props} style={[styles.p, style]} ref={ref} />; 1155058f92SEvan Bacon}) as ComponentType<TextProps>; 1255058f92SEvan Bacon 1355058f92SEvan Baconexport const B = forwardRef(({ style, ...props }: TextProps, ref) => { 1460ea71b8SEvan Bacon return <Text {...props} style={[styles.b, style]} ref={ref} />; 1555058f92SEvan Bacon}) as ComponentType<TextProps>; 1655058f92SEvan Bacon 1755058f92SEvan Baconexport const S = forwardRef(({ style, ...props }: TextProps, ref) => { 1860ea71b8SEvan Bacon return <Text {...props} style={[styles.s, style]} ref={ref} />; 1955058f92SEvan Bacon}) as ComponentType<TextProps>; 2055058f92SEvan Bacon 2155058f92SEvan Baconexport const I = forwardRef(({ style, ...props }: TextProps, ref) => { 2260ea71b8SEvan Bacon return <Text {...props} style={[styles.i, style]} ref={ref} />; 2355058f92SEvan Bacon}) as ComponentType<TextProps>; 2455058f92SEvan Bacon 2555058f92SEvan Baconexport const Q = forwardRef(({ children, cite, style, ...props }: QuoteProps, ref) => { 2655058f92SEvan Bacon return ( 2760ea71b8SEvan Bacon <Text {...props} style={[styles.q, style]} ref={ref}> 2855058f92SEvan Bacon "{children}" 2960ea71b8SEvan Bacon </Text> 3055058f92SEvan Bacon ); 3155058f92SEvan Bacon}) as ComponentType<QuoteProps>; 3255058f92SEvan Bacon 3355058f92SEvan Baconexport const BlockQuote = forwardRef(({ style, cite, ...props }: BlockQuoteProps, ref) => { 3455058f92SEvan Bacon return <View {...props} style={[styles.blockQuote, style]} ref={ref} />; 3555058f92SEvan Bacon}) as ComponentType<BlockQuoteProps>; 3655058f92SEvan Bacon 3755058f92SEvan Baconexport const BR = forwardRef(({ style, ...props }: TextProps, ref) => { 3855058f92SEvan Bacon return <Text {...props} style={[styles.br, style]} ref={ref} />; 3955058f92SEvan Bacon}) as ComponentType<TextProps>; 4055058f92SEvan Bacon 4155058f92SEvan Baconexport const Mark = forwardRef(({ style, ...props }: TextProps, ref) => { 4255058f92SEvan Bacon return <Text {...props} style={[styles.mark, style]} ref={ref} />; 4355058f92SEvan Bacon}) as ComponentType<TextProps>; 4455058f92SEvan Bacon 4537e143d9SEvan Baconexport const Code = forwardRef(({ style, ...props }: TextProps, ref) => { 4637e143d9SEvan Bacon return <Text {...props} style={[styles.code, style]} ref={ref} />; 4755058f92SEvan Bacon}) as ComponentType<TextProps>; 4855058f92SEvan Bacon 4955058f92SEvan Baconfunction isTextProps(props: any): props is TextProps { 5055058f92SEvan Bacon return typeof props.children === 'string'; 5155058f92SEvan Bacon} 5255058f92SEvan Bacon 5355058f92SEvan Bacontype PreProps = TextProps | ViewProps; 5455058f92SEvan Bacon 5555058f92SEvan Baconexport const Pre = forwardRef((props: PreProps, ref: any) => { 5655058f92SEvan Bacon if (isTextProps(props)) { 5737e143d9SEvan Bacon return <Text {...props} style={[styles.code, styles.pre, props.style]} ref={ref} />; 5855058f92SEvan Bacon } 5955058f92SEvan Bacon return <View {...props} style={[styles.pre, props.style]} ref={ref} />; 6055058f92SEvan Bacon}) as ComponentType<PreProps>; 6155058f92SEvan Bacon 6255058f92SEvan Bacon// Extract dateTime to prevent passing it to the native Text element 6355058f92SEvan Baconexport const Time = forwardRef(({ dateTime, ...props }: TimeProps, ref) => { 6455058f92SEvan Bacon return <Text {...props} ref={ref} />; 6555058f92SEvan Bacon}) as ComponentType<TimeProps>; 6655058f92SEvan Bacon 6755058f92SEvan Baconexport const Strong = B; 6855058f92SEvan Baconexport const Del = S; 6955058f92SEvan Baconexport const EM = I; 70f4a8f663SEvan Baconexport const Span = Text; 7155058f92SEvan Bacon 7255058f92SEvan Baconconst styles = StyleSheet.create({ 7355058f92SEvan Bacon p: { 741aa8cfddSBrent Vatne // @ts-ignore 7555058f92SEvan Bacon marginVertical: em(1), 7655058f92SEvan Bacon }, 7755058f92SEvan Bacon b: { 7855058f92SEvan Bacon fontWeight: 'bold', 7955058f92SEvan Bacon }, 8055058f92SEvan Bacon q: { 8155058f92SEvan Bacon fontStyle: 'italic', 8255058f92SEvan Bacon }, 8337e143d9SEvan Bacon code: { 84db776b89SEvan Bacon fontFamily: Platform.select({ default: 'Courier', ios: 'Courier New', android: 'monospace' }), 8537e143d9SEvan Bacon fontWeight: '500', 8637e143d9SEvan Bacon }, 8755058f92SEvan Bacon pre: { 881aa8cfddSBrent Vatne // @ts-ignore 8955058f92SEvan Bacon marginVertical: em(1), 9055058f92SEvan Bacon }, 9155058f92SEvan Bacon blockQuote: { 921aa8cfddSBrent Vatne // @ts-ignore 9355058f92SEvan Bacon marginVertical: em(1), 9455058f92SEvan Bacon }, 9555058f92SEvan Bacon br: { 9655058f92SEvan Bacon width: 0, 971aa8cfddSBrent Vatne // @ts-ignore 9860ea71b8SEvan Bacon height: em(0.5), 9955058f92SEvan Bacon }, 10055058f92SEvan Bacon s: { 10155058f92SEvan Bacon textDecorationLine: 'line-through', 10255058f92SEvan Bacon textDecorationStyle: 'solid', 10355058f92SEvan Bacon }, 10455058f92SEvan Bacon mark: { 10555058f92SEvan Bacon backgroundColor: 'yellow', 10655058f92SEvan Bacon color: 'black', 10755058f92SEvan Bacon }, 10855058f92SEvan Bacon i: { 10955058f92SEvan Bacon fontStyle: 'italic', 11055058f92SEvan Bacon }, 11155058f92SEvan Bacon}); 112