@salas-ds/cli 0.1.0 → 0.2.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.
Files changed (92) hide show
  1. package/dist/index.js +253 -86
  2. package/package.json +4 -5
  3. package/templates/angular/accordion/accordion-content.component.ts +9 -0
  4. package/templates/angular/accordion/accordion-item.component.ts +138 -0
  5. package/templates/angular/accordion/accordion-trigger.component.ts +9 -0
  6. package/templates/angular/accordion/accordion.component.ts +120 -0
  7. package/templates/angular/accordion/accordion.module.ts +21 -0
  8. package/templates/angular/autocomplete/autocomplete.component.ts +707 -0
  9. package/templates/angular/autocomplete/autocomplete.module.ts +8 -0
  10. package/templates/angular/avatar/avatar-badge.component.ts +18 -0
  11. package/templates/angular/avatar/avatar-fallback.component.ts +39 -0
  12. package/templates/angular/avatar/avatar-group-count.component.ts +46 -0
  13. package/templates/angular/avatar/avatar-group.component.ts +33 -0
  14. package/templates/angular/avatar/avatar-image.component.ts +57 -0
  15. package/templates/angular/avatar/avatar.component.ts +73 -0
  16. package/templates/angular/avatar/avatar.module.ts +27 -0
  17. package/templates/angular/badge/badge.component.ts +84 -0
  18. package/templates/angular/badge/badge.module.ts +9 -0
  19. package/templates/angular/button/button.component.ts +24 -4
  20. package/templates/angular/card/card.component.ts +100 -0
  21. package/templates/angular/card/card.module.ts +8 -0
  22. package/templates/angular/checkbox/checkbox.component.ts +172 -0
  23. package/templates/angular/checkbox/checkbox.module.ts +8 -0
  24. package/templates/angular/datepicker/datepicker.component.ts +660 -0
  25. package/templates/angular/datepicker/datepicker.module.ts +8 -0
  26. package/templates/angular/dialog/dialog-content.component.ts +9 -0
  27. package/templates/angular/dialog/dialog-description.component.ts +17 -0
  28. package/templates/angular/dialog/dialog-footer.component.ts +17 -0
  29. package/templates/angular/dialog/dialog-header.component.ts +14 -0
  30. package/templates/angular/dialog/dialog-title.component.ts +18 -0
  31. package/templates/angular/dialog/dialog-trigger.component.ts +9 -0
  32. package/templates/angular/dialog/dialog.component.ts +212 -0
  33. package/templates/angular/dialog/dialog.module.ts +31 -0
  34. package/templates/angular/input/input.component.ts +229 -0
  35. package/templates/angular/input/input.module.ts +8 -0
  36. package/templates/angular/scroll-area/scroll-area.component.ts +72 -0
  37. package/templates/angular/scroll-area/scroll-area.module.ts +9 -0
  38. package/templates/angular/scroll-area/scroll-bar.component.ts +15 -0
  39. package/templates/angular/select/select.component.ts +292 -0
  40. package/templates/angular/select/select.module.ts +8 -0
  41. package/templates/angular/separator/separator.component.ts +63 -0
  42. package/templates/angular/separator/separator.module.ts +9 -0
  43. package/templates/angular/sheet/sheet-content.component.ts +13 -0
  44. package/templates/angular/sheet/sheet-description.component.ts +29 -0
  45. package/templates/angular/sheet/sheet-footer.component.ts +27 -0
  46. package/templates/angular/sheet/sheet-header.component.ts +26 -0
  47. package/templates/angular/sheet/sheet-title.component.ts +31 -0
  48. package/templates/angular/sheet/sheet-trigger.component.ts +11 -0
  49. package/templates/angular/sheet/sheet.component.ts +251 -0
  50. package/templates/angular/sheet/sheet.module.ts +30 -0
  51. package/templates/angular/sidebar/sidebar-content.component.ts +18 -0
  52. package/templates/angular/sidebar/sidebar-footer.component.ts +20 -0
  53. package/templates/angular/sidebar/sidebar-group-content.component.ts +16 -0
  54. package/templates/angular/sidebar/sidebar-group-label.component.ts +20 -0
  55. package/templates/angular/sidebar/sidebar-group.component.ts +14 -0
  56. package/templates/angular/sidebar/sidebar-header.component.ts +20 -0
  57. package/templates/angular/sidebar/sidebar-inset.component.ts +85 -0
  58. package/templates/angular/sidebar/sidebar-menu-button.component.ts +75 -0
  59. package/templates/angular/sidebar/sidebar-menu-item.component.ts +14 -0
  60. package/templates/angular/sidebar/sidebar-menu.component.ts +19 -0
  61. package/templates/angular/sidebar/sidebar-provider.component.ts +68 -0
  62. package/templates/angular/sidebar/sidebar-trigger.component.ts +58 -0
  63. package/templates/angular/sidebar/sidebar.component.ts +196 -0
  64. package/templates/angular/sidebar/sidebar.module.ts +48 -0
  65. package/templates/angular/sidebar/sidebar.service.ts +93 -0
  66. package/templates/angular/skeleton/skeleton.component.ts +44 -0
  67. package/templates/angular/skeleton/skeleton.module.ts +8 -0
  68. package/templates/angular/spinner/spinner.component.ts +75 -0
  69. package/templates/angular/spinner/spinner.module.ts +8 -0
  70. package/templates/angular/table/table-body.component.ts +23 -0
  71. package/templates/angular/table/table-caption.component.ts +29 -0
  72. package/templates/angular/table/table-cell.component.ts +49 -0
  73. package/templates/angular/table/table-footer.component.ts +32 -0
  74. package/templates/angular/table/table-head.component.ts +48 -0
  75. package/templates/angular/table/table-header.component.ts +28 -0
  76. package/templates/angular/table/table-row.component.ts +36 -0
  77. package/templates/angular/table/table.component.ts +35 -0
  78. package/templates/angular/table/table.module.ts +33 -0
  79. package/templates/angular/tabs/tabs-content.component.ts +71 -0
  80. package/templates/angular/tabs/tabs-list.component.ts +70 -0
  81. package/templates/angular/tabs/tabs-trigger.component.ts +149 -0
  82. package/templates/angular/tabs/tabs.component.ts +155 -0
  83. package/templates/angular/tabs/tabs.module.ts +21 -0
  84. package/templates/angular/textarea/textarea.component.ts +268 -0
  85. package/templates/angular/textarea/textarea.module.ts +8 -0
  86. package/templates/angular/toast/toast.module.ts +8 -0
  87. package/templates/angular/toast/toast.service.ts +104 -0
  88. package/templates/angular/toast/toaster.component.ts +329 -0
  89. package/templates/angular/tooltip/tooltip-content.component.ts +43 -0
  90. package/templates/angular/tooltip/tooltip-trigger.component.ts +13 -0
  91. package/templates/angular/tooltip/tooltip.component.ts +243 -0
  92. package/templates/angular/tooltip/tooltip.module.ts +10 -0
