index.js 1.02 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;
};

陈帅's avatar
陈帅 committed
22 23 24
const SiderMenuWrapper = props => {
  const { isMobile, menuData, collapsed } = props;
  return isMobile ? (
25
    <DrawerMenu
26
      getContainer={null}
27
      level={null}
jim's avatar
jim committed
28
      handleChild={null}
陈帅's avatar
陈帅 committed
29
      open={!collapsed}
jim's avatar
jim committed
30 31 32
      onMaskClick={() => {
        props.onCollapse(true);
      }}
33
    >
jim's avatar
jim committed
34 35
      <SiderMenu
        {...props}
陈帅's avatar
陈帅 committed
36 37
        flatMenuKeys={getFlatMenuKeys(menuData)}
        collapsed={isMobile ? false : collapsed}
jim's avatar
jim committed
38
      />
39
    </DrawerMenu>
jim's avatar
jim committed
40
  ) : (
陈帅's avatar
陈帅 committed
41
    <SiderMenu {...props} flatMenuKeys={getFlatMenuKeys(menuData)} />
jim's avatar
jim committed
42
  );
陈帅's avatar
陈帅 committed
43
};
ZHAO Jinxiang's avatar
ZHAO Jinxiang committed
44 45

export default SiderMenuWrapper;