Before you start writing code, please familiarize yourself with this CONTRIBUTING.md document to ensure the codebase maintains its quality and consistency.
- Group your import statements as follows: external modules, aliases (
@
), and relative paths. - Sort imports alphabetically within each group.
- Use descriptive names for your types and interfaces.
- Group and sort the type imports separately from component imports.
In this codebase, we follow a strict structure for organizing files related to React components to make the project more maintainable and understandable. Here's how you should structure files for individual components:
For each component, create a dedicated directory with the name of the component. Inside this directory, maintain separate files for:
- The component logic (a
.tsx
file) - The styles associated with the component (a
.module.css
file) - Type definitions (a
.ts
file if necessary)
-
Component file:
- Name the main file
index.tsx
for cleaner import syntax. - Document the props the component accepts using TypeScript and JSDoc comments to provide clear guidance on how the component should be used.
- Name the main file
-
Styles file:
- Use CSS Modules to scope styles to the component.
- These files should always be called
styles.module.css
. - Organize your styles logically (e.g., grouped by functionality or chronologically as they appear in the markup).
-
Types file:
- If a component has complex types or interfaces, extract them into a separate file named
types.ts
. - Document each type/interface clearly, explaining what it represents and where/how it should be used.
- If a component has complex types or interfaces, extract them into a separate file named
- When utilizing dynamic imports, handle the loading state gracefully by displaying a skeleton component.
- Match the skeleton height reasonably close to the expected height of the loaded component to provide a smoother user experience and reduce layout shift.
- Use JSDoc comments to explain the purpose and usage of constants, functions, or components.
- Clearly document any important decisions or considerations to maintain clarity for other developers.
- Leverage destructuring to access properties of the props object.
- When mapping over arrays to render components, use meaningful names for variables.
- Ensure that components receive the necessary props, potentially passed dynamically based on the component's requirements.
- Where appropriate, include error handling to manage potential issues gracefully and maintain a good user experience.
- Keep accessibility in mind, ensuring components are navigable and usable with a keyboard alone, providing alt text for images, and ensuring that colours meet WCAG 2.1 AA contrast requirements at minimum. Though not part of a current standard, in the future this is likely to be updated to the APCA colour contrast standard. Where possible, contrast should be meeting this standard already (while not negating WCAG 2.1 AA contrast ratios for the sake of search performance).
To maintain a consistent coding style and avoid common mistakes, we use ESLint. Here is how you can ensure your code meets the project’s standards:
We use ESLint to analyze the code for potential errors and to enforce a consistent style.
- Installation: Ensure you have ESLint installed in your development environment. Refer to the ESLint documentation for installation guidelines.
- Ensure your code follows the established style guide.
- Include meaningful commit messages and PR descriptions to help reviewers understand your changes.
- Before submitting, test your changes locally to ensure they work correctly.
- When opening new issues, include a detailed description to help others understand the problem.
- Label issues appropriately, using existing labels where possible.
- To set up your development environment, follow the steps in the README.md file.