iter(g115): 新增月历组件 calendar
This commit is contained in:
@@ -3,22 +3,7 @@ import type { Signal } from '@ui-arch/frame';
|
||||
import { bindOutside, pushOverlay } from './overlay.js';
|
||||
import { flip } from './position.js';
|
||||
import type { DatePickerProps } from './types.js';
|
||||
|
||||
const pad = (n: number): string => String(n).padStart(2, '0'); // 两位补零
|
||||
const fmt = (y: number, m: number, d: number): string => `${y}-${pad(m + 1)}-${pad(d)}`; // 拼成 YYYY-MM-DD
|
||||
const parse = (s: string): [number, number, number] | null => {
|
||||
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
|
||||
return m ? [Number(m[1]), Number(m[2]) - 1, Number(m[3])] : null; // 非法串返回 null,调用方回落到今天
|
||||
};
|
||||
const today = (): [number, number, number] => {
|
||||
const d = new Date();
|
||||
return [d.getFullYear(), d.getMonth(), d.getDate()];
|
||||
};
|
||||
const shiftDay = (key: string, delta: number): string => {
|
||||
const p = parse(key) ?? today();
|
||||
const d = new Date(p[0], p[1], p[2] + delta);
|
||||
return fmt(d.getFullYear(), d.getMonth(), d.getDate());
|
||||
};
|
||||
import { fmt, pad, parse, shiftDay, today } from './dateKit.js';
|
||||
|
||||
/*** 日期选择:单月网格 + 上下月翻页 + 今天快捷键,value 信号双向绑定,方向键/PageUp/PageDown 可导航 ***/
|
||||
export function datePicker(props: DatePickerProps): HTMLElement {
|
||||
|
||||
Reference in New Issue
Block a user