Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions web/src/components/svg-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ const svgModules = import.meta.glob('@/assets/svg/**/*.svg', {
query: '?url',
});

const routeList: { name: string; value: string }[] = Object.entries(
svgModules,
).map(([path, module]) => {
const name = path.replace(/^.*\/assets\/svg\//, '').replace(/\.[^/.]+$/, '');
// @ts-ignore
return { name, value: module.default || module };
});
const svgMap: Record<string, string> = Object.entries(svgModules).reduce(
(acc, [path, module]) => {
const name = path
.replace(/^.*\/assets\/svg\//, '')
.replace(/\.[^/.]+$/, '');
// @ts-ignore
acc[name] = module.default || module;
return acc;
},
{} as Record<string, string>,
);

interface IProps extends IconComponentProps {
name: string;
Expand All @@ -46,12 +50,12 @@ interface IProps extends IconComponentProps {

const SvgIcon = memo(
({ name, width, height, imgClass, ...restProps }: IProps) => {
const ListItem = routeList.find((item) => item.name === name);
const value = svgMap[name];
return (
<Icon
component={() => (
<img
src={ListItem?.value}
src={value}
alt=""
width={width}
height={height}
Expand Down