You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
888 B
JavaScript
40 lines
888 B
JavaScript
'use strict';
|
|
|
|
const React = require("react");
|
|
|
|
const defaultStyle = require("./style.css");
|
|
const useTheme = require("../../util/themeable");
|
|
const ListItemContext = require("../../contexts/list-item");
|
|
|
|
// FIXME: Track full collapsing state throughout the tree
|
|
|
|
module.exports = function List({ children, onPick, onSelect }) {
|
|
let [ selectedItem, setSelectedItem ] = React.useState([]);
|
|
let { withTheme } = useTheme({ control: "list", defaultStyle });
|
|
|
|
let itemContext = {
|
|
path: [],
|
|
selectedPath: selectedItem,
|
|
onClick: function (path) {
|
|
if (onSelect != null) {
|
|
onSelect(path);
|
|
}
|
|
|
|
setSelectedItem(path);
|
|
},
|
|
onDoubleClick: function (path) {
|
|
if (onPick != null) {
|
|
onPick(path);
|
|
}
|
|
}
|
|
};
|
|
|
|
return (
|
|
<ListItemContext.Provider value={itemContext}>
|
|
<div className={withTheme("list")}>
|
|
{children}
|
|
</div>
|
|
</ListItemContext.Provider>
|
|
);
|
|
};
|