Skip to content

Commit 6c437d8

Browse files
authored
Replacing HTML components with MUI components (#3)
* Update UI to use MUI components * Update based on Reviewers comments
1 parent 18e6594 commit 6c437d8

File tree

8 files changed

+793
-49
lines changed

8 files changed

+793
-49
lines changed

dashi/package-lock.json

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

dashi/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"preview": "vite preview"
1313
},
1414
"dependencies": {
15+
"@emotion/react": "^11.13.3",
16+
"@emotion/styled": "^11.13.0",
17+
"@mui/material": "^6.1.1",
1518
"immer": "^10.1.1",
1619
"plotly.js": "^2.35.2",
1720
"react": "^18.3.1",

dashi/src/app/Panel.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { CSSProperties, ReactElement } from "react";
1+
import {CSSProperties, ReactElement} from "react";
22

33
import { Contribution } from "../model/contribution";
44
import { PropertyChangeHandler } from "../model/component";
55
import DashiComponent from "../components/DashiComponent";
66
import { ContributionState } from "../store/appStore";
7+
import {CircularProgress} from "@mui/material";
78

89
const panelContainerStyle: CSSProperties = {
910
display: "flex",
@@ -40,7 +41,7 @@ function Panel({ panelModel, panelState, onPropertyChange }: PanelProps) {
4041
</span>
4142
);
4243
} else if (componentModelResult.status === "pending") {
43-
panelElement = <span>Loading {panelModel.name}...</span>;
44+
panelElement = <span><CircularProgress size={30} color="secondary" /> Loading {panelModel.name}...</span>;
4445
}
4546
return <div style={panelContainerStyle}>{panelElement}</div>;
4647
}

dashi/src/app/PanelsControl.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import useAppStore, { ContribPoint } from "../store/appStore";
22
import { hidePanel } from "../actions/hidePanel";
33
import { showPanel } from "../actions/showPanel";
4+
import {Checkbox} from "@mui/material";
45

56
const contribPoint: ContribPoint = "panels";
67

@@ -27,10 +28,10 @@ function PanelsControl() {
2728
const id = `panels.${panelIndex}`;
2829
return (
2930
<div key={id}>
30-
<input
31+
<Checkbox
32+
color="secondary"
3133
id={id}
32-
type="checkbox"
33-
checked={panelState.visible}
34+
checked={panelState.visible || false}
3435
value={panelIndex}
3536
onChange={(e) => {
3637
if (e.currentTarget.checked) {

dashi/src/components/DashiBox.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { BoxModel, PropertyChangeHandler } from "../model/component";
22
import DashiChildren from "./DashiChildren";
3+
import {Box} from "@mui/material";
34

45
export interface DashiBoxProps extends Omit<BoxModel, "type"> {
56
onPropertyChange: PropertyChangeHandler;
67
}
78

89
function DashiBox({ id, style, components, onPropertyChange }: DashiBoxProps) {
910
return (
10-
<div id={id} style={style}>
11+
<Box id={id} style={style}>
1112
<DashiChildren
1213
components={components}
1314
onPropertyChange={onPropertyChange}
1415
/>
15-
</div>
16+
</Box>
1617
);
1718
}
1819

dashi/src/components/DashiButton.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MouseEvent } from "react";
22
import { ButtonModel, PropertyChangeHandler } from "../model/component";
3+
import Button from '@mui/material/Button';
34

45
export interface DashiButtonProps extends Omit<ButtonModel, "type"> {
56
onPropertyChange: PropertyChangeHandler;
@@ -27,7 +28,7 @@ function DashiButton({
2728
}
2829
};
2930
return (
30-
<button
31+
<Button
3132
id={id}
3233
name={name}
3334
value={value}
@@ -36,7 +37,7 @@ function DashiButton({
3637
onClick={handleClick}
3738
>
3839
{text}
39-
</button>
40+
</Button>
4041
);
4142
}
4243

dashi/src/components/DashiDropdown.tsx

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import "react";
22
import { DropdownModel, PropertyChangeHandler } from "../model/component";
3-
import { ChangeEvent } from "react";
3+
import React from "react";
4+
import {
5+
// Box,
6+
FormControl,
7+
InputLabel,
8+
MenuItem,
9+
Select,
10+
SelectChangeEvent,
11+
} from "@mui/material";
412

513
export interface DashiDropdownProps extends Omit<DropdownModel, "type"> {
614
onPropertyChange: PropertyChangeHandler;
@@ -10,19 +18,23 @@ function DashiDropdown({
1018
id,
1119
name,
1220
value,
13-
style,
1421
options,
1522
disabled,
23+
style,
24+
label,
1625
onPropertyChange,
1726
}: DashiDropdownProps) {
18-
const handleChange = (event: ChangeEvent<HTMLSelectElement>) => {
27+
const [dropdownValue, setDropdownValue] = React.useState(value);
28+
const handleChange = (event: SelectChangeEvent) => {
1929
if (!id) {
2030
return;
2131
}
22-
let newValue: string | number = event.currentTarget.value;
23-
if (typeof value === "number") {
32+
let newValue: string | number = event.target.value;
33+
if (typeof value == "number") {
2434
newValue = Number.parseInt(newValue);
2535
}
36+
37+
setDropdownValue(newValue);
2638
return onPropertyChange({
2739
componentType: "Dropdown",
2840
componentId: id,
@@ -31,20 +43,24 @@ function DashiDropdown({
3143
});
3244
};
3345
return (
34-
<select
35-
id={id}
36-
name={name}
37-
value={value}
38-
style={style}
39-
disabled={disabled}
40-
onChange={handleChange}
41-
>
42-
{options.map(([text, value], index) => (
43-
<option key={index} value={value}>
44-
{text}
45-
</option>
46-
))}
47-
</select>
46+
<FormControl>
47+
{label && <InputLabel>{label}</InputLabel>}
48+
<Select
49+
id={id}
50+
name={name}
51+
style={style}
52+
value={`${dropdownValue}`}
53+
disabled={disabled}
54+
onChange={handleChange}
55+
variant={"filled"}
56+
>
57+
{options.map(([text, value], index) => (
58+
<MenuItem key={index} value={value}>
59+
{text}
60+
</MenuItem>
61+
))}
62+
</Select>
63+
</FormControl>
4864
);
4965
}
5066

dashi/src/model/component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Component, CSSProperties } from "react";
1+
import { CSSProperties } from "react";
22
import { Config, Layout, PlotData } from "plotly.js";
33

44
export type ComponentType = "Button" | "Dropdown" | "Plot" | "Box";
55

66
export interface ComponentModel {
77
type: ComponentType;
8+
label?: string;
89
// common HTML attributes
910
id?: string;
1011
name?: string;

0 commit comments

Comments
 (0)