Skip to content

Commit 865a69c

Browse files
committed
new Divider component
1 parent 2dd8f1a commit 865a69c

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, it, expect } from "vitest";
2+
import { render, screen } from "@testing-library/react";
3+
import type { ComponentChangeHandler } from "@/types/state/event";
4+
import { Divider } from "./Divider";
5+
6+
describe("Divider", () => {
7+
it("should render the Box component", () => {
8+
const onChange: ComponentChangeHandler = () => {};
9+
render(
10+
<Divider
11+
id="dv"
12+
type={"Divider"}
13+
flexItem
14+
children={["Section 1"]}
15+
onChange={onChange}
16+
/>,
17+
);
18+
// to inspect rendered component, do:
19+
// expect(document.querySelector("#bx")).toEqual({});
20+
expect(screen.getByText("Section 1")).not.toBeUndefined();
21+
});
22+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { ElementType } from "react";
2+
import MuiDivider from "@mui/material/Divider";
3+
4+
import type { ComponentState, ComponentProps } from "@/index";
5+
import { Children } from "@/index";
6+
7+
interface DividerState extends ComponentState {
8+
orientation?: "horizontal" | "vertical";
9+
variant?: "fullWidth" | "inset" | "middle";
10+
flexItem?: boolean;
11+
textAlign?: "left" | "center" | "right";
12+
component?: ElementType<Element>;
13+
}
14+
15+
interface DividerProps extends ComponentProps, DividerState {}
16+
17+
export const Divider = ({
18+
id,
19+
style,
20+
orientation,
21+
variant,
22+
flexItem,
23+
textAlign,
24+
children: nodes,
25+
onChange,
26+
}: DividerProps) => {
27+
return (
28+
<MuiDivider
29+
id={id}
30+
style={style}
31+
orientation={orientation}
32+
variant={variant}
33+
flexItem={flexItem}
34+
textAlign={textAlign}
35+
>
36+
<Children nodes={nodes} onChange={onChange} />
37+
</MuiDivider>
38+
);
39+
};

chartlets.js/packages/lib/src/plugins/mui/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Box } from "./Box";
33
import { Button } from "./Button";
44
import { Checkbox } from "./Checkbox";
55
import { CircularProgress } from "./CircularProgress";
6+
import { Divider } from "./Divider";
67
import { IconButton } from "./IconButton";
78
import { RadioGroup } from "./RadioGroup";
89
import { Select } from "./Select";
@@ -18,6 +19,7 @@ export default function mui(): Plugin {
1819
["Button", Button],
1920
["Checkbox", Checkbox],
2021
["CircularProgress", CircularProgress],
22+
["Divider", Divider],
2123
["IconButton", IconButton],
2224
["RadioGroup", RadioGroup],
2325
["Select", Select],

chartlets.py/chartlets/components/divider.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ class Divider(Container):
99
unobtrusive line for grouping elements to reinforce visual hierarchy.
1010
"""
1111

12-
label: str | None = None
13-
"""The text label."""
14-
1512
orientation: str | None = None
1613
"""The orientation. Can be `horizontal` (default) or `vertical`."""
1714

chartlets.py/demo/my_extension/my_panel_3.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def render_panel(
4242
id="info_text", children=update_info_text(ctx, dataset_id, opaque, color)
4343
)
4444

45+
divider = Divider(style={"paddingTop": "10px", "paddingBottom": "10px"})
46+
4547
return Box(
4648
style={
4749
"display": "flex",
@@ -50,7 +52,7 @@ def render_panel(
5052
"height": "100%",
5153
"gap": "6px",
5254
},
53-
children=[opaque_checkbox, color_select, Divider(), info_text],
55+
children=[opaque_checkbox, color_select, divider, info_text],
5456
)
5557

5658

0 commit comments

Comments
 (0)