@planningcenter/tapestry-react 2.9.0-rc.1 → 2.9.0-rc.2
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/TimeField/TimeField.js +262 -222
- package/dist/cjs/TimeField/TimeField.test.js +31 -31
- package/dist/cjs/TimeField/legacy_TimeField.js +274 -0
- package/dist/cjs/TimeField/utils.js +6 -12
- package/dist/cjs/utils.js +9 -0
- package/dist/esm/TimeField/TimeField.js +252 -225
- package/dist/esm/TimeField/TimeField.test.js +31 -31
- package/dist/esm/TimeField/legacy_TimeField.js +271 -0
- package/dist/esm/TimeField/utils.js +6 -12
- package/dist/esm/utils.js +9 -1
- package/dist/types/TimeField/TimeField.d.ts +35 -0
- package/package.json +2 -2
- package/src/TimeField/TimeField.mdx +1 -1
- package/src/TimeField/TimeField.test.tsx +68 -52
- package/src/TimeField/TimeField.tsx +326 -0
- package/src/TimeField/{TimeField.js → legacy_TimeField.js} +2 -6
- package/src/TimeField/utils.js +13 -11
- package/src/utils.js +8 -0
|
@@ -189,9 +189,9 @@ it('increment hour on arrow up', function () {
|
|
|
189
189
|
}),
|
|
190
190
|
hourInput = _setup15.hourInput;
|
|
191
191
|
|
|
192
|
-
expect(hourInput).toHaveValue(
|
|
192
|
+
expect(hourInput).toHaveValue('01');
|
|
193
193
|
userEvent.type(hourInput, '{arrowup}');
|
|
194
|
-
expect(hourInput).toHaveValue(
|
|
194
|
+
expect(hourInput).toHaveValue('02');
|
|
195
195
|
});
|
|
196
196
|
it('increment hour if arrow up on minutes exceeds max value', function () {
|
|
197
197
|
var _setup16 = setup({
|
|
@@ -201,9 +201,9 @@ it('increment hour if arrow up on minutes exceeds max value', function () {
|
|
|
201
201
|
hourInput = _setup16.hourInput,
|
|
202
202
|
minuteInput = _setup16.minuteInput;
|
|
203
203
|
|
|
204
|
-
expect(hourInput).toHaveValue(
|
|
204
|
+
expect(hourInput).toHaveValue('01');
|
|
205
205
|
userEvent.type(minuteInput, '{arrowup}');
|
|
206
|
-
expect(hourInput).toHaveValue(
|
|
206
|
+
expect(hourInput).toHaveValue('02');
|
|
207
207
|
});
|
|
208
208
|
it('decrement hour on arrow down', function () {
|
|
209
209
|
var _setup17 = setup({
|
|
@@ -212,9 +212,9 @@ it('decrement hour on arrow down', function () {
|
|
|
212
212
|
}),
|
|
213
213
|
hourInput = _setup17.hourInput;
|
|
214
214
|
|
|
215
|
-
expect(hourInput).toHaveValue(
|
|
215
|
+
expect(hourInput).toHaveValue('02');
|
|
216
216
|
userEvent.type(hourInput, '{arrowdown}');
|
|
217
|
-
expect(hourInput).toHaveValue(
|
|
217
|
+
expect(hourInput).toHaveValue('01');
|
|
218
218
|
});
|
|
219
219
|
it('decrement hour if arrow down on minutes exceeds min value', function () {
|
|
220
220
|
var _setup18 = setup({
|
|
@@ -224,9 +224,9 @@ it('decrement hour if arrow down on minutes exceeds min value', function () {
|
|
|
224
224
|
hourInput = _setup18.hourInput,
|
|
225
225
|
minuteInput = _setup18.minuteInput;
|
|
226
226
|
|
|
227
|
-
expect(hourInput).toHaveValue(
|
|
227
|
+
expect(hourInput).toHaveValue('02');
|
|
228
228
|
userEvent.type(minuteInput, '{arrowdown}');
|
|
229
|
-
expect(hourInput).toHaveValue(
|
|
229
|
+
expect(hourInput).toHaveValue('01');
|
|
230
230
|
});
|
|
231
231
|
it('increment minute on arrow up', function () {
|
|
232
232
|
var _setup19 = setup({
|
|
@@ -235,9 +235,9 @@ it('increment minute on arrow up', function () {
|
|
|
235
235
|
}),
|
|
236
236
|
minuteInput = _setup19.minuteInput;
|
|
237
237
|
|
|
238
|
-
expect(minuteInput).toHaveValue(
|
|
238
|
+
expect(minuteInput).toHaveValue('42');
|
|
239
239
|
userEvent.type(minuteInput, '{arrowup}');
|
|
240
|
-
expect(minuteInput).toHaveValue(
|
|
240
|
+
expect(minuteInput).toHaveValue('43');
|
|
241
241
|
});
|
|
242
242
|
it('decrement minute on arrow down', function () {
|
|
243
243
|
var _setup20 = setup({
|
|
@@ -246,9 +246,9 @@ it('decrement minute on arrow down', function () {
|
|
|
246
246
|
}),
|
|
247
247
|
minuteInput = _setup20.minuteInput;
|
|
248
248
|
|
|
249
|
-
expect(minuteInput).toHaveValue(
|
|
249
|
+
expect(minuteInput).toHaveValue('43');
|
|
250
250
|
userEvent.type(minuteInput, '{arrowdown}');
|
|
251
|
-
expect(minuteInput).toHaveValue(
|
|
251
|
+
expect(minuteInput).toHaveValue('42');
|
|
252
252
|
});
|
|
253
253
|
it('set minute to min value if arrow up on minutes exceeds max value', function () {
|
|
254
254
|
var _setup21 = setup({
|
|
@@ -257,9 +257,9 @@ it('set minute to min value if arrow up on minutes exceeds max value', function
|
|
|
257
257
|
}),
|
|
258
258
|
minuteInput = _setup21.minuteInput;
|
|
259
259
|
|
|
260
|
-
expect(minuteInput).toHaveValue(
|
|
260
|
+
expect(minuteInput).toHaveValue('59');
|
|
261
261
|
userEvent.type(minuteInput, '{arrowup}');
|
|
262
|
-
expect(minuteInput).toHaveValue(
|
|
262
|
+
expect(minuteInput).toHaveValue('00');
|
|
263
263
|
});
|
|
264
264
|
it('set minute to max value if arrow down on minutes exceeds min value', function () {
|
|
265
265
|
var _setup22 = setup({
|
|
@@ -268,9 +268,9 @@ it('set minute to max value if arrow down on minutes exceeds min value', functio
|
|
|
268
268
|
}),
|
|
269
269
|
minuteInput = _setup22.minuteInput;
|
|
270
270
|
|
|
271
|
-
expect(minuteInput).toHaveValue(
|
|
271
|
+
expect(minuteInput).toHaveValue('00');
|
|
272
272
|
userEvent.type(minuteInput, '{arrowdown}');
|
|
273
|
-
expect(minuteInput).toHaveValue(
|
|
273
|
+
expect(minuteInput).toHaveValue('59');
|
|
274
274
|
});
|
|
275
275
|
it('toggle meridiem if arrow up on hour exceeds eleven', function () {
|
|
276
276
|
var _setup23 = setup({
|
|
@@ -285,7 +285,7 @@ it('toggle meridiem if arrow up on hour exceeds eleven', function () {
|
|
|
285
285
|
});
|
|
286
286
|
it('toggle meridiem if arrow down on hour exceeds min value', function () {
|
|
287
287
|
var _setup24 = setup({
|
|
288
|
-
hours:
|
|
288
|
+
hours: 0
|
|
289
289
|
}),
|
|
290
290
|
hourInput = _setup24.hourInput,
|
|
291
291
|
meridiemInput = _setup24.meridiemInput;
|
|
@@ -300,9 +300,9 @@ it('set 12 hour clock to min value if arrow up on hour exceeds max value', funct
|
|
|
300
300
|
}),
|
|
301
301
|
hourInput = _setup25.hourInput;
|
|
302
302
|
|
|
303
|
-
expect(hourInput).toHaveValue(
|
|
303
|
+
expect(hourInput).toHaveValue('12');
|
|
304
304
|
userEvent.type(hourInput, '{arrowup}');
|
|
305
|
-
expect(hourInput).toHaveValue(
|
|
305
|
+
expect(hourInput).toHaveValue('01');
|
|
306
306
|
});
|
|
307
307
|
it('set 24 hour clock to min value if arrow up on hour exceeds max value', function () {
|
|
308
308
|
var _setup26 = setup({
|
|
@@ -311,9 +311,9 @@ it('set 24 hour clock to min value if arrow up on hour exceeds max value', funct
|
|
|
311
311
|
}),
|
|
312
312
|
hourInput = _setup26.hourInput;
|
|
313
313
|
|
|
314
|
-
expect(hourInput).toHaveValue(
|
|
314
|
+
expect(hourInput).toHaveValue('23');
|
|
315
315
|
userEvent.type(hourInput, '{arrowup}');
|
|
316
|
-
expect(hourInput).toHaveValue(
|
|
316
|
+
expect(hourInput).toHaveValue('00');
|
|
317
317
|
});
|
|
318
318
|
it('set 12 hour clock to max value if arrow down on hour exceeds min value', function () {
|
|
319
319
|
var _setup27 = setup({
|
|
@@ -321,9 +321,9 @@ it('set 12 hour clock to max value if arrow down on hour exceeds min value', fun
|
|
|
321
321
|
}),
|
|
322
322
|
hourInput = _setup27.hourInput;
|
|
323
323
|
|
|
324
|
-
expect(hourInput).toHaveValue(
|
|
324
|
+
expect(hourInput).toHaveValue('01');
|
|
325
325
|
userEvent.type(hourInput, '{arrowdown}');
|
|
326
|
-
expect(hourInput).toHaveValue(
|
|
326
|
+
expect(hourInput).toHaveValue('12');
|
|
327
327
|
});
|
|
328
328
|
it('set 24 hour clock to max value if arrow down on hour exceeds min value', function () {
|
|
329
329
|
var _setup28 = setup({
|
|
@@ -332,9 +332,9 @@ it('set 24 hour clock to max value if arrow down on hour exceeds min value', fun
|
|
|
332
332
|
}),
|
|
333
333
|
hourInput = _setup28.hourInput;
|
|
334
334
|
|
|
335
|
-
expect(hourInput).toHaveValue(
|
|
335
|
+
expect(hourInput).toHaveValue('00');
|
|
336
336
|
userEvent.type(hourInput, '{arrowdown}');
|
|
337
|
-
expect(hourInput).toHaveValue(
|
|
337
|
+
expect(hourInput).toHaveValue('23');
|
|
338
338
|
});
|
|
339
339
|
it('does not change the value of hours on arrow up or arrow down if ignored', function () {
|
|
340
340
|
var _setup29 = setup({
|
|
@@ -344,11 +344,11 @@ it('does not change the value of hours on arrow up or arrow down if ignored', fu
|
|
|
344
344
|
}),
|
|
345
345
|
hourInput = _setup29.hourInput;
|
|
346
346
|
|
|
347
|
-
expect(hourInput).toHaveValue(
|
|
347
|
+
expect(hourInput).toHaveValue('01');
|
|
348
348
|
userEvent.type(hourInput, '{arrowup}');
|
|
349
|
-
expect(hourInput).toHaveValue(
|
|
349
|
+
expect(hourInput).toHaveValue('01');
|
|
350
350
|
userEvent.type(hourInput, '{arrowdown}');
|
|
351
|
-
expect(hourInput).toHaveValue(
|
|
351
|
+
expect(hourInput).toHaveValue('01');
|
|
352
352
|
});
|
|
353
353
|
it('does not change the value of minutes on arrow up or arrow down if ignored', function () {
|
|
354
354
|
var _setup30 = setup({
|
|
@@ -358,11 +358,11 @@ it('does not change the value of minutes on arrow up or arrow down if ignored',
|
|
|
358
358
|
}),
|
|
359
359
|
minuteInput = _setup30.minuteInput;
|
|
360
360
|
|
|
361
|
-
expect(minuteInput).toHaveValue(
|
|
361
|
+
expect(minuteInput).toHaveValue('42');
|
|
362
362
|
userEvent.type(minuteInput, '{arrowup}');
|
|
363
|
-
expect(minuteInput).toHaveValue(
|
|
363
|
+
expect(minuteInput).toHaveValue('42');
|
|
364
364
|
userEvent.type(minuteInput, '{arrowdown}');
|
|
365
|
-
expect(minuteInput).toHaveValue(
|
|
365
|
+
expect(minuteInput).toHaveValue('42');
|
|
366
366
|
}); // ios
|
|
367
367
|
|
|
368
368
|
it('renders iOS as a single input', function () {
|
|
@@ -0,0 +1,271 @@
|
|
|
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;
|
|
@@ -10,18 +10,12 @@ export function addHoursToTime(time, hoursToAdd) {
|
|
|
10
10
|
export function addMinutesToTime(time, minutesToAdd) {
|
|
11
11
|
var hours = time[0],
|
|
12
12
|
minutes = time[1];
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
minutes = remainderMinutes;
|
|
20
|
-
} else {
|
|
21
|
-
minutes = nextMinutes;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return [hours, minutes];
|
|
13
|
+
var totalTimeInMinutes = hours * 60 + minutes;
|
|
14
|
+
var totalMinutesInDay = 24 * 60;
|
|
15
|
+
var newTime = parseInt(totalTimeInMinutes) + parseInt(minutesToAdd);
|
|
16
|
+
var newHours = newTime > totalMinutesInDay ? Math.floor(newTime / 60) - 24 : Math.floor(newTime / 60);
|
|
17
|
+
var newMinutes = newTime % 60;
|
|
18
|
+
return [newHours, newMinutes];
|
|
25
19
|
}
|
|
26
20
|
export function addTimeToDate(date, time) {
|
|
27
21
|
var hours = time[0],
|
package/dist/esm/utils.js
CHANGED
|
@@ -352,6 +352,14 @@ function isArray(value) {
|
|
|
352
352
|
function isFunction(value) {
|
|
353
353
|
return value && value.constructor === Function;
|
|
354
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Determines if value is a number
|
|
357
|
+
*/
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
function isNumber(value) {
|
|
361
|
+
return /^[0-9]$/i.test(value);
|
|
362
|
+
}
|
|
355
363
|
/**
|
|
356
364
|
* Determines if a value is present in an array by
|
|
357
365
|
* performing a shallow equal check on each item.
|
|
@@ -821,4 +829,4 @@ function mergeProps() {
|
|
|
821
829
|
}, {});
|
|
822
830
|
}
|
|
823
831
|
|
|
824
|
-
export { cloneChildren, composeEvents, composeMultipleEvents, createCSSProperty, deselectCurrentTextRange, generateId, getCSSProperty, getClosestFocusableElement, getClosestViewport, getInteractiveChildElements, getRect, getScrollbarWidth, getTabbableSiblings, getTextWidth, insertAtIndex, isArray, isElementInteractive, isFunction, isIOS, isValueInArray, joinChildren, lockScroll, mergeProps, noop, objectToCSSProperties, padNumber, pageViewChange, range, removeAtIndex, renderIndexedGroup, reorderArray, shallowEqual, selectFullTextRange, stopImmediatePropagation, stopPropagationClick, supportsPassiveEvents, trapFocus };
|
|
832
|
+
export { cloneChildren, composeEvents, composeMultipleEvents, createCSSProperty, deselectCurrentTextRange, generateId, getCSSProperty, getClosestFocusableElement, getClosestViewport, getInteractiveChildElements, getRect, getScrollbarWidth, getTabbableSiblings, getTextWidth, insertAtIndex, isArray, isElementInteractive, isFunction, isIOS, isNumber, isValueInArray, joinChildren, lockScroll, mergeProps, noop, objectToCSSProperties, padNumber, pageViewChange, range, removeAtIndex, renderIndexedGroup, reorderArray, shallowEqual, selectFullTextRange, stopImmediatePropagation, stopPropagationClick, supportsPassiveEvents, trapFocus };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
declare type TimeFieldProps = {
|
|
2
|
+
/**
|
|
3
|
+
* An array of keys to ignore when pushed.
|
|
4
|
+
* ex: ["ArrowUp", "ArrowDown"].
|
|
5
|
+
*/
|
|
6
|
+
ignoredKeys?: string[];
|
|
7
|
+
interval?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Render native time input, defaults to `true` if user platform is an iOS device, otherwise `false`.
|
|
10
|
+
*/
|
|
11
|
+
isIOS?: boolean;
|
|
12
|
+
max?: number;
|
|
13
|
+
min?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Receives new time from typing or navigating with up and down arrow keys.
|
|
16
|
+
*/
|
|
17
|
+
onChange: (event: any) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Displays time based on a 12 hour clock, `true` by default.
|
|
20
|
+
*/
|
|
21
|
+
twelveHourClock?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The controlled value passed to the internal input.
|
|
24
|
+
* Accepts an array of [hours, minutes] based on a 24 hour clock.
|
|
25
|
+
*/
|
|
26
|
+
value: [number, number];
|
|
27
|
+
};
|
|
28
|
+
declare const TimeField: {
|
|
29
|
+
({ ignoredKeys, interval, isIOS, max, min, onChange, twelveHourClock, value, ...restProps }: TimeFieldProps): JSX.Element;
|
|
30
|
+
addHoursToTime: any;
|
|
31
|
+
addMinutesToTime: any;
|
|
32
|
+
addTimeToDate: any;
|
|
33
|
+
getTimeFromDate: any;
|
|
34
|
+
};
|
|
35
|
+
export default TimeField;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/tapestry-react",
|
|
3
|
-
"version": "2.9.0-rc.
|
|
3
|
+
"version": "2.9.0-rc.2",
|
|
4
4
|
"description": "A collection of flexible React components to help you build resilient, accessible user interfaces quickly and effectively.",
|
|
5
5
|
"author": "Front End Systems Engineering <frontend@pco.bz>",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
90
|
"@planningcenter/icons": "^14.18.1",
|
|
91
|
-
"@planningcenter/react-beautiful-dnd": "^13.
|
|
91
|
+
"@planningcenter/react-beautiful-dnd": "^13.4.0",
|
|
92
92
|
"@popmotion/popcorn": "^0.4.4",
|
|
93
93
|
"@popperjs/core": "^2.11.6",
|
|
94
94
|
"@react-hook/window-size": "^3.1.1",
|