about summary refs log tree commit diff
path: root/src/view/com/util/Html.tsx
blob: 245952e401adab088473d349c56f4c4ce2dcb69a (plain) (blame)
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
import React from 'react'
import {StyleSheet, View} from 'react-native'
import {usePalette} from 'lib/hooks/usePalette'
import {Text} from './text/Text'
import {TextLink} from './Link'

/**
 * These utilities are used to define long documents in an html-like
 * DSL. See for instance /locale/en/privacy-policy.tsx
 */

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}: React.PropsWithChildren<{}>) {
  return <View style={styles.ul}>{children}</View>
}

export function OL({children}: React.PropsWithChildren<{}>) {
  return <View style={styles.ol}>{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 || <>&bull;</>}</Text>
      <Text type="md" style={[pal.text, styles.liText]}>
        {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}
    />
  )
}

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: 18,
  },
  ol: {
    marginBottom: 10,
    paddingLeft: 18,
  },
  li: {
    flexDirection: 'row',
    paddingRight: 10,
    marginBottom: 10,
  },
  liBullet: {
    paddingRight: 10,
  },
  liText: {},
  a: {
    marginBottom: 10,
  },
})