|
1
|
|
|
import * as mdc from 'material-components-web'; |
|
2
|
|
|
import React from 'react'; |
|
3
|
|
|
import ReactDOM from 'react-dom'; |
|
4
|
|
|
import Model, {IPages} from './SideMenu/Model'; |
|
5
|
|
|
|
|
6
|
|
|
export interface IAdapter { |
|
7
|
|
|
onClose(): void |
|
8
|
|
|
onMenu(name: string): void |
|
9
|
|
|
} |
|
10
|
|
|
|
|
11
|
|
|
export interface IProperties { |
|
12
|
|
|
model: Model, |
|
13
|
|
|
adapter: IAdapter |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
interface IState { |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
export default class SideMenu extends React.Component<IProperties, IState> { |
|
20
|
|
|
drawer: mdc.drawer.MDCDrawer | any | undefined; |
|
21
|
|
|
|
|
22
|
|
|
componentDidMount(): void { |
|
23
|
|
|
// @ts-ignore |
|
24
|
3 |
|
this.drawer = new mdc.drawer.MDCDrawer(ReactDOM.findDOMNode(this)); |
|
25
|
3 |
|
this.drawer.listen('MDCDrawer:closed', this.props.adapter.onClose); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
onMenuClick(event: React.MouseEvent<HTMLAnchorElement>, name: string) { |
|
29
|
1 |
|
event.stopPropagation(); |
|
30
|
1 |
|
event.preventDefault(); |
|
31
|
1 |
|
this.props.adapter.onMenu(name); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
render(): React.ReactElement { |
|
35
|
4 |
|
const model: Model = this.props.model; |
|
36
|
4 |
|
const adapter: IAdapter = this.props.adapter; |
|
37
|
4 |
|
this.drawer && (this.drawer.open = model.isOpen); |
|
38
|
|
|
|
|
39
|
4 |
|
const translation: IPages<string> | any = model.translation; |
|
40
|
4 |
|
const isActive: IPages<boolean> | any = model.isActive; |
|
41
|
4 |
|
const url: IPages<string> | any = model.url; |
|
42
|
|
|
|
|
43
|
4 |
|
const menuEntries: React.ReactElement[] = model.pageNames.map( |
|
44
|
|
|
(name: string): React.ReactElement => { |
|
45
|
8 |
|
return <a |
|
46
|
|
|
key={'menuEntry:' + name} |
|
47
|
|
|
className={'mdc-list-item' + (isActive[name] ? ' mdc-list-item--activated' : '')} |
|
48
|
|
|
href={url[name]} |
|
49
|
|
|
aria-selected={isActive[name] ? 'true' : 'false'} |
|
50
|
|
|
data-testid={name} |
|
51
|
|
|
|
|
52
|
1 |
|
onClick={(event: React.MouseEvent<HTMLAnchorElement>) => this.onMenuClick(event, name)} |
|
53
|
|
|
> |
|
54
|
|
|
<i className="material-icons mdc-list-item__graphic" aria-hidden="true">{name}</i> |
|
55
|
|
|
<span className="mdc-list-item__text">{translation[name]}</span> |
|
56
|
|
|
</a>; |
|
57
|
|
|
} |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
4 |
|
return <React.Fragment> |
|
61
|
|
|
<aside className="mdc-drawer mdc-drawer--modal mdc-top-app-bar--fixed-adjust"> |
|
62
|
|
|
<div className="mdc-drawer__content"> |
|
63
|
|
|
<nav className="mdc-list"> |
|
64
|
|
|
{menuEntries} |
|
65
|
|
|
</nav> |
|
66
|
|
|
</div> |
|
67
|
|
|
</aside> |
|
68
|
|
|
<div className="mdc-drawer-scrim" /> |
|
69
|
|
|
</React.Fragment>; |
|
70
|
|
|
} |
|
71
|
|
|
} |