zent
Version:
一套前端设计语言和基于React的实现
17 lines (13 loc) • 538 B
text/typescript
import { cloneElement, PureComponent } from 'react';
import { getKeyFromChildrenIndex } from './utils';
export default abstract class CommonMenu<T, S> extends PureComponent<T, S> {
abstract handleClick(e: React.MouseEvent, index: unknown): void;
renderCommonMenuItem(component, index, subPrefix, extraProps?: any) {
const newChildProps = {
specKey: getKeyFromChildrenIndex(component, index, subPrefix),
onClick: this.handleClick,
...extraProps,
};
return cloneElement(component, newChildProps);
}
}