Skip to content

fix: should not export list item internal variables type#4200

Closed
winchesHe wants to merge 4 commits into
canaryfrom
fix/intertype-should-not-expoort
Closed

fix: should not export list item internal variables type#4200
winchesHe wants to merge 4 commits into
canaryfrom
fix/intertype-should-not-expoort

Conversation

@winchesHe
Copy link
Copy Markdown
Contributor

@winchesHe winchesHe commented Dec 1, 2024

Closes #

📝 Description

related #4157

⛳️ Current behavior (updates)

🚀 New behavior

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

📝 Additional Information

Summary by CodeRabbit

  • New Features

    • Updated type definitions for MenuProps and MenuItemVariantProps, enhancing flexibility in component usage.
    • Enhanced type safety and structure for the files property in the ReactLiveDemo component.
  • Bug Fixes

    • Adjusted properties in type definitions to ensure accurate representation of component capabilities.
    • Improved encapsulation by preventing the export of internal variable types for list items.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Dec 1, 2024

🦋 Changeset detected

Latest commit: 3e8f7bf

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

This PR includes changesets to release 12 packages
Name Type
@nextui-org/menu Patch
@nextui-org/theme Patch
@nextui-org/dropdown Patch
@nextui-org/react Patch
@nextui-org/autocomplete Patch
@nextui-org/checkbox Patch
@nextui-org/date-input Patch
@nextui-org/date-picker Patch
@nextui-org/form Patch
@nextui-org/input Patch
@nextui-org/radio Patch
@nextui-org/table 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

@vercel
Copy link
Copy Markdown

vercel Bot commented Dec 1, 2024

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

Name Status Preview Comments Updated (UTC)
nextui-docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 1, 2024 3:47pm
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 1, 2024 3:47pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 1, 2024

Walkthrough

The pull request modifies type definitions related to the Menu and menuItem components within the application. Specifically, it updates the MenuProps type to include all properties from the Props<T> interface without exclusions and alters the MenuItemVariantProps type to exclude specific properties. The implementation of the components remains unchanged, focusing solely on type structure adjustments.

Changes

File Path Change Summary
packages/components/menu/src/menu.tsx Updated MenuProps type to extend Props<T> directly, removing exclusions for certain properties.
packages/core/theme/src/components/menu.ts Modified MenuItemVariantProps type to exclude hasDescriptionTextChild and hasTitleTextChild.
.changeset/ninety-mails-yell.md Introduced a patch for dependencies and refined encapsulation of internal variable types for list items.
apps/docs/components/docs/components/code-demo/react-live-demo.tsx Changed files property type in ReactLiveDemoProps from string[] to SandpackFiles.
packages/components/listbox/src/use-listbox-item.ts Updated import to include MenuItemVariantProps and refined type casting in mapPropsVariants.
packages/components/menu/src/use-menu-item.ts Updated import to include MenuItemVariantProps and refined type casting in mapPropsVariants.

Possibly related PRs

Suggested labels

💥 Type: Breaking Change, 📋 Scope : Docs

Suggested reviewers

  • jrgarciadev
  • wingkwong

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9ed57fc and 3e8f7bf.

📒 Files selected for processing (3)
  • apps/docs/components/docs/components/code-demo/react-live-demo.tsx (2 hunks)
  • packages/components/listbox/src/use-listbox-item.ts (2 hunks)
  • packages/components/menu/src/use-menu-item.ts (2 hunks)
🔇 Additional comments (4)
apps/docs/components/docs/components/code-demo/react-live-demo.tsx (2)

16-16: LGTM: Type enhancement for files prop

The change from string[] to SandpackFiles provides better type safety and alignment with the Sandpack library's type system.


51-51: Verify type assertion safety

The type assertion to string might be unsafe if SandpackFiles can contain non-string values.

✅ Verification successful

Type assertion is safe in this context

The type assertion is safe because:

  1. files is explicitly typed as SandpackFiles from "@codesandbox/sandpack-react/types"
  2. The code is defensively checking for existence with optional chaining (files?.[DEFAULT_FILE])
  3. The CopyButton component expects a string value, and since this is being used in a code demo context where files contain source code, the content will always be a string
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check SandpackFiles type definition
rg -A 5 "export (type|interface) SandpackFiles" 

Length of output: 49


Script:

#!/bin/bash
# Try searching for SandpackFiles in node_modules
fd -g "*sandpack*.d.ts" -x cat {} \; | rg -A 5 "export (type|interface) SandpackFiles"

# Search for imports of SandpackFiles
rg "import.*SandpackFiles.*from"

# Search for the actual usage context
rg -B 5 -A 5 "value=\{files\?\.\[DEFAULT_FILE\] as string\}"

Length of output: 1720


Script:

#!/bin/bash
# Let's check the actual usage of files in the component and its type
rg -B 10 -A 10 "const.*files.*:" apps/docs/components/docs/components/code-demo/react-live-demo.tsx

