Skip to content

Commit c360b5b

Browse files
authored
Fix MaterialUIComponent (#566)
* Fix MaterialUIComponent * Apply suggestion from @philippjfr * Apply suggestion from @philippjfr * Update docs
1 parent 0ed59ce commit c360b5b

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

doc/how_to/custom.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class RainbowButton(MaterialUIComponent):
4949
interval = param.Integer(default=200, doc="""
5050
Time in ms between color changes.""")
5151

52-
_esm_base = "RainbowButton.jsx"
52+
_esm = "RainbowButton.jsx"
5353
_importmap = {
5454
"imports": {
5555
"confetti": "https://esm.sh/canvas-confetti@1.6.0"

src/panel_material_ui/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def _exports__(cls):
325325
"react-is": ["*react_is"],
326326
"react-dom": ["*react_dom"],
327327
"react/jsx-runtime": [("jsx", "jsxs", "Fragment")],
328-
"./utils": [("install_theme_hooks",)],
328+
"./utils": [("apply_global_css","install_theme_hooks",)],
329329
"@mui/material/styles": ["*material_styles"],
330330
"@mui/material": ["*material_ui"],
331331
})
@@ -634,7 +634,7 @@ def _get_properties(self, doc: Document | None) -> dict[str, Any]:
634634

635635
@classmethod
636636
def _render_esm_base(cls):
637-
esm = cls._esm_base
637+
esm = cls._esm_base or cls._esm
638638
if not esm.endswith(('.js', '.jsx', '.ts', '.tsx')):
639639
esm_base = esm
640640
else:
@@ -646,7 +646,8 @@ def _render_esm_base(cls):
646646
esm_base, component_name = transform.apply(cls, esm_base, component_name)
647647
esm_base += f'\nexport default {{ render: {component_name} }}'
648648
esm_base = esm_base.replace(
649-
'import {install_theme_hooks} from "./utils"', 'import pnmui from "panel-material-ui"; const install_theme_hooks = pnmui.install_theme_hooks'
649+
'import {apply_global_css, install_theme_hooks} from "./utils"',
650+
'import pnmui from "panel-material-ui"; const install_theme_hooks = pnmui.install_theme_hooks; const apply_global_css = pnmui.apply_global_css;'
650651
).replace(
651652
'import * as React from "react"', ''
652653
)

tests/test_base.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from panel_material_ui.base import MaterialUIComponent
2+
3+
4+
class _TestComponentESMBase(MaterialUIComponent):
5+
_esm_base = (
6+
"export function render() { return null }"
7+
)
8+
9+
10+
11+
class _TestComponentESM(MaterialUIComponent):
12+
_esm = (
13+
"export function render() { return null }"
14+
)
15+
16+
17+
def test_render_esm_base_patches_utils_import():
18+
esm_base = _TestComponentESM._render_esm_base()
19+
assert (
20+
"const install_theme_hooks = pnmui.install_theme_hooks; "
21+
"const apply_global_css = pnmui.apply_global_css;"
22+
) in esm_base
23+
24+
25+
def test_render_esm_patches_utils_import():
26+
esm_base = _TestComponentESMBase._render_esm_base()
27+
assert (
28+
"const install_theme_hooks = pnmui.install_theme_hooks; "
29+
"const apply_global_css = pnmui.apply_global_css;"
30+
) in esm_base

0 commit comments

Comments
 (0)