Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins): icons enhanced feature can be used for layout menu #12515

Merged
merged 6 commits into from
Jul 12, 2024
14 changes: 12 additions & 2 deletions packages/plugins/src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,19 @@ export default { ${icons.join(', ')} };
`,
});

// 是否启用了 icons 功能
const isIconsFeatureEnable = !!api.config.icons;
fz6m marked this conversation as resolved.
Show resolved Hide resolved
// runtime.tsx
api.writeTmpFile({
path: 'runtime.tsx',
content: `
import React from 'react';
import icons from './icons';
import { Icon, getIconComponent } from '@umijs/max';
${
isIconsFeatureEnable
? `import { Icon, getIconComponent } from '@umijs/max';`
: ''
}

function formatIcon(name: string) {
return name
Expand All @@ -443,10 +449,14 @@ export function patchRoutes({ routes }) {
Object.keys(routes).forEach(key => {
const { icon } = routes[key];
if (icon && typeof icon === 'string') {
const Component = getIconComponent(icon)
${
isIconsFeatureEnable
? `const Component = getIconComponent(icon)
if (Component) {
routes[key].icon = <Icon icon={icon} width={14} height={14} />;
fz6m marked this conversation as resolved.
Show resolved Hide resolved
return;
}`
: ''
}

const upperIcon = formatIcon(icon);
Expand Down