index.js 1.01 KB
Newer Older
jim's avatar
jim committed
1
import 'rc-drawer/assets/index.css';
2
import React from 'react';
jim's avatar
jim committed
3
import DrawerMenu from 'rc-drawer';
qixian.cs@outlook.com's avatar
qixian.cs@outlook.com committed
4
import SiderMenu from './SliderMenu';
偏右'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;
};

ZHAO Jinxiang's avatar
ZHAO Jinxiang committed
22
const SiderMenuWrapper = props =>
jim's avatar
jim committed
23
  props.isMobile ? (
24 25 26
    <DrawerMenu
      parent={null}
      level={null}
jim's avatar
jim committed
27
      handleChild={null}
28
      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
  );
ZHAO Jinxiang's avatar
ZHAO Jinxiang committed
43 44

export default SiderMenuWrapper;