1 |
|
2 |
|
3 | import React from 'react';
|
4 | import { CommonProps } from '../util';
|
5 | import { PopupProps } from '../overlay';
|
6 | import { InputProps } from '../input';
|
7 | import { ButtonProps } from '../button';
|
8 | import { Dayjs, ConfigType } from 'dayjs';
|
9 |
|
10 | interface IPresetType {
|
11 | label?: string;
|
12 | value?: ConfigType | (() => ConfigType);
|
13 | }
|
14 | interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
|
15 | defaultValue?: any;
|
16 | onChange?: any;
|
17 | }
|
18 |
|
19 | export interface DatePreset extends ButtonProps {
|
20 | label: string;
|
21 | // 时间值(dayjs 对象或时间字符串)或者返回时间值的函数
|
22 | value: any;
|
23 | }
|
24 |
|
25 | export interface RangePreset {
|
26 | [propName: string]: Dayjs[];
|
27 | }
|
28 |
|
29 | export type StateValue = Dayjs | null;
|
30 |
|
31 | export interface TimePickerProps extends HTMLAttributesWeak, CommonProps {
|
32 | /**
|
33 | * 按钮的文案
|
34 | */
|
35 | label?: React.ReactNode;
|
36 | name?: string;
|
37 |
|
38 | /**
|
39 | * 输入框状态
|
40 | */
|
41 | state?: 'error' | 'success';
|
42 |
|
43 | /**
|
44 | * 输入框提示
|
45 | */
|
46 | placeholder?: string;
|
47 |
|
48 | /**
|
49 | * 时间值(dayjs 对象或时间字符串,受控状态使用)
|
50 | */
|
51 | value?: ConfigType;
|
52 |
|
53 | /**
|
54 | * 时间初值(dayjs 对象或时间字符串,非受控状态使用)
|
55 | */
|
56 | defaultValue?: ConfigType;
|
57 |
|
58 | /**
|
59 | * 时间选择框的尺寸
|
60 | */
|
61 | size?: 'small' | 'medium' | 'large';
|
62 |
|
63 | /**
|
64 | * 是否允许清空时间
|
65 | */
|
66 | hasClear?: boolean;
|
67 |
|
68 | /**
|
69 | * 时间的格式
|
70 | * https://dayjs.gitee.io/docs/zh-CN/display/format
|
71 | */
|
72 | format?: string;
|
73 |
|
74 | /**
|
75 | * 小时选项步长
|
76 | */
|
77 | hourStep?: number;
|
78 |
|
79 | /**
|
80 | * 分钟选项步长
|
81 | */
|
82 | minuteStep?: number;
|
83 |
|
84 | /**
|
85 | * 秒钟选项步长
|
86 | */
|
87 | secondStep?: number;
|
88 |
|
89 | /**
|
90 | * 禁用小时函数
|
91 | */
|
92 | disabledHours?: (index: number) => boolean;
|
93 |
|
94 | |
95 |
|
96 |
|
97 | disabledMinutes?: (index: number) => boolean;
|
98 |
|
99 | |
100 |
|
101 |
|
102 | disabledSeconds?: (index: number) => boolean;
|
103 |
|
104 | |
105 |
|
106 |
|
107 | visible?: boolean;
|
108 |
|
109 | |
110 |
|
111 |
|
112 | defaultVisible?: boolean;
|
113 |
|
114 | |
115 |
|
116 |
|
117 | popupContainer?: string | HTMLElement | ((target: HTMLElement) => HTMLElement);
|
118 |
|
119 | /**
|
120 | * 弹层对齐方式, 详情见Overlay 文档
|
121 | */
|
122 | popupAlign?: string;
|
123 |
|
124 | /**
|
125 | * 弹层触发方式
|
126 | */
|
127 | popupTriggerType?: 'click' | 'hover';
|
128 |
|
129 | /**
|
130 | * 弹层展示状态变化时的回调
|
131 | */
|
132 | onVisibleChange?: (visible: boolean, reason: string) => void;
|
133 |
|
134 | |
135 |
|
136 |
|
137 | popupStyle?: React.CSSProperties;
|
138 |
|
139 | |
140 |
|
141 |
|
142 | popupClassName?: string;
|
143 |
|
144 | |
145 |
|
146 |
|
147 | popupProps?: PopupProps;
|
148 |
|
149 | |
150 |
|
151 |
|
152 | disabled?: boolean;
|
153 |
|
154 | |
155 |
|
156 |
|
157 | hasBorder?: boolean;
|
158 |
|
159 | |
160 |
|
161 |
|
162 | inputProps?: InputProps;
|
163 |
|
164 | |
165 |
|
166 |
|
167 | isPreview?: boolean;
|
168 |
|
169 | |
170 |
|
171 |
|
172 |
|
173 | renderPreview?: (value: StateValue | [StateValue, StateValue]) => React.ReactNode;
|
174 |
|
175 | |
176 |
|
177 |
|
178 | ranges?: RangePreset | DatePreset[];
|
179 |
|
180 | |
181 |
|
182 |
|
183 | onChange?: (date: Dayjs, dateString: string) => void;
|
184 | }
|
185 |
|
186 | export interface RangePickerProps
|
187 | extends Omit<
|
188 | TimePickerProps,
|
189 | 'value' | 'placeholder' | 'defaultValue' | 'onOk' | 'disabled' | 'onChange' | 'preset'
|
190 | > {
|
191 | value?: Array<ConfigType>;
|
192 | defaultValue?: Array<ConfigType>;
|
193 | onOk?: (value: Array<Dayjs>, strVal: Array<string>) => void;
|
194 | onChange?: (value: Array<Dayjs>, strVal: Array<string>) => void;
|
195 | placeholder?: string | Array<string>;
|
196 | disabled?: boolean | boolean[];
|
197 | preset?: IPresetType | IPresetType[];
|
198 | }
|
199 |
|
200 | export class RangePicker extends React.Component<RangePickerProps, any> {
|
201 | type: 'range';
|
202 | }
|
203 |
|
204 | export default class TimePicker extends React.Component<TimePickerProps, any> {
|
205 | static RangePicker: typeof RangePicker;
|
206 | }
|