Skip to content

Commit

Permalink
feat(menu): expose menu custom configue;
Browse files Browse the repository at this point in the history
  • Loading branch information
yehuozhili committed Jun 19, 2020
1 parent eb17df8 commit 1b80507
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/Menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,28 @@ export interface MenuProps {
style?: CSSProperties;
/** 回调函数 */
onSelect?: SelectCallback;
/** 用户自己逻辑,可以拿到点击索引和修改激活索引的方法,用于制作二次点击取消等效果*/
customHandle?: (
index: string,
current: string | undefined,
setActive: React.Dispatch<React.SetStateAction<string | undefined>>
) => void;
}

export const Menu: FC<MenuProps> = (props) => {
const { className, mode, style, children, defaultIndex, onSelect } = props;
const { className, mode, customHandle, style, children, defaultIndex, onSelect } = props;
const [currentActive, setActive] = useState(defaultIndex);
const classes = classNames("bigbear-menu", className, {
"menu-vertical": mode === "vertical",
"menu-horizontal": mode === "horizontal"
});
const handleClick = (index: string) => {
setActive(index);
if (onSelect) onSelect(index);
if (customHandle) {
customHandle(index, currentActive, setActive);
} else {
setActive(index);
if (onSelect) onSelect(index);
}
};
const passedContext: IMenuContext = {
index: currentActive ? currentActive : "0",
Expand Down

0 comments on commit 1b80507

Please sign in to comment.