npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@libs-ui/components-datetime-dropdown

v0.2.356-1

Published

> 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.

Readme

Datetime Dropdown

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.

Version

0.2.355-14

Khi nào sử dụng

  • Cần chọn tháng/năm/quý từ dropdown thay vì calendar picker
  • Cần chọn khoảng thời gian (from-to) với validation tự động
  • Cần tùy chỉnh format hiển thị (year, month, quarter, year-month, month-day, year-quarter)
  • Cần responsive layout tự động cho form nhỏ

Important Notes

  • selectedDateTime sử dụng WritableSignal — cần tạo signal trước khi truyền vào
  • typeFormat quyết định số lượng và loại dropdown hiển thị
  • isMultiple=true sẽ hiển thị 2 nhóm dropdown (From/To) với validation so sánh
  • Component tự động responsive khi không đủ không gian

Cài đặt & Import

import {
  LibsUiComponentsDatetimeDropdownComponent,
  IEmitSingleDateDropdown,
  IEmitMultiDateDropdown,
  IDateDropdownFunctionControlEvent,
  TYPE_DATE_DROPDOWN_FORMAT,
  IFromAndToDateLabel,
  IValidDateDropdown,
} from '@libs-ui/components-datetime-dropdown';

Ví dụ sử dụng

1. Basic Usage (month-day single)

<libs_ui-components-datetime-dropdown
  [typeFormat]="'month-day'"
  (outChooseSingleDate)="onSingleDateSelected($event)"
></libs_ui-components-datetime-dropdown>
import { signal } from '@angular/core';
import { IEmitSingleDateDropdown } from '@libs-ui/components-datetime-dropdown';

onSingleDateSelected(event: IEmitSingleDateDropdown) {
  console.log('Month:', event.month, 'Day:', event.day);
}

2. Different Formats

<!-- Chỉ chọn năm -->
<libs_ui-components-datetime-dropdown
  [typeFormat]="'year'"
  [reverseYear]="true"
  [minYear]="2020"
  [maxYear]="2030"
  (outChooseSingleDate)="onYearSelected($event)"
></libs_ui-components-datetime-dropdown>

<!-- Chỉ chọn tháng -->
<libs_ui-components-datetime-dropdown
  [typeFormat]="'month'"
  (outChooseSingleDate)="onMonthSelected($event)"
></libs_ui-components-datetime-dropdown>

<!-- Chọn năm-tháng -->
<libs_ui-components-datetime-dropdown
  [typeFormat]="'year-month'"
  (outChooseSingleDate)="onYearMonthSelected($event)"
></libs_ui-components-datetime-dropdown>

<!-- Chọn năm-quý -->
<libs_ui-components-datetime-dropdown
  [typeFormat]="'year-quarter'"
  (outChooseSingleDate)="onYearQuarterSelected($event)"
></libs_ui-components-datetime-dropdown>

3. Multi Date Range (from-to)

<libs_ui-components-datetime-dropdown
  [typeFormat]="'year-month'"
  [isMultiple]="true"
  [fromAndToDateLabel]="{ from: 'i18n_label_from', to: 'i18n_to' }"
  [selectedDateTime]="selectedRange"
  (outChooseMultiDate)="onMultiDateSelected($event)"
  (outFunctionsControl)="onFunctionsControl($event)"
></libs_ui-components-datetime-dropdown>
import { signal, WritableSignal } from '@angular/core';
import {
  IEmitMultiDateDropdown,
  IEmitSingleDateDropdown,
  IDateDropdownFunctionControlEvent,
} from '@libs-ui/components-datetime-dropdown';

selectedRange: IEmitMultiDateDropdown = {
  from: signal<IEmitSingleDateDropdown>({ year: 2024, month: 1 }),
  to: signal<IEmitSingleDateDropdown>({ year: 2024, month: 12 }),
};

functionsControl!: IDateDropdownFunctionControlEvent;

onMultiDateSelected(event: IEmitMultiDateDropdown) {
  console.log('From:', event.from(), 'To:', event.to());
}

onFunctionsControl(event: IDateDropdownFunctionControlEvent) {
  this.functionsControl = event;
}

4. With Validation

