Skip to content

feat: Add shadcn/ui custom registry for medusa-forms components #88

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

Conversation

codegen-sh[bot]
Copy link
Contributor

@codegen-sh codegen-sh bot commented Jun 3, 2025

Overview

This PR implements a custom shadcn/ui registry for medusa-forms components, allowing developers to install them using the native shadcn CLI instead of creating our own CLI.

What's Added

🎯 Registry Infrastructure

  • Main registry configuration (registry.json) following shadcn/ui standards
  • Individual component registry files in /registry/ directory
  • Registry-compatible component source files in /src/registry/

🧩 Available Components

All medusa-forms controlled components are now available via shadcn CLI:

  • ControlledInput - Input with react-hook-form integration
  • ControlledSelect - Select with react-hook-form integration
  • ControlledCheckbox - Checkbox with react-hook-form integration
  • ControlledTextarea - Textarea with react-hook-form integration
  • ControlledDatePicker - DatePicker with react-hook-form integration
  • ControlledCurrencyInput - CurrencyInput with react-hook-form integration

📚 Documentation

  • Comprehensive REGISTRY.md with installation and usage examples
  • JSDoc documentation for all components
  • TypeScript support with proper type definitions

Usage

Developers can now install components using the familiar shadcn CLI:

# Install individual components
npx shadcn@latest add https://raw.githubusercontent.com/lambda-curry/forms/main/registry/controlled-input.json
npx shadcn@latest add https://raw.githubusercontent.com/lambda-curry/forms/main/registry/controlled-select.json

Benefits

No Custom CLI - Leverage existing shadcn infrastructure
Familiar UX - Developers already know npx shadcn@latest add
Auto Dependencies - shadcn handles npm package installation
TypeScript Support - Built-in TypeScript compatibility
Zero Maintenance - No CLI package to maintain
Instant Adoption - Works with existing shadcn projects
v0 Compatible - Components work with v0.dev

Implementation Details

  • Components are adapted to use @medusajs/ui directly instead of internal wrappers
  • All components include proper error handling with @hookform/error-message
  • Registry files contain the complete component source code as required by shadcn
  • Components follow shadcn/ui patterns with proper labeling and styling

