Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chartlets.js/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
- `LinearProgress`
- `Switch`

* Supporting `tooltip` property for interactive MUI components.

## Version 0.0.29 (from 2024/11/26)

* Resolved warnings that appeared when using Vega charts.
Expand Down
29 changes: 16 additions & 13 deletions chartlets.js/packages/lib/src/plugins/mui/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MuiButton from "@mui/material/Button";
import MuiIcon from "@mui/material/Icon";

import type { ComponentState, ComponentProps } from "@/index";
import { Tooltip } from "./Tooltip";

interface ButtonState extends ComponentState {
text?: string;
Expand Down Expand Up @@ -45,18 +46,20 @@ export function Button({
}
};
return (
<MuiButton
id={id}
name={name}
style={style}
variant={variant}
color={color}
disabled={disabled}
startIcon={startIcon && <MuiIcon>{startIcon}</MuiIcon>}
endIcon={endIcon && <MuiIcon>{endIcon}</MuiIcon>}
onClick={handleClick}
>
{text}
</MuiButton>
<Tooltip>
<MuiButton
id={id}
name={name}
style={style}
variant={variant}
color={color}
disabled={disabled}
startIcon={startIcon && <MuiIcon>{startIcon}</MuiIcon>}
endIcon={endIcon && <MuiIcon>{endIcon}</MuiIcon>}
onClick={handleClick}
>
{text}
</MuiButton>
</Tooltip>
);
}
32 changes: 18 additions & 14 deletions chartlets.js/packages/lib/src/plugins/mui/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import MuiFormControl from "@mui/material/FormControl";
import MuiFormControlLabel from "@mui/material/FormControlLabel";

import type { ComponentState, ComponentProps } from "@/index";
import { Tooltip } from "@mui/material";

interface CheckboxState extends ComponentState {
label?: string;
Expand All @@ -19,6 +20,7 @@ export function Checkbox({
value,
disabled,
style,
tooltip,
label,
onChange,
}: CheckboxProps) {
Expand All @@ -33,19 +35,21 @@ export function Checkbox({
}
};
return (
<MuiFormControl variant="filled" size="small" style={style}>
<MuiFormControlLabel
label={label}
control={
<MuiCheckbox
id={id}
name={name}
checked={Boolean(value)}
disabled={disabled}
onChange={handleChange}
/>
}
/>
</MuiFormControl>
<Tooltip title={tooltip}>
<MuiFormControl variant="filled" size="small" style={style}>
<MuiFormControlLabel
label={label}
control={
<MuiCheckbox
id={id}
name={name}
checked={Boolean(value)}
disabled={disabled}
onChange={handleChange}
/>
}
/>
</MuiFormControl>
</Tooltip>
);
}
26 changes: 15 additions & 11 deletions chartlets.js/packages/lib/src/plugins/mui/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MuiIconButton from "@mui/material/IconButton";
import MuiIcon from "@mui/material/Icon";

import type { ComponentState, ComponentProps } from "@/index";
import { Tooltip } from "./Tooltip";

interface IconButtonState extends ComponentState {
icon?: string;
Expand All @@ -24,6 +25,7 @@ export function IconButton({
id,
name,
style,
tooltip,
color,
icon,
size,
Expand All @@ -41,16 +43,18 @@ export function IconButton({
}
};
return (
<MuiIconButton
id={id}
name={name}
style={style}
color={color}
size={size}
disabled={disabled}
onClick={handleClick}
>
<MuiIcon>{icon}</MuiIcon>
</MuiIconButton>
<Tooltip title={tooltip}>
<MuiIconButton
id={id}
name={name}
style={style}
color={color}
size={size}
disabled={disabled}
onClick={handleClick}
>
<MuiIcon>{icon}</MuiIcon>
</MuiIconButton>
</Tooltip>
);
}
40 changes: 22 additions & 18 deletions chartlets.js/packages/lib/src/plugins/mui/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import MuiSelect, { type SelectChangeEvent } from "@mui/material/Select";

import type { ComponentState, ComponentProps } from "@/index";
import { isString } from "@/utils/isString";
import { Tooltip } from "./Tooltip";

export type SelectOption =
| string
Expand All @@ -27,6 +28,7 @@ export function Select({
options,
disabled,
style,
tooltip,
label,
onChange,
}: SelectProps) {
Expand All @@ -45,24 +47,26 @@ export function Select({
}
};
return (
<MuiFormControl variant="filled" size="small" style={style}>
{label && <MuiInputLabel id={`${id}-label`}>{label}</MuiInputLabel>}
<MuiSelect
labelId={`${id}-label`}
id={id}
name={name}
value={`${value}`}
disabled={disabled}
onChange={handleChange}
>
{Array.isArray(options) &&
options.map(normalizeSelectOption).map(([value, text], index) => (
<MuiMenuItem key={index} value={value}>
{text}
</MuiMenuItem>
))}
</MuiSelect>
</MuiFormControl>
<Tooltip title={tooltip}>
<MuiFormControl variant="filled" size="small" style={style}>
{label && <MuiInputLabel id={`${id}-label`}>{label}</MuiInputLabel>}
<MuiSelect
labelId={`${id}-label`}
id={id}
name={name}
value={`${value}`}
disabled={disabled}
onChange={handleChange}
>
{Array.isArray(options) &&
options.map(normalizeSelectOption).map(([value, text], index) => (
<MuiMenuItem key={index} value={value}>
{text}
</MuiMenuItem>
))}
</MuiSelect>
</MuiFormControl>
</Tooltip>
);
}

Expand Down
16 changes: 16 additions & 0 deletions chartlets.js/packages/lib/src/plugins/mui/Tooltip.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import { Tooltip } from "./Tooltip";

describe("Tooltip", () => {
it("should render its child component", () => {
render(
<Tooltip title={"Does nothing :)"}>
<button>Click Me</button>
</Tooltip>,
);
// to inspect rendered component, do:
// expect(document.querySelector("#typo")).toEqual({});
expect(screen.getByText("Click Me")).not.toBeUndefined();
});
});
11 changes: 11 additions & 0 deletions chartlets.js/packages/lib/src/plugins/mui/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import MuiTooltip from "@mui/material/Tooltip";
import type { ReactElement } from "react";

interface TooltipProps {
title?: string;
children: ReactElement;
}

export function Tooltip({ title, children }: TooltipProps) {
return title ? <MuiTooltip title={title}>{children}</MuiTooltip> : children;
}
1 change: 1 addition & 0 deletions chartlets.js/packages/lib/src/types/state/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ComponentState {
disabled?: boolean;
label?: string;
color?: string;
tooltip?: string;
}

export interface ContainerState extends ComponentState {
Expand Down
2 changes: 2 additions & 0 deletions chartlets.py/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- using `schema` instead of `type` property for callback arguments
- using `return` object with `schema` property for callback return values

* Added `tooltip` property to interactive components.

* New components
- `Switch`

Expand Down
8 changes: 8 additions & 0 deletions chartlets.py/chartlets/components/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class Button(Component):
One "contained" | "outlined" | "text". Defaults to "text".
"""

tooltip: str | None = None
"""Tooltip title. Optional."""



@dataclass(frozen=True)
class IconButton(Component):
Expand All @@ -50,3 +54,7 @@ class IconButton(Component):
"""The button variant.
One "contained" | "outlined" | "text". Defaults to "text".
"""

tooltip: str | None = None
"""Tooltip title. Optional."""

4 changes: 4 additions & 0 deletions chartlets.py/chartlets/components/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ class Checkbox(Component):

label: str = ""
"""The checkbox label."""

tooltip: str | None = None
"""Tooltip title. Optional."""

4 changes: 4 additions & 0 deletions chartlets.py/chartlets/components/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ class Select(Component):
"""The options given as a list of number or text values or a list
of (value, label) pairs.
"""

tooltip: str | None = None
"""Tooltip title. Optional."""

1 change: 1 addition & 0 deletions chartlets.py/demo/my_extension/my_panel_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def render_panel(ctx: Context) -> Component:
label="Dataset",
options=[(i, f"DS #{i + 1}") for i in range(len(ctx.datasets))],
style={"flexGrow": 0, "minWidth": 120},
tooltip="Select the test dataset to be used"
)
control_group = Box(
style={
Expand Down
1 change: 1 addition & 0 deletions chartlets.py/demo/my_extension/my_panel_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def render_panel(
label="Variable",
options=[(v, v) for v in variable_names],
style={"flexGrow": 0, "minWidth": 120},
tooltip="Select the variable of the test dataset to be used"
)
control_group = Box(
style={
Expand Down
2 changes: 2 additions & 0 deletions chartlets.py/demo/my_extension/my_panel_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def render_panel(
id="opaque",
value=opaque,
label="Opaque",
tooltip="Select whether the color is opaque"
)

color_select = Select(
Expand All @@ -34,6 +35,7 @@ def render_panel(
label="Color",
options=COLORS,
style={"flexGrow": 0, "minWidth": 80},
tooltip="Select color"
)

info_text = Typography(
Expand Down
Loading