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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
import * as React from 'react'
import {StyleSheet, View} from 'react-native'
import {usePalette} from 'lib/hooks/usePalette'
import {Text} from './text/Text'
import {TextLink} from './Link'
import {isDesktopWeb} from 'platform/detection'
/**
* These utilities are used to define long documents in an html-like
* DSL. See for instance /locale/en/privacy-policy.tsx
*/
interface IsChildProps {
isChild?: boolean
}
// type ReactNodeWithIsChildProp =
// | React.ReactElement<IsChildProps>
// | React.ReactElement<IsChildProps>[]
// | React.ReactNode
export function H1({children}: React.PropsWithChildren<{}>) {
const pal = usePalette('default')
return (
<Text type="title-xl" style={[pal.text, styles.h1]}>
{children}
</Text>
)
}
export function H2({children}: React.PropsWithChildren<{}>) {
const pal = usePalette('default')
return (
<Text type="title-lg" style={[pal.text, styles.h2]}>
{children}
</Text>
)
}
export function H3({children}: React.PropsWithChildren<{}>) {
const pal = usePalette('default')
return (
<Text type="title" style={[pal.text, styles.h3]}>
{children}
</Text>
)
}
export function H4({children}: React.PropsWithChildren<{}>) {
const pal = usePalette('default')
return (
<Text type="title-sm" style={[pal.text, styles.h4]}>
{children}
</Text>
)
}
export function P({children}: React.PropsWithChildren<{}>) {
const pal = usePalette('default')
return (
<Text type="md" style={[pal.text, styles.p]}>
{children}
</Text>
)
}
export function UL({children, isChild}: React.PropsWithChildren<IsChildProps>) {
return (
<View style={[styles.ul, isChild && styles.ulChild]}>
{markChildProps(children)}
</View>
)
}
export function OL({children, isChild}: React.PropsWithChildren<IsChildProps>) {
return (
<View style={[styles.ol, isChild && styles.olChild]}>
{markChildProps(children)}
</View>
)
}
export function LI({
children,
value,
}: React.PropsWithChildren<{value?: string}>) {
const pal = usePalette('default')
return (
<View style={styles.li}>
<Text style={[pal.text, styles.liBullet]}>{value || <>•</>}</Text>
<Text type="md" style={[pal.text, styles.liText]}>
{markChildProps(children)}
</Text>
</View>
)
}
export function A({children, href}: React.PropsWithChildren<{href: string}>) {
const pal = usePalette('default')
return (
<TextLink
type="md"
style={[pal.link, styles.a]}
text={children}
href={href}
/>
)
}
export function STRONG({children}: React.PropsWithChildren<{}>) {
const pal = usePalette('default')
return (
<Text type="md-medium" style={[pal.text]}>
{children}
</Text>
)
}
export function EM({children}: React.PropsWithChildren<{}>) {
const pal = usePalette('default')
return (
<Text type="md" style={[pal.text, styles.em]}>
{children}
</Text>
)
}
function markChildProps(children: React.ReactNode) {
return React.Children.map(children, child => {
if (React.isValidElement(child)) {
return React.cloneElement<IsChildProps>(
child as React.ReactElement<IsChildProps>,
{isChild: true},
)
}
return child
})
}
const styles = StyleSheet.create({
h1: {
marginTop: 20,
marginBottom: 10,
letterSpacing: 0.8,
},
h2: {
marginTop: 20,
marginBottom: 10,
letterSpacing: 0.8,
},
h3: {
marginBottom: 10,
},
h4: {
marginBottom: 10,
fontWeight: 'bold',
},
p: {
marginBottom: 10,
},
ul: {
marginBottom: 10,
paddingLeft: isDesktopWeb ? 18 : 4,
},
ulChild: {
paddingTop: 10,
marginBottom: 0,
},
ol: {
marginBottom: 10,
paddingLeft: isDesktopWeb ? 18 : 4,
},
olChild: {
paddingTop: 10,
marginBottom: 0,
},
li: {
flexDirection: 'row',
paddingRight: 20,
marginBottom: 10,
},
liBullet: {
paddingRight: 10,
},
liText: {},
a: {
marginBottom: 10,
},
em: {
fontStyle: 'italic',
},
})
|