@birdnet/advanced-react-dates 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/.babelrc +67 -0
  2. package/.eslintrc +66 -0
  3. package/.nvmrc +1 -0
  4. package/.nyc_output/4d8efcd220c2aec1f2b4ffd49d875001.json +1 -0
  5. package/.nyc_output/66d34779498a5d49bcf9d757dfc7fdb5.json +1 -0
  6. package/.nyc_output/8ca7e04140934515928bc7d4ae476b73.json +1 -0
  7. package/.nyc_output/afc270bb597bfc50e690436959c2ae54.json +1 -0
  8. package/.nycrc +19 -0
  9. package/.travis.yml +13 -0
  10. package/CHANGELOG.md +665 -0
  11. package/CLAUDE.md +56 -0
  12. package/INTHEWILD.md +9 -0
  13. package/LICENSE +21 -0
  14. package/README.md +421 -2
  15. package/constants.js +2 -0
  16. package/esm/components/CalendarDay.js +321 -0
  17. package/esm/components/CalendarIcon.js +11 -0
  18. package/esm/components/CalendarMonth.js +254 -0
  19. package/esm/components/CalendarMonthGrid.js +365 -0
  20. package/esm/components/CalendarWeek.js +11 -0
  21. package/esm/components/ChevronDown.js +11 -0
  22. package/esm/components/ChevronUp.js +11 -0
  23. package/esm/components/CloseButton.js +12 -0
  24. package/esm/components/CustomizableCalendarDay.js +341 -0
  25. package/esm/components/DateInput.js +344 -0
  26. package/esm/components/DateRangePicker.js +647 -0
  27. package/esm/components/DateRangePickerInput.js +341 -0
  28. package/esm/components/DateRangePickerInputController.js +348 -0
  29. package/esm/components/DayPicker.js +1167 -0
  30. package/esm/components/DayPickerKeyboardShortcuts.js +364 -0
  31. package/esm/components/DayPickerNavigation.js +314 -0
  32. package/esm/components/DayPickerRangeController.js +1202 -0
  33. package/esm/components/DayPickerSingleDateController.js +690 -0
  34. package/esm/components/KeyboardShortcutRow.js +69 -0
  35. package/esm/components/LeftArrow.js +11 -0
  36. package/esm/components/RightArrow.js +11 -0
  37. package/esm/components/SingleDatePicker.js +605 -0
  38. package/esm/components/SingleDatePickerInput.js +264 -0
  39. package/esm/components/SingleDatePickerInputController.js +260 -0
  40. package/esm/constants.js +28 -0
  41. package/esm/defaultPhrases.js +225 -0
  42. package/esm/index.js +20 -0
  43. package/esm/initialize.js +2 -0
  44. package/esm/shapes/AnchorDirectionShape.js +3 -0
  45. package/esm/shapes/CalendarInfoPositionShape.js +3 -0
  46. package/esm/shapes/DateRangePickerShape.js +101 -0
  47. package/esm/shapes/DayOfWeekShape.js +3 -0
  48. package/esm/shapes/DisabledShape.js +3 -0
  49. package/esm/shapes/FocusedInputShape.js +3 -0
  50. package/esm/shapes/IconPositionShape.js +3 -0
  51. package/esm/shapes/ModifiersShape.js +18 -0
  52. package/esm/shapes/NavPositionShape.js +3 -0
  53. package/esm/shapes/OpenDirectionShape.js +3 -0
  54. package/esm/shapes/OrientationShape.js +3 -0
  55. package/esm/shapes/ScrollableOrientationShape.js +3 -0
  56. package/esm/shapes/SingleDatePickerShape.js +90 -0
  57. package/esm/theme/DefaultTheme.js +176 -0
  58. package/esm/utils/calculateDimension.js +28 -0
  59. package/esm/utils/disableScroll.js +67 -0
  60. package/esm/utils/getActiveElement.js +3 -0
  61. package/esm/utils/getCalendarDaySettings.js +48 -0
  62. package/esm/utils/getCalendarMonthWeeks.js +37 -0
  63. package/esm/utils/getCalendarMonthWidth.js +4 -0
  64. package/esm/utils/getDetachedContainerStyles.js +36 -0
  65. package/esm/utils/getInputHeight.js +42 -0
  66. package/esm/utils/getNumberOfCalendarMonthWeeks.js +11 -0
  67. package/esm/utils/getPhrase.js +7 -0
  68. package/esm/utils/getPhrasePropTypes.js +9 -0
  69. package/esm/utils/getPooledMoment.js +8 -0
  70. package/esm/utils/getPreviousMonthMemoLast.js +9 -0
  71. package/esm/utils/getResponsiveContainerStyles.js +8 -0
  72. package/esm/utils/getSelectedDateOffset.js +8 -0
  73. package/esm/utils/getTransformStyles.js +8 -0
  74. package/esm/utils/getVisibleDays.js +42 -0
  75. package/esm/utils/isAfterDay.js +7 -0
  76. package/esm/utils/isBeforeDay.js +13 -0
  77. package/esm/utils/isDayVisible.js +38 -0
  78. package/esm/utils/isInclusivelyAfterDay.js +6 -0
  79. package/esm/utils/isInclusivelyBeforeDay.js +6 -0
  80. package/esm/utils/isNextDay.js +7 -0
  81. package/esm/utils/isNextMonth.js +6 -0
  82. package/esm/utils/isPrevMonth.js +6 -0
  83. package/esm/utils/isPreviousDay.js +7 -0
  84. package/esm/utils/isSameDay.js +7 -0
  85. package/esm/utils/isSameMonth.js +7 -0
  86. package/esm/utils/isTransitionEndSupported.js +3 -0
  87. package/esm/utils/modifiers.js +94 -0
  88. package/esm/utils/noflip.js +10 -0
  89. package/esm/utils/registerCSSInterfaceWithDefaultTheme.js +5 -0
  90. package/esm/utils/registerInterfaceWithDefaultTheme.js +6 -0
  91. package/esm/utils/toISODateString.js +12 -0
  92. package/esm/utils/toISOMonthString.js +12 -0
  93. package/esm/utils/toLocalizedDateString.js +8 -0
  94. package/esm/utils/toMomentObject.js +7 -0
  95. package/index.js +2 -0
  96. package/initialize.js +2 -0
  97. package/karma.conf.js +82 -0
  98. package/lib/components/CalendarDay.js +327 -0
  99. package/lib/components/CalendarIcon.js +18 -0
  100. package/lib/components/CalendarMonth.js +259 -0
  101. package/lib/components/CalendarMonthGrid.js +372 -0
  102. package/lib/components/CalendarWeek.js +18 -0
  103. package/lib/components/ChevronDown.js +18 -0
  104. package/lib/components/ChevronUp.js +18 -0
  105. package/lib/components/CloseButton.js +19 -0
  106. package/lib/components/CustomizableCalendarDay.js +347 -0
  107. package/lib/components/DateInput.js +351 -0
  108. package/lib/components/DateRangePicker.js +653 -0
  109. package/lib/components/DateRangePickerInput.js +348 -0
  110. package/lib/components/DateRangePickerInputController.js +354 -0
  111. package/lib/components/DayPicker.js +1175 -0
  112. package/lib/components/DayPickerKeyboardShortcuts.js +371 -0
  113. package/lib/components/DayPickerNavigation.js +321 -0
  114. package/lib/components/DayPickerRangeController.js +1208 -0
  115. package/lib/components/DayPickerSingleDateController.js +695 -0
  116. package/lib/components/KeyboardShortcutRow.js +76 -0
  117. package/lib/components/LeftArrow.js +18 -0
  118. package/lib/components/RightArrow.js +18 -0
  119. package/lib/components/SingleDatePicker.js +611 -0
  120. package/lib/components/SingleDatePickerInput.js +271 -0
  121. package/lib/components/SingleDatePickerInputController.js +266 -0
  122. package/lib/constants.js +34 -0
  123. package/lib/css/_datepicker.css +886 -0
  124. package/lib/defaultPhrases.js +231 -0
  125. package/lib/index.js +146 -0
  126. package/lib/initialize.js +5 -0
  127. package/lib/shapes/AnchorDirectionShape.js +10 -0
  128. package/lib/shapes/CalendarInfoPositionShape.js +10 -0
  129. package/lib/shapes/DateRangePickerShape.js +108 -0
  130. package/lib/shapes/DayOfWeekShape.js +10 -0
  131. package/lib/shapes/DisabledShape.js +10 -0
  132. package/lib/shapes/FocusedInputShape.js +10 -0
  133. package/lib/shapes/IconPositionShape.js +10 -0
  134. package/lib/shapes/ModifiersShape.js +25 -0
  135. package/lib/shapes/NavPositionShape.js +10 -0
  136. package/lib/shapes/OpenDirectionShape.js +10 -0
  137. package/lib/shapes/OrientationShape.js +10 -0
  138. package/lib/shapes/ScrollableOrientationShape.js +10 -0
  139. package/lib/shapes/SingleDatePickerShape.js +97 -0
  140. package/lib/theme/DefaultTheme.js +182 -0
  141. package/lib/utils/calculateDimension.js +34 -0
  142. package/lib/utils/disableScroll.js +75 -0
  143. package/lib/utils/getActiveElement.js +9 -0
  144. package/lib/utils/getCalendarDaySettings.js +55 -0
  145. package/lib/utils/getCalendarMonthWeeks.js +44 -0
  146. package/lib/utils/getCalendarMonthWidth.js +10 -0
  147. package/lib/utils/getDetachedContainerStyles.js +41 -0
  148. package/lib/utils/getInputHeight.js +48 -0
  149. package/lib/utils/getNumberOfCalendarMonthWeeks.js +18 -0
  150. package/lib/utils/getPhrase.js +13 -0
  151. package/lib/utils/getPhrasePropTypes.js +16 -0
  152. package/lib/utils/getPooledMoment.js +15 -0
  153. package/lib/utils/getPreviousMonthMemoLast.js +15 -0
  154. package/lib/utils/getResponsiveContainerStyles.js +15 -0
  155. package/lib/utils/getSelectedDateOffset.js +14 -0
  156. package/lib/utils/getTransformStyles.js +14 -0
  157. package/lib/utils/getVisibleDays.js +49 -0
  158. package/lib/utils/isAfterDay.js +14 -0
  159. package/lib/utils/isBeforeDay.js +20 -0
  160. package/lib/utils/isDayVisible.js +45 -0
  161. package/lib/utils/isInclusivelyAfterDay.js +13 -0
  162. package/lib/utils/isInclusivelyBeforeDay.js +13 -0
  163. package/lib/utils/isNextDay.js +14 -0
  164. package/lib/utils/isNextMonth.js +13 -0
  165. package/lib/utils/isPrevMonth.js +13 -0
  166. package/lib/utils/isPreviousDay.js +14 -0
  167. package/lib/utils/isSameDay.js +14 -0
  168. package/lib/utils/isSameMonth.js +14 -0
  169. package/lib/utils/isTransitionEndSupported.js +9 -0
  170. package/lib/utils/modifiers.js +102 -0
  171. package/lib/utils/noflip.js +16 -0
  172. package/lib/utils/registerCSSInterfaceWithDefaultTheme.js +12 -0
  173. package/lib/utils/registerInterfaceWithDefaultTheme.js +13 -0
  174. package/lib/utils/toISODateString.js +19 -0
  175. package/lib/utils/toISOMonthString.js +19 -0
  176. package/lib/utils/toLocalizedDateString.js +15 -0
  177. package/lib/utils/toMomentObject.js +14 -0
  178. package/package.json +141 -4
  179. package/scripts/.eslintrc +7 -0
  180. package/scripts/buildCSS.js +37 -0
  181. package/scripts/pure-component-fallback.js +70 -0
  182. package/scripts/renderAllComponents.jsx +25 -0
  183. package/src/components/CalendarDay.jsx +366 -0
  184. package/src/components/CalendarIcon.jsx +3 -0
  185. package/src/components/CalendarMonth.jsx +300 -0
  186. package/src/components/CalendarMonthGrid.jsx +427 -0
  187. package/src/components/CalendarWeek.jsx +17 -0
  188. package/src/components/ChevronDown.jsx +3 -0
  189. package/src/components/ChevronUp.jsx +3 -0
  190. package/src/components/CloseButton.jsx +3 -0
  191. package/src/components/CustomizableCalendarDay.jsx +382 -0
  192. package/src/components/DateInput.jsx +401 -0
  193. package/src/components/DateRangePicker.jsx +777 -0
  194. package/src/components/DateRangePickerInput.jsx +434 -0
  195. package/src/components/DateRangePickerInputController.jsx +379 -0
  196. package/src/components/DayPicker.jsx +1407 -0
  197. package/src/components/DayPickerKeyboardShortcuts.jsx +443 -0
  198. package/src/components/DayPickerNavigation.jsx +445 -0
  199. package/src/components/DayPickerRangeController.jsx +1409 -0
  200. package/src/components/DayPickerSingleDateController.jsx +769 -0
  201. package/src/components/KeyboardShortcutRow.jsx +93 -0
  202. package/src/components/LeftArrow.jsx +3 -0
  203. package/src/components/RightArrow.jsx +3 -0
  204. package/src/components/SingleDatePicker.jsx +731 -0
  205. package/src/components/SingleDatePickerInput.jsx +329 -0
  206. package/src/components/SingleDatePickerInputController.jsx +280 -0
  207. package/src/constants.js +37 -0
  208. package/src/defaultPhrases.js +215 -0
  209. package/src/index.js +20 -0
  210. package/src/initialize.js +3 -0
  211. package/src/shapes/AnchorDirectionShape.js +8 -0
  212. package/src/shapes/CalendarInfoPositionShape.js +15 -0
  213. package/src/shapes/DateRangePickerShape.js +111 -0
  214. package/src/shapes/DayOfWeekShape.js +5 -0
  215. package/src/shapes/DisabledShape.js +5 -0
  216. package/src/shapes/FocusedInputShape.js +8 -0
  217. package/src/shapes/IconPositionShape.js +8 -0
  218. package/src/shapes/ModifiersShape.js +20 -0
  219. package/src/shapes/NavPositionShape.js +8 -0
  220. package/src/shapes/OpenDirectionShape.js +8 -0
  221. package/src/shapes/OrientationShape.js +8 -0
  222. package/src/shapes/ScrollableOrientationShape.js +13 -0
  223. package/src/shapes/SingleDatePickerShape.js +100 -0
  224. package/src/svg/arrow-left.svg +1 -0
  225. package/src/svg/arrow-right.svg +1 -0
  226. package/src/svg/calendar.svg +1 -0
  227. package/src/svg/chevron-down.svg +1 -0
  228. package/src/svg/chevron-up.svg +1 -0
  229. package/src/svg/close.svg +1 -0
  230. package/src/theme/DefaultTheme.js +196 -0
  231. package/src/utils/calculateDimension.js +32 -0
  232. package/src/utils/disableScroll.js +65 -0
  233. package/src/utils/getActiveElement.js +3 -0
  234. package/src/utils/getCalendarDaySettings.js +61 -0
  235. package/src/utils/getCalendarMonthWeeks.js +49 -0
  236. package/src/utils/getCalendarMonthWidth.js +3 -0
  237. package/src/utils/getDetachedContainerStyles.js +39 -0
  238. package/src/utils/getInputHeight.js +67 -0
  239. package/src/utils/getNumberOfCalendarMonthWeeks.js +15 -0
  240. package/src/utils/getPhrase.jsx +9 -0
  241. package/src/utils/getPhrasePropTypes.js +9 -0
  242. package/src/utils/getPooledMoment.js +10 -0
  243. package/src/utils/getPreviousMonthMemoLast.js +11 -0
  244. package/src/utils/getResponsiveContainerStyles.js +18 -0
  245. package/src/utils/getSelectedDateOffset.js +6 -0
  246. package/src/utils/getTransformStyles.js +8 -0
  247. package/src/utils/getVisibleDays.js +54 -0
  248. package/src/utils/isAfterDay.js +9 -0
  249. package/src/utils/isBeforeDay.js +18 -0
  250. package/src/utils/isDayVisible.js +57 -0
  251. package/src/utils/isInclusivelyAfterDay.js +8 -0
  252. package/src/utils/isInclusivelyBeforeDay.js +8 -0
  253. package/src/utils/isNextDay.js +9 -0
  254. package/src/utils/isNextMonth.js +8 -0
  255. package/src/utils/isPrevMonth.js +8 -0
  256. package/src/utils/isPreviousDay.js +9 -0
  257. package/src/utils/isSameDay.js +10 -0
  258. package/src/utils/isSameMonth.js +9 -0
  259. package/src/utils/isTransitionEndSupported.js +3 -0
  260. package/src/utils/modifiers.js +116 -0
  261. package/src/utils/noflip.js +11 -0
  262. package/src/utils/registerCSSInterfaceWithDefaultTheme.js +7 -0
  263. package/src/utils/registerInterfaceWithDefaultTheme.js +7 -0
  264. package/src/utils/toISODateString.js +14 -0
  265. package/src/utils/toISOMonthString.js +14 -0
  266. package/src/utils/toLocalizedDateString.js +12 -0
  267. package/src/utils/toMomentObject.js +12 -0
@@ -0,0 +1,443 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { forbidExtraProps } from 'airbnb-prop-types';
4
+ import { withStyles, withStylesPropTypes } from 'react-with-styles';
5
+
6
+ import { DayPickerKeyboardShortcutsPhrases } from '../defaultPhrases';
7
+ import getPhrasePropTypes from '../utils/getPhrasePropTypes';
8
+
9
+ import KeyboardShortcutRow from './KeyboardShortcutRow';
10
+ import CloseButton from './CloseButton';
11
+
12
+ export const TOP_LEFT = 'top-left';
13
+ export const TOP_RIGHT = 'top-right';
14
+ export const BOTTOM_RIGHT = 'bottom-right';
15
+
16
+ const propTypes = forbidExtraProps({
17
+ ...withStylesPropTypes,
18
+ block: PropTypes.bool,
19
+ // TODO: rename button location to be direction-agnostic
20
+ buttonLocation: PropTypes.oneOf([TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT]),
21
+ showKeyboardShortcutsPanel: PropTypes.bool,
22
+ openKeyboardShortcutsPanel: PropTypes.func,
23
+ closeKeyboardShortcutsPanel: PropTypes.func,
24
+ phrases: PropTypes.shape(getPhrasePropTypes(DayPickerKeyboardShortcutsPhrases)),
25
+ renderKeyboardShortcutsButton: PropTypes.func,
26
+ renderKeyboardShortcutsPanel: PropTypes.func,
27
+ });
28
+
29
+ const defaultProps = {
30
+ block: false,
31
+ buttonLocation: BOTTOM_RIGHT,
32
+ showKeyboardShortcutsPanel: false,
33
+ openKeyboardShortcutsPanel() {},
34
+ closeKeyboardShortcutsPanel() {},
35
+ phrases: DayPickerKeyboardShortcutsPhrases,
36
+ renderKeyboardShortcutsButton: undefined,
37
+ renderKeyboardShortcutsPanel: undefined,
38
+ };
39
+
40
+ function getKeyboardShortcuts(phrases) {
41
+ return [
42
+ {
43
+ unicode: '↵',
44
+ label: phrases.enterKey,
45
+ action: phrases.selectFocusedDate,
46
+ },
47
+ {
48
+ unicode: '←/→',
49
+ label: phrases.leftArrowRightArrow,
50
+ action: phrases.moveFocusByOneDay,
51
+ },
52
+ {
53
+ unicode: '↑/↓',
54
+ label: phrases.upArrowDownArrow,
55
+ action: phrases.moveFocusByOneWeek,
56
+ },
57
+ {
58
+ unicode: 'PgUp/PgDn',
59
+ label: phrases.pageUpPageDown,
60
+ action: phrases.moveFocusByOneMonth,
61
+ },
62
+ {
63
+ unicode: 'Home/End',
64
+ label: phrases.homeEnd,
65
+ action: phrases.moveFocustoStartAndEndOfWeek,
66
+ },
67
+ {
68
+ unicode: 'Esc',
69
+ label: phrases.escape,
70
+ action: phrases.returnFocusToInput,
71
+ },
72
+ {
73
+ unicode: '?',
74
+ label: phrases.questionMark,
75
+ action: phrases.openThisPanel,
76
+ },
77
+ ];
78
+ }
79
+
80
+ class DayPickerKeyboardShortcuts extends React.PureComponent {
81
+ constructor(...args) {
82
+ super(...args);
83
+
84
+ const { phrases } = this.props;
85
+ this.state = {
86
+ phrases,
87
+ keyboardShortcuts: getKeyboardShortcuts(phrases),
88
+ };
89
+
90
+ this.onShowKeyboardShortcutsButtonClick = this.onShowKeyboardShortcutsButtonClick.bind(this);
91
+ this.setShowKeyboardShortcutsButtonRef = this.setShowKeyboardShortcutsButtonRef.bind(this);
92
+ this.setHideKeyboardShortcutsButtonRef = this.setHideKeyboardShortcutsButtonRef.bind(this);
93
+ this.handleFocus = this.handleFocus.bind(this);
94
+ this.onKeyDown = this.onKeyDown.bind(this);
95
+ }
96
+
97
+ static getDerivedStateFromProps(props, state) {
98
+ if (props.phrases !== state.phrases) {
99
+ return {
100
+ phrases: props.phrases,
101
+ keyboardShortcuts: getKeyboardShortcuts(props.phrases),
102
+ };
103
+ }
104
+ return null;
105
+ }
106
+
107
+ componentDidUpdate() {
108
+ this.handleFocus();
109
+ }
110
+
111
+ handleFocus() {
112
+ if (this.hideKeyboardShortcutsButton) {
113
+ // automatically move focus into the dialog by moving
114
+ // to the only interactive element, the hide button
115
+ this.hideKeyboardShortcutsButton.focus();
116
+ }
117
+ }
118
+
119
+ onKeyDown(e) {
120
+ e.stopPropagation();
121
+
122
+ const { closeKeyboardShortcutsPanel } = this.props;
123
+ // Because the close button is the only focusable element inside of the panel, this
124
+ // amounts to a very basic focus trap. The user can exit the panel by "pressing" the
125
+ // close button or hitting escape
126
+ switch (e.key) {
127
+ case 'Escape':
128
+ closeKeyboardShortcutsPanel();
129
+ break;
130
+
131
+ // do nothing - this allows the up and down arrows continue their
132
+ // default behavior of scrolling the content of the Keyboard Shortcuts Panel
133
+ // which is needed when only a single month is shown for instance.
134
+ case 'ArrowUp':
135
+ case 'ArrowDown':
136
+ break;
137
+
138
+ // completely block the rest of the keys that have functionality outside of this panel
139
+ case 'Tab':
140
+ case 'Home':
141
+ case 'End':
142
+ case 'PageUp':
143
+ case 'PageDown':
144
+ case 'ArrowLeft':
145
+ case 'ArrowRight':
146
+ e.preventDefault();
147
+ break;
148
+
149
+ default:
150
+ break;
151
+ }
152
+ }
153
+
154
+ onShowKeyboardShortcutsButtonClick() {
155
+ const { openKeyboardShortcutsPanel } = this.props;
156
+
157
+ // we want to return focus to this button after closing the keyboard shortcuts panel
158
+ openKeyboardShortcutsPanel(() => { this.showKeyboardShortcutsButton.focus(); });
159
+ }
160
+
161
+ setShowKeyboardShortcutsButtonRef(ref) {
162
+ this.showKeyboardShortcutsButton = ref;
163
+ }
164
+
165
+ setHideKeyboardShortcutsButtonRef(ref) {
166
+ this.hideKeyboardShortcutsButton = ref;
167
+ }
168
+
169
+ render() {
170
+ const {
171
+ block,
172
+ buttonLocation,
173
+ showKeyboardShortcutsPanel,
174
+ closeKeyboardShortcutsPanel,
175
+ css,
176
+ styles,
177
+ phrases,
178
+ renderKeyboardShortcutsButton,
179
+ renderKeyboardShortcutsPanel,
180
+ } = this.props;
181
+ const { keyboardShortcuts } = this.state;
182
+
183
+ const toggleButtonText = showKeyboardShortcutsPanel
184
+ ? phrases.hideKeyboardShortcutsPanel
185
+ : phrases.showKeyboardShortcutsPanel;
186
+
187
+ const bottomRight = buttonLocation === BOTTOM_RIGHT;
188
+ const topRight = buttonLocation === TOP_RIGHT;
189
+ const topLeft = buttonLocation === TOP_LEFT;
190
+
191
+ return (
192
+ <div>
193
+ {renderKeyboardShortcutsButton
194
+ && renderKeyboardShortcutsButton({
195
+ // passing in context-specific props
196
+ ref: this.setShowKeyboardShortcutsButtonRef,
197
+ onClick: this.onShowKeyboardShortcutsButtonClick,
198
+ ariaLabel: toggleButtonText,
199
+ })}
200
+ {!renderKeyboardShortcutsButton && (
201
+ <button
202
+ ref={this.setShowKeyboardShortcutsButtonRef}
203
+ {...css(
204
+ styles.DayPickerKeyboardShortcuts_buttonReset,
205
+ styles.DayPickerKeyboardShortcuts_show,
206
+ bottomRight && styles.DayPickerKeyboardShortcuts_show__bottomRight,
207
+ topRight && styles.DayPickerKeyboardShortcuts_show__topRight,
208
+ topLeft && styles.DayPickerKeyboardShortcuts_show__topLeft,
209
+ )}
210
+ type="button"
211
+ aria-label={toggleButtonText}
212
+ onClick={this.onShowKeyboardShortcutsButtonClick}
213
+ onMouseUp={(e) => {
214
+ e.currentTarget.blur();
215
+ }}
216
+ >
217
+ <span
218
+ {...css(
219
+ styles.DayPickerKeyboardShortcuts_showSpan,
220
+ bottomRight && styles.DayPickerKeyboardShortcuts_showSpan__bottomRight,
221
+ topRight && styles.DayPickerKeyboardShortcuts_showSpan__topRight,
222
+ topLeft && styles.DayPickerKeyboardShortcuts_showSpan__topLeft,
223
+ )}
224
+ >
225
+ ?
226
+ </span>
227
+ </button>
228
+ )}
229
+ {showKeyboardShortcutsPanel && (
230
+ renderKeyboardShortcutsPanel ? (
231
+ renderKeyboardShortcutsPanel({
232
+ closeButtonAriaLabel: phrases.hideKeyboardShortcutsPanel,
233
+ keyboardShortcuts,
234
+ onCloseButtonClick: closeKeyboardShortcutsPanel,
235
+ onKeyDown: this.onKeyDown,
236
+ title: phrases.keyboardShortcuts,
237
+ })
238
+ ) : (
239
+ <div
240
+ {...css(styles.DayPickerKeyboardShortcuts_panel)}
241
+ role="dialog"
242
+ aria-labelledby="DayPickerKeyboardShortcuts_title"
243
+ aria-describedby="DayPickerKeyboardShortcuts_description"
244
+ >
245
+ <div
246
+ {...css(styles.DayPickerKeyboardShortcuts_title)}
247
+ id="DayPickerKeyboardShortcuts_title"
248
+ >
249
+ {phrases.keyboardShortcuts}
250
+ </div>
251
+
252
+ <button
253
+ ref={this.setHideKeyboardShortcutsButtonRef}
254
+ {...css(
255
+ styles.DayPickerKeyboardShortcuts_buttonReset,
256
+ styles.DayPickerKeyboardShortcuts_close,
257
+ )}
258
+ type="button"
259
+ tabIndex="0"
260
+ aria-label={phrases.hideKeyboardShortcutsPanel}
261
+ onClick={closeKeyboardShortcutsPanel}
262
+ onKeyDown={this.onKeyDown}
263
+ >
264
+ <CloseButton {...css(styles.DayPickerKeyboardShortcuts_closeSvg)} />
265
+ </button>
266
+
267
+ <ul
268
+ {...css(styles.DayPickerKeyboardShortcuts_list)}
269
+ id="DayPickerKeyboardShortcuts_description"
270
+ >
271
+ {keyboardShortcuts.map(({ unicode, label, action }) => (
272
+ <KeyboardShortcutRow
273
+ key={label}
274
+ unicode={unicode}
275
+ label={label}
276
+ action={action}
277
+ block={block}
278
+ />
279
+ ))}
280
+ </ul>
281
+ </div>
282
+ )
283
+ )}
284
+ </div>
285
+ );
286
+ }
287
+ }
288
+
289
+ DayPickerKeyboardShortcuts.propTypes = propTypes;
290
+ DayPickerKeyboardShortcuts.defaultProps = defaultProps;
291
+
292
+ export default withStyles(({ reactDates: { color, font, zIndex } }) => ({
293
+ DayPickerKeyboardShortcuts_buttonReset: {
294
+ background: 'none',
295
+ border: 0,
296
+ borderRadius: 0,
297
+ color: 'inherit',
298
+ font: 'inherit',
299
+ lineHeight: 'normal',
300
+ overflow: 'visible',
301
+ padding: 0,
302
+ cursor: 'pointer',
303
+ fontSize: font.size,
304
+
305
+ ':active': {
306
+ outline: 'none',
307
+ },
308
+ },
309
+
310
+ DayPickerKeyboardShortcuts_show: {
311
+ width: 33,
312
+ height: 26,
313
+ position: 'absolute',
314
+ zIndex: zIndex + 2,
315
+
316
+ '::before': {
317
+ content: '""',
318
+ display: 'block',
319
+ position: 'absolute',
320
+ },
321
+ },
322
+
323
+ DayPickerKeyboardShortcuts_show__bottomRight: {
324
+ bottom: 0,
325
+ right: 0,
326
+
327
+ '::before': {
328
+ borderTop: '26px solid transparent',
329
+ borderRight: `33px solid ${color.core.primary}`,
330
+ bottom: 0,
331
+ right: 0,
332
+ },
333
+
334
+ ':hover::before': {
335
+ borderRight: `33px solid ${color.core.primary_dark}`,
336
+ },
337
+ },
338
+
339
+ DayPickerKeyboardShortcuts_show__topRight: {
340
+ top: 0,
341
+ right: 0,
342
+
343
+ '::before': {
344
+ borderBottom: '26px solid transparent',
345
+ borderRight: `33px solid ${color.core.primary}`,
346
+ top: 0,
347
+ right: 0,
348
+ },
349
+
350
+ ':hover::before': {
351
+ borderRight: `33px solid ${color.core.primary_dark}`,
352
+ },
353
+ },
354
+
355
+ DayPickerKeyboardShortcuts_show__topLeft: {
356
+ top: 0,
357
+ left: 0,
358
+
359
+ '::before': {
360
+ borderBottom: '26px solid transparent',
361
+ borderLeft: `33px solid ${color.core.primary}`,
362
+ top: 0,
363
+ left: 0,
364
+ },
365
+
366
+ ':hover::before': {
367
+ borderLeft: `33px solid ${color.core.primary_dark}`,
368
+ },
369
+ },
370
+
371
+ DayPickerKeyboardShortcuts_showSpan: {
372
+ color: color.core.white,
373
+ position: 'absolute',
374
+ },
375
+
376
+ DayPickerKeyboardShortcuts_showSpan__bottomRight: {
377
+ bottom: 0,
378
+ right: 5,
379
+ },
380
+
381
+ DayPickerKeyboardShortcuts_showSpan__topRight: {
382
+ top: 1,
383
+ right: 5,
384
+ },
385
+
386
+ DayPickerKeyboardShortcuts_showSpan__topLeft: {
387
+ top: 1,
388
+ left: 5,
389
+ },
390
+
391
+ DayPickerKeyboardShortcuts_panel: {
392
+ overflow: 'auto',
393
+ background: color.background,
394
+ border: `1px solid ${color.core.border}`,
395
+ borderRadius: 2,
396
+ position: 'absolute',
397
+ top: 0,
398
+ bottom: 0,
399
+ right: 0,
400
+ left: 0,
401
+ zIndex: zIndex + 2,
402
+ padding: 22,
403
+ margin: 33,
404
+ textAlign: 'left', // TODO: investigate use of text-align throughout the library
405
+ },
406
+
407
+ DayPickerKeyboardShortcuts_title: {
408
+ fontSize: 16,
409
+ fontWeight: 'bold',
410
+ margin: 0,
411
+ },
412
+
413
+ DayPickerKeyboardShortcuts_list: {
414
+ listStyle: 'none',
415
+ padding: 0,
416
+ fontSize: font.size,
417
+ },
418
+
419
+ DayPickerKeyboardShortcuts_close: {
420
+ position: 'absolute',
421
+ right: 22,
422
+ top: 22,
423
+ zIndex: zIndex + 2,
424
+
425
+ ':active': {
426
+ outline: 'none',
427
+ },
428
+ },
429
+
430
+ DayPickerKeyboardShortcuts_closeSvg: {
431
+ height: 15,
432
+ width: 15,
433
+ fill: color.core.grayLighter,
434
+
435
+ ':hover': {
436
+ fill: color.core.grayLight,
437
+ },
438
+
439
+ ':focus': {
440
+ fill: color.core.grayLight,
441
+ },
442
+ },
443
+ }), { pureComponent: typeof React.PureComponent !== 'undefined' })(DayPickerKeyboardShortcuts);