Quick Overview
Creating a new component involves these main steps:- Create main component in
src/lib/components/magic-ui/ - Create route in
src/routes/magic/docs/components/ - Add component to
registry.json - Build registry with
pnpm registry:build - Test component installation
- Submit a pull request
Follow each step carefully to ensure your component integrates properly with the project.
Component Creation Workflow
Create Main Component
Create your component folder inside Example component structure:
src/lib/components/magic-ui/.Folder Structure
Use TypeScript for type safety and better developer experience.
Create Documentation Route
Build Registry
Run the registry build command to generate installation files:This generates JSON files in
static/r/ for each component, enabling CLI installation.Always rebuild the registry after making changes to ensure the installation files are up to date.
Test Component Installation
Test that your component can be installed correctly using the CLI.
Start the Development Server
Test Installation in a Sample Project
In a separate test Svelte project with shadcn-svelte installed:Verification Checklist
- Component files are copied to the correct location
- Dependencies are added to
package.json - CSS variables and keyframes are added (if any)
- Component renders and works as expected
- No console errors or warnings
Testing installation in a fresh project helps catch issues before submitting your PR.
Submit Pull Request
Once everything is working, create a pull request.
Create and Push Your Branch
PR Submission Checklist
Before submitting, verify:- Component created in
src/lib/components/magic-ui/ - Route created in
src/routes/magic/docs/components/ +page.sveltewith proper SEO metadatallms.txt/+server.tsservingdocs.mddocs.mdwith AI-readable documentationexamples/folder withpreview.svelteand variantsdata.tswith proper types, code, SEO, and examples- Component added to
registry.json - Registry built successfully (
pnpm registry:build) - Component tested via CLI installation
- Code follows project style guidelines
- All files use TypeScript
A complete PR checklist helps ensure your contribution can be reviewed and merged quickly.
Best Practices
Naming Conventions
Naming Conventions
- Use kebab-case for folder and file names
- Use PascalCase for component names in code
- Use kebab-case for component IDs in registry.json
- Folder:
text-shimmer/ - File:
text-shimmer.svelte - Component:
<TextShimmer> - Registry ID:
"text-shimmer"
Props and Types
Props and Types
- Document all props with TypeScript types
- Provide sensible default values
- Make props optional where appropriate
- Export types for consumer use
Examples and Variants
Examples and Variants
- Create at least one
preview.svelteshowing basic usage - Add variant examples for different configurations
- Show real-world use cases
- Keep examples simple and focused
Dependencies
Dependencies
- Only include necessary npm packages
- Use
motion-svfor animations when possible - Document any peer dependencies
- Keep the dependency list minimal
CSS and Styling
CSS and Styling
- Use Tailwind classes when possible
- Use
cssVarsfor animation timing values - Use
cssobject for @keyframes definitions - Avoid inline styles unless necessary
Testing Before PR
Testing Before PR
Always test installation in a fresh project:
- Create a new SvelteKit project
- Install shadcn-svelte
- Add your component via CLI
- Verify all files are copied
- Test the component works
- Check for errors in console
Common Issues
Registry Build Fails
Ifpnpm registry:build fails:
- Check
registry.jsonsyntax is valid JSON - Verify all file paths in
registry.jsonexist - Ensure component files have no syntax errors
- Check that all dependencies are installed
Installation Doesn’t Copy Files
If CLI installation doesn’t work:- Verify the registry JSON was generated in
static/r/ - Check the dev server is running on the correct port
- Ensure file paths in
registry.jsonmatch actual locations - Rebuild the registry and restart the dev server
Component Not Rendering
If the component doesn’t work after installation:- Check browser console for errors
- Verify all imports are correct
- Ensure dependencies are installed
- Check that CSS variables were added to the config
Most issues can be resolved by carefully following the folder structure and registry configuration steps.