-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTile.jsx
86 lines (76 loc) · 2.16 KB
/
Tile.jsx
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
77
78
79
80
81
82
83
84
85
86
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import mergeClassNames from 'merge-class-names';
import { tileProps } from './shared/propTypes';
export default class Tile extends Component {
static getDerivedStateFromProps(nextProps, prevState) {
const {
date,
tileClassName,
tileContent,
view,
} = nextProps;
const nextState = {};
if (tileClassName !== prevState.tileClassNameProps) {
nextState.tileClassName = typeof tileClassName === 'function' ? tileClassName({ date, view }) : tileClassName;
nextState.tileClassNameProps = tileClassName;
}
if (tileContent !== prevState.tileContentProps) {
nextState.tileContent = typeof tileContent === 'function' ? tileContent({ date, view }) : tileContent;
nextState.tileContentProps = tileContent;
}
return nextState;
}
state = {};
render() {
const {
activeStartDate,
children,
classes,
date,
formatAbbr,
locale,
maxDate,
maxDateTransform,
minDate,
minDateTransform,
onClick,
onMouseOver,
style,
tileDisabled,
view,
} = this.props;
const { tileClassName, tileContent } = this.state;
return (
<button
className={mergeClassNames(classes, tileClassName)}
disabled={
(minDate && minDateTransform(minDate) > date)
|| (maxDate && maxDateTransform(maxDate) < date)
|| (tileDisabled && tileDisabled({ activeStartDate, date, view }))
}
onClick={onClick && (() => onClick(date))}
onFocus={onMouseOver && (() => onMouseOver(date))}
onMouseOver={onMouseOver && (() => onMouseOver(date))}
style={style}
type="button"
>
{formatAbbr
? (
<abbr aria-label={formatAbbr(locale, date)}>
{children}
</abbr>
)
: children}
{tileContent}
</button>
);
}
}
Tile.propTypes = {
...tileProps,
children: PropTypes.node.isRequired,
formatAbbr: PropTypes.func,
maxDateTransform: PropTypes.func.isRequired,
minDateTransform: PropTypes.func.isRequired,
};