Skip to content

Commit

Permalink
fix(ui): timeline - content - separate base styles from horizontal/ve…
Browse files Browse the repository at this point in the history
…rtical (#1430)

* fix(ui): timeline
- separate `TimelineContent` base styles from horizontal/vertical styles

* add changeset
  • Loading branch information
SutuSebastian authored Jun 20, 2024
1 parent b963b2c commit 83a055a
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-camels-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"flowbite-react": patch
---

fix(ui): timeline - content - separate `TimelineContent` base styles from horizontal/vertical styles
81 changes: 81 additions & 0 deletions packages/ui/src/components/Timeline/Timeline.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { render, screen } from "@testing-library/react";
import type { FC } from "react";
import { describe, expect, it } from "vitest";
import { Flowbite, type CustomFlowbiteTheme } from "../Flowbite";
import type { TimelineProps } from "./Timeline";
import { Timeline } from "./Timeline";

Expand All @@ -19,6 +20,26 @@ describe("Components / Timeline", () => {
expect(timelinePoint()).toBeInTheDocument();
expect(timelinePoint().childNodes[0]).toContainHTML("svg");
});

it("should use `horizontal` classes of content if provided", () => {
render(
<Flowbite theme={{ theme }}>
<TestTimelineNoIcon horizontal={true} />
</Flowbite>,
);

expect(timelineContent()).toHaveClass(horizontalContentClass);
});

it("should not use `vertical` classes of content if provided", () => {
render(
<Flowbite theme={{ theme }}>
<TestTimelineNoIcon horizontal={true} />
</Flowbite>,
);

expect(timelineContent()).not.toHaveClass(verticalContentClass);
});
});
describe("Rendering vertical mode", () => {
it("should have margin-top when do not icon", () => {
Expand All @@ -34,6 +55,47 @@ describe("Components / Timeline", () => {
expect(timelinePoint()).toBeInTheDocument();
expect(timelinePoint().childNodes[0]).toContainHTML("svg");
});

it("should use `vertical` classes of content if provided", () => {
render(
<Flowbite theme={{ theme }}>
<TestTimelineNoIcon />
</Flowbite>,
);

expect(timelineContent()).toHaveClass(verticalContentClass);
});

it("should not use `horizontal` classes of content if provided", () => {
render(
<Flowbite theme={{ theme }}>
<TestTimelineNoIcon />
</Flowbite>,
);

expect(timelineContent()).not.toHaveClass(horizontalContentClass);
});
});
describe("Theme", () => {
it("should use `base` classes of content in horizontal mode", () => {
render(
<Flowbite theme={{ theme }}>
<TestTimelineNoIcon horizontal={true} />
</Flowbite>,
);

expect(timelineContent()).toHaveClass(baseContentClass);
});

it("should use `base` classes of content in vertical mode", () => {
render(
<Flowbite theme={{ theme }}>
<TestTimelineNoIcon />
</Flowbite>,
);

expect(timelineContent()).toHaveClass(baseContentClass);
});
});
});

Expand Down Expand Up @@ -92,3 +154,22 @@ const IconSVG = () => (
);

const timelinePoint = () => screen.getByTestId("timeline-point");
const timelineContent = () => screen.getByTestId("timeline-content");

const baseContentClass = "dummy-base-content";
const verticalContentClass = "dummy-vertical-content";
const horizontalContentClass = "dummy-horizontal-content";

const theme: CustomFlowbiteTheme = {
timeline: {
item: {
content: {
root: {
base: baseContentClass,
vertical: verticalContentClass,
horizontal: horizontalContentClass,
},
},
},
},
};
8 changes: 7 additions & 1 deletion packages/ui/src/components/Timeline/TimelineContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import type { FlowbiteTimelineTitleTheme } from "./TimelineTitle";
export interface FlowbiteTimelineContentTheme {
root: {
base: string;
horizontal: string;
vertical: string;
};
time: FlowbiteTimelineTitleTheme;
title: FlowbiteTimelineTimeTheme;
Expand All @@ -37,7 +39,11 @@ export const TimelineContent: FC<TimelineContentProps> = ({

return (
<TimelineContentContext.Provider value={{ theme }}>
<div data-testid="timeline-content" className={twMerge(horizontal && theme.root.base, className)} {...props}>
<div
data-testid="timeline-content"
className={twMerge(theme.root.base, horizontal ? theme.root.horizontal : theme.root.vertical, className)}
{...props}
>
{children}
</div>
</TimelineContentContext.Provider>
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/Timeline/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export const timelineTheme: FlowbiteTimelineTheme = createTheme({
},
content: {
root: {
base: "mt-3 sm:pr-8",
base: "",
horizontal: "mt-3 sm:pr-8",
vertical: "",
},
body: {
base: "mb-4 text-base font-normal text-gray-500 dark:text-gray-400",
Expand Down

0 comments on commit 83a055a

Please sign in to comment.