Skip to content

Commit c618a64

Browse files
committed
Added component IconButton and enhanced other components' attributes.
1 parent c747ee3 commit c618a64

File tree

13 files changed

+152
-12
lines changed

13 files changed

+152
-12
lines changed

chartlets.js/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version 0.0.27 (from 2024/11/25)
2+
3+
* Added component `IconButton` and enhanced other components' attributes.
4+
15
## Version 0.0.26 (from 2024/11/23)
26

37
* Channels such as `Input`, `State`, `Output` no longer have a `link` property.

chartlets.js/package-lock.json

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

chartlets.js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chartlets",
3-
"version": "0.0.26",
3+
"version": "0.0.27",
44
"description": "An experimental library for integrating interactive charts into existing JavaScript applications.",
55
"type": "module",
66
"files": [
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import MuiBox from "@mui/material/Box";
22

3+
import type { ElementType } from "react";
34
import type { ComponentState } from "@/lib/types/state/component";
4-
import { Children } from "../component/Children";
55
import type { ComponentProps } from "@/lib/component/Component";
6+
import { Children } from "@/lib/component/Children";
67

7-
interface BoxState extends ComponentState {}
8+
interface BoxState extends ComponentState {
9+
component?: ElementType<Element>;
10+
}
811

912
interface BoxProps extends ComponentProps, BoxState {}
1013

11-
export function Box({ id, style, children, onChange }: BoxProps) {
14+
export function Box({
15+
id,
16+
style,
17+
color,
18+
component,
19+
children: nodes,
20+
onChange,
21+
}: BoxProps) {
1222
return (
13-
<MuiBox id={id} style={style}>
14-
<Children nodes={children} onChange={onChange} />
23+
<MuiBox id={id} style={style} color={color} component={component || "div"}>
24+
<Children nodes={nodes} onChange={onChange} />
1525
</MuiBox>
1626
);
1727
}

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import { type MouseEvent } from "react";
22
import MuiButton from "@mui/material/Button";
3+
import MuiIcon from "@mui/material/Icon";
34

45
import { type ComponentState } from "@/lib/types/state/component";
56
import type { ComponentProps } from "@/lib/component/Component";
67

78
interface ButtonState extends ComponentState {
89
text?: string;
10+
startIcon?: string;
11+
endIcon?: string;
12+
variant?: "contained" | "outlined" | "text";
13+
color?:
14+
| "inherit"
15+
| "primary"
16+
| "secondary"
17+
| "success"
18+
| "error"
19+
| "info"
20+
| "warning";
921
}
1022

1123
interface ButtonProps extends ComponentProps, ButtonState {}
@@ -15,8 +27,12 @@ export function Button({
1527
id,
1628
name,
1729
style,
18-
text,
30+
variant,
31+
color,
1932
disabled,
33+
text,
34+
startIcon,
35+
endIcon,
2036
onChange,
2137
}: ButtonProps) {
2238
const handleClick = (_event: MouseEvent<HTMLButtonElement>) => {
@@ -34,7 +50,11 @@ export function Button({
3450
id={id}
3551
name={name}
3652
style={style}
53+
variant={variant}
54+
color={color}
3755
disabled={disabled}
56+
startIcon={startIcon && <MuiIcon>{startIcon}</MuiIcon>}
57+
endIcon={endIcon && <MuiIcon>{endIcon}</MuiIcon>}
3858
onClick={handleClick}
3959
>
4060
{text}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { type MouseEvent } from "react";
2+
import MuiIconButton from "@mui/material/IconButton";
3+
import MuiIcon from "@mui/material/Icon";
4+
5+
import { type ComponentState } from "@/lib/types/state/component";
6+
import type { ComponentProps } from "@/lib/component/Component";
7+
8+
interface IconButtonState extends ComponentState {
9+
icon?: string;
10+
color?:
11+
| "inherit"
12+
| "primary"
13+
| "secondary"
14+
| "success"
15+
| "error"
16+
| "info"
17+
| "warning";
18+
size?: "small" | "medium" | "large";
19+
}
20+
21+
interface IconButtonProps extends ComponentProps, IconButtonState {}
22+
23+
export function IconButton({
24+
type,
25+
id,
26+
name,
27+
style,
28+
color,
29+
icon,
30+
size,
31+
disabled,
32+
onChange,
33+
}: IconButtonProps) {
34+
const handleClick = (_event: MouseEvent<HTMLButtonElement>) => {
35+
if (id) {
36+
onChange({
37+
componentType: type,
38+
id: id,
39+
property: "clicked",
40+
value: true,
41+
});
42+
}
43+
};
44+
return (
45+
<MuiIconButton
46+
id={id}
47+
name={name}
48+
style={style}
49+
color={color}
50+
size={size}
51+
disabled={disabled}
52+
onClick={handleClick}
53+
>
54+
<MuiIcon>{icon}</MuiIcon>
55+
</MuiIconButton>
56+
);
57+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import MuiTypography from "@mui/material/Typography";
22
import { type TypographyVariant } from "@mui/material";
33

4-
import { Children } from "@/lib/component/Children";
54
import type { ComponentState } from "@/lib/types/state/component";
65
import type { ComponentProps } from "@/lib/component/Component";
6+
import { Children } from "@/lib/component/Children";
77

88
interface TypographyState extends ComponentState {
99
align?: "right" | "left" | "center" | "inherit" | "justify";

chartlets.js/src/lib/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ export {
3535
export { type HostStore } from "@/lib/types/state/options";
3636

3737
/////////////////////////////////////////////////////////////////////
38-
// Register standard Chartlets components
38+
// Register standard Chartlets components that can be rendered
39+
// by the Chartlets `Component` component.
40+
// Plugins may register their own components.
3941

4042
import { registry } from "@/lib/component/Registry";
4143

4244
import { Box } from "@/lib/components/Box";
4345
import { Button } from "@/lib/components/Button";
4446
import { Checkbox } from "@/lib/components/Checkbox";
4547
import { CircularProgress } from "@/lib/components/CircularProgress";
48+
import { IconButton } from "@/lib/components/IconButton";
4649
import { Plot } from "@/lib/components/Plot";
4750
import { Select } from "@/lib/components/Select";
4851
import { Typography } from "@/lib/components/Typography";
@@ -51,6 +54,7 @@ registry.register("Box", Box);
5154
registry.register("Button", Button);
5255
registry.register("Checkbox", Checkbox);
5356
registry.register("CircularProgress", CircularProgress);
57+
registry.register("IconButton", IconButton);
5458
registry.register("Plot", Plot);
5559
registry.register("Select", Select);
5660
registry.register("Typography", Typography);

chartlets.js/src/lib/types/state/component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface ComponentState {
2929
style?: CSSProperties;
3030
disabled?: boolean;
3131
label?: string;
32+
color?: string;
3233
}
3334

3435
export interface ContainerState extends ComponentState {

chartlets.py/CHANGES.md

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

3+
* Added component `IconButton` and enhanced other components' attributes.
4+
35
* Channels such as `Input`, `State`, `Output` no longer have a `link` property.
46
Instead, we use a special `id` format, namely `"@app"` and `@container`
57
to address states other than components.

0 commit comments

Comments
 (0)