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

refactor: improve dx for writing a docs component #2544

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

Innei
Copy link

@Innei Innei commented Mar 18, 2024

Closes #

📝 Description

Add a brief description

The component DX that writes docs now is very unfriendly and difficult to maintain.

Like this. What stringfiy code??

CleanShot 2024-03-18 at 9  39 42@2x

For now, I just refactor this and improve DX. And now we can write code in single tsx file, and import it.
CleanShot 2024-03-18 at 9  40 39@2x

And import it assert to raw.

import App from "./bordered-variant.raw.tsx?raw";

const react = {
  "/App.jsx": App,
};

export default {
  ...react,
};

💣 Is this a breaking change (Yes/No):

No

📝 Additional Information

Summary by CodeRabbit

  • New Features
    • Introduced a new way to import and use components in the documentation app, enhancing code readability and maintainability.
  • Documentation
    • Updated the documentation app configuration to support new content types and improve the authoring experience.
  • Refactor
    • Refactored accordion components to use a more efficient import method.
  • Chores
    • Updated dependencies to ensure compatibility and security.
  • Tests
    • Ensured all new changes are compatible with existing configurations and types.

@Innei Innei requested a review from jrgarciadev as a code owner March 18, 2024 13:41
Copy link

changeset-bot bot commented Mar 18, 2024

⚠️ No Changeset found

Latest commit: 5c15533

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

vercel bot commented Mar 18, 2024

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

Name Status Preview Comments Updated (UTC)
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2024 1:43pm

Copy link

vercel bot commented Mar 18, 2024

@Innei is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Mar 18, 2024

Walkthrough

The update significantly changes how components in the documentation app are defined, moving from internal definitions to importing them from raw files. It also introduces the esbuild-plugin-raw to handle raw file imports, updates dependencies, and enhances the contentlayer.config.js with new computed fields and esbuild options. Additionally, a new TypeScript declaration file is added for importing files as raw strings, and various document type definitions are refined.

Changes

Files Change Summary
.../accordion/bordered-variant.ts
.../accordion/compact.ts
Changed to import App from respective .raw.tsx files instead of defining it internally.
.../contentlayer.config.js Added RawPlugin import, new computed fields, updated AuthorProperties and BlogPost types, added esbuildOptions.
.../package.json Added esbuild-plugin-raw dependency.
.../tsconfig.json Added "types.d.ts" to included files.
.../types.d.ts Introduced declaration for importing files as raw strings.
pnpm-lock.yaml Added esbuild-plugin-raw and its dependencies, updated eslint-config-next, added esbuild dependency.

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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between e67b3af and 5c15533.
Files selected for processing (9)
  • apps/docs/content/components/accordion/bordered-variant.raw.tsx (1 hunks)
  • apps/docs/content/components/accordion/bordered-variant.ts (1 hunks)
  • apps/docs/content/components/accordion/compact.raw.tsx (1 hunks)
  • apps/docs/content/components/accordion/compact.ts (1 hunks)
  • apps/docs/contentlayer.config.js (6 hunks)
  • apps/docs/package.json (1 hunks)
  • apps/docs/tsconfig.json (1 hunks)
  • apps/docs/types.d.ts (1 hunks)
  • pnpm-lock.yaml (2 hunks)
Additional comments: 13
apps/docs/types.d.ts (1)
  • 1-3: LGTM! This TypeScript module declaration is essential for the new approach to handling code snippets in documentation, aligning perfectly with the PR's objectives.
apps/docs/content/components/accordion/compact.ts (1)
  • 1-4: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-8]

LGTM! The change to import App from compact.raw.tsx using the raw string import method is a clear improvement, making the management of code snippets more straightforward.

apps/docs/content/components/accordion/bordered-variant.ts (1)
  • 1-4: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-8]

LGTM! Importing App from bordered-variant.raw.tsx using the raw string import method is consistent with the project's new approach and improves the developer experience.

apps/docs/tsconfig.json (1)
  • 27-28: LGTM! Including "types.d.ts" in the tsconfig.json file is necessary for the TypeScript compiler to recognize the custom module declaration for raw string imports, aligning with the PR's objectives.
apps/docs/content/components/accordion/compact.raw.tsx (1)
  • 1-20: LGTM! This file correctly implements the new approach for handling code snippets in documentation by providing the raw TSX code for the compact accordion variant. The code is well-structured and follows best practices.
apps/docs/content/components/accordion/bordered-variant.raw.tsx (1)
  • 1-20: LGTM! This file provides the raw TSX code for the bordered-variant accordion, aligning with the new approach for managing code snippets in documentation. The code is clean and follows best practices.
apps/docs/contentlayer.config.js (3)
  • 5-5: LGTM! Importing RawPlugin from 'esbuild-plugin-raw' is necessary for enabling raw string imports, aligning with the PR's objectives.
  • 18-18: LGTM! The addition of computed fields in the Doc document type is well-justified and aligns with the PR's objectives.
  • 83-88: LGTM! The esbuildOptions function is correctly configured to use RawPlugin, facilitating the import of raw content. This change supports the new approach for handling code snippets in documentation.
apps/docs/package.json (1)
  • 121-121: LGTM! Adding esbuild-plugin-raw as a dependency is essential for enabling raw string imports, supporting the PR's objectives to improve the developer experience.
pnpm-lock.yaml (3)
  • 577-579: The addition of esbuild-plugin-raw with version 0.1.8 and its specific dependency on [email protected] aligns well with the PR objectives to improve the developer experience by enabling raw content import functionality. This change is correctly implemented.
  • 577-579: The update to eslint-config-next to version 13.5.6 seems to be part of general dependency maintenance. It's important to ensure that this update does not introduce any breaking changes or conflicts with the current project setup.
  • 15391-15397: The detailed entry for [email protected] correctly specifies its resolution, peerDependencies, and direct dependency on [email protected]. This ensures compatibility with a range of esbuild versions, aligning with the PR's goal to improve developer experience through raw content import functionality.

@winchesHe
Copy link
Member

That's great, it's very easy to write docs component!

@ryo-manba
Copy link
Member

@Innei
Thanks for your PR!
Could you please resolve the conflicts so that we can proceed with the review?

@wingkwong wingkwong changed the base branch from main to canary April 28, 2024 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants