@oneluiz/dual-datepicker 1.0.2 → 2.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.
@@ -1,292 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- 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;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DualDatepickerComponent = void 0;
13
- const core_1 = require("@angular/core");
14
- const common_1 = require("@angular/common");
15
- const forms_1 = require("@angular/forms");
16
- let DualDatepickerComponent = class DualDatepickerComponent {
17
- elementRef;
18
- placeholder = 'Select date range';
19
- fechaInicio = '';
20
- fechaFin = '';
21
- showPresets = true;
22
- closeOnSelection = true;
23
- closeOnPresetSelection = true;
24
- closeOnClickOutside = true;
25
- presets = [
26
- { label: 'Last month', daysAgo: 30 },
27
- { label: 'Last 6 months', daysAgo: 180 },
28
- { label: 'Last year', daysAgo: 365 }
29
- ];
30
- inputBackgroundColor = '#fff';
31
- inputTextColor = '#495057';
32
- inputBorderColor = '#ced4da';
33
- inputBorderColorHover = '#ced4da';
34
- inputBorderColorFocus = '#80bdff';
35
- inputPadding = '0.375rem 0.75rem';
36
- dateRangeChange = new core_1.EventEmitter();
37
- dateRangeSelected = new core_1.EventEmitter();
38
- mostrarDatePicker = false;
39
- rangoFechas = '';
40
- fechaSeleccionandoInicio = true;
41
- mesActual = new Date();
42
- mesAnterior = new Date();
43
- diasMesActual = [];
44
- diasMesAnterior = [];
45
- constructor(elementRef) {
46
- this.elementRef = elementRef;
47
- }
48
- onClickOutside(event) {
49
- if (this.mostrarDatePicker && this.closeOnClickOutside) {
50
- const clickedInside = this.elementRef.nativeElement.contains(event.target);
51
- if (!clickedInside) {
52
- this.cerrarDatePicker();
53
- }
54
- }
55
- }
56
- ngOnInit() {
57
- if (this.fechaInicio && this.fechaFin) {
58
- this.actualizarRangoFechasTexto();
59
- this.generarCalendarios();
60
- }
61
- }
62
- ngOnChanges(changes) {
63
- if (changes['fechaInicio'] || changes['fechaFin']) {
64
- if (this.fechaInicio && this.fechaFin) {
65
- this.actualizarRangoFechasTexto();
66
- this.generarCalendarios();
67
- }
68
- else if (!this.fechaInicio && !this.fechaFin) {
69
- this.rangoFechas = '';
70
- }
71
- }
72
- }
73
- formatearFecha(fecha) {
74
- const year = fecha.getFullYear();
75
- const month = String(fecha.getMonth() + 1).padStart(2, '0');
76
- const day = String(fecha.getDate()).padStart(2, '0');
77
- return `${year}-${month}-${day}`;
78
- }
79
- formatearFechaDisplay(fechaStr) {
80
- if (!fechaStr)
81
- return '';
82
- const fecha = new Date(fechaStr + 'T00:00:00');
83
- const meses = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
84
- return `${fecha.getDate()} ${meses[fecha.getMonth()]}`;
85
- }
86
- actualizarRangoFechasTexto() {
87
- if (this.fechaInicio && this.fechaFin) {
88
- const inicio = this.formatearFechaDisplay(this.fechaInicio);
89
- const fin = this.formatearFechaDisplay(this.fechaFin);
90
- this.rangoFechas = `${inicio} - ${fin}`;
91
- }
92
- else {
93
- this.rangoFechas = '';
94
- }
95
- }
96
- toggleDatePicker() {
97
- this.mostrarDatePicker = !this.mostrarDatePicker;
98
- if (this.mostrarDatePicker) {
99
- this.fechaSeleccionandoInicio = true;
100
- this.mesAnterior = new Date(this.mesActual.getFullYear(), this.mesActual.getMonth() - 1, 1);
101
- this.generarCalendarios();
102
- }
103
- }
104
- cerrarDatePicker() {
105
- this.mostrarDatePicker = false;
106
- }
107
- generarCalendarios() {
108
- this.diasMesAnterior = this.generarCalendarioMes(this.mesAnterior);
109
- this.diasMesActual = this.generarCalendarioMes(this.mesActual);
110
- }
111
- generarCalendarioMes(fecha) {
112
- const año = fecha.getFullYear();
113
- const mes = fecha.getMonth();
114
- const primerDia = new Date(año, mes, 1);
115
- const ultimoDia = new Date(año, mes + 1, 0);
116
- const diasEnMes = ultimoDia.getDate();
117
- const primerDiaSemana = primerDia.getDay();
118
- const diasMes = [];
119
- for (let i = 0; i < primerDiaSemana; i++) {
120
- diasMes.push({ dia: null, esMesActual: false });
121
- }
122
- for (let dia = 1; dia <= diasEnMes; dia++) {
123
- const fechaDia = new Date(año, mes, dia);
124
- const fechaStr = this.formatearFecha(fechaDia);
125
- diasMes.push({
126
- dia: dia,
127
- fecha: fechaStr,
128
- esMesActual: true,
129
- esInicio: this.fechaInicio === fechaStr,
130
- esFin: this.fechaFin === fechaStr,
131
- enRango: this.estaEnRango(fechaStr)
132
- });
133
- }
134
- return diasMes;
135
- }
136
- estaEnRango(fechaStr) {
137
- if (!this.fechaInicio || !this.fechaFin)
138
- return false;
139
- return fechaStr >= this.fechaInicio && fechaStr <= this.fechaFin;
140
- }
141
- seleccionarDia(diaObj) {
142
- if (!diaObj.esMesActual)
143
- return;
144
- if (this.fechaSeleccionandoInicio) {
145
- this.fechaInicio = diaObj.fecha;
146
- this.fechaFin = '';
147
- this.fechaSeleccionandoInicio = false;
148
- this.emitirCambio();
149
- }
150
- else {
151
- if (diaObj.fecha < this.fechaInicio) {
152
- this.fechaFin = this.fechaInicio;
153
- this.fechaInicio = diaObj.fecha;
154
- }
155
- else {
156
- this.fechaFin = diaObj.fecha;
157
- }
158
- this.actualizarRangoFechasTexto();
159
- if (this.closeOnSelection) {
160
- this.mostrarDatePicker = false;
161
- }
162
- this.fechaSeleccionandoInicio = true;
163
- this.emitirSeleccion();
164
- }
165
- this.generarCalendarios();
166
- }
167
- cambiarMes(direccion) {
168
- this.mesActual = new Date(this.mesActual.getFullYear(), this.mesActual.getMonth() + direccion, 1);
169
- this.mesAnterior = new Date(this.mesActual.getFullYear(), this.mesActual.getMonth() - 1, 1);
170
- this.generarCalendarios();
171
- }
172
- getNombreMes(fecha) {
173
- const meses = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
174
- return `${meses[fecha.getMonth()]} ${fecha.getFullYear()}`;
175
- }
176
- seleccionarRangoPredefinido(preset) {
177
- const hoy = new Date();
178
- const fechaInicio = new Date(hoy);
179
- fechaInicio.setDate(hoy.getDate() - preset.daysAgo);
180
- this.fechaInicio = this.formatearFecha(fechaInicio);
181
- this.fechaFin = this.formatearFecha(hoy);
182
- this.actualizarRangoFechasTexto();
183
- this.generarCalendarios();
184
- if (this.closeOnPresetSelection) {
185
- this.mostrarDatePicker = false;
186
- }
187
- this.emitirSeleccion();
188
- }
189
- limpiar() {
190
- this.fechaInicio = '';
191
- this.fechaFin = '';
192
- this.rangoFechas = '';
193
- this.mostrarDatePicker = false;
194
- this.fechaSeleccionandoInicio = true;
195
- this.emitirCambio();
196
- }
197
- emitirCambio() {
198
- this.dateRangeChange.emit({
199
- fechaInicio: this.fechaInicio,
200
- fechaFin: this.fechaFin,
201
- rangoTexto: this.rangoFechas
202
- });
203
- }
204
- emitirSeleccion() {
205
- this.dateRangeSelected.emit({
206
- fechaInicio: this.fechaInicio,
207
- fechaFin: this.fechaFin,
208
- rangoTexto: this.rangoFechas
209
- });
210
- }
211
- };
212
- exports.DualDatepickerComponent = DualDatepickerComponent;
213
- __decorate([
214
- (0, core_1.Input)(),
215
- __metadata("design:type", String)
216
- ], DualDatepickerComponent.prototype, "placeholder", void 0);
217
- __decorate([
218
- (0, core_1.Input)(),
219
- __metadata("design:type", String)
220
- ], DualDatepickerComponent.prototype, "fechaInicio", void 0);
221
- __decorate([
222
- (0, core_1.Input)(),
223
- __metadata("design:type", String)
224
- ], DualDatepickerComponent.prototype, "fechaFin", void 0);
225
- __decorate([
226
- (0, core_1.Input)(),
227
- __metadata("design:type", Boolean)
228
- ], DualDatepickerComponent.prototype, "showPresets", void 0);
229
- __decorate([
230
- (0, core_1.Input)(),
231
- __metadata("design:type", Boolean)
232
- ], DualDatepickerComponent.prototype, "closeOnSelection", void 0);
233
- __decorate([
234
- (0, core_1.Input)(),
235
- __metadata("design:type", Boolean)
236
- ], DualDatepickerComponent.prototype, "closeOnPresetSelection", void 0);
237
- __decorate([
238
- (0, core_1.Input)(),
239
- __metadata("design:type", Boolean)
240
- ], DualDatepickerComponent.prototype, "closeOnClickOutside", void 0);
241
- __decorate([
242
- (0, core_1.Input)(),
243
- __metadata("design:type", Array)
244
- ], DualDatepickerComponent.prototype, "presets", void 0);
245
- __decorate([
246
- (0, core_1.Input)(),
247
- __metadata("design:type", String)
248
- ], DualDatepickerComponent.prototype, "inputBackgroundColor", void 0);
249
- __decorate([
250
- (0, core_1.Input)(),
251
- __metadata("design:type", String)
252
- ], DualDatepickerComponent.prototype, "inputTextColor", void 0);
253
- __decorate([
254
- (0, core_1.Input)(),
255
- __metadata("design:type", String)
256
- ], DualDatepickerComponent.prototype, "inputBorderColor", void 0);
257
- __decorate([
258
- (0, core_1.Input)(),
259
- __metadata("design:type", String)
260
- ], DualDatepickerComponent.prototype, "inputBorderColorHover", void 0);
261
- __decorate([
262
- (0, core_1.Input)(),
263
- __metadata("design:type", String)
264
- ], DualDatepickerComponent.prototype, "inputBorderColorFocus", void 0);
265
- __decorate([
266
- (0, core_1.Input)(),
267
- __metadata("design:type", String)
268
- ], DualDatepickerComponent.prototype, "inputPadding", void 0);
269
- __decorate([
270
- (0, core_1.Output)(),
271
- __metadata("design:type", Object)
272
- ], DualDatepickerComponent.prototype, "dateRangeChange", void 0);
273
- __decorate([
274
- (0, core_1.Output)(),
275
- __metadata("design:type", Object)
276
- ], DualDatepickerComponent.prototype, "dateRangeSelected", void 0);
277
- __decorate([
278
- (0, core_1.HostListener)('document:click', ['$event']),
279
- __metadata("design:type", Function),
280
- __metadata("design:paramtypes", [MouseEvent]),
281
- __metadata("design:returntype", void 0)
282
- ], DualDatepickerComponent.prototype, "onClickOutside", null);
283
- exports.DualDatepickerComponent = DualDatepickerComponent = __decorate([
284
- (0, core_1.Component)({
285
- selector: 'ngx-dual-datepicker',
286
- standalone: true,
287
- imports: [common_1.CommonModule, forms_1.FormsModule],
288
- templateUrl: './dual-datepicker.component.html',
289
- styleUrl: './dual-datepicker.component.scss'
290
- }),
291
- __metadata("design:paramtypes", [core_1.ElementRef])
292
- ], DualDatepickerComponent);
@@ -1,256 +0,0 @@
1
- // Dual Datepicker Component Styles
2
- .datepicker-wrapper {
3
- position: relative;
4
- width: 100%;
5
-
6
- .datepicker-input {
7
- display: block;
8
- width: 100%;
9
- padding: 0.375rem 0.75rem;
10
- font-size: 1rem;
11
- font-weight: 400;
12
- line-height: 1.5;
13
- color: #495057;
14
- background-color: #fff;
15
- background-clip: padding-box;
16
- border: 1px solid #ced4da;
17
- border-radius: 0.25rem;
18
- transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
19
- cursor: pointer;
20
-
21
- &:hover {
22
- border-color: var(--input-border-hover, #ced4da);
23
- }
24
-
25
- &:focus {
26
- border-color: var(--input-border-focus, #80bdff);
27
- box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
28
- outline: 0;
29
- }
30
-
31
- &::placeholder {
32
- color: #6c757d;
33
- opacity: 1;
34
- }
35
-
36
- &:disabled,
37
- &[readonly] {
38
- background-color: #e9ecef;
39
- opacity: 1;
40
- }
41
- }
42
- }
43
-
44
- .date-picker-dropdown {
45
- position: absolute;
46
- top: 100%;
47
- left: 0;
48
- margin-top: 4px;
49
- background: white;
50
- border: 1px solid #e1e4e8;
51
- border-radius: 8px;
52
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 0 1px rgba(0, 0, 0, 0.08);
53
- padding: 16px;
54
- z-index: 1060;
55
- min-width: 680px;
56
-
57
- @media (max-width: 768px) {
58
- min-width: 100%;
59
- left: 0;
60
- right: 0;
61
- }
62
- }
63
-
64
- .date-picker-header-only-close {
65
- display: flex;
66
- justify-content: flex-end;
67
- margin-bottom: 12px;
68
-
69
- .btn-close-calendar {
70
- background-color: transparent;
71
- border: 1px solid transparent;
72
- color: #6b7280;
73
- padding: 6px 10px;
74
- border-radius: 6px;
75
- cursor: pointer;
76
- transition: all 0.15s ease;
77
- font-size: 1.5rem;
78
- line-height: 1;
79
-
80
- &:hover {
81
- background-color: #fee;
82
- border-color: #fcc;
83
- color: #dc2626;
84
- transform: translateY(-1px);
85
- box-shadow: 0 2px 4px rgba(220, 38, 38, 0.1);
86
- }
87
-
88
- &:active {
89
- transform: translateY(0);
90
- box-shadow: none;
91
- }
92
- }
93
- }
94
-
95
- .date-picker-presets {
96
- display: flex;
97
- gap: 6px;
98
- margin-bottom: 16px;
99
- padding-bottom: 12px;
100
- border-bottom: 1px solid #e5e7eb;
101
- align-items: center;
102
-
103
- @media (max-width: 768px) {
104
- flex-wrap: wrap;
105
- }
106
-
107
- button {
108
- font-size: 0.75rem;
109
- padding: 6px 14px;
110
- border: none;
111
- background-color: #f9fafb;
112
- color: #374151;
113
- border-radius: 6px;
114
- transition: all 0.15s ease;
115
- font-weight: 500;
116
- cursor: pointer;
117
- border: 1px solid #e5e7eb;
118
-
119
- &:hover {
120
- background-color: #f3f4f6;
121
- border-color: #d1d5db;
122
- transform: translateY(-1px);
123
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
124
- }
125
-
126
- &:active {
127
- transform: translateY(0);
128
- box-shadow: none;
129
- }
130
- }
131
-
132
- .btn-close-calendar {
133
- margin-left: auto;
134
- background-color: transparent;
135
- border: 1px solid transparent;
136
- color: #6b7280;
137
- padding: 6px 10px;
138
- font-size: 1.5rem;
139
- line-height: 1;
140
-
141
- &:hover {
142
- background-color: #fee;
143
- border-color: #fcc;
144
- color: #dc2626;
145
- transform: translateY(-1px);
146
- box-shadow: 0 2px 4px rgba(220, 38, 38, 0.1);
147
- }
148
-
149
- &:active {
150
- transform: translateY(0);
151
- box-shadow: none;
152
- }
153
- }
154
- }
155
-
156
- .date-picker-calendars {
157
- display: flex;
158
- gap: 32px;
159
-
160
- @media (max-width: 768px) {
161
- flex-direction: column;
162
- gap: 16px;
163
- }
164
- }
165
-
166
- .date-picker-calendar {
167
- flex: 1;
168
- }
169
-
170
- .date-picker-header {
171
- display: flex;
172
- justify-content: space-between;
173
- align-items: center;
174
- margin-bottom: 12px;
175
- padding: 0 4px;
176
-
177
- span {
178
- font-size: 0.813rem;
179
- font-weight: 600;
180
- color: #111827;
181
- }
182
-
183
- button {
184
- padding: 4px;
185
- color: #6b7280;
186
- text-decoration: none;
187
- border-radius: 6px;
188
- transition: all 0.15s ease;
189
- border: none;
190
- background: transparent;
191
- cursor: pointer;
192
-
193
- &:hover {
194
- background-color: #f3f4f6;
195
- color: #111827;
196
- }
197
- }
198
- }
199
-
200
- .date-picker-weekdays {
201
- display: grid;
202
- grid-template-columns: repeat(7, 1fr);
203
- gap: 2px;
204
- margin-bottom: 4px;
205
-
206
- span {
207
- text-align: center;
208
- font-size: 0.625rem;
209
- font-weight: 600;
210
- color: #6b7280;
211
- padding: 6px;
212
- }
213
- }
214
-
215
- .date-picker-days {
216
- display: grid;
217
- grid-template-columns: repeat(7, 1fr);
218
- gap: 2px;
219
- }
220
-
221
- .date-picker-day {
222
- aspect-ratio: 1;
223
- border: none;
224
- background: transparent;
225
- border-radius: 50%;
226
- font-size: 0.75rem;
227
- cursor: pointer;
228
- transition: all 0.15s ease;
229
- color: #374151;
230
- font-weight: 400;
231
-
232
- &:hover:not(:disabled):not(.selected) {
233
- background-color: #f3f4f6;
234
- color: #111827;
235
- }
236
-
237
- &.empty {
238
- visibility: hidden;
239
- }
240
-
241
- &.selected {
242
- background-color: #222;
243
- color: white;
244
- font-weight: 600;
245
- }
246
-
247
- &.in-range {
248
- background-color: #f9fafb;
249
- border-radius: 0;
250
- }
251
-
252
- &:disabled {
253
- cursor: not-allowed;
254
- opacity: 0.3;
255
- }
256
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC"}
package/dist/index.esm.js DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * Public API Surface of @ngx-tools/dual-datepicker
3
- */
4
-
5
- export { DualDatepickerComponent } from './dual-datepicker.component.js';
package/dist/index.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- /**
3
- * Public API Surface of @oneluiz/dual-datepicker
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DualDatepickerComponent = void 0;
7
- var dual_datepicker_component_1 = require("./dual-datepicker.component");
8
- Object.defineProperty(exports, "DualDatepickerComponent", { enumerable: true, get: function () { return dual_datepicker_component_1.DualDatepickerComponent; } });