UNPKG

4.29 kBTypeScriptView Raw
1/// <reference types="react" />
2
3import React from 'react';
4import { CommonProps } from '../util';
5import { PopupProps } from '../overlay';
6import { InputProps } from '../input';
7import { ButtonProps } from '../button';
8import { Dayjs, ConfigType } from 'dayjs';
9
10interface IPresetType {
11 label?: string;
12 value?: ConfigType | (() => ConfigType);
13}
14interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
15 defaultValue?: any;
16 onChange?: any;
17}
18
19export interface DatePreset extends ButtonProps {
20 label: string;
21 // 时间值(dayjs 对象或时间字符串)或者返回时间值的函数
22 value: any;
23}
24
25export interface RangePreset {
26 [propName: string]: Dayjs[];
27}
28
29export type StateValue = Dayjs | null;
30
31export 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 * 透传给 Input 的属性
161 */
162 inputProps?: InputProps;
163
164 /**
165 * 是否为预览态
166 */
167 isPreview?: boolean;
168
169 /**
170 * 预览态模式下渲染的内容
171 * @param value 时间
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
186export 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
200export class RangePicker extends React.Component<RangePickerProps, any> {
201 type: 'range';
202}
203
204export default class TimePicker extends React.Component<TimePickerProps, any> {
205 static RangePicker: typeof RangePicker;
206}