index.js 1014 Bytes
Newer Older
jiang's avatar
jiang committed
1
import 'rc-drawer-menu/assets/index.css';
2
import React from 'react';
jiang's avatar
jiang committed
3 4
import DrawerMenu from 'rc-drawer-menu';
import SiderMenu from './SiderMenu';
偏右's avatar
偏右 committed
5

jim's avatar
jim committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**
 * Recursively flatten the data
 * [{path:string},{path:string}] => {path,path2}
 * @param  menus
 */
const getFlatMenuKeys = menuData => {
  let keys = [];
  menuData.forEach(item => {
    if (item.children) {
      keys = keys.concat(getFlatMenuKeys(item.children));
    }
    keys.push(item.path);
  });
  return keys;
};

jim's avatar
jim committed
22
export default props =>
jim's avatar
jim committed
23
  props.isMobile || props.fixSiderbar ? (
24 25 26 27 28
    <DrawerMenu
      parent={null}
      level={null}
      iconChild={null}
      open={!props.collapsed}
jim's avatar
jim committed
29 30 31
      onMaskClick={() => {
        props.onCollapse(true);
      }}
32 33
      width="256px"
    >
jim's avatar
jim committed
34 35 36 37 38
      <SiderMenu
        {...props}
        flatMenuKeys={getFlatMenuKeys(props.menuData)}
        collapsed={props.isMobile ? false : props.collapsed}
      />
39
    </DrawerMenu>
jim's avatar
jim committed
40
  ) : (
jim's avatar
jim committed
41
    <SiderMenu {...props} flatMenuKeys={getFlatMenuKeys(props.menuData)} />
jim's avatar
jim committed
42
  );