项目作者: fericode

项目描述 :
A free JavaScript Jalali (Persian) and Gregorian (Miladi) dual datepicker library for Blazor applications
高级语言: SCSS
项目地址: git://github.com/fericode/Blazor.PersianDatePicker.git
创建时间: 2021-03-29T04:49:54Z
项目社区:https://github.com/fericode/Blazor.PersianDatePicker

开源协议:MIT License

下载


Blazor.PersianDatePicker

NuGet Version
License: MIT

🎈 Optimize design after v2.0.0 | Mark holidays (optional) after v3.5.0 — Thanks to @Mostafa-Moradi for asking the feature

Important fix in v3.4.0 — update your package: The 1403 Jalali leap year was miscalculated therefore all dates in the next Jalali year (1404) were wrong by one day. It is resolved now. Thanks to @web724online for creating the issue.

Important fix in v3.2.0: When we set the bound parameter value to some date by code (for example in the OnInitialize method of our component) and then click on the input, the selected date in the datepicker was always today, not that date. It is resolved now. Thanks to @EsmaeelAmarloo for creating the issue.

Compatibility:

It is compatible and installable on all .NET 5, .NET 6, .NET 7 and .NET 8 Blazor projects

Usage:

1- Install Blazor.PersianDatePicker from Nuget.org

2- Add <script src="_content/Blazor.PersianDatePicker/datepicker.min.js" type="text/javascript"></script> to your index.html or _Host.cshtml or App.razor (in .NET 8)

3- Add <link href="_content/Blazor.PersianDatePicker/datepicker.css" rel="stylesheet" /> to your index.html or _Host.cshtml or App.razor (in .NET 8)

4- Add @using Blazor.PersianDatePicker to _imports.razor

5- Use the component InputPersianDatePicker

Options:

  1. <InputPersianDatePicker
  2. // Html input element id attribute
  3. Id="myInputDatePicker" //Optional
  4. // Bind input value to local variable or dto etc
  5. @bind-Value="_myComponentField"
  6. // Html input element name attribute
  7. Name="myInputName" //Optional
  8. // Control visibility of input
  9. Visible="true" //Default: true
  10. // Disabled make input disabled. This means only showing value and the picker popup won't open
  11. Disabled="false" //Default: false
  12. // Readonly make input readonly. This means the user cannot change the picker value e.g. by typing
  13. ReadOnly="true" //Default: true
  14. // Picker'align relative to input
  15. // Options: Align.Right | Align.Left
  16. PickerAlign="Align.Right" //Default: Align.Right
  17. // Show calendar icon on text input
  18. ShowCalendarIcon="true" //Default: true
  19. // Calendar icon position relative to input
  20. // Options: IconPosition.BasedOnAlign | IconPosition.Left | IconPosition.Right
  21. CalendarIconPosition="IconPosition.BasedOnAlign" //Default: IconPosition.BasedOnAlign
  22. // Can be used in changing the vertical position of the picker popup relative to the input
  23. PickerOffsetTopPositionInPixels="2" //Default: 2
  24. // Initial value for the input set today
  25. InitialValueSetOnToday="false" //Default: false
  26. // Calendar type for date picker including Dual, Single, etc
  27. // Options: Calendar.DualModeJalaliDefault | Calendar.DualModeMiladiDefault | Calendar.SingleModeJalali | Calendar.SingleModeMiladi
  28. CalendarType="Calendar.DualModeJalaliDefault" //Default: Calendar.DualModeJalaliDefault
  29. // Control the digit type showing in the input after selecting by the picker
  30. // Options: DigitType.BasedOnCalendar | DigitType.Persian | DigitType.English
  31. DigitType="DigitType.BasedOnCalendar" //Default: DigitType.BasedOnCalendar
  32. // Format of date to show in the input after selecting by picker, e.g. 1400/01/01 or 1400-01-01
  33. // Options: DateFormat.yyyy_slash_MM_slash_dd | DateFormat.yyyy_dash_MM_dash_dd
  34. DateFormat="DateFormat.yyyy_slash_MM_slash_dd" //Default: DateFormat.yyyy_slash_MM_slash_dd
  35. // Prevent the user from selecting a date before today
  36. MinDateSetOnToday="true" //Default: true
  37. // Input placeholder
  38. Placeholder="Select date"
  39. // CSS class for input element
  40. CssClass="form-control"
  41. // Inline styles for input element
  42. Style="border:1px solid red; width:50%"
  43. // Choose a theme for changing the look and feel of the picker
  44. // Options: PickerTheme.Default | PickerTheme.Dark | PickerTheme.Blue | PickerTheme.Cheerup | PickerTheme.RedBlack
  45. // Themes can be seen in the image
  46. Theme="PickerTheme.Default"
  47. // Mark holidays red color in Persian calendar
  48. MarkHolidays="true" //Default: true
  49. // Mark red color for the dates provided here in the calendar
  50. // Both "/" seperated and "-" seperated Jalali date formats are valid
  51. MarkedDates="@(["1403-06-25", "1403/06/27", "1403/06/28"])" //Optional
  52. // Input change event
  53. OnChange="@(() => Console.WriteLine("OK"))"
  54. // Input text clear event (by pressing close button)
  55. OnClear="@(() => Console.WriteLine("Cleared"))" />

💡 You can add multi-instances of InputPersianDatePicker components on a page and all of them work independently without any problem

Sample template for fast usage:

Copy from here then paste in your project; change some options and you’re done.

  1. <InputPersianDatePicker Id="myInputDatePicker"
  2. @bind-Value="_variable4"
  3. Name="myInputName"
  4. Visible="true"
  5. Disabled="false"
  6. PickerAlign="Align.Right"
  7. PickerOffsetTopPositionInPixels="1"
  8. InitialValueSetOnToday="false"
  9. CalendarType="Calendar.SingleModeJalali"
  10. DigitType="DigitType.BasedOnCalendar"
  11. DateFormat="DateFormat.yyyy_slash_MM_slash_dd"
  12. MinDateSetOnToday="true"
  13. Placeholder="Select date"
  14. CssClass="form-control"
  15. Style="border:1px solid green; width:20%; float:right"
  16. Theme="PickerTheme.RedBlack"
  17. MarkHolidays="true"
  18. MarkedDates="@(["1403-06-25", "1403/06/27", "1403/06/28"])"
  19. OnChange="@(() => Console.WriteLine("OK"))" />

Performance:

  • js size (gzipped) ⇒ 35 kb

  • css size (gzipped) ⇒ 5 kb

  • dll size (gzipped) ⇒‌ 9 kb

Special Thanks:

This project is ported from pwt.datepicker project with a lot of customizations and optimizations for easy and fast use for Blazor applications. Therefore, I appreciate the great effort of Reza Babakhani @babakhani and all contributors of that project