Skip to content

Feat/render timeline point inner content #1520

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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/lucky-ladybugs-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"flowbite-react": patch
---

Allow `Timeline.Point` to render components as inner content.
6 changes: 6 additions & 0 deletions apps/web/content/docs/components/timeline.mdx
Original file line number Diff line number Diff line change
@@ -31,6 +31,12 @@ Use the `horizontal` prop to show the timeline component and the child component

<Example name="timeline.horizontal" />

## Render props

Use the `render` prop to render an Avatar or any other component as TimelinePoint inner content.

<Example name="timeline.render" />

## Theme

To learn more about how to customize the appearance of components, please see the [Theme docs](/docs/customize/theme).
1 change: 1 addition & 0 deletions apps/web/examples/timeline/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { horizontal } from "./timeline.horizontal";
export { root } from "./timeline.root";
export { vertical } from "./timeline.vertical";
export { render } from "./timeline.render";
211 changes: 211 additions & 0 deletions apps/web/examples/timeline/timeline.render.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
"use client";

import {
Avatar,
Badge,
Card,
Timeline,
TimelineBody,
TimelineContent,
TimelineItem,
TimelinePoint,
} from "flowbite-react";
import { type CodeData } from "~/components/code-demo";

const code = `
"use client";

import { Avatar, Badge, Timeline } from "flowbite-react";

export function Component() {
<Timeline>
<Timeline.Item>
<Timeline.Point
render={() => (
<Avatar img="https://flowbite.com/docs/images/people/profile-picture-3.jpg" rounded size="xm" />
)}
/>
<Timeline.Content>
<Timeline.Body>
<Card>
<div className="-m-2 sm:flex sm:items-center sm:justify-between">
<time className="mb-1 text-xs font-normal text-gray-400 sm:order-last sm:mb-0">just now</time>

<div className="text-sm font-normal text-gray-500 dark:text-gray-300">
Bonnie moved{" "}
<a href="#" className="font-semibold text-blue-600 hover:underline dark:text-blue-500">
Jese Leos
</a>{" "}
to{" "}
<Badge color="gray" className="inline">
Funny Group
</Badge>
</div>
</div>
</Card>
</Timeline.Body>
</Timeline.Content>
</Timeline.Item>
<Timeline.Item>
<Timeline.Point
render={() => (
<Avatar img="https://flowbite.com/docs/images/people/profile-picture-5.jpg" rounded size="xm" />
)}
/>
<Timeline.Content>
<Timeline.Body>
<Card>
<div className="-m-2">
<div className="mb-3 sm:flex sm:items-center sm:justify-between">
<time className="mb-1 text-xs font-normal text-gray-400 sm:order-last sm:mb-0">2 hours ago</time>
<div className="text-sm font-normal text-gray-500 dark:text-gray-300">
Thomas Lean commented on{" "}
<a href="#" className="font-semibold text-gray-900 hover:underline dark:text-white">
Flowbite Pro
</a>
</div>
</div>

<Card className="border-gray-200 bg-gray-50 text-xs font-normal italic text-gray-500 dark:border-gray-500 dark:bg-gray-600 dark:text-gray-300">
<div className="-m-3">
Hi ya'll! I wanted to share a webinar zeroheight is having regarding how to best measure your design
system! This is the second session of our new webinar series on #DesignSystems discussions where
we'll be speaking about Measurement.
</div>
</Card>
</div>
</Card>
</Timeline.Body>
</Timeline.Content>
</Timeline.Item>
<Timeline.Item>
<Timeline.Point
render={() => (
<Avatar img="https://flowbite.com/docs/images/people/profile-picture-1.jpg" rounded size="xm" />
)}
/>
<Timeline.Content>
<Timeline.Body>
<Card>
<div className="-m-2 sm:flex sm:items-center sm:justify-between">
<time className="mb-1 text-xs font-normal text-gray-400 sm:order-last sm:mb-0">1 day ago</time>

<div className="text-sm font-normal text-gray-500 dark:text-gray-300">
Jese Leos has changed{" "}
<a href="#" className="font-semibold text-blue-600 hover:underline dark:text-blue-500">
Pricing page
</a>{" "}
task status to <span className="font-semibold text-gray-900 dark:text-white">Finished</span>
</div>
</div>
</Card>
</Timeline.Body>
</Timeline.Content>
</Timeline.Item>
</Timeline>
}
`;

