This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
index.js
60 lines (55 loc) · 1.65 KB
/
index.js
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
import React from "react";
import { MenuBar, commandMenuEnhancer } from "teselagen-react-components";
import { compose } from "redux";
import { memoize } from "lodash";
import withEditorProps from "../withEditorProps";
import menuDef from "./defaultConfig";
import getCommands from "../commands";
import pureNoFunc from "../utils/pureNoFunc";
const ident = x => x;
class OveMenuBar extends React.Component {
constructor(props) {
super(props);
const commands = getCommands(this);
this.enhancers = [
commandMenuEnhancer(commands, {
useTicks: true,
omitIcons: true
})
];
this.counter = 0;
}
getFilteredMenu = memoize((menuFilter, menuDef) => {
this.counter++;
if (this.counter === 50)
console.warn(
`It's likely you're passing a new "menuFilter" function every time. This will cause unecessary re-renders. Try not to recreate a new function each time!`
);
return menuFilter(JSON.parse(JSON.stringify(menuDef)));
});
render() {
const { menuFilter = ident } = this.props;
// Clone original menu def to protect it from accidental mutation
return (
<div
className="veMenuBarContainer"
style={{ display: "flex" /* height: "100%" */ }}
>
<MenuBar
menu={this.getFilteredMenu(menuFilter, menuDef)}
enhancers={this.enhancers}
/>
{/* <div
className="menuBarDivider"
style={{
height: "87%",
width: 2,
margin: 2,
background: "lightgrey"
}}
/> */}
</div>
);
}
}
export default compose(withEditorProps)(pureNoFunc(OveMenuBar));