Skip to content

Commit e1677bf

Browse files
committed
update changes.md and formatting
1 parent 2ffa9be commit e1677bf

File tree

3 files changed

+73
-65
lines changed

3 files changed

+73
-65
lines changed

chartlets.js/CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Version 0.1.4 (in development)
2+
3+
* Add `multiple` property for `Select` component to enable the
4+
of multiple elements.
5+
16
## Version 0.1.0 (in development)
27

38
* Reorganised Chartlets project to better separate demo from library code.

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

Lines changed: 64 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,81 +8,80 @@ import { isString } from "@/utils/isString";
88
import { Tooltip } from "./Tooltip";
99

1010
export type SelectOption =
11-
| string
12-
| number
13-
| [string, string]
14-
| [number, string]
15-
| { value: string | number; label?: string };
11+
| string
12+
| number
13+
| [string, string]
14+
| [number, string]
15+
| { value: string | number; label?: string };
1616

1717
interface SelectState extends ComponentState {
18-
options?: SelectOption[];
19-
multiple?: boolean
18+
options?: SelectOption[];
19+
multiple?: boolean;
2020
}
2121

2222
interface SelectProps extends ComponentProps, SelectState {}
2323

2424
export function Select({
25-
type,
26-
id,
27-
name,
28-
value,
29-
options,
30-
disabled,
31-
style,
32-
tooltip,
33-
label,
34-
multiple,
35-
onChange,
25+
type,
26+
id,
27+
name,
28+
value,
29+
options,
30+
disabled,
31+
style,
32+
tooltip,
33+
label,
34+
multiple,
35+
onChange,
3636
}: SelectProps) {
37-
const handleChange = (event: SelectChangeEvent) => {
38-
if (id) {
39-
let newValue: string | number = event.target.value;
40-
if (typeof value == "number") {
41-
newValue = Number.parseInt(newValue);
42-
}
43-
onChange({
44-
componentType: type,
45-
id: id,
46-
property: "value",
47-
value: newValue,
48-
});
49-
}
50-
};
51-
return (
52-
<Tooltip title={tooltip}>
53-
<MuiFormControl variant="filled" size="small" style={style}>
54-
{label && <MuiInputLabel id={`${id}-label`}>{label}</MuiInputLabel>}
55-
<MuiSelect
56-
labelId={`${id}-label`}
57-
id={id}
58-
name={name}
59-
value={`${value}`}
60-
disabled={disabled}
61-
multiple={multiple}
62-
onChange={handleChange}
63-
>
64-
{Array.isArray(options) &&
65-
options.map(normalizeSelectOption).map(([value, text], index) => (
66-
<MuiMenuItem key={index} value={value}>
67-
{text}
68-
</MuiMenuItem>
69-
))}
70-
</MuiSelect>
71-
</MuiFormControl>
72-
</Tooltip>
73-
);
37+
const handleChange = (event: SelectChangeEvent) => {
38+
if (id) {
39+
let newValue: string | number = event.target.value;
40+
if (typeof value == "number") {
41+
newValue = Number.parseInt(newValue);
42+
}
43+
onChange({
44+
componentType: type,
45+
id: id,
46+
property: "value",
47+
value: newValue,
48+
});
49+
}
50+
};
51+
return (
52+
<Tooltip title={tooltip}>
53+
<MuiFormControl variant="filled" size="small" style={style}>
54+
{label && <MuiInputLabel id={`${id}-label`}>{label}</MuiInputLabel>}
55+
<MuiSelect
56+
labelId={`${id}-label`}
57+
id={id}
58+
name={name}
59+
value={`${value}`}
60+
disabled={disabled}
61+
multiple={multiple}
62+
onChange={handleChange}>
63+
{Array.isArray(options) &&
64+
options.map(normalizeSelectOption).map(([value, text], index) => (
65+
<MuiMenuItem key={index} value={value}>
66+
{text}
67+
</MuiMenuItem>
68+
))}
69+
</MuiSelect>
70+
</MuiFormControl>
71+
</Tooltip>
72+
);
7473
}
7574

7675
function normalizeSelectOption(
77-
option: SelectOption,
76+
option: SelectOption
7877
): [string | number, string] {
79-
if (isString(option)) {
80-
return [option, option];
81-
} else if (typeof option === "number") {
82-
return [option, option.toString()];
83-
} else if (Array.isArray(option)) {
84-
return option;
85-
} else {
86-
return [option.value, option.label || `${option.value}`];
87-
}
78+
if (isString(option)) {
79+
return [option, option];
80+
} else if (typeof option === "number") {
81+
return [option, option.toString()];
82+
} else if (Array.isArray(option)) {
83+
return option;
84+
} else {
85+
return [option.value, option.label || `${option.value}`];
86+
}
8887
}

chartlets.py/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
## Version 0.1.4 (in development)
12

3+
* Add `multiple` property for `Select` component to enable the
4+
of multiple elements.
5+
26
## Version 0.1.0 (from 2025/01/14)
37

48
* Reorganised Chartlets project to better separate demo from library code.

0 commit comments

Comments
 (0)