jamis
Version:
一种支持通过JSON配置方式生成页面的组件库
114 lines (113 loc) • 4.3 kB
TypeScript
import type { ThemeProps } from 'jamis-core';
import type { Moment } from 'moment';
export type DateType = 'year' | 'month' | 'date' | 'hours' | 'minutes' | 'seconds' | 'milliseconds';
export interface BoundaryObject {
max: number;
min: number;
}
export interface DateBoundary {
year: BoundaryObject;
month: BoundaryObject;
date: BoundaryObject;
hours: BoundaryObject;
minutes: BoundaryObject;
seconds: BoundaryObject;
milliseconds?: BoundaryObject;
}
export type TimeScale = 'hours' | 'minutes' | 'seconds' | 'milliseconds';
export type CalendarViewMode = 'time' | 'days' | 'months' | 'quarters' | 'years';
export interface TimeConstraintItem {
min: number;
max: number;
step: number;
}
export interface TimeConstraints {
hours?: TimeConstraintItem;
minutes?: TimeConstraintItem;
seconds?: TimeConstraintItem;
milliseconds?: TimeConstraintItem;
}
export interface SchedularItem {
startTime: Date;
endTime: Date;
content: string | React.ReactElement;
className?: string;
}
export type DateExpression<T extends number = number> = T extends number ? `${string | ''}${'+' | '-'}${T}${'millisecond' | 'milliseconds' | 'second' | 'seconds' | 'min' | 'mins' | 'minute' | 'minutes' | 'hour' | 'hours' | 'day' | 'days' | 'week' | 'weeks' | 'weekday' | 'weekdays' | 'month' | 'months' | 'year' | 'years'}` | string : never;
export interface CalendarState {
inputFormat?: string;
currentView: CalendarViewMode;
viewDate: moment.Moment;
selectedDate: moment.Moment;
inputValue?: string;
open?: boolean;
updateOn: CalendarViewMode;
}
export interface CalendarProps extends ThemeProps {
closeOnSelect?: boolean;
date?: any;
dateFormat?: string;
defaultValue?: any;
displayTimeZone?: string;
embed?: boolean;
hideHeader?: boolean;
input?: boolean;
inputFormat?: string;
isEndDate?: boolean;
largeMode?: boolean;
locale: string;
maxDate?: moment.Moment;
minDate?: moment.Moment;
open?: boolean;
requiredConfirm?: boolean;
schedules?: SchedularItem[];
showToolbar?: boolean;
strictParsing?: boolean;
timeConstraints?: TimeConstraints;
timeFormat?: any;
timeRangeHeader?: string;
todayActiveStyle?: React.CSSProperties;
updateOn?: string;
utc?: boolean;
value?: moment.Moment;
viewDate?: moment.Moment;
viewMode?: CalendarViewMode;
prevIcon?: string;
nextIcon?: string;
schemaType?: string;
/** 是否禁用年度和月份变更, 默认是false */
disableMonthSwitch?: boolean;
isValidDate?: (currentDate: moment.Moment, selected?: moment.Moment) => boolean;
onViewModeChange?: (type: string) => void;
onClose?: () => void;
onBlur?: (date?: Moment) => void;
onChange?: (value: any) => void;
renderDay?: (props: any, currentDate: moment.Moment, selectedDate: moment.Moment) => JSX.Element;
renderMonth?: (props: any, month: number, year: number, date: any) => JSX.Element;
renderQuarter?: (props: any, quartar: number, year?: number, date?: moment.Moment) => JSX.Element;
renderYear?: (props: any, year: number) => JSX.Element;
onScheduleClick?: (scheduleData: any) => void;
}
export interface CalendarPartBaseProps extends ThemeProps {
updateOn?: CalendarViewMode;
viewDate: moment.Moment;
selectedDate: moment.Moment;
minDate?: moment.Moment;
maxDate?: moment.Moment;
hideHeader?: boolean;
inputFormat?: string;
/** 控制是否显示picker view */
showPickerView?: boolean;
/** 渲染器的类型 */
schemaType?: string;
addTime: (amount: number, type: string, toSelected?: boolean) => () => void;
subtractTime: (amount: number, type: string, toSelected?: boolean) => () => void;
isValidDate?: (currentDate: moment.Moment, selected?: moment.Moment) => boolean;
setDate: (date: string) => void;
onChange: (value: moment.Moment, callback?: () => void) => void;
onClose?: () => void;
onConfirm?: (value: number[], types: DateType[]) => void;
showView: (view: CalendarViewMode) => () => void;
updateSelectedDate: (event: React.MouseEvent<any>, close?: boolean) => void;
setCalendarState: (state: Partial<CalendarState>, callback?: () => void) => void;
}