-
-
Notifications
You must be signed in to change notification settings - Fork 45
Menu Component #31
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
Menu Component #31
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThe pull request includes multiple updates across various files. Key changes involve updating Docker image versions, modifying component structures, and introducing new components like Changes
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
🧹 Outside diff range and nitpick comments (10)
content/docs/components/menu.mdx (4)
1-8: Update the metadata section for better maintainability.
- The
lastUpdateddate is set to a future date (19 Oct, 2024), which could be confusing for users.- Consider using a relative path or version tag in the source code link instead of referencing the main branch directly, as branch names can change.
Apply this diff:
-lastUpdated: 19 Oct, 2024 +lastUpdated: <current_date> - source: https://github.com/Logging-Stuff/RetroUI/blob/main/packages/ui/Menu/Menu.tsx + source: https://github.com/Logging-Stuff/RetroUI/tree/HEAD/packages/ui/Menu/Menu.tsx
10-13: Remove duplicate showcase and improve spacing.
- The component showcase appears twice (here and in the Examples section).
- Using multiple
<br />tags for spacing is not recommended. Consider using CSS margins or a spacing component instead.Remove the duplicate showcase and replace breaks with proper spacing:
-<ComponentShowcase name="menu-style-default" /> -<br /> -<br /> +<div className="mb-8"> + {/* Showcase will appear in Examples section */} +</div>
16-20: Enhance installation instructions.
- Include package manager alternatives (yarn, pnpm).
- Specify the recommended version of
@radix-ui/react-dropdown-menuto ensure compatibility.Update the installation section:
#### 1. Install dependencies: ```sh -npm install @radix-ui/react-dropdown-menu +npm install @radix-ui/react-dropdown-menu@^1.0.0 + +# or +yarn add @radix-ui/react-dropdown-menu@^1.0.0 + +# or +pnpm add @radix-ui/react-dropdown-menu@^1.0.0--- `24-26`: **Improve code copy section clarity.** Add more context about what the code contains and any prerequisites or configuration needed. Update the section: ```diff -#### 2. Copy the code 👇 into your project: +#### 2. Add the Menu component to your project: + +The following code includes the Menu component with its TypeScript types and styling. Make sure you have `tailwindcss` configured in your project. <ComponentSource name="menu" />packages/ui/Menu/Menu.tsx (3)
1-9: LGTM! Consider importing additional React types.The setup looks good with proper client-side directive and necessary imports. Consider importing
ComponentPropsWithoutReffrom React as it might be useful for proper typing of the component props.-import React, { HTMLAttributes } from "react"; +import React, { HTMLAttributes, ComponentPropsWithoutRef } from "react";
14-26: Improve component flexibility and styling consistency.The Content implementation has several areas for improvement:
- Hardcoded positioning values limit reusability
- Shadow and border styling could be more consistent with design system
const Content = ({ className, ...props }: IMenuContent) => ( <DropdownMenu.Portal> <DropdownMenu.Content - side="bottom" - align="start" + side={props.side || "bottom"} + align={props.align || "start"} className={cn( - "bg-white border-2 border-black shadow-md absolute top-2 min-w-20", + "bg-white border border-gray-200 shadow-lg rounded-md min-w-[180px] animate-in fade-in-80 data-[side=bottom]:slide-in-from-top-1 data-[side=top]:slide-in-from-bottom-1", className )} {...props} /> </DropdownMenu.Portal> );
35-41: Enhance component composition with proper TypeScript support.While the composition pattern is good, it could benefit from proper TypeScript namespace declaration and display names.
+export interface MenuComponentType { + Root: typeof Menu; + Trigger: typeof Trigger; + Content: typeof Content; + Item: typeof MenuItem; +} const MenuComponent = Object.assign(Menu, { Trigger, Content, Item: MenuItem, -}); +}) as MenuComponentType; +MenuComponent.displayName = "Menu"; export { MenuComponent as Menu };.github/workflows/deploy.yml (2)
27-27: Optimize Docker build configuration.Consider adding platform specification and utilizing build cache for faster builds.
- docker build -t devarifhossain/retroui:1.0.8 ./ + docker build --platform linux/amd64 \ + --cache-from devarifhossain/retroui:latest \ + --build-arg BUILDKIT_INLINE_CACHE=1 \ + -t devarifhossain/retroui:1.0.8 ./
Line range hint
41-42: Add deployment safety measures.The current deployment strategy lacks health checks and rollback capabilities. Consider adding these safety measures to prevent failed deployments from affecting production.
Consider:
- Adding container health checks
- Implementing a rolling update strategy
- Adding automated rollback on deployment failure
- Including smoke tests post-deployment
Would you like me to provide an example implementation of these safety measures?
🧰 Tools
🪛 yamllint
[error] 29-29: trailing spaces
(trailing-spaces)
app/(sink)/demo/components/page.tsx (1)
117-117: Replace empty spacing div with proper marginUsing empty divs for spacing is not recommended. Consider using margin on the parent container or proper layout components instead.
- <div className="h-36"></div> + <div className="container max-w-6xl mx-auto space-y-6 mb-36">
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (15)
.github/workflows/deploy.yml(1 hunks)app/(marketing)/page.tsx(3 hunks)app/(sink)/demo/components/page.tsx(2 hunks)config/components.ts(2 hunks)config/navigation.ts(1 hunks)content/docs/components/menu.mdx(1 hunks)infra/docker-compose.prod.yml(1 hunks)package.json(1 hunks)packages/ui/Buttons/Button.tsx(2 hunks)packages/ui/Cards/Card.tsx(0 hunks)packages/ui/Menu/Menu.tsx(1 hunks)packages/ui/Menu/index.ts(1 hunks)packages/ui/index.ts(1 hunks)preview/components/avatar-style-circle-sizes.tsx(1 hunks)preview/components/menu-style-default.tsx(1 hunks)
💤 Files with no reviewable changes (1)
- packages/ui/Cards/Card.tsx
✅ Files skipped from review due to trivial changes (4)
- infra/docker-compose.prod.yml
- packages/ui/Menu/index.ts
- preview/components/avatar-style-circle-sizes.tsx
- preview/components/menu-style-default.tsx
🔇 Additional comments (10)
packages/ui/index.ts (1)
11-11: LGTM! Verify Menu directory structure.
The export follows the established pattern for component exports.
Let's verify the Menu directory structure:
✅ Verification successful
Menu component structure follows the established pattern ✅
The verification confirms that the Menu component follows the same directory structure pattern as other components:
- Has a dedicated directory:
packages/ui/Menu/ - Contains component file:
Menu.tsx - Includes barrel file:
index.ts
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify Menu component directory structure matches other components
# Test 1: Check if Menu directory exists and contains expected files
fd -t d '^Menu$' packages/ui
fd -t f '^Menu\.(tsx|ts)$|^index\.ts$' packages/ui/Menu
# Test 2: Compare with structure of other components (e.g., Buttons)
echo "Comparing with Buttons component structure:"
fd . packages/ui/Buttons -t f
Length of output: 383
package.json (1)
16-16: LGTM! The Radix UI dropdown menu dependency is properly specified.
The addition aligns well with the existing Radix UI component usage in the project.
Let's verify there are no existing menu implementations to avoid duplication:
✅ Verification successful
The Radix UI dropdown menu dependency is correctly added and properly utilized
The codebase shows a well-structured implementation of the Menu component in packages/ui/Menu/Menu.tsx that already uses @radix-ui/react-dropdown-menu. The other menu-related files (HamburgerMenu.tsx and menu-style-default.tsx) either use this new Menu component or implement different functionality (hamburger menu for navigation). There's no duplication of menu implementations.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for existing menu-related components or implementations
rg -i "menu" --type ts --type tsx
Length of output: 61
Script:
#!/bin/bash
# Search for existing menu-related components or implementations
# Using more generic file extensions and multiple searches
rg -i "menu" --type typescript --type javascript
# Also search for specific file names that might contain menu implementations
fd -e ts -e tsx -e js -e jsx -i "menu"
Length of output: 219
Script:
#!/bin/bash
# Check the content of existing menu-related files to understand their implementation
cat components/HamburgerMenu.tsx packages/ui/Menu/Menu.tsx preview/components/menu-style-default.tsx
# Also check for any Radix UI menu imports in these files
rg "@radix-ui/react-dropdown-menu" components/HamburgerMenu.tsx packages/ui/Menu/Menu.tsx preview/components/menu-style-default.tsx
Length of output: 2541
packages/ui/Buttons/Button.tsx (1)
42-42: LGTM! Clean ref forwarding implementation.
The ref forwarding implementation follows React's best practices and enhances the component's reusability, particularly useful for the Menu component integration.
config/navigation.ts (1)
25-25: LGTM! Verify documentation files exist.
The navigation entries for Dialog and Menu components are properly added and maintain alphabetical ordering.
Let's verify that the documentation files exist:
Also applies to: 27-27
✅ Verification successful
Navigation entries correctly configured with existing documentation files ✅
Both documentation files exist at the expected locations:
- content/docs/components/dialog.mdx
- content/docs/components/menu.mdx
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if the documentation files exist for the new navigation entries
# Test: Verify menu documentation exists
fd --type f "menu.mdx$" content/docs/components/
# Test: Verify dialog documentation exists (since it was reorganized)
fd --type f "dialog.mdx$" content/docs/components/
Length of output: 171
app/(sink)/demo/components/page.tsx (1)
9-9: LGTM: Import follows existing patterns
The Menu import is correctly grouped with other UI components.
app/(marketing)/page.tsx (4)
11-11: LGTM! Import change aligns with component renaming.
The import statement correctly reflects the component renaming from Avatar to AvatarStyleCircleSizes.
68-74: LGTM! Button section layout improvements.
The changes enhance the component showcase by:
- Using a more balanced 2-column grid layout
- Properly spacing buttons with flex container
- Demonstrating both default and outline variants side by side
84-85: LGTM! Avatar component update is consistent.
The Avatar section correctly implements the renamed component.
86-88: LGTM! BasicCard section maintains consistent structure.
The new BasicCard section follows the established pattern of component showcases with proper spacing and heading style.
config/components.ts (1)
34-41: LGTM! Component configuration follows established patterns.
The menu component addition and text component reordering maintain consistent structure and naming conventions.
| ## Examples | ||
|
|
||
| ### Default | ||
|
|
||
| <ComponentShowcase name="menu-style-default" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance the examples section.
Consider adding:
- Description of what the default example demonstrates
- More examples showing different use cases (e.g., nested menus, custom triggers, keyboard navigation)
- Code snippets showing how to implement each example
Would you like me to help generate additional example code and documentation for common use cases?
packages/ui/Menu/Menu.tsx
Outdated
| interface IMenuContent extends HTMLAttributes<HTMLDivElement> { | ||
| children: React.ReactNode; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Strengthen type safety with Radix UI props.
The interface should include Radix UI's DropdownMenu.Content specific props for better type safety and developer experience.
-interface IMenuContent extends HTMLAttributes<HTMLDivElement> {
+interface IMenuContent extends ComponentPropsWithoutRef<typeof DropdownMenu.Content> {
children: React.ReactNode;
+ side?: "top" | "right" | "bottom" | "left";
+ align?: "start" | "center" | "end";
}Committable suggestion skipped: line range outside the PR's diff.
packages/ui/Menu/Menu.tsx
Outdated
| const MenuItem = (props: any) => ( | ||
| <DropdownMenu.Item | ||
| className="p-2 hover:bg-primary-400 outline-none cursor-pointer " | ||
| {...props} | ||
| /> | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Fix type safety and enhance accessibility.
The MenuItem implementation has several critical issues:
- Uses
anytype which bypasses type safety - Missing proper accessibility attributes
- Basic styling could be enhanced
-const MenuItem = (props: any) => (
+const MenuItem = React.forwardRef<
+ HTMLDivElement,
+ ComponentPropsWithoutRef<typeof DropdownMenu.Item>
+>(({ className, ...props }, ref) => (
<DropdownMenu.Item
- className="p-2 hover:bg-primary-400 outline-none cursor-pointer "
+ ref={ref}
+ className={cn(
+ "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-primary-400 hover:text-white focus:bg-primary-400 focus:text-white data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
+ className
+ )}
{...props}
/>
-);
+));
+MenuItem.displayName = "MenuItem";📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const MenuItem = (props: any) => ( | |
| <DropdownMenu.Item | |
| className="p-2 hover:bg-primary-400 outline-none cursor-pointer " | |
| {...props} | |
| /> | |
| ); | |
| const MenuItem = React.forwardRef< | |
| HTMLDivElement, | |
| ComponentPropsWithoutRef<typeof DropdownMenu.Item> | |
| >(({ className, ...props }, ref) => ( | |
| <DropdownMenu.Item | |
| ref={ref} | |
| className={cn( | |
| "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-primary-400 hover:text-white focus:bg-primary-400 focus:text-white data-[disabled]:pointer-events-none data-[disabled]:opacity-50", | |
| className | |
| )} | |
| {...props} | |
| /> | |
| )); | |
| MenuItem.displayName = "MenuItem"; |
| docker build -t devarifhossain/retroui:1.0.8 ./ | ||
| docker push devarifhossain/retroui:1.0.8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider automating version management.
Instead of hardcoding the version, consider deriving it from the GitHub release tag to prevent version mismatches and reduce manual updates.
- docker build -t devarifhossain/retroui:1.0.8 ./
- docker push devarifhossain/retroui:1.0.8
+ VERSION=${GITHUB_REF#refs/tags/v}
+ docker build -t devarifhossain/retroui:$VERSION ./
+ docker push devarifhossain/retroui:$VERSION
+ docker tag devarifhossain/retroui:$VERSION devarifhossain/retroui:latest
+ docker push devarifhossain/retroui:latest📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| docker build -t devarifhossain/retroui:1.0.8 ./ | |
| docker push devarifhossain/retroui:1.0.8 | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| docker build -t devarifhossain/retroui:$VERSION ./ | |
| docker push devarifhossain/retroui:$VERSION | |
| docker tag devarifhossain/retroui:$VERSION devarifhossain/retroui:latest | |
| docker push devarifhossain/retroui:latest |
| import React, { ButtonHTMLAttributes } from "react"; | ||
|
|
||
| const buttonVariants = cva("font-head transition-all", { | ||
| const buttonVariants = cva("font-head transition-all outline-none", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Ensure focus visibility for accessibility.
While removing the default outline, make sure to maintain a visible focus indicator for keyboard navigation. Consider adding a custom focus style using :focus-visible for better accessibility.
-const buttonVariants = cva("font-head transition-all outline-none", {
+const buttonVariants = cva("font-head transition-all outline-none focus-visible:ring-2 focus-visible:ring-primary-400 focus-visible:ring-offset-2", {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const buttonVariants = cva("font-head transition-all outline-none", { | |
| const buttonVariants = cva("font-head transition-all outline-none focus-visible:ring-2 focus-visible:ring-primary-400 focus-visible:ring-offset-2", { |
| <div> | ||
| <Menu> | ||
| <Menu.Trigger asChild> | ||
| <Button>Menu</Button> | ||
| </Menu.Trigger> | ||
| <Menu.Content className="min-w-36"> | ||
| <Menu.Item>Menu Item 1</Menu.Item> | ||
| <Menu.Item>Menu Item 2</Menu.Item> | ||
| <Menu.Item>Menu Item 3</Menu.Item> | ||
| </Menu.Content> | ||
| </Menu> | ||
| </div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance Menu accessibility and user experience
While the basic implementation works, consider these improvements:
- Add an aria-label to the Menu button
- Include visual indicators for keyboard navigation
- Add descriptions to menu items for better context
- Consider adding error boundaries
Here's a suggested implementation:
<Menu>
<Menu.Trigger asChild>
- <Button>Menu</Button>
+ <Button aria-label="Open menu options">Menu</Button>
</Menu.Trigger>
- <Menu.Content className="min-w-36">
+ <Menu.Content className="min-w-36" aria-label="Menu options">
- <Menu.Item>Menu Item 1</Menu.Item>
- <Menu.Item>Menu Item 2</Menu.Item>
- <Menu.Item>Menu Item 3</Menu.Item>
+ <Menu.Item>
+ <span className="font-medium">Menu Item 1</span>
+ <span className="text-sm text-gray-500 ml-2">Description</span>
+ </Menu.Item>
+ <Menu.Item>
+ <span className="font-medium">Menu Item 2</span>
+ <span className="text-sm text-gray-500 ml-2">Description</span>
+ </Menu.Item>
+ <Menu.Item>
+ <span className="font-medium">Menu Item 3</span>
+ <span className="text-sm text-gray-500 ml-2">Description</span>
+ </Menu.Item>
</Menu.Content>
</Menu>📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| <div> | |
| <Menu> | |
| <Menu.Trigger asChild> | |
| <Button>Menu</Button> | |
| </Menu.Trigger> | |
| <Menu.Content className="min-w-36"> | |
| <Menu.Item>Menu Item 1</Menu.Item> | |
| <Menu.Item>Menu Item 2</Menu.Item> | |
| <Menu.Item>Menu Item 3</Menu.Item> | |
| </Menu.Content> | |
| </Menu> | |
| </div> | |
| <div> | |
| <Menu> | |
| <Menu.Trigger asChild> | |
| <Button aria-label="Open menu options">Menu</Button> | |
| </Menu.Trigger> | |
| <Menu.Content className="min-w-36" aria-label="Menu options"> | |
| <Menu.Item> | |
| <span className="font-medium">Menu Item 1</span> | |
| <span className="text-sm text-gray-500 ml-2">Description</span> | |
| </Menu.Item> | |
| <Menu.Item> | |
| <span className="font-medium">Menu Item 2</span> | |
| <span className="text-sm text-gray-500 ml-2">Description</span> | |
| </Menu.Item> | |
| <Menu.Item> | |
| <span className="font-medium">Menu Item 3</span> | |
| <span className="text-sm text-gray-500 ml-2">Description</span> | |
| </Menu.Item> | |
| </Menu.Content> | |
| </Menu> | |
| </div> |
| "menu-style-default": { | ||
| name: "menu-style-default", | ||
| filePath: "preview/components/menu-style-default.tsx", | ||
| preview: lazy(() => import("@/preview/components/menu-style-default")), | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Found several name-path mismatches in component examples
Several components have inconsistent name properties that don't match their file paths:
avatar-style-fallbackspoints toavatar-style-circle-fallbacks.tsxbadge-style-defaultis duplicated and points tobadge-style-rounded.tsxbutton-style-defaultis duplicated and points tobutton-style-outline.tsxtypography-ppoints totab-style-default.tsx
These mismatches could cause confusion and should be corrected to maintain consistency throughout the codebase.
🔗 Analysis chain
LGTM! New menu example follows the established pattern.
The configuration is correctly structured with proper lazy loading implementation.
I noticed some examples might have incorrect name properties. Let's verify:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for mismatches between example names and their file paths
# Extract examples with potential name mismatches
rg -A 2 'name: ".+?".*\n.*filePath: "preview/components/(.+?)\.tsx"' | \
grep -E 'name:|filePath:' | \
awk '{
if($1=="name:") name=substr($2,2,length($2)-3);
if($1=="filePath:") {
split($2,path,"/");
file=substr(path[3],1,length(path[3])-5);
if(name!=file) printf "Mismatch - Name: %s, File: %s\n",name,file;
}
}'
Length of output: 539
Script:
#!/bin/bash
# Let's try a different approach using ripgrep's multiline mode
rg -U --multiline '^.*"name": "([^"]+)".*\n.*"filePath": "preview/components/([^"]+)\.tsx"' config/components.ts | \
while IFS= read -r line; do
name=$(echo "$line" | grep -o '"name": "[^"]*"' | cut -d'"' -f4)
file=$(echo "$line" | grep -o '"filePath": "[^"]*"' | cut -d'"' -f4 | awk -F'/' '{print $NF}' | sed 's/\.tsx$//')
if [ "$name" != "$file" ]; then
echo "Mismatch - Name: $name, File: $file"
fi
done
Length of output: 136
Script:
#!/bin/bash
# Let's simplify and try a different approach
rg -A1 'name:' config/components.ts | \
grep -E '(name:|filePath:)' | \
sed 's/[",]//g' | \
sed 's/^ *//'
Length of output: 2736
Summary by CodeRabbit
Release Notes
New Features
Menucomponent with a trigger button and three selectable items.MenuDefaultcomponent demonstrating theMenufunctionality.Homecomponent layout for improved spacing and added a new button variant.Documentation
Menucomponent, including installation instructions and examples.Bug Fixes
Chores