-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathTooltipExample.tsx
More file actions
253 lines (242 loc) · 7.31 KB
/
Copy pathTooltipExample.tsx
File metadata and controls
253 lines (242 loc) · 7.31 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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import * as React from 'react';
import { Platform, StyleSheet, View, Image } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import {
Appbar,
Avatar,
Banner,
Button,
Chip,
FAB,
IconButton,
List,
ToggleButton,
Tooltip,
Card,
} from 'react-native-paper';
import { isWeb } from '../../utils';
import ScreenWrapper from '../ScreenWrapper';
const MORE_ICON = Platform.OS === 'ios' ? 'dots-horizontal' : 'dots-vertical';
const DURATION_MEDIUM = 1500;
const DURATION_LONG = 3000;
const formOfTransport = [
{ title: 'Car - default delays' },
{ title: 'Airplane - default delays' },
{ title: 'Taxi - long enter delay', enterTouchDelay: DURATION_MEDIUM },
{ title: 'Train - long enter delay', enterTouchDelay: DURATION_MEDIUM },
{ title: 'Ferry - long leave delay', leaveTouchDelay: DURATION_MEDIUM },
{ title: 'Bus - long leave delay', leaveTouchDelay: DURATION_MEDIUM },
{
title: 'Walk - long both delays',
enterTouchDelay: DURATION_MEDIUM,
leaveTouchDelay: DURATION_LONG,
},
];
const TooltipExample = () => {
const navigation = useNavigation('TooltipExample');
const [textAlign, setTextAlign] = React.useState('bold');
React.useLayoutEffect(() => {
navigation.setOptions({
header: () => (
<Appbar.Header elevated>
<Tooltip title="Go back">
{(props) => (
<Appbar.BackAction
{...props}
onPress={() => navigation.goBack()}
/>
)}
</Tooltip>
<Appbar.Content title="Tooltips" />
<Tooltip title="Print ⌘ + P">
{(props) => (
<Appbar.Action {...props} icon="printer" onPress={() => {}} />
)}
</Tooltip>
<Tooltip title="Search">
{(props) => (
<Appbar.Action {...props} icon="magnify" onPress={() => {}} />
)}
</Tooltip>
<Tooltip title="More options">
{(props) => (
<Appbar.Action {...props} icon={MORE_ICON} onPress={() => {}} />
)}
</Tooltip>
</Appbar.Header>
),
});
});
return (
<>
<ScreenWrapper>
<Banner visible>
A tooltip is displayed upon
{!isWeb
? ' tapping and holding a screen element or component'
: ' hovering over a screen element or component'}
. Continuously display the tooltip as long as the user long-presses or
hovers over the element.
</Banner>
<List.Section title="Icon Buttons">
<View style={styles.iconButtonContainer}>
{formOfTransport.map((transport, index) => (
<Tooltip
key={index}
title={transport.title}
enterTouchDelay={transport.enterTouchDelay}
leaveTouchDelay={transport.leaveTouchDelay}
>
{(props) => (
<IconButton
{...props}
icon={transport.title.split(' ')[0].toLowerCase()}
size={24}
onPress={() => {}}
/>
)}
</Tooltip>
))}
</View>
</List.Section>
<List.Section title="Toggle Buttons">
<ToggleButton.Row
value={textAlign}
style={styles.toggleButtonRow}
onValueChange={setTextAlign}
>
<Tooltip title="Align left">
{(props) => (
<ToggleButton
{...props}
icon="format-align-left"
value="left"
/>
)}
</Tooltip>
<Tooltip title="Align center">
{(props) => (
<ToggleButton
{...props}
icon="format-align-center"
value="center"
/>
)}
</Tooltip>
<Tooltip title="Align right">
{(props) => (
<ToggleButton
{...props}
icon="format-align-right"
value="right"
disabled
/>
)}
</Tooltip>
</ToggleButton.Row>
</List.Section>
<List.Section title="Avatar">
<View style={styles.avatarContainer}>
<Tooltip title="Username">
{(props) => <Avatar.Text {...props} label="U" />}
</Tooltip>
</View>
</List.Section>
<List.Section title="Chip">
<View style={styles.chipContainer}>
<Tooltip title="Copied">
{(props) => (
<Chip
{...props}
mode="outlined"
avatar={
<Image
source={require('../../assets/images/avatar.png')}
accessibilityIgnoresInvertColors
/>
}
>
John Doe
</Chip>
)}
</Tooltip>
</View>
</List.Section>
<List.Section title="Card">
<Tooltip title="Cafeteria, 1st floor">
{(props) => (
<Card {...props} style={styles.cardContainer}>
<Card.Title
title="Lunch break"
subtitle="1:00-2:00 PM"
left={(leftProps) => (
<Avatar.Icon {...leftProps} icon="food-fork-drink" />
)}
/>
</Card>
)}
</Tooltip>
</List.Section>
<List.Section title="Rich tooltips">
<View style={styles.iconButtonContainer}>
<Tooltip.Rich
title="Add to library"
content="Save this item to read it later from any of your devices."
actions={({ dismiss }) => (
<>
<Button compact onPress={dismiss}>
Learn more
</Button>
<Button compact mode="contained" onPress={dismiss}>
Add
</Button>
</>
)}
>
{(props) => <IconButton {...props} icon="plus" size={24} />}
</Tooltip.Rich>
<Tooltip.Rich content="A rich tooltip with body text only — no title or actions.">
{(props) => (
<IconButton {...props} icon="information" size={24} />
)}
</Tooltip.Rich>
</View>
</List.Section>
</ScreenWrapper>
<View style={styles.fabContainer}>
<Tooltip title="Press Me">
{(props) => <FAB {...props} icon="plus" onPress={() => {}} />}
</Tooltip>
</View>
</>
);
};
TooltipExample.title = 'Tooltip';
export default TooltipExample;
const styles = StyleSheet.create({
avatarContainer: {
marginHorizontal: 16,
width: 64,
},
chipContainer: {
marginHorizontal: 16,
alignItems: 'center',
flexDirection: 'row',
},
fabContainer: {
margin: 16,
right: 0,
position: 'absolute',
bottom: 0,
},
cardContainer: {
margin: 16,
},
toggleButtonRow: {
paddingHorizontal: 16,
},
iconButtonContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
},
});