|
1 | 1 | import PropTypes from 'prop-types'; |
2 | 2 | import React from 'react'; |
3 | | -import { intlShape } from 'react-intl'; |
4 | | -import { configShape } from '../util/shapes'; |
| 3 | +import { FormattedMessage } from 'react-intl'; |
5 | 4 | import Icon from './Icon'; |
| 5 | +import { useConfigContext } from '../configurations/ConfigContext'; |
| 6 | +import { useTranslationsContext } from '../util/useTranslationsContext'; |
6 | 7 |
|
7 | | -export default function SelectFromMapHeaderComponent(props, { config, intl }) { |
8 | | - const title = |
9 | | - props.titleId !== undefined |
10 | | - ? intl.formatMessage({ |
11 | | - id: props.titleId, |
12 | | - defaultMessage: 'Select viaPoint', |
13 | | - }) |
14 | | - : ''; |
15 | | - |
16 | | - const backBtnCursorPointerClassName = `${ |
17 | | - props.hideBackBtn ? 'no-pointer' : 'cursor-pointer' |
18 | | - }`; |
19 | | - const closeBtnCursorPointerClassName = `${ |
20 | | - props.hideCloseBtn ? 'no-pointer' : 'cursor-pointer' |
21 | | - }`; |
| 8 | +export default function SelectFromMapHeader(props) { |
| 9 | + const { colors } = useConfigContext(); |
| 10 | + const intl = useTranslationsContext(); |
22 | 11 |
|
23 | 12 | return ( |
24 | 13 | <div className="select-from-map-nav-container"> |
25 | | - <button |
26 | | - type="button" |
27 | | - className={`from-map-modal-nav-button ${backBtnCursorPointerClassName}`} |
28 | | - onClick={props.hideBackBtn ? undefined : props.onBackBtnClick} |
29 | | - aria-label={intl.formatMessage({ |
30 | | - id: 'back-button-title', |
31 | | - defaultMessage: 'Go back to previous page', |
32 | | - })} |
33 | | - > |
34 | | - {!props.hideBackBtn && ( |
35 | | - <Icon |
36 | | - img={props.backBtnIcon} |
37 | | - color={config.colors.primary} |
38 | | - className={`${props.iconClassName} ${backBtnCursorPointerClassName}`} |
39 | | - /> |
40 | | - )} |
41 | | - </button> |
42 | | - {title && !props.titleClassName && ( |
43 | | - <div className="select-from-map-nav-title">{title}</div> |
| 14 | + {!props.hideBackBtn && ( |
| 15 | + <button |
| 16 | + type="button" |
| 17 | + className="from-map-modal-nav-button" |
| 18 | + onClick={props.hideBackBtn ? undefined : props.onBackBtnClick} |
| 19 | + aria-label={intl.formatMessage({ |
| 20 | + id: 'back-button-title', |
| 21 | + defaultMessage: 'Go back to previous page', |
| 22 | + })} |
| 23 | + > |
| 24 | + <Icon img="icon_arrow-left" color={colors.primary} /> |
| 25 | + </button> |
44 | 26 | )} |
45 | | - {title && props.titleClassName && ( |
46 | | - <span className={props.titleClassName}>{title}</span> |
| 27 | + <div className="select-from-map-nav-title"> |
| 28 | + <FormattedMessage id={props.titleId} /> |
| 29 | + </div> |
| 30 | + {!props.hideCloseBtn && ( |
| 31 | + <button |
| 32 | + type="button" |
| 33 | + className="from-map-modal-nav-button" |
| 34 | + onClick={props.hideCloseBtn ? undefined : props.onCloseBtnClick} |
| 35 | + aria-label={intl.formatMessage({ |
| 36 | + id: 'back-button-title', |
| 37 | + defaultMessage: 'Go back to previous page', |
| 38 | + })} |
| 39 | + > |
| 40 | + <Icon img="icon_close" color={colors.primary} /> |
| 41 | + </button> |
47 | 42 | )} |
48 | | - <button |
49 | | - type="button" |
50 | | - className={`from-map-modal-nav-button ${closeBtnCursorPointerClassName}`} |
51 | | - onClick={props.hideCloseBtn ? undefined : props.onCloseBtnClick} |
52 | | - aria-label={intl.formatMessage({ |
53 | | - id: 'back-button-title', |
54 | | - defaultMessage: 'Go back to previous page', |
55 | | - })} |
56 | | - > |
57 | | - {!props.hideCloseBtn && ( |
58 | | - <Icon |
59 | | - img={props.closeBtnIcon} |
60 | | - color={config.colors.primary} |
61 | | - className={`${props.iconClassName} ${closeBtnCursorPointerClassName}`} |
62 | | - /> |
63 | | - )} |
64 | | - </button> |
65 | 43 | </div> |
66 | 44 | ); |
67 | 45 | } |
68 | 46 |
|
69 | | -SelectFromMapHeaderComponent.propTypes = { |
70 | | - titleId: PropTypes.string, |
| 47 | +SelectFromMapHeader.propTypes = { |
| 48 | + titleId: PropTypes.string.isRequired, |
71 | 49 | onBackBtnClick: PropTypes.func, |
72 | 50 | onCloseBtnClick: PropTypes.func, |
73 | | - backBtnIcon: PropTypes.string, |
74 | | - closeBtnIcon: PropTypes.string, |
75 | 51 | hideBackBtn: PropTypes.bool, |
76 | 52 | hideCloseBtn: PropTypes.bool, |
77 | | - titleClassName: PropTypes.string, |
78 | | - iconClassName: PropTypes.string, |
79 | 53 | }; |
80 | 54 |
|
81 | | -SelectFromMapHeaderComponent.defaultProps = { |
82 | | - titleId: undefined, |
83 | | - backBtnIcon: 'icon_arrow-left', |
84 | | - closeBtnIcon: 'icon_close', |
| 55 | +SelectFromMapHeader.defaultProps = { |
85 | 56 | onBackBtnClick: PropTypes.func, |
86 | 57 | onCloseBtnClick: PropTypes.func, |
87 | 58 | hideBackBtn: false, |
88 | 59 | hideCloseBtn: false, |
89 | | - titleClassName: undefined, |
90 | | - iconClassName: undefined, |
91 | | -}; |
92 | | - |
93 | | -SelectFromMapHeaderComponent.contextTypes = { |
94 | | - config: configShape.isRequired, |
95 | | - intl: intlShape.isRequired, |
96 | 60 | }; |
0 commit comments