2.2.1 • Published 5 months ago

persian-date-ranger v2.2.1

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

Persian Date Ranger

Overview

Overview The Persian Date Ranger is a comprehensive Persian date picker component for Angular projects. It allows users to easily integrate a Jalali (Persian) calendar with various features such as date range selection, date format customization, and navigation options.

This package is free for use in Angular projects and helps developers add a Persian date picker to their web applications.


Features

Persian Calendar: Provides a Persian (Jalali) date picker. Date Range Picker (rangePicker): Enables users to select a date range for reservations or any other use cases. Customizable Date Formats: Supports various date formats including YYYY-MM-DD, jYYYY/jMM/jDD, and others. Positioning: The calendar can be positioned relative to the input element using the stickyFlipPosition directive.


Installation

To install the Persian Date Ranger package, use the following command:

npm install persian-date-ranger

Make sure you have the following peer dependencies installed in your Angular project:

@angular/common version ^16.0.0
@angular/core version ^16.0.0

Usage

Import the Module In your Angular module (e.g., app.module.ts), import the PersianDateRangerModule:

import {PersianDateRangerModule} from 'persian-date-ranger';

@NgModule({
  declarations: [AppComponent],
  imports: [PersianDateRangerModule],
  bootstrap: [AppComponent]
})
export class AppModule {
}

Using the Component in HTML To use the PersianDateRanger in your component's template:

<persian-date-ranger
  [placeholder]="'Select a date'"
  (selectedDate)="onDateSelected($event)">
</persian-date-ranger>

Or

<persian-date-ranger
  [placeholder]="'Select a date'"
  [(ngModel)]="date"
  (selectedDate)="onDateSelected($event)">
</persian-date-ranger>

Example of Range Picker (For Reservation) You can use the rangePicker feature to allow users to select a range of dates:

<persian-date-ranger
  [minDate]="'1400/01/01'"
  [maxDate]="'1403/01/01'"
  (selectedDate)="onDateRangeSelected($event)">
</persian-date-ranger>

If you want to use the calendar only for display, you can use the following tag:

<persian-date-calendar></persian-date-calendar>

To select a specific date for display, you can use the following tag:

<persian-date-calendar [selectedMonth]="8" selectedDay="2" [selectedYear]="1403"></persian-date-calendar>

API

Inputs

InputTypeDescription
showNearMonthDaysbooleanDetermines whether the days from the previous and next months should be displayed. Default is true.
showGotoTodaybooleanIf true, shows a button to quickly go to today's date. Default is true.
enableChangeMonthbooleanAllows or disables the ability to change the month. Default is true.
enableChangeYearbooleanAllows or disables the ability to change the year. Default is true.
enableNavigateMonthbooleanEnables or disables the navigation of months using arrows. Default is true.
enableNavigateYearbooleanEnables or disables the navigation of years using arrows. Default is true.
currentMonthShadowbooleanIf true, adds a shadow effect to the current month in the calendar. Default is false.
closeOnSelectDatebooleanDetermines whether the calendar closes automatically when a date is selected. Default is false.
rangePickerbooleanIf true, enables the date range picker, allowing users to select a start and end date. Default is false.
startDateanyThe start date for the date range when rangePicker is enabled.
endDateanyThe end date for the date range when rangePicker is enabled.
showCurrentDatebooleanIf true, highlights the current date in the calendar. Default is false.
holidays{ format: string, date: any[] }Allows you to highlight holidays on the calendar. The format is the date format, and date is an array of holiday dates.
minDatestringThe minimum date allowed for selection. Format: DateFormat.
maxDatestringThe maximum date allowed for selection. Format: DateFormat.
selectedYearnumberThe default selected year in the calendar. Default is the current Persian year.
selectedMonthnumberThe default selected month in the calendar. Default is the current Persian month.
selectedDaynumberThe default selected day in the calendar. Default is the current Persian day.
calendarModebooleanIf true, enables the calendar mode for date selection. Default is false.
datePickerModebooleanIf true, enables the date picker mode, allowing users to select a single date. Default is false.
dateFormatDateFormatThe format for displaying and inputting the date. Possible values include DateFormat.
defaultValuebooleanIf true, the default value is selected when the calendar is first opened. Default is false.
datesBetweenstring[]An array of dates that are part of the selected range. Only applicable if rangePicker is enabled.
minDateDateFormatThe minimum date allowed for selection. Format: DateFormat.
maxDateDateFormatThe maximum date allowed for selection. Format: DateFormat.
placeholderstringPlaceholder text for the input field.
inputClassstringCustom CSS classes for the input element.
rangePickerbooleanEnables or disables date range selection.
returnFormatDateFormatThe format of the returned date. Possible values: DateFormat.
displayModestringControls the display mode of the date picker. Options: inline, popup.
positionstringDefines the position of the calendar relative to the input. Available positions: Positions.
inputDirectivestringUsed to pass a directive to the input and use it within the component, the inputDirective is employed.
useNgModelAsInitialbooleanIf you don't want to use ngModel for the initial value.

