Skip to content

Conversation

@GoldGroove06
Copy link
Contributor

@GoldGroove06 GoldGroove06 commented Jan 27, 2025

js to tsx stories

Summary by CodeRabbit

  • Chores

    • Updated Storybook story files for various UI components
    • Improved type annotations and import statements
    • Simplified render function signatures in component stories
  • Documentation

    • Enhanced type safety for component stories
    • Streamlined component story definitions

Note: These changes are primarily internal improvements to the development process and do not directly impact end-user functionality.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2025

Walkthrough

The pull request involves updates to several Storybook story files across different UI components. The changes primarily focus on improving type annotations, adding React imports, and simplifying render function signatures. Modifications are consistent across Callout, Card, Code, Disclosure, and Dropdown story files, suggesting a systematic approach to standardizing component story definitions.

Changes

File Change Summary
src/components/ui/*/stories/*.stories.tsx - Added React import
- Updated render function signatures
- Enhanced type annotations for args
Callout.stories.tsx - Simplified render method
- Updated template function types to any
Card.stories.tsx - Removed args from render and template functions
- Commented out Avatar size prop
Code.stories.tsx - Added CodeProps import
- Updated className definitions
- Specified args type with React.JSX.IntrinsicAttributes & CodeProps
Disclosure.stories.tsx - Added DisclosureProps import
- Updated render function type annotation
Dropdown.stories.tsx - Simplified render function to remove args parameter

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • kotAPI

Poem

🐰 A Rabbit's Tale of Code Refinement

With types so sharp and imports so neat,
Our stories now dance to a cleaner beat
React imports hop, signatures gleam
Storybook stories join the type-safe dream!

Hop hop hooray! 🎉


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 (10)
src/components/ui/Code/stories/Code.stories.tsx (2)

Line range hint 11-24: Consider improving component composition.

The render function has duplicate Code components with similar props. Consider extracting the common structure to reduce duplication.

 render: (args: React.JSX.IntrinsicAttributes & CodeProps) => <SandboxEditor>
     <div>
         <div className='flex space-x-2'>
-            <Code  {...args}>
-                requestAnimationFrame()
-            </Code>
-            <Code {...args}>
-                {Code_TEXT}
-            </Code>
+            {[
+                'requestAnimationFrame()',
+                Code_TEXT
+            ].map((text, index) => (
+                <Code key={index} {...args}>{text}</Code>
+            ))}
         </div>
     </div>
 </SandboxEditor>

31-31: Standardize className formatting.

The className prop has inconsistent spacing in different stories.

-        className :'space-x-1'
+        className: 'space-x-1'
-        className:'space-x-1',
+        className: 'space-x-1',

Also applies to: 37-37

src/components/ui/Card/stories/Card.stories.tsx (2)

12-12: Remove commented code about Avatar size prop.

Instead of keeping commented code, document the Avatar component's limitations in the component's documentation or remove the comment if it's no longer relevant.

-                // size='lg' avatar doesn't have size prop

Line range hint 34-39: Consider using Array.from for better readability.

The Template function uses Array(10).fill(0) which is less idiomatic than Array.from.

 const Template = () => <div>
     <SandboxEditor className="gap-3 grid grid-cols-4">
-        {Array(10).fill(0).map((_, i) => <CardStory key={i}/>)}
+        {Array.from({ length: 10 }, (_, i) => <CardStory key={i}/>)}
     </SandboxEditor>
 </div>;
src/components/ui/Disclosure/stories/Disclosure.stories.tsx (2)

1-4: Consolidate React imports.

The React and JSX imports can be combined into a single import statement.

-import { JSX } from 'react';
-import Disclosure, { DisclosureProps } from '../Disclosure'
+import React, { JSX } from 'react';
+import Disclosure, { DisclosureProps } from '../Disclosure';
 import SandboxEditor from '~/components/tools/SandboxEditor/SandboxEditor';
-import React from 'react';

Line range hint 36-44: Add type definition for disclosureItems.

Consider adding a type definition for the disclosureItems array to improve type safety.

+interface DisclosureItem {
+    title: string;
+    content: string;
+}
+
-const disclosureItems = [
+const disclosureItems: DisclosureItem[] = [
     {
       title: 'Section 1',
       content: 'Content for section 1'
     },
     {
       title: 'Section 2',
       content: 'Content for section 2'
     }, 
]
src/components/ui/Dropdown/stories/Dropdown.stories.tsx (2)

11-12: Replace inline styles with CSS classes.

Consider moving inline styles to CSS classes for better maintainability.

-        <div className=' bg-gray-400 p-4 overflow-auto' style={{ height: '200px' }}>
-            <div className='block' style={{ height: '400px' }}>
+        <div className='bg-gray-400 p-4 overflow-auto h-[200px]'>
+            <div className='block h-[400px]'>

Line range hint 18-35: Extract long text content to constants.

The dropdown content contains repeated text that should be extracted to a constant for better maintainability.

+const LONG_TEXT = 'Hello this is a dropdown. '.repeat(5);
+
 <Dropdown
     onSelect={() => {}} label={'Bello'} list={[
         {
-            value: `hello Hello this is a dropdown. Hello this is a dropdown. 
-                Hello this is a dropdown. Hello`,
+            value: LONG_TEXT,
             label: 'hello'
         }
     ]}>
     <div>
-        Hello this is a dropdown. Hello this is a dropdown. Hello this is a dropdown. Hello this is a
-        dropdown. Hello this is a dropdown. Hello this is a dropdown. Hello this is a dropdown. Hello
-        this is a dropdown. Hello this is a dropdown. Hello this is a dropdown. Hello this is a
-        dropdown. Hello this is a dropdown. Hello this is a dropdown. Hello this is a dropdown. Hello
+        {LONG_TEXT}
     </div>
 </Dropdown>
src/components/ui/Callout/stories/Callout.stories.tsx (2)

Line range hint 14-27: Consider adding proper type annotations to the render function.

While removing unused args parameter simplifies the code, we should maintain type safety by properly typing the render function.

-    render: () => <>
+    render: React.FC = () => <>

Line range hint 1-54: Consider a more thorough TypeScript migration approach.

While the file has been successfully converted to TSX, the migration could be more thorough:

  1. Story metadata could be typed using Meta and StoryObj from @storybook/react
  2. Template functions could use proper component prop types
  3. Story arguments could be properly typed

This would provide better type safety and improved developer experience.

Example structure:

import type { Meta, StoryObj } from '@storybook/react';

const meta: Meta<typeof Callout> = {
  title: 'Components/Callout',
  component: Callout,
  // ... other metadata
};

export default meta;
type Story = StoryObj<typeof Callout>;

export const All: Story = {
  args: {
    className: ''
  }
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dd1a65c and c9f932d.

📒 Files selected for processing (5)
  • src/components/ui/Callout/stories/Callout.stories.tsx (4 hunks)
  • src/components/ui/Card/stories/Card.stories.tsx (2 hunks)
  • src/components/ui/Code/stories/Code.stories.tsx (3 hunks)
  • src/components/ui/Disclosure/stories/Disclosure.stories.tsx (1 hunks)
  • src/components/ui/Dropdown/stories/Dropdown.stories.tsx (1 hunks)
🔇 Additional comments (3)
src/components/ui/Code/stories/Code.stories.tsx (1)

1-2: LGTM! Good TypeScript migration.

The addition of React import and CodeProps type improves type safety.

src/components/ui/Callout/stories/Callout.stories.tsx (2)

4-4: LGTM! Required React import added.

The React import is necessary for TSX files and is correctly placed.


Line range hint 38-44: Replace any type with proper Callout component props type.

Using any type defeats the purpose of TypeScript migration. We should use the proper props type from the Callout component.

Let's verify the available types:

Apply this improvement:

-const DefaultTextTemplate = (args: any) => {
+const DefaultTextTemplate = (args: React.ComponentProps<typeof Callout>) => {

-const RedTextTemplate = (args: any) => {
+const RedTextTemplate = (args: React.ComponentProps<typeof Callout>) => {

Also applies to: 48-54

✅ Verification successful

The review comment's suggestion is correct and provides a better solution

Using React.ComponentProps<typeof Callout> is indeed better than any as it:

  • Provides proper type safety
  • Automatically stays in sync with component changes
  • Eliminates the need for explicit type imports
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if Callout component exports its props type
ast-grep --pattern 'export (type|interface) CalloutProps'

# Alternative pattern to find props definition
ast-grep --pattern 'interface CalloutProps'

Length of output: 105


Script:

#!/bin/bash
# Find and show Callout component implementation
ast-grep --pattern 'const Callout = $_' -A 10

# Look for any type definitions in files containing Callout
rg "type\s+\w+Props|interface\s+\w+Props" --type ts --type tsx -C 2

Length of output: 976


Script:

#!/bin/bash
# Check Callout.tsx file for type definitions
cat src/components/ui/Callout/Callout.tsx

# Fixed ripgrep command for TypeScript/TSX files
rg "type\s+\w+Props|interface\s+\w+Props" -t typescript -t tsx -C 2

Length of output: 847

@kotAPI kotAPI added the automerge A tag that tells kodiak bot to automerge PRs for us when tests and approval conditions are met label Jan 27, 2025
@kodiakhq kodiakhq bot merged commit 7104800 into rad-ui:main Jan 27, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge A tag that tells kodiak bot to automerge PRs for us when tests and approval conditions are met

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants