@libs-ui/components-datetime-dropdown 0.2.355-13 → 0.2.355-15
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/README.md +318 -2
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,3 +1,319 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Datetime Dropdown
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Component chọn ngày/tháng/năm/quý dạng dropdown, hỗ trợ single và multi (from-to) selection với validation tự động.
|
|
4
|
+
|
|
5
|
+
## Version
|
|
6
|
+
|
|
7
|
+
`0.2.355-14`
|
|
8
|
+
|
|
9
|
+
## Khi nào sử dụng
|
|
10
|
+
|
|
11
|
+
- Cần chọn tháng/năm/quý từ dropdown thay vì calendar picker
|
|
12
|
+
- Cần chọn khoảng thời gian (from-to) với validation tự động
|
|
13
|
+
- Cần tùy chỉnh format hiển thị (`year`, `month`, `quarter`, `year-month`, `month-day`, `year-quarter`)
|
|
14
|
+
- Cần responsive layout tự động cho form nhỏ
|
|
15
|
+
|
|
16
|
+
## Important Notes
|
|
17
|
+
|
|
18
|
+
- `selectedDateTime` sử dụng `WritableSignal` — cần tạo signal trước khi truyền vào
|
|
19
|
+
- `typeFormat` quyết định số lượng và loại dropdown hiển thị
|
|
20
|
+
- `isMultiple=true` sẽ hiển thị 2 nhóm dropdown (From/To) với validation so sánh
|
|
21
|
+
- Component tự động responsive khi không đủ không gian
|
|
22
|
+
|
|
23
|
+
## Cài đặt & Import
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import {
|
|
27
|
+
LibsUiComponentsDatetimeDropdownComponent,
|
|
28
|
+
IEmitSingleDateDropdown,
|
|
29
|
+
IEmitMultiDateDropdown,
|
|
30
|
+
IDateDropdownFunctionControlEvent,
|
|
31
|
+
TYPE_DATE_DROPDOWN_FORMAT,
|
|
32
|
+
IFromAndToDateLabel,
|
|
33
|
+
IValidDateDropdown,
|
|
34
|
+
} from '@libs-ui/components-datetime-dropdown';
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Ví dụ sử dụng
|
|
38
|
+
|
|
39
|
+
### 1. Basic Usage (month-day single)
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<libs_ui-components-datetime-dropdown
|
|
43
|
+
[typeFormat]="'month-day'"
|
|
44
|
+
(outChooseSingleDate)="onSingleDateSelected($event)"
|
|
45
|
+
></libs_ui-components-datetime-dropdown>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { signal } from '@angular/core';
|
|
50
|
+
import { IEmitSingleDateDropdown } from '@libs-ui/components-datetime-dropdown';
|
|
51
|
+
|
|
52
|
+
onSingleDateSelected(event: IEmitSingleDateDropdown) {
|
|
53
|
+
console.log('Month:', event.month, 'Day:', event.day);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 2. Different Formats
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<!-- Chỉ chọn năm -->
|
|
61
|
+
<libs_ui-components-datetime-dropdown
|
|
62
|
+
[typeFormat]="'year'"
|
|
63
|
+
[reverseYear]="true"
|
|
64
|
+
[minYear]="2020"
|
|
65
|
+
[maxYear]="2030"
|
|
66
|
+
(outChooseSingleDate)="onYearSelected($event)"
|
|
67
|
+
></libs_ui-components-datetime-dropdown>
|
|
68
|
+
|
|
69
|
+
<!-- Chỉ chọn tháng -->
|
|
70
|
+
<libs_ui-components-datetime-dropdown
|
|
71
|
+
[typeFormat]="'month'"
|
|
72
|
+
(outChooseSingleDate)="onMonthSelected($event)"
|
|
73
|
+
></libs_ui-components-datetime-dropdown>
|
|
74
|
+
|
|
75
|
+
<!-- Chọn năm-tháng -->
|
|
76
|
+
<libs_ui-components-datetime-dropdown
|
|
77
|
+
[typeFormat]="'year-month'"
|
|
78
|
+
(outChooseSingleDate)="onYearMonthSelected($event)"
|
|
79
|
+
></libs_ui-components-datetime-dropdown>
|
|
80
|
+
|
|
81
|
+
<!-- Chọn năm-quý -->
|
|
82
|
+
<libs_ui-components-datetime-dropdown
|
|
83
|
+
[typeFormat]="'year-quarter'"
|
|
84
|
+
(outChooseSingleDate)="onYearQuarterSelected($event)"
|
|
85
|
+
></libs_ui-components-datetime-dropdown>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 3. Multi Date Range (from-to)
|
|
89
|
+
|
|
90
|
+
```html
|
|
91
|
+
<libs_ui-components-datetime-dropdown
|
|
92
|
+
[typeFormat]="'year-month'"
|
|
93
|
+
[isMultiple]="true"
|
|
94
|
+
[fromAndToDateLabel]="{ from: 'i18n_label_from', to: 'i18n_to' }"
|
|
95
|
+
[selectedDateTime]="selectedRange"
|
|
96
|
+
(outChooseMultiDate)="onMultiDateSelected($event)"
|
|
97
|
+
(outFunctionsControl)="onFunctionsControl($event)"
|
|
98
|
+
></libs_ui-components-datetime-dropdown>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { signal, WritableSignal } from '@angular/core';
|
|
103
|
+
import {
|
|
104
|
+
IEmitMultiDateDropdown,
|
|
105
|
+
IEmitSingleDateDropdown,
|
|
106
|
+
IDateDropdownFunctionControlEvent,
|
|
107
|
+
} from '@libs-ui/components-datetime-dropdown';
|
|
108
|
+
|
|
109
|
+
selectedRange: IEmitMultiDateDropdown = {
|
|
110
|
+
from: signal<IEmitSingleDateDropdown>({ year: 2024, month: 1 }),
|
|
111
|
+
to: signal<IEmitSingleDateDropdown>({ year: 2024, month: 12 }),
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
functionsControl!: IDateDropdownFunctionControlEvent;
|
|
115
|
+
|
|
116
|
+
onMultiDateSelected(event: IEmitMultiDateDropdown) {
|
|
117
|
+
console.log('From:', event.from(), 'To:', event.to());
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
onFunctionsControl(event: IDateDropdownFunctionControlEvent) {
|
|
121
|
+
this.functionsControl = event;
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 4. With Validation
|
|
126
|
+
|
|
127
|
+
```html
|
|
128
|
+
<libs_ui-components-datetime-dropdown
|
|
129
|
+
[typeFormat]="'year-month'"
|
|
130
|
+
[isMultiple]="true"
|
|
131
|
+
[validRequired]="{ message: 'i18n_required', messageValidCompareTime: 'i18n_invalid_range' }"
|
|
132
|
+
[ignoreAllowTimeEqual]="true"
|
|
133
|
+
[ignoreValidTimeCompare]="false"
|
|
134
|
+
[isCheckErrorWhenSelectItem]="true"
|
|
135
|
+
[isBorderError]="isBorderError"
|
|
136
|
+
(outFunctionsControl)="onFunctionsControl($event)"
|
|
137
|
+
(outChooseMultiDate)="onMultiDateSelected($event)"
|
|
138
|
+
></libs_ui-components-datetime-dropdown>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
async onSubmit() {
|
|
143
|
+
const isValid = await this.functionsControl.checkIsValid();
|
|
144
|
+
if (!isValid) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// Tiến hành submit
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
resetForm() {
|
|
151
|
+
this.functionsControl.resetTime?.();
|
|
152
|
+
this.functionsControl.resetError?.();
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## API Reference
|
|
157
|
+
|
|
158
|
+
### Inputs
|
|
159
|
+
|
|
160
|
+
| Tên | Kiểu | Mặc định | Mô tả |
|
|
161
|
+
| --- | --- | --- | --- |
|
|
162
|
+
| `[classIncludeTextDisplayWhenNoSelect]` | `string \| undefined` | `undefined` | CSS class tùy chỉnh text hiển thị khi chưa chọn giá trị |
|
|
163
|
+
| `[disable]` | `boolean` | `false` | Vô hiệu hóa toàn bộ component |
|
|
164
|
+
| `[disableSecond]` | `boolean` | `false` | Vô hiệu hóa dropdown thứ hai cho đến khi dropdown đầu tiên được chọn |
|
|
165
|
+
| `[fromAndToDateLabel]` | `IFromAndToDateLabel` | `{ from: 'i18n_label_from', to: 'i18n_to' }` | Tùy chỉnh label From/To khi `isMultiple=true` |
|
|
166
|
+
| `[getItemYearDisplay]` | `(year: string) => string` | — | Hàm tùy chỉnh hiển thị label cho item năm |
|
|
167
|
+
| `[hiddenDate]` | `IHiddenDate \| undefined` | `undefined` | Ẩn các giá trị ngày/tháng cụ thể khỏi dropdown |
|
|
168
|
+
| `[ignoreAllowTimeEqual]` | `boolean` | `true` | Bỏ qua cho phép thời gian bằng nhau khi so sánh from/to. `true` = from phải nhỏ hơn to (không cho bằng) |
|
|
169
|
+
| `[ignoreConvertYearSelected]` | `boolean` | `false` | Bỏ qua chuyển đổi label năm đã chọn (hiển thị raw value) |
|
|
170
|
+
| `[ignoreFromAndToDateLabel]` | `boolean` | `false` | Ẩn label From/To khi `isMultiple=true` |
|
|
171
|
+
| `[ignoreRequiredValueSecondWhenNotValidRequired]` | `boolean` | `false` | Bỏ qua validate giá trị thứ 2 khi `validRequired` không được set |
|
|
172
|
+
| `[ignoreValidTimeCompare]` | `boolean` | `false` | Bỏ qua validation so sánh thời gian from/to |
|
|
173
|
+
| `[isBorderError]` | `boolean` | `false` | Hiển thị viền lỗi trên component |
|
|
174
|
+
| `[isCheckErrorWhenSelectItem]` | `boolean` | `true` | Kiểm tra lỗi mỗi khi chọn item |
|
|
175
|
+
| `[isEmitAfterChanged]` | `boolean` | `false` | Emit `outSelectedDropdown` mỗi lần chọn giá trị (bao gồm lần đầu init) |
|
|
176
|
+
| `[isMultiple]` | `boolean` | `false` | Chế độ multi selection (From/To) — hiển thị 2 nhóm dropdown |
|
|
177
|
+
| `[labelConfig]` | `ILabel \| undefined` | `undefined` | Cấu hình label (từ `@libs-ui/components-label`) |
|
|
178
|
+
| `[listHasButtonUnSelectOption]` | `boolean` | `false` | Hiển thị nút bỏ chọn trong dropdown list |
|
|
179
|
+
| `[listKeysDisable]` | `IDateDropdownDisableKeys \| undefined` | `undefined` | Danh sách key bị vô hiệu hóa cho từng dropdown (from/to) |
|
|
180
|
+
| `[listMaxItemShow]` | `{ year?: number; month?: number; quarter?: number; day?: number } \| undefined` | `undefined` | Giới hạn số item hiển thị cho từng loại dropdown |
|
|
181
|
+
| `[maxYear]` | `number` | `0` (sử dụng DEFAULT_MAX_YEAR) | Năm tối đa hiển thị trong dropdown năm |
|
|
182
|
+
| `[minWidth]` | `number \| undefined` | `undefined` | Chiều rộng tối thiểu của component (px) |
|
|
183
|
+
| `[minYear]` | `number` | `0` (sử dụng DEFAULT_MIN_YEAR) | Năm tối thiểu hiển thị trong dropdown năm |
|
|
184
|
+
| `[readonly]` | `boolean` | `false` | Chế độ chỉ đọc |
|
|
185
|
+
| `[reverseYear]` | `boolean \| undefined` | `undefined` | Đảo ngược thứ tự danh sách năm (năm mới nhất lên đầu) |
|
|
186
|
+
| `[selectedDateTime]` | `IEmitMultiDateDropdown \| undefined` | `undefined` | Giá trị khởi tạo — sử dụng `WritableSignal` bên trong |
|
|
187
|
+
| `[typeFormat]` | `TYPE_DATE_DROPDOWN_FORMAT` | `'month-day'` | Loại format hiển thị: `'year'`, `'month'`, `'quarter'`, `'year-month'`, `'month-day'`, `'year-quarter'` |
|
|
188
|
+
| `[validRequired]` | `IValidDateDropdown` | — | Cấu hình validation bắt buộc với message lỗi tùy chỉnh |
|
|
189
|
+
| `[widthByElement]` | `boolean` | `false` | Tính width dropdown theo phần tử cha |
|
|
190
|
+
| `[widthDropdown]` | `number` | `136` | Chiều rộng mỗi dropdown (px) |
|
|
191
|
+
| `[zIndex]` | `number` | `1200` | z-index của dropdown overlay |
|
|
192
|
+
|
|
193
|
+
### Outputs
|
|
194
|
+
|
|
195
|
+
| Tên | Kiểu | Mô tả |
|
|
196
|
+
| --- | --- | --- |
|
|
197
|
+
| `(outChangStageFlagMouse)` | `EventEmitter<IFlagMouse>` | Emit khi trạng thái chuột thay đổi (hover/leave) |
|
|
198
|
+
| `(outChooseMultiDate)` | `EventEmitter<IEmitMultiDateDropdown>` | Emit khi chọn đầy đủ cả From và To (chỉ khi `isMultiple=true`) |
|
|
199
|
+
| `(outChooseSingleDate)` | `EventEmitter<IEmitSingleDateDropdown>` | Emit khi chọn đầy đủ single date (chỉ khi `isMultiple=false`) |
|
|
200
|
+
| `(outFunctionsControl)` | `EventEmitter<IDateDropdownFunctionControlEvent>` | Emit object chứa các hàm điều khiển component từ bên ngoài |
|
|
201
|
+
| `(outSelectedDropdown)` | `EventEmitter<IEmitSingleDateDropdown \| IEmitMultiDateDropdown>` | Emit mỗi lần chọn giá trị (cần `isEmitAfterChanged=true`). Lưu ý: cần check `undefined` kỹ khi sử dụng |
|
|
202
|
+
|
|
203
|
+
### FunctionsControl Methods
|
|
204
|
+
|
|
205
|
+
Object nhận được từ `(outFunctionsControl)`:
|
|
206
|
+
|
|
207
|
+
| Method | Kiểu trả về | Mô tả |
|
|
208
|
+
| --- | --- | --- |
|
|
209
|
+
| `checkIsValid()` | `Promise<boolean>` | Kiểm tra validation toàn bộ component. Trả về `false` nếu có lỗi required hoặc lỗi so sánh from/to |
|
|
210
|
+
| `resetError()` | `Promise<void>` | Xóa tất cả trạng thái lỗi hiển thị trên component |
|
|
211
|
+
| `resetTime()` | `Promise<void>` | Reset toàn bộ giá trị đã chọn về trạng thái ban đầu |
|
|
212
|
+
|
|
213
|
+
## Types & Interfaces
|
|
214
|
+
|
|
215
|
+
### TYPE_DATE_DROPDOWN_FORMAT
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
type TYPE_DATE_DROPDOWN_FORMAT = 'year' | 'month' | 'quarter' | 'year-month' | 'month-day' | 'year-quarter' | string;
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### TYPE_DATE_FORMAT
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
type TYPE_DATE_FORMAT = 'year' | 'month' | 'quarter' | 'day';
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### IEmitSingleDateDropdown
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
interface IEmitSingleDateDropdown {
|
|
231
|
+
year?: number;
|
|
232
|
+
month?: number;
|
|
233
|
+
quarter?: number;
|
|
234
|
+
day?: number;
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### IEmitMultiDateDropdown
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
interface IEmitMultiDateDropdown {
|
|
242
|
+
from: WritableSignal<IEmitSingleDateDropdown>;
|
|
243
|
+
to: WritableSignal<IEmitSingleDateDropdown>;
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### IDateDropdownFunctionControlEvent
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
interface IDateDropdownFunctionControlEvent {
|
|
251
|
+
checkIsValid: () => Promise<boolean>;
|
|
252
|
+
resetError?: () => Promise<void>;
|
|
253
|
+
resetTime?: () => Promise<void>;
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### IValidDateDropdown
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
interface IValidDateDropdown {
|
|
261
|
+
message?: string;
|
|
262
|
+
interpolateParams?: { any: object };
|
|
263
|
+
messageValidCompareTime?: string;
|
|
264
|
+
interpolateParamsCompareTime?: { any: object };
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### IFromAndToDateLabel
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
interface IFromAndToDateLabel {
|
|
272
|
+
to?: string;
|
|
273
|
+
from?: string;
|
|
274
|
+
classLabelTo?: string;
|
|
275
|
+
classLabelFrom?: string;
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### IDateDropdownDisableKeys
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
interface IDateDropdownDisableKeys {
|
|
283
|
+
from?: WritableSignal<IDateDropdownDisable>;
|
|
284
|
+
to?: WritableSignal<IDateDropdownDisable>;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
interface IDateDropdownDisable {
|
|
288
|
+
year?: WritableSignal<Array<number>>;
|
|
289
|
+
month?: WritableSignal<Array<number>>;
|
|
290
|
+
quarter?: WritableSignal<Array<number>>;
|
|
291
|
+
day?: WritableSignal<Array<number>>;
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### IHiddenDate
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
interface IHiddenDate {
|
|
299
|
+
formatDate: TYPE_DATE_DROPDOWN_FORMAT;
|
|
300
|
+
yearMonth?: WritableSignal<Array<WritableSignal<{ hiddenYear: number; hiddenMonths: Array<number> }>>>;
|
|
301
|
+
monthDay?: WritableSignal<Array<WritableSignal<{ hiddenMonth: number; hiddenDays: Array<number> }>>>;
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## Tùy chỉnh style
|
|
306
|
+
|
|
307
|
+
- Sử dụng `[classIncludeTextDisplayWhenNoSelect]` để tùy chỉnh text display khi chưa chọn giá trị
|
|
308
|
+
- Sử dụng `[widthDropdown]` để điều chỉnh chiều rộng mỗi dropdown (mặc định `136px`)
|
|
309
|
+
- Sử dụng `[fromAndToDateLabel]` để tùy chỉnh label From/To, bao gồm cả CSS class qua `classLabelFrom` và `classLabelTo`
|
|
310
|
+
|
|
311
|
+
## Demo
|
|
312
|
+
|
|
313
|
+
- Local: [http://localhost:4500/datetime/dropdown](http://localhost:4500/datetime/dropdown)
|
|
314
|
+
|
|
315
|
+
## Test
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
npx nx test components-datetime-dropdown
|
|
319
|
+
```
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libs-ui/components-datetime-dropdown",
|
|
3
|
-
"version": "0.2.355-
|
|
3
|
+
"version": "0.2.355-15",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/core": ">=18.0.0",
|
|
6
6
|
"@ngx-translate/core": "^15.0.0",
|
|
7
|
-
"@libs-ui/services-http-request": "0.2.355-
|
|
8
|
-
"@libs-ui/utils": "0.2.355-
|
|
9
|
-
"@libs-ui/components-datetime-picker": "0.2.355-
|
|
10
|
-
"@libs-ui/components-label": "0.2.355-
|
|
11
|
-
"@libs-ui/components-popover": "0.2.355-
|
|
7
|
+
"@libs-ui/services-http-request": "0.2.355-15",
|
|
8
|
+
"@libs-ui/utils": "0.2.355-15",
|
|
9
|
+
"@libs-ui/components-datetime-picker": "0.2.355-15",
|
|
10
|
+
"@libs-ui/components-label": "0.2.355-15",
|
|
11
|
+
"@libs-ui/components-popover": "0.2.355-15",
|
|
12
12
|
"rxjs": "~7.8.0",
|
|
13
|
-
"@libs-ui/components-dropdown": "0.2.355-
|
|
14
|
-
"@libs-ui/components-list": "0.2.355-
|
|
13
|
+
"@libs-ui/components-dropdown": "0.2.355-15",
|
|
14
|
+
"@libs-ui/components-list": "0.2.355-15"
|
|
15
15
|
},
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"module": "fesm2022/libs-ui-components-datetime-dropdown.mjs",
|