-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
112 lines (99 loc) · 3.37 KB
/
index.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* External dependencies
*/
// Needed to initialise the default datepicker styles.
// See: https://github.com/airbnb/react-dates#initialize
import 'react-dates/initialize';
/**
* WordPress dependencies
*/
import { Component, Fragment } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import Button from '../button';
import { default as DatePicker } from './date';
import { default as TimePicker } from './time';
export { DatePicker, TimePicker };
export class DateTimePicker extends Component {
constructor() {
super( ...arguments );
this.state = { calendarHelpIsVisible: false };
this.onClickDescriptionToggle = this.onClickDescriptionToggle.bind( this );
}
onClickDescriptionToggle() {
this.setState( { calendarHelpIsVisible: ! this.state.calendarHelpIsVisible } );
}
render() {
const { currentDate, is12Hour, onChange } = this.props;
return (
<div className="components-datetime">
{ ! this.state.calendarHelpIsVisible && (
<Fragment>
<TimePicker
currentTime={ currentDate }
onChange={ onChange }
is12Hour={ is12Hour }
/>
<DatePicker
currentDate={ currentDate }
onChange={ onChange }
/>
</Fragment>
) }
{ this.state.calendarHelpIsVisible && (
<Fragment>
<div className="components-datetime__calendar-help">
<h4>{ __( 'Click to Select' ) }</h4>
<ul>
<li>{ __( 'Click the right or left arrows to select other months in the past or the future.' ) }</li>
<li>{ __( 'Click the desired day to select it.' ) }</li>
</ul>
<h4>{ __( 'Navigating with a keyboard' ) }</h4>
<ul>
<li>
<abbr aria-label={ _x( 'Enter', 'keyboard button' ) }>↵</abbr>
{ ' ' /* JSX removes whitespace, but a space is required for screen readers. */ }
<span>{ __( 'Select the date in focus.' ) }</span>
</li>
<li>
<abbr aria-label={ __( 'Left and Right Arrows' ) }>←/→</abbr>
{ ' ' /* JSX removes whitespace, but a space is required for screen readers. */ }
{ __( 'Move backward (left) or forward (right) by one day.' ) }
</li>
<li>
<abbr aria-label={ __( 'Up and Down Arrows' ) }>↑/↓</abbr>
{ ' ' /* JSX removes whitespace, but a space is required for screen readers. */ }
{ __( 'Move backward (up) or forward (down) by one week.' ) }
</li>
<li>
<abbr aria-label={ __( 'Page Up and Page Down' ) }>{ __( 'PgUp/PgDn' ) }</abbr>
{ ' ' /* JSX removes whitespace, but a space is required for screen readers. */ }
{ __( 'Move backward (PgUp) or forward (PgDn) by one month.' ) }
</li>
<li>
<abbr aria-label={ __( 'Home and End' ) }>{ __( 'Home/End' ) }</abbr>
{ ' ' /* JSX removes whitespace, but a space is required for screen readers. */ }
{ __( 'Go to the first (home) or last (end) day of a week.' ) }
</li>
</ul>
<Button isSmall onClick={ this.onClickDescriptionToggle }>
{ __( 'Close' ) }
</Button>
</div>
</Fragment>
) }
{ ! this.state.calendarHelpIsVisible && (
<Button
className="components-datetime__date-help-button"
isLink
onClick={ this.onClickDescriptionToggle }
>
{ __( 'Calendar Help' ) }
</Button>
) }
</div>
);
}
}