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

Feat/render timeline point inner content #1520

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

adel-gu
Copy link

@adel-gu adel-gu commented Dec 26, 2024

Issue #1276

Summary

This PR adds an optional render prop on the TimelinePoint to render any component as inner content for the TimelinePoint component.

Example usage

    ...
      <Timeline.Point
          render={() => (
            <Avatar img="https://flowbite.com/docs/images/people/profile-picture-3.jpg" rounded size="xm" />
          )}
      />
    ...

Preview

Screenshot from 2024-12-26 10-28-53

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a "Render props" section to the Timeline component documentation.
    • Introduced a new React component for rendering a structured timeline with customizable inner content.
    • Added a new story titled "ActivityLog" to showcase the Timeline component with avatars and timestamps.
    • Enhanced the TimelinePoint component to support a render function for flexible content rendering.
  • Bug Fixes

    • Improved test coverage for the Timeline component, validating the render prop functionality.
  • Documentation

    • Updated documentation to include guidance on the new render prop feature.

Copy link

changeset-bot bot commented Dec 26, 2024

🦋 Changeset detected

Latest commit: de75a47

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
flowbite-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Dec 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flowbite-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 28, 2024 3:48pm
flowbite-react-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 28, 2024 3:48pm

Copy link
Contributor

coderabbitai bot commented Dec 26, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/ui/src/components/Timeline/TimelinePoint.tsx