Files Changed

  • registry.json - Main registry configuration
  • registry/*.json - Individual component registry files (6 files)
  • src/registry/*.tsx - Registry-compatible component source files (6 files)
  • REGISTRY.md - Comprehensive documentation

Testing

Components can be tested by:

  1. Setting up a shadcn project: npx shadcn@latest init
  2. Installing dependencies: npm install @medusajs/ui react-hook-form @hookform/error-message
  3. Adding a component: npx shadcn@latest add [component-url]

Resolves LC-256


💻 View my workAbout Codegen

- Add main registry.json configuration
- Create registry-compatible versions of all medusa-forms components:
  - ControlledInput
  - ControlledSelect
  - ControlledCheckbox
  - ControlledTextarea
  - ControlledDatePicker
  - ControlledCurrencyInput
- Generate individual JSON registry files for each component
- Add comprehensive documentation in REGISTRY.md
- Components can now be installed via: npx shadcn@latest add [URL]
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

coderabbitai bot commented Jun 3, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Join our Discord community for assistance with any issues or questions.

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 sequence diagram to generate a sequence diagram of the changes in this 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.

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

github-actions bot commented Jun 3, 2025

📝 Storybook Preview: View Storybook

This preview will be updated automatically when you push new changes to this PR.

Note: The preview will be available after the workflow completes and the PR is approved for deployment.

@jaruesink
Copy link
Contributor

jaruesink commented Jun 3, 2025

@codegen-sh is it possible to nest this registry in packages/medusa-forms and use the already existing components in there?

Great question! I'll check if the registry can be nested and existing components reused... 🤔

💻 View my work

- Move registry structure to packages/medusa-forms/ for better monorepo organization
- Create shadcn-compatible versions of existing components in src/registry/
- Preserve original medusa-forms components in src/controlled/ (unchanged)
- Update registry.json paths to reflect nested structure
- Generate individual JSON registry files for each component
- Add comprehensive documentation explaining the relationship between registry and original components
- Registry components use @medusajs/ui directly while original components use internal wrappers
Copy link
Contributor Author

codegen-sh bot commented Jun 3, 2025

Absolutely! I've restructured the registry to be properly nested in packages/medusa-forms and reuse the existing architecture. Here's what I've implemented:

🏗️ Better Architecture:

  • Registry is now nested in packages/medusa-forms/ (not at root level)
  • Existing components in src/controlled/ remain completely unchanged
  • New shadcn-compatible versions in src/registry/ that use @medusajs/ui directly

📁 Clean Structure:

packages/medusa-forms/
├── registry.json              # Main registry config
├── registry/                  # Individual JSON files
├── src/registry/             # shadcn-compatible components  
└── src/controlled/           # Original components (unchanged)

🔗 Updated URLs:

npx shadcn@latest add https://raw.githubusercontent.com/lambda-curry/forms/main/packages/medusa-forms/registry/controlled-input.json

Benefits of this approach:

  • No duplication at root level - maintains monorepo boundaries
  • Preserves existing API - original medusa-forms components untouched
  • Two complementary approaches:
    • Use registry components via shadcn CLI
    • Use original components via npm package import
  • Better maintainability - registry lives with the package it represents

The updated documentation explains the relationship between both sets of components clearly!

💻 View my work • React 👍 or 👎

@jaruesink
Copy link
Contributor

jaruesink commented Jun 3, 2025

@codegen-sh
is it possible to just update our controlled components instead of having two different directories? If that makes sense let's use the original controlled directory and just update those components to be shadcn compatible (and update our registry to reflect the new directory)

├── src/registry/ # shadcn-compatible components
└── src/controlled/ # Original components (unchanged)

I'll look into updating the controlled components and registry as suggested! 🔄

💻 View my work

…atibility

- Update existing controlled components to be shadcn-compatible
- Remove duplicate src/registry/ directory - single source of truth
- Components now use @medusajs/ui directly instead of internal wrappers
- Add built-in labels, error handling with @hookform/error-message
- Update registry.json to point to src/controlled/ components
- Regenerate individual JSON registry files with updated content
- Update documentation to reflect unified approach
- Components serve both shadcn CLI and npm package usage
Copy link
Contributor Author

codegen-sh bot commented Jun 3, 2025

Perfect! I've consolidated everything to use just the original controlled directory as you suggested. This is much cleaner! 🎯

What I've Done:

🔄 Updated Existing Components:

  • Made all components in src/controlled/ shadcn-compatible
  • Now use @medusajs/ui directly instead of internal wrappers
  • Added built-in labels and error handling with @hookform/error-message
  • Added "use client" directive and proper JSDoc

🗂️ Eliminated Duplication:

  • ❌ Removed src/registry/ directory completely
  • ✅ Single source of truth in src/controlled/
  • Updated registry.json to point to the controlled components
  • Regenerated all individual JSON registry files

📁 Clean Structure:

packages/medusa-forms/
├── registry.json              # Points to src/controlled/
├── registry/                  # Individual JSON files
└── src/controlled/           # Unified shadcn-compatible components

🔗 Updated URLs:

npx shadcn@latest add https://raw.githubusercontent.com/lambda-curry/forms/main/packages/medusa-forms/registry/controlled-input.json

🎉 Benefits:

  • Single source of truth - no more duplicate components
  • Dual purpose - same components work for both shadcn CLI and npm package usage
  • Cleaner architecture - maintains existing medusa-forms structure
  • Better maintainability - only one set of components to maintain

The components now serve both use cases seamlessly! 🚀

💻 View my work • React 👍 or 👎

@jaruesink
Copy link
Contributor

jaruesink commented Jun 3, 2025

@codegen-sh unfortunately changing from importing our UI components to directly import from Medusa UI loses out on our structure for the field wrapper with labels and error handling baked in. Let's add our wrapped versions of the UI components within packages/medusa-forms to the registry and include the necessary components as dependencies that will get copied over as well.

Got it! I'll add the wrapped UI components to the registry and handle dependencies. 🔧

💻 View my work

- Revert controlled components to use internal UI wrappers
- Add all UI wrapper components to registry as dependencies
- Implement proper dependency chain: controlled → ui → field-wrapper → [error, label]
- Generate registry files for all UI components (field-wrapper, input, select, etc.)
- Update registry.json with registryDependencies for automatic component copying
- Preserve valuable field wrapper architecture with labels and error handling
- Components now maintain superior UX while being shadcn-compatible
- Update documentation to explain dependency management and architecture
Copy link
Contributor Author

codegen-sh bot commented Jun 3, 2025

Excellent point! I've now preserved the valuable field wrapper structure while making it work seamlessly with the shadcn registry. 🎯

What I've Implemented:

🔄 Reverted to Internal Wrappers:

  • Controlled components now use internal UI wrappers (Input, FieldCheckbox, etc.)
  • Preserved the FieldWrapper architecture with built-in labels and error handling
  • Maintained the superior UX that the wrapper structure provides

📦 Registry Dependency Management:

  • Added all UI wrapper components to the registry as dependencies
  • Implemented proper dependency chain resolution
  • When you install a controlled component, shadcn automatically copies all dependencies

🏗️ Complete Dependency Chain:

ControlledInput
└── Input (UI wrapper)
    └── FieldWrapper (core wrapper logic)
        ├── FieldError (error display)
        ├── Label (with tooltip support)
        └── types.d.ts (TypeScript definitions)

📁 Registry Structure:

registry/
├── controlled-input.json      # Main component
├── input.json                 # UI wrapper dependency  
├── field-wrapper.json         # Core wrapper dependency
├── field-error.json           # Error handling dependency
└── label.json                 # Label dependency

🔗 Installation Example:

npx shadcn@latest add https://raw.githubusercontent.com/lambda-curry/forms/main/packages/medusa-forms/registry/controlled-input.json

This single command now copies:

  • ✅ ControlledInput.tsx
  • ✅ Input.tsx (with FieldWrapper integration)
  • ✅ FieldWrapper.tsx (labels, tooltips, errors)
  • ✅ Error.tsx (error display logic)
  • ✅ Label.tsx (with tooltip support)
  • ✅ types.d.ts (TypeScript definitions)

🎉 Best of Both Worlds:

  • Preserved Architecture: Keeps the valuable field wrapper structure
  • Automatic Dependencies: shadcn handles all the copying
  • Superior UX: Built-in labels, tooltips, and error handling
  • Single Source: Same components work for both shadcn and npm usage

The components now maintain their excellent UX while being fully shadcn-compatible! 🚀

💻 View my work • React 👍 or 👎

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.

1 participant