-
-
Notifications
You must be signed in to change notification settings - Fork 727
/
Day.js
76 lines (72 loc) · 1.82 KB
/
Day.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React, { PropTypes } from 'react';
function handleEvent(handler, day, modifiers) {
if (!handler) {
return undefined;
}
const dayState = {};
modifiers.forEach(modifier => { dayState[modifier] = true; });
return e => {
e.persist();
handler(e, day, dayState);
};
}
export default function Day({
day,
tabIndex,
empty,
modifiers,
onMouseEnter,
onMouseLeave,
onClick,
onKeyDown,
onTouchStart,
onTouchEnd,
ariaLabel,
ariaDisabled,
ariaSelected,
children,
}) {
let className = 'DayPicker-Day';
className += modifiers.map(modifier => ` ${className}--${modifier}`).join('');
if (empty) {
return <div role="gridcell" aria-disabled className={className} />;
}
return (
<div
className={className}
tabIndex={tabIndex}
role="gridcell"
aria-label={ariaLabel}
aria-disabled={ariaDisabled.toString()}
aria-selected={ariaSelected.toString()}
onClick={handleEvent(onClick, day, modifiers)}
onKeyDown={handleEvent(onKeyDown, day, modifiers)}
onMouseEnter={handleEvent(onMouseEnter, day, modifiers)}
onMouseLeave={handleEvent(onMouseLeave, day, modifiers)}
onTouchEnd={handleEvent(onTouchEnd, day, modifiers)}
onTouchStart={handleEvent(onTouchStart, day, modifiers)}
>
{children}
</div>
);
}
Day.propTypes = {
day: PropTypes.instanceOf(Date).isRequired,
children: PropTypes.node.isRequired,
ariaDisabled: PropTypes.bool,
ariaLabel: PropTypes.string,
ariaSelected: PropTypes.bool,
empty: PropTypes.bool,
modifiers: PropTypes.array,
onClick: PropTypes.func,
onKeyDown: PropTypes.func,
onMouseEnter: PropTypes.func,
onMouseLeave: PropTypes.func,
onTouchEnd: PropTypes.func,
onTouchStart: PropTypes.func,
tabIndex: PropTypes.number,
};
Day.defaultProps = {
modifiers: [],
empty: false,
};