import React, { ComponentType, forwardRef } from 'react'; import { StyleSheet, Platform } from 'react-native'; import { BlockQuoteProps, QuoteProps, TimeProps } from './Text.types'; import { em } from '../css/units'; import Text, { TextProps } from '../primitives/Text'; import View, { ViewProps } from '../primitives/View'; export const P = forwardRef(({ style, ...props }: TextProps, ref) => { return ; }) as ComponentType; export const B = forwardRef(({ style, ...props }: TextProps, ref) => { return ; }) as ComponentType; export const S = forwardRef(({ style, ...props }: TextProps, ref) => { return ; }) as ComponentType; export const I = forwardRef(({ style, ...props }: TextProps, ref) => { return ; }) as ComponentType; export const Q = forwardRef(({ children, cite, style, ...props }: QuoteProps, ref) => { return ( "{children}" ); }) as ComponentType; export const BlockQuote = forwardRef(({ style, cite, ...props }: BlockQuoteProps, ref) => { return ; }) as ComponentType; export const BR = forwardRef(({ style, ...props }: TextProps, ref) => { return ; }) as ComponentType; export const Mark = forwardRef(({ style, ...props }: TextProps, ref) => { return ; }) as ComponentType; export const Code = forwardRef(({ style, ...props }: TextProps, ref) => { return ; }) as ComponentType; function isTextProps(props: any): props is TextProps { return typeof props.children === 'string'; } type PreProps = TextProps | ViewProps; export const Pre = forwardRef((props: PreProps, ref: any) => { if (isTextProps(props)) { return ; } return ; }) as ComponentType; // Extract dateTime to prevent passing it to the native Text element export const Time = forwardRef(({ dateTime, ...props }: TimeProps, ref) => { return ; }) as ComponentType; export const Strong = B; export const Del = S; export const EM = I; export const Span = Text; const styles = StyleSheet.create({ p: { // @ts-ignore marginVertical: em(1), }, b: { fontWeight: 'bold', }, q: { fontStyle: 'italic', }, code: { fontFamily: Platform.select({ default: 'Courier', ios: 'Courier New', android: 'monospace' }), fontWeight: '500', }, pre: { // @ts-ignore marginVertical: em(1), }, blockQuote: { // @ts-ignore marginVertical: em(1), }, br: { width: 0, // @ts-ignore height: em(0.5), }, s: { textDecorationLine: 'line-through', textDecorationStyle: 'solid', }, mark: { backgroundColor: 'yellow', color: 'black', }, i: { fontStyle: 'italic', }, });