Skip to content

Commit 7d74f67

Browse files
committed
update formatting
1 parent 0cd39a4 commit 7d74f67

File tree

2 files changed

+70
-70
lines changed

2 files changed

+70
-70
lines changed

chartlets.js/CHANGES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Version 0.1.4 (in development)
22

3-
* Add `multiple` property for `Select` component to enable the
4-
of multiple elements.
3+
* Add `multiple` property for `Select` component to enable the selection
4+
of multiple elements. The `default` mode is supported at the moment.
55

66
## Version 0.1.3 (from 2025/01/28)
77

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

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,86 +8,86 @@ 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 = false,
35-
onChange,
25+
type,
26+
id,
27+
name,
28+
value,
29+
options,
30+
disabled,
31+
style,
32+
tooltip,
33+
label,
34+
multiple = false,
35+
onChange,
3636
}: SelectProps) {
37-
const handleChange = (event: SelectChangeEvent<unknown>) => {
38-
if (id) {
39-
let newValue: string | number | (string | number)[] = multiple
40-
? (event.target.value as (string | number)[])
41-
: (event.target.value as string | number);
37+
const handleChange = (event: SelectChangeEvent<unknown>) => {
38+
if (id) {
39+
let newValue: string | number | (string | number)[] = multiple
40+
? (event.target.value as (string | number)[])
41+
: (event.target.value as string | number);
4242

43-
if (!multiple && typeof value === "number") {
44-
newValue = Number.parseInt(newValue as string);
45-
}
43+
if (!multiple && typeof value === "number") {
44+
newValue = Number.parseInt(newValue as string);
45+
}
4646

47-
onChange({
48-
componentType: type,
49-
id: id,
50-
property: "value",
51-
value: newValue,
52-
});
53-
}
54-
};
55-
return (
56-
<Tooltip title={tooltip}>
57-
<MuiFormControl variant="filled" size="small" style={style}>
58-
{label && <MuiInputLabel id={`${id}-label`}>{label}</MuiInputLabel>}
59-
<MuiSelect
60-
labelId={`${id}-label`}
61-
id={id}
62-
name={name}
63-
value={value}
64-
disabled={disabled}
65-
multiple={multiple}
66-
onChange={handleChange}>
67-
{Array.isArray(options) &&
68-
options
69-
.map(normalizeSelectOption)
70-
.map(([optionValue, optionLabel], index) => (
71-
<MuiMenuItem key={index} value={optionValue}>
72-
{optionLabel}
73-
</MuiMenuItem>
74-
))}
75-
</MuiSelect>
76-
</MuiFormControl>
77-
</Tooltip>
78-
);
47+
onChange({
48+
componentType: type,
49+
id: id,
50+
property: "value",
51+
value: newValue,
52+
});
53+
}
54+
};
55+
return (
56+
<Tooltip title={tooltip}>
57+
<MuiFormControl variant="filled" size="small" style={style}>
58+
{label && <MuiInputLabel id={`${id}-label`}>{label}</MuiInputLabel>}
59+
<MuiSelect
60+
labelId={`${id}-label`}
61+
id={id}
62+
name={name}
63+
value={value}
64+
disabled={disabled}
65+
multiple={multiple}
66+
onChange={handleChange}>
67+
{Array.isArray(options) &&
68+
options
69+
.map(normalizeSelectOption)
70+
.map(([optionValue, optionLabel], index) => (
71+
<MuiMenuItem key={index} value={optionValue}>
72+
{optionLabel}
73+
</MuiMenuItem>
74+
))}
75+
</MuiSelect>
76+
</MuiFormControl>
77+
</Tooltip>
78+
);
7979
}
8080

8181
function normalizeSelectOption(
82-
option: SelectOption
82+
option: SelectOption
8383
): [string | number, string] {
84-
if (isString(option)) {
85-
return [option, option];
86-
} else if (typeof option === "number") {
87-
return [option, option.toString()];
88-
} else if (Array.isArray(option)) {
89-
return option;
90-
} else {
91-
return [option.value, option.label || `${option.value}`];
92-
}
84+
if (isString(option)) {
85+
return [option, option];
86+
} else if (typeof option === "number") {
87+
return [option, option.toString()];
88+
} else if (Array.isArray(option)) {
89+
return option;
90+
} else {
91+
return [option.value, option.label || `${option.value}`];
92+
}
9393
}

0 commit comments

Comments
 (0)