/*
 * Author: chenruilong
 * Create Time: 2022/01/18
 * Description:
 */
import React from 'react';
import { SubMenu, SubMenuProps } from 'rc-menu';

interface BrickSubMenuProps extends SubMenuProps {
  icon?: React.ReactElement;
}

const prefixCls = 'brick-menu';

export default (props: BrickSubMenuProps) => {
  const { icon, ...rest } = props;

  return (
    <SubMenu
      {...rest}
      title={
        <>
          {icon &&
            React.cloneElement(icon, {
              className: prefixCls + '-title-icon',
            })}
          <span className={prefixCls + '-title-content'}>{props.title}</span>
        </>
      }
    />
  );
};