# Also check if there are any type definitions in the local codebase
ast-grep --pattern 'type SandpackFiles = $_'

Length of output: 148


Script:

#!/bin/bash
# Let's examine the entire react-live-demo.tsx file to understand the context better
cat apps/docs/components/docs/components/code-demo/react-live-demo.tsx

# Also check how files are being used in other places
rg "files\?\.\[" --type typescript

Length of output: 2694

packages/components/listbox/src/use-listbox-item.ts (1)

4-4: LGTM: Enhanced type safety for variant props

The use of MenuItemVariantProps for variant keys typing ensures consistent prop handling between menu and listbox items.

Also applies to: 32-35

✅ Verification successful

LGTM: Consistent type usage between menu and listbox items

The usage of MenuItemVariantProps is correctly implemented in both components:

  • In use-menu-item.ts, it's used with menuItem.variantKeys
  • In use-listbox-item.ts, it's used with listboxItem.variantKeys
  • The core theme defines ListboxItemVariantProps as an alias of MenuItemVariantProps

This ensures type consistency and proper variant handling across both components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify MenuItemVariantProps usage consistency
ast-grep --pattern 'import { $$$, MenuItemVariantProps } from "@nextui-org/theme"'

Length of output: 321


Script:

#!/bin/bash
# Check how MenuItemVariantProps is used in both files
ast-grep --pattern 'MenuItemVariantProps'

Length of output: 525


Script:

#!/bin/bash
# Check how the variant props are used in the implementation
ast-grep --pattern 'mapPropsVariants<MenuItemVariantProps>'

Length of output: 61


Script:

#!/bin/bash
# Check the implementation details in both files
rg "mapPropsVariants" -A 3 packages/components/listbox/src/use-listbox-item.ts packages/components/menu/src/use-menu-item.ts

Length of output: 1358

packages/components/menu/src/use-menu-item.ts (1)

5-5: LGTM: Consistent type handling with listbox

The implementation mirrors the changes in use-listbox-item.ts, ensuring consistent typing of variant props across menu and listbox components.

Also applies to: 32-35

✅ Verification successful

Let me verify the consistency of variant props handling between menu and listbox components more thoroughly.


Verified: Consistent type handling between menu and listbox components

The implementation shows perfect alignment between menu and listbox components:

  • Both use MenuItemVariantProps from @nextui-org/theme
  • Both apply identical type casting pattern with variantKeys
  • The listbox component correctly reuses menu's type definitions as seen in the theme package
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify consistent usage of variant keys
rg -A 2 "menuItem.variantKeys|listboxItem.variantKeys"

Length of output: 488


Script:

#!/bin/bash
# Check the implementation of mapPropsVariants in both files
ast-grep --pattern 'const $_ = mapPropsVariants($_,$_)'

# Check the type imports and their usage
rg -A 2 "MenuItemVariantProps"

Length of output: 7937


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 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.

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
Copy Markdown
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

🧹 Outside diff range and nitpick comments (1)
packages/core/theme/src/components/menu.ts (1)

532-535: LGTM! Correctly prevents exposure of internal variant properties

The change appropriately excludes internal properties from the exported MenuItemVariantProps type while maintaining their internal usage for CSS class application.

Consider adding a JSDoc comment explaining why these properties are excluded from the exported type:

+/**
+ * MenuItemVariantProps excludes internal properties used for CSS class application
+ * to prevent their exposure in the public API.
+ */
export type MenuItemVariantProps = Omit<
  VariantProps<typeof menuItem>,
  "hasDescriptionTextChild" | "hasTitleTextChild"
>;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1c46061 and 200da2c.

📒 Files selected for processing (2)
  • packages/components/menu/src/menu.tsx (1 hunks)
  • packages/core/theme/src/components/menu.ts (1 hunks)
🔇 Additional comments (2)
packages/components/menu/src/menu.tsx (1)

77-77: Verify the impact of exposing internal properties

The removal of Omit utility exposes internal properties (hasChildItems, hasTitleTextChild, hasDescriptionTextChild) through the MenuProps type. This could lead to unintended usage of these internal properties by consumers.

Let's check for any existing usage of these properties:

packages/core/theme/src/components/menu.ts (1)

Line range hint 150-161: LGTM! Well-structured internal variant handling

The implementation correctly handles text truncation as an internal UI concern. The variant properties are well-typed and appropriately scoped.

@jrgarciadev
Copy link
Copy Markdown
Member

Hey @winchesHe I see no impactful changes here other than moving the types from one file to another, does this solve the mentioned issue?

@winchesHe
Copy link
Copy Markdown
Contributor Author

winchesHe commented Dec 1, 2024

Hey @winchesHe I see no impactful changes here other than moving the types from one file to another, does this solve the mentioned issue?

Yes, the original changes omit the internal types in the menu props, but it doesn't have, so i change it to the menuItem

@jrgarciadev jrgarciadev closed this Dec 1, 2024
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