export function Component() {
return (
<Timeline>
<TimelineItem>
<TimelinePoint
render={() => (
<Avatar img="https://flowbite.com/docs/images/people/profile-picture-3.jpg" rounded size="xm" />
)}
/>
<TimelineContent>
<TimelineBody>
<Card>
<div className="-m-2 sm:flex sm:items-center sm:justify-between">
<time className="mb-1 text-xs font-normal text-gray-400 sm:order-last sm:mb-0">just now</time>

<div className="text-sm font-normal text-gray-500 dark:text-gray-300">
Bonnie moved{" "}
<a href="#" className="font-semibold text-blue-600 hover:underline dark:text-blue-500">
Jese Leos
</a>{" "}
to{" "}
<Badge color="gray" className="inline">
Funny Group
</Badge>
</div>
</div>
</Card>
</TimelineBody>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelinePoint
render={() => (
<Avatar img="https://flowbite.com/docs/images/people/profile-picture-5.jpg" rounded size="xm" />
)}
/>
<TimelineContent>
<TimelineBody>
<Card>
<div className="-m-2">
<div className="mb-3 sm:flex sm:items-center sm:justify-between">
<time className="mb-1 text-xs font-normal text-gray-400 sm:order-last sm:mb-0">2 hours ago</time>
<div className="text-sm font-normal text-gray-500 dark:text-gray-300">
Thomas Lean commented on{" "}
<a href="#" className="font-semibold text-gray-900 hover:underline dark:text-white">
Flowbite Pro
</a>
</div>
</div>

<Card className="border-gray-200 bg-gray-50 text-xs font-normal italic text-gray-500 dark:border-gray-500 dark:bg-gray-600 dark:text-gray-300">
<div className="-m-3">
Hi ya'll! I wanted to share a webinar zeroheight is having regarding how to best measure your design
system! This is the second session of our new webinar series on #DesignSystems discussions where
we'll be speaking about Measurement.
</div>
</Card>
</div>
</Card>
</TimelineBody>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelinePoint
render={() => (
<Avatar img="https://flowbite.com/docs/images/people/profile-picture-1.jpg" rounded size="xm" />
)}
/>
<TimelineContent>
<TimelineBody>
<Card>
<div className="-m-2 sm:flex sm:items-center sm:justify-between">
<time className="mb-1 text-xs font-normal text-gray-400 sm:order-last sm:mb-0">1 day ago</time>

<div className="text-sm font-normal text-gray-500 dark:text-gray-300">
Jese Leos has changed{" "}
<a href="#" className="font-semibold text-blue-600 hover:underline dark:text-blue-500">
Pricing page
</a>{" "}
task status to <span className="font-semibold text-gray-900 dark:text-white">Finished</span>
</div>
</div>
</Card>
</TimelineBody>
</TimelineContent>
</TimelineItem>
</Timeline>
);
}

export const render: CodeData = {
type: "single",
code: [
{
fileName: "client",
language: "tsx",
code,
},
],
githubSlug: "timeline/timeline.render.tsx",
component: <Component />,
iframe: 391,
};
32 changes: 32 additions & 0 deletions packages/ui/src/components/Timeline/Timeline.spec.tsx
Original file line number Diff line number Diff line change
@@ -21,6 +21,13 @@ describe("Components / Timeline", () => {
expect(timelinePoint().childNodes[0]).toContainHTML("svg");
});

it("should render custom inner content when using render prop", () => {
render(<TestTimelineWithRenderProp horizontal={true} />);

expect(timelinePoint()).toBeInTheDocument();
expect(timelinePoint().childNodes[0]).toContainHTML("img");
});

