-
-
Notifications
You must be signed in to change notification settings - Fork 338
Expand file tree
/
Copy pathPresetPanel.tsx
More file actions
62 lines (56 loc) · 1.71 KB
/
PresetPanel.tsx
File metadata and controls
62 lines (56 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as React from 'react';
import type { ValueDate } from '../../interface';
import moment from 'moment';
export interface PresetPanelProps<ValueType = any, DateType extends object = any> {
prefixCls: string;
presets: ValueDate<ValueType>[];
onClick: (value: ValueType) => void;
onHover: (value: ValueType) => void;
maxDate?: DateType;
}
function executeValue<ValueType extends object>(value: ValueDate<ValueType>['value']): ValueType {
return typeof value === 'function' ? value() : value;
}
export default function PresetPanel<DateType extends object = any>(
props: PresetPanelProps<DateType>,
) {
const { prefixCls, presets, onClick, onHover, maxDate } = props;
if (!presets.length) {
return null;
}
return (
<div className={`${prefixCls}-presets`}>
<ul>
{presets.map(({ label, value }, index) => {
// const isDisabled =
// maxDate && moment.isMoment(maxDate)
// ? moment(typeof value === 'function' ? value() : value).isAfter(maxDate)
// : false;
const isDisabled = maxDate
? moment(typeof value === 'function' ? value() : value).isAfter(maxDate)
: false;
return (
<li
key={index}
onClick={() => {
if (!isDisabled) {
onClick(executeValue(value));
}
}}
onMouseEnter={() => {
if (!isDisabled) {
onHover(executeValue(value));
}
}}
onMouseLeave={() => {
onHover(null);
}}
>
{label}
</li>
);
})}
</ul>
</div>
);
}