-
Notifications
You must be signed in to change notification settings - Fork 990
/
Copy pathmenu-grid-list.component.tsx
62 lines (55 loc) · 1.47 KB
/
menu-grid-list.component.tsx
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
import React from 'react';
import { Dimensions, ListRenderItemInfo, StyleSheet } from 'react-native';
import { Card, List, ListElement, ListItemElement, ListProps, Text } from '@ui-kitten/components';
import { MenuItem } from '../model/menu-item.model';
export interface MenuGridListProps extends Omit<ListProps, 'renderItem'> {
data: MenuItem[];
onItemPress: (index: number) => void;
}
export const MenuGridList = (props: MenuGridListProps): ListElement => {
const { contentContainerStyle, onItemPress, ...listProps } = props;
const renderItem = (info: ListRenderItemInfo<MenuItem>): ListItemElement => (
<Card
style={styles.item}
onPress={() => props.onItemPress(info.index)}>
<>
{info.item.icon({ width: 64, height: 64, alignSelf: 'center' })}
<Text
style={styles.itemTitle}
category='s2'>
{info.item.title}
</Text>
</>
</Card>
);
return (
<List
{...listProps}
contentContainerStyle={[styles.container, contentContainerStyle]}
numColumns={2}
renderItem={renderItem}
/>
);
};
const styles = StyleSheet.create({
container: {
padding: 8,
},
item: {
flex: 1,
justifyContent: 'center',
aspectRatio: 1.0,
margin: 8,
maxWidth: Dimensions.get('window').width / 2 - 24,
},
itemImage: {
alignSelf: 'center',
width: 64,
height: 64,
},
itemTitle: {
alignSelf: 'center',
marginTop: 8,
textAlign: 'center',
},
});