@planningcenter/tapestry-react 2.6.0-rc.9 → 2.6.1
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 +8 -1
- package/dist/cjs/Button/Button.test.js +51 -8
- package/dist/cjs/Collapse/Collapse.js +3 -1
- package/dist/cjs/DataTable/components/BodyRow.js +2 -2
- package/dist/cjs/DataTable/hooks/useCollapsibleRows.js +2 -2
- package/dist/cjs/Dropdown/Dropdown.js +23 -4
- package/dist/cjs/Dropdown/Dropdown.test.js +3 -3
- package/dist/cjs/Dropdown/Link.js +2 -4
- package/dist/cjs/Input/InputLabel.js +40 -63
- package/dist/cjs/Modal/Modal.js +18 -8
- package/dist/cjs/Modal/Modal.test.js +2 -2
- package/dist/cjs/Popover/Popover.js +10 -2
- package/dist/cjs/Scrim/Scrim.js +16 -4
- package/dist/cjs/Table/Table.js +5 -3
- package/dist/cjs/ThemeProvider/ThemeProvider.js +2 -2
- package/dist/cjs/TimeField/TimeField.js +38 -3
- package/dist/cjs/TimeField/TimeField.test.js +179 -10
- package/dist/cjs/Tooltip/Tooltip.js +27 -23
- package/dist/cjs/Tooltip/Tooltip.test.js +178 -0
- package/dist/cjs/system/utils.js +2 -2
- package/dist/cjs/utils.js +3 -3
- package/dist/esm/Button/Button.js +8 -1
- package/dist/esm/Button/Button.test.js +67 -9
- package/dist/esm/Collapse/Collapse.js +3 -1
- package/dist/esm/DataTable/components/BodyRow.js +2 -2
- package/dist/esm/DataTable/hooks/useCollapsibleRows.js +1 -1
- package/dist/esm/Dropdown/Dropdown.js +24 -5
- package/dist/esm/Dropdown/Dropdown.test.js +1 -1
- package/dist/esm/Dropdown/Link.js +1 -2
- package/dist/esm/Input/InputLabel.js +40 -63
- package/dist/esm/Modal/Modal.js +16 -8
- package/dist/esm/Modal/Modal.test.js +1 -1
- package/dist/esm/Popover/Popover.js +8 -2
- package/dist/esm/Scrim/Scrim.js +15 -4
- package/dist/esm/Table/Table.js +2 -1
- package/dist/esm/ThemeProvider/ThemeProvider.js +1 -1
- package/dist/esm/TimeField/TimeField.js +37 -3
- package/dist/esm/TimeField/TimeField.test.js +153 -10
- package/dist/esm/Tooltip/Tooltip.js +29 -24
- package/dist/esm/Tooltip/Tooltip.test.js +160 -0
- package/dist/esm/system/utils.js +1 -1
- package/dist/esm/utils.js +1 -1
- package/dist/types/Button/Button.d.ts +4 -0
- package/dist/types/ThemeProvider/ThemeProvider.d.ts +3 -3
- package/dist/types/Tooltip/Tooltip.test.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/package.json +4 -4
- package/src/Button/Button.test.tsx +30 -0
- package/src/Button/Button.tsx +14 -1
- package/src/Collapse/Collapse.js +1 -1
- package/src/DataTable/DataTable.js +1 -1
- package/src/DataTable/components/BodyRow.js +1 -1
- package/src/DataTable/hooks/useCollapsibleRows.js +1 -1
- package/src/Dropdown/Dropdown.js +19 -5
- package/src/Dropdown/Dropdown.mdx +3 -3
- package/src/Dropdown/Dropdown.test.tsx +1 -1
- package/src/Dropdown/Link.js +1 -7
- package/src/Input/InputLabel.js +39 -36
- package/src/Input/InputLabel.mdx +1 -0
- package/src/Modal/Modal.js +16 -6
- package/src/Modal/Modal.mdx +2 -1
- package/src/Modal/Modal.test.tsx +1 -1
- package/src/Popover/Popover.mdx +1 -0
- package/src/Popover/Popover.tsx +8 -2
- package/src/Scrim/Scrim.mdx +1 -0
- package/src/Scrim/Scrim.tsx +11 -6
- package/src/Sidebar/Sidebar.mdx +0 -1
- package/src/Table/Table.js +2 -1
- package/src/ThemeProvider/ThemeProvider.tsx +7 -6
- package/src/TimeField/TimeField.js +36 -3
- package/src/TimeField/TimeField.test.tsx +105 -1
- package/src/Tooltip/Tooltip.js +19 -21
- package/src/Tooltip/Tooltip.test.tsx +136 -0
- package/src/index.d.ts +1 -1
- package/src/system/utils.js +1 -1
- package/src/utils.js +1 -1
|
@@ -33,6 +33,9 @@ var _utils = require("../utils");
|
|
|
33
33
|
|
|
34
34
|
var _utils2 = require("./utils");
|
|
35
35
|
|
|
36
|
+
var MIN_MINUTE = 0;
|
|
37
|
+
var MAX_MINUTE = 59;
|
|
38
|
+
|
|
36
39
|
var TimeField = /*#__PURE__*/function (_Component) {
|
|
37
40
|
(0, _inheritsLoose2["default"])(TimeField, _Component);
|
|
38
41
|
|
|
@@ -89,9 +92,31 @@ var TimeField = /*#__PURE__*/function (_Component) {
|
|
|
89
92
|
});
|
|
90
93
|
});
|
|
91
94
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleHoursKeyDown", function (event) {
|
|
95
|
+
var hour = Number(event.target.value);
|
|
96
|
+
var isTwelveHourClock = _this.props.twelveHourClock;
|
|
97
|
+
var isHourEleven = _utils2.HOURS_TO_NOON - 1;
|
|
98
|
+
var maxHour = isTwelveHourClock ? _utils2.HOURS_TO_NOON : _utils2.HOURS_IN_DAY - 1;
|
|
99
|
+
var minHour = isTwelveHourClock ? 1 : 0;
|
|
100
|
+
|
|
92
101
|
if (event.key === 'ArrowRight') {
|
|
93
102
|
_this.inputBox.focus(1);
|
|
94
103
|
}
|
|
104
|
+
|
|
105
|
+
if (event.key === 'ArrowUp' && isTwelveHourClock && hour === isHourEleven) {
|
|
106
|
+
_this.toggleMeridiem();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (event.key === 'ArrowUp' && hour === maxHour) {
|
|
110
|
+
_this.updateHours(1);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (event.key === 'ArrowDown' && isTwelveHourClock && hour === minHour) {
|
|
114
|
+
_this.toggleMeridiem();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (event.key === 'ArrowDown' && hour === minHour) {
|
|
118
|
+
_this.updateHours(-1);
|
|
119
|
+
}
|
|
95
120
|
});
|
|
96
121
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleMinutesChange", function (minutes) {
|
|
97
122
|
_this.updateTime({
|
|
@@ -99,6 +124,8 @@ var TimeField = /*#__PURE__*/function (_Component) {
|
|
|
99
124
|
});
|
|
100
125
|
});
|
|
101
126
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleMinutesKeyDown", function (event) {
|
|
127
|
+
var minute = Number(event.target.value);
|
|
128
|
+
|
|
102
129
|
if (_this.props.ignoredKeys.includes(event.key)) {
|
|
103
130
|
return;
|
|
104
131
|
}
|
|
@@ -110,6 +137,14 @@ var TimeField = /*#__PURE__*/function (_Component) {
|
|
|
110
137
|
if (event.key === 'ArrowRight') {
|
|
111
138
|
_this.inputBox.focus(2);
|
|
112
139
|
}
|
|
140
|
+
|
|
141
|
+
if (event.key === 'ArrowUp' && minute >= MAX_MINUTE) {
|
|
142
|
+
_this.updateMinutes(1);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (event.key === 'ArrowDown' && minute <= MIN_MINUTE) {
|
|
146
|
+
_this.updateMinutes(-1);
|
|
147
|
+
}
|
|
113
148
|
});
|
|
114
149
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleAMPMKeyDown", function (event) {
|
|
115
150
|
if (_this.props.ignoredKeys.includes(event.key)) {
|
|
@@ -200,8 +235,8 @@ var TimeField = /*#__PURE__*/function (_Component) {
|
|
|
200
235
|
fontVariantNumeric: "tabular-nums",
|
|
201
236
|
moveFocusOnMax: true,
|
|
202
237
|
value: minutes,
|
|
203
|
-
min:
|
|
204
|
-
max:
|
|
238
|
+
min: MIN_MINUTE,
|
|
239
|
+
max: MAX_MINUTE,
|
|
205
240
|
pad: 2,
|
|
206
241
|
grow: 0,
|
|
207
242
|
width: "2ch",
|
|
@@ -214,7 +249,7 @@ var TimeField = /*#__PURE__*/function (_Component) {
|
|
|
214
249
|
highlightOnInteraction: true,
|
|
215
250
|
value: this.state.meridiem,
|
|
216
251
|
grow: 0,
|
|
217
|
-
width:
|
|
252
|
+
width: "2em",
|
|
218
253
|
textAlign: "center",
|
|
219
254
|
"aria-label": "AM/PM",
|
|
220
255
|
onChange: _utils.noop // prevent React warnings
|
|
@@ -204,7 +204,7 @@ it('does not change the meridiem on arrow key if arrow keys are ignored', functi
|
|
|
204
204
|
|
|
205
205
|
expect(meridiemInput).toHaveValue('PM');
|
|
206
206
|
});
|
|
207
|
-
it('
|
|
207
|
+
it('increment hour on arrow up', function () {
|
|
208
208
|
var _setup15 = setup({
|
|
209
209
|
hours: 1,
|
|
210
210
|
minutes: 42
|
|
@@ -217,13 +217,182 @@ it('changes the value of hours on arrow up or arrow down', function () {
|
|
|
217
217
|
|
|
218
218
|
expect(hourInput).toHaveValue("02");
|
|
219
219
|
});
|
|
220
|
-
it('
|
|
220
|
+
it('increment hour if arrow up on minutes exceeds max value', function () {
|
|
221
221
|
var _setup16 = setup({
|
|
222
|
+
hours: 1,
|
|
223
|
+
minutes: 59
|
|
224
|
+
}),
|
|
225
|
+
hourInput = _setup16.hourInput,
|
|
226
|
+
minuteInput = _setup16.minuteInput;
|
|
227
|
+
|
|
228
|
+
expect(hourInput).toHaveValue("01");
|
|
229
|
+
|
|
230
|
+
_userEvent["default"].type(minuteInput, '{arrowup}');
|
|
231
|
+
|
|
232
|
+
expect(hourInput).toHaveValue("02");
|
|
233
|
+
});
|
|
234
|
+
it('decrement hour on arrow down', function () {
|
|
235
|
+
var _setup17 = setup({
|
|
236
|
+
hours: 2,
|
|
237
|
+
minutes: 42
|
|
238
|
+
}),
|
|
239
|
+
hourInput = _setup17.hourInput;
|
|
240
|
+
|
|
241
|
+
expect(hourInput).toHaveValue("02");
|
|
242
|
+
|
|
243
|
+
_userEvent["default"].type(hourInput, '{arrowdown}');
|
|
244
|
+
|
|
245
|
+
expect(hourInput).toHaveValue("01");
|
|
246
|
+
});
|
|
247
|
+
it('decrement hour if arrow down on minutes exceeds min value', function () {
|
|
248
|
+
var _setup18 = setup({
|
|
249
|
+
hours: 2,
|
|
250
|
+
minutes: 0
|
|
251
|
+
}),
|
|
252
|
+
hourInput = _setup18.hourInput,
|
|
253
|
+
minuteInput = _setup18.minuteInput;
|
|
254
|
+
|
|
255
|
+
expect(hourInput).toHaveValue("02");
|
|
256
|
+
|
|
257
|
+
_userEvent["default"].type(minuteInput, '{arrowdown}');
|
|
258
|
+
|
|
259
|
+
expect(hourInput).toHaveValue("01");
|
|
260
|
+
});
|
|
261
|
+
it('increment minute on arrow up', function () {
|
|
262
|
+
var _setup19 = setup({
|
|
263
|
+
hours: 1,
|
|
264
|
+
minutes: 42
|
|
265
|
+
}),
|
|
266
|
+
minuteInput = _setup19.minuteInput;
|
|
267
|
+
|
|
268
|
+
expect(minuteInput).toHaveValue("42");
|
|
269
|
+
|
|
270
|
+
_userEvent["default"].type(minuteInput, '{arrowup}');
|
|
271
|
+
|
|
272
|
+
expect(minuteInput).toHaveValue("43");
|
|
273
|
+
});
|
|
274
|
+
it('decrement minute on arrow down', function () {
|
|
275
|
+
var _setup20 = setup({
|
|
276
|
+
hours: 2,
|
|
277
|
+
minutes: 43
|
|
278
|
+
}),
|
|
279
|
+
minuteInput = _setup20.minuteInput;
|
|
280
|
+
|
|
281
|
+
expect(minuteInput).toHaveValue("43");
|
|
282
|
+
|
|
283
|
+
_userEvent["default"].type(minuteInput, '{arrowdown}');
|
|
284
|
+
|
|
285
|
+
expect(minuteInput).toHaveValue("42");
|
|
286
|
+
});
|
|
287
|
+
it('set minute to min value if arrow up on minutes exceeds max value', function () {
|
|
288
|
+
var _setup21 = setup({
|
|
289
|
+
hours: 1,
|
|
290
|
+
minutes: 59
|
|
291
|
+
}),
|
|
292
|
+
minuteInput = _setup21.minuteInput;
|
|
293
|
+
|
|
294
|
+
expect(minuteInput).toHaveValue("59");
|
|
295
|
+
|
|
296
|
+
_userEvent["default"].type(minuteInput, '{arrowup}');
|
|
297
|
+
|
|
298
|
+
expect(minuteInput).toHaveValue("00");
|
|
299
|
+
});
|
|
300
|
+
it('set minute to max value if arrow down on minutes exceeds min value', function () {
|
|
301
|
+
var _setup22 = setup({
|
|
302
|
+
hours: 1,
|
|
303
|
+
minutes: 0
|
|
304
|
+
}),
|
|
305
|
+
minuteInput = _setup22.minuteInput;
|
|
306
|
+
|
|
307
|
+
expect(minuteInput).toHaveValue("00");
|
|
308
|
+
|
|
309
|
+
_userEvent["default"].type(minuteInput, '{arrowdown}');
|
|
310
|
+
|
|
311
|
+
expect(minuteInput).toHaveValue("59");
|
|
312
|
+
});
|
|
313
|
+
it('toggle meridiem if arrow up on hour exceeds eleven', function () {
|
|
314
|
+
var _setup23 = setup({
|
|
315
|
+
hours: 11
|
|
316
|
+
}),
|
|
317
|
+
hourInput = _setup23.hourInput,
|
|
318
|
+
meridiemInput = _setup23.meridiemInput;
|
|
319
|
+
|
|
320
|
+
expect(meridiemInput).toHaveValue('AM');
|
|
321
|
+
|
|
322
|
+
_userEvent["default"].type(hourInput, '{arrowup}');
|
|
323
|
+
|
|
324
|
+
expect(meridiemInput).toHaveValue('PM');
|
|
325
|
+
});
|
|
326
|
+
it('toggle meridiem if arrow down on hour exceeds min value', function () {
|
|
327
|
+
var _setup24 = setup({
|
|
328
|
+
hours: 1
|
|
329
|
+
}),
|
|
330
|
+
hourInput = _setup24.hourInput,
|
|
331
|
+
meridiemInput = _setup24.meridiemInput;
|
|
332
|
+
|
|
333
|
+
expect(meridiemInput).toHaveValue('AM');
|
|
334
|
+
|
|
335
|
+
_userEvent["default"].type(hourInput, '{arrowdown}');
|
|
336
|
+
|
|
337
|
+
expect(meridiemInput).toHaveValue('PM');
|
|
338
|
+
});
|
|
339
|
+
it('set 12 hour clock to min value if arrow up on hour exceeds max value', function () {
|
|
340
|
+
var _setup25 = setup({
|
|
341
|
+
hours: 12
|
|
342
|
+
}),
|
|
343
|
+
hourInput = _setup25.hourInput;
|
|
344
|
+
|
|
345
|
+
expect(hourInput).toHaveValue("12");
|
|
346
|
+
|
|
347
|
+
_userEvent["default"].type(hourInput, '{arrowup}');
|
|
348
|
+
|
|
349
|
+
expect(hourInput).toHaveValue("01");
|
|
350
|
+
});
|
|
351
|
+
it('set 24 hour clock to min value if arrow up on hour exceeds max value', function () {
|
|
352
|
+
var _setup26 = setup({
|
|
353
|
+
hours: 23,
|
|
354
|
+
twelveHourClock: false
|
|
355
|
+
}),
|
|
356
|
+
hourInput = _setup26.hourInput;
|
|
357
|
+
|
|
358
|
+
expect(hourInput).toHaveValue("23");
|
|
359
|
+
|
|
360
|
+
_userEvent["default"].type(hourInput, '{arrowup}');
|
|
361
|
+
|
|
362
|
+
expect(hourInput).toHaveValue("00");
|
|
363
|
+
});
|
|
364
|
+
it('set 12 hour clock to max value if arrow down on hour exceeds min value', function () {
|
|
365
|
+
var _setup27 = setup({
|
|
366
|
+
hours: 1
|
|
367
|
+
}),
|
|
368
|
+
hourInput = _setup27.hourInput;
|
|
369
|
+
|
|
370
|
+
expect(hourInput).toHaveValue("01");
|
|
371
|
+
|
|
372
|
+
_userEvent["default"].type(hourInput, '{arrowdown}');
|
|
373
|
+
|
|
374
|
+
expect(hourInput).toHaveValue("12");
|
|
375
|
+
});
|
|
376
|
+
it('set 24 hour clock to max value if arrow down on hour exceeds min value', function () {
|
|
377
|
+
var _setup28 = setup({
|
|
378
|
+
hours: 0,
|
|
379
|
+
twelveHourClock: false
|
|
380
|
+
}),
|
|
381
|
+
hourInput = _setup28.hourInput;
|
|
382
|
+
|
|
383
|
+
expect(hourInput).toHaveValue("00");
|
|
384
|
+
|
|
385
|
+
_userEvent["default"].type(hourInput, '{arrowdown}');
|
|
386
|
+
|
|
387
|
+
expect(hourInput).toHaveValue("23");
|
|
388
|
+
});
|
|
389
|
+
it('does not change the value of hours on arrow up or arrow down if ignored', function () {
|
|
390
|
+
var _setup29 = setup({
|
|
222
391
|
hours: 1,
|
|
223
392
|
minutes: 42,
|
|
224
393
|
ignoredKeys: ['ArrowUp', 'ArrowDown']
|
|
225
394
|
}),
|
|
226
|
-
hourInput =
|
|
395
|
+
hourInput = _setup29.hourInput;
|
|
227
396
|
|
|
228
397
|
expect(hourInput).toHaveValue("01");
|
|
229
398
|
|
|
@@ -236,12 +405,12 @@ it('does not change the value of hours on arrow up or arrow down if ignored', fu
|
|
|
236
405
|
expect(hourInput).toHaveValue("01");
|
|
237
406
|
});
|
|
238
407
|
it('does not change the value of minutes on arrow up or arrow down if ignored', function () {
|
|
239
|
-
var
|
|
408
|
+
var _setup30 = setup({
|
|
240
409
|
hours: 1,
|
|
241
410
|
minutes: 42,
|
|
242
411
|
ignoredKeys: ['ArrowUp', 'ArrowDown']
|
|
243
412
|
}),
|
|
244
|
-
minuteInput =
|
|
413
|
+
minuteInput = _setup30.minuteInput;
|
|
245
414
|
|
|
246
415
|
expect(minuteInput).toHaveValue("42");
|
|
247
416
|
|
|
@@ -255,15 +424,15 @@ it('does not change the value of minutes on arrow up or arrow down if ignored',
|
|
|
255
424
|
}); // ios
|
|
256
425
|
|
|
257
426
|
it('renders iOS as a single input', function () {
|
|
258
|
-
var
|
|
427
|
+
var _setup31 = setup({
|
|
259
428
|
isIOS: true,
|
|
260
429
|
hours: 13,
|
|
261
430
|
minutes: 42
|
|
262
431
|
}),
|
|
263
|
-
container =
|
|
264
|
-
hourInput =
|
|
265
|
-
minuteInput =
|
|
266
|
-
meridiemInput =
|
|
432
|
+
container = _setup31.container,
|
|
433
|
+
hourInput = _setup31.hourInput,
|
|
434
|
+
minuteInput = _setup31.minuteInput,
|
|
435
|
+
meridiemInput = _setup31.meridiemInput;
|
|
267
436
|
|
|
268
437
|
var singleTimeInput = container.querySelector('[type=time]');
|
|
269
438
|
expect(singleTimeInput).toHaveValue('13:42');
|
|
@@ -57,23 +57,22 @@ function Tooltip(props, ref) {
|
|
|
57
57
|
triggerOnHover = _useThemeProps$trigge2 === void 0 ? true : _useThemeProps$trigge2,
|
|
58
58
|
childProps = (0, _objectWithoutPropertiesLoose2["default"])(_useThemeProps, ["children", "openDelay", "closeDelay", "defaultOpen", "keepInView", "placement", "popoverProps", "renderTo", "title", "triggerOnFocus", "triggerOnHover"]);
|
|
59
59
|
|
|
60
|
-
var isPageInView = true;
|
|
61
|
-
var
|
|
62
|
-
var isMouseDown = false;
|
|
60
|
+
var isPageInView = (0, _react.useRef)(true);
|
|
61
|
+
var isMouseDown = (0, _react.useRef)(false);
|
|
63
62
|
var openTimeoutId = (0, _react.useRef)(null);
|
|
64
|
-
var closeTimeoutId = (0, _react.useRef)(null);
|
|
65
|
-
|
|
66
|
-
var cleanupPageViewChange = (0, _react.useCallback)((0, _utils.pageViewChange)(function (inView) {
|
|
67
|
-
return setTimeout(function () {
|
|
68
|
-
return isPageInView = inView;
|
|
69
|
-
});
|
|
70
|
-
}));
|
|
63
|
+
var closeTimeoutId = (0, _react.useRef)(null);
|
|
71
64
|
|
|
72
65
|
var _useState = (0, _react.useState)(defaultOpen),
|
|
73
66
|
isPopoverOpen = _useState[0],
|
|
74
67
|
setIsPopoverOpen = _useState[1];
|
|
75
68
|
|
|
76
69
|
(0, _react.useEffect)(function () {
|
|
70
|
+
// prevents tooltips showing when focused and navigating back to a page after leaving
|
|
71
|
+
var cleanupPageViewChange = (0, _utils.pageViewChange)(function (inView) {
|
|
72
|
+
return setTimeout(function () {
|
|
73
|
+
return isPageInView.current = inView;
|
|
74
|
+
});
|
|
75
|
+
});
|
|
77
76
|
emitter.on('CLOSE_OPEN_TOOLTIPS', close);
|
|
78
77
|
return function () {
|
|
79
78
|
emitter.off('CLOSE_OPEN_TOOLTIPS', close);
|
|
@@ -116,7 +115,8 @@ function Tooltip(props, ref) {
|
|
|
116
115
|
close();
|
|
117
116
|
}
|
|
118
117
|
}, [triggerOnHover]);
|
|
119
|
-
|
|
118
|
+
|
|
119
|
+
var createOpenTimeout = function createOpenTimeout() {
|
|
120
120
|
clearGlobalTimeout();
|
|
121
121
|
|
|
122
122
|
if (openTimeoutId.current === null) {
|
|
@@ -130,8 +130,9 @@ function Tooltip(props, ref) {
|
|
|
130
130
|
}, instantDelay ? 0 : openDelay);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
}
|
|
134
|
-
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
var createCloseTimeout = function createCloseTimeout() {
|
|
135
136
|
startGlobalTimeout();
|
|
136
137
|
|
|
137
138
|
if (closeTimeoutId.current === null) {
|
|
@@ -141,19 +142,22 @@ function Tooltip(props, ref) {
|
|
|
141
142
|
return close();
|
|
142
143
|
}, closeDelay);
|
|
143
144
|
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
var handleFocus = function handleFocus() {
|
|
148
|
+
if (isPageInView.current && !isMouseDown.current) {
|
|
147
149
|
open();
|
|
148
150
|
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
var handleMouseDown = function handleMouseDown() {
|
|
154
|
+
isMouseDown.current = true;
|
|
152
155
|
close();
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
var handleMouseUp = function handleMouseUp() {
|
|
159
|
+
isMouseDown.current = false;
|
|
160
|
+
};
|
|
157
161
|
|
|
158
162
|
var child = _react.Children.only(children);
|
|
159
163
|
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
6
|
+
|
|
7
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
8
|
+
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
|
|
11
|
+
var _react2 = require("@testing-library/react");
|
|
12
|
+
|
|
13
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
14
|
+
|
|
15
|
+
require("@testing-library/jest-dom/extend-expect");
|
|
16
|
+
|
|
17
|
+
var _ = require("..");
|
|
18
|
+
|
|
19
|
+
describe('Tooltip', function () {
|
|
20
|
+
test('does not render string when closed', function () {
|
|
21
|
+
var string = 'Test Text';
|
|
22
|
+
(0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_.Tooltip, {
|
|
23
|
+
title: string
|
|
24
|
+
}, /*#__PURE__*/_react["default"].createElement(_.Text, null, "Tooltip anchor")));
|
|
25
|
+
expect(_react2.screen.queryByText(string)).toBeNull();
|
|
26
|
+
});
|
|
27
|
+
test('renders string on hover', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
28
|
+
var string, tooltip;
|
|
29
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
30
|
+
while (1) {
|
|
31
|
+
switch (_context.prev = _context.next) {
|
|
32
|
+
case 0:
|
|
33
|
+
string = 'Test Text';
|
|
34
|
+
(0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_.Tooltip, {
|
|
35
|
+
title: string
|
|
36
|
+
}, /*#__PURE__*/_react["default"].createElement(_.Text, null, "Tooltip anchor")));
|
|
37
|
+
|
|
38
|
+
_userEvent["default"].hover(_react2.screen.getByText('Tooltip anchor'));
|
|
39
|
+
|
|
40
|
+
_context.next = 5;
|
|
41
|
+
return _react2.screen.findByText(string);
|
|
42
|
+
|
|
43
|
+
case 5:
|
|
44
|
+
tooltip = _context.sent;
|
|
45
|
+
expect(tooltip).toBeInTheDocument();
|
|
46
|
+
|
|
47
|
+
case 7:
|
|
48
|
+
case "end":
|
|
49
|
+
return _context.stop();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}, _callee);
|
|
53
|
+
})));
|
|
54
|
+
test('renders string on focus', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
55
|
+
var string, tooltip;
|
|
56
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
57
|
+
while (1) {
|
|
58
|
+
switch (_context2.prev = _context2.next) {
|
|
59
|
+
case 0:
|
|
60
|
+
string = 'Test Text';
|
|
61
|
+
(0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_.Tooltip, {
|
|
62
|
+
title: string,
|
|
63
|
+
triggerOnFocus: true
|
|
64
|
+
}, /*#__PURE__*/_react["default"].createElement(_.Button, null, "Tooltip anchor")));
|
|
65
|
+
|
|
66
|
+
_userEvent["default"].tab();
|
|
67
|
+
|
|
68
|
+
_context2.next = 5;
|
|
69
|
+
return _react2.screen.findByText(string);
|
|
70
|
+
|
|
71
|
+
case 5:
|
|
72
|
+
tooltip = _context2.sent;
|
|
73
|
+
expect(tooltip).toBeInTheDocument();
|
|
74
|
+
|
|
75
|
+
case 7:
|
|
76
|
+
case "end":
|
|
77
|
+
return _context2.stop();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}, _callee2);
|
|
81
|
+
})));
|
|
82
|
+
test('removes string after timeout', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
|
|
83
|
+
var string, anchor, tooltip;
|
|
84
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
85
|
+
while (1) {
|
|
86
|
+
switch (_context3.prev = _context3.next) {
|
|
87
|
+
case 0:
|
|
88
|
+
string = 'Test Text';
|
|
89
|
+
(0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_.Tooltip, {
|
|
90
|
+
title: string
|
|
91
|
+
}, /*#__PURE__*/_react["default"].createElement(_.Text, null, "Tooltip anchor")));
|
|
92
|
+
anchor = _react2.screen.getByText('Tooltip anchor');
|
|
93
|
+
expect(_react2.screen.queryByText(string)).toBeNull();
|
|
94
|
+
|
|
95
|
+
_userEvent["default"].hover(anchor);
|
|
96
|
+
|
|
97
|
+
_context3.next = 7;
|
|
98
|
+
return _react2.screen.findByText(string);
|
|
99
|
+
|
|
100
|
+
case 7:
|
|
101
|
+
tooltip = _context3.sent;
|
|
102
|
+
expect(tooltip).toBeInTheDocument();
|
|
103
|
+
|
|
104
|
+
_userEvent["default"].unhover(anchor);
|
|
105
|
+
|
|
106
|
+
_context3.next = 12;
|
|
107
|
+
return (0, _react2.waitFor)(function () {
|
|
108
|
+
expect(_react2.screen.queryByText(string)).not.toBeInTheDocument();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
case 12:
|
|
112
|
+
case "end":
|
|
113
|
+
return _context3.stop();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}, _callee3);
|
|
117
|
+
})));
|
|
118
|
+
test('stays open when hovering a custom tooltip', function () {
|
|
119
|
+
var CustomTooltip = function CustomTooltip() {
|
|
120
|
+
var _hooks$useHover = _.hooks.useHover(),
|
|
121
|
+
hover = _hooks$useHover.hover,
|
|
122
|
+
hoverProps = _hooks$useHover.hoverProps;
|
|
123
|
+
|
|
124
|
+
return /*#__PURE__*/_react["default"].createElement(_.Tooltip, {
|
|
125
|
+
title: /*#__PURE__*/_react["default"].createElement(_.Link, {
|
|
126
|
+
to: "#"
|
|
127
|
+
}, /*#__PURE__*/_react["default"].createElement(_.StackView, null, /*#__PURE__*/_react["default"].createElement(_.Text, {
|
|
128
|
+
"data-hover": hover
|
|
129
|
+
}, string)))
|
|
130
|
+
}, /*#__PURE__*/_react["default"].createElement(_.Button, hoverProps, "Tooltip anchor"));
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
var string = 'Test Text';
|
|
134
|
+
(0, _react2.render)( /*#__PURE__*/_react["default"].createElement(CustomTooltip, null));
|
|
135
|
+
|
|
136
|
+
var anchor = _react2.screen.getByText('Tooltip anchor');
|
|
137
|
+
|
|
138
|
+
_userEvent["default"].hover(anchor);
|
|
139
|
+
|
|
140
|
+
(0, _react2.act)(function () {
|
|
141
|
+
jest.runAllTimers();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
var tooltip = _react2.screen.getByText(string);
|
|
145
|
+
|
|
146
|
+
expect(tooltip).toBeInTheDocument();
|
|
147
|
+
|
|
148
|
+
_userEvent["default"].unhover(anchor);
|
|
149
|
+
|
|
150
|
+
_userEvent["default"].hover(tooltip);
|
|
151
|
+
|
|
152
|
+
(0, _react2.act)(function () {
|
|
153
|
+
jest.runAllTimers();
|
|
154
|
+
});
|
|
155
|
+
expect(tooltip).toBeInTheDocument();
|
|
156
|
+
|
|
157
|
+
_userEvent["default"].unhover(tooltip);
|
|
158
|
+
|
|
159
|
+
(0, _react2.act)(function () {
|
|
160
|
+
jest.runAllTimers();
|
|
161
|
+
});
|
|
162
|
+
expect(tooltip).not.toBeInTheDocument();
|
|
163
|
+
});
|
|
164
|
+
test('cleans up pageViewChange listeners', function () {
|
|
165
|
+
window.removeEventListener = jest.fn().mockImplementation(function (event, callback) {});
|
|
166
|
+
document.removeEventListener = jest.fn().mockImplementation(function (event, callback) {});
|
|
167
|
+
|
|
168
|
+
var _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_.Tooltip, {
|
|
169
|
+
title: "Test Text"
|
|
170
|
+
}, /*#__PURE__*/_react["default"].createElement(_.Text, null, "Tooltip anchor"))),
|
|
171
|
+
unmount = _render.unmount;
|
|
172
|
+
|
|
173
|
+
unmount();
|
|
174
|
+
expect(window.removeEventListener).toBeCalledWith('focus', expect.any(Function));
|
|
175
|
+
expect(window.removeEventListener).toBeCalledWith('blur', expect.any(Function));
|
|
176
|
+
expect(document.removeEventListener).toBeCalledWith('visibilitychange', expect.any(Function));
|
|
177
|
+
});
|
|
178
|
+
});
|
package/dist/cjs/system/utils.js
CHANGED
|
@@ -24,7 +24,7 @@ var _react2 = require("@emotion/react");
|
|
|
24
24
|
|
|
25
25
|
var _polished = require("polished");
|
|
26
26
|
|
|
27
|
-
var
|
|
27
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
28
28
|
|
|
29
29
|
var _colors = require("./colors");
|
|
30
30
|
|
|
@@ -161,7 +161,7 @@ function getForegroundColor(color) {
|
|
|
161
161
|
|
|
162
162
|
function useThemeValue(path, defaultValue) {
|
|
163
163
|
var userTheme = (0, _react.useContext)(_react2.ThemeContext);
|
|
164
|
-
return path ? (0,
|
|
164
|
+
return path ? (0, _get["default"])(userTheme, path, defaultValue || (0, _get["default"])(_defaultTheme["default"], path)) : userTheme || _defaultTheme["default"];
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
function useThemeProps(path, props) {
|
package/dist/cjs/utils.js
CHANGED
|
@@ -46,7 +46,7 @@ var _react = require("react");
|
|
|
46
46
|
|
|
47
47
|
var _tabbable = require("tabbable");
|
|
48
48
|
|
|
49
|
-
var
|
|
49
|
+
var _kebabCase = _interopRequireDefault(require("lodash/kebabCase"));
|
|
50
50
|
|
|
51
51
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
52
52
|
|
|
@@ -785,11 +785,11 @@ function createCSSProperty(key, value) {
|
|
|
785
785
|
createdCSSProperties.add(key);
|
|
786
786
|
}
|
|
787
787
|
|
|
788
|
-
return "--" + (0,
|
|
788
|
+
return "--" + (0, _kebabCase["default"])(key) + "-" + (0, _kebabCase["default"])(value);
|
|
789
789
|
}
|
|
790
790
|
|
|
791
791
|
function getCSSProperty(key, value) {
|
|
792
|
-
return key && value ? "var(--" + (0,
|
|
792
|
+
return key && value ? "var(--" + (0, _kebabCase["default"])(key) + "-" + (0, _kebabCase["default"])(value) + ")" : undefined;
|
|
793
793
|
}
|
|
794
794
|
|
|
795
795
|
function objectToCSSProperties(themeKey, props) {
|
|
@@ -210,6 +210,13 @@ export function Button(_ref) {
|
|
|
210
210
|
|
|
211
211
|
if (to) {
|
|
212
212
|
restProps['href'] = to;
|
|
213
|
+
} // remove `type` if either `to` or `href` is specified
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
if (to || restProps.href) {
|
|
217
|
+
buttonProps = _objectSpread(_objectSpread({}, buttonProps), {}, {
|
|
218
|
+
type: null
|
|
219
|
+
});
|
|
213
220
|
} // apply stroke defaults and higher z-index when hovering to show outline in group properly
|
|
214
221
|
|
|
215
222
|
|
|
@@ -244,7 +251,7 @@ export function Button(_ref) {
|
|
|
244
251
|
restProps = mergeProps(restProps, wrapperProps);
|
|
245
252
|
}
|
|
246
253
|
|
|
247
|
-
if (type && restProps.as && restProps.as !== "button") {
|
|
254
|
+
if (buttonProps.type && restProps.as && restProps.as !== "button") {
|
|
248
255
|
console.log("Tapestry-React: <Button/> type prop is only supported by <button> and not <" + restProps.as + ">.");
|
|
249
256
|
}
|
|
250
257
|
}
|