-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathAutoCompleteSuggestionHeader.tsx
More file actions
127 lines (111 loc) · 3.07 KB
/
AutoCompleteSuggestionHeader.tsx
File metadata and controls
127 lines (111 loc) · 3.07 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
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
import React, { useMemo } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { useTheme } from '../../contexts/themeContext/ThemeContext';
import { Smile } from '../../icons/Smile';
import { primitives } from '../../theme';
export type AutoCompleteSuggestionHeaderProps = {
queryText?: string;
triggerType?: string;
};
export const CommandsHeader: React.FC<AutoCompleteSuggestionHeaderProps> = () => {
const {
theme: {
semantics,
messageInput: {
suggestions: {
header: { container, title },
},
},
},
} = useTheme();
const styles = useStyles();
return (
<View style={[styles.container, container]}>
<Text
style={[styles.title, { color: semantics.textTertiary }, title]}
testID='commands-header-title'
>
{'Instant Commands'}
</Text>
</View>
);
};
export const EmojiHeader: React.FC<AutoCompleteSuggestionHeaderProps> = ({ queryText }) => {
const {
theme: {
messageInput: {
suggestions: {
header: { container, title },
},
},
semantics,
},
} = useTheme();
const styles = useStyles();
return (
<View style={[styles.container, container]}>
<Smile pathFill={semantics.accentPrimary} />
<Text style={[styles.title, title]} testID='emojis-header-title'>
{`Emoji matching "${queryText}"`}
</Text>
</View>
);
};
const UnMemoizedAutoCompleteSuggestionHeader = ({
queryText,
triggerType,
}: AutoCompleteSuggestionHeaderProps) => {
if (triggerType === 'command') {
return <CommandsHeader />;
} else if (triggerType === 'emoji') {
return <EmojiHeader queryText={queryText} />;
} else {
return null;
}
};
const areEqual = (
prevProps: AutoCompleteSuggestionHeaderProps,
nextProps: AutoCompleteSuggestionHeaderProps,
) => {
const { queryText: prevQueryText, triggerType: prevType } = prevProps;
const { queryText: nextQueryText, triggerType: nextType } = nextProps;
const typeEqual = prevType === nextType;
if (!typeEqual) {
return false;
}
const valueEqual = prevQueryText === nextQueryText;
if (!valueEqual) {
return false;
}
return true;
};
const MemoizedAutoCompleteSuggestionHeader = React.memo(
UnMemoizedAutoCompleteSuggestionHeader,
areEqual,
);
export const AutoCompleteSuggestionHeader = (props: AutoCompleteSuggestionHeaderProps) => (
<MemoizedAutoCompleteSuggestionHeader {...props} />
);
AutoCompleteSuggestionHeader.displayName =
'AutoCompleteSuggestionHeader{messageInput{suggestions{Header}}}';
const useStyles = () => {
const {
theme: { semantics },
} = useTheme();
return useMemo(() => {
return StyleSheet.create({
container: {
alignItems: 'center',
flexDirection: 'row',
padding: 8,
},
title: {
fontSize: primitives.typographyFontSizeSm,
lineHeight: primitives.typographyLineHeightNormal,
fontWeight: primitives.typographyFontWeightMedium,
paddingLeft: 8,
color: semantics.textSecondary,
},
});
}, [semantics]);
};