-
Notifications
You must be signed in to change notification settings - Fork 295
/
SidebarCategory.tsx
42 lines (38 loc) · 1.12 KB
/
SidebarCategory.tsx
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
// @flow
import React, { Component } from 'react';
import type { Node } from 'react';
import SVGInline from 'react-svg-inline';
import { observer } from 'mobx-react';
import classNames from 'classnames';
import { camelCase } from 'lodash';
import type { SidebarCategoryInfo } from '../../config/sidebarConfig';
import styles from './SidebarCategory.scss';
type Props = {
category: SidebarCategoryInfo,
isActive: boolean,
onClick: Function,
content?: Node,
};
@observer
export default class SidebarCategory extends Component<Props> {
render() {
const { category, isActive, onClick, content } = this.props;
const { name, icon, route } = category;
const className = camelCase(name);
const componentStyles = classNames(
styles.component,
className,
styles[className],
{
[styles.active]: isActive,
}
);
const iconClassName = classNames(styles.icon, styles[`${className}Icon`]);
return (
<button className={componentStyles} onClick={() => onClick(route)}>
<SVGInline svg={icon} className={iconClassName} />
{content}
</button>
);
}
}