Skip to content

Commit fc343b0

Browse files
committed
add demo panel E
1 parent f8c9f6e commit fc343b0

File tree

5 files changed

+170
-82
lines changed

5 files changed

+170
-82
lines changed

chartlets.js/package-lock.json

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

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from "react";
21
import MuiFormControl from "@mui/material/FormControl";
32
import MuiInputLabel from "@mui/material/InputLabel";
43
import MuiMenuItem from "@mui/material/MenuItem";
@@ -32,17 +31,19 @@ export function Select({
3231
style,
3332
tooltip,
3433
label,
35-
multiple,
34+
multiple = false,
3635
onChange,
3736
}: SelectProps) {
38-
const [personName, setPersonName] = React.useState<string[]>([]);
39-
40-
const handleChange = (event: SelectChangeEvent) => {
37+
const handleChange = (event: SelectChangeEvent<unknown>) => {
4138
if (id) {
42-
let newValue: string | number = event.target.value;
43-
if (typeof value == "number") {
44-
newValue = Number.parseInt(newValue);
39+
let newValue: string | number | (string | number)[] = multiple
40+
? (event.target.value as (string | number)[])
41+
: (event.target.value as string | number);
42+
43+
if (!multiple && typeof value === "number") {
44+
newValue = Number.parseInt(newValue as string);
4545
}
46+
4647
onChange({
4748
componentType: type,
4849
id: id,
@@ -59,16 +60,18 @@ export function Select({
5960
labelId={`${id}-label`}
6061
id={id}
6162
name={name}
62-
value={`${value}`}
63+
value={value}
6364
disabled={disabled}
6465
multiple={multiple}
6566
onChange={handleChange}>
6667
{Array.isArray(options) &&
67-
options.map(normalizeSelectOption).map(([value, text], index) => (
68-
<MuiMenuItem key={index} value={value}>
69-
{text}
70-
</MuiMenuItem>
71-
))}
68+
options
69+
.map(normalizeSelectOption)
70+
.map(([optionValue, optionLabel], index) => (
71+
<MuiMenuItem key={index} value={optionValue}>
72+
{optionLabel}
73+
</MuiMenuItem>
74+
))}
7275
</MuiSelect>
7376
</MuiFormControl>
7477
</Tooltip>

chartlets.py/demo/my_extension/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
from .my_panel_2 import panel as my_panel_2
44
from .my_panel_3 import panel as my_panel_3
55
from .my_panel_4 import panel as my_panel_4
6+
from .my_panel_5 import panel as my_panel_5
67

78
ext = Extension(__name__)
89
ext.add(my_panel_1)
910
ext.add(my_panel_2)
1011
ext.add(my_panel_3)
1112
ext.add(my_panel_4)
13+
ext.add(my_panel_5)

chartlets.py/demo/my_extension/my_panel_2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ def render_panel(
2424
)
2525
select = Select(
2626
id="selected_variable_name",
27-
value=[var_name],
27+
value=var_name,
2828
label="Variable",
2929
options=[(v, v) for v in variable_names],
3030
style={"flexGrow": 0, "minWidth": 120},
31-
multiple=True,
3231
tooltip="Select the variable of the test dataset to be used",
3332
)
3433
control_group = Box(

0 commit comments

Comments
 (0)