From 240519369dc0dc8c3a407728476ea0ef96a624ed Mon Sep 17 00:00:00 2001 From: adel Date: Thu, 26 Dec 2024 09:26:02 +0100 Subject: [PATCH 1/5] Added support for render props function in Timeline.Point --- .../src/components/Timeline/Timeline.spec.tsx | 32 +++++++ .../components/Timeline/Timeline.stories.tsx | 94 +++++++++++++++++++ .../src/components/Timeline/TimelinePoint.tsx | 4 + 3 files changed, 130 insertions(+) diff --git a/packages/ui/src/components/Timeline/Timeline.spec.tsx b/packages/ui/src/components/Timeline/Timeline.spec.tsx index ed9f27730..78b6cf8e8 100644 --- a/packages/ui/src/components/Timeline/Timeline.spec.tsx +++ b/packages/ui/src/components/Timeline/Timeline.spec.tsx @@ -21,6 +21,13 @@ describe("Components / Timeline", () => { expect(timelinePoint().childNodes[0]).toContainHTML("svg"); }); + it("should render custom inner content when using render prop", () => { + render(); + + expect(timelinePoint()).toBeInTheDocument(); + expect(timelinePoint().childNodes[0]).toContainHTML("img"); + }); + it("should use `horizontal` classes of content if provided", () => { render( @@ -56,6 +63,13 @@ describe("Components / Timeline", () => { expect(timelinePoint().childNodes[0]).toContainHTML("svg"); }); + it("should render custom inner content when using render prop", () => { + render(); + + expect(timelinePoint()).toBeInTheDocument(); + expect(timelinePoint().childNodes[0]).toContainHTML("img"); + }); + it("should use `vertical` classes of content if provided", () => { render( @@ -135,6 +149,24 @@ const TestTimelineWithIcon: FC = ({ horizontal, className }): JSX ); }; +const TestTimelineWithRenderProp: FC = ({ horizontal, className }): JSX.Element => { + return ( + + + } /> + + February 2022 + Application UI code in Tailwind CSS + + Get access to over 20+ pages including a dashboard layout, charts, kanban board, calendar, and pre-order + E-commerce & Marketing pages. + + + + + ); +}; + const IconSVG = () => ( ), }; + +export const ActivityLog = Template.bind({}); +ActivityLog.args = { + children: ( + <> + + ( + + )} + /> + + + +
+ + +
+ Bonnie moved{" "} + + Jese Leos + {" "} + to{" "} + + Funny Group + +
+
+
+
+
+
+ + ( + + )} + /> + + + +
+
+ +
+ Thomas Lean commented on{" "} + + Flowbite Pro + +
+
+ + +
+ 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. +
+
+
+
+
+
+
+ + ( + + )} + /> + + + +
+ + +
+ Jese Leos has changed{" "} + + Pricing page + {" "} + task status to Finished +
+
+
+
+
+
+ + ), +}; diff --git a/packages/ui/src/components/Timeline/TimelinePoint.tsx b/packages/ui/src/components/Timeline/TimelinePoint.tsx index 17112af06..0291efe5d 100644 --- a/packages/ui/src/components/Timeline/TimelinePoint.tsx +++ b/packages/ui/src/components/Timeline/TimelinePoint.tsx @@ -26,6 +26,7 @@ export interface FlowbiteTimelinePointTheme { export interface TimelnePointProps extends ComponentProps<"div"> { icon?: FC>; theme?: DeepPartial; + render?: () => React.ReactElement; } export const TimelinePoint: FC = ({ @@ -33,6 +34,7 @@ export const TimelinePoint: FC = ({ className, icon: Icon, theme: customTheme = {}, + render = undefined, ...props }) => { const { horizontal } = useTimelineContext(); @@ -51,6 +53,8 @@ export const TimelinePoint: FC = ({ + ) : render ? ( + {render()} ) : (
Date: Thu, 26 Dec 2024 09:29:13 +0100 Subject: [PATCH 2/5] Added docs for the Timeline.Point render prop --- apps/web/content/docs/components/timeline.mdx | 6 + apps/web/examples/timeline/index.ts | 1 + .../web/examples/timeline/timeline.render.tsx | 211 ++++++++++++++++++ 3 files changed, 218 insertions(+) create mode 100644 apps/web/examples/timeline/timeline.render.tsx diff --git a/apps/web/content/docs/components/timeline.mdx b/apps/web/content/docs/components/timeline.mdx index 62733b489..1402afbeb 100644 --- a/apps/web/content/docs/components/timeline.mdx +++ b/apps/web/content/docs/components/timeline.mdx @@ -31,6 +31,12 @@ Use the `horizontal` prop to show the timeline component and the child component +## Render props + +Use the `render` prop to render an Avatar or any other component as TimelinePoint inner content. + + + ## Theme To learn more about how to customize the appearance of components, please see the [Theme docs](/docs/customize/theme). diff --git a/apps/web/examples/timeline/index.ts b/apps/web/examples/timeline/index.ts index 479235816..8ba113a98 100644 --- a/apps/web/examples/timeline/index.ts +++ b/apps/web/examples/timeline/index.ts @@ -1,3 +1,4 @@ export { horizontal } from "./timeline.horizontal"; export { root } from "./timeline.root"; export { vertical } from "./timeline.vertical"; +export { render } from "./timeline.render"; diff --git a/apps/web/examples/timeline/timeline.render.tsx b/apps/web/examples/timeline/timeline.render.tsx new file mode 100644 index 000000000..e61e5822c --- /dev/null +++ b/apps/web/examples/timeline/timeline.render.tsx @@ -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() { + + + ( + + )} + /> + + + +
+ + +
+ Bonnie moved{" "} + + Jese Leos + {" "} + to{" "} + + Funny Group + +
+
+
+
+
+
+ + ( + + )} + /> + + + +
+
+ +
+ Thomas Lean commented on{" "} + + Flowbite Pro + +
+
+ + +
+ 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. +
+
+
+
+
+
+
+ + ( + + )} + /> + + + +
+ + +
+ Jese Leos has changed{" "} + + Pricing page + {" "} + task status to Finished +
+
+
+
+
+
+
+} +`; + +export function Component() { + return ( + + + ( + + )} + /> + + + +
+ + +
+ Bonnie moved{" "} + + Jese Leos + {" "} + to{" "} + + Funny Group + +
+
+
+
+
+
+ + ( + + )} + /> + + + +
+
+ +
+ Thomas Lean commented on{" "} + + Flowbite Pro + +
+
+ + +
+ 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. +
+
+
+
+
+
+
+ + ( + + )} + /> + + + +
+ + +
+ Jese Leos has changed{" "} + + Pricing page + {" "} + task status to Finished +
+
+
+
+
+
+
+ ); +} + +export const render: CodeData = { + type: "single", + code: [ + { + fileName: "client", + language: "tsx", + code, + }, + ], + githubSlug: "timeline/timeline.render.tsx", + component: , + iframe: 391, +}; From efea456f82f18d733f7142e3ab9cc64e1b6f3778 Mon Sep 17 00:00:00 2001 From: adel Date: Sat, 28 Dec 2024 16:46:23 +0100 Subject: [PATCH 3/5] Remove redundant 'undefined" value for render prop. --- packages/ui/src/components/Timeline/TimelinePoint.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ui/src/components/Timeline/TimelinePoint.tsx b/packages/ui/src/components/Timeline/TimelinePoint.tsx index 0291efe5d..2c68dacd9 100644 --- a/packages/ui/src/components/Timeline/TimelinePoint.tsx +++ b/packages/ui/src/components/Timeline/TimelinePoint.tsx @@ -34,7 +34,7 @@ export const TimelinePoint: FC = ({ className, icon: Icon, theme: customTheme = {}, - render = undefined, + render, ...props }) => { const { horizontal } = useTimelineContext(); From de75a474e85a4dcff321c145592da54b47fcca0f Mon Sep 17 00:00:00 2001 From: adel Date: Sat, 28 Dec 2024 16:46:57 +0100 Subject: [PATCH 4/5] Added patch changeset --- .changeset/lucky-ladybugs-film.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lucky-ladybugs-film.md diff --git a/.changeset/lucky-ladybugs-film.md b/.changeset/lucky-ladybugs-film.md new file mode 100644 index 000000000..3a12afbdf --- /dev/null +++ b/.changeset/lucky-ladybugs-film.md @@ -0,0 +1,5 @@ +--- +"flowbite-react": patch +--- + +Allow `Timeline.Point` to render components as inner content. From 2c54812ed8b424733b82894739c7e345595cce3c Mon Sep 17 00:00:00 2001 From: adel Date: Wed, 15 Jan 2025 17:14:27 +0100 Subject: [PATCH 5/5] Update TimelinePoint render prop type to return React.ReactNode --- packages/ui/src/components/Timeline/TimelinePoint.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ui/src/components/Timeline/TimelinePoint.tsx b/packages/ui/src/components/Timeline/TimelinePoint.tsx index 2c68dacd9..6c660f9d9 100644 --- a/packages/ui/src/components/Timeline/TimelinePoint.tsx +++ b/packages/ui/src/components/Timeline/TimelinePoint.tsx @@ -26,7 +26,7 @@ export interface FlowbiteTimelinePointTheme { export interface TimelnePointProps extends ComponentProps<"div"> { icon?: FC>; theme?: DeepPartial; - render?: () => React.ReactElement; + render?: () => React.ReactNode; } export const TimelinePoint: FC = ({