Skip to content

Commit 794871e

Browse files
authored
Merge pull request #138 from bcdev/clarasb-124-support_icons
Support Icons
2 parents ca7fcd5 + 47ca26d commit 794871e

12 files changed

Lines changed: 532 additions & 421 deletions

File tree

chartlets.js/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
- `vite: ^7.1.11`
77
- `vitest: ^3.2.4`
88

9+
* Added icon support for `Button`, `IconButton` and `Tabs` components.
10+
(#124).
11+
912
## Version 0.1.7 (from 2025/12/03)
1013

1114
* Updated dependencies

chartlets.js/package-lock.json

Lines changed: 446 additions & 405 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"dependencies": {
3131
"@emotion/react": "^11.13.3",
3232
"@emotion/styled": "^11.13.0",
33-
"@mui/material": "^6.1.5",
33+
"@mui/material": "^6.2.1",
3434
"chartlets": "file:../lib",
3535
"react": "^18.3.1",
3636
"react-dom": "^18.3.1",
@@ -45,6 +45,7 @@
4545
"@eslint/compat": "^1.4.0",
4646
"@eslint/eslintrc": "^3.3.1",
4747
"@eslint/js": "^9.38.0",
48+
"@fontsource/material-icons": "^5.1.1",
4849
"@types/node": "^20.11.17",
4950
"@types/react": "^18.3.11",
5051
"@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
@@ -9,6 +9,7 @@ import ReactDOM from "react-dom/client";
99

1010
import App from "./App";
1111

12+
import "@fontsource/material-icons";
1213
import "./index.css";
1314

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
import { type MouseEvent } from "react";
88
import MuiButton from "@mui/material/Button";
9-
import MuiIcon from "@mui/material/Icon";
109

1110
import type { ComponentProps, ComponentState } from "@/index";
1211
import { Tooltip } from "./Tooltip";
12+
import { Icon } from "./Icon";
1313

1414
interface ButtonState extends ComponentState {
1515
text?: string;
@@ -61,8 +61,8 @@ export function Button({
6161
variant={variant}
6262
color={color}
6363
disabled={disabled}
64-
startIcon={startIcon && <MuiIcon>{startIcon}</MuiIcon>}
65-
endIcon={endIcon && <MuiIcon>{endIcon}</MuiIcon>}
64+
startIcon={startIcon && <Icon iconName={startIcon} />}
65+
endIcon={endIcon && <Icon iconName={endIcon} />}
6666
onClick={handleClick}
6767
>
6868
{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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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";
8+
9+
interface IconProps {
10+
iconName?: string;
11+
}
12+
13+
export const Icon = ({ iconName }: IconProps) => {
14+
if (!iconName) return null;
15+
16+
return (
17+
<MuiIcon
18+
sx={{
19+
fontFamily: "Material Icons",
20+
textTransform: "none",
21+
lineHeight: 1,
22+
}}
23+
>
24+
{iconName}
25+
</MuiIcon>
26+
);
27+
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
import { type MouseEvent } from "react";
88
import MuiIconButton from "@mui/material/IconButton";
9-
import MuiIcon from "@mui/material/Icon";
109

1110
import type { ComponentState, ComponentProps } from "@/index";
11+
import { Icon } from "./Icon";
1212
import { Tooltip } from "./Tooltip";
1313

1414
interface IconButtonState extends ComponentState {
@@ -59,7 +59,7 @@ export function IconButton({
5959
disabled={disabled}
6060
onClick={handleClick}
6161
>
62-
<MuiIcon>{icon}</MuiIcon>
62+
<Icon iconName={icon} />
6363
</MuiIconButton>
6464
</Tooltip>
6565
);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66

77
import MuiBox from "@mui/material/Box";
8-
import MuiIcon from "@mui/material/Icon";
98
import MuiTabs from "@mui/material/Tabs";
109
import MuiTab from "@mui/material/Tab";
1110

1211
import type { ComponentProps, ComponentState } from "@/index";
1312
import type { SyntheticEvent } from "react";
1413
import { Box } from "@/plugins/mui/Box";
14+
import { Icon } from "./Icon";
1515
import { isString } from "@/utils/isString";
1616
import { isComponentState } from "@/types/state/component";
1717

@@ -62,8 +62,7 @@ export function Tabs({
6262
key={index}
6363
label={tabState ? tabState.label : isString(tab) ? tab : ""}
6464
icon={
65-
tabState &&
66-
tabState.icon && <MuiIcon>{tabState.icon}</MuiIcon>
65+
tabState && tabState.icon && <Icon iconName={tabState.icon} />
6766
}
6867
disabled={disabled || (tabState && tabState.disabled)}
6968
/>

chartlets.py/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Version 0.1.8 (in development)
22

3+
* Added `size` and removed `variant` property from `IconButton`
4+
component to align with component in chartlets.js. (#124)
5+
36
## Version 0.1.7 (from 2025/12/03)
47

58
* Updated dependencies

0 commit comments

Comments
 (0)