@planningcenter/tapestry-react 2.9.0-rc.4 → 2.9.0-rc.7
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.
- package/dist/cjs/Button/Button.js +15 -4
- package/dist/cjs/FilterLayout/FilterLayout.js +5 -3
- package/dist/cjs/TimeField/utils.js +12 -6
- package/dist/cjs/ToggleSwitch/ToggleSwitch.js +99 -0
- package/dist/cjs/ToggleSwitch/ToggleSwitch.test.js +67 -0
- package/dist/cjs/ToggleSwitch/index.js +15 -0
- package/dist/cjs/index.d.js +13 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/system/colors/colors.js +17 -0
- package/dist/cjs/system/default-theme.js +3 -0
- package/dist/cjs/system/plugins/color.js +3 -1
- package/dist/cjs/system/style-names.js +1 -1
- package/dist/cjs/utils.js +0 -9
- package/dist/esm/Button/Button.js +15 -4
- package/dist/esm/FilterLayout/FilterLayout.js +5 -3
- package/dist/esm/TimeField/utils.js +12 -6
- package/dist/esm/ToggleSwitch/ToggleSwitch.js +80 -0
- package/dist/esm/ToggleSwitch/ToggleSwitch.test.js +57 -0
- package/dist/esm/ToggleSwitch/index.js +2 -0
- package/dist/esm/index.d.js +2 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/system/colors/colors.js +18 -1
- package/dist/esm/system/default-theme.js +3 -0
- package/dist/esm/system/plugins/color.js +3 -1
- package/dist/esm/system/style-names.js +1 -1
- package/dist/esm/utils.js +1 -9
- package/dist/types/Button/Button.d.ts +5 -1
- package/dist/types/ToggleSwitch/ToggleSwitch.d.ts +22 -0
- package/dist/types/ToggleSwitch/ToggleSwitch.test.d.ts +1 -0
- package/dist/types/ToggleSwitch/index.d.ts +2 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/system/style-names.d.ts +2 -2
- package/package.json +1 -1
- package/src/Button/Button.tsx +26 -3
- package/src/FilterLayout/FilterLayout.tsx +9 -6
- package/src/TimeField/TimeField.mdx +1 -1
- package/src/TimeField/utils.js +11 -13
- package/src/ToggleSwitch/ToggleSwitch.mdx +56 -0
- package/src/ToggleSwitch/ToggleSwitch.test.tsx +51 -0
- package/src/ToggleSwitch/ToggleSwitch.tsx +106 -0
- package/src/ToggleSwitch/index.ts +2 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +1 -0
- package/src/system/colors/colors.js +20 -1
- package/src/system/default-theme.ts +3 -0
- package/src/system/plugins/color.js +3 -0
- package/src/system/style-names.ts +1 -0
- package/src/utils.js +0 -8
- package/dist/cjs/TimeField/legacy_TimeField.js +0 -274
- package/dist/esm/TimeField/legacy_TimeField.js +0 -271
- package/src/TimeField/legacy_TimeField.js +0 -278
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
4
|
-
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
|
|
5
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
6
|
-
import React, { Component } from 'react';
|
|
7
|
-
import Box from '../Box';
|
|
8
|
-
import Input from '../Input/Input';
|
|
9
|
-
import InputBox from '../Input/InputBox';
|
|
10
|
-
import InputField from '../Input/InputField';
|
|
11
|
-
import NumberField from '../NumberField';
|
|
12
|
-
import { isIOS, noop, padNumber } from '../utils';
|
|
13
|
-
import { HOURS_TO_NOON, HOURS_IN_DAY, addHoursToTime, addMinutesToTime, addTimeToDate, getMeridiem, getTimeFromDate } from './utils';
|
|
14
|
-
var MIN_MINUTE = 0;
|
|
15
|
-
var MAX_MINUTE = 59;
|
|
16
|
-
|
|
17
|
-
var _ref = /*#__PURE__*/React.createElement(Box, {
|
|
18
|
-
as: "span",
|
|
19
|
-
width: 0.5,
|
|
20
|
-
textAlign: "center",
|
|
21
|
-
userSelect: "none"
|
|
22
|
-
}, ":");
|
|
23
|
-
|
|
24
|
-
var TimeField = /*#__PURE__*/function (_Component) {
|
|
25
|
-
_inheritsLoose(TimeField, _Component);
|
|
26
|
-
|
|
27
|
-
function TimeField(props) {
|
|
28
|
-
var _this;
|
|
29
|
-
|
|
30
|
-
_this = _Component.call(this, props) || this;
|
|
31
|
-
|
|
32
|
-
_defineProperty(_assertThisInitialized(_this), "setInputBoxRef", function (component) {
|
|
33
|
-
_this.inputBox = component;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
_defineProperty(_assertThisInitialized(_this), "updateTime", function (time) {
|
|
37
|
-
if (time === void 0) {
|
|
38
|
-
time = {};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
var _this$props$value = _this.props.value,
|
|
42
|
-
hours = _this$props$value[0],
|
|
43
|
-
minutes = _this$props$value[1];
|
|
44
|
-
|
|
45
|
-
if (time.hours !== undefined) {
|
|
46
|
-
hours = time.hours;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (time.minutes !== undefined) {
|
|
50
|
-
minutes = time.minutes;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (_this.props.twelveHourClock && !_this.props.isIOS) {
|
|
54
|
-
if (hours > 11 && _this.state.meridiem === 'AM') {
|
|
55
|
-
hours -= 12;
|
|
56
|
-
} else if (hours < 12 && _this.state.meridiem === 'PM') {
|
|
57
|
-
hours += 12;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
_this.props.onChange([hours, minutes]);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
_defineProperty(_assertThisInitialized(_this), "updateHours", function (amount) {
|
|
65
|
-
_this.props.onChange(addHoursToTime(_this.props.value, amount));
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
_defineProperty(_assertThisInitialized(_this), "updateMinutes", function (amount) {
|
|
69
|
-
_this.props.onChange(addMinutesToTime(_this.props.value, amount));
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
_defineProperty(_assertThisInitialized(_this), "toggleMeridiem", function () {
|
|
73
|
-
_this.setState(function (state) {
|
|
74
|
-
return {
|
|
75
|
-
meridiem: state.meridiem === 'AM' ? 'PM' : 'AM'
|
|
76
|
-
};
|
|
77
|
-
}, _this.updateTime);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
_defineProperty(_assertThisInitialized(_this), "handleHoursChange", function (hours) {
|
|
81
|
-
_this.updateTime({
|
|
82
|
-
hours: hours
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
_defineProperty(_assertThisInitialized(_this), "handleHoursKeyDown", function (event) {
|
|
87
|
-
var hour = Number(event.target.value);
|
|
88
|
-
var isTwelveHourClock = _this.props.twelveHourClock;
|
|
89
|
-
var isHourEleven = HOURS_TO_NOON - 1;
|
|
90
|
-
var maxHour = isTwelveHourClock ? HOURS_TO_NOON : HOURS_IN_DAY - 1;
|
|
91
|
-
var minHour = isTwelveHourClock ? 1 : 0;
|
|
92
|
-
|
|
93
|
-
if (event.key === 'ArrowRight') {
|
|
94
|
-
_this.inputBox.focus(1);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (event.key === 'ArrowUp' && isTwelveHourClock && hour === isHourEleven) {
|
|
98
|
-
_this.toggleMeridiem();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (event.key === 'ArrowUp' && hour === maxHour) {
|
|
102
|
-
_this.updateHours(1);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (event.key === 'ArrowDown' && isTwelveHourClock && hour === minHour) {
|
|
106
|
-
_this.toggleMeridiem();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (event.key === 'ArrowDown' && hour === minHour) {
|
|
110
|
-
_this.updateHours(-1);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
_defineProperty(_assertThisInitialized(_this), "handleMinutesChange", function (minutes) {
|
|
115
|
-
_this.updateTime({
|
|
116
|
-
minutes: minutes
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
_defineProperty(_assertThisInitialized(_this), "handleMinutesKeyDown", function (event) {
|
|
121
|
-
var minute = Number(event.target.value);
|
|
122
|
-
|
|
123
|
-
if (_this.props.ignoredKeys.includes(event.key)) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (event.key === 'ArrowLeft') {
|
|
128
|
-
_this.inputBox.focus(0);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (event.key === 'ArrowRight') {
|
|
132
|
-
_this.inputBox.focus(2);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (event.key === 'ArrowUp' && minute >= MAX_MINUTE) {
|
|
136
|
-
_this.updateMinutes(1);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (event.key === 'ArrowDown' && minute <= MIN_MINUTE) {
|
|
140
|
-
_this.updateMinutes(-1);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
_defineProperty(_assertThisInitialized(_this), "handleAMPMKeyDown", function (event) {
|
|
145
|
-
if (_this.props.ignoredKeys.includes(event.key)) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (event.key !== 'Tab' && !(event.metaKey && event.key === 'r')) {
|
|
150
|
-
event.preventDefault();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (event.key === 'ArrowLeft') {
|
|
154
|
-
_this.inputBox.focus(1);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (event.key.toLowerCase() === 'a' && _this.state.meridiem === 'PM' || event.key.toLowerCase() === 'p' && _this.state.meridiem === 'AM' || event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
|
158
|
-
_this.toggleMeridiem();
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
_defineProperty(_assertThisInitialized(_this), "handleIOSChange", function (event) {
|
|
163
|
-
var _event$target$value$s = event.target.value.split(':'),
|
|
164
|
-
hours = _event$target$value$s[0],
|
|
165
|
-
minutes = _event$target$value$s[1];
|
|
166
|
-
|
|
167
|
-
_this.updateTime({
|
|
168
|
-
hours: +hours,
|
|
169
|
-
minutes: +minutes
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
_this.state = {
|
|
174
|
-
meridiem: getMeridiem(props.value)
|
|
175
|
-
};
|
|
176
|
-
return _this;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
var _proto = TimeField.prototype;
|
|
180
|
-
|
|
181
|
-
_proto.componentDidUpdate = function componentDidUpdate(lastProps) {
|
|
182
|
-
if (lastProps.value[0] !== this.props.value[0]) {
|
|
183
|
-
this.setState({
|
|
184
|
-
meridiem: getMeridiem(this.props.value)
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
_proto.render = function render() {
|
|
190
|
-
var _this$props = this.props,
|
|
191
|
-
ignoredKeys = _this$props.ignoredKeys,
|
|
192
|
-
value = _this$props.value,
|
|
193
|
-
min = _this$props.min,
|
|
194
|
-
max = _this$props.max,
|
|
195
|
-
interval = _this$props.interval,
|
|
196
|
-
onChange = _this$props.onChange,
|
|
197
|
-
twelveHourClock = _this$props.twelveHourClock,
|
|
198
|
-
isIOS = _this$props.isIOS,
|
|
199
|
-
restProps = _objectWithoutPropertiesLoose(_this$props, ["ignoredKeys", "value", "min", "max", "interval", "onChange", "twelveHourClock", "isIOS"]);
|
|
200
|
-
|
|
201
|
-
var hours = value[0],
|
|
202
|
-
minutes = value[1];
|
|
203
|
-
return isIOS ? /*#__PURE__*/React.createElement(Input, _extends({}, restProps, {
|
|
204
|
-
type: "time",
|
|
205
|
-
autoWidth: hours + ":" + padNumber(minutes, 2) + " " + this.state.meridiem,
|
|
206
|
-
value: padNumber(hours, 2) + ":" + padNumber(minutes, 2),
|
|
207
|
-
onChange: this.handleIOSChange
|
|
208
|
-
})) : /*#__PURE__*/React.createElement(InputBox, _extends({
|
|
209
|
-
ref: this.setInputBoxRef,
|
|
210
|
-
inline: true
|
|
211
|
-
}, restProps), /*#__PURE__*/React.createElement(NumberField, {
|
|
212
|
-
autoWidth: false,
|
|
213
|
-
fontVariantNumeric: "tabular-nums",
|
|
214
|
-
moveFocusOnMax: true,
|
|
215
|
-
value: twelveHourClock ? hours % HOURS_TO_NOON || HOURS_TO_NOON : hours,
|
|
216
|
-
min: twelveHourClock ? 1 : 0,
|
|
217
|
-
max: twelveHourClock ? HOURS_TO_NOON : HOURS_IN_DAY - 1,
|
|
218
|
-
pad: 2,
|
|
219
|
-
grow: 0,
|
|
220
|
-
width: "2ch",
|
|
221
|
-
textAlign: "center",
|
|
222
|
-
"aria-label": "Hours",
|
|
223
|
-
onChange: this.handleHoursChange,
|
|
224
|
-
onKeyDown: this.handleHoursKeyDown,
|
|
225
|
-
ignoredKeys: ignoredKeys
|
|
226
|
-
}), _ref, /*#__PURE__*/React.createElement(NumberField, {
|
|
227
|
-
autoWidth: false,
|
|
228
|
-
fontVariantNumeric: "tabular-nums",
|
|
229
|
-
moveFocusOnMax: true,
|
|
230
|
-
value: minutes,
|
|
231
|
-
min: MIN_MINUTE,
|
|
232
|
-
max: MAX_MINUTE,
|
|
233
|
-
pad: 2,
|
|
234
|
-
grow: 0,
|
|
235
|
-
width: "2ch",
|
|
236
|
-
textAlign: "center",
|
|
237
|
-
"aria-label": "Minutes",
|
|
238
|
-
onChange: this.handleMinutesChange,
|
|
239
|
-
onKeyDown: this.handleMinutesKeyDown,
|
|
240
|
-
ignoredKeys: ignoredKeys
|
|
241
|
-
}), twelveHourClock && /*#__PURE__*/React.createElement(InputField, {
|
|
242
|
-
highlightOnInteraction: true,
|
|
243
|
-
value: this.state.meridiem,
|
|
244
|
-
grow: 0,
|
|
245
|
-
width: "2em",
|
|
246
|
-
textAlign: "center",
|
|
247
|
-
"aria-label": "AM/PM",
|
|
248
|
-
onChange: noop // prevent React warnings
|
|
249
|
-
,
|
|
250
|
-
onKeyDown: this.handleAMPMKeyDown
|
|
251
|
-
}));
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
return TimeField;
|
|
255
|
-
}(Component);
|
|
256
|
-
|
|
257
|
-
_defineProperty(TimeField, "addHoursToTime", addHoursToTime);
|
|
258
|
-
|
|
259
|
-
_defineProperty(TimeField, "addMinutesToTime", addMinutesToTime);
|
|
260
|
-
|
|
261
|
-
_defineProperty(TimeField, "addTimeToDate", addTimeToDate);
|
|
262
|
-
|
|
263
|
-
_defineProperty(TimeField, "getTimeFromDate", getTimeFromDate);
|
|
264
|
-
|
|
265
|
-
_defineProperty(TimeField, "defaultProps", {
|
|
266
|
-
twelveHourClock: true,
|
|
267
|
-
ignoredKeys: [],
|
|
268
|
-
isIOS: isIOS
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
export default TimeField;
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import React, { Component } from 'react'
|
|
3
|
-
|
|
4
|
-
import Box from '../Box'
|
|
5
|
-
import Input from '../Input/Input'
|
|
6
|
-
import InputBox from '../Input/InputBox'
|
|
7
|
-
import InputField from '../Input/InputField'
|
|
8
|
-
import NumberField from '../NumberField'
|
|
9
|
-
import { isIOS, noop, padNumber } from '../utils'
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
HOURS_TO_NOON,
|
|
13
|
-
HOURS_IN_DAY,
|
|
14
|
-
addHoursToTime,
|
|
15
|
-
addMinutesToTime,
|
|
16
|
-
addTimeToDate,
|
|
17
|
-
getMeridiem,
|
|
18
|
-
getTimeFromDate,
|
|
19
|
-
} from './utils'
|
|
20
|
-
|
|
21
|
-
const MIN_MINUTE = 0
|
|
22
|
-
const MAX_MINUTE = 59
|
|
23
|
-
|
|
24
|
-
type Props = {
|
|
25
|
-
/**
|
|
26
|
-
* An array of keys to ignore when pushed.
|
|
27
|
-
* ex: ["ArrowUp", "ArrowDown"].
|
|
28
|
-
*/
|
|
29
|
-
ignoredKeys: string[],
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Render native time input, defaults to `true` if user platform is an iOS device, otherwise `false`.
|
|
33
|
-
*/
|
|
34
|
-
isIOS: boolean,
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Receives new time from typing or navigating with up and down arrow keys.
|
|
38
|
-
*/
|
|
39
|
-
onChange: (time: string) => null,
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Displays time based on a 12 hour clock, `true` by default.
|
|
43
|
-
*/
|
|
44
|
-
twelveHourClock: boolean,
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* The controlled value passed to the internal input.
|
|
48
|
-
* Accepts an array of [hours, minutes] based on a 24 hour clock.
|
|
49
|
-
*/
|
|
50
|
-
value: Array<number, number>,
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
class TimeField extends Component<Props> {
|
|
54
|
-
static addHoursToTime = addHoursToTime
|
|
55
|
-
|
|
56
|
-
static addMinutesToTime = addMinutesToTime
|
|
57
|
-
|
|
58
|
-
static addTimeToDate = addTimeToDate
|
|
59
|
-
|
|
60
|
-
static getTimeFromDate = getTimeFromDate
|
|
61
|
-
|
|
62
|
-
static defaultProps = {
|
|
63
|
-
twelveHourClock: true,
|
|
64
|
-
ignoredKeys: [],
|
|
65
|
-
isIOS,
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
constructor(props) {
|
|
69
|
-
super(props)
|
|
70
|
-
this.state = {
|
|
71
|
-
meridiem: getMeridiem(props.value),
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
componentDidUpdate(lastProps) {
|
|
76
|
-
if (lastProps.value[0] !== this.props.value[0]) {
|
|
77
|
-
this.setState({
|
|
78
|
-
meridiem: getMeridiem(this.props.value),
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
setInputBoxRef = (component) => {
|
|
84
|
-
this.inputBox = component
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
updateTime = (time = {}) => {
|
|
88
|
-
let [hours, minutes] = this.props.value
|
|
89
|
-
if (time.hours !== undefined) {
|
|
90
|
-
hours = time.hours
|
|
91
|
-
}
|
|
92
|
-
if (time.minutes !== undefined) {
|
|
93
|
-
minutes = time.minutes
|
|
94
|
-
}
|
|
95
|
-
if (this.props.twelveHourClock && !this.props.isIOS) {
|
|
96
|
-
if (hours > 11 && this.state.meridiem === 'AM') {
|
|
97
|
-
hours -= 12
|
|
98
|
-
} else if (hours < 12 && this.state.meridiem === 'PM') {
|
|
99
|
-
hours += 12
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
this.props.onChange([hours, minutes])
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
updateHours = (amount) => {
|
|
106
|
-
this.props.onChange(addHoursToTime(this.props.value, amount))
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
updateMinutes = (amount) => {
|
|
110
|
-
this.props.onChange(addMinutesToTime(this.props.value, amount))
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
toggleMeridiem = () => {
|
|
114
|
-
this.setState(
|
|
115
|
-
(state) => ({ meridiem: state.meridiem === 'AM' ? 'PM' : 'AM' }),
|
|
116
|
-
this.updateTime
|
|
117
|
-
)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
handleHoursChange = (hours) => {
|
|
121
|
-
this.updateTime({ hours })
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
handleHoursKeyDown = (event) => {
|
|
125
|
-
const hour = Number(event.target.value)
|
|
126
|
-
const isTwelveHourClock = this.props.twelveHourClock
|
|
127
|
-
const isHourEleven = HOURS_TO_NOON - 1
|
|
128
|
-
const maxHour = isTwelveHourClock ? HOURS_TO_NOON : HOURS_IN_DAY - 1
|
|
129
|
-
const minHour = isTwelveHourClock ? 1 : 0
|
|
130
|
-
|
|
131
|
-
if (event.key === 'ArrowRight') {
|
|
132
|
-
this.inputBox.focus(1)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (event.key === 'ArrowUp' && isTwelveHourClock && hour === isHourEleven) {
|
|
136
|
-
this.toggleMeridiem()
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (event.key === 'ArrowUp' && hour === maxHour) {
|
|
140
|
-
this.updateHours(1)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (event.key === 'ArrowDown' && isTwelveHourClock && hour === minHour) {
|
|
144
|
-
this.toggleMeridiem()
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (event.key === 'ArrowDown' && hour === minHour) {
|
|
148
|
-
this.updateHours(-1)
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
handleMinutesChange = (minutes) => {
|
|
153
|
-
this.updateTime({ minutes })
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
handleMinutesKeyDown = (event) => {
|
|
157
|
-
const minute = Number(event.target.value)
|
|
158
|
-
|
|
159
|
-
if (this.props.ignoredKeys.includes(event.key)) {
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
if (event.key === 'ArrowLeft') {
|
|
163
|
-
this.inputBox.focus(0)
|
|
164
|
-
}
|
|
165
|
-
if (event.key === 'ArrowRight') {
|
|
166
|
-
this.inputBox.focus(2)
|
|
167
|
-
}
|
|
168
|
-
if (event.key === 'ArrowUp' && minute >= MAX_MINUTE) {
|
|
169
|
-
this.updateMinutes(1)
|
|
170
|
-
}
|
|
171
|
-
if (event.key === 'ArrowDown' && minute <= MIN_MINUTE) {
|
|
172
|
-
this.updateMinutes(-1)
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
handleAMPMKeyDown = (event) => {
|
|
177
|
-
if (this.props.ignoredKeys.includes(event.key)) {
|
|
178
|
-
return
|
|
179
|
-
}
|
|
180
|
-
if (event.key !== 'Tab' && !(event.metaKey && event.key === 'r')) {
|
|
181
|
-
event.preventDefault()
|
|
182
|
-
}
|
|
183
|
-
if (event.key === 'ArrowLeft') {
|
|
184
|
-
this.inputBox.focus(1)
|
|
185
|
-
}
|
|
186
|
-
if (
|
|
187
|
-
(event.key.toLowerCase() === 'a' && this.state.meridiem === 'PM') ||
|
|
188
|
-
(event.key.toLowerCase() === 'p' && this.state.meridiem === 'AM') ||
|
|
189
|
-
event.key === 'ArrowUp' ||
|
|
190
|
-
event.key === 'ArrowDown'
|
|
191
|
-
) {
|
|
192
|
-
this.toggleMeridiem()
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
handleIOSChange = (event) => {
|
|
197
|
-
const [hours, minutes] = event.target.value.split(':')
|
|
198
|
-
this.updateTime({ hours: +hours, minutes: +minutes })
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
render() {
|
|
202
|
-
const {
|
|
203
|
-
ignoredKeys,
|
|
204
|
-
value,
|
|
205
|
-
min,
|
|
206
|
-
max,
|
|
207
|
-
interval,
|
|
208
|
-
onChange,
|
|
209
|
-
twelveHourClock,
|
|
210
|
-
isIOS,
|
|
211
|
-
...restProps
|
|
212
|
-
} = this.props
|
|
213
|
-
const [hours, minutes] = value
|
|
214
|
-
return isIOS ? (
|
|
215
|
-
<Input
|
|
216
|
-
{...restProps}
|
|
217
|
-
type="time"
|
|
218
|
-
autoWidth={`${hours}:${padNumber(minutes, 2)} ${this.state.meridiem}`}
|
|
219
|
-
value={`${padNumber(hours, 2)}:${padNumber(minutes, 2)}`}
|
|
220
|
-
onChange={this.handleIOSChange}
|
|
221
|
-
/>
|
|
222
|
-
) : (
|
|
223
|
-
<InputBox ref={this.setInputBoxRef} inline {...restProps}>
|
|
224
|
-
<NumberField
|
|
225
|
-
autoWidth={false}
|
|
226
|
-
fontVariantNumeric="tabular-nums"
|
|
227
|
-
moveFocusOnMax
|
|
228
|
-
value={
|
|
229
|
-
twelveHourClock ? hours % HOURS_TO_NOON || HOURS_TO_NOON : hours
|
|
230
|
-
}
|
|
231
|
-
min={twelveHourClock ? 1 : 0}
|
|
232
|
-
max={twelveHourClock ? HOURS_TO_NOON : HOURS_IN_DAY - 1}
|
|
233
|
-
pad={2}
|
|
234
|
-
grow={0}
|
|
235
|
-
width="2ch"
|
|
236
|
-
textAlign="center"
|
|
237
|
-
aria-label="Hours"
|
|
238
|
-
onChange={this.handleHoursChange}
|
|
239
|
-
onKeyDown={this.handleHoursKeyDown}
|
|
240
|
-
{...{ ignoredKeys }}
|
|
241
|
-
/>
|
|
242
|
-
<Box as="span" width={0.5} textAlign="center" userSelect="none">
|
|
243
|
-
:
|
|
244
|
-
</Box>
|
|
245
|
-
<NumberField
|
|
246
|
-
autoWidth={false}
|
|
247
|
-
fontVariantNumeric="tabular-nums"
|
|
248
|
-
moveFocusOnMax
|
|
249
|
-
value={minutes}
|
|
250
|
-
min={MIN_MINUTE}
|
|
251
|
-
max={MAX_MINUTE}
|
|
252
|
-
pad={2}
|
|
253
|
-
grow={0}
|
|
254
|
-
width="2ch"
|
|
255
|
-
textAlign="center"
|
|
256
|
-
aria-label="Minutes"
|
|
257
|
-
onChange={this.handleMinutesChange}
|
|
258
|
-
onKeyDown={this.handleMinutesKeyDown}
|
|
259
|
-
{...{ ignoredKeys }}
|
|
260
|
-
/>
|
|
261
|
-
{twelveHourClock && (
|
|
262
|
-
<InputField
|
|
263
|
-
highlightOnInteraction
|
|
264
|
-
value={this.state.meridiem}
|
|
265
|
-
grow={0}
|
|
266
|
-
width="2em"
|
|
267
|
-
textAlign="center"
|
|
268
|
-
aria-label="AM/PM"
|
|
269
|
-
onChange={noop} // prevent React warnings
|
|
270
|
-
onKeyDown={this.handleAMPMKeyDown}
|
|
271
|
-
/>
|
|
272
|
-
)}
|
|
273
|
-
</InputBox>
|
|
274
|
-
)
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export default TimeField
|