File tree Expand file tree Collapse file tree
chartlets.js/packages/lib/src/plugins/mui
chartlets.py/demo/my_extension Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { type MouseEvent } from "react" ;
22import MuiButton from "@mui/material/Button" ;
3- import MuiIcon from "@mui/material/Icon" ;
43
54import type { ComponentProps , ComponentState } from "@/index" ;
65import { Tooltip } from "./Tooltip" ;
6+ import { Icon } from "./Icon" ;
77
88interface ButtonState extends ComponentState {
99 text ?: string ;
@@ -55,8 +55,8 @@ export function Button({
5555 variant = { variant }
5656 color = { color }
5757 disabled = { disabled }
58- startIcon = { startIcon && < MuiIcon > { startIcon } </ MuiIcon > }
59- endIcon = { endIcon && < MuiIcon > { endIcon } </ MuiIcon > }
58+ startIcon = { startIcon && < Icon iconName = { startIcon } > </ Icon > }
59+ endIcon = { endIcon && < Icon iconName = { endIcon } > </ Icon > }
6060 onClick = { handleClick }
6161 >
6262 { text }
Original file line number Diff line number Diff line change 1+ import * as MuiIcons from "@mui/icons-material" ;
2+
3+ interface IconProps {
4+ iconName ?: string ;
5+ }
6+
7+ export const Icon = ( { iconName } : IconProps ) => {
8+ if ( ! iconName ) return null ;
9+
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 /> ;
20+ } ;
Original file line number Diff line number Diff line change 11import { type MouseEvent } from "react" ;
22import MuiIconButton from "@mui/material/IconButton" ;
3- import MuiIcon from "@mui/material/Icon" ;
43
54import type { ComponentState , ComponentProps } from "@/index" ;
5+ import { Icon } from "./Icon" ;
66import { Tooltip } from "./Tooltip" ;
77
88interface IconButtonState extends ComponentState {
@@ -53,7 +53,7 @@ export function IconButton({
5353 disabled = { disabled }
5454 onClick = { handleClick }
5555 >
56- < MuiIcon > { icon } </ MuiIcon >
56+ < Icon iconName = { icon } > </ Icon >
5757 </ MuiIconButton >
5858 </ Tooltip >
5959 ) ;
Original file line number Diff line number Diff line change 11import MuiBox from "@mui/material/Box" ;
2- import MuiIcon from "@mui/material/Icon" ;
32import MuiTabs from "@mui/material/Tabs" ;
43import MuiTab from "@mui/material/Tab" ;
54
65import type { ComponentProps , ComponentState } from "@/index" ;
76import type { SyntheticEvent } from "react" ;
87import { Box } from "@/plugins/mui/Box" ;
8+ import { Icon } from "./Icon" ;
99import { isString } from "@/utils/isString" ;
1010import { isComponentState } from "@/types/state/component" ;
1111
@@ -57,7 +57,7 @@ export function Tabs({
5757 label = { tabState ? tabState . label : isString ( tab ) ? tab : "" }
5858 icon = {
5959 tabState &&
60- tabState . icon && < MuiIcon > { tabState . icon } </ MuiIcon >
60+ tabState . icon && < Icon iconName = { tabState . icon } > </ Icon >
6161 }
6262 disabled = { disabled || ( tabState && tabState . disabled ) }
6363 />
Original file line number Diff line number Diff line change 1212def render_panel (
1313 ctx : Context ,
1414) -> Component :
15- open_button = Button (id = "open_button" , text = "Open Dialog" )
15+ open_button = Button (id = "open_button" , text = "Open Dialog" , startIcon = "ChatBubble" )
1616 okay_button = Button (id = "okay_button" , text = "Okay" )
1717 not_okay_button = Button (id = "not_okay_button" , text = "Not okay" )
1818 dialog = Dialog (
You can’t perform that action at this time.
0 commit comments