Skip to content

Commit

Permalink
feat: addPanel add renderTitle for user custom (umijs#3646)
Browse files Browse the repository at this point in the history
  • Loading branch information
ycjcl868 authored and sorrycc committed Nov 18, 2019
1 parent 32d2e2c commit 1115aab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default (api: IUiApi) => {

api.addPanel({
title: 'org.umi.ui.blocks.content.title',
titleComponent: () => <TitleTab />,
headerTitle: <TitleTab />,
provider: ({ children, ...restProps }) => (
<Container.Provider initialState={{ api }} {...restProps}>
{children}
Expand Down
4 changes: 4 additions & 0 deletions packages/umi-types/ui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ declare namespace IUI {
icon: IconType | string;
actions?: IPanelAction;
beta?: boolean;
/** header title, default use `title` */
headerTitle?: ReactNode;
/** custom title Component */
renderTitle?: (title: string) => ReactNode;
}

interface IService {
Expand Down
10 changes: 7 additions & 3 deletions packages/umi-ui/client/src/layouts/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default withRouter(props => {
);

const MenuItem = ({ panel, ...restProps }) => {
const { renderTitle } = panel;
const renderIcon = () => {
const icon = typeof panel.icon === 'string' ? { type: panel.icon } : panel.icon;

Expand All @@ -145,6 +146,9 @@ export default withRouter(props => {
return <Icon {...icon} />;
};

const titleText = renderLocaleText(panel.title);
const titleNode = renderTitle ? renderTitle(titleText) : titleText;

return (
<Menu.Item
key={panel.path}
Expand All @@ -156,9 +160,9 @@ export default withRouter(props => {
<NavLink exact to={`${panel.path}${search}`}>
{renderIcon()}
{isMini ? (
<p className={styles.menuText}>{renderLocaleText(panel.title)}</p>
<p className={styles.menuText}>{titleNode}</p>
) : (
<span className={styles.menuItem}>{renderLocaleText(panel.title)}</span>
<span className={styles.menuItem}>{titleNode}</span>
)}
</NavLink>
</Menu.Item>
Expand Down Expand Up @@ -330,7 +334,7 @@ export default withRouter(props => {
<div key="header" className={styles.header}>
<h1>
{activePanel &&
(activePanel.titleComponent ? activePanel.titleComponent() : title)}
(activePanel.headerTitle ? activePanel.headerTitle : title)}
</h1>
{Array.isArray(actions) && actions.length > 0 && (
<Row type="flex" className={styles['header-actions']}>
Expand Down

0 comments on commit 1115aab

Please sign in to comment.