forked from paypal/paypal-messaging-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeader.jsx
More file actions
124 lines (119 loc) · 5.03 KB
/
Header.jsx
File metadata and controls
124 lines (119 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/** @jsx h */
import { Fragment, h } from 'preact';
import { useState } from 'preact/hooks';
import { isLander, useServerData, useTransitionState, useScroll, currencyFormat } from '../lib';
import Icon from './Icon';
const Header = ({
headline,
subheadline,
isQualifying = 'false',
qualifyingSubheadline,
closeButtonLabel = 'Close',
viewName,
useV4Design,
useV5Design,
use5Dot1Design
}) => {
const { country } = useServerData();
const [, handleClose] = useTransitionState();
const [isScrolled, setScrolled] = useState(false);
useScroll(
({ target: { scrollTop } }) => {
if (!isScrolled && scrollTop > 0) {
setScrolled(true);
} else if (isScrolled && scrollTop <= 0) {
setScrolled(false);
}
},
[isScrolled]
);
// Used to specifically target styles to a specific country
const countryClassName = country?.toLowerCase();
// IMPORTANT: These elements cannot be nested inside of other elements.
// They are using very precise CSS position sticky rules that require this
// specific adjacent DOM structure
return (
<Fragment>
<div aria-hidden="true" className="header__fixed-wrapper header__fixed-wrapper--front">
<div
className={`header__background-wrapper header__background-wrapper--gradient ${
useV4Design ? 'v4Design' : ''
} ${useV5Design ? 'v5Design' : ''}`}
/>
</div>
<div aria-hidden="true" className="header__fixed-wrapper">
<div
className={`header__background-wrapper ${useV4Design ? 'v4Design' : ''} ${
useV5Design ? 'v5Design' : ''
}`}
/>
</div>
<div className="header__icons">
<div className={`logo__wrapper ${isScrolled ? 'logo__wrapper--scroll' : ''}`}>
<div className="pp-logo">
<Icon name={useV5Design ? 'logo_v5' : 'logo'} />
</div>
</div>
{!isLander && (
// We don't need to render an 'x' button if the target is a lander since you will close via a
// merchant-provided close button from their own iframe, or by closing the window in the case of a webpage.
<button
className={`close ${useV5Design ? 'v5Design' : ''}`}
aria-label={closeButtonLabel}
type="button"
id="close-btn"
aria-keyshortcuts="escape"
onClick={() => handleClose('Close Button')}
>
<Icon name={useV5Design ? 'close_v5' : 'close'} />
</button>
)}
<div className="header__fixed-wrapper header__fixed-wrapper--front">
<div
className={`header__background-wrapper header__background-wrapper--sticky ${
useV4Design ? 'v4Design' : ''
} ${useV5Design ? 'v5Design' : ''}`}
/>
</div>
</div>
<div className="header__content">
{!useV5Design && (
<div>
<Icon name={`${viewName}-desktop`} />
<Icon name={`${viewName}-mobile`} />
{/* <Icon name="background-pp-mobile" /> */}
</div>
)}
<h2
// id used for aria-labelleby on modal container element
id="header__headline"
className={`headline-${countryClassName} ${useV5Design ? 'v5Design' : ''} ${
use5Dot1Design ? 'headline-new' : ''
}`}
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: headline }}
/>
{isQualifying === 'true' && qualifyingSubheadline !== '' ? (
<p
className={`subheadline_p subheadline-${countryClassName} qualifying ${
useV5Design ? 'v5Design' : ''
}`}
>
{qualifyingSubheadline.replace(/(\s?EUR)/g, ' €')}
</p>
) : (
<p
className={`subheadline_p subheadline-${countryClassName} ${useV5Design ? 'v5Design' : ''} ${
country === 'DE' ? 'DE' : ''
}`}
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: currencyFormat(subheadline) ?? ''
}}
/>
)}
</div>
</Fragment>
);
};
export default Header;