Outputs

OutputTypeDescription
selectedDateEventEmitterEmits the selected date (in the specified format). Example: (selectedDate)="onDateSelected($event)"

Methods

MethodDescription
writeValue(value: any)Writes the selected date to the component. Can be used to set the initial value.
registerOnChange(fn: any)Registers a callback to handle changes in the selected date.
registerOnTouched(fn: any)Registers a callback to handle when the input is touched.

Features in Detail

rangePicker The rangePicker feature allows users to select multiple dates in a range (e.g., for reservations). Once enabled, it allows selecting a start date and end date. This feature can be enhanced in future versions to handle more complex range-based use cases.

minDate and maxDate The minDate and maxDate inputs let you restrict the date range the user can select. These dates should be passed in Jalali format (jYYYY/jMM/jDD).

Example usage:

<persian-date-ranger
  [minDate]="'1400/01/01'"
  [maxDate]="'1403/01/01'"
  (selectedDate)="onDateSelected($event)">
</persian-date-ranger>

Date Formats

This package supports several date formats:

jYYYY/jMM/jDD: Persian date format (default). jYYYY-jMM-jDD: Alternative Persian date format. timestamp: Returns the date as a Unix timestamp. YYYY-MM-DD: Gregorian date format. Example usage for date formats:

Positions

position-top
position-bottom
position-left
position-right
position-top-right
position-top-left
position-bottom-right
position-bottom-left

DateFormat

'YYYYMMDD'
'YYYY-MM-DD'
'YYYY/MM/DD'
'jYYYY/jMM/jDD'
'jYYYY-jMM-jDD'
'jYYYYjMMjDD'
'timestamp'
<persian-date-ranger [returnFormat]="'YYYY-MM-DD'"></persian-date-ranger>

Conclusion

You can also use ngModel, ngModelChange, or Forms to capture the data. This feature allows you to easily retrieve data from the inputs and interact with it through two-way binding.

The Persian Date Ranger is a powerful and flexible component for integrating a Persian (Jalali) calendar in Angular applications. It offers a wide range of features, including customizable date formats, date range selection, and flexible positioning, making it perfect for projects that require Persian date support.

2.2.1

5 months ago

2.2.0

5 months ago

2.0.5

5 months ago

2.0.4

5 months ago

2.0.7

5 months ago

2.0.6

5 months ago

2.0.9

5 months ago

2.0.8

5 months ago

2.1.9

5 months ago

2.1.2

5 months ago

2.1.1

5 months ago

2.1.4

5 months ago

2.1.3

5 months ago

2.1.6

5 months ago

2.1.5

5 months ago

2.1.8

5 months ago

2.1.7

5 months ago

2.1.0

5 months ago

0.0.0-watch

11 months ago

2.0.3

11 months ago

2.0.2

11 months ago

2.0.1

12 months ago

2.0.0

12 months ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

0.0.37

1 year ago

0.0.38

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.0.30

1 year ago

0.0.31

1 year ago

0.0.32

1 year ago

0.0.33

1 year ago

0.0.34

1 year ago

0.0.35

1 year ago

0.0.36

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago