Refer to our comprehensive Design and UX Philosophy documentation for a detailed guide on our approach to standardizing frontend development practices across CFIA projects.
The Design and UX Philosophy emphasizes a user-centric approach, ensuring that the applications we develop are intuitive, accessible, and efficient. This philosophy aligns with our commitment to providing an exceptional user experience, where the needs and preferences of users are at the forefront of every design decision.
- Component-Level Styling: Styled Components enable defining styles at the component level, enhancing modularity and reusability. This encapsulation ensures styles remain confined to their respective components.
- Dynamic Styling: Easily pass props to dynamically alter styles with Styled Components, offering greater flexibility and control over component appearance.
- Reduced Naming Conflicts: Styled Components generate unique class names, significantly reducing the risk of naming conflicts in a large codebase.
- Easier Deletion of Unused Styles: Deleting a component also removes its associated styles, preventing the accumulation of unused CSS.
- Improved Developer Experience: Styled Components integrate with modern development tools, providing features like syntax highlighting and style linting, thus enhancing the overall development process.
Below is the visual representation of the Finesse Frontend component structure:
For a detailed view and interactive experience with the diagram, visit the Finesse Component Diagram on Lucidchart.
- The root source folder branches into two main parts:
App.tsx
contexts
(folder)
- Serves as the entry point, branching out to:
Home.tsx
SearchPage.tsx
- Utilizes several shared components:
Header.tsx
DebugPanel.tsx
CFIALogo.tsx
SearchBar.tsx
- Has a unique component:
AlertBanner.tsx
- Also uses shared components:
Header.tsx
DebugPanel.tsx
CFIALogo.tsx
SearchBar.tsx
- Exclusive components:
SearchResultList.tsx
HighlightedContent.tsx
- Contains three context components:
AlertContext.tsx
DataContext.tsx
LayoutContext.tsx
This structure illustrates a separation of concerns between pages (Home
and
SearchPage
) and shared components, and the encapsulation of state management
in context components.
- The React application follows a parent-child relationship as shown in the diagram above.
- The diagram illustrates the flow of component props and the location at which components are imported.
- As for CSS and styling, styled components was used.
- Styled components is a library that allows you to write CSS in JS while building custom components in Reactjs.
- Styled components library can be installed via npm with
npm i styled-components
. - Any component that uses styled components, will import from the
src/components/styles/indexElements.tsx
file.
The decision to adopt Styled Components is rooted in the desire to address the complexities and limitations of traditional CSS, especially in large-scale and dynamic application environments. Styled Components offer a solution that couples the visual design directly with the component logic, resulting in a more cohesive development process. This approach not only streamlines the styling of applications but also aligns with the modern trends of component-based architecture, promoting better maintainability and scalability.
For a detailed explanation and the rationale behind this decision, refer to our ADR on Styling with Styled Components.
While traditional CSS is familiar and straightforward, it often leads to challenges like global scope, naming conflicts, and difficulties in maintaining a large codebase. Other CSS-in-JS solutions offer similar benefits to Styled Components but may lack the comprehensive feature set, developer tooling support, and community backing that Styled Components provide.
By choosing Styled Components, we leverage a robust and community-endorsed framework that integrates seamlessly with the React ecosystem, offering a future-proof solution for our styling needs.