Skip to content

Commit 83a055a

Browse files
fix(ui): timeline - content - separate base styles from horizontal/vertical (#1430)
* fix(ui): timeline - separate `TimelineContent` base styles from horizontal/vertical styles * add changeset
1 parent b963b2c commit 83a055a

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

.changeset/quiet-camels-bake.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"flowbite-react": patch
3+
---
4+
5+
fix(ui): timeline - content - separate `TimelineContent` base styles from horizontal/vertical styles

packages/ui/src/components/Timeline/Timeline.spec.tsx

+81
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { render, screen } from "@testing-library/react";
22
import type { FC } from "react";
33
import { describe, expect, it } from "vitest";
4+
import { Flowbite, type CustomFlowbiteTheme } from "../Flowbite";
45
import type { TimelineProps } from "./Timeline";
56
import { Timeline } from "./Timeline";
67

@@ -19,6 +20,26 @@ describe("Components / Timeline", () => {
1920
expect(timelinePoint()).toBeInTheDocument();
2021
expect(timelinePoint().childNodes[0]).toContainHTML("svg");
2122
});
23+
24+
it("should use `horizontal` classes of content if provided", () => {
25+
render(
26+
<Flowbite theme={{ theme }}>
27+
<TestTimelineNoIcon horizontal={true} />
28+
</Flowbite>,
29+
);
30+
31+
expect(timelineContent()).toHaveClass(horizontalContentClass);
32+
});
33+
34+
it("should not use `vertical` classes of content if provided", () => {
35+
render(
36+
<Flowbite theme={{ theme }}>
37+
<TestTimelineNoIcon horizontal={true} />
38+
</Flowbite>,
39+
);
40+
41+
expect(timelineContent()).not.toHaveClass(verticalContentClass);
42+
});
2243
});
2344
describe("Rendering vertical mode", () => {
2445
it("should have margin-top when do not icon", () => {
@@ -34,6 +55,47 @@ describe("Components / Timeline", () => {
3455
expect(timelinePoint()).toBeInTheDocument();
3556
expect(timelinePoint().childNodes[0]).toContainHTML("svg");
3657
});
58+
59+
it("should use `vertical` classes of content if provided", () => {
60+
render(
61+
<Flowbite theme={{ theme }}>
62+
<TestTimelineNoIcon />
63+
</Flowbite>,
64+
);
65+
66+
expect(timelineContent()).toHaveClass(verticalContentClass);
67+
});
68+
69+
it("should not use `horizontal` classes of content if provided", () => {
70+
render(
71+
<Flowbite theme={{ theme }}>
72+
<TestTimelineNoIcon />
73+
</Flowbite>,
74+
);
75+
76+
expect(timelineContent()).not.toHaveClass(horizontalContentClass);
77+
});
78+
});
79+
describe("Theme", () => {
80+
it("should use `base` classes of content in horizontal mode", () => {
81+
render(
82+
<Flowbite theme={{ theme }}>
83+
<TestTimelineNoIcon horizontal={true} />
84+
</Flowbite>,
85+
);
86+
87+
expect(timelineContent()).toHaveClass(baseContentClass);
88+
});
89+
90+
it("should use `base` classes of content in vertical mode", () => {
91+
render(
92+
<Flowbite theme={{ theme }}>
93+
<TestTimelineNoIcon />
94+
</Flowbite>,
95+
);
96+
97+
expect(timelineContent()).toHaveClass(baseContentClass);
98+
});
3799
});
38100
});
39101

@@ -92,3 +154,22 @@ const IconSVG = () => (
92154
);
93155

94156
const timelinePoint = () => screen.getByTestId("timeline-point");
157+
const timelineContent = () => screen.getByTestId("timeline-content");
158+
159+
const baseContentClass = "dummy-base-content";
160+
const verticalContentClass = "dummy-vertical-content";
161+
const horizontalContentClass = "dummy-horizontal-content";
162+
163+
const theme: CustomFlowbiteTheme = {
164+
timeline: {
165+
item: {
166+
content: {
167+
root: {
168+
base: baseContentClass,
169+
vertical: verticalContentClass,
170+
horizontal: horizontalContentClass,
171+
},
172+
},
173+
},
174+
},
175+
};

packages/ui/src/components/Timeline/TimelineContent.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import type { FlowbiteTimelineTitleTheme } from "./TimelineTitle";
1414
export interface FlowbiteTimelineContentTheme {
1515
root: {
1616
base: string;
17+
horizontal: string;
18+
vertical: string;
1719
};
1820
time: FlowbiteTimelineTitleTheme;
1921
title: FlowbiteTimelineTimeTheme;
@@ -37,7 +39,11 @@ export const TimelineContent: FC<TimelineContentProps> = ({
3739

3840
return (
3941
<TimelineContentContext.Provider value={{ theme }}>
40-
<div data-testid="timeline-content" className={twMerge(horizontal && theme.root.base, className)} {...props}>
42+
<div
43+
data-testid="timeline-content"
44+
className={twMerge(theme.root.base, horizontal ? theme.root.horizontal : theme.root.vertical, className)}
45+
{...props}
46+
>
4147
{children}
4248
</div>
4349
</TimelineContentContext.Provider>

packages/ui/src/components/Timeline/theme.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export const timelineTheme: FlowbiteTimelineTheme = createTheme({
1515
},
1616
content: {
1717
root: {
18-
base: "mt-3 sm:pr-8",
18+
base: "",
19+
horizontal: "mt-3 sm:pr-8",
20+
vertical: "",
1921
},
2022
body: {
2123
base: "mb-4 text-base font-normal text-gray-500 dark:text-gray-400",

0 commit comments

Comments
 (0)