hijri-date-time-picker 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +183 -0
- package/dist/demo.d.ts +8 -0
- package/dist/demo.js +209 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/hijri-date-picker.component.d.ts +86 -0
- package/dist/lib/hijri-date-picker.component.js +647 -0
- package/dist/lib/hijri-date-picker.types.d.ts +84 -0
- package/dist/lib/hijri-date-picker.types.js +21 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Hany
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Hijri Date Time Picker Component
|
|
2
|
+
|
|
3
|
+
An Angular standalone component for dual-mode Gregorian and Hijri date selection with time support using the Umm Al-Qura calendar system.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
✨ **Dual Calendar Support**: Switch between Gregorian and Hijri (Umm Al-Qura) calendars
|
|
8
|
+
🌍 **Localization**: Full support for English and Arabic languages
|
|
9
|
+
↔️ **RTL/LTR**: Automatic layout direction based on locale
|
|
10
|
+
📅 **Multiple Selection**: Single or multiple date selection modes
|
|
11
|
+
🕒 **DateTime Support**: Integrated time selection with modern styling
|
|
12
|
+
🎨 **Customizable Styling**: Comprehensive theming via CSS variables
|
|
13
|
+
✅ **Validation**: Future date validation with configurable limits
|
|
14
|
+
📱 **Responsive**: Mobile-friendly design
|
|
15
|
+
♿ **Accessible**: ARIA labels and keyboard navigation support
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install hijri-date-time-picker hijri-date
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Dependencies
|
|
24
|
+
|
|
25
|
+
- `@angular/core` >= 15.0.0
|
|
26
|
+
- `@angular/common` >= 15.0.0
|
|
27
|
+
- `hijri-date` ^0.2.2
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### Basic Example
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { Component } from '@angular/core';
|
|
35
|
+
import { HijriDatePickerComponent, SelectedDate } from 'hijri-date-time-picker';
|
|
36
|
+
|
|
37
|
+
@Component({
|
|
38
|
+
selector: 'app-root',
|
|
39
|
+
standalone: true,
|
|
40
|
+
imports: [HijriDatePickerComponent],
|
|
41
|
+
template: `
|
|
42
|
+
<hijri-date-picker
|
|
43
|
+
[mode]="'greg'"
|
|
44
|
+
[locale]="'en'"
|
|
45
|
+
(dateSelected)="onDateSelected($event)">
|
|
46
|
+
</hijri-date-picker>
|
|
47
|
+
`
|
|
48
|
+
})
|
|
49
|
+
export class AppComponent {
|
|
50
|
+
onDateSelected(date: SelectedDate) {
|
|
51
|
+
console.log('Selected date:', date);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### DateTime Picker Example
|
|
57
|
+
|
|
58
|
+
```html
|
|
59
|
+
<hijri-date-picker
|
|
60
|
+
[enableTime]="true"
|
|
61
|
+
[timeFormat]="'12'"
|
|
62
|
+
[minuteStep]="15"
|
|
63
|
+
[enableSeconds]="false"
|
|
64
|
+
(dateSelected)="onDateTimeSelected($event)">
|
|
65
|
+
</hijri-date-picker>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Initial Date Binding
|
|
69
|
+
|
|
70
|
+
```html
|
|
71
|
+
<!-- Single Date Selection -->
|
|
72
|
+
<hijri-date-picker
|
|
73
|
+
[initialSelectedDate]="myDate">
|
|
74
|
+
</hijri-date-picker>
|
|
75
|
+
|
|
76
|
+
<!-- Multiple Dates Selection -->
|
|
77
|
+
<hijri-date-picker
|
|
78
|
+
[multiple]="true"
|
|
79
|
+
[initialSelectedDates]="myDates">
|
|
80
|
+
</hijri-date-picker>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## API Reference
|
|
84
|
+
|
|
85
|
+
### Inputs
|
|
86
|
+
|
|
87
|
+
#### Mode & Configuration
|
|
88
|
+
|
|
89
|
+
| Input | Type | Default | Description |
|
|
90
|
+
|-------|------|---------|-------------|
|
|
91
|
+
| `canChangeMode` | `boolean` | `true` | Enable/disable mode toggle button |
|
|
92
|
+
| `mode` | `'greg' \| 'hijri'` | `'greg'` | Initial calendar mode |
|
|
93
|
+
| `dir` | `'ltr' \| 'rtl'` | `'ltr'` | Text direction |
|
|
94
|
+
| `locale` | `'en' \| 'ar'` | `'en'` | Language locale |
|
|
95
|
+
|
|
96
|
+
#### DateTime Configuration (NEW)
|
|
97
|
+
|
|
98
|
+
| Input | Type | Default | Description |
|
|
99
|
+
|-------|------|---------|-------------|
|
|
100
|
+
| `enableTime` | `boolean` | `false` | Enable time selection UI |
|
|
101
|
+
| `timeFormat` | `'12' \| '24'` | `'24'` | Time display format |
|
|
102
|
+
| `minuteStep` | `number` | `1` | Increment step for minutes |
|
|
103
|
+
| `enableSeconds` | `boolean` | `false` | Show seconds selection |
|
|
104
|
+
| `defaultTime` | `{ hours, minutes, seconds? }` | `undefined` | Default time to show |
|
|
105
|
+
|
|
106
|
+
#### Validation
|
|
107
|
+
|
|
108
|
+
| Input | Type | Default | Description |
|
|
109
|
+
|-------|------|---------|-------------|
|
|
110
|
+
| `futureValidation` | `boolean` | `true` | Prevent selecting dates beyond limit |
|
|
111
|
+
| `futureYearsLimit` | `number` | `10` | Maximum years in the future |
|
|
112
|
+
| `isRequired` | `boolean` | `false` | Require date selection before submit |
|
|
113
|
+
|
|
114
|
+
#### Selection & Binding
|
|
115
|
+
|
|
116
|
+
| Input | Type | Default | Description |
|
|
117
|
+
|-------|------|---------|-------------|
|
|
118
|
+
| `multiple` | `boolean` | `false` | Enable multiple date selection |
|
|
119
|
+
| `showConfirmButton` | `boolean` | `false` | Show submit button |
|
|
120
|
+
| `initialSelectedDate` | `Date` | `undefined` | Pre-select a single date |
|
|
121
|
+
| `initialSelectedDates` | `Date[]` | `[]` | Pre-select multiple dates |
|
|
122
|
+
|
|
123
|
+
#### Labels
|
|
124
|
+
|
|
125
|
+
| Input | Type | Default | Description |
|
|
126
|
+
|-------|------|---------|-------------|
|
|
127
|
+
| `submitTextButton` | `string` | `'Submit'` | Submit button text |
|
|
128
|
+
| `todaysDateText` | `string` | `'Today'` | Today button text |
|
|
129
|
+
| `ummAlQuraDateText` | `string` | `'Umm Al-Qura Calendar'` | Calendar type label |
|
|
130
|
+
| `yearSelectLabel` | `string` | `'Year'` | Year dropdown label |
|
|
131
|
+
| `monthSelectLabel` | `string` | `'Month'` | Month dropdown label |
|
|
132
|
+
|
|
133
|
+
### Outputs
|
|
134
|
+
|
|
135
|
+
| Output | Type | Description |
|
|
136
|
+
|--------|------|-------------|
|
|
137
|
+
| `dateSelected` | `EventEmitter<SelectedDate \| SelectedDate[]>` | Emits when date(s) selected |
|
|
138
|
+
| `modeChanged` | `EventEmitter<'greg' \| 'hijri'>` | Emits when calendar mode changes |
|
|
139
|
+
|
|
140
|
+
### Types
|
|
141
|
+
|
|
142
|
+
#### SelectedDate
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
interface SelectedDate {
|
|
146
|
+
gregorian: Date;
|
|
147
|
+
hijri: {
|
|
148
|
+
year: number;
|
|
149
|
+
month: number;
|
|
150
|
+
day: number;
|
|
151
|
+
};
|
|
152
|
+
time?: {
|
|
153
|
+
hours: number;
|
|
154
|
+
minutes: number;
|
|
155
|
+
seconds: number;
|
|
156
|
+
};
|
|
157
|
+
formatted: {
|
|
158
|
+
gregorian: string;
|
|
159
|
+
hijri: string;
|
|
160
|
+
time?: string;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Styling
|
|
166
|
+
|
|
167
|
+
The component can be customized using the `styles` input or by overriding CSS variables:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
const customStyles: DatePickerStyles = {
|
|
171
|
+
primaryColor: '#4f46e5',
|
|
172
|
+
secondaryColor: '#818cf8',
|
|
173
|
+
borderRadius: '8px'
|
|
174
|
+
};
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT
|
|
180
|
+
|
|
181
|
+
## Credits
|
|
182
|
+
|
|
183
|
+
Built with [Angular](https://angular.io/) and [hijri-date](https://www.npmjs.com/package/hijri-date).
|
package/dist/demo.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SelectedDate, DatePickerStyles } from './lib/hijri-date-picker.component';
|
|
2
|
+
export declare class DemoComponent {
|
|
3
|
+
selectedDates: {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
};
|
|
6
|
+
customStyles: DatePickerStyles;
|
|
7
|
+
onDateSelected(date: SelectedDate | SelectedDate[], key: string): void;
|
|
8
|
+
}
|
package/dist/demo.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Component } from '@angular/core';
|
|
8
|
+
import { bootstrapApplication } from '@angular/platform-browser';
|
|
9
|
+
import { HijriDatePickerComponent } from './lib/hijri-date-picker.component';
|
|
10
|
+
let DemoComponent = class DemoComponent {
|
|
11
|
+
selectedDates = {};
|
|
12
|
+
customStyles = {
|
|
13
|
+
primaryColor: '#059669',
|
|
14
|
+
secondaryColor: '#34d399',
|
|
15
|
+
selectedDateBackground: '#059669',
|
|
16
|
+
todayColor: '#f59e0b',
|
|
17
|
+
borderRadius: '12px',
|
|
18
|
+
fontFamily: 'Inter, sans-serif'
|
|
19
|
+
};
|
|
20
|
+
onDateSelected(date, key) {
|
|
21
|
+
this.selectedDates[key] = date;
|
|
22
|
+
console.log(`Date selected for ${key}:`, date);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
DemoComponent = __decorate([
|
|
26
|
+
Component({
|
|
27
|
+
selector: 'app-demo',
|
|
28
|
+
standalone: true,
|
|
29
|
+
imports: [HijriDatePickerComponent],
|
|
30
|
+
template: `
|
|
31
|
+
<div class="demo-container">
|
|
32
|
+
<h1>Hijri Date Picker Demo</h1>
|
|
33
|
+
|
|
34
|
+
<div class="demo-grid">
|
|
35
|
+
<!-- Example 1: Basic Gregorian -->
|
|
36
|
+
<div class="demo-card">
|
|
37
|
+
<h2>Basic Gregorian</h2>
|
|
38
|
+
<hijri-date-picker
|
|
39
|
+
[mode]="'greg'"
|
|
40
|
+
[locale]="'en'"
|
|
41
|
+
[canChangeMode]="true"
|
|
42
|
+
(dateSelected)="onDateSelected($event, 'basic')">
|
|
43
|
+
</hijri-date-picker>
|
|
44
|
+
<div class="output" *ngIf="selectedDates['basic']">
|
|
45
|
+
<strong>Selected:</strong>
|
|
46
|
+
<pre>{{ selectedDates['basic'] | json }}</pre>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
<!-- Example 2: Hijri with Arabic -->
|
|
51
|
+
<div class="demo-card">
|
|
52
|
+
<h2>Hijri Calendar (Arabic)</h2>
|
|
53
|
+
<hijri-date-picker
|
|
54
|
+
[mode]="'hijri'"
|
|
55
|
+
[locale]="'ar'"
|
|
56
|
+
[dir]="'rtl'"
|
|
57
|
+
[canChangeMode]="true"
|
|
58
|
+
[submitTextButton]="'تأكيد'"
|
|
59
|
+
[todaysDateText]="'اليوم'"
|
|
60
|
+
[yearSelectLabel]="'السنة'"
|
|
61
|
+
[monthSelectLabel]="'الشهر'"
|
|
62
|
+
(dateSelected)="onDateSelected($event, 'hijri')">
|
|
63
|
+
</hijri-date-picker>
|
|
64
|
+
<div class="output" *ngIf="selectedDates['hijri']">
|
|
65
|
+
<strong>Selected:</strong>
|
|
66
|
+
<pre>{{ selectedDates['hijri'] | json }}</pre>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<!-- Example 3: Multiple Selection -->
|
|
71
|
+
<div class="demo-card">
|
|
72
|
+
<h2>Multiple Selection</h2>
|
|
73
|
+
<hijri-date-picker
|
|
74
|
+
[mode]="'greg'"
|
|
75
|
+
[locale]="'en'"
|
|
76
|
+
[multiple]="true"
|
|
77
|
+
[showConfirmButton]="true"
|
|
78
|
+
[submitTextButton]="'Confirm Selection'"
|
|
79
|
+
(dateSelected)="onDateSelected($event, 'multiple')">
|
|
80
|
+
</hijri-date-picker>
|
|
81
|
+
<div class="output" *ngIf="selectedDates['multiple']">
|
|
82
|
+
<strong>Selected Dates:</strong>
|
|
83
|
+
<pre>{{ selectedDates['multiple'] | json }}</pre>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<!-- Example 4: Custom Styling -->
|
|
88
|
+
<div class="demo-card">
|
|
89
|
+
<h2>Custom Theme</h2>
|
|
90
|
+
<hijri-date-picker
|
|
91
|
+
[mode]="'greg'"
|
|
92
|
+
[locale]="'en'"
|
|
93
|
+
[styles]="customStyles"
|
|
94
|
+
[canChangeMode]="true"
|
|
95
|
+
(dateSelected)="onDateSelected($event, 'custom')">
|
|
96
|
+
</hijri-date-picker>
|
|
97
|
+
<div class="output" *ngIf="selectedDates['custom']">
|
|
98
|
+
<strong>Selected:</strong>
|
|
99
|
+
<pre>{{ selectedDates['custom'] | json }}</pre>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
|
|
103
|
+
<!-- Example 5: Future Date Validation -->
|
|
104
|
+
<div class="demo-card">
|
|
105
|
+
<h2>No Future Dates</h2>
|
|
106
|
+
<hijri-date-picker
|
|
107
|
+
[mode]="'greg'"
|
|
108
|
+
[locale]="'en'"
|
|
109
|
+
[futureValidation]="true"
|
|
110
|
+
[futureYearsLimit]="0"
|
|
111
|
+
[todaysDateText]="'Select Today'"
|
|
112
|
+
(dateSelected)="onDateSelected($event, 'validation')">
|
|
113
|
+
</hijri-date-picker>
|
|
114
|
+
<div class="output" *ngIf="selectedDates['validation']">
|
|
115
|
+
<strong>Selected:</strong>
|
|
116
|
+
<pre>{{ selectedDates['validation'] | json }}</pre>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
<!-- Example 6: Minimal UI -->
|
|
121
|
+
<div class="demo-card">
|
|
122
|
+
<h2>Minimal UI</h2>
|
|
123
|
+
<hijri-date-picker
|
|
124
|
+
[mode]="'greg'"
|
|
125
|
+
[locale]="'en'"
|
|
126
|
+
[canChangeMode]="false"
|
|
127
|
+
[todaysDateSection]="false"
|
|
128
|
+
[disableYearPicker]="true"
|
|
129
|
+
[disableMonthPicker]="true"
|
|
130
|
+
(dateSelected)="onDateSelected($event, 'minimal')">
|
|
131
|
+
</hijri-date-picker>
|
|
132
|
+
<div class="output" *ngIf="selectedDates['minimal']">
|
|
133
|
+
<strong>Selected:</strong>
|
|
134
|
+
<pre>{{ selectedDates['minimal'] | json }}</pre>
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
`,
|
|
140
|
+
styles: [`
|
|
141
|
+
.demo-container {
|
|
142
|
+
max-width: 1400px;
|
|
143
|
+
margin: 0 auto;
|
|
144
|
+
padding: 40px 20px;
|
|
145
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
h1 {
|
|
149
|
+
text-align: center;
|
|
150
|
+
color: #1f2937;
|
|
151
|
+
margin-bottom: 40px;
|
|
152
|
+
font-size: 2.5rem;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.demo-grid {
|
|
156
|
+
display: grid;
|
|
157
|
+
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
|
|
158
|
+
gap: 30px;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.demo-card {
|
|
162
|
+
background: white;
|
|
163
|
+
border-radius: 12px;
|
|
164
|
+
padding: 24px;
|
|
165
|
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.demo-card h2 {
|
|
169
|
+
margin-top: 0;
|
|
170
|
+
margin-bottom: 20px;
|
|
171
|
+
color: #374151;
|
|
172
|
+
font-size: 1.25rem;
|
|
173
|
+
border-bottom: 2px solid #e5e7eb;
|
|
174
|
+
padding-bottom: 10px;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.output {
|
|
178
|
+
margin-top: 20px;
|
|
179
|
+
padding: 16px;
|
|
180
|
+
background: #f9fafb;
|
|
181
|
+
border-radius: 8px;
|
|
182
|
+
border: 1px solid #e5e7eb;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.output strong {
|
|
186
|
+
display: block;
|
|
187
|
+
margin-bottom: 8px;
|
|
188
|
+
color: #374151;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.output pre {
|
|
192
|
+
margin: 0;
|
|
193
|
+
font-size: 12px;
|
|
194
|
+
color: #6b7280;
|
|
195
|
+
white-space: pre-wrap;
|
|
196
|
+
word-wrap: break-word;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@media (max-width: 768px) {
|
|
200
|
+
.demo-grid {
|
|
201
|
+
grid-template-columns: 1fr;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
`]
|
|
205
|
+
})
|
|
206
|
+
], DemoComponent);
|
|
207
|
+
export { DemoComponent };
|
|
208
|
+
// Bootstrap the demo application
|
|
209
|
+
bootstrapApplication(DemoComponent);
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { EventEmitter, OnInit, OnChanges, SimpleChanges } from '@angular/core';
|
|
2
|
+
import { DateMode, Direction, Locale, SelectedDate, DatePickerStyles, TimeFormat } from './hijri-date-picker.types';
|
|
3
|
+
export declare class HijriDatePickerComponent implements OnInit, OnChanges {
|
|
4
|
+
canChangeMode: boolean;
|
|
5
|
+
mode: DateMode;
|
|
6
|
+
dir: Direction;
|
|
7
|
+
locale: Locale;
|
|
8
|
+
futureValidation: boolean;
|
|
9
|
+
futureYearsLimit: number;
|
|
10
|
+
isRequired: boolean;
|
|
11
|
+
multiple: boolean;
|
|
12
|
+
showConfirmButton: boolean;
|
|
13
|
+
initialSelectedDate?: Date;
|
|
14
|
+
initialSelectedDates?: Date[];
|
|
15
|
+
submitTextButton: string;
|
|
16
|
+
todaysDateText: string;
|
|
17
|
+
ummAlQuraDateText: string;
|
|
18
|
+
yearSelectLabel: string;
|
|
19
|
+
monthSelectLabel: string;
|
|
20
|
+
todaysDateSection: boolean;
|
|
21
|
+
markToday: boolean;
|
|
22
|
+
disableYearPicker: boolean;
|
|
23
|
+
disableMonthPicker: boolean;
|
|
24
|
+
disableDayPicker: boolean;
|
|
25
|
+
styles: DatePickerStyles;
|
|
26
|
+
enableTime: boolean;
|
|
27
|
+
timeFormat: TimeFormat;
|
|
28
|
+
minuteStep: number;
|
|
29
|
+
enableSeconds: boolean;
|
|
30
|
+
defaultTime?: {
|
|
31
|
+
hours: number;
|
|
32
|
+
minutes: number;
|
|
33
|
+
seconds?: number;
|
|
34
|
+
};
|
|
35
|
+
dateSelected: EventEmitter<SelectedDate | SelectedDate[]>;
|
|
36
|
+
modeChanged: EventEmitter<DateMode>;
|
|
37
|
+
currentYear: number;
|
|
38
|
+
currentMonth: number;
|
|
39
|
+
currentHijriYear: number;
|
|
40
|
+
currentHijriMonth: number;
|
|
41
|
+
selectedDates: SelectedDate[];
|
|
42
|
+
calendarDays: any[];
|
|
43
|
+
today: Date;
|
|
44
|
+
years: number[];
|
|
45
|
+
months: string[];
|
|
46
|
+
weekdays: string[];
|
|
47
|
+
selectedTime: {
|
|
48
|
+
hours: number;
|
|
49
|
+
minutes: number;
|
|
50
|
+
seconds: number;
|
|
51
|
+
};
|
|
52
|
+
isPM: boolean;
|
|
53
|
+
ngOnInit(): void;
|
|
54
|
+
ngOnChanges(changes: SimpleChanges): void;
|
|
55
|
+
private initializeCalendar;
|
|
56
|
+
private initializeSelectedDates;
|
|
57
|
+
private initializeTime;
|
|
58
|
+
private updateLocaleData;
|
|
59
|
+
private generateYears;
|
|
60
|
+
private generateCalendar;
|
|
61
|
+
private generateGregorianCalendar;
|
|
62
|
+
private generateHijriCalendar;
|
|
63
|
+
private getDaysInHijriMonth;
|
|
64
|
+
private isSameDay;
|
|
65
|
+
private isDateDisabled;
|
|
66
|
+
private isDateSelected;
|
|
67
|
+
onDayClick(dayInfo: any): void;
|
|
68
|
+
private createSelectedDate;
|
|
69
|
+
private formatGregorianDate;
|
|
70
|
+
private formatHijriDate;
|
|
71
|
+
onYearChange(event: Event): void;
|
|
72
|
+
onMonthChange(event: Event): void;
|
|
73
|
+
previousMonth(): void;
|
|
74
|
+
nextMonth(): void;
|
|
75
|
+
toggleMode(): void;
|
|
76
|
+
selectToday(): void;
|
|
77
|
+
onSubmit(): void;
|
|
78
|
+
incrementTime(type: 'hours' | 'minutes' | 'seconds'): void;
|
|
79
|
+
decrementTime(type: 'hours' | 'minutes' | 'seconds'): void;
|
|
80
|
+
onTimeChange(type: 'hours' | 'minutes' | 'seconds', event: any): void;
|
|
81
|
+
setAMPM(pm: boolean): void;
|
|
82
|
+
private formatTime;
|
|
83
|
+
private updateSelectedDateTime;
|
|
84
|
+
getCustomStyles(): any;
|
|
85
|
+
}
|
|
86
|
+
export type { SelectedDate, DatePickerStyles, DateMode, Direction, Locale };
|
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
|
11
|
+
import { CommonModule } from '@angular/common';
|
|
12
|
+
import HijriDate, { toHijri } from 'hijri-date/lib/safe';
|
|
13
|
+
import { GREGORIAN_MONTHS_EN, GREGORIAN_MONTHS_AR, HIJRI_MONTHS_EN, HIJRI_MONTHS_AR, WEEKDAY_NAMES_EN, WEEKDAY_NAMES_AR } from './hijri-date-picker.types';
|
|
14
|
+
let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
15
|
+
// Mode & Configuration
|
|
16
|
+
canChangeMode = true;
|
|
17
|
+
mode = 'greg';
|
|
18
|
+
dir = 'ltr';
|
|
19
|
+
locale = 'en';
|
|
20
|
+
// Validation
|
|
21
|
+
futureValidation = true;
|
|
22
|
+
futureYearsLimit = 10;
|
|
23
|
+
isRequired = false;
|
|
24
|
+
// Selection
|
|
25
|
+
multiple = false;
|
|
26
|
+
showConfirmButton = false;
|
|
27
|
+
initialSelectedDate; // For single selection mode - bind initial date
|
|
28
|
+
initialSelectedDates; // For multiple selection mode - bind initial dates
|
|
29
|
+
// Labels
|
|
30
|
+
submitTextButton = 'Submit';
|
|
31
|
+
todaysDateText = 'Today';
|
|
32
|
+
ummAlQuraDateText = 'Umm Al-Qura Calendar';
|
|
33
|
+
yearSelectLabel = 'Year';
|
|
34
|
+
monthSelectLabel = 'Month';
|
|
35
|
+
// Display Options
|
|
36
|
+
todaysDateSection = true;
|
|
37
|
+
markToday = true;
|
|
38
|
+
disableYearPicker = false;
|
|
39
|
+
disableMonthPicker = false;
|
|
40
|
+
disableDayPicker = false;
|
|
41
|
+
// Styling
|
|
42
|
+
styles = {};
|
|
43
|
+
// Time Configuration
|
|
44
|
+
enableTime = false;
|
|
45
|
+
timeFormat = '24';
|
|
46
|
+
minuteStep = 1;
|
|
47
|
+
enableSeconds = false;
|
|
48
|
+
defaultTime;
|
|
49
|
+
// Outputs
|
|
50
|
+
dateSelected = new EventEmitter();
|
|
51
|
+
modeChanged = new EventEmitter();
|
|
52
|
+
// Internal State
|
|
53
|
+
currentYear = new Date().getFullYear();
|
|
54
|
+
currentMonth = new Date().getMonth();
|
|
55
|
+
currentHijriYear = 0;
|
|
56
|
+
currentHijriMonth = 0;
|
|
57
|
+
selectedDates = [];
|
|
58
|
+
calendarDays = [];
|
|
59
|
+
today = new Date();
|
|
60
|
+
years = [];
|
|
61
|
+
months = [];
|
|
62
|
+
weekdays = [];
|
|
63
|
+
// Time state
|
|
64
|
+
selectedTime = {
|
|
65
|
+
hours: 0,
|
|
66
|
+
minutes: 0,
|
|
67
|
+
seconds: 0
|
|
68
|
+
};
|
|
69
|
+
isPM = false;
|
|
70
|
+
ngOnInit() {
|
|
71
|
+
this.initializeCalendar();
|
|
72
|
+
this.initializeSelectedDates();
|
|
73
|
+
this.initializeTime();
|
|
74
|
+
this.updateLocaleData();
|
|
75
|
+
this.generateYears();
|
|
76
|
+
this.generateCalendar();
|
|
77
|
+
}
|
|
78
|
+
ngOnChanges(changes) {
|
|
79
|
+
if (changes['mode'] || changes['locale']) {
|
|
80
|
+
this.updateLocaleData();
|
|
81
|
+
this.generateCalendar();
|
|
82
|
+
}
|
|
83
|
+
// Handle changes to initial selected dates
|
|
84
|
+
if (changes['initialSelectedDate'] || changes['initialSelectedDates']) {
|
|
85
|
+
this.initializeSelectedDates();
|
|
86
|
+
this.generateCalendar();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
initializeCalendar() {
|
|
90
|
+
const hijriToday = new HijriDate();
|
|
91
|
+
this.currentHijriYear = hijriToday.getFullYear();
|
|
92
|
+
this.currentHijriMonth = hijriToday.getMonth();
|
|
93
|
+
}
|
|
94
|
+
initializeSelectedDates() {
|
|
95
|
+
// Handle single selection mode
|
|
96
|
+
if (!this.multiple && this.initialSelectedDate) {
|
|
97
|
+
this.selectedDates = [this.createSelectedDate(this.initialSelectedDate)];
|
|
98
|
+
}
|
|
99
|
+
// Handle multiple selection mode
|
|
100
|
+
if (this.multiple && this.initialSelectedDates && this.initialSelectedDates.length > 0) {
|
|
101
|
+
this.selectedDates = this.initialSelectedDates.map(date => this.createSelectedDate(date));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
initializeTime() {
|
|
105
|
+
if (!this.enableTime) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
// Set default time if provided
|
|
109
|
+
if (this.defaultTime) {
|
|
110
|
+
this.selectedTime = {
|
|
111
|
+
hours: this.defaultTime.hours,
|
|
112
|
+
minutes: this.defaultTime.minutes,
|
|
113
|
+
seconds: this.defaultTime.seconds || 0
|
|
114
|
+
};
|
|
115
|
+
// Set AM/PM for 12-hour format
|
|
116
|
+
if (this.timeFormat === '12') {
|
|
117
|
+
this.isPM = this.selectedTime.hours >= 12;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// Default to current time
|
|
122
|
+
const now = new Date();
|
|
123
|
+
this.selectedTime = {
|
|
124
|
+
hours: now.getHours(),
|
|
125
|
+
minutes: now.getMinutes(),
|
|
126
|
+
seconds: now.getSeconds()
|
|
127
|
+
};
|
|
128
|
+
this.isPM = this.selectedTime.hours >= 12;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
updateLocaleData() {
|
|
132
|
+
// Update weekday names
|
|
133
|
+
this.weekdays = this.locale === 'ar' ? WEEKDAY_NAMES_AR : WEEKDAY_NAMES_EN;
|
|
134
|
+
// Update month names based on mode and locale
|
|
135
|
+
if (this.mode === 'hijri') {
|
|
136
|
+
this.months = this.locale === 'ar' ? HIJRI_MONTHS_AR : HIJRI_MONTHS_EN;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.months = this.locale === 'ar' ? GREGORIAN_MONTHS_AR : GREGORIAN_MONTHS_EN;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
generateYears() {
|
|
143
|
+
const currentYear = this.mode === 'hijri' ? this.currentHijriYear : this.currentYear;
|
|
144
|
+
const startYear = currentYear - 100;
|
|
145
|
+
const endYear = currentYear + this.futureYearsLimit;
|
|
146
|
+
this.years = [];
|
|
147
|
+
for (let year = startYear; year <= endYear; year++) {
|
|
148
|
+
this.years.push(year);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
generateCalendar() {
|
|
152
|
+
this.calendarDays = [];
|
|
153
|
+
if (this.mode === 'hijri') {
|
|
154
|
+
this.generateHijriCalendar();
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
this.generateGregorianCalendar();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
generateGregorianCalendar() {
|
|
161
|
+
const firstDay = new Date(this.currentYear, this.currentMonth, 1);
|
|
162
|
+
const lastDay = new Date(this.currentYear, this.currentMonth + 1, 0);
|
|
163
|
+
const startingDayOfWeek = firstDay.getDay();
|
|
164
|
+
const daysInMonth = lastDay.getDate();
|
|
165
|
+
// Add empty cells for days before the first day of the month
|
|
166
|
+
for (let i = 0; i < startingDayOfWeek; i++) {
|
|
167
|
+
this.calendarDays.push({ day: null, disabled: true });
|
|
168
|
+
}
|
|
169
|
+
// Add days of the month
|
|
170
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
171
|
+
const date = new Date(this.currentYear, this.currentMonth, day);
|
|
172
|
+
const isToday = this.isSameDay(date, this.today);
|
|
173
|
+
const isDisabled = this.isDateDisabled(date);
|
|
174
|
+
const isSelected = this.isDateSelected(date);
|
|
175
|
+
this.calendarDays.push({
|
|
176
|
+
day,
|
|
177
|
+
date,
|
|
178
|
+
isToday,
|
|
179
|
+
isDisabled,
|
|
180
|
+
isSelected,
|
|
181
|
+
disabled: false
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
generateHijriCalendar() {
|
|
186
|
+
const hijriDate = new HijriDate(this.currentHijriYear, this.currentHijriMonth, 1);
|
|
187
|
+
const gregorianDate = hijriDate.toGregorian();
|
|
188
|
+
const startingDayOfWeek = gregorianDate.getDay();
|
|
189
|
+
// Get days in Hijri month (typically 29 or 30)
|
|
190
|
+
const daysInMonth = this.getDaysInHijriMonth(this.currentHijriYear, this.currentHijriMonth);
|
|
191
|
+
// Add empty cells for days before the first day of the month
|
|
192
|
+
for (let i = 0; i < startingDayOfWeek; i++) {
|
|
193
|
+
this.calendarDays.push({ day: null, disabled: true });
|
|
194
|
+
}
|
|
195
|
+
// Add days of the month
|
|
196
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
197
|
+
const hijriDay = new HijriDate(this.currentHijriYear, this.currentHijriMonth, day);
|
|
198
|
+
const gregorianDay = hijriDay.toGregorian();
|
|
199
|
+
const isToday = this.isSameDay(gregorianDay, this.today);
|
|
200
|
+
const isDisabled = this.isDateDisabled(gregorianDay);
|
|
201
|
+
const isSelected = this.isDateSelected(gregorianDay);
|
|
202
|
+
this.calendarDays.push({
|
|
203
|
+
day,
|
|
204
|
+
date: gregorianDay,
|
|
205
|
+
hijriDate: hijriDay,
|
|
206
|
+
isToday,
|
|
207
|
+
isDisabled,
|
|
208
|
+
isSelected,
|
|
209
|
+
disabled: false
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
getDaysInHijriMonth(year, month) {
|
|
214
|
+
// Try to create the 30th day; if it fails, the month has 29 days
|
|
215
|
+
try {
|
|
216
|
+
new HijriDate(year, month, 30);
|
|
217
|
+
return 30;
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
return 29;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
isSameDay(date1, date2) {
|
|
224
|
+
return date1.getFullYear() === date2.getFullYear() &&
|
|
225
|
+
date1.getMonth() === date2.getMonth() &&
|
|
226
|
+
date1.getDate() === date2.getDate();
|
|
227
|
+
}
|
|
228
|
+
isDateDisabled(date) {
|
|
229
|
+
if (this.futureValidation) {
|
|
230
|
+
const maxDate = new Date();
|
|
231
|
+
maxDate.setFullYear(maxDate.getFullYear() + this.futureYearsLimit);
|
|
232
|
+
return date > maxDate;
|
|
233
|
+
}
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
isDateSelected(date) {
|
|
237
|
+
return this.selectedDates.some(selected => this.isSameDay(selected.gregorian, date));
|
|
238
|
+
}
|
|
239
|
+
onDayClick(dayInfo) {
|
|
240
|
+
if (dayInfo.disabled || dayInfo.isDisabled) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const selectedDate = this.createSelectedDate(dayInfo.date);
|
|
244
|
+
if (this.multiple) {
|
|
245
|
+
const index = this.selectedDates.findIndex(d => this.isSameDay(d.gregorian, dayInfo.date));
|
|
246
|
+
if (index > -1) {
|
|
247
|
+
this.selectedDates.splice(index, 1);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
this.selectedDates.push(selectedDate);
|
|
251
|
+
}
|
|
252
|
+
if (!this.showConfirmButton) {
|
|
253
|
+
this.dateSelected.emit([...this.selectedDates]);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
this.selectedDates = [selectedDate];
|
|
258
|
+
if (!this.showConfirmButton) {
|
|
259
|
+
this.dateSelected.emit(selectedDate);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
this.generateCalendar();
|
|
263
|
+
}
|
|
264
|
+
createSelectedDate(date) {
|
|
265
|
+
const hijriDate = toHijri(date);
|
|
266
|
+
// If time is enabled, set the time on the date object
|
|
267
|
+
if (this.enableTime) {
|
|
268
|
+
let hours24 = this.selectedTime.hours;
|
|
269
|
+
if (this.timeFormat === '12') {
|
|
270
|
+
if (this.isPM && this.selectedTime.hours !== 12) {
|
|
271
|
+
hours24 = this.selectedTime.hours + 12;
|
|
272
|
+
}
|
|
273
|
+
else if (!this.isPM && this.selectedTime.hours === 12) {
|
|
274
|
+
hours24 = 0;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
date.setHours(hours24, this.selectedTime.minutes, this.selectedTime.seconds);
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
gregorian: date,
|
|
281
|
+
hijri: {
|
|
282
|
+
year: hijriDate.getFullYear(),
|
|
283
|
+
month: hijriDate.getMonth(),
|
|
284
|
+
day: hijriDate.getDate()
|
|
285
|
+
},
|
|
286
|
+
time: this.enableTime ? {
|
|
287
|
+
hours: date.getHours(),
|
|
288
|
+
minutes: date.getMinutes(),
|
|
289
|
+
seconds: date.getSeconds()
|
|
290
|
+
} : undefined,
|
|
291
|
+
formatted: {
|
|
292
|
+
gregorian: this.formatGregorianDate(date),
|
|
293
|
+
hijri: this.formatHijriDate(hijriDate),
|
|
294
|
+
time: this.enableTime ? this.formatTime(date.getHours(), date.getMinutes(), date.getSeconds()) : undefined
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
formatGregorianDate(date) {
|
|
299
|
+
const day = date.getDate();
|
|
300
|
+
const month = this.locale === 'ar' ? GREGORIAN_MONTHS_AR[date.getMonth()] : GREGORIAN_MONTHS_EN[date.getMonth()];
|
|
301
|
+
const year = date.getFullYear();
|
|
302
|
+
return this.locale === 'ar'
|
|
303
|
+
? `${day} ${month} ${year}`
|
|
304
|
+
: `${month} ${day}, ${year}`;
|
|
305
|
+
}
|
|
306
|
+
formatHijriDate(hijriDate) {
|
|
307
|
+
const day = hijriDate.getDate();
|
|
308
|
+
const month = this.locale === 'ar'
|
|
309
|
+
? HIJRI_MONTHS_AR[hijriDate.getMonth()]
|
|
310
|
+
: HIJRI_MONTHS_EN[hijriDate.getMonth()];
|
|
311
|
+
const year = hijriDate.getFullYear();
|
|
312
|
+
return this.locale === 'ar'
|
|
313
|
+
? `${day} ${month} ${year} هـ`
|
|
314
|
+
: `${day} ${month} ${year} AH`;
|
|
315
|
+
}
|
|
316
|
+
onYearChange(event) {
|
|
317
|
+
const year = parseInt(event.target.value);
|
|
318
|
+
if (this.mode === 'hijri') {
|
|
319
|
+
this.currentHijriYear = year;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
this.currentYear = year;
|
|
323
|
+
}
|
|
324
|
+
this.generateCalendar();
|
|
325
|
+
}
|
|
326
|
+
onMonthChange(event) {
|
|
327
|
+
const month = parseInt(event.target.value);
|
|
328
|
+
if (this.mode === 'hijri') {
|
|
329
|
+
this.currentHijriMonth = month;
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
this.currentMonth = month;
|
|
333
|
+
}
|
|
334
|
+
this.generateCalendar();
|
|
335
|
+
}
|
|
336
|
+
previousMonth() {
|
|
337
|
+
if (this.mode === 'hijri') {
|
|
338
|
+
if (this.currentHijriMonth === 0) {
|
|
339
|
+
this.currentHijriMonth = 11;
|
|
340
|
+
this.currentHijriYear--;
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
this.currentHijriMonth--;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
if (this.currentMonth === 0) {
|
|
348
|
+
this.currentMonth = 11;
|
|
349
|
+
this.currentYear--;
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
this.currentMonth--;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
this.generateCalendar();
|
|
356
|
+
}
|
|
357
|
+
nextMonth() {
|
|
358
|
+
if (this.mode === 'hijri') {
|
|
359
|
+
if (this.currentHijriMonth === 11) {
|
|
360
|
+
this.currentHijriMonth = 0;
|
|
361
|
+
this.currentHijriYear++;
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
this.currentHijriMonth++;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
if (this.currentMonth === 11) {
|
|
369
|
+
this.currentMonth = 0;
|
|
370
|
+
this.currentYear++;
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
this.currentMonth++;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
this.generateCalendar();
|
|
377
|
+
}
|
|
378
|
+
toggleMode() {
|
|
379
|
+
if (!this.canChangeMode) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
this.mode = this.mode === 'greg' ? 'hijri' : 'greg';
|
|
383
|
+
this.updateLocaleData();
|
|
384
|
+
this.generateYears();
|
|
385
|
+
this.generateCalendar();
|
|
386
|
+
this.modeChanged.emit(this.mode);
|
|
387
|
+
}
|
|
388
|
+
selectToday() {
|
|
389
|
+
const today = new Date();
|
|
390
|
+
this.onDayClick({ date: today, disabled: false, isDisabled: false });
|
|
391
|
+
}
|
|
392
|
+
onSubmit() {
|
|
393
|
+
if (this.isRequired && this.selectedDates.length === 0) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (this.multiple) {
|
|
397
|
+
this.dateSelected.emit([...this.selectedDates]);
|
|
398
|
+
}
|
|
399
|
+
else if (this.selectedDates.length > 0) {
|
|
400
|
+
this.dateSelected.emit(this.selectedDates[0]);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
// Time handling methods
|
|
404
|
+
incrementTime(type) {
|
|
405
|
+
if (type === 'hours') {
|
|
406
|
+
const max = this.timeFormat === '12' ? 12 : 23;
|
|
407
|
+
this.selectedTime.hours = (this.selectedTime.hours + 1) > max ? (this.timeFormat === '12' ? 1 : 0) : this.selectedTime.hours + 1;
|
|
408
|
+
}
|
|
409
|
+
else if (type === 'minutes') {
|
|
410
|
+
this.selectedTime.minutes = (this.selectedTime.minutes + this.minuteStep) > 59 ? 0 : this.selectedTime.minutes + this.minuteStep;
|
|
411
|
+
}
|
|
412
|
+
else if (type === 'seconds') {
|
|
413
|
+
this.selectedTime.seconds = (this.selectedTime.seconds + 1) > 59 ? 0 : this.selectedTime.seconds + 1;
|
|
414
|
+
}
|
|
415
|
+
this.updateSelectedDateTime();
|
|
416
|
+
}
|
|
417
|
+
decrementTime(type) {
|
|
418
|
+
if (type === 'hours') {
|
|
419
|
+
const min = this.timeFormat === '12' ? 1 : 0;
|
|
420
|
+
const max = this.timeFormat === '12' ? 12 : 23;
|
|
421
|
+
this.selectedTime.hours = (this.selectedTime.hours - 1) < min ? max : this.selectedTime.hours - 1;
|
|
422
|
+
}
|
|
423
|
+
else if (type === 'minutes') {
|
|
424
|
+
this.selectedTime.minutes = (this.selectedTime.minutes - this.minuteStep) < 0 ? 59 : this.selectedTime.minutes - this.minuteStep;
|
|
425
|
+
}
|
|
426
|
+
else if (type === 'seconds') {
|
|
427
|
+
this.selectedTime.seconds = (this.selectedTime.seconds - 1) < 0 ? 59 : this.selectedTime.seconds - 1;
|
|
428
|
+
}
|
|
429
|
+
this.updateSelectedDateTime();
|
|
430
|
+
}
|
|
431
|
+
onTimeChange(type, event) {
|
|
432
|
+
const value = parseInt(event.target.value) || 0;
|
|
433
|
+
if (type === 'hours') {
|
|
434
|
+
const min = this.timeFormat === '12' ? 1 : 0;
|
|
435
|
+
const max = this.timeFormat === '12' ? 12 : 23;
|
|
436
|
+
this.selectedTime.hours = Math.max(min, Math.min(max, value));
|
|
437
|
+
}
|
|
438
|
+
else if (type === 'minutes') {
|
|
439
|
+
this.selectedTime.minutes = Math.max(0, Math.min(59, value));
|
|
440
|
+
}
|
|
441
|
+
else if (type === 'seconds') {
|
|
442
|
+
this.selectedTime.seconds = Math.max(0, Math.min(59, value));
|
|
443
|
+
}
|
|
444
|
+
this.updateSelectedDateTime();
|
|
445
|
+
}
|
|
446
|
+
setAMPM(pm) {
|
|
447
|
+
this.isPM = pm;
|
|
448
|
+
this.updateSelectedDateTime();
|
|
449
|
+
}
|
|
450
|
+
formatTime(hours, minutes, seconds) {
|
|
451
|
+
if (this.timeFormat === '12') {
|
|
452
|
+
const displayHours = hours % 12 || 12;
|
|
453
|
+
const ampm = hours >= 12 ? 'PM' : 'AM';
|
|
454
|
+
const minutesStr = minutes.toString().padStart(2, '0');
|
|
455
|
+
if (this.enableSeconds) {
|
|
456
|
+
const secondsStr = seconds.toString().padStart(2, '0');
|
|
457
|
+
return `${displayHours}:${minutesStr}:${secondsStr} ${ampm}`;
|
|
458
|
+
}
|
|
459
|
+
return `${displayHours}:${minutesStr} ${ampm}`;
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
const hoursStr = hours.toString().padStart(2, '0');
|
|
463
|
+
const minutesStr = minutes.toString().padStart(2, '0');
|
|
464
|
+
if (this.enableSeconds) {
|
|
465
|
+
const secondsStr = seconds.toString().padStart(2, '0');
|
|
466
|
+
return `${hoursStr}:${minutesStr}:${secondsStr}`;
|
|
467
|
+
}
|
|
468
|
+
return `${hoursStr}:${minutesStr}`;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
updateSelectedDateTime() {
|
|
472
|
+
if (!this.enableTime || this.selectedDates.length === 0) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
// Convert 12-hour to 24-hour if needed
|
|
476
|
+
let hours24 = this.selectedTime.hours;
|
|
477
|
+
if (this.timeFormat === '12') {
|
|
478
|
+
if (this.isPM && this.selectedTime.hours !== 12) {
|
|
479
|
+
hours24 = this.selectedTime.hours + 12;
|
|
480
|
+
}
|
|
481
|
+
else if (!this.isPM && this.selectedTime.hours === 12) {
|
|
482
|
+
hours24 = 0;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
// Update all selected dates with new time
|
|
486
|
+
this.selectedDates = this.selectedDates.map(selectedDate => {
|
|
487
|
+
const newDate = new Date(selectedDate.gregorian);
|
|
488
|
+
newDate.setHours(hours24, this.selectedTime.minutes, this.selectedTime.seconds);
|
|
489
|
+
return {
|
|
490
|
+
...selectedDate,
|
|
491
|
+
gregorian: newDate,
|
|
492
|
+
time: {
|
|
493
|
+
hours: hours24,
|
|
494
|
+
minutes: this.selectedTime.minutes,
|
|
495
|
+
seconds: this.selectedTime.seconds
|
|
496
|
+
},
|
|
497
|
+
formatted: {
|
|
498
|
+
...selectedDate.formatted,
|
|
499
|
+
time: this.formatTime(hours24, this.selectedTime.minutes, this.selectedTime.seconds)
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
getCustomStyles() {
|
|
505
|
+
return {
|
|
506
|
+
'--primary-color': this.styles.primaryColor || '#4f46e5',
|
|
507
|
+
'--secondary-color': this.styles.secondaryColor || '#818cf8',
|
|
508
|
+
'--background-color': this.styles.backgroundColor || '#ffffff',
|
|
509
|
+
'--text-color': this.styles.textColor || '#1f2937',
|
|
510
|
+
'--selected-date-color': this.styles.selectedDateColor || '#ffffff',
|
|
511
|
+
'--selected-date-background': this.styles.selectedDateBackground || '#4f46e5',
|
|
512
|
+
'--today-color': this.styles.todayColor || '#10b981',
|
|
513
|
+
'--disabled-color': this.styles.disabledColor || '#d1d5db',
|
|
514
|
+
'--border-color': this.styles.borderColor || '#e5e7eb',
|
|
515
|
+
'--hover-color': this.styles.hoverColor || '#f3f4f6',
|
|
516
|
+
'--font-family': this.styles.fontFamily || 'system-ui, -apple-system, sans-serif',
|
|
517
|
+
'--font-size': this.styles.fontSize || '14px',
|
|
518
|
+
'--border-radius': this.styles.borderRadius || '8px'
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
__decorate([
|
|
523
|
+
Input(),
|
|
524
|
+
__metadata("design:type", Boolean)
|
|
525
|
+
], HijriDatePickerComponent.prototype, "canChangeMode", void 0);
|
|
526
|
+
__decorate([
|
|
527
|
+
Input(),
|
|
528
|
+
__metadata("design:type", String)
|
|
529
|
+
], HijriDatePickerComponent.prototype, "mode", void 0);
|
|
530
|
+
__decorate([
|
|
531
|
+
Input(),
|
|
532
|
+
__metadata("design:type", String)
|
|
533
|
+
], HijriDatePickerComponent.prototype, "dir", void 0);
|
|
534
|
+
__decorate([
|
|
535
|
+
Input(),
|
|
536
|
+
__metadata("design:type", String)
|
|
537
|
+
], HijriDatePickerComponent.prototype, "locale", void 0);
|
|
538
|
+
__decorate([
|
|
539
|
+
Input(),
|
|
540
|
+
__metadata("design:type", Boolean)
|
|
541
|
+
], HijriDatePickerComponent.prototype, "futureValidation", void 0);
|
|
542
|
+
__decorate([
|
|
543
|
+
Input(),
|
|
544
|
+
__metadata("design:type", Number)
|
|
545
|
+
], HijriDatePickerComponent.prototype, "futureYearsLimit", void 0);
|
|
546
|
+
__decorate([
|
|
547
|
+
Input(),
|
|
548
|
+
__metadata("design:type", Boolean)
|
|
549
|
+
], HijriDatePickerComponent.prototype, "isRequired", void 0);
|
|
550
|
+
__decorate([
|
|
551
|
+
Input(),
|
|
552
|
+
__metadata("design:type", Boolean)
|
|
553
|
+
], HijriDatePickerComponent.prototype, "multiple", void 0);
|
|
554
|
+
__decorate([
|
|
555
|
+
Input(),
|
|
556
|
+
__metadata("design:type", Boolean)
|
|
557
|
+
], HijriDatePickerComponent.prototype, "showConfirmButton", void 0);
|
|
558
|
+
__decorate([
|
|
559
|
+
Input(),
|
|
560
|
+
__metadata("design:type", Date)
|
|
561
|
+
], HijriDatePickerComponent.prototype, "initialSelectedDate", void 0);
|
|
562
|
+
__decorate([
|
|
563
|
+
Input(),
|
|
564
|
+
__metadata("design:type", Array)
|
|
565
|
+
], HijriDatePickerComponent.prototype, "initialSelectedDates", void 0);
|
|
566
|
+
__decorate([
|
|
567
|
+
Input(),
|
|
568
|
+
__metadata("design:type", String)
|
|
569
|
+
], HijriDatePickerComponent.prototype, "submitTextButton", void 0);
|
|
570
|
+
__decorate([
|
|
571
|
+
Input(),
|
|
572
|
+
__metadata("design:type", String)
|
|
573
|
+
], HijriDatePickerComponent.prototype, "todaysDateText", void 0);
|
|
574
|
+
__decorate([
|
|
575
|
+
Input(),
|
|
576
|
+
__metadata("design:type", String)
|
|
577
|
+
], HijriDatePickerComponent.prototype, "ummAlQuraDateText", void 0);
|
|
578
|
+
__decorate([
|
|
579
|
+
Input(),
|
|
580
|
+
__metadata("design:type", String)
|
|
581
|
+
], HijriDatePickerComponent.prototype, "yearSelectLabel", void 0);
|
|
582
|
+
__decorate([
|
|
583
|
+
Input(),
|
|
584
|
+
__metadata("design:type", String)
|
|
585
|
+
], HijriDatePickerComponent.prototype, "monthSelectLabel", void 0);
|
|
586
|
+
__decorate([
|
|
587
|
+
Input(),
|
|
588
|
+
__metadata("design:type", Boolean)
|
|
589
|
+
], HijriDatePickerComponent.prototype, "todaysDateSection", void 0);
|
|
590
|
+
__decorate([
|
|
591
|
+
Input(),
|
|
592
|
+
__metadata("design:type", Boolean)
|
|
593
|
+
], HijriDatePickerComponent.prototype, "markToday", void 0);
|
|
594
|
+
__decorate([
|
|
595
|
+
Input(),
|
|
596
|
+
__metadata("design:type", Boolean)
|
|
597
|
+
], HijriDatePickerComponent.prototype, "disableYearPicker", void 0);
|
|
598
|
+
__decorate([
|
|
599
|
+
Input(),
|
|
600
|
+
__metadata("design:type", Boolean)
|
|
601
|
+
], HijriDatePickerComponent.prototype, "disableMonthPicker", void 0);
|
|
602
|
+
__decorate([
|
|
603
|
+
Input(),
|
|
604
|
+
__metadata("design:type", Boolean)
|
|
605
|
+
], HijriDatePickerComponent.prototype, "disableDayPicker", void 0);
|
|
606
|
+
__decorate([
|
|
607
|
+
Input(),
|
|
608
|
+
__metadata("design:type", Object)
|
|
609
|
+
], HijriDatePickerComponent.prototype, "styles", void 0);
|
|
610
|
+
__decorate([
|
|
611
|
+
Input(),
|
|
612
|
+
__metadata("design:type", Boolean)
|
|
613
|
+
], HijriDatePickerComponent.prototype, "enableTime", void 0);
|
|
614
|
+
__decorate([
|
|
615
|
+
Input(),
|
|
616
|
+
__metadata("design:type", String)
|
|
617
|
+
], HijriDatePickerComponent.prototype, "timeFormat", void 0);
|
|
618
|
+
__decorate([
|
|
619
|
+
Input(),
|
|
620
|
+
__metadata("design:type", Number)
|
|
621
|
+
], HijriDatePickerComponent.prototype, "minuteStep", void 0);
|
|
622
|
+
__decorate([
|
|
623
|
+
Input(),
|
|
624
|
+
__metadata("design:type", Boolean)
|
|
625
|
+
], HijriDatePickerComponent.prototype, "enableSeconds", void 0);
|
|
626
|
+
__decorate([
|
|
627
|
+
Input(),
|
|
628
|
+
__metadata("design:type", Object)
|
|
629
|
+
], HijriDatePickerComponent.prototype, "defaultTime", void 0);
|
|
630
|
+
__decorate([
|
|
631
|
+
Output(),
|
|
632
|
+
__metadata("design:type", Object)
|
|
633
|
+
], HijriDatePickerComponent.prototype, "dateSelected", void 0);
|
|
634
|
+
__decorate([
|
|
635
|
+
Output(),
|
|
636
|
+
__metadata("design:type", Object)
|
|
637
|
+
], HijriDatePickerComponent.prototype, "modeChanged", void 0);
|
|
638
|
+
HijriDatePickerComponent = __decorate([
|
|
639
|
+
Component({
|
|
640
|
+
selector: 'hijri-date-picker',
|
|
641
|
+
standalone: true,
|
|
642
|
+
imports: [CommonModule],
|
|
643
|
+
templateUrl: './hijri-date-picker.component.html',
|
|
644
|
+
styleUrls: ['./hijri-date-picker.component.css']
|
|
645
|
+
})
|
|
646
|
+
], HijriDatePickerComponent);
|
|
647
|
+
export { HijriDatePickerComponent };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date picker mode types
|
|
3
|
+
*/
|
|
4
|
+
export type DateMode = 'greg' | 'hijri';
|
|
5
|
+
/**
|
|
6
|
+
* Text direction types
|
|
7
|
+
*/
|
|
8
|
+
export type Direction = 'ltr' | 'rtl';
|
|
9
|
+
/**
|
|
10
|
+
* Locale types
|
|
11
|
+
*/
|
|
12
|
+
export type Locale = 'en' | 'ar';
|
|
13
|
+
/**
|
|
14
|
+
* Selected date information
|
|
15
|
+
*/
|
|
16
|
+
export interface SelectedDate {
|
|
17
|
+
gregorian: Date;
|
|
18
|
+
hijri: {
|
|
19
|
+
year: number;
|
|
20
|
+
month: number;
|
|
21
|
+
day: number;
|
|
22
|
+
};
|
|
23
|
+
time?: {
|
|
24
|
+
hours: number;
|
|
25
|
+
minutes: number;
|
|
26
|
+
seconds: number;
|
|
27
|
+
};
|
|
28
|
+
formatted: {
|
|
29
|
+
gregorian: string;
|
|
30
|
+
hijri: string;
|
|
31
|
+
time?: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Time format types
|
|
36
|
+
*/
|
|
37
|
+
export type TimeFormat = '12' | '24';
|
|
38
|
+
/**
|
|
39
|
+
* Custom styling configuration
|
|
40
|
+
*/
|
|
41
|
+
export interface DatePickerStyles {
|
|
42
|
+
primaryColor?: string;
|
|
43
|
+
secondaryColor?: string;
|
|
44
|
+
backgroundColor?: string;
|
|
45
|
+
textColor?: string;
|
|
46
|
+
selectedDateColor?: string;
|
|
47
|
+
selectedDateBackground?: string;
|
|
48
|
+
todayColor?: string;
|
|
49
|
+
disabledColor?: string;
|
|
50
|
+
borderColor?: string;
|
|
51
|
+
hoverColor?: string;
|
|
52
|
+
fontFamily?: string;
|
|
53
|
+
fontSize?: string;
|
|
54
|
+
borderRadius?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Label configuration
|
|
58
|
+
*/
|
|
59
|
+
export interface DatePickerLabels {
|
|
60
|
+
submitTextButton?: string;
|
|
61
|
+
todaysDateText?: string;
|
|
62
|
+
ummAlQuraDateText?: string;
|
|
63
|
+
yearSelectLabel?: string;
|
|
64
|
+
monthSelectLabel?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Display configuration
|
|
68
|
+
*/
|
|
69
|
+
export interface DatePickerDisplay {
|
|
70
|
+
todaysDateSection?: boolean;
|
|
71
|
+
markToday?: boolean;
|
|
72
|
+
disableYearPicker?: boolean;
|
|
73
|
+
disableMonthPicker?: boolean;
|
|
74
|
+
disableDayPicker?: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Month names in different locales
|
|
78
|
+
*/
|
|
79
|
+
export declare const GREGORIAN_MONTHS_EN: string[];
|
|
80
|
+
export declare const GREGORIAN_MONTHS_AR: string[];
|
|
81
|
+
export declare const HIJRI_MONTHS_EN: string[];
|
|
82
|
+
export declare const HIJRI_MONTHS_AR: string[];
|
|
83
|
+
export declare const WEEKDAY_NAMES_EN: string[];
|
|
84
|
+
export declare const WEEKDAY_NAMES_AR: string[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Month names in different locales
|
|
3
|
+
*/
|
|
4
|
+
export const GREGORIAN_MONTHS_EN = [
|
|
5
|
+
'January', 'February', 'March', 'April', 'May', 'June',
|
|
6
|
+
'July', 'August', 'September', 'October', 'November', 'December'
|
|
7
|
+
];
|
|
8
|
+
export const GREGORIAN_MONTHS_AR = [
|
|
9
|
+
'يناير', 'فبراير', 'مارس', 'أبريل', 'مايو', 'يونيو',
|
|
10
|
+
'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوفمبر', 'ديسمبر'
|
|
11
|
+
];
|
|
12
|
+
export const HIJRI_MONTHS_EN = [
|
|
13
|
+
'Muharram', 'Safar', 'Rabi\' al-Awwal', 'Rabi\' al-Thani', 'Jumada al-Awwal', 'Jumada al-Thani',
|
|
14
|
+
'Rajab', 'Sha\'ban', 'Ramadan', 'Shawwal', 'Dhu al-Qi\'dah', 'Dhu al-Hijjah'
|
|
15
|
+
];
|
|
16
|
+
export const HIJRI_MONTHS_AR = [
|
|
17
|
+
'محرم', 'صفر', 'ربيع الأول', 'ربيع الثاني', 'جمادى الأولى', 'جمادى الثانية',
|
|
18
|
+
'رجب', 'شعبان', 'رمضان', 'شوال', 'ذو القعدة', 'ذو الحجة'
|
|
19
|
+
];
|
|
20
|
+
export const WEEKDAY_NAMES_EN = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
21
|
+
export const WEEKDAY_NAMES_AR = ['الأحد', 'الإثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت'];
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hijri-date-time-picker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Angular standalone component for dual-mode Gregorian and Hijri date selection",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"angular",
|
|
18
|
+
"hijri",
|
|
19
|
+
"gregorian",
|
|
20
|
+
"date-picker",
|
|
21
|
+
"calendar",
|
|
22
|
+
"umm-al-qura"
|
|
23
|
+
],
|
|
24
|
+
"author": "Hany",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"homepage": "https://github.com/hanygamal72/hijri-date-time-picker#readme",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/hanygamal72/hijri-date-time-picker/issues"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/hanygamal72/hijri-date-time-picker.git"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@angular/core": ">=15.0.0",
|
|
36
|
+
"@angular/common": ">=15.0.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"hijri-date": "^0.2.2"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@angular/core": "^17.0.0",
|
|
43
|
+
"@angular/common": "^17.0.0",
|
|
44
|
+
"@angular/platform-browser": "^17.0.0",
|
|
45
|
+
"typescript": "^5.0.0"
|
|
46
|
+
}
|
|
47
|
+
}
|