Skip to content

Commit 99825ef

Browse files
committed
Reorganising components; added CircularProgress
1 parent fe2985c commit 99825ef

File tree

13 files changed

+115
-72
lines changed

13 files changed

+115
-72
lines changed

chartlets.js/src/lib/actions/helpers/applyStateChangeRequests.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { describe, it, expect } from "vitest";
22

3+
import { type ComponentState } from "@/lib";
34
import { type ContribPoint } from "@/lib/types/model/extension";
45
import { type StateChangeRequest } from "@/lib/types/model/callback";
5-
import {
6-
type BoxState,
7-
type ComponentState,
8-
type PlotState,
9-
} from "@/lib/types/state/component";
6+
import { type BoxState } from "@/lib/components/Box";
7+
import { type PlotState } from "@/lib/components/Plot";
108
import { type ContributionState } from "@/lib/types/state/contribution";
119
import {
1210
applyComponentStateChange,

chartlets.js/src/lib/actions/helpers/getInputValues.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, it, expect } from "vitest";
22

3-
import type { ComponentState, PlotState } from "@/lib/types/state/component";
3+
import type { ComponentState } from "@/lib";
4+
import type { PlotState } from "@/lib/components/Plot";
45
import {
56
getInputValueFromComponent,
67
getInputValueFromState,

chartlets.js/src/lib/components/Box.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import MuiBox from "@mui/material/Box";
22

3-
import { type BoxState } from "@/lib/types/state/component";
3+
import { type ContainerState } from "@/lib/types/state/component";
44
import { type ComponentChangeHandler } from "@/lib/types/state/event";
55
import { ComponentChildren } from "./ComponentChildren";
66

7+
export interface BoxState extends ContainerState {
8+
type: "Box";
9+
}
10+
711
export interface BoxProps extends Omit<BoxState, "type"> {
812
onChange: ComponentChangeHandler;
913
}

chartlets.js/src/lib/components/Button.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { type MouseEvent } from "react";
22
import MuiButton from "@mui/material/Button";
33

4-
import { type ButtonState } from "@/lib/types/state/component";
4+
import { type ComponentState } from "@/lib/types/state/component";
55
import { type ComponentChangeHandler } from "@/lib/types/state/event";
66

7+
export interface ButtonState extends ComponentState {
8+
type: "Button";
9+
text: string;
10+
}
11+
712
export interface ButtonProps extends Omit<ButtonState, "type"> {
813
onChange: ComponentChangeHandler;
914
}

chartlets.js/src/lib/components/Checkbox.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import MuiCheckbox from "@mui/material/Checkbox";
33
import MuiFormControl from "@mui/material/FormControl";
44
import MuiFormControlLabel from "@mui/material/FormControlLabel";
55

6-
import { type CheckboxState } from "@/lib/types/state/component";
6+
import { type ComponentState } from "@/lib/types/state/component";
77
import { type ComponentChangeHandler } from "@/lib/types/state/event";
88

9+
export interface CheckboxState extends ComponentState {
10+
type: "Checkbox";
11+
label: string;
12+
value?: boolean;
13+
}
14+
915
export interface CheckboxProps extends Omit<CheckboxState, "type"> {
1016
onChange: ComponentChangeHandler;
1117
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import MuiCircularProgress from "@mui/material/CircularProgress";
2+
3+
import { type ComponentState } from "@/lib/types/state/component";
4+
5+
export interface CircularProgressState extends ComponentState {
6+
type: "CircularProgress";
7+
size?: number | string;
8+
value?: number;
9+
variant?: "determinate" | "indeterminate";
10+
}
11+
12+
export interface CircularProgressProps
13+
extends Omit<CircularProgressState, "type"> {}
14+
15+
export function CircularProgress({
16+
id,
17+
style,
18+
size,
19+
value,
20+
variant,
21+
}: CircularProgressProps) {
22+
return (
23+
<MuiCircularProgress
24+
id={id}
25+
style={style}
26+
size={size}
27+
value={value}
28+
variant={variant}
29+
/>
30+
);
31+
}

chartlets.js/src/lib/components/Component.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { Checkbox, type CheckboxProps } from "./Checkbox";
66
import { Select, type SelectProps } from "./Select";
77
import { Plot, type PlotProps } from "./Plot";
88
import { Typography, type TypographyProps } from "@/lib/components/Typography";
9+
import {
10+
CircularProgress,
11+
type CircularProgressProps,
12+
} from "./CircularProgress";
913

1014
export interface ComponentProps extends ComponentState {
1115
onChange: ComponentChangeHandler;
@@ -28,7 +32,11 @@ export function Component({ type, ...props }: ComponentProps) {
2832
return <Box {...(props as BoxProps)} />;
2933
} else if (type === "Checkbox") {
3034
return <Checkbox {...(props as CheckboxProps)} />;
35+
} else if (type === "CircularProgress") {
36+
return <CircularProgress {...(props as CircularProgressProps)} />;
3137
} else if (type === "Typography") {
3238
return <Typography {...(props as TypographyProps)} />;
39+
} else {
40+
console.error(`Cannot render unknown component type ${type}`);
3341
}
3442
}

chartlets.js/src/lib/components/Plot.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
import { VegaLite } from "react-vega";
1+
import { VegaLite, type VisualizationSpec } from "react-vega";
22

3-
import { type PlotState } from "@/lib/types/state/component";
3+
import { type ComponentState } from "@/lib/types/state/component";
44
import { type ComponentChangeHandler } from "@/lib/types/state/event";
55

6+
export interface PlotState extends ComponentState {
7+
type: "Plot";
8+
chart:
9+
| (VisualizationSpec & {
10+
datasets?: Record<string, unknown>; // Add the datasets property
11+
})
12+
| null;
13+
}
14+
615
export interface PlotProps extends Omit<PlotState, "type"> {
716
onChange: ComponentChangeHandler;
817
}

chartlets.js/src/lib/components/Select.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@ import MuiInputLabel from "@mui/material/InputLabel";
33
import MuiMenuItem from "@mui/material/MenuItem";
44
import MuiSelect, { type SelectChangeEvent } from "@mui/material/Select";
55

6-
import {
7-
type SelectOption,
8-
type SelectState,
9-
} from "@/lib/types/state/component";
6+
import { type ComponentState } from "@/lib/types/state/component";
107
import { type ComponentChangeHandler } from "@/lib/types/state/event";
118

9+
export type SelectOption =
10+
| string
11+
| number
12+
| [string, string]
13+
| [number, string]
14+
| { value: string | number; label?: string };
15+
16+
export interface SelectState extends ComponentState {
17+
type: "Select";
18+
options: SelectOption[];
19+
}
20+
1221
export interface SelectProps extends Omit<SelectState, "type"> {
1322
onChange: ComponentChangeHandler;
1423
}

chartlets.js/src/lib/components/Typography.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import MuiTypography from "@mui/material/Typography";
2+
import { type TypographyVariant } from "@mui/material";
23

3-
import type { TypographyState } from "@/lib/types/state/component";
44
import { ComponentChildren } from "@/lib/components/ComponentChildren";
5-
import type { ComponentChangeHandler } from "@/lib";
5+
import type { ComponentChangeHandler, ContainerState } from "@/lib";
6+
7+
export interface TypographyState extends ContainerState {
8+
type: "Typography";
9+
align?: "right" | "left" | "center" | "inherit" | "justify";
10+
gutterBottom?: boolean;
11+
noWrap?: boolean;
12+
variant?: TypographyVariant;
13+
}
614

715
export interface TypographyProps extends Omit<TypographyState, "type"> {
816
onChange: ComponentChangeHandler;
@@ -11,11 +19,22 @@ export interface TypographyProps extends Omit<TypographyState, "type"> {
1119
export function Typography({
1220
id,
1321
style,
22+
align,
23+
gutterBottom,
24+
noWrap,
25+
variant,
1426
children: components,
1527
onChange,
1628
}: TypographyProps) {
1729
return (
18-
<MuiTypography id={id} style={style}>
30+
<MuiTypography
31+
id={id}
32+
style={style}
33+
align={align}
34+
gutterBottom={gutterBottom}
35+
noWrap={noWrap}
36+
variant={variant}
37+
>
1938
<ComponentChildren components={components} onChange={onChange} />
2039
</MuiTypography>
2140
);

0 commit comments

Comments
 (0)