How thomascsd/ngx-dot-calendar works
Main Components
• Angular Application (Demo/Usage): Located in the “src” folder. This represents the host application where the calendar component is being used. It includes the main module, app component, header, standalone component, etc.
• ngx-dot-calendar Library:
– Modules and Components: Under “projects/ngx-dot-calendar/src/lib/components” you have the main calendar component, date and years sub-components along with their HTML, TS, and SCSS files.
– Directives: For example, the “dateHighlight.directive.ts” in the “directive” folder which adds extra behavior (like highlighting dates).
– Interfaces: These files under “interfaces” (e.g., DateContent, DateRenderer, and SelectedDateContext) define the contracts used within the library.
– Public API: The “public_api.ts” aggregates and exposes the library modules.
• External Dependencies:
– Angular (v14 and above): The project is designed to run on Angular which underpins both the host application and the library.
– date-fns: Listed as a peer dependency to handle date manipulations.
• Build and Test Tools:
– Angular CLI configuration (angular.json, Karma and Protractor for testing, etc.)
– Linting and formatting (tslint.json, .prettierrc, etc.)
Relationships and Interactions
• The host application integrates the ngx-dot-calendar library via module imports (see example usage in README). It communicates with the calendar component via property binding ([dateContents]) and event binding ((onSelect)).
• Within the ngx-dot-calendar library, the main calendar component breaks down into sub-components such as the dates and years components. These sub-components collaborate to render the calendar UI.
• The directive (dateHighlight.directive.ts) is applied to parts of the calendar to add conditional formatting/logic (e.g., highlighting Sundays).
• Interfaces define the types and expected contracts for inputs and outputs between components, ensuring proper data flow.
• External modules (like date-fns) are used within the component logic to compute dates and formats.
Important Architectural Patterns and Design Choices
• Modular Architecture: The separation between the main application (demo usage) and the reusable library module keeps concerns isolated.
• Component-driven Design: The library clearly uses the Angular component-based paradigm with additional support via directives and interfaces.
• Reusability and Extensibility: The library is designed with clear API contracts (attributes and callback events) and is easily integrated into other Angular projects.
• Configuration and Environment Separation: There are dedicated configurations for production, testing, and development (multiple tsconfig files, karma.conf.js, etc.) which are critical for maintainability.
Relevant Technologies, Frameworks, or Libraries
• Angular Framework: Core to the project, as it supports both the host application and library.
• date-fns: For date manipulation and formatting.
• Testing frameworks: Karma for unit tests and Protractor for end-to-end tests.