<libs_ui-components-datetime-dropdown
  [typeFormat]="'year-month'"
  [isMultiple]="true"
  [validRequired]="{ message: 'i18n_required', messageValidCompareTime: 'i18n_invalid_range' }"
  [ignoreAllowTimeEqual]="true"
  [ignoreValidTimeCompare]="false"
  [isCheckErrorWhenSelectItem]="true"
  [isBorderError]="isBorderError"
  (outFunctionsControl)="onFunctionsControl($event)"
  (outChooseMultiDate)="onMultiDateSelected($event)"
></libs_ui-components-datetime-dropdown>
async onSubmit() {
  const isValid = await this.functionsControl.checkIsValid();
  if (!isValid) {
    return;
  }
  // Tiến hành submit
}

resetForm() {
  this.functionsControl.resetTime?.();
  this.functionsControl.resetError?.();
}

API Reference

Inputs

| Tên | Kiểu | Mặc định | Mô tả | | --- | --- | --- | --- | | [classIncludeTextDisplayWhenNoSelect] | string \| undefined | undefined | CSS class tùy chỉnh text hiển thị khi chưa chọn giá trị | | [disable] | boolean | false | Vô hiệu hóa toàn bộ component | | [disableSecond] | boolean | false | Vô hiệu hóa dropdown thứ hai cho đến khi dropdown đầu tiên được chọn | | [fromAndToDateLabel] | IFromAndToDateLabel | { from: 'i18n_label_from', to: 'i18n_to' } | Tùy chỉnh label From/To khi isMultiple=true | | [getItemYearDisplay] | (year: string) => string | — | Hàm tùy chỉnh hiển thị label cho item năm | | [hiddenDate] | IHiddenDate \| undefined | undefined | Ẩn các giá trị ngày/tháng cụ thể khỏi dropdown | | [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) | | [ignoreConvertYearSelected] | boolean | false | Bỏ qua chuyển đổi label năm đã chọn (hiển thị raw value) | | [ignoreFromAndToDateLabel] | boolean | false | Ẩn label From/To khi isMultiple=true | | [ignoreRequiredValueSecondWhenNotValidRequired] | boolean | false | Bỏ qua validate giá trị thứ 2 khi validRequired không được set | | [ignoreValidTimeCompare] | boolean | false | Bỏ qua validation so sánh thời gian from/to | | [isBorderError] | boolean | false | Hiển thị viền lỗi trên component | | [isCheckErrorWhenSelectItem] | boolean | true | Kiểm tra lỗi mỗi khi chọn item | | [isEmitAfterChanged] | boolean | false | Emit outSelectedDropdown mỗi lần chọn giá trị (bao gồm lần đầu init) | | [isMultiple] | boolean | false | Chế độ multi selection (From/To) — hiển thị 2 nhóm dropdown | | [labelConfig] | ILabel \| undefined | undefined | Cấu hình label (từ @libs-ui/components-label) | | [listHasButtonUnSelectOption] | boolean | false | Hiển thị nút bỏ chọn trong dropdown list | | [listKeysDisable] | IDateDropdownDisableKeys \| undefined | undefined | Danh sách key bị vô hiệu hóa cho từng dropdown (from/to) | | [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 | | [maxYear] | number | 0 (sử dụng DEFAULT_MAX_YEAR) | Năm tối đa hiển thị trong dropdown năm | | [minWidth] | number \| undefined | undefined | Chiều rộng tối thiểu của component (px) | | [minYear] | number | 0 (sử dụng DEFAULT_MIN_YEAR) | Năm tối thiểu hiển thị trong dropdown năm | | [readonly] | boolean | false | Chế độ chỉ đọc | | [reverseYear] | boolean \| undefined | undefined | Đảo ngược thứ tự danh sách năm (năm mới nhất lên đầu) | | [selectedDateTime] | IEmitMultiDateDropdown \| undefined | undefined | Giá trị khởi tạo — sử dụng WritableSignal bên trong | | [typeFormat] | TYPE_DATE_DROPDOWN_FORMAT | 'month-day' | Loại format hiển thị: 'year', 'month', 'quarter', 'year-month', 'month-day', 'year-quarter' | | [validRequired] | IValidDateDropdown | — | Cấu hình validation bắt buộc với message lỗi tùy chỉnh | | [widthByElement] | boolean | false | Tính width dropdown theo phần tử cha | | [widthDropdown] | number | 136 | Chiều rộng mỗi dropdown (px) | | [zIndex] | number | 1200 | z-index của dropdown overlay |

Outputs

| Tên | Kiểu | Mô tả | | --- | --- | --- | | (outChangStageFlagMouse) | EventEmitter<IFlagMouse> | Emit khi trạng thái chuột thay đổi (hover/leave) | | (outChooseMultiDate) | EventEmitter<IEmitMultiDateDropdown> | Emit khi chọn đầy đủ cả From và To (chỉ khi isMultiple=true) | | (outChooseSingleDate) | EventEmitter<IEmitSingleDateDropdown> | Emit khi chọn đầy đủ single date (chỉ khi isMultiple=false) | | (outFunctionsControl) | EventEmitter<IDateDropdownFunctionControlEvent> | Emit object chứa các hàm điều khiển component từ bên ngoài | | (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 |

FunctionsControl Methods

Object nhận được từ (outFunctionsControl):

| Method | Kiểu trả về | Mô tả | | --- | --- | --- | | 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 | | resetError() | Promise<void> | Xóa tất cả trạng thái lỗi hiển thị trên component | | resetTime() | Promise<void> | Reset toàn bộ giá trị đã chọn về trạng thái ban đầu |

Types & Interfaces

TYPE_DATE_DROPDOWN_FORMAT

type TYPE_DATE_DROPDOWN_FORMAT = 'year' | 'month' | 'quarter' | 'year-month' | 'month-day' | 'year-quarter' | string;

TYPE_DATE_FORMAT

type TYPE_DATE_FORMAT = 'year' | 'month' | 'quarter' | 'day';

IEmitSingleDateDropdown

interface IEmitSingleDateDropdown {
  year?: number;
  month?: number;
  quarter?: number;
  day?: number;
}

IEmitMultiDateDropdown

interface IEmitMultiDateDropdown {
  from: WritableSignal<IEmitSingleDateDropdown>;
  to: WritableSignal<IEmitSingleDateDropdown>;
}

IDateDropdownFunctionControlEvent

interface IDateDropdownFunctionControlEvent {
  checkIsValid: () => Promise<boolean>;
  resetError?: () => Promise<void>;
  resetTime?: () => Promise<void>;
}

IValidDateDropdown

interface IValidDateDropdown {
  message?: string;
  interpolateParams?: { any: object };
  messageValidCompareTime?: string;
  interpolateParamsCompareTime?: { any: object };
}

IFromAndToDateLabel

interface IFromAndToDateLabel {
  to?: string;
  from?: string;
  classLabelTo?: string;
  classLabelFrom?: string;
}

IDateDropdownDisableKeys

interface IDateDropdownDisableKeys {
  from?: WritableSignal<IDateDropdownDisable>;
  to?: WritableSignal<IDateDropdownDisable>;
}

interface IDateDropdownDisable {
  year?: WritableSignal<Array<number>>;
  month?: WritableSignal<Array<number>>;
  quarter?: WritableSignal<Array<number>>;
  day?: WritableSignal<Array<number>>;
}

IHiddenDate

interface IHiddenDate {
  formatDate: TYPE_DATE_DROPDOWN_FORMAT;
  yearMonth?: WritableSignal<Array<WritableSignal<{ hiddenYear: number; hiddenMonths: Array<number> }>>>;
  monthDay?: WritableSignal<Array<WritableSignal<{ hiddenMonth: number; hiddenDays: Array<number> }>>>;
}

Tùy chỉnh style

  • Sử dụng [classIncludeTextDisplayWhenNoSelect] để tùy chỉnh text display khi chưa chọn giá trị
  • Sử dụng [widthDropdown] để điều chỉnh chiều rộng mỗi dropdown (mặc định 136px)
  • Sử dụng [fromAndToDateLabel] để tùy chỉnh label From/To, bao gồm cả CSS class qua classLabelFromclassLabelTo

Demo

Test

npx nx test components-datetime-dropdown