@digitransit-component/digitransit-component-favourite-bar 6.0.5 → 7.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.
- package/README.md +38 -32
- package/lib/index.cjs +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.development.cjs +232 -272
- package/lib/index.js +230 -269
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import {
|
|
2
|
+
import React, { useState, useRef, useEffect } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import cx from 'classnames';
|
|
5
|
-
import differenceWith from 'lodash/differenceWith';
|
|
6
|
-
import isEqual from 'lodash/isEqual';
|
|
7
|
-
import isEmpty from 'lodash/isEmpty';
|
|
8
5
|
import Shimmer from '@hsl-fi/shimmer';
|
|
9
6
|
import SuggestionItem from '@digitransit-component/digitransit-component-suggestion-item';
|
|
10
7
|
import Icon, { defaultColors } from '@digitransit-component/digitransit-component-icon';
|
|
11
8
|
import 'lodash/uniqWith';
|
|
9
|
+
import 'lodash/isEqual';
|
|
12
10
|
import memoize from 'lodash/memoize';
|
|
13
11
|
import escapeRegExp from 'lodash/escapeRegExp';
|
|
14
12
|
import cloneDeep from 'lodash/cloneDeep';
|
|
@@ -247,6 +245,23 @@ i18n.init();
|
|
|
247
245
|
|
|
248
246
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
249
247
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
248
|
+
const DEFAULT_FONT_WEIGHTS = {
|
|
249
|
+
medium: 500
|
|
250
|
+
};
|
|
251
|
+
const TOGGLE_DEBOUNCE_MS = 200;
|
|
252
|
+
const LIST_BOTTOM_MARGIN = 16;
|
|
253
|
+
const MIN_LIST_HEIGHT = 120;
|
|
254
|
+
const FAVOURITE_ICON_ID_TO_NAME = {
|
|
255
|
+
'icon-icon_place': 'place',
|
|
256
|
+
'icon-icon_home': 'home',
|
|
257
|
+
'icon-icon_work': 'work',
|
|
258
|
+
'icon-icon_sport': 'sport',
|
|
259
|
+
'icon-icon_school': 'school',
|
|
260
|
+
'icon-icon_shopping': 'shopping',
|
|
261
|
+
// Map two buggy ids temporarily. This code can be removed at some point.
|
|
262
|
+
icon_home: 'home',
|
|
263
|
+
icon_work: 'work'
|
|
264
|
+
};
|
|
250
265
|
const isKeyboardSelectionEvent = event => {
|
|
251
266
|
const space = [13, ' ', 'Spacebar'];
|
|
252
267
|
const enter = [32, 'Enter'];
|
|
@@ -273,7 +288,9 @@ const FavouriteLocation = ({
|
|
|
273
288
|
color,
|
|
274
289
|
lang
|
|
275
290
|
}) => {
|
|
276
|
-
const [t] = useTranslation(
|
|
291
|
+
const [t] = useTranslation('translation', {
|
|
292
|
+
i18n
|
|
293
|
+
});
|
|
277
294
|
const ariaLabel = label === '' ? text : `${text} ${label} ${t('add-destination', {
|
|
278
295
|
lng: lang
|
|
279
296
|
})}`;
|
|
@@ -309,8 +326,6 @@ process.env.NODE_ENV !== "production" ? FavouriteLocation.propTypes = {
|
|
|
309
326
|
color: PropTypes.string.isRequired,
|
|
310
327
|
lang: PropTypes.string.isRequired
|
|
311
328
|
} : void 0;
|
|
312
|
-
const LIST_BOTTOM_MARGIN = 16;
|
|
313
|
-
const MIN_LIST_HEIGHT = 120;
|
|
314
329
|
|
|
315
330
|
/**
|
|
316
331
|
* FavouriteBar renders favourites. FavouriteBar displays the first two favourites, the rest are shown in a list.
|
|
@@ -318,263 +333,215 @@ const MIN_LIST_HEIGHT = 120;
|
|
|
318
333
|
* <FavouriteBar
|
|
319
334
|
* favourites={favourites}
|
|
320
335
|
* onClickFavourite={onClickFavourite}
|
|
321
|
-
* onAddPlace={
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
336
|
+
* onAddPlace={onAddPlace}
|
|
337
|
+
* onEdit={onEdit}
|
|
338
|
+
* onAddHome={onAddHome}
|
|
339
|
+
* onAddWork={onAddWork}
|
|
340
|
+
* lang={lang}
|
|
341
|
+
* isLoading={isLoading}
|
|
326
342
|
* />
|
|
327
343
|
*/
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
344
|
+
function FavouriteBar({
|
|
345
|
+
favourites,
|
|
346
|
+
onClickFavourite,
|
|
347
|
+
onAddPlace,
|
|
348
|
+
onEdit,
|
|
349
|
+
onAddHome,
|
|
350
|
+
onAddWork,
|
|
351
|
+
lang = 'fi',
|
|
352
|
+
isLoading = false,
|
|
353
|
+
colors = defaultColors,
|
|
354
|
+
fontWeights = DEFAULT_FONT_WEIGHTS
|
|
355
|
+
}) {
|
|
356
|
+
const [t] = useTranslation('translation', {
|
|
357
|
+
i18n
|
|
358
|
+
});
|
|
359
|
+
const [listOpen, setListOpen] = useState(false);
|
|
360
|
+
const [listMaxHeight, setListMaxHeight] = useState(null);
|
|
361
|
+
const expandListRef = useRef(null);
|
|
362
|
+
const suggestionListRef = useRef(null);
|
|
363
|
+
const firstItemRef = useRef(null);
|
|
364
|
+
const lastToggleRef = useRef(0);
|
|
365
|
+
const focusAfterToggleRef = useRef(false);
|
|
366
|
+
const firstFavourite = favourites[0] || null;
|
|
367
|
+
const secondFavourite = favourites[1] || null;
|
|
368
|
+
const listFavourites = favourites.slice(2);
|
|
369
|
+
const translate = id => t(id, {
|
|
370
|
+
lng: lang
|
|
371
|
+
});
|
|
372
|
+
useEffect(() => {
|
|
373
|
+
const handleClickOutside = event => {
|
|
374
|
+
if (suggestionListRef.current && expandListRef.current && !suggestionListRef.current.contains(event.target) && !expandListRef.current.contains(event.target)) {
|
|
375
|
+
setListOpen(false);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
379
|
+
return () => document.removeEventListener('mousedown', handleClickOutside);
|
|
380
|
+
}, []);
|
|
381
|
+
|
|
382
|
+
// Let the list grow down to the bottom edge of the viewport
|
|
383
|
+
useEffect(() => {
|
|
384
|
+
if (!listOpen) {
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
387
|
+
const updateListMaxHeight = () => {
|
|
388
|
+
const list = suggestionListRef.current;
|
|
334
389
|
if (list) {
|
|
335
390
|
const {
|
|
336
391
|
top
|
|
337
392
|
} = list.getBoundingClientRect();
|
|
338
|
-
|
|
339
|
-
this.setState({
|
|
340
|
-
listMaxHeight
|
|
341
|
-
});
|
|
393
|
+
setListMaxHeight(Math.max(window.innerHeight - top - LIST_BOTTOM_MARGIN, MIN_LIST_HEIGHT));
|
|
342
394
|
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
_defineProperty(this, "translate", id => {
|
|
361
|
-
return this.props.t(id, {
|
|
362
|
-
lng: this.props.lang
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
_defineProperty(this, "handleClickOutside", event => {
|
|
366
|
-
if (this.suggestionListRef.current && this.expandListRef.current && !this.suggestionListRef.current.contains(event.target) && !this.expandListRef.current.contains(event.target)) {
|
|
367
|
-
this.setState({
|
|
368
|
-
listOpen: false
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
_defineProperty(this, "suggestionSelected", index => {
|
|
373
|
-
const {
|
|
374
|
-
favourites
|
|
375
|
-
} = this.state;
|
|
376
|
-
if (index < favourites.length) {
|
|
377
|
-
this.props.onClickFavourite(favourites[index]);
|
|
378
|
-
} else if (index === favourites.length) {
|
|
379
|
-
this.props.onAddPlace();
|
|
380
|
-
} else if (index === favourites.length + 1) {
|
|
381
|
-
this.props.onEdit();
|
|
395
|
+
};
|
|
396
|
+
updateListMaxHeight();
|
|
397
|
+
window.addEventListener('resize', updateListMaxHeight);
|
|
398
|
+
return () => window.removeEventListener('resize', updateListMaxHeight);
|
|
399
|
+
}, [listOpen]);
|
|
400
|
+
|
|
401
|
+
// Move focus only after a toggle, not when the list is closed by other means
|
|
402
|
+
useEffect(() => {
|
|
403
|
+
if (focusAfterToggleRef.current) {
|
|
404
|
+
focusAfterToggleRef.current = false;
|
|
405
|
+
if (listOpen) {
|
|
406
|
+
firstItemRef.current?.focus();
|
|
407
|
+
} else {
|
|
408
|
+
expandListRef.current?.focus();
|
|
382
409
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
410
|
+
}
|
|
411
|
+
}, [listOpen]);
|
|
412
|
+
const toggleList = () => {
|
|
413
|
+
const now = Date.now();
|
|
414
|
+
if (now - lastToggleRef.current > TOGGLE_DEBOUNCE_MS) {
|
|
415
|
+
lastToggleRef.current = now;
|
|
416
|
+
focusAfterToggleRef.current = true;
|
|
417
|
+
setListOpen(open => !open);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
const getCustomSuggestions = () => {
|
|
421
|
+
const customSuggestions = [{
|
|
422
|
+
name: translate('add-place'),
|
|
423
|
+
selectedIconId: 'favourite'
|
|
424
|
+
}];
|
|
425
|
+
if (favourites.length === 0) {
|
|
426
|
+
return customSuggestions;
|
|
427
|
+
}
|
|
428
|
+
return [...customSuggestions, {
|
|
429
|
+
name: translate('edit'),
|
|
430
|
+
selectedIconId: 'edit'
|
|
431
|
+
}];
|
|
432
|
+
};
|
|
433
|
+
const suggestionSelected = index => {
|
|
434
|
+
if (index < listFavourites.length) {
|
|
435
|
+
onClickFavourite(listFavourites[index]);
|
|
436
|
+
} else if (index === listFavourites.length) {
|
|
437
|
+
onAddPlace();
|
|
438
|
+
} else if (index === listFavourites.length + 1) {
|
|
439
|
+
onEdit();
|
|
440
|
+
}
|
|
441
|
+
toggleList();
|
|
442
|
+
};
|
|
443
|
+
const handleKeyDown = (event, index) => {
|
|
444
|
+
const key = event && (event.key || event.which || event.keyCode) || '';
|
|
445
|
+
if (isKeyboardSelectionEvent(event)) {
|
|
446
|
+
if (!listOpen) {
|
|
447
|
+
toggleList();
|
|
448
|
+
} else {
|
|
449
|
+
suggestionSelected(index);
|
|
405
450
|
}
|
|
406
|
-
})
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
return /*#__PURE__*/React.createElement("li", {
|
|
410
|
-
key: `favourite-suggestion-item-${index}`
|
|
411
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
412
|
-
role: "button",
|
|
413
|
-
type: "button",
|
|
414
|
-
tabIndex: "0",
|
|
415
|
-
id: id,
|
|
416
|
-
className: cx(styles['favourite-suggestion-item']),
|
|
417
|
-
onClick: () => this.suggestionSelected(index),
|
|
418
|
-
onKeyDown: e => this.handleKeyDown(e, index),
|
|
419
|
-
ref: index === 0 ? this.firstItemRef : ''
|
|
420
|
-
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
421
|
-
,
|
|
422
|
-
autoFocus: index === 0,
|
|
423
|
-
"aria-label": `${item?.name || ''} ${item?.address || ''} ${ariaLabelSuffix}`
|
|
424
|
-
}, /*#__PURE__*/React.createElement(SuggestionItem, {
|
|
425
|
-
item: item,
|
|
426
|
-
colors: this.props.colors,
|
|
427
|
-
fontWeights: this.props.fontWeights
|
|
428
|
-
})));
|
|
429
|
-
});
|
|
430
|
-
_defineProperty(this, "getCustomSuggestions", () => {
|
|
431
|
-
const customSuggestions = [{
|
|
432
|
-
name: this.translate('add-place'),
|
|
433
|
-
selectedIconId: 'favourite'
|
|
434
|
-
}];
|
|
435
|
-
if (this.props.favourites.length === 0) {
|
|
436
|
-
return customSuggestions;
|
|
451
|
+
} else if (key === 'Escape' || key === 27) {
|
|
452
|
+
if (listOpen) {
|
|
453
|
+
toggleList();
|
|
437
454
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
selectedIconId: 'edit'
|
|
441
|
-
}];
|
|
442
|
-
});
|
|
443
|
-
this.state = {
|
|
444
|
-
listOpen: false,
|
|
445
|
-
firstFavourite: props.favourites[0] || null,
|
|
446
|
-
secondFavourite: props.favourites[1] || null,
|
|
447
|
-
favourites: props.favourites.slice(2, props.favourites.length),
|
|
448
|
-
timestamp: 0,
|
|
449
|
-
listMaxHeight: null
|
|
450
|
-
};
|
|
451
|
-
this.expandListRef = /*#__PURE__*/React.createRef();
|
|
452
|
-
this.suggestionListRef = /*#__PURE__*/React.createRef();
|
|
453
|
-
this.firstItemRef = /*#__PURE__*/React.createRef();
|
|
454
|
-
}
|
|
455
|
-
componentDidMount() {
|
|
456
|
-
document.addEventListener('mousedown', this.handleClickOutside);
|
|
457
|
-
window.addEventListener('resize', this.updateListMaxHeight);
|
|
458
|
-
}
|
|
459
|
-
static getDerivedStateFromProps(nextProps, prevState) {
|
|
460
|
-
const {
|
|
461
|
-
favourites
|
|
462
|
-
} = prevState;
|
|
463
|
-
const nextFavourites = nextProps.favourites;
|
|
464
|
-
if (!isEmpty(differenceWith(nextFavourites, favourites, isEqual)) || !isEmpty(differenceWith(favourites, nextFavourites, isEqual)) || !isEqual(nextFavourites, favourites) || isEmpty(nextFavourites)) {
|
|
465
|
-
return {
|
|
466
|
-
firstFavourite: nextFavourites[0] || null,
|
|
467
|
-
secondFavourite: nextFavourites[1] || null,
|
|
468
|
-
favourites: nextFavourites.slice(2, nextFavourites.length)
|
|
469
|
-
};
|
|
455
|
+
} else if (key === 'Tab' && !event.shiftKey && index === listFavourites.length + getCustomSuggestions().length - 1) {
|
|
456
|
+
setListOpen(false);
|
|
470
457
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}
|
|
477
|
-
render() {
|
|
478
|
-
const {
|
|
479
|
-
onClickFavourite,
|
|
480
|
-
isLoading,
|
|
481
|
-
fontWeights
|
|
482
|
-
} = this.props;
|
|
483
|
-
const {
|
|
484
|
-
primary
|
|
485
|
-
} = this.props.colors;
|
|
486
|
-
const {
|
|
487
|
-
listOpen,
|
|
488
|
-
favourites,
|
|
489
|
-
firstFavourite,
|
|
490
|
-
secondFavourite,
|
|
491
|
-
listMaxHeight
|
|
492
|
-
} = this.state;
|
|
493
|
-
const expandIcon = this.props.favourites.length === 0 ? 'plus' : 'arrow';
|
|
494
|
-
const [name1, address1] = formatFavourite(firstFavourite);
|
|
495
|
-
const [name2, address2] = formatFavourite(secondFavourite);
|
|
496
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
497
|
-
style: {
|
|
498
|
-
'--font-weight-medium': fontWeights.medium
|
|
499
|
-
}
|
|
458
|
+
};
|
|
459
|
+
const renderSuggestion = (item, index, ariaLabelSuffix = '') => {
|
|
460
|
+
const id = `favourite-suggestion-list--item-${index}`;
|
|
461
|
+
return /*#__PURE__*/React.createElement("li", {
|
|
462
|
+
key: `favourite-suggestion-item-${index}`
|
|
500
463
|
}, /*#__PURE__*/React.createElement("div", {
|
|
501
|
-
|
|
502
|
-
}, /*#__PURE__*/React.createElement(FavouriteLocation, {
|
|
503
|
-
text: name1 || this.translate('add-home'),
|
|
504
|
-
label: address1 || '',
|
|
505
|
-
clickItem: () => firstFavourite ? onClickFavourite(firstFavourite) : this.props.onAddHome(),
|
|
506
|
-
iconId: firstFavourite && firstFavourite.selectedIconId ? FavouriteBar.FavouriteIconIdToNameMap[firstFavourite.selectedIconId] : 'home',
|
|
507
|
-
isLoading: isLoading,
|
|
508
|
-
color: primary,
|
|
509
|
-
lang: this.props.lang
|
|
510
|
-
}), /*#__PURE__*/React.createElement(FavouriteLocation, {
|
|
511
|
-
text: name2 || this.translate('add-work'),
|
|
512
|
-
label: address2 || '',
|
|
513
|
-
clickItem: () => secondFavourite ? onClickFavourite(secondFavourite) : this.props.onAddWork(),
|
|
514
|
-
iconId: secondFavourite && secondFavourite.selectedIconId ? FavouriteBar.FavouriteIconIdToNameMap[secondFavourite.selectedIconId] : 'work',
|
|
515
|
-
isLoading: isLoading,
|
|
516
|
-
color: primary,
|
|
517
|
-
lang: this.props.lang
|
|
518
|
-
}), /*#__PURE__*/React.createElement("button", {
|
|
464
|
+
role: "button",
|
|
519
465
|
type: "button",
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
466
|
+
tabIndex: "0",
|
|
467
|
+
id: id,
|
|
468
|
+
className: cx(styles['favourite-suggestion-item']),
|
|
469
|
+
onClick: () => suggestionSelected(index),
|
|
470
|
+
onKeyDown: e => handleKeyDown(e, index),
|
|
471
|
+
ref: index === 0 ? firstItemRef : undefined
|
|
472
|
+
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
473
|
+
,
|
|
474
|
+
autoFocus: index === 0,
|
|
475
|
+
"aria-label": `${item?.name || ''} ${item?.address || ''} ${ariaLabelSuffix}`
|
|
476
|
+
}, /*#__PURE__*/React.createElement(SuggestionItem, {
|
|
477
|
+
item: item,
|
|
478
|
+
colors: colors,
|
|
479
|
+
fontWeights: fontWeights
|
|
480
|
+
})));
|
|
481
|
+
};
|
|
482
|
+
const {
|
|
483
|
+
primary
|
|
484
|
+
} = colors;
|
|
485
|
+
const expandIcon = favourites.length === 0 ? 'plus' : 'arrow';
|
|
486
|
+
const [name1, address1] = formatFavourite(firstFavourite);
|
|
487
|
+
const [name2, address2] = formatFavourite(secondFavourite);
|
|
488
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
489
|
+
style: {
|
|
490
|
+
'--font-weight-medium': fontWeights.medium
|
|
491
|
+
}
|
|
492
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
493
|
+
className: styles['favourite-container']
|
|
494
|
+
}, /*#__PURE__*/React.createElement(FavouriteLocation, {
|
|
495
|
+
text: name1 || translate('add-home'),
|
|
496
|
+
label: address1 || '',
|
|
497
|
+
clickItem: () => firstFavourite ? onClickFavourite(firstFavourite) : onAddHome(),
|
|
498
|
+
iconId: firstFavourite && firstFavourite.selectedIconId ? FAVOURITE_ICON_ID_TO_NAME[firstFavourite.selectedIconId] : 'home',
|
|
499
|
+
isLoading: isLoading,
|
|
500
|
+
color: primary,
|
|
501
|
+
lang: lang
|
|
502
|
+
}), /*#__PURE__*/React.createElement(FavouriteLocation, {
|
|
503
|
+
text: name2 || translate('add-work'),
|
|
504
|
+
label: address2 || '',
|
|
505
|
+
clickItem: () => secondFavourite ? onClickFavourite(secondFavourite) : onAddWork(),
|
|
506
|
+
iconId: secondFavourite && secondFavourite.selectedIconId ? FAVOURITE_ICON_ID_TO_NAME[secondFavourite.selectedIconId] : 'work',
|
|
507
|
+
isLoading: isLoading,
|
|
508
|
+
color: primary,
|
|
509
|
+
lang: lang
|
|
510
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
511
|
+
type: "button",
|
|
512
|
+
className: cx(styles.expandButton, styles[expandIcon], listOpen && styles.rotate),
|
|
513
|
+
ref: expandListRef,
|
|
514
|
+
id: "favourite-expand-button",
|
|
515
|
+
onKeyDown: e => handleKeyDown(e),
|
|
516
|
+
onClick: toggleList,
|
|
517
|
+
"aria-expanded": listOpen,
|
|
518
|
+
"aria-label": translate('open-favourites')
|
|
519
|
+
}, /*#__PURE__*/React.createElement(Shimmer, {
|
|
520
|
+
active: isLoading
|
|
521
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
522
|
+
img: expandIcon,
|
|
523
|
+
color: primary
|
|
524
|
+
})))), /*#__PURE__*/React.createElement("div", {
|
|
525
|
+
className: styles['favourite-suggestion-container']
|
|
526
|
+
}, listOpen && /*#__PURE__*/React.createElement("ul", {
|
|
527
|
+
className: styles['favourite-suggestion-list'],
|
|
528
|
+
id: "favourite-suggestion-list",
|
|
529
|
+
style: listMaxHeight ? {
|
|
530
|
+
maxHeight: listMaxHeight
|
|
531
|
+
} : undefined,
|
|
532
|
+
ref: suggestionListRef,
|
|
533
|
+
"aria-label": translate('favourites-list')
|
|
534
|
+
}, listFavourites.map((item, index) => {
|
|
535
|
+
const favouriteLabel = formatFavouritePlaceLabel(item.name, item.address);
|
|
536
|
+
const address = favouriteLabel[1];
|
|
537
|
+
return renderSuggestion(_objectSpread(_objectSpread({}, item), {}, {
|
|
538
|
+
address
|
|
539
|
+
}), index, `, ${translate('add-destination')}`);
|
|
540
|
+
}), listFavourites.length > 0 && /*#__PURE__*/React.createElement("div", {
|
|
541
|
+
"aria-hidden": true,
|
|
542
|
+
className: styles.divider
|
|
543
|
+
}), getCustomSuggestions().map((item, index) => renderSuggestion(item, listFavourites.length + index, undefined)))));
|
|
553
544
|
}
|
|
554
|
-
_defineProperty(FavouriteBar, "defaultProps", {
|
|
555
|
-
onClickFavourite: () => ({}),
|
|
556
|
-
onAddPlace: () => ({}),
|
|
557
|
-
onEdit: () => ({}),
|
|
558
|
-
onAddHome: () => ({}),
|
|
559
|
-
onAddWork: () => ({}),
|
|
560
|
-
lang: 'fi',
|
|
561
|
-
isLoading: false,
|
|
562
|
-
colors: defaultColors,
|
|
563
|
-
fontWeights: {
|
|
564
|
-
medium: 500
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
_defineProperty(FavouriteBar, "FavouriteIconIdToNameMap", {
|
|
568
|
-
'icon-icon_place': 'place',
|
|
569
|
-
'icon-icon_home': 'home',
|
|
570
|
-
'icon-icon_work': 'work',
|
|
571
|
-
'icon-icon_sport': 'sport',
|
|
572
|
-
'icon-icon_school': 'school',
|
|
573
|
-
'icon-icon_shopping': 'shopping',
|
|
574
|
-
// Map two buggy ids temporarily. This code can be removed at some point.
|
|
575
|
-
icon_home: 'home',
|
|
576
|
-
icon_work: 'work'
|
|
577
|
-
});
|
|
578
545
|
process.env.NODE_ENV !== "production" ? FavouriteBar.propTypes = {
|
|
579
546
|
/** Required. Array of favourites, favourite object contains following properties.
|
|
580
547
|
* @type {Array<object>}
|
|
@@ -597,16 +564,16 @@ process.env.NODE_ENV !== "production" ? FavouriteBar.propTypes = {
|
|
|
597
564
|
selectedIconId: PropTypes.string,
|
|
598
565
|
favouriteId: PropTypes.string
|
|
599
566
|
})).isRequired,
|
|
600
|
-
/**
|
|
601
|
-
onClickFavourite: PropTypes.func,
|
|
602
|
-
/**
|
|
603
|
-
onAddPlace: PropTypes.func,
|
|
604
|
-
/**
|
|
605
|
-
onEdit: PropTypes.func,
|
|
606
|
-
/**
|
|
607
|
-
onAddHome: PropTypes.func,
|
|
608
|
-
/**
|
|
609
|
-
onAddWork: PropTypes.func,
|
|
567
|
+
/** Required. Function for clicking favourites. */
|
|
568
|
+
onClickFavourite: PropTypes.func.isRequired,
|
|
569
|
+
/** Required. Function for selecting "Add place" from suggestions. */
|
|
570
|
+
onAddPlace: PropTypes.func.isRequired,
|
|
571
|
+
/** Required. Function for selected "Edit" from suggestions. */
|
|
572
|
+
onEdit: PropTypes.func.isRequired,
|
|
573
|
+
/** Required. Function for "Add home" button. */
|
|
574
|
+
onAddHome: PropTypes.func.isRequired,
|
|
575
|
+
/** Required. Function for "Add work" button. */
|
|
576
|
+
onAddWork: PropTypes.func.isRequired,
|
|
610
577
|
/** Optional. Language, fi, en or sv. */
|
|
611
578
|
lang: PropTypes.string,
|
|
612
579
|
/** Optional. Whether to show loading animation, true or false. */
|
|
@@ -617,14 +584,8 @@ process.env.NODE_ENV !== "production" ? FavouriteBar.propTypes = {
|
|
|
617
584
|
fontWeights: PropTypes.shape({
|
|
618
585
|
/** Default value is 500. */
|
|
619
586
|
medium: PropTypes.number
|
|
620
|
-
})
|
|
621
|
-
/** Translation function */
|
|
622
|
-
t: PropTypes.func.isRequired
|
|
587
|
+
})
|
|
623
588
|
} : void 0;
|
|
624
|
-
const FavouriteBarWithTranslation = withTranslation()(FavouriteBar);
|
|
625
|
-
var index = props => /*#__PURE__*/React.createElement(I18nextProvider, {
|
|
626
|
-
i18n: i18n
|
|
627
|
-
}, /*#__PURE__*/React.createElement(FavouriteBarWithTranslation, props));
|
|
628
589
|
|
|
629
|
-
export {
|
|
590
|
+
export { FavouriteBar as default };
|
|
630
591
|
//# sourceMappingURL=index.js.map
|