Commit 9dfef253826782c2dfb5b6335d3dd317756bf3f3
ux: improve typography and styling in markdown posts
David Gómez authored on 4/3/2020, 11:06:22 AMstaltz committed on 4/3/2020, 11:06:22 AM
Parent: dc16dad0ac4a489f5b6e01d067074e5f2a45105f
Files changed
src/frontend/components/Markdown.ts | changed |
src/frontend/global-styles/typography.ts | changed |
src/frontend/components/Markdown.ts | ||
---|---|---|
@@ -3,96 +3,105 @@ | ||
3 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
4 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | 6 | |
7 | -import {createElement, PureComponent} from 'react'; | |
8 | -import {View, Text, Linking, StyleSheet, TextProperties} from 'react-native'; | |
7 | +import {createElement as $, PureComponent} from 'react'; | |
8 | +import {Linking, StyleSheet, Text, TextProperties, View} from 'react-native'; | |
9 | 9 | import {Palette} from '../global-styles/palette'; |
10 | 10 | import {Dimensions} from '../global-styles/dimens'; |
11 | 11 | import {Typography as Typ} from '../global-styles/typography'; |
12 | 12 | import {GlobalEventBus} from '../drivers/eventbus'; |
13 | 13 | import ZoomableImage from './ZoomableImage'; |
14 | -const remark = require('remark'); | |
15 | -const ReactMarkdown = require('react-markdown'); | |
16 | -const normalizeForReactNative = require('mdast-normalize-react-native'); | |
17 | 14 | const gemojiToEmoji = require('remark-gemoji-to-emoji'); |
18 | 15 | const imagesToSsbServeBlobs = require('remark-images-to-ssb-serve-blobs'); |
16 | +const linkifyRegex = require('remark-linkify-regex'); | |
17 | +const normalizeForReactNative = require('mdast-normalize-react-native'); | |
18 | +const ReactMarkdown = require('react-markdown'); | |
19 | 19 | const Ref = require('ssb-ref'); |
20 | -const linkifyRegex = require('remark-linkify-regex'); | |
20 | +const remark = require('remark'); | |
21 | 21 | |
22 | -const $ = createElement; | |
23 | - | |
24 | 22 | const textProps: TextProperties = { |
25 | 23 | selectable: true, |
26 | 24 | textBreakStrategy: 'simple', |
27 | 25 | }; |
28 | 26 | |
29 | 27 | const styles = StyleSheet.create({ |
30 | - paragraph: { | |
31 | - flexWrap: 'wrap', | |
32 | - flexDirection: 'row', | |
33 | - alignItems: 'flex-start', | |
34 | - justifyContent: 'flex-start', | |
35 | - marginVertical: Dimensions.verticalSpaceSmall, | |
36 | - }, | |
37 | - | |
38 | - paragraphText: { | |
39 | - flexWrap: 'wrap', | |
40 | - overflow: 'visible', | |
41 | - color: Palette.text, | |
42 | - }, | |
43 | - | |
44 | 28 | text: {}, |
45 | 29 | |
46 | - listItemText: { | |
47 | - color: Palette.text, | |
48 | - }, | |
49 | - | |
50 | 30 | heading1: { |
51 | - fontWeight: 'bold', | |
52 | - marginVertical: Dimensions.verticalSpaceNormal, | |
53 | - fontSize: Typ.baseSize * Typ.scaleUp * Typ.scaleUp, | |
31 | + fontWeight: '700', | |
54 | 32 | color: Palette.text, |
33 | + fontSize: Typ.baseSize * Math.pow(Typ.scaleUp, 3), | |
34 | + lineHeight: Typ.baseSize * Math.pow(Typ.scaleUp, 3) * Typ.baseLeading, | |
35 | + marginVertical: Dimensions.verticalSpaceSmall, | |
55 | 36 | }, |
56 | 37 | |
57 | 38 | heading2: { |
58 | - fontWeight: 'bold', | |
59 | - marginVertical: Dimensions.verticalSpaceNormal, | |
60 | - fontSize: Typ.baseSize * Typ.scaleUp, | |
39 | + fontWeight: '700', | |
61 | 40 | color: Palette.text, |
41 | + fontSize: Typ.baseSize * Math.pow(Typ.scaleUp, 2), | |
42 | + lineHeight: Typ.baseSize * Math.pow(Typ.scaleUp, 2) * Typ.baseLeading, | |
43 | + marginVertical: Dimensions.verticalSpaceSmall, | |
62 | 44 | }, |
63 | 45 | |
64 | 46 | heading3: { |
65 | - fontWeight: 'bold', | |
47 | + fontWeight: '700', | |
48 | + color: Palette.text, | |
49 | + fontSize: Typ.baseSize * Typ.scaleUp, | |
50 | + lineHeight: Typ.baseSize * Typ.scaleUp * Typ.baseLeading, | |
66 | 51 | marginVertical: Dimensions.verticalSpaceSmall, |
67 | - fontSize: Typ.baseSize, | |
68 | - color: Palette.text, | |
69 | 52 | }, |
70 | 53 | |
71 | 54 | heading4: { |
72 | - fontWeight: 'bold', | |
73 | - fontSize: Typ.baseSize * Typ.scaleDown, | |
55 | + fontWeight: '700', | |
74 | 56 | color: Palette.text, |
57 | + fontSize: Typ.baseSize, | |
58 | + lineHeight: Typ.baseSize * Typ.baseLeading, | |
59 | + marginVertical: Dimensions.verticalSpaceSmall, | |
75 | 60 | }, |
76 | 61 | |
77 | 62 | heading5: { |
78 | - fontWeight: 'bold', | |
79 | - fontSize: Typ.baseSize * Typ.scaleDown * Typ.scaleDown, | |
63 | + fontWeight: '700', | |
80 | 64 | color: Palette.text, |
65 | + fontSize: Typ.baseSize * Typ.scaleDown, | |
66 | + lineHeight: Typ.baseSize * Typ.baseLeading, | |
67 | + marginVertical: Dimensions.verticalSpaceSmall, | |
81 | 68 | }, |
82 | 69 | |
83 | 70 | heading6: { |
84 | - fontWeight: 'bold', | |
85 | - fontSize: Typ.baseSize * Typ.scaleDown * Typ.scaleDown * Typ.scaleDown, | |
71 | + fontWeight: '700', | |
86 | 72 | color: Palette.text, |
73 | + fontSize: Typ.baseSize * Math.pow(Typ.scaleDown, 2), | |
74 | + lineHeight: Typ.baseSize * Typ.baseLeading, | |
75 | + marginVertical: Dimensions.verticalSpaceSmall, | |
87 | 76 | }, |
88 | 77 | |
78 | + paragraph: { | |
79 | + flexWrap: 'wrap', | |
80 | + flexDirection: 'row', | |
81 | + alignItems: 'flex-start', | |
82 | + justifyContent: 'flex-start', | |
83 | + marginVertical: Dimensions.verticalSpaceSmall, | |
84 | + }, | |
85 | + | |
86 | + paragraphText: { | |
87 | + flexWrap: 'wrap', | |
88 | + overflow: 'visible', | |
89 | + color: Palette.text, | |
90 | + fontSize: Typ.baseSize, | |
91 | + lineHeight: Typ.baseSize * Typ.baseLeading, | |
92 | + }, | |
93 | + | |
94 | + strong: { | |
95 | + fontWeight: '700', | |
96 | + }, | |
97 | + | |
89 | 98 | em: { |
90 | 99 | fontStyle: 'italic', |
91 | 100 | }, |
92 | 101 | |
93 | - strong: { | |
94 | - fontWeight: 'bold', | |
102 | + strikethrough: { | |
103 | + textDecorationLine: 'line-through', | |
95 | 104 | }, |
96 | 105 | |
97 | 106 | link: { |
98 | 107 | textDecorationLine: 'underline', |
@@ -102,54 +111,52 @@ | ||
102 | 111 | color: Palette.textBrand, |
103 | 112 | textDecorationLine: 'underline', |
104 | 113 | }, |
105 | 114 | |
106 | - inlineCode: { | |
107 | - backgroundColor: Palette.backgroundTextWeak, | |
108 | - color: Palette.textWeak, | |
109 | - paddingLeft: 4, | |
110 | - paddingRight: 4, | |
111 | - borderRadius: 2, | |
112 | - fontFamily: Typ.fontFamilyMonospace, | |
115 | + listItemText: { | |
116 | + color: Palette.text, | |
117 | + fontSize: Typ.baseSize, | |
118 | + lineHeight: Typ.baseSize * Typ.baseLeading, | |
113 | 119 | }, |
114 | 120 | |
115 | - strikethrough: { | |
116 | - textDecorationLine: 'line-through', | |
121 | + orderedBullet: { | |
122 | + fontWeight: '700', | |
117 | 123 | }, |
118 | 124 | |
119 | - blockquote: { | |
125 | + inlineCode: { | |
120 | 126 | backgroundColor: Palette.backgroundTextWeak, |
121 | - borderLeftWidth: 3, | |
122 | - borderLeftColor: Palette.backgroundTextWeakStrong, | |
123 | - paddingLeft: Dimensions.horizontalSpaceSmall, | |
124 | - paddingRight: 1, | |
127 | + fontFamily: Typ.fontFamilyMonospace, | |
128 | + color: Palette.textWeak, | |
125 | 129 | }, |
126 | 130 | |
127 | 131 | codeBlock: { |
128 | 132 | backgroundColor: Palette.backgroundTextWeak, |
129 | - marginVertical: 2, | |
130 | - paddingVertical: 3, | |
131 | - paddingHorizontal: 5, | |
132 | - borderRadius: 2, | |
133 | + marginVertical: Dimensions.verticalSpaceSmall, | |
134 | + padding: Dimensions.verticalSpaceSmall, | |
133 | 135 | }, |
134 | 136 | |
135 | 137 | codeText: { |
138 | + fontFamily: Typ.fontFamilyMonospace, | |
139 | + fontWeight: '400', | |
136 | 140 | color: Palette.textWeak, |
137 | 141 | fontSize: Typ.fontSizeSmall, |
138 | - fontWeight: 'normal', | |
139 | - fontFamily: Typ.fontFamilyMonospace, | |
142 | + lineHeight: Typ.fontSizeSmall * Typ.baseLeading, | |
140 | 143 | }, |
141 | 144 | |
145 | + blockquote: { | |
146 | + backgroundColor: Palette.backgroundTextWeak, | |
147 | + borderLeftWidth: 3, | |
148 | + borderLeftColor: Palette.backgroundTextWeakStrong, | |
149 | + marginVertical: Dimensions.verticalSpaceSmall, | |
150 | + paddingLeft: Dimensions.horizontalSpaceSmall, | |
151 | + paddingRight: 1, | |
152 | + }, | |
153 | + | |
142 | 154 | horizontalLine: { |
143 | 155 | backgroundColor: Palette.textLine, |
156 | + marginVertical: Dimensions.verticalSpaceSmall, | |
144 | 157 | height: 2, |
145 | - marginTop: Dimensions.verticalSpaceSmall, | |
146 | - marginBottom: Dimensions.verticalSpaceSmall, | |
147 | 158 | }, |
148 | - | |
149 | - orderedBullet: { | |
150 | - fontWeight: 'bold', | |
151 | - }, | |
152 | 159 | }); |
153 | 160 | |
154 | 161 | const renderers = { |
155 | 162 | root: (props: {children: any}) => $(View, null, props.children), |
src/frontend/global-styles/typography.ts | ||
---|---|---|
@@ -5,18 +5,20 @@ | ||
5 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | 6 | |
7 | 7 | import {Platform} from 'react-native'; |
8 | 8 | |
9 | -const BASE_SIZE = 15; // px | |
9 | +const BASE_SIZE = 16; // px | pt | |
10 | 10 | const SCALE = 1.125; |
11 | +const LEADING = 1.5; | |
11 | 12 | |
12 | 13 | const scaleUp = SCALE; |
13 | 14 | const scaleDown = 1 / SCALE; |
14 | 15 | |
15 | 16 | export const Typography = { |
16 | 17 | scaleUp, |
17 | 18 | scaleDown, |
18 | 19 | baseSize: BASE_SIZE, |
20 | + baseLeading: LEADING, | |
19 | 21 | fontSizeLarge: BASE_SIZE * scaleUp * scaleUp, |
20 | 22 | fontSizeBig: BASE_SIZE * scaleUp, |
21 | 23 | fontSizeNormal: BASE_SIZE, |
22 | 24 | fontSizeSmall: BASE_SIZE * scaleDown, |
Built with git-ssb-web