@digitransit-component/digitransit-component-favourite-bar 6.0.4 → 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 +235 -252
- package/lib/index.js +233 -249
- 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
|
})}`;
|
|
@@ -316,242 +333,215 @@ process.env.NODE_ENV !== "production" ? FavouriteLocation.propTypes = {
|
|
|
316
333
|
* <FavouriteBar
|
|
317
334
|
* favourites={favourites}
|
|
318
335
|
* onClickFavourite={onClickFavourite}
|
|
319
|
-
* onAddPlace={
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
336
|
+
* onAddPlace={onAddPlace}
|
|
337
|
+
* onEdit={onEdit}
|
|
338
|
+
* onAddHome={onAddHome}
|
|
339
|
+
* onAddWork={onAddWork}
|
|
340
|
+
* lang={lang}
|
|
341
|
+
* isLoading={isLoading}
|
|
324
342
|
* />
|
|
325
343
|
*/
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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);
|
|
342
376
|
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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;
|
|
389
|
+
if (list) {
|
|
390
|
+
const {
|
|
391
|
+
top
|
|
392
|
+
} = list.getBoundingClientRect();
|
|
393
|
+
setListMaxHeight(Math.max(window.innerHeight - top - LIST_BOTTOM_MARGIN, MIN_LIST_HEIGHT));
|
|
354
394
|
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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();
|
|
366
409
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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);
|
|
389
450
|
}
|
|
390
|
-
})
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return /*#__PURE__*/React.createElement("li", {
|
|
394
|
-
key: `favourite-suggestion-item-${index}`
|
|
395
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
396
|
-
role: "button",
|
|
397
|
-
type: "button",
|
|
398
|
-
tabIndex: "0",
|
|
399
|
-
id: id,
|
|
400
|
-
className: cx(styles['favourite-suggestion-item']),
|
|
401
|
-
onClick: () => this.suggestionSelected(index),
|
|
402
|
-
onKeyDown: e => this.handleKeyDown(e, index),
|
|
403
|
-
ref: index === 0 ? this.firstItemRef : ''
|
|
404
|
-
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
405
|
-
,
|
|
406
|
-
autoFocus: index === 0,
|
|
407
|
-
"aria-label": `${item?.name || ''} ${item?.address || ''} ${ariaLabelSuffix}`
|
|
408
|
-
}, /*#__PURE__*/React.createElement(SuggestionItem, {
|
|
409
|
-
item: item,
|
|
410
|
-
colors: this.props.colors,
|
|
411
|
-
fontWeights: this.props.fontWeights
|
|
412
|
-
})));
|
|
413
|
-
});
|
|
414
|
-
_defineProperty(this, "getCustomSuggestions", () => {
|
|
415
|
-
const customSuggestions = [{
|
|
416
|
-
name: this.translate('add-place'),
|
|
417
|
-
selectedIconId: 'favourite'
|
|
418
|
-
}];
|
|
419
|
-
if (this.props.favourites.length === 0) {
|
|
420
|
-
return customSuggestions;
|
|
451
|
+
} else if (key === 'Escape' || key === 27) {
|
|
452
|
+
if (listOpen) {
|
|
453
|
+
toggleList();
|
|
421
454
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
selectedIconId: 'edit'
|
|
425
|
-
}];
|
|
426
|
-
});
|
|
427
|
-
this.state = {
|
|
428
|
-
listOpen: false,
|
|
429
|
-
firstFavourite: props.favourites[0] || null,
|
|
430
|
-
secondFavourite: props.favourites[1] || null,
|
|
431
|
-
favourites: props.favourites.slice(2, props.favourites.length),
|
|
432
|
-
timestamp: 0
|
|
433
|
-
};
|
|
434
|
-
this.expandListRef = /*#__PURE__*/React.createRef();
|
|
435
|
-
this.suggestionListRef = /*#__PURE__*/React.createRef();
|
|
436
|
-
this.firstItemRef = /*#__PURE__*/React.createRef();
|
|
437
|
-
}
|
|
438
|
-
componentDidMount() {
|
|
439
|
-
document.addEventListener('mousedown', this.handleClickOutside);
|
|
440
|
-
}
|
|
441
|
-
static getDerivedStateFromProps(nextProps, prevState) {
|
|
442
|
-
const {
|
|
443
|
-
favourites
|
|
444
|
-
} = prevState;
|
|
445
|
-
const nextFavourites = nextProps.favourites;
|
|
446
|
-
if (!isEmpty(differenceWith(nextFavourites, favourites, isEqual)) || !isEmpty(differenceWith(favourites, nextFavourites, isEqual)) || !isEqual(nextFavourites, favourites) || isEmpty(nextFavourites)) {
|
|
447
|
-
return {
|
|
448
|
-
firstFavourite: nextFavourites[0] || null,
|
|
449
|
-
secondFavourite: nextFavourites[1] || null,
|
|
450
|
-
favourites: nextFavourites.slice(2, nextFavourites.length)
|
|
451
|
-
};
|
|
455
|
+
} else if (key === 'Tab' && !event.shiftKey && index === listFavourites.length + getCustomSuggestions().length - 1) {
|
|
456
|
+
setListOpen(false);
|
|
452
457
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
render() {
|
|
459
|
-
const {
|
|
460
|
-
onClickFavourite,
|
|
461
|
-
isLoading,
|
|
462
|
-
fontWeights
|
|
463
|
-
} = this.props;
|
|
464
|
-
const {
|
|
465
|
-
primary
|
|
466
|
-
} = this.props.colors;
|
|
467
|
-
const {
|
|
468
|
-
listOpen,
|
|
469
|
-
favourites,
|
|
470
|
-
firstFavourite,
|
|
471
|
-
secondFavourite
|
|
472
|
-
} = this.state;
|
|
473
|
-
const expandIcon = this.props.favourites.length === 0 ? 'plus' : 'arrow';
|
|
474
|
-
const [name1, address1] = formatFavourite(firstFavourite);
|
|
475
|
-
const [name2, address2] = formatFavourite(secondFavourite);
|
|
476
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
477
|
-
style: {
|
|
478
|
-
'--font-weight-medium': fontWeights.medium
|
|
479
|
-
}
|
|
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}`
|
|
480
463
|
}, /*#__PURE__*/React.createElement("div", {
|
|
481
|
-
|
|
482
|
-
}, /*#__PURE__*/React.createElement(FavouriteLocation, {
|
|
483
|
-
text: name1 || this.translate('add-home'),
|
|
484
|
-
label: address1 || '',
|
|
485
|
-
clickItem: () => firstFavourite ? onClickFavourite(firstFavourite) : this.props.onAddHome(),
|
|
486
|
-
iconId: firstFavourite && firstFavourite.selectedIconId ? FavouriteBar.FavouriteIconIdToNameMap[firstFavourite.selectedIconId] : 'home',
|
|
487
|
-
isLoading: isLoading,
|
|
488
|
-
color: primary,
|
|
489
|
-
lang: this.props.lang
|
|
490
|
-
}), /*#__PURE__*/React.createElement(FavouriteLocation, {
|
|
491
|
-
text: name2 || this.translate('add-work'),
|
|
492
|
-
label: address2 || '',
|
|
493
|
-
clickItem: () => secondFavourite ? onClickFavourite(secondFavourite) : this.props.onAddWork(),
|
|
494
|
-
iconId: secondFavourite && secondFavourite.selectedIconId ? FavouriteBar.FavouriteIconIdToNameMap[secondFavourite.selectedIconId] : 'work',
|
|
495
|
-
isLoading: isLoading,
|
|
496
|
-
color: primary,
|
|
497
|
-
lang: this.props.lang
|
|
498
|
-
}), /*#__PURE__*/React.createElement("button", {
|
|
464
|
+
role: "button",
|
|
499
465
|
type: "button",
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
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)))));
|
|
530
544
|
}
|
|
531
|
-
_defineProperty(FavouriteBar, "defaultProps", {
|
|
532
|
-
onClickFavourite: () => ({}),
|
|
533
|
-
onAddPlace: () => ({}),
|
|
534
|
-
onEdit: () => ({}),
|
|
535
|
-
onAddHome: () => ({}),
|
|
536
|
-
onAddWork: () => ({}),
|
|
537
|
-
lang: 'fi',
|
|
538
|
-
isLoading: false,
|
|
539
|
-
colors: defaultColors,
|
|
540
|
-
fontWeights: {
|
|
541
|
-
medium: 500
|
|
542
|
-
}
|
|
543
|
-
});
|
|
544
|
-
_defineProperty(FavouriteBar, "FavouriteIconIdToNameMap", {
|
|
545
|
-
'icon-icon_place': 'place',
|
|
546
|
-
'icon-icon_home': 'home',
|
|
547
|
-
'icon-icon_work': 'work',
|
|
548
|
-
'icon-icon_sport': 'sport',
|
|
549
|
-
'icon-icon_school': 'school',
|
|
550
|
-
'icon-icon_shopping': 'shopping',
|
|
551
|
-
// Map two buggy ids temporarily. This code can be removed at some point.
|
|
552
|
-
icon_home: 'home',
|
|
553
|
-
icon_work: 'work'
|
|
554
|
-
});
|
|
555
545
|
process.env.NODE_ENV !== "production" ? FavouriteBar.propTypes = {
|
|
556
546
|
/** Required. Array of favourites, favourite object contains following properties.
|
|
557
547
|
* @type {Array<object>}
|
|
@@ -574,16 +564,16 @@ process.env.NODE_ENV !== "production" ? FavouriteBar.propTypes = {
|
|
|
574
564
|
selectedIconId: PropTypes.string,
|
|
575
565
|
favouriteId: PropTypes.string
|
|
576
566
|
})).isRequired,
|
|
577
|
-
/**
|
|
578
|
-
onClickFavourite: PropTypes.func,
|
|
579
|
-
/**
|
|
580
|
-
onAddPlace: PropTypes.func,
|
|
581
|
-
/**
|
|
582
|
-
onEdit: PropTypes.func,
|
|
583
|
-
/**
|
|
584
|
-
onAddHome: PropTypes.func,
|
|
585
|
-
/**
|
|
586
|
-
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,
|
|
587
577
|
/** Optional. Language, fi, en or sv. */
|
|
588
578
|
lang: PropTypes.string,
|
|
589
579
|
/** Optional. Whether to show loading animation, true or false. */
|
|
@@ -594,14 +584,8 @@ process.env.NODE_ENV !== "production" ? FavouriteBar.propTypes = {
|
|
|
594
584
|
fontWeights: PropTypes.shape({
|
|
595
585
|
/** Default value is 500. */
|
|
596
586
|
medium: PropTypes.number
|
|
597
|
-
})
|
|
598
|
-
/** Translation function */
|
|
599
|
-
t: PropTypes.func.isRequired
|
|
587
|
+
})
|
|
600
588
|
} : void 0;
|
|
601
|
-
const FavouriteBarWithTranslation = withTranslation()(FavouriteBar);
|
|
602
|
-
var index = props => /*#__PURE__*/React.createElement(I18nextProvider, {
|
|
603
|
-
i18n: i18n
|
|
604
|
-
}, /*#__PURE__*/React.createElement(FavouriteBarWithTranslation, props));
|
|
605
589
|
|
|
606
|
-
export {
|
|
590
|
+
export { FavouriteBar as default };
|
|
607
591
|
//# sourceMappingURL=index.js.map
|