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/timeline vertical #1224

Closed
wants to merge 2 commits into from
Closed
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
83 changes: 83 additions & 0 deletions src/components/Timeline/Timeline.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { FC } from 'react';
import { describe, expect, it } from 'vitest';
import type { TimelineProps } from './Timeline';
import { Timeline } from './Timeline';
import { Flowbite, type CustomFlowbiteTheme } from '../Flowbite';

describe.concurrent('Components / Timeline', () => {
describe('Rendering horizontal mode', () => {
Expand All @@ -26,7 +27,28 @@ describe.concurrent('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', () => {
render(<TestTimelineNoIcon horizontal={false} />);
Expand All @@ -41,6 +63,48 @@ describe.concurrent('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 @@ -100,3 +164,22 @@ const IconSVG = () => (

const timeline = () => screen.getByTestId('timeline-component');
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,
},
},
},
},
};
13 changes: 12 additions & 1 deletion 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;
vertical?: string;
horizontal?: string;
};
time: FlowbiteTimelineTitleTheme;
title: FlowbiteTimelineTimeTheme;
Expand All @@ -37,7 +39,16 @@ 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,
!horizontal && theme.root.vertical,
className,
)}
{...props}
>
{children}
</div>
</TimelineContentContext.Provider>
Expand Down
Loading