Skip to content

Commit 9328a52

Browse files
committed
set fontFamily for MuiIcons
1 parent 5b46611 commit 9328a52

File tree

10 files changed

+237
-197
lines changed

10 files changed

+237
-197
lines changed

chartlets.js/package-lock.json

Lines changed: 182 additions & 178 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chartlets.js/packages/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"dependencies": {
3131
"@emotion/react": "^11.13.3",
3232
"@emotion/styled": "^11.13.0",
33-
"@mui/icons-material": "^6.2.1",
3433
"@mui/material": "^6.2.1",
3534
"chartlets": "file:../lib",
3635
"react": "^18.3.1",
@@ -46,6 +45,7 @@
4645
"@eslint/compat": "^1.4.0",
4746
"@eslint/eslintrc": "^3.3.1",
4847
"@eslint/js": "^9.38.0",
48+
"@fontsource/material-icons": "^5.1.1",
4949
"@types/node": "^20.11.17",
5050
"@types/react": "^18.3.11",
5151
"@types/react-dom": "^18.3.1",

chartlets.js/packages/demo/src/main.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ReactDOM from "react-dom/client";
33

44
import App from "./App";
55

6+
import "@fontsource/material-icons";
67
import "./index.css";
78

89
ReactDOM.createRoot(document.getElementById("root")!).render(

chartlets.js/packages/lib/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"zustand": "^5.0"
6262
},
6363
"peerDependencies": {
64-
"@mui/icons-material": "^6.2.1",
6564
"@mui/material": "^6.2.1",
6665
"@mui/x-data-grid": ">=7",
6766
"react": "^18.3.1",

chartlets.js/packages/lib/src/plugins/mui/Button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export function Button({
5555
variant={variant}
5656
color={color}
5757
disabled={disabled}
58-
startIcon={startIcon && <Icon iconName={startIcon}></Icon>}
59-
endIcon={endIcon && <Icon iconName={endIcon}></Icon>}
58+
startIcon={startIcon && <Icon iconName={startIcon} />}
59+
endIcon={endIcon && <Icon iconName={endIcon} />}
6060
onClick={handleClick}
6161
>
6262
{text}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2019-2026 by Brockmann Consult Development team
3+
* Permissions are hereby granted under the terms of the MIT License:
4+
* https://opensource.org/licenses/MIT.
5+
*/
6+
7+
import { describe, it, expect } from "vitest";
8+
import { render, screen } from "@testing-library/react";
9+
import { Icon } from "./Icon";
10+
11+
describe("Icon", () => {
12+
it("should render nothing if iconName is not given", () => {
13+
const { container } = render(<Icon />);
14+
expect(container.firstChild).toBeNull();
15+
});
16+
17+
it("should render the iconName", () => {
18+
render(<Icon iconName="sunny" />);
19+
expect(screen.getByText("sunny")).not.toBeUndefined();
20+
});
21+
22+
it("should render a MUI Icon root element", () => {
23+
render(<Icon iconName="home" />);
24+
25+
const icon = screen.getByText("home");
26+
// MUI Icon renders as a <span> with MuiIcon-root class in default configuration
27+
expect(icon.tagName.toLowerCase()).toEqual("span");
28+
expect(icon.className).toContain("MuiIcon-root");
29+
});
30+
});
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import * as MuiIcons from "@mui/icons-material";
1+
/*
2+
* Copyright (c) 2019-2026 by Brockmann Consult Development team
3+
* Permissions are hereby granted under the terms of the MIT License:
4+
* https://opensource.org/licenses/MIT.
5+
*/
6+
7+
import MuiIcon from "@mui/material/Icon";
28

39
interface IconProps {
410
iconName?: string;
@@ -7,14 +13,15 @@ interface IconProps {
713
export const Icon = ({ iconName }: IconProps) => {
814
if (!iconName) return null;
915

10-
const IconComponent = (MuiIcons as Record<string, React.ElementType>)[
11-
iconName
12-
];
13-
14-
if (!IconComponent) {
15-
console.warn(`Icon "${iconName}" not found in @mui/icons-material`);
16-
return null;
17-
}
18-
19-
return <IconComponent />;
16+
return (
17+
<MuiIcon
18+
sx={{
19+
fontFamily: "Material Icons",
20+
textTransform: "none",
21+
lineHeight: 1,
22+
}}
23+
>
24+
{iconName}
25+
</MuiIcon>
26+
);
2027
};

chartlets.js/packages/lib/src/plugins/mui/IconButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function IconButton({
5353
disabled={disabled}
5454
onClick={handleClick}
5555
>
56-
<Icon iconName={icon}></Icon>
56+
<Icon iconName={icon} />
5757
</MuiIconButton>
5858
</Tooltip>
5959
);

chartlets.js/packages/lib/src/plugins/mui/Tabs.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ export function Tabs({
5656
key={index}
5757
label={tabState ? tabState.label : isString(tab) ? tab : ""}
5858
icon={
59-
tabState &&
60-
tabState.icon && <Icon iconName={tabState.icon}></Icon>
59+
tabState && tabState.icon && <Icon iconName={tabState.icon} />
6160
}
6261
disabled={disabled || (tabState && tabState.disabled)}
6362
/>

chartlets.py/demo/my_extension/my_panel_5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def render_panel(
1515
open_button = Button(
1616
id="open_button",
1717
text="Open Dialog",
18-
startIcon="ChatBubble",
18+
startIcon="chat_bubble",
1919
variant="outlined",
2020
color="warning",
2121
)

0 commit comments

Comments
 (0)