-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainMenuNavItem.js
48 lines (38 loc) · 1.07 KB
/
MainMenuNavItem.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
import React, { useState } from 'react';
import uuidv4 from 'uuid';
import './MainMenu.css';
const DEFAULT_CLASS_NAME = 'c-MainMenu_NavItem';
function NavItemText({ text }) {
return (
<span className="c-MainMenu_NavItemText">{text}</span>
);
}
function NavItemContext({ context }) {
return (
<span className="c-MainMenu_NavItemContext">{context}</span>
);
}
function MainMenuNavItem({ id, text, context, onClick, children }) {
const [isVisible, setIsVisible] = useState(false);
const kids = [<NavItemText text={ text } key={ uuidv4() } />];
const props = {
className: DEFAULT_CLASS_NAME,
id,
};
if (context) {
kids.push(<NavItemContext context={ context } key={ uuidv4() }/>);
}
if (children) {
kids.push(children);
}
if (onClick) {
Object.assign(props, {
onClick: (event) => {
onClick( event, { isVisible, setIsVisible });
},
className: isVisible ? `${DEFAULT_CLASS_NAME} is-Visible` : DEFAULT_CLASS_NAME,
});
}
return React.createElement('li', props, kids);
}
export default MainMenuNavItem;