-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
140 lines (129 loc) · 3.2 KB
/
index.js
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import React, { Fragment, useEffect, useState } from 'react'
import classNames from 'classnames'
import PropTypes from 'prop-types'
import { ExtensionPoint, useRuntime } from 'vtex.render-runtime'
import TopMenu from './components/TopMenu'
import Spacer from './components/Helpers/Spacer'
import { logo, collapsible, icons, searchBar, login } from './defaults'
import styles from './store-header.css'
import useDevice from './hooks/useDevice'
/**
* Main header component
*/
const Header = ({
leanWhen,
linkUrl,
logoUrl,
logoTitle,
logoSize,
showSearchBar,
showLogin,
iconClasses,
labelClasses,
collapsibleAnimation,
}) => {
const { page, getSettings } = useRuntime()
const { mobile } = useDevice()
const [containerHeight, setContainerHeight] = useState(null)
const { storeName } = getSettings('vtex.store')
useEffect(() => {
if (document) {
const containerElement = document.querySelector(
'.vtex-store-header-2-x-container'
)
const elementHeight = containerElement && containerElement.offsetHeight
setContainerHeight(elementHeight)
}
})
const topMenuOptions = {
linkUrl,
logoUrl,
logoTitle: logoTitle || storeName || '',
logoSize,
showSearchBar,
showLogin,
iconClasses,
labelClasses,
collapsibleAnimation,
mobile,
}
const isLeanMode = () => {
const acceptedPaths = new RegExp(leanWhen)
return acceptedPaths.test(page)
}
const containerClasses = classNames(
styles.container,
'fixed top-0 z-4 w-100',
isLeanMode() ? styles.leanMode : ''
)
return (
<Fragment>
<div className={containerClasses}>
<TopMenu
{...topMenuOptions}
leanMode={isLeanMode()}
extraHeaders={
<div
className="left-0 w-100"
style={{
transform: 'translateZ(0)', //Avoid shaking
}}
>
<ExtensionPoint id="telemarketing" />
<ExtensionPoint id="menu-link" />
</div>
}
/>
</div>
<Spacer containerHeight={containerHeight} />
</Fragment>
)
}
Header.propTypes = {
/** Cases in which the menu is in lean mode */
leanWhen: PropTypes.string,
...login.propTypes,
...searchBar.propTypes,
...icons.propTypes,
...logo.propTypes,
...collapsible.propTypes,
}
Header.defaultProps = {
leanWhen: 'a^',
...login.defaultProps,
...searchBar.defaultProps,
...icons.defaultProps,
...logo.defaultProps,
...collapsible.defaultProps,
}
Header.schema = {
title: 'admin/editor.header.title',
description: 'admin/editor.header.description',
type: 'object',
properties: {
logoUrl: {
type: 'string',
title: 'admin/editor.header.logo.image',
widget: {
'ui:widget': 'image-uploader',
},
},
linkUrl: {
type: 'string',
title: 'admin/editor.header.link.url',
},
showSearchBar: {
title: 'admin/editor.header.show.searchbar.title',
type: 'boolean',
default: true,
isLayout: true,
},
showLogin: {
title: 'admin/editor.header.show.login.title',
type: 'boolean',
default: true,
isLayout: true,
},
},
}
export default Header