Oops! Something went wrong! :(

ESLint: 8.57.0

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/packages/ui".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in "packages/ui/.eslintrc.cjs".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

Walkthrough

The pull request introduces a new "Render props" feature for the Timeline component, enhancing its documentation and implementation across several files. This feature allows developers to customize the inner content of timeline points by rendering components such as avatars. Changes include updates to documentation, the addition of a new React component, export statements, test cases, and Storybook stories, collectively improving the flexibility and usability of the Timeline component.

Changes

File Change Summary
apps/web/content/docs/components/timeline.mdx Added "Render props" section explaining how to use the render prop
apps/web/examples/timeline/index.ts Added export for render function from ./timeline.render module
apps/web/examples/timeline/timeline.render.tsx New client component with timeline example using render props
packages/ui/src/components/Timeline/Timeline.spec.tsx Added test case for render prop functionality
packages/ui/src/components/Timeline/Timeline.stories.tsx New ActivityLog story showcasing render prop with avatars
packages/ui/src/components/Timeline/TimelinePoint.tsx Added render prop to TimelinePointProps interface
.changeset/lucky-ladybugs-film.md Enhanced Timeline.Point component to support rendering components as inner content

Sequence Diagram

sequenceDiagram
    participant Developer
    participant TimelineComponent
    participant RenderProp
    
    Developer->>TimelineComponent: Configure Timeline
    Developer->>TimelineComponent: Provide render prop
    TimelineComponent->>RenderProp: Invoke render function
    RenderProp-->>TimelineComponent: Return custom React element
    TimelineComponent->>Developer: Render custom content
Loading

Poem

🐰 A Timeline's Tale of Render and Flair

Hop, skip, and jump through events with care
Avatars dancing, stories unfold
Render props weaving narratives bold
A rabbit's delight, components so bright! 🎨

— CodeRabbit's Poetic Insight 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/ui/src/components/Timeline/Timeline.stories.tsx (1)

54-144: New ActivityLog story

Defining a realistic “activity log” scenario with custom rendering of Avatar inside Timeline.Point effectively showcases the utility of the new render prop. Great for user clarity.
Consider referencing the new render prop in story comments for discoverability.

apps/web/examples/timeline/timeline.render.tsx (1)

109-197: Encapsulate repeated structures for maintainability.
Three similar TimelineItem blocks are repeated (lines 113-138, 139-170, 171-194). Consider abstracting common patterns (e.g., the <Avatar> rendering and markup inside <TimelineItem>) into a reusable helper component or a higher-order function to minimize duplication and improve maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bed3c41 and 6252528.

📒 Files selected for processing (6)
  • apps/web/content/docs/components/timeline.mdx (1 hunks)
  • apps/web/examples/timeline/index.ts (1 hunks)
  • apps/web/examples/timeline/timeline.render.tsx (1 hunks)
  • packages/ui/src/components/Timeline/Timeline.spec.tsx (3 hunks)
  • packages/ui/src/components/Timeline/Timeline.stories.tsx (2 hunks)
  • packages/ui/src/components/Timeline/TimelinePoint.tsx (2 hunks)
🔇 Additional comments (12)
apps/web/examples/timeline/index.ts (1)

4-4: Export statement looks good.

Exporting the render function here ensures it's accessible elsewhere. Make sure the named export render matches the default or named export in the target file for consistency.

packages/ui/src/components/Timeline/TimelinePoint.tsx (3)

29-29: New optional prop: render

Adding render?: () => React.ReactElement; extends component flexibility nicely. This approach provides a clean way to inject custom content into the timeline point.


37-37: Default value initialization

Defining render = undefined helps clarify usage and ensures consistent handling internally. Looks fine.


56-57: Conditional rendering is well-structured.

Using Icon if present, otherwise falling back to render, then a fallback marker, is logically consistent. Nicely implemented for clarity and maintainability.

packages/ui/src/components/Timeline/Timeline.stories.tsx (1)

2-3: New imports for Avatar and Badge

These imports enhance the story’s visual demonstration of custom timeline points and item content. No issues found.

packages/ui/src/components/Timeline/Timeline.spec.tsx (3)

24-29: Test coverage for the render prop (horizontal mode)

This test ensures that the custom inner content is rendered. The assertion .toContainHTML("img") is straightforward and sufficient to confirm correctness.


66-71: Test coverage for the render prop (vertical mode)

Likewise, verifying the custom content in vertical mode is consistent and provides full coverage of both orientations.


152-168: Helper component TestTimelineWithRenderProp

The example usage of render={() => <img ... />} is concise and clearly demonstrates the custom render flow. Good addition to the test suite for completeness.

apps/web/examples/timeline/timeline.render.tsx (3)

1-2: Use of "use client" is correct and aligns with Next.js app directory best practices.
No issues found related to rendering on the client side.


15-46: Ensure synchronization of example code with the actual component usage.
The multiline string in code (lines 15-46) displays the same component structure as defined later in the file. Any future modifications to the Component should be mirrored here, to avoid inconsistency in the example code snippet.


199-211: Export object provides a clean story/demo reference.
No issues found with the explanation or code snippet references. The definition of render: CodeData is straightforward and aids in providing a user-facing example.

apps/web/content/docs/components/timeline.mdx (1)

34-39: Documentation properly illustrates the new render prop usage.
Adding a dedicated “Render props” section clarifies how to pass a component, like Avatar, within the TimelinePoint. The example reference is concise and effectively guides users toward the new feature.

Copy link
Collaborator

@SutuSebastian SutuSebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure to run bun changeset and select flowbite-react for a patch change, give it a title and add the file to this PR

}

export const TimelinePoint: FC<TimelnePointProps> = ({
children,
className,
icon: Icon,
theme: customTheme = {},
render = undefined,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default to undefined is redundant in this case

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.changeset/lucky-ladybugs-film.md (1)

1-5: Enhance the changeset description with more details.

While the description is clear, it would be more helpful to include:

Consider expanding the description like this:

---
"flowbite-react": patch
---

-Allow `Timeline.Point` to render components as inner content.
+Allow `Timeline.Point` to render components as inner content through an optional `render` prop.
+
+Example usage:
+```jsx
+<Timeline.Point render={() => <Avatar img="path/to/image" size="md" rounded />} />
+```
+
+Resolves #1276 by providing more flexibility in customizing timeline points.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6252528 and de75a47.

📒 Files selected for processing (2)
  • .changeset/lucky-ladybugs-film.md (1 hunks)
  • packages/ui/src/components/Timeline/TimelinePoint.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/ui/src/components/Timeline/TimelinePoint.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants