From 7beaeb3e181fc2b95335cac75831a825d0b451dc Mon Sep 17 00:00:00 2001 From: Gramli Date: Thu, 11 Dec 2025 20:47:28 +0100 Subject: [PATCH 1/4] - add more keywords, rewrite readme --- README.md | 706 +++++++++++---------- package.json | 18 +- projects/angular-mydatepicker/package.json | 17 +- 3 files changed, 386 insertions(+), 355 deletions(-) diff --git a/README.md b/README.md index 9470de4..970514f 100644 --- a/README.md +++ b/README.md @@ -1,418 +1,426 @@ -

angular-mydatepicker

-
- +# angular-mydatepicker + [![Build&Test](https://github.com/Gramli/angular-mydatepicker/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/Gramli/angular-mydatepicker/actions/workflows/build_and_test.yml) +[![codecov](https://codecov.io/gh/gramli/angular-mydatepicker/branch/master/graph/badge.svg)](https://codecov.io/gh/gramli/angular-mydatepicker) +[![npm version](https://badge.fury.io/js/gramli-angular-mydatepicker.svg)](https://www.npmjs.com/package/gramli-angular-mydatepicker) +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) -
-

Angular datepicker and date range picker

+A highly configurable Angular datepicker and date range picker with no external dependencies. Lightweight, flexible, and feature-rich. -**Note:** This repository was originally forked from `nodro7/angular-mydatepicker`. +**[Demo App](https://github.com/Gramli/angular-mydatepicker/tree/master/example)** | **[API Documentation](#api-reference)** -## Angular Versions +## Features -The following list describes the compatibility with Angular: +- **Zero dependencies** - Pure Angular implementation +- **Dual modes** - Single date or date range selection +- **Flexible display** - Popup or inline mode +- **Rich localization** - 40+ built-in locales with easy customization +- **Keyboard navigation** - Full accessibility support +- **RTL support** - Right-to-left language compatibility +- **Smooth animations** - Multiple animation styles for calendar transitions +- **Highly customizable** - 50+ configuration options +- **Well tested** - Comprehensive test coverage +- **TypeScript** - Full type definitions included -| Angular Notifier | Angular | Compilation | -| ---------------- | ------- | ------------------ | -| `0.15.x` | `17.x` | Ivy (partial mode) | -| `0.16.x` | `18.x` | Ivy (partial mode) | -| `0.17.x` | `19.x` | Ivy (partial mode) | -| `0.18.x` | `20.x` | Ivy (partial mode) | -| `21.0.x` | `21.x` | Ivy (partial mode) | +## Installation -For older versions visit: -https://github.com/nodro7/angular-mydatepicker +```bash +npm install gramli-angular-mydatepicker +``` ---- -## Install +## Quick Start + +### 1. Import the module + +Add `AngularMyDatePickerModule` to your application module: + +```typescript +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { AngularMyDatePickerModule } from 'gramli-angular-mydatepicker'; + +@NgModule({ + imports: [ + BrowserModule, + FormsModule, + ReactiveFormsModule, + AngularMyDatePickerModule + ], + declarations: [AppComponent], + bootstrap: [AppComponent] +}) +export class AppModule { } +``` -```console -npm install gramli-angular-mydatepicker +### 2. Use in your component + +**Template-driven forms (ngModel):** + +```html + ``` ---- -## Changelog +**Reactive forms:** + +```html + +``` -CHANGELOG.md has been deprecated, for recent changes see [GitHub releases](https://github.com/gramli/angular-mydatepicker/releases). +**Component TypeScript:** ---- +```typescript +import { IAngularMyDpOptions, IMyDateModel } from 'gramli-angular-mydatepicker'; -## Browser support +export class MyComponent { + myOptions: IAngularMyDpOptions = { + dateRange: false, + dateFormat: 'dd.mm.yyyy' + }; + + model: IMyDateModel = null; +} +``` -| Chrome | Firefox | Edge | IE11 | Safari | iOS Safari | -| :------------- | :------------- | :----| :---------- | :----| :---------- | -| :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | +## Compatibility ---- +| Package Version | Angular Version | +|----------------|-----------------| +| `21.0.x` | `21.x` | +| `0.18.x` | `20.x` | +| `0.17.x` | `19.x` | +| `0.16.x` | `18.x` | +| `0.15.x` | `17.x` | -## Description +> [!NOTE] +> This project was originally forked from [nodro7/angular-mydatepicker](https://github.com/nodro7/angular-mydatepicker). For older versions, visit the original repository. -Highly configurable Angular datepicker and date range picker. +## Usage Examples -Basic idea to create this library was to make it as configurable as possible. The library is implemented as a directive. It is done this way, because then there is more choices to configure it. +### Basic Date Picker -### Main features +```typescript +// component.ts +import { IAngularMyDpOptions } from 'gramli-angular-mydatepicker'; -* no dependencies to other libraries -* currently localized [languages](https://github.com/gramli/angular-mydatepicker#locale-attribute) -* datepicker -* date range picker -* popup mode -* inline mode -* supports keyboard -* supports RTL -* animation of calendar (open/close) -* awesome configuration possibilities - * easily set styles to the component which are in line with your page theme - * calendar - * input box and input box controls - * 50 [options](https://github.com/gramli/angular-mydatepicker#options-attribute) - * change value of any option dynamically -* well tested - * coverage [report](https://codecov.io/gh/gramli/angular-mydatepicker) - * most of the code is from existing libraries which are widely used +myOptions: IAngularMyDpOptions = { + dateFormat: 'dd.mm.yyyy', + firstDayOfWeek: 'mo' +}; +``` -## Installation +```html + + +``` + +### Date Range Picker + +```typescript +myRangeOptions: IAngularMyDpOptions = { + dateRange: true, + dateFormat: 'dd.mm.yyyy' +}; +``` + +### Inline Mode + +```html + +``` + +### With Locale + +```typescript +myOptions: IAngularMyDpOptions = { + dateFormat: 'dd/mm/yyyy' +}; +``` + +```html + +``` + +For complete examples, see: +- [ngModel example](https://github.com/gramli/angular-mydatepicker/tree/master/example/app/date-picker-ngmodel) +- [Reactive forms example](https://github.com/gramli/angular-mydatepicker/tree/master/example/app/date-picker-reactive-forms) +- [Inline mode example](https://github.com/gramli/angular-mydatepicker/tree/master/example/app/date-picker-inline) + +## API Reference -To install this component to an external project, follow the procedure: - -1. `npm install gramli-angular-mydatepicker` - -2. Add `AngularMyDatePickerModule` import to your `@NgModule` as follows: - - ```ts - import { BrowserModule } from '@angular/platform-browser'; - import { NgModule } from '@angular/core'; - import { FormsModule, ReactiveFormsModule } from '@angular/forms'; - import { AngularMyDatePickerModule } from 'gramli-angular-mydatepicker'; - - @NgModule({ - declarations: [ - AppComponent - ], - imports: [ - BrowserModule, - ReactiveFormsModule, - FormsModule, - AngularMyDatePickerModule - ], - providers: [], - bootstrap: [AppComponent] - }) - export class AppModule { } - ``` - -## Usage - -Use one of the following two options. - -### 1. ngModel binding - -In this option the **ngModel** binding is used. - -* [ngModel example application](https://github.com/gramli/angular-mydatepicker/tree/master/example/app/date-picker-ngmodel) - -There are two ways to initialize date or date range to the model. - -* single date mode -* date range mode - -### 2. Reactive forms - -In this option the value accessor of reactive forms is used. - -* [reactive example application](https://github.com/gramli/angular-mydatepicker/tree/master/example/app/date-picker-reactive-forms) - -## Attributes - -### options attribute - -The `options` attribute is a type of [IAngularMyDpOptions](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-options.interface.ts). It has the following optional properties. - -| Option | Default | Type | Description | -| :------------- | :------------- | :----| :---------- | -| **dateRange** | false | boolean | Date picker mode (date picker or date range picker). | -| **inline** | false | boolean | Normal mode or inline mode. If **inline** mode is used, set the input box **type** attribute to **hidden** and this option to **true**. [Here](https://github.com/gramli/angular-mydatepicker/blob/master/example/app/date-picker-inline/date-picker-inline.html#L10) is an example.| -| **dayLabels** | {su: 'Sun', mo: 'Mon', tu: 'Tue', we: 'Wed', th: 'Thu', fr: 'Fri', sa: 'Sat'} | [IMyDayLabels](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-day-labels.interface.ts) | Day labels visible on the selector. | -| **monthLabels** | { 1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr', 5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec' } | [IMyMonthLabels](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-month-labels.interface.ts) | Month labels visible on the selector. | -| **dateFormat** | yyyy-mm-dd | string | Date format on the selection area and the callback. For example: **d.m.yyyy**, **dd.mm.yyyy**, **yyyy-m-d**, **yyyy-mm-dd**, **d mmm yyyy**, **dd mmm yyyy**, **d## of mmm yyyy** (d = Day not leading zero, dd = Day with leading zero, d## = Ordinal dates for example 3rd, m = Month not leading zero, mm = Month with leading zero, mmm = Month as a text, yyyy = Year four digit) | -| **defaultView** | date | [DefaultView](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/enums/default-view.enum.ts) | Calendar opens to this view (date, month or year).| -| **firstDayOfWeek** | mo | string | First day of week on calendar. One of the following: **mo, tu, we, th, fr, sa, su** | -| **sunHighlight** | true | boolean | Sunday red colored on calendar. | -| **satHighlight** | false | boolean | Saturday red colored on calendar. | -| **highlightDates** | no default value | Array<[IMyDate](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-date.interface.ts)> | Dates red colored on calendar. Value of year or month can be zero. If it is zero it affects all years/months. For example: **[{year: 2019, month: 11, day: 14}, {year: 2019, month: 1, day: 15}]** | -| **markCurrentDay** | true | boolean | Is current day (today) marked (underline) on calendar. | -| **markCurrentMonth** | true | boolean | Is current month marked (underline) on calendar. Can be used if **monthSelector = true**. | -| **markCurrentYear** | true | boolean | Is current year marked (underline) on calendar. Can be used if **yearSelector = true**. | -| **monthSelector** | true | boolean | If **true** and if month label is selected opens a selector of months. | -| **yearSelector** | true | boolean | If **true** and if year label is selected opens a selector of years. | -| **disableHeaderButtons** | true | boolean | Prevent to change the calendar view with header buttons if previous or next month are fully disabled by the **disableUntil** or the **disableSince** options. | -| **showWeekNumbers** | false | boolean | Are week numbers visible or not on calendar. Can be used if **firstDayOfWeek = mo**. | -| **selectorHeight** | 266px | string | Selector height. | -| **selectorWidth** | 266px | string | Selector width. | -| **disableUntil** | no default value | [IMyDate](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-date.interface.ts) | Disable dates backward starting from the given date. For example: **{year: 2019, month: 6, day: 26}**. To reset the existing **disableUntil** value set: **{year: 0, month: 0, day: 0}** | -| **disableSince** | no default value | [IMyDate](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-date.interface.ts) | Disable dates forward starting from the given date. For example: **{year: 2019, month: 7, day: 22}**. To reset the existing **disableSince** value set: **{year: 0, month: 0, day: 0}** | -| **disableDates** | no default value | Array<[IMyDate](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-date.interface.ts)>
or
Array<[IMyDisabledDates](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-disabled-dates.interface.ts)> | Disable dates one by one. Array of disabled dates. For example: **[{year: 2019, month: 11, day: 14}, {year: 2019, month: 1, day: 15}]**. Or it is possible to disable dates by setting own style to **td** element. For example: **[{dates: [{year: 2020, month: 5, day: 19}, {year: 2020, month: 5, day: 20}], styleClass: 'yoga'}]**. Value of **styleClass** is name of CSS selector. The definition of the CSS selector have to be added to the **stylesData** option. For example it is possible add a CSS **background-color** to definition of this selector.

Value of year or month can be zero. If it is zero it affects all years/months. For example disable first day of every month: **[{year: 0, month: 0, day: 1}]**. To reset existing **disableDates** value set empty array to it. | -| **disableDateRanges** | no default value | Array<[IMyDateRange](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-date-range.interface.ts)> | Disable date ranges. For example: **[{begin: {year: 2019, month: 11, day: 14}, end: {year: 2019, month: 11, day: 20}}]**. To reset existing value of **disableDateRanges** set empty array to it. | -| **disableWeekends** | false | boolean | Disable weekends. (Saturday and Sunday). | -| **disableWeekdays** | no default value | Array< string > | Disable weekdays. Array of weekdays to disable. Weekdays are same strings as the **firstDayOfWeek** option. For example: **['tu', 'we']** which disables Tuesdays and Wednesdays. | -| **enableDates** | no default value | Array<[IMyDate](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-date.interface.ts)> | Enable single dates one by one if the date is disabled. For example if you disable the date range and want to enable some dates in range. Array of enabled days. For example: **[{year: 2019, month: 11, day: 14}, {year: 2019, month: 1, day: 15}]**. Value of year or month can be zero. If it is zero it affects all years/months. For example enable first day of every month: **[{year: 0, month: 0, day: 1}]**. To reset existing **enableDates** value set empty array to it. | -| **markDates** | no default value | Array<[IMyMarkedDates](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-marked-dates.interface.ts)> | Mark dates for different colors or styles. For example: **[{dates: [{year: 2019, month: 11, day: 14}, {year: 2019, month: 12, day: 16}], color: '#004198', styleClass: 'karateDates'}, {dates: [{year: 2018, month: 10, day: 1}, {year: 2018, month: 11, day: 4}], color: 'green', styleClass: 'yogaDates'}]**. The **color** property is optional. If it is given it adds a triangle to the upper left corner of the date. The **styleClass** is optional. If it is given it changes the style of the **td** element of the date. Value of the **styleClass** is a CSS selector name. The definition of the CSS selector have to be added to the **stylesData** option. For example it is possible add a CSS **background-color** to definition of this selector. Both **color** and **styleClass** can be used at the same time.

Value of year or month can be zero. If it is zero it affects all years/months. To reset existing value of **markDates** set empty array to it. | -| **markWeekends** | no default value | [IMyMarkedDate](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-marked-date.interface.ts) | Mark weekends (Saturday and Sunday). For example: **{marked: true, color: 'red'}**. Value of color can be any CSS color code. To reset existing value of **markWeekends** set: **{marked: false, color: ''}** | -| **alignSelectorRight** | false | boolean | Align selector right. | -| **openSelectorTopOfInput** | false | boolean | Open selector top of input field. | -| **closeSelectorOnDateSelect** | true | boolean | Is selector closed or not on a date select. | -| **closeSelectorOnDocumentClick** | true | boolean | Is selector closed or not on a document click. | -| **minYear** | 1000 | number | Minimum allowed year in calendar. Cannot be less than **1000**. | -| **maxYear** | 9999 | number | Maximum allowed year in calendar. Cannot be more than **9999**. | -| **showSelectorArrow** | true | boolean | Is selector (calendar) arrow shown or not. | -| **appendSelectorToBody** | false | boolean | Is selector (calendar) appended to body element or not. | -| **focusInputOnDateSelect** | true | boolean | Is the input box focused after a date select. | -| **moveFocusByArrowKeys** | true | boolean | Is focus moved or not on the calendar by arrow keys. | -| **dateRangeDatesDelimiter** | " - " | string | The delimiter of dates in a date range. | -| **inputFieldValidation** | true | boolean | Input field validation enabled or not after **blur** event of input field. | -| **showMonthNumber** | true | boolean | Is month number shown or not on the month view. | -| **todayTxt** | empty string | string | Today footer text. This value comes also from locale [Locales](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/services/angular-mydatepicker.locale.service.ts): If there is locale it is not necessary to add this property. Also the **showFooterToday** option have to be **true** in order to use this option. If you want to add only today date to the footer put empty string to the value of this option.| -| **showFooterToday** | false | boolean | Is today footer shown or not. | -| **calendarAnimation** | no default value | [IMyCalendarAnimation](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-calendar-animation.interface.ts) | The type of open (**in**) and close (**out**) animation of calendar. One of the following ([CalAnimation](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/enums/cal-animation.enum.ts)) value: **None**, **Fade**, **ScaleTop**, **ScaleCenter**, **Rotate**, **FlipDiagonal** or **Own**. Try animations [here](https://gramli.github.io/angular-mydatepicker/).| -| **viewChangeAnimation** | true | boolean | Is view change animation enabled or not. | -| **rtl** | false | boolean | Is RTL enabled or not. Try RTL [here](https://gramli.github.io/angular-mydatepicker/). | -| **stylesData** | no default value | [IMyStyles](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-styles.interface.ts) | Overridden styles of the datepicker. See also [chapter](https://github.com/gramli/angular-mydatepicker#override-styles-of-component) below. | -| **divHostElement** | no default value | [IMyDivHostElement](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-div-host-element.interface.ts) | Div as a host element. In case of non-editable date field enable this option and put a **angular-mydatepicker** directive inside a **div** element. Placeholder text is an additional property of this option. Functionality is limited if this option is enabled. It is also possible to use input box and set it to **disabled** to archieve non-editable date field. | -| **ariaLabelPrevMonth** | Previous Month | string | Aria label text of previous month button. | -| **ariaLabelNextMonth** | Next Month | string | Aria label text of next month button. | - -### locale attribute - -An **ISO 639-1** language code can be provided as shorthand for the following options (**dayLabels**, **monthLabels**, **dateFormat**, **firstDayOfWeek**, **sunHighlight** and **todayTxt**). -Currently supported languages are: - -| Language code | Description | -| :------------- | :------------- | -| **en** | English | -| **fr** | French | -| **fr-ch** | French - Switzerland | -| **ja** | Japanese | -| **fi** | Finnish | -| **es** | Spanish | -| **hu** | Hungarian | -| **sv** | Swedish | -| **nl** | Dutch | -| **ru** | Russian | -| **uk** | Ukrainian | -| **uz** | Uzbek | -| **no** | Norwegian | -| **tr** | Turkish | -| **pt-br** | Portuguese - Brazil | -| **de** | German | -| **de-ch** | German - Switzerland | -| **it** | Italian | -| **it-ch** | Italian - Switzerland | -| **pl** | Polish | -| **my** | Burmese | -| **sk** | Slovak | -| **sl** | Slovenian | -| **zh-cn** | Chinese - China | -| **he** | Hebrew | -| **ro** | Romanian - Romania | -| **ca** | Catalan | -| **id** | Indonesian | -| **en-au** | English - Australia | -| **en-gb** | English - British | -| **am-et** | Amharic | -| **cs** | Czech | -| **el** | Greek | -| **kk** | Kazakh | -| **th** | Thai | -| **ko-kr** | Korean | -| **da** | Danish | -| **lt** | Lithuanian | -| **vi** | Vietnamese | -| **bn** | Bengali | -| **bg** | Bulgarian | -| **hr** | Croatian | -| **ar** | Arabic | -| **is** | Icelandic | -| **tw** | Chinese - Taiwan | -| **lv** | Latvian | -| **et** | Estonian | - -The **locale** options can be overridden by **options** attribute. - -* a new locale data will be added to [this](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/services/angular-mydatepicker.locale.service.ts) -file. If you want to add a new locale create a pull request. - -Try locales [here](https://gramli.github.io/angular-mydatepicker/). - -### defaultMonth attribute - -Visible month/year when calendar is opened: - -* If date is already selected => calendar opens to the month and the year of the selected date - * In date range mode => calendar opens to the month and the year of the selected begin date - * If an **overrideSelection** property is set to **true** in the [IMyDefaultMonth](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-default-month.interface.ts) the calendar opens to the month and the year specified in the the **defaultMonth** attribute even the date is selected. -* If the **defaultMonth** is set => calendar opens to the month and the year specified in the the **defaultMonth** attribute -* If none of above => calendar opens to the month and the year of current date - -Value of the **defaultMonth** attribute can be: - -* [IMyDefaultMonth](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-default-month.interface.ts) object. The value of **defMonth** property can be a string which contain year number and month number separated by delimiter. The delimiter can be any special character. For example: **08-2019** or **08/2019**. -* a string which contain year number and month number separated by delimiter. The delimiter can be any special character. For example: **08-2019** or **08/2019**. - -## Functions - -You can can call functions of the directive. Define a local variable to the input field as follows: +### Configuration Options + +The datepicker accepts an `options` attribute of type [`IAngularMyDpOptions`](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-options.interface.ts) with 50+ configuration options. + +#### Core Options + +| Option | Type | Default | Description | +|--------|------|---------|-------------| +| `dateRange` | `boolean` | `false` | Enable date range picker mode | +| `inline` | `boolean` | `false` | Display calendar inline (set input `type="hidden"`) | +| `dateFormat` | `string` | `'yyyy-mm-dd'` | Date format (e.g., `'dd.mm.yyyy'`, `'mm/dd/yyyy'`) | +| `defaultView` | `DefaultView` | `date` | Initial calendar view: `date`, `month`, or `year` | +| `firstDayOfWeek` | `string` | `'mo'` | First day of week: `mo`, `tu`, `we`, `th`, `fr`, `sa`, `su` | +| `showWeekNumbers` | `boolean` | `false` | Display ISO week numbers | +| `selectorHeight` | `string` | `'266px'` | Calendar height | +| `selectorWidth` | `string` | `'266px'` | Calendar width | + +#### Date Constraints + +| Option | Type | Description | +|--------|------|-------------| +| `disableUntil` | `IMyDate` | Disable all dates before this date | +| `disableSince` | `IMyDate` | Disable all dates after this date | +| `disableDates` | `IMyDate[]` | Disable specific dates | +| `disableDateRanges` | `IMyDateRange[]` | Disable date ranges | +| `disableWeekends` | `boolean` | Disable Saturdays and Sundays | +| `disableWeekdays` | `string[]` | Disable specific weekdays (e.g., `['tu', 'we']`) | +| `enableDates` | `IMyDate[]` | Enable specific dates (overrides disable rules) | + +#### Styling & Highlighting + +| Option | Type | Description | +|--------|------|-------------| +| `markDates` | `IMyMarkedDates[]` | Mark dates with colors or custom styles | +| `markWeekends` | `IMyMarkedDate` | Highlight weekends with custom color | +| `highlightDates` | `IMyDate[]` | Highlight specific dates in red | +| `sunHighlight` | `boolean` | Highlight Sundays in red | +| `satHighlight` | `boolean` | Highlight Saturdays in red | +| `stylesData` | `IMyStyles` | Override default styles | + +#### Animation & Behavior + +| Option | Type | Default | Description | +|--------|------|---------|-------------| +| `calendarAnimation` | `IMyCalendarAnimation` | `None` | Open/close animation: `None`, `Fade`, `ScaleTop`, `ScaleCenter`, `Rotate`, `FlipDiagonal`, `Own` | +| `viewChangeAnimation` | `boolean` | `true` | Enable view transition animations | +| `closeSelectorOnDateSelect` | `boolean` | `true` | Close calendar after date selection | +| `closeSelectorOnDocumentClick` | `boolean` | `true` | Close calendar on outside click | +| `rtl` | `boolean` | `false` | Enable right-to-left mode | + +#### Accessibility + +| Option | Type | Default | +|--------|------|---------| +| `ariaLabelPrevMonth` | `string` | `'Previous Month'` | +| `ariaLabelNextMonth` | `string` | `'Next Month'` | + +For the complete list of options, see [`IAngularMyDpOptions`](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-options.interface.ts). + +### Locales + +The datepicker supports 40+ locales out of the box. Set the `locale` attribute to an [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code: ```html - + ``` -The **#dp="angular-mydatepicker"** defines the local variable named **dp**. You can use it to call functions of the directive -for example **(click)="dp.openCalendar()"**. +#### Supported Locales + +`en`, `fr`, `fr-ch`, `ja`, `fi`, `es`, `hu`, `sv`, `nl`, `ru`, `uk`, `uz`, `no`, `tr`, `pt-br`, `de`, `de-ch`, `it`, `it-ch`, `pl`, `my`, `sk`, `sl`, `zh-cn`, `he`, `ro`, `ca`, `id`, `en-au`, `en-gb`, `am-et`, `cs`, `el`, `kk`, `th`, `ko-kr`, `da`, `lt`, `vi`, `bn`, `bg`, `hr`, `ar`, `is`, `tw`, `lv`, `et` + +> [!TIP] +> To add a new locale, submit a PR updating the [locale service](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/services/angular-mydatepicker.locale.service.ts). + +### Default Month -### openCalendar function +Control which month is displayed when the calendar opens: -Opens the calendar. +```typescript +// String format +defaultMonth: '08-2019' -### closeCalendar function +// Object format +defaultMonth: { + defMonth: '08/2019', + overrideSelection: true // Show this month even if a date is selected +} +``` -Closes the calendar. +The calendar opens to: +1. The selected date's month (or begin date in range mode) +2. The `defaultMonth` if specified (or if `overrideSelection: true`) +3. The current month if neither above applies -### toggleCalendar function +### Directive Methods -Closes the calendar if it is open and opens the calendar if it is closed. Returns **true** if the operation was open the calendar, otherwise returns **false**. +Access directive methods using a template reference variable: -### clearDate function +```html + +``` -Clears the date or date range from the input box and model. +| Method | Description | +|--------|-------------| +| `dp.openCalendar()` | Open the calendar | +| `dp.closeCalendar()` | Close the calendar | +| `dp.toggleCalendar()` | Toggle calendar (returns `true` if opened) | +| `dp.clearDate()` | Clear the selected date/range | +| `dp.isDateValid()` | Check if current input is valid | +| `dp.headerAction(action)` | Trigger header button action | +| `dp.setHostValue(value)` | Set input box value | + +### Events + +#### dateChanged + +Emitted when a date is selected, cleared, or input is valid. + +```typescript +onDateChanged(event: IMyDateModel) { + if (event.isRange) { + console.log('Range:', event.dateRange); + } else { + console.log('Date:', event.singleDate); + } +} +``` -### isDateValid function +**Event structure:** +- `isRange`: boolean - true for date ranges +- `singleDate`: `{ date, jsDate, formatted, epoc }` (when `isRange` is false) +- `dateRange`: `{ beginDate, beginJsDate, beginEpoc, endDate, endJsDate, endEpoc, formatted }` (when `isRange` is true) -Returns **true** if the date or date range in the input box is valid. Otherwise it returns **false**. This function also calls the **inputFieldChanged** callback. +#### inputFieldChanged -### headerAction function +Emitted on input field changes. -Header button (previous, month, year or next) action. Calling this function has same behaviour as clicking of the header button. Function has one parameter [HeaderAction](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/enums/header-action.enum.ts). +```typescript +onInputChanged(event: IMyInputFieldChanged) { + console.log('Value:', event.value); + console.log('Valid:', event.valid); +} +``` -### setHostValue function +#### calendarViewChanged -Sets host (input box) value. +Emitted when the calendar view changes. -## Callbacks +```typescript +onViewChanged(event: IMyCalendarViewChanged) { + console.log('Month:', event.month, 'Year:', event.year); +} +``` -### dateChanged callback +#### calendarToggle -* called when a **single date** or **date range** is selected, cleared or input field typing is valid -* event parameter: - * **event.isRange**: **true** if a date range is selected, **false** if a single date is selected - * **event.singleDate**: event data if **isRange** is **false**, if **isRange** is **true** this property is **null** - * **date**: [IMyDate](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-date.interface.ts) object for example: { year: 2019, month: 9, day: 7 } - * **jsDate**: Javascript Date object - * **formatted**: Date as a string in the same format as the **dateFormat** option is. For example '2016-11-22' - * **epoc**: Epoc time stamp. For example: 1479765600 - * **event.dateRange**: event data if **isRange** is **true**, if **isRange** is **false** this property is **null** - * **beginDate**: [IMyDate](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-date.interface.ts) object for example: { year: 2019, month: 11, day: 7 } - * **beginJsDate**: Javascript Date object - * **beginEpoc**: Epoc time stamp for example: 1479765600 - * **endDate**: [IMyDate](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-date.interface.ts) object for example: { year: 2019, month: 11, day: 9 } - * **endJsDate**: Javascript Date object - * **endEpoc**: Epoc time stamp. For example: 1479765600 - * **formatted**: Date range as a string. The date is in the same format as the **dateFormat** option is. For example '2019-11-22 - 2019-11-24' +Emitted when calendar opens/closes with reason code: +- `1` - Calendar opened +- `2` - Closed by date select +- `3` - Closed by calendar button +- `4` - Closed by outside click +- `5` - Closed by ESC key -* Type of event parameter is [IMyDateModel](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-date-model.interface.ts) +#### rangeDateSelection -### inputFieldChanged callback +Emitted in date range mode when a date is selected. -* called when the value change in the input field, date or date range is selected or date is cleared. -* event parameter: - * **event.value**: Value of the input field. For example: '2018-11-22' - * **event.dateFormat**: Date format. For example 'yyyy-mm-dd' - * **event.valid**: Boolean value indicating is the value of input field valid or not. For example: true -* Type of event parameter is [IMyInputFieldChanged](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-input-field-changed.interface.ts) +```typescript +onRangeSelection(event) { + console.log(event.isBegin ? 'Start date:' : 'End date:', event.formatted); +} +``` -### calendarViewChanged callback +#### viewActivated -* called when the calendar view is changed. The date selection view activated or month/year changed on the date selection view. -* event parameter: - * **event.year**: Year number in calendar. For example: 2018 - * **event.month**: Month number in calendar. For example: 11 - * **event.first**: First day of selected month and year. Type of [IMyWeekday](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-weekday.interface.ts). For example: {number: 1, weekday: "tu"} - * **event.last**: Last day of selected month and year. Type of [IMyWeekday](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-weekday.interface.ts). For example: {number: 30, weekday: "we"} -* event parameter type is [IMyCalendarViewChanged](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-calendar-view-changed.interface.ts) -* values of the weekday property are same as values of the **firstDayOfWeek** option +Emitted when calendar view changes (date/month/year). -### calendarToggle callback +```typescript +onViewActivated(view: ActiveView) { + // 1 = date view, 2 = month view, 3 = year view +} +``` -* called when the calendar is opened or closed - * **event**: number from **1** to **5** indicating the reason of the event - * **1** = calendar opened - * **2** = calendar closed by date select - * **3** = calendar closed by calendar button - * **4** = calendar closed by outside click (document click) - * **5** = calendar closed by ESC key +## Styling + +Override any styles from the [default stylesheet](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/css/angular-mydatepicker.style.css) using the `stylesData` option: + +```typescript +myOptions: IAngularMyDpOptions = { + stylesData: { + selector: 'dp1', + styles: ` + .dp1 .myDpMarkCurrDay { + border-bottom: 2px solid #0099ff; + } + ` + } +} +``` -### rangeDateSelection callback +## Development -* called in a date range mode when a date is selected - * event parameter: - * **event.isBegin**: Is begin date. **true** if begin date, **false** if end date - * **event.date**: Selected date as an [IMyDate](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/interfaces/my-date.interface.ts) object - * **event.dateFormat**: Date format given in options. For example 'yyyy-mm-dd' - * **event.formatted**: Selected date as a string (format based on **dateFormat** option). For example '2019-05-10' - * **event.epoc**: Epoc time stamp. For example: 1557435600 +### Prerequisites -### viewActivated callback +- [Git](https://git-scm.com/) +- [Node.js](https://nodejs.org/) with npm -* called when the calendar view (date, month or year) change - * **event**: View number as an enum value [ActiveView](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/enums/active-view.enum.ts) - * **1** = date view - * **2** = month view - * **3** = year view +### Setup -## Override styles of component +```bash +git clone https://github.com/Gramli/angular-mydatepicker.git +cd angular-mydatepicker +npm install +``` + +### Run Demo + +```bash +npm start +# Navigate to http://localhost:4200 +``` -It is possible to override styles of the datepicker. Each datepicker can define unique styles in case of multiple datepickers on the same page. -It is possible override any of [these](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/css/angular-mydatepicker.style.css) styles. +### Testing & Linting -## Development of this component +```bash +# Run tests with coverage +npm run test-lib +# Coverage report available in test-output/ -In order the following commands work you need a **git client** and **npm**. +# Run linter +npm run lint-lib +``` + +### Build Library -* At first fork and clone this repo: - 1. __git clone __ - 2. **cd angular-mydatepicker** +```bash +npm run build-lib +# Output: dist/angular-mydatepicker/ +``` -* Install dependencies: - 1. **npm install** +### Create Local Package -* Run sample application: - 1. **ng serve** - 2. Navigate to ____ +```bash +npm run build-lib +cd dist/angular-mydatepicker +npm pack +# Install in your project: +# npm install path/to/gramli-angular-mydatepicker-x.y.z.tgz +``` -* Run tests and lint: - 1. Tests: **npm run test-lib** - * the **test-output** folder is created under the root folder and it contains a coverage report - 2. Lint: **npm run lint-lib** +## Contributing -* Build datepicker library: - 1. **npm run build-lib** - * the **dist/angular-mydatepicker** folder is created under the root folder - -* Build a local npm installation package: - 1. **npm run build-lib** - 2. **cd dist/angular-mydatepicker** - 3. **npm pack** - * local installation package is created to the **dist/angular-mydatepicker** folder. For example: **angular-mydatepicker-0.0.1.tgz** - -* Install local **npm** package to your project: - 1. **npm install path_to_folder/angular-mydatepicker-0.0.1.tgz** +Contributions are welcome! Please feel free to submit a Pull Request. For new locales, update the [locale service](https://github.com/gramli/angular-mydatepicker/blob/master/projects/angular-mydatepicker/src/lib/services/angular-mydatepicker.locale.service.ts). ## License -* [MIT](https://github.com/gramli/angular-mydatepicker/blob/master/LICENSE) +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. -## Original Authors +## Credits -* [nodro7](https://github.com/nodro7) -* [kekeh](https://github.com/kekeh) +Originally created by [kekeh](https://github.com/kekeh) and [nodro7](https://github.com/nodro7) and. Currently maintained by [Gramli](https://github.com/Gramli). diff --git a/package.json b/package.json index e04f990..05d497e 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,22 @@ "description": "Angular datepicker", "keywords": [ "angular", - "date", - "picker", + "angular-date-picker", + "date-picker", "datepicker", - "range" + "date-range-picker", + "calendar", + "angular-calendar", + "angular-ui", + "angular-components", + "lightweight", + "typescript", + "date-input", + "form-control", + "form-field", + "customizable", + "ui-component", + "date-selection" ], "author": "gramli", "license": "MIT", diff --git a/projects/angular-mydatepicker/package.json b/projects/angular-mydatepicker/package.json index 6375734..921b789 100644 --- a/projects/angular-mydatepicker/package.json +++ b/projects/angular-mydatepicker/package.json @@ -4,11 +4,22 @@ "description": "Angular datepicker", "keywords": [ "angular", - "date", - "picker", + "angular-date-picker", + "date-picker", "datepicker", + "date-range-picker", "calendar", - "range" + "angular-calendar", + "angular-ui", + "angular-components", + "lightweight", + "typescript", + "date-input", + "form-control", + "form-field", + "customizable", + "ui-component", + "date-selection" ], "author": "gramli", "license": "MIT", From b451ab85202348c2f814b4e089ba0ef6a16c2264 Mon Sep 17 00:00:00 2001 From: Gramli Date: Thu, 11 Dec 2025 20:53:23 +0100 Subject: [PATCH 2/4] - fix build and test workflow, add coverage --- .github/workflows/build_and_test.yml | 56 +++++++++++----------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 73b165c..3ec769d 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -8,49 +8,37 @@ on: workflow_dispatch: jobs: - build: - name: Build + build-and-test: + name: Build, Test & Lint runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3 - - name: Setup NodeJS - uses: actions/setup-node@v3 + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 with: - node-version: 22.20.x + node-version: 'lts/*' + cache: 'npm' + - name: Install dependencies run: npm ci - - name: Build Lib + + - name: Lint Library + run: npm run lint-lib + + - name: Build Library run: npm run build-lib + - name: Build Example run: npm run build-example - test: - name: Test - needs: build - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Setup NodeJS - uses: actions/setup-node@v3 - with: - node-version: 22.20.x - - name: Install dependencies - run: npm ci + - name: Test Library + run: npm run test-lib - lint: - name: Lint - needs: build - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Setup NodeJS - uses: actions/setup-node@v3 + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 with: - node-version: 22.20.x - - name: Install dependencies - run: npm ci - - name: Run Lint - run: npm run lint-lib \ No newline at end of file + files: ./coverage/angular-mydatepicker/coverage-final.json + fail_ci_if_error: false + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file From f27d572e5b821646d8c8619162b1d833d358facc Mon Sep 17 00:00:00 2001 From: Gramli Date: Thu, 11 Dec 2025 20:59:40 +0100 Subject: [PATCH 3/4] - remove coverage --- .github/workflows/build_and_test.yml | 9 +-------- README.md | 1 - 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 3ec769d..75bb2db 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -34,11 +34,4 @@ jobs: run: npm run build-example - name: Test Library - run: npm run test-lib - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - files: ./coverage/angular-mydatepicker/coverage-final.json - fail_ci_if_error: false - token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file + run: npm run test-lib \ No newline at end of file diff --git a/README.md b/README.md index 970514f..579df68 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # angular-mydatepicker [![Build&Test](https://github.com/Gramli/angular-mydatepicker/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/Gramli/angular-mydatepicker/actions/workflows/build_and_test.yml) -[![codecov](https://codecov.io/gh/gramli/angular-mydatepicker/branch/master/graph/badge.svg)](https://codecov.io/gh/gramli/angular-mydatepicker) [![npm version](https://badge.fury.io/js/gramli-angular-mydatepicker.svg)](https://www.npmjs.com/package/gramli-angular-mydatepicker) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) From 0c0ed8a980e31d8bdd5fb269e80c24f41588b6c9 Mon Sep 17 00:00:00 2001 From: Gramli Date: Thu, 11 Dec 2025 21:05:29 +0100 Subject: [PATCH 4/4] - edit description --- package.json | 2 +- projects/angular-mydatepicker/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 05d497e..cc80d07 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "angular-mydatepicker-example", "version": "21.0.0", - "description": "Angular datepicker", + "description": "A highly configurable Angular datepicker and date range picker with no external dependencies. Lightweight, flexible, and feature-rich.", "keywords": [ "angular", "angular-date-picker", diff --git a/projects/angular-mydatepicker/package.json b/projects/angular-mydatepicker/package.json index 921b789..6faa0f8 100644 --- a/projects/angular-mydatepicker/package.json +++ b/projects/angular-mydatepicker/package.json @@ -1,7 +1,7 @@ { "name": "gramli-angular-mydatepicker", "version": "21.0.0", - "description": "Angular datepicker", + "description": "A highly configurable Angular datepicker and date range picker with no external dependencies. Lightweight, flexible, and feature-rich.", "keywords": [ "angular", "angular-date-picker",