-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMainPanel.js
More file actions
93 lines (84 loc) · 1.96 KB
/
MainPanel.js
File metadata and controls
93 lines (84 loc) · 1.96 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
import React from 'react';
import PropTypes from 'prop-types';
import kind from '@enact/core/kind';
import ri from '@enact/ui/resolution';
import {Panel, Header} from '@enact/moonstone/Panels';
import {VirtualGridList} from '@enact/moonstone/VirtualList';
import GridListImageItem from '@enact/moonstone/GridListImageItem';
const GridItem = kind({
name: 'GridItem',
propTypes: {
index: PropTypes.number,
items: PropTypes.array,
onSelect: PropTypes.func
},
handlers: {
onSelect: (ev, {index, onSelect}) => onSelect({index})
},
render: ({index, items, onSelect, ...rest}) => {
if (items && items[index]) {
return (
<GridListImageItem
{...rest}
caption={items[index].title}
source={items[index].image}
subCaption={items[index].subTitle}
onClick={onSelect}
/>
);
}
}
});
// eslint-disable-next-line enact/display-name, enact/prop-types
const renderItem = ({items, onChangePanel}) => ({index, ...rest}) => {
if (items && items[index]) {
return (
<GridItem
{...rest}
items={items}
index={index}
onSelect={onChangePanel}
/>
);
}
};
const MainPanel = kind({
name: 'MainPanel',
propTypes: {
/**
* A collection of all of the items to be rendered by this VirtualGridList
* @type {Array}
*/
items: PropTypes.array,
/**
* A function to run when the panel changes
* @type {Function}
*/
onChangePanel: PropTypes.func
},
computed: {
itemRenderer: renderItem
},
render: ({items, itemRenderer, ...rest}) => {
delete rest.onChangePanel;
return (
<Panel {...rest}>
<Header type="compact">
<title>Example Layouts</title>
<titleBelow>Choose a layout</titleBelow>
</Header>
<VirtualGridList
itemRenderer={itemRenderer}
dataSize={items.length}
focusableScrollbar
itemSize={{minWidth: ri.scale(300), minHeight: ri.scale(270)}}
spacing={ri.scale(18)}
style={{
height: '100%'
}}
/>
</Panel>
);
}
});
export default MainPanel;