-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathTextRenderer.tsx
More file actions
86 lines (76 loc) · 2.17 KB
/
Copy pathTextRenderer.tsx
File metadata and controls
86 lines (76 loc) · 2.17 KB
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
import { useRef } from 'react';
import type { TextStyle } from 'react-native';
import {
EnrichedText,
type BlurEvent,
type EnrichedTextInstance,
type FocusEvent,
type OnLinkPressEvent,
type OnMentionPressEvent,
} from 'react-native-enriched-html';
import { WEB_DEFAULT_HTML_STYLE } from '../defaultHtmlStyle';
const LINK_REGEX =
/^(?:enriched:\/\/\S+|(?:https?:\/\/)?(?:www\.)?swmansion\.com(?:\/\S*)?)$/i;
const SANITIZATION_CONFIG = {
linkRegex: LINK_REGEX,
};
interface TextRendererProps {
htmlValue: string;
}
export function TextRenderer({ htmlValue }: TextRendererProps) {
const ref = useRef<EnrichedTextInstance>(null);
const handleTextFocus = (e: FocusEvent) => {
console.log('[EnrichedText] onFocus', e.nativeEvent);
};
const handleTextBlur = (e: BlurEvent) => {
console.log('[EnrichedText] onBlur', e.nativeEvent);
};
const handleLinkPress = (e: OnLinkPressEvent) => {
console.log('[EnrichedText] link press event', e);
};
const handleMentionPress = (e: OnMentionPressEvent) => {
console.log('[EnrichedText] mention press event', e);
};
return (
<div className="container enriched-text-container">
<h1 className="app-title">Enriched Text</h1>
<EnrichedText
ref={ref}
style={enrichedTextStyle}
htmlStyle={WEB_DEFAULT_HTML_STYLE}
onFocus={handleTextFocus}
onBlur={handleTextBlur}
onLinkPress={handleLinkPress}
onMentionPress={handleMentionPress}
sanitizationConfig={SANITIZATION_CONFIG}
>
{htmlValue}
</EnrichedText>
<div className="btn-row" data-testid="editor-actions-row">
<button
className="btn"
data-testid="focus-button"
onClick={() => ref.current?.focus()}
>
Focus
</button>
<button
className="btn"
data-testid="blur-button"
onClick={() => ref.current?.blur()}
>
Blur
</button>
</div>
</div>
);
}
const enrichedTextStyle: TextStyle = {
backgroundColor: 'gainsboro',
width: '100%',
marginVertical: 12,
paddingVertical: 12,
paddingHorizontal: 14,
borderRadius: 8,
fontSize: 18,
};