Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): timeline - content - separate base styles from horizontal/vertical #1430

Merged
merged 2 commits into from
Jun 20, 2024
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
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
Loading