Skip to content

Commit

Permalink
feat(layout): add menuTextRender props
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Sep 5, 2024
1 parent 9151e33 commit 1d65e22
Show file tree
Hide file tree
Showing 2 changed files with 247 additions and 275 deletions.
19 changes: 17 additions & 2 deletions packages/layout/src/components/SiderMenu/BaseMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ export type BaseMenuProps = {
) => React.ReactNode
>;

/**
* 修改 name,如果想做个简单的国际化,可以使用这个方法
*/
menuTextRender: WithFalse<
(
item: MenuDataItem,
defaultText: React.ReactNode,
menuProps: BaseMenuProps,
) => React.ReactNode
>;

/**
* @name 处理 menuData 的方法,与 menuDataRender 不同,postMenuData处理完成后会直接渲染,不再进行国际化和拼接处理
*
Expand Down Expand Up @@ -339,13 +350,17 @@ class MenuUtil {
getIntlName = (item: MenuDataItem) => {
const { name, locale } = item;
const { menu, formatMessage } = this.props;
let finalName = name;
if (locale && menu?.locale !== false) {
return formatMessage?.({
finalName = formatMessage?.({
id: locale,
defaultMessage: name,
});
}
return name;
if (this.props.menuTextRender) {
return this.props.menuTextRender(item, finalName, this.props);
}
return finalName;
};

/**
Expand Down
Loading

0 comments on commit 1d65e22

Please sign in to comment.