Code Quality Standards
Maintaining high code quality ensures the Blocks library remains reliable, accessible, and easy to maintain. Follow these guidelines when contributing.Code Style and Formatting
The project uses Biome for linting and code formatting. Always run the linter before committing:The project includes git hooks that automatically validate commit messages using commitlint.
TypeScript Usage
All components should be written in TypeScript:- Use explicit types for props and component parameters
- Leverage TypeScript’s type inference where appropriate
- Avoid using
anytype unless absolutely necessary - Define proper interfaces for complex prop structures
Import Organization
Organize imports in the following order:- External packages (React, third-party libraries)
- Internal UI components from
@/components/ui - Other internal imports
- Types and interfaces
Component Naming Conventions
File Naming
Use kebab-case for file names:login-01.tsxfile-upload-03.tsxcommand-menu-02.tsx
Component Naming
Use PascalCase for component names:Login01FileUpload03CommandMenu02
Block IDs
Block IDs should match the file name and follow this pattern:login-01stats-15file-upload-06
Accessibility Requirements
Accessibility is a core principle of the Blocks library. All components must meet the following standards:Semantic HTML
Use semantic HTML elements:ARIA Attributes
Use ARIA attributes when semantic HTML is insufficient:- Add
aria-labelfor icon-only buttons - Use
aria-describedbyfor form field descriptions - Include
aria-hiddenfor decorative elements - Implement proper focus management for interactive components
Keyboard Navigation
Ensure all interactive elements are keyboard accessible:- All interactive elements should be focusable
- Focus states should be clearly visible
- Implement logical tab order
- Support standard keyboard shortcuts (Enter, Space, Escape)
Color Contrast
Maintain proper color contrast ratios:- Use CSS variables from the theme system
- Test with different themes (light/dark)
- Ensure text meets WCAG AA standards (4.5:1 for normal text)
Component Structure
Layout and Styling
Use Tailwind CSS classes for styling:- Prefer utility classes over custom CSS
- Use responsive classes (
sm:,md:,lg:) for responsive design - Leverage the
cn()utility for conditional classes - Follow mobile-first approach
Component Composition
Build components using existing UI components from@/components/ui:
- Button
- Input
- Label
- Card
- Dialog
- Separator
- And other shadcn/ui components
State Management
For blocks with state:- Use React hooks (
useState,useEffect) appropriately - Keep state as local as possible
- Consider uncontrolled components for form inputs
- Document any required external state management
Documentation Standards
Component Documentation
While blocks are primarily visual components, consider adding JSDoc comments for complex logic:Metadata Quality
Provide clear, descriptive metadata:Performance Considerations
Optimize Imports
Import only what you need:Image Optimization
If your block includes images:- Use Next.js
Imagecomponent - Provide appropriate
alttext - Specify width and height
- Use appropriate formats (WebP, AVIF)
Avoid Heavy Dependencies
Minimize external dependencies:- Use built-in browser APIs when possible
- Leverage existing project dependencies
- Avoid adding new packages unless necessary
Testing Your Contribution
Before submitting, verify your block:Visual testing
Test the block in both light and dark themes:Toggle between themes in the UI to ensure proper styling.
Accessibility testing
Test with keyboard navigation:
- Tab through all interactive elements
- Verify focus indicators are visible
- Test screen reader compatibility if possible
Responsive testing
Test on different screen sizes:
- Mobile (320px+)
- Tablet (768px+)
- Desktop (1024px+)
Commit Message Format
The project uses conventional commits with commitlint. Follow this format:Commit Types
feat:- New feature or blockfix:- Bug fixdocs:- Documentation changesstyle:- Code style changes (formatting, etc.)refactor:- Code refactoringtest:- Adding or updating testschore:- Maintenance tasks
Examples
Code Review Checklist
Before submitting your pull request, verify:- Code follows TypeScript best practices
- Component uses proper naming conventions
- All accessibility requirements are met
- Component works in both light and dark themes
- Responsive design works on all screen sizes
- Registry has been regenerated
- Linter passes without errors
- Build completes successfully
- Commit messages follow conventional format
- Metadata is clear and descriptive
Reviewers will check these items when reviewing your pull request. Following these guidelines helps speed up the review process.
Questions?
If you have questions about these guidelines:- Review existing blocks for examples
- Check the project’s GitHub discussions
- Open an issue for clarification