it("should use `horizontal` classes of content if provided", () => {
render(
<Flowbite theme={{ theme }}>
@@ -56,6 +63,13 @@ describe("Components / Timeline", () => {
expect(timelinePoint().childNodes[0]).toContainHTML("svg");
});

it("should render custom inner content when using render prop", () => {
render(<TestTimelineWithRenderProp horizontal={false} />);

expect(timelinePoint()).toBeInTheDocument();
expect(timelinePoint().childNodes[0]).toContainHTML("img");
});

it("should use `vertical` classes of content if provided", () => {
render(
<Flowbite theme={{ theme }}>
@@ -135,6 +149,24 @@ const TestTimelineWithIcon: FC<TimelineProps> = ({ horizontal, className }): JSX
);
};

const TestTimelineWithRenderProp: FC<TimelineProps> = ({ horizontal, className }): JSX.Element => {
return (
<Timeline horizontal={horizontal} className={className}>
<Timeline.Item>
<Timeline.Point render={() => <img src="https://flowbite.com/docs/images/people/profile-picture-5.jpg" />} />
<Timeline.Content>
<Timeline.Time>February 2022</Timeline.Time>
<Timeline.Title>Application UI code in Tailwind CSS</Timeline.Title>
<Timeline.Body>
Get access to over 20+ pages including a dashboard layout, charts, kanban board, calendar, and pre-order
E-commerce & Marketing pages.
</Timeline.Body>
</Timeline.Content>
</Timeline.Item>
</Timeline>
);
};

const IconSVG = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
94 changes: 94 additions & 0 deletions packages/ui/src/components/Timeline/Timeline.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { Meta, StoryFn } from "@storybook/react";
import { Avatar } from "../Avatar";
import { Badge } from "../Badge";
import { Card } from "../Card";
import type { TimelineProps } from "./Timeline";
import { Timeline } from "./Timeline";

@@ -48,3 +51,94 @@ Default.args = {
</>
),
};

export const ActivityLog = Template.bind({});
ActivityLog.args = {
children: (
<>
<Timeline.Item>
<Timeline.Point
render={() => (
<Avatar img="https://flowbite.com/docs/images/people/profile-picture-3.jpg" rounded size="xm" />
)}
/>
<Timeline.Content>
<Timeline.Body>
<Card>
<div className="-m-2 sm:flex sm:items-center sm:justify-between">
<time className="mb-1 text-xs font-normal text-gray-400 sm:order-last sm:mb-0">just now</time>

<div className="text-sm font-normal text-gray-500 dark:text-gray-300">
Bonnie moved{" "}
<a href="#" className="font-semibold text-blue-600 hover:underline dark:text-blue-500">
Jese Leos
</a>{" "}
to{" "}
<Badge color="gray" className="inline">
Funny Group
</Badge>
</div>
</div>
</Card>
</Timeline.Body>
</Timeline.Content>
</Timeline.Item>
<Timeline.Item>
<Timeline.Point
render={() => (
<Avatar img="https://flowbite.com/docs/images/people/profile-picture-5.jpg" rounded size="xm" />
)}
/>
<Timeline.Content>
<Timeline.Body>
<Card>
<div className="-m-2">
<div className="mb-3 sm:flex sm:items-center sm:justify-between">
<time className="mb-1 text-xs font-normal text-gray-400 sm:order-last sm:mb-0">2 hours ago</time>
<div className="text-sm font-normal text-gray-500 dark:text-gray-300">
Thomas Lean commented on{" "}
<a href="#" className="font-semibold text-gray-900 hover:underline dark:text-white">
Flowbite Pro
</a>
</div>
</div>

<Card className="border-gray-200 bg-gray-50 text-xs font-normal italic text-gray-500 dark:border-gray-500 dark:bg-gray-600 dark:text-gray-300">
<div className="-m-3">
Hi ya'll! I wanted to share a webinar zeroheight is having regarding how to best measure your design
system! This is the second session of our new webinar series on #DesignSystems discussions where
we'll be speaking about Measurement.
</div>
</Card>
</div>
</Card>
</Timeline.Body>
</Timeline.Content>
</Timeline.Item>
<Timeline.Item>
<Timeline.Point
render={() => (
<Avatar img="https://flowbite.com/docs/images/people/profile-picture-1.jpg" rounded size="xm" />
)}
/>
<Timeline.Content>
<Timeline.Body>
<Card>
<div className="-m-2 sm:flex sm:items-center sm:justify-between">
<time className="mb-1 text-xs font-normal text-gray-400 sm:order-last sm:mb-0">1 day ago</time>

<div className="text-sm font-normal text-gray-500 dark:text-gray-300">
Jese Leos has changed{" "}
<a href="#" className="font-semibold text-blue-600 hover:underline dark:text-blue-500">
Pricing page
</a>{" "}
task status to <span className="font-semibold text-gray-900 dark:text-white">Finished</span>
</div>
</div>
</Card>
</Timeline.Body>
</Timeline.Content>
</Timeline.Item>
</>
),
};
4 changes: 4 additions & 0 deletions packages/ui/src/components/Timeline/TimelinePoint.tsx
Original file line number Diff line number Diff line change
@@ -26,13 +26,15 @@ export interface FlowbiteTimelinePointTheme {
export interface TimelnePointProps extends ComponentProps<"div"> {
icon?: FC<ComponentProps<"svg">>;
theme?: DeepPartial<FlowbiteTimelinePointTheme>;
render?: () => React.ReactNode;
}

export const TimelinePoint: FC<TimelnePointProps> = ({
children,
className,
icon: Icon,
theme: customTheme = {},
render,
...props
}) => {
const { horizontal } = useTimelineContext();
@@ -51,6 +53,8 @@ export const TimelinePoint: FC<TimelnePointProps> = ({
<span className={twMerge(theme.marker.icon.wrapper)}>
<Icon aria-hidden className={twMerge(theme.marker.icon.base)} />
</span>
) : render ? (
<span className={twMerge(theme.marker.icon.wrapper)}>{render()}</span>
) : (
<div
className={twMerge(horizontal && theme.marker.base.horizontal, !horizontal && theme.marker.base.vertical)}

Unchanged files with check annotations Beta

<div className="relative">
{/* <Banner /> */}
<DocsNavbar {...state} />
<div className="mx-auto w-full max-w-8xl lg:flex lg:px-4">

Check warning on line 36 in apps/web/app/docs/layout.tsx

GitHub Actions / 🕵 Lint

Classname 'max-w-8xl' is not a Tailwind CSS class!
<DocsSidebar {...state} />
<div className="w-full min-w-0">{children}</div>
</div>
return (
<Navbar
fluid
theme={{

Check warning on line 50 in apps/web/app/docs/layout.tsx

GitHub Actions / 🕵 Lint

Classname 'max-w-8xl' is not a Tailwind CSS class!
root: {
base: "sticky top-0 z-[60] mx-auto flex w-full items-center justify-between border-b border-gray-200 bg-white text-gray-500 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400",
inner: {
<Link
href={href}
target={isExternal ? "_blank" : undefined}
className={twMerge(

Check warning on line 170 in apps/web/app/docs/layout.tsx

GitHub Actions / 🕵 Lint

Classname 'text-primary-700' is not a Tailwind CSS class!

Check warning on line 170 in apps/web/app/docs/layout.tsx

GitHub Actions / 🕵 Lint

Classname 'hover:text-primary-700' is not a Tailwind CSS class!

Check warning on line 170 in apps/web/app/docs/layout.tsx

GitHub Actions / 🕵 Lint

Classname 'dark:text-primary-500' is not a Tailwind CSS class!
"flex flex-wrap items-center py-2 font-medium",
pathname === href
? "text-primary-700 hover:text-primary-700 dark:text-primary-500"
<div className="relative flex min-h-screen flex-col">
<HomeNavbar />
<div className="mx-auto flex max-w-screen-sm flex-1 flex-col justify-center px-4 py-8 text-center sm:py-16 lg:px-6 xl:px-0">
<h1 className="mb-4 text-4xl font-extrabold text-primary-600">404 - Page Not Found</h1>

Check warning on line 9 in apps/web/app/not-found.tsx

GitHub Actions / 🕵 Lint

Classname 'text-primary-600' is not a Tailwind CSS class!
<p className="text-gray-500 md:text-xl dark:text-gray-400">
Whoops! That page doesn’t exist. But do not fret, check out our other resources to get started.
</p>
<div {...(isRTL && { dir: "rtl" })} className="code-preview-wrapper">
<div className="flex border-x border-gray-200 bg-white bg-gradient-to-r p-0 dark:border-gray-600 dark:bg-gray-900">
<div
className={twMerge("code-responsive-wrapper w-full", isDarkMode !== null && (isDarkMode ? "dark" : "light"))}

Check warning on line 250 in apps/web/components/code-demo.tsx

GitHub Actions / 🕵 Lint

Classname 'light' is not a Tailwind CSS class!
>
<div
className={twMerge(
href={href}
target="_blank"
rel="nofollow noopener noreferrer"
className="inline-flex w-fit items-center justify-center gap-2 rounded-lg border border-gray-200 bg-white px-3 py-2 text-center text-xs font-medium text-gray-900 hover:bg-gray-100 hover:text-primary-700 focus:text-primary-700 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:text-white dark:focus:ring-gray-700"

Check warning on line 277 in apps/web/components/code-demo.tsx

GitHub Actions / 🕵 Lint

Classname 'hover:text-primary-700' is not a Tailwind CSS class!

Check warning on line 277 in apps/web/components/code-demo.tsx

GitHub Actions / 🕵 Lint

Classname 'focus:text-primary-700' is not a Tailwind CSS class!
>
<svg
aria-hidden
<Tooltip key={v.name} content={v.title}>
<button
onClick={() => onSelect(v.name)}
className="flex size-9 items-center justify-center rounded-lg border border-gray-200 bg-white text-xs font-medium text-gray-700 hover:bg-gray-100 hover:text-primary-700 focus:z-10 focus:outline-none focus:ring-2 focus:ring-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-500"

Check warning on line 312 in apps/web/components/code-demo.tsx

GitHub Actions / 🕵 Lint

Classname 'hover:text-primary-700' is not a Tailwind CSS class!
>
<span className="sr-only">{v.title}</span>
<v.icon className="size-4" />