Skip to content

Commit c1e5a86

Browse files
authored
fix: Text pass className & Tracker circular deps (#352)
1 parent 0040214 commit c1e5a86

File tree

5 files changed

+37
-51
lines changed

5 files changed

+37
-51
lines changed

src/components/text-elements/Text/Text.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ export interface TextProps extends React.HTMLAttributes<HTMLParagraphElement> {
1010
}
1111

1212
const Text = React.forwardRef<HTMLParagraphElement, TextProps>((props, ref) => {
13-
const { color = BaseColors.Gray, children } = props;
13+
const { color = BaseColors.Gray, className, children } = props;
1414
return (
1515
<p
1616
ref={ref}
1717
className={twMerge(
1818
getColorClassNames(color, colorPalette.text).textColor,
1919
fontSize.sm,
2020
fontWeight.sm,
21+
className,
2122
)}
2223
>
2324
{children}

src/components/vis-elements/Tracker/Tracker.tsx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
11
import React from "react";
22
import { twMerge } from "tailwind-merge";
33

4-
import { makeClassName, spacing } from "lib";
4+
import {
5+
colorPalette,
6+
makeClassName,
7+
spacing,
8+
borderRadius,
9+
getColorClassNames,
10+
mergeRefs,
11+
} from "lib";
512
import { Color } from "../../../lib/inputTypes";
6-
import TrackerBlock from "./TrackerBlock";
13+
import Tooltip, { useTooltip } from "components/util-elements/Tooltip/Tooltip";
714

815
export const makeTrackerClassName = makeClassName("Tracker");
916

1017
export interface TrackerBlockProps {
11-
key?: string;
18+
key?: string | number;
1219
color?: Color;
1320
tooltip?: string;
1421
}
1522

23+
const TrackerBlock = React.forwardRef<HTMLDivElement, TrackerBlockProps>((props, ref) => {
24+
const { color, tooltip, ...other } = props;
25+
26+
const { tooltipProps, getReferenceProps } = useTooltip();
27+
28+
return (
29+
<div
30+
ref={mergeRefs([ref, tooltipProps.refs.setReference])}
31+
className={twMerge(
32+
makeTrackerClassName("trackingBlock"),
33+
"w-full h-full",
34+
getColorClassNames(color ?? "gray", colorPalette.background).bgColor,
35+
borderRadius.md.all,
36+
)}
37+
{...other}
38+
{...getReferenceProps}
39+
>
40+
<Tooltip text={tooltip} {...tooltipProps} />
41+
</div>
42+
);
43+
});
44+
1645
export interface TrackerProps extends React.HTMLAttributes<HTMLDivElement> {
1746
data: TrackerBlockProps[];
1847
}
@@ -31,7 +60,7 @@ const Tracker = React.forwardRef<HTMLDivElement, TrackerProps>((props, ref) => {
3160
{...other}
3261
>
3362
{data.map((item, idx) => (
34-
<TrackerBlock key={item.key ?? idx} color={item.color ?? "gray"} tooltip={item.tooltip} />
63+
<TrackerBlock key={item.key ?? idx} color={item.color} tooltip={item.tooltip} />
3564
))}
3665
</div>
3766
);

src/components/vis-elements/Tracker/TrackerBlock.tsx

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/stories/chart-elements/LineChart.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const ResponsiveTemplate: ComponentStory<typeof LineChart> = (args) => (
2121
<LineChart {...args} />
2222
</Card>
2323
</div>
24-
<Title marginTop="mt-5">Desktop</Title>
24+
<Title className="mt-5">Desktop</Title>
2525
<Card>
2626
<LineChart {...args} />
2727
</Card>

src/tests/vis-elements/Tracker.test.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@ import React from "react";
22
import { render } from "@testing-library/react";
33

44
import Tracker from "components/vis-elements/Tracker/Tracker";
5-
import TrackerBlock from "components/vis-elements/Tracker/TrackerBlock";
65

76
describe("Tracker", () => {
87
test("renders the Tracker component with default props", () => {
9-
render(
10-
<Tracker>
11-
<TrackerBlock color="green" />
12-
<TrackerBlock color="green" />
13-
</Tracker>,
14-
);
8+
render(<Tracker data={[{ color: "green" }, { color: "green" }]} />);
159
});
1610
});

0 commit comments

Comments
 (0)