@@ -0,0 +1,660 @@
1
+ import {
2
+ Component,
3
+ Input,
4
+ Output,
5
+ EventEmitter,
6
+ forwardRef,
7
+ OnInit,
8
+ ViewChild,
9
+ ElementRef,
10
+ HostListener,
11
+ } from '@angular/core';
12
+ import { ControlValueAccessor, NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
13
+ import { cn } from '../utils';
14
+ import { LucideAngularModule } from 'lucide-angular';
15
+ import { CommonModule } from '@angular/common';
16
+
17
+ /**
18
+ * DatePicker component types
19
+ */
20
+
21
+ export type DatePickerMode = 'single' | 'range' | 'multiple';
22
+ export type DatePickerVariant = 'default' | 'error' | 'success';
23
+ export type DatePickerSize = 'sm' | 'md' | 'lg';
24
+
25
+ export interface DatePickerProps {
26
+ mode?: DatePickerMode;
27
+ variant?: DatePickerVariant;
28
+ size?: DatePickerSize;
29
+ disabled?: boolean;
30
+ required?: boolean;
31
+ placeholder?: string;
32
+ value?: Date | Date[] | { from?: Date; to?: Date };
33
+ minDate?: Date;
34
+ maxDate?: Date;
35
+ name?: string;
36
+ id?: string;
37
+ locale?: string;
38
+ format?: string;
39
+ showTime?: boolean;
40
+ showWeekNumbers?: boolean;
41
+ }
42
+
43
+
44
+ interface CalendarDay {
45
+ date: Date;
46
+ isCurrentMonth: boolean;
47
+ isToday: boolean;
48
+ isSelected: boolean;
49
+ isInRange?: boolean;
50
+ isRangeStart?: boolean;
51
+ isRangeEnd?: boolean;
52
+ isDisabled: boolean;
53
+ }
54
+
55
+ @Component({
56
+ selector: 'salas-datepicker',
57
+ standalone: true,
58
+ imports: [FormsModule, CommonModule, LucideAngularModule],
59
+ template: `
60
+ <div [class]="wrapperClasses" #wrapper>
61
+ <div [class]="inputWrapperClasses">
62
+ <lucide-icon name="calendar" [size]="iconSize" class="salas-datepicker-icon" />
63
+ <input
64
+ [id]="id"
65
+ [name]="name"
66
+ [disabled]="disabled"
67
+ [required]="required"
68
+ [placeholder]="placeholder"
69
+ [class]="inputClasses"
70
+ [value]="displayValue"
71
+ (mousedown)="onInputMouseDown($event)"
72
+ (focus)="onFocus()"
73
+ (blur)="onBlur()"
74
+ readonly
75
+ [attr.aria-invalid]="variant === 'error'"
76
+ [attr.aria-expanded]="isOpen"
77
+ />
78
+ @if (displayValue && !disabled) {
79
+ <button
80
+ type="button"
81
+ class="salas-datepicker-clear"
82
+ (click)="clearValue($event)"
83
+ aria-label="Clear"
84
+ >
85
+ <lucide-icon name="x" [size]="iconSize" />
86
+ </button>
87
+ }
88
+ </div>
89
+
90
+ @if (isOpen) {
91
+ <div [class]="calendarClasses">
92
+ <div class="salas-datepicker-header">
93
+ <button
94
+ type="button"
95
+ class="salas-datepicker-nav"
96
+ (click)="previousMonth()"
97
+ aria-label="Previous month"
98
+ >
99
+
100
+ </button>
101
+ <div class="salas-datepicker-month-year">
102
+ {{ currentMonthLabel }} {{ currentYear }}
103
+ </div>
104
+ <button
105
+ type="button"
106
+ class="salas-datepicker-nav"
107
+ (click)="nextMonth()"
108
+ aria-label="Next month"
109
+ >
110
+
111
+ </button>
112
+ </div>
113
+
114
+ <div class="salas-datepicker-weekdays">
115
+ @for (day of weekDays; track day) {
116
+ <div class="salas-datepicker-weekday">{{ day }}</div>
117
+ }
118
+ </div>
119
+
120
+ <div class="salas-datepicker-days">
121
+ @for (day of calendarDays; track day.date.getTime()) {
122
+ <button
123
+ type="button"
124
+ [class]="getDayClasses(day)"
125
+ [disabled]="day.isDisabled"
126
+ (click)="selectDate(day.date)"
127
+ >
128
+ {{ day.date.getDate() }}
129
+ </button>
130
+ }
131
+ </div>
132
+ </div>
133
+ }
134
+ </div>
135
+ `,
136
+ styles: [`
137
+ .salas-datepicker-wrapper {
138
+ position: relative;
139
+ display: inline-block;
140
+ width: 100%;
141
+ }
142
+
143
+ .salas-datepicker-input-wrapper {
144
+ position: relative;
145
+ display: flex;
146
+ align-items: center;
147
+ }
148
+
149
+ .salas-datepicker {
150
+ width: 100%;
151
+ border-radius: 0.375rem;
152
+ border: 1px solid var(--salas-gray-300);
153
+ background-color: white;
154
+ padding: 0 0.75rem;
155
+ padding-left: 2.5rem;
156
+ font-size: 0.875rem;
157
+ transition: all 0.2s;
158
+ outline: none;
159
+ cursor: pointer;
160
+ }
161
+
162
+ .salas-datepicker:focus {
163
+ border-color: var(--salas-primary-500);
164
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
165
+ }
166
+
167
+ .salas-datepicker:disabled {
168
+ background-color: var(--salas-gray-50);
169
+ cursor: not-allowed;
170
+ opacity: 0.6;
171
+ }
172
+
173
+ .salas-datepicker-icon {
174
+ position: absolute;
175
+ left: 0.75rem;
176
+ color: var(--salas-gray-400);
177
+ pointer-events: none;
178
+ z-index: 1;
179
+ }
180
+
181
+ .salas-datepicker-clear {
182
+ position: absolute;
183
+ right: 0.75rem;
184
+ cursor: pointer;
185
+ pointer-events: all;
186
+ background: none;
187
+ border: none;
188
+ padding: 0.25rem;
189
+ display: flex;
190
+ align-items: center;
191
+ justify-content: center;
192
+ color: var(--salas-gray-400);
193
+ z-index: 1;
194
+ }
195
+
196
+ .salas-datepicker-clear:hover {
197
+ color: var(--salas-gray-600);
198
+ }
199
+
200
+ /* Variants */
201
+ .salas-datepicker--error {
202
+ border-color: var(--salas-destructive-500);
203
+ }
204
+
205
+ .salas-datepicker--error:focus {
206
+ border-color: var(--salas-destructive-500);
207
+ box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
208
+ }
209
+
210
+ .salas-datepicker--success {
211
+ border-color: var(--salas-success-500);
212
+ }
213
+
214
+ .salas-datepicker--success:focus {
215
+ border-color: var(--salas-success-500);
216
+ box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
217
+ }
218
+
219
+ /* Sizes */
220
+ .salas-datepicker--sm {
221
+ height: 2rem;
222
+ padding: 0 0.625rem;
223
+ padding-left: 2rem;
224
+ font-size: 0.8125rem;
225
+ }
226
+
227
+ .salas-datepicker--md {
228
+ height: 2.5rem;
229
+ }
230
+
231
+ .salas-datepicker--lg {
232
+ height: 3rem;
233
+ padding: 0 1rem;
234
+ padding-left: 2.75rem;
235
+ font-size: 1rem;
236
+ }
237
+
238
+ /* Calendar */
239
+ .salas-datepicker-calendar {
240
+ position: absolute;
241
+ top: 100%;
242
+ left: 0;
243
+ margin-top: 0.25rem;
244
+ background-color: white;
245
+ border: 1px solid var(--salas-gray-200);
246
+ border-radius: 0.375rem;
247
+ box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
248
+ padding: 1rem;
249
+ z-index: 1000;
250
+ min-width: 18rem;
251
+ }
252
+
253
+ .salas-datepicker-header {
254
+ display: flex;
255
+ align-items: center;
256
+ justify-content: space-between;
257
+ margin-bottom: 1rem;
258
+ }
259
+
260
+ .salas-datepicker-month-year {
261
+ font-weight: 600;
262
+ font-size: 0.875rem;
263
+ }
264
+
265
+ .salas-datepicker-nav {
266
+ background: none;
267
+ border: none;
268
+ cursor: pointer;
269
+ padding: 0.25rem 0.5rem;
270
+ font-size: 1.25rem;
271
+ color: var(--salas-gray-600);
272
+ border-radius: 0.25rem;
273
+ }
274
+
275
+ .salas-datepicker-nav:hover {
276
+ background-color: var(--salas-gray-100);
277
+ }
278
+
279
+ .salas-datepicker-weekdays {
280
+ display: grid;
281
+ grid-template-columns: repeat(7, 1fr);
282
+ gap: 0.25rem;
283
+ margin-bottom: 0.5rem;
284
+ }
285
+
286
+ .salas-datepicker-weekday {
287
+ text-align: center;
288
+ font-size: 0.75rem;
289
+ font-weight: 500;
290
+ color: var(--salas-gray-500);
291
+ padding: 0.25rem;
292
+ }
293
+
294
+ .salas-datepicker-days {
295
+ display: grid;
296
+ grid-template-columns: repeat(7, 1fr);
297
+ gap: 0.25rem;
298
+ }
299
+
300
+ .salas-datepicker-day {
301
+ aspect-ratio: 1;
302
+ border: none;
303
+ background: none;
304
+ cursor: pointer;
305
+ border-radius: 0.25rem;
306
+ font-size: 0.875rem;
307
+ color: var(--salas-gray-900);
308
+ transition: all 0.2s;
309
+ }
310
+
311
+ .salas-datepicker-day:hover:not(:disabled) {
312
+ background-color: var(--salas-gray-100);
313
+ }
314
+
315
+ .salas-datepicker-day--other-month {
316
+ color: var(--salas-gray-400);
317
+ }
318
+
319
+ .salas-datepicker-day--today {
320
+ font-weight: 600;
321
+ color: var(--salas-primary-600);
322
+ }
323
+
324
+ .salas-datepicker-day--selected {
325
+ background-color: var(--salas-primary-500);
326
+ color: white;
327
+ }
328
+
329
+ .salas-datepicker-day--selected:hover {
330
+ background-color: var(--salas-primary-600);
331
+ }
332
+
333
+ .salas-datepicker-day--in-range {
334
+ background-color: var(--salas-primary-50);
335
+ }
336
+
337
+ .salas-datepicker-day--range-start,
338
+ .salas-datepicker-day--range-end {
339
+ background-color: var(--salas-primary-500);
340
+ color: white;
341
+ }
342
+
343
+ .salas-datepicker-day:disabled {
344
+ opacity: 0.3;
345
+ cursor: not-allowed;
346
+ }
347
+ `],
348
+ providers: [
349
+ {
350
+ provide: NG_VALUE_ACCESSOR,
351
+ useExisting: forwardRef(() => SalasDatepickerComponent),
352
+ multi: true,
353
+ },
354
+ ],
355
+ })
356
+ export class SalasDatepickerComponent implements ControlValueAccessor, OnInit, DatePickerProps {
357
+ @ViewChild('wrapper', { static: true }) wrapper!: ElementRef<HTMLElement>;
358
+
359
+ @Input() mode: DatePickerMode = 'single';
360
+ @Input() variant: DatePickerVariant = 'default';
361
+ @Input() size: DatePickerSize = 'md';
362
+ @Input() disabled = false;
363
+ @Input() required = false;
364
+ @Input() placeholder = 'Select date';
365
+ @Input() value?: Date | Date[] | { from?: Date; to?: Date };
366
+ @Input() minDate?: Date;
367
+ @Input() maxDate?: Date;
368
+ @Input() name = '';
369
+ @Input() id = '';
370
+ @Input() locale = 'en-US';
371
+ @Input() format = 'MM/dd/yyyy';
372
+ @Input() showTime = false;
373
+ @Input() showWeekNumbers = false;
374
+
375
+ @Output() valueChange = new EventEmitter<Date | Date[] | { from?: Date; to?: Date }>();
376
+
377
+ isOpen = false;
378
+ currentMonth = new Date().getMonth();
379
+ currentYear = new Date().getFullYear();
380
+ calendarDays: CalendarDay[] = [];
381
+ weekDays = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
382
+ displayValue = '';
383
+
384
+ private onChange = (value: Date | Date[] | { from?: Date; to?: Date }) => {};
385
+ private onTouched = () => {};
386
+
387
+ ngOnInit(): void {
388
+ this.generateCalendar();
389
+ this.updateDisplayValue();
390
+ }
391
+
392
+ @HostListener('document:click', ['$event'])
393
+ onClickOutside(event: MouseEvent): void {
394
+ if (!this.wrapper.nativeElement.contains(event.target as Node)) {
395
+ this.isOpen = false;
396
+ }
397
+ }
398
+
399
+ get wrapperClasses(): string {
400
+ return cn('salas-datepicker-wrapper');
401
+ }
402
+
403
+ get inputWrapperClasses(): string {
404
+ return cn('salas-datepicker-input-wrapper');
405
+ }
406
+
407
+ get inputClasses(): string {
408
+ return cn(
409
+ 'salas-datepicker',
410
+ `salas-datepicker--${this.size}`,
411
+ this.variant !== 'default' && `salas-datepicker--${this.variant}`
412
+ );
413
+ }
414
+
415
+ get calendarClasses(): string {
416
+ return cn('salas-datepicker-calendar');
417
+ }
418
+
419
+ get iconSize(): number {
420
+ return this.size === 'sm' ? 16 : this.size === 'lg' ? 20 : 18;
421
+ }
422
+
423
+ get currentMonthLabel(): string {
424
+ return new Date(this.currentYear, this.currentMonth).toLocaleDateString(this.locale, {
425
+ month: 'long',
426
+ });
427
+ }
428
+
429
+ generateCalendar(): void {
430
+ const firstDay = new Date(this.currentYear, this.currentMonth, 1);
431
+ const lastDay = new Date(this.currentYear, this.currentMonth + 1, 0);
432
+ const startDate = new Date(firstDay);
433
+ startDate.setDate(startDate.getDate() - startDate.getDay());
434
+
435
+ const days: CalendarDay[] = [];
436
+ const today = new Date();
437
+ today.setHours(0, 0, 0, 0);
438
+
439
+ for (let i = 0; i < 42; i++) {
440
+ const date = new Date(startDate);
441
+ date.setDate(startDate.getDate() + i);
442
+
443
+ const isCurrentMonth = date.getMonth() === this.currentMonth;
444
+ const isToday = this.isSameDay(date, today);
445
+ const isSelected = this.isDateSelected(date);
446
+ const isDisabled = this.isDateDisabled(date);
447
+
448
+ days.push({
449
+ date,
450
+ isCurrentMonth,
451
+ isToday,
452
+ isSelected,
453
+ isDisabled,
454
+ });
455
+ }
456
+
457
+ this.calendarDays = days;
458
+ }
459
+
460
+ isSameDay(date1: Date, date2: Date): boolean {
461
+ return (
462
+ date1.getFullYear() === date2.getFullYear() &&
463
+ date1.getMonth() === date2.getMonth() &&
464
+ date1.getDate() === date2.getDate()
465
+ );
466
+ }
467
+
468
+ isDateSelected(date: Date): boolean {
469
+ if (!this.value) return false;
470
+
471
+ if (this.mode === 'single' && this.value instanceof Date) {
472
+ return this.isSameDay(date, this.value);
473
+ }
474
+
475
+ if (this.mode === 'multiple' && Array.isArray(this.value)) {
476
+ return this.value.some(d => this.isSameDay(date, d));
477
+ }
478
+
479
+ if (this.mode === 'range' && typeof this.value === 'object' && 'from' in this.value) {
480
+ const range = this.value as { from?: Date; to?: Date };
481
+ if (range.from && this.isSameDay(date, range.from)) return true;
482
+ if (range.to && this.isSameDay(date, range.to)) return true;
483
+ if (range.from && range.to) {
484
+ return date >= range.from && date <= range.to;
485
+ }
486
+ }
487
+
488
+ return false;
489
+ }
490
+
491
+ isDateDisabled(date: Date): boolean {
492
+ if (this.minDate && date < this.minDate) return true;
493
+ if (this.maxDate && date > this.maxDate) return true;
494
+ return false;
495
+ }
496
+
497
+ getDayClasses(day: CalendarDay): string {
498
+ return cn(
499
+ 'salas-datepicker-day',
500
+ !day.isCurrentMonth && 'salas-datepicker-day--other-month',
501
+ day.isToday && 'salas-datepicker-day--today',
502
+ day.isSelected && 'salas-datepicker-day--selected'
503
+ );
504
+ }
505
+
506
+ selectDate(date: Date): void {
507
+ if (this.isDateDisabled(date)) return;
508
+
509
+ if (this.mode === 'single') {
510
+ this.value = date;
511
+ this.displayValue = this.formatDate(date);
512
+ this.isOpen = false;
513
+ } else if (this.mode === 'multiple') {
514
+ const values = Array.isArray(this.value) ? [...this.value] : [];
515
+ const index = values.findIndex(d => this.isSameDay(d, date));
516
+ if (index >= 0) {
517
+ values.splice(index, 1);
518
+ } else {
519
+ values.push(date);
520
+ }
521
+ this.value = values;
522
+ this.displayValue = values.map(d => this.formatDate(d)).join(', ');
523
+ } else if (this.mode === 'range') {
524
+ const range = (this.value && typeof this.value === 'object' && 'from' in this.value
525
+ ? { ...(this.value as { from?: Date; to?: Date }) }
526
+ : {}) as { from?: Date; to?: Date };
527
+
528
+ if (!range.from || (range.from && range.to)) {
529
+ range.from = date;
530
+ range.to = undefined;
531
+ } else if (range.from && !range.to) {
532
+ if (date < range.from) {
533
+ range.to = range.from;
534
+ range.from = date;
535
+ } else {
536
+ range.to = date;
537
+ }
538
+ this.isOpen = false;
539
+ }
540
+
541
+ this.value = range;
542
+ if (range.from && range.to) {
543
+ this.displayValue = `${this.formatDate(range.from)} - ${this.formatDate(range.to)}`;
544
+ } else if (range.from) {
545
+ this.displayValue = this.formatDate(range.from);
546
+ }
547
+ }
548
+
549
+ if (this.value !== undefined) {
550
+ this.onChange(this.value);
551
+ this.valueChange.emit(this.value);
552
+ }
553
+ this.generateCalendar();
554
+ }
555
+
556
+ formatDate(date: Date): string {
557
+ return date.toLocaleDateString(this.locale);
558
+ }
559
+
560
+ updateDisplayValue(): void {
561
+ if (!this.value) {
562
+ this.displayValue = '';
563
+ return;
564
+ }
565
+
566
+ if (this.mode === 'single' && this.value instanceof Date) {
567
+ this.displayValue = this.formatDate(this.value);
568
+ } else if (this.mode === 'multiple' && Array.isArray(this.value)) {
569
+ this.displayValue = this.value.map(d => this.formatDate(d)).join(', ');
570
+ } else if (this.mode === 'range' && typeof this.value === 'object' && 'from' in this.value) {
571
+ const range = this.value as { from?: Date; to?: Date };
572
+ if (range.from && range.to) {
573
+ this.displayValue = `${this.formatDate(range.from)} - ${this.formatDate(range.to)}`;
574
+ } else if (range.from) {
575
+ this.displayValue = this.formatDate(range.from);
576
+ }
577
+ }
578
+ }
579
+
580
+ onInputMouseDown(event: MouseEvent): void {
581
+ // Prevenir o blur quando clica no input
582
+ event.preventDefault();
583
+ if (!this.disabled) {
584
+ this.isOpen = !this.isOpen;
585
+ }
586
+ }
587
+
588
+ toggleCalendar(): void {
589
+ if (!this.disabled) {
590
+ this.isOpen = !this.isOpen;
591
+ }
592
+ }
593
+
594
+ onFocus(): void {
595
+ if (!this.disabled) {
596
+ this.isOpen = true;
597
+ }
598
+ }
599
+
600
+ onBlur(): void {
601
+ // Delay para permitir cliques no calendário antes de fechar
602
+ setTimeout(() => {
603
+ // Verificar se o elemento ativo ainda está dentro do wrapper
604
+ const activeElement = document.activeElement;
605
+ if (!this.wrapper.nativeElement.contains(activeElement)) {
606
+ this.isOpen = false;
607
+ this.onTouched();
608
+ }
609
+ }, 300);
610
+ }
611
+
612
+ clearValue(event: Event): void {
613
+ event.stopPropagation();
614
+ this.value = undefined;
615
+ this.displayValue = '';
616
+ // Não chamar onChange com undefined, apenas emitir o evento
617
+ this.valueChange.emit(undefined as any);
618
+ this.generateCalendar();
619
+ this.generateCalendar();
620
+ }
621
+
622
+ previousMonth(): void {
623
+ if (this.currentMonth === 0) {
624
+ this.currentMonth = 11;
625
+ this.currentYear--;
626
+ } else {
627
+ this.currentMonth--;
628
+ }
629
+ this.generateCalendar();
630
+ }
631
+
632
+ nextMonth(): void {
633
+ if (this.currentMonth === 11) {
634
+ this.currentMonth = 0;
635
+ this.currentYear++;
636
+ } else {
637
+ this.currentMonth++;
638
+ }
639
+ this.generateCalendar();
640
+ }
641
+
642
+ // ControlValueAccessor implementation
643
+ writeValue(value: Date | Date[] | { from?: Date; to?: Date }): void {
644
+ this.value = value;
645
+ this.updateDisplayValue();
646
+ this.generateCalendar();
647
+ }
648
+
649
+ registerOnChange(fn: (value: Date | Date[] | { from?: Date; to?: Date }) => void): void {
650
+ this.onChange = fn;
651
+ }
652
+
653
+ registerOnTouched(fn: () => void): void {
654
+ this.onTouched = fn;
655
+ }
656
+
657
+ setDisabledState(isDisabled: boolean): void {
658
+ this.disabled = isDisabled;
659
+ }
660
+ }
@@ -0,0 +1,8 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { SalasDatepickerComponent } from './datepicker.component';
3
+
4
+ @NgModule({
5
+ imports: [SalasDatepickerComponent],
6
+ exports: [SalasDatepickerComponent],
7
+ })
8
+ export class SalasDatepickerModule {}
@@ -0,0 +1,9 @@
1
+ import { Component } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'salas-dialog-content',
5
+ standalone: true,
6
+ template: '<ng-content></ng-content>',
7
+ styles: [`:host { display: contents; }`],
8
+ })
9
+ export class SalasDialogContentComponent {}
@@ -0,0 +1,17 @@
1
+ import { Component, ViewEncapsulation } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'salas-dialog-description',
5
+ standalone: true,
6
+ encapsulation: ViewEncapsulation.None,
7
+ template: `<p class="salas-dialog-description"><ng-content></ng-content></p>`,
8
+ styles: [`
9
+ .salas-dialog-description {
10
+ margin: 0.375rem 0 0;
11
+ font-size: 0.875rem;
12
+ line-height: 1.5;
13
+ color: var(--salas-text-muted);
14
+ }
15
+ `],
16
+ })
17
+ export class SalasDialogDescriptionComponent {}
@@ -0,0 +1,17 @@
1
+ import { Component, ViewEncapsulation } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'salas-dialog-footer',
5
+ standalone: true,
6
+ encapsulation: ViewEncapsulation.None,
7
+ template: `<div class="salas-dialog-footer"><ng-content></ng-content></div>`,
8
+ styles: [`
9
+ .salas-dialog-footer {
10
+ margin-top: 1.5rem;
11
+ display: flex;
12
+ justify-content: flex-end;
13
+ gap: 0.5rem;
14
+ }
15
+ `],
16
+ })
17
+ export class SalasDialogFooterComponent {}