Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from vtex-apps/feature/future-header
Feature/future header
- Loading branch information
Showing
32 changed files
with
406 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Border from './components/Border' | ||
|
||
export default Border |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Layout from './components/Layout' | ||
|
||
export default Layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Row from './components/Row' | ||
|
||
export default Row |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Spacer from './components/Spacer' | ||
|
||
export default Spacer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import React from 'react' | ||
|
||
export default () => <div /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react' | ||
import { ExtensionPoint, useRuntime } from 'vtex.render-runtime' | ||
import Media from 'react-media' | ||
|
||
const CustomHeader = () => { | ||
const { hints: { mobile } } = useRuntime() | ||
|
||
if (!window || !window.matchMedia) { | ||
return mobile ? ( | ||
<ExtensionPoint id="unstable--header-layout.mobile" /> | ||
) : ( | ||
<ExtensionPoint id="unstable--header-layout.desktop" /> | ||
) | ||
} | ||
|
||
return ( | ||
<React.Fragment> | ||
<Media query="(max-width:40rem)"> | ||
{matches => matches ? ( | ||
<ExtensionPoint id="unstable--header-layout.mobile" /> | ||
) : ( | ||
<ExtensionPoint id="unstable--header-layout.desktop" /> | ||
)} | ||
</Media> | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
export default CustomHeader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
|
||
const Layout = ({ children }) => ( | ||
<React.Fragment> | ||
{children} | ||
</React.Fragment> | ||
) | ||
|
||
export default Layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react' | ||
import classNames from 'classnames' | ||
import { Container } from 'vtex.store-components' | ||
|
||
const Row = ({ children, fullWidth, sticky, inverted }) => { | ||
const content = ( | ||
<div className="w-100 flex items-center"> | ||
{children} | ||
</div> | ||
) | ||
|
||
return ( | ||
<div | ||
className={classNames('w-100 top-0', inverted ? 'bg-base--inverted c-on-base--inverted' : 'bg-base c-on-base', { 'z-999': sticky })} | ||
style={{ | ||
// TODO: use `sticky` class once it's available on render | ||
position: sticky ? 'sticky' : 'relative', | ||
}}> | ||
{fullWidth ? content : ( | ||
<Container className="w-100 flex"> | ||
{content} | ||
</Container> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default Row |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from "react" | ||
|
||
const Spacer = () => <div className="flex flex-grow-1" /> | ||
|
||
export default Spacer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +1,24 @@ | ||
import React, { Fragment, useEffect, useLayoutEffect, 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 React from 'react' | ||
import { useChildBlock__unstable } from 'vtex.render-runtime' | ||
import LegacyHeader from './legacy' | ||
import CustomHeader from './components/CustomHeader' | ||
|
||
import styles from './store-header.css' | ||
import useDevice from './hooks/useDevice' | ||
const Header = props => { | ||
const headerDesktop = !!useChildBlock__unstable({ id: 'unstable--header-layout.desktop' }) | ||
const headerMobile = !!useChildBlock__unstable({ id: 'unstable--header-layout.mobile' }) | ||
|
||
/** | ||
* 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 : '' | ||
) | ||
const hasCustomHeader = headerDesktop || headerMobile | ||
|
||
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> | ||
hasCustomHeader | ||
? <CustomHeader {...props} /> | ||
: <LegacyHeader {...props} /> | ||
) | ||
} | ||
|
||
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: 'editor.header.title', | ||
description: 'editor.header.description', | ||
type: 'object', | ||
properties: { | ||
logoUrl: { | ||
type: 'string', | ||
title: 'editor.header.logo.image', | ||
widget: { | ||
'ui:widget': 'image-uploader', | ||
}, | ||
}, | ||
linkUrl: { | ||
type: 'string', | ||
title: 'editor.header.link.url', | ||
}, | ||
showSearchBar: { | ||
title: 'editor.header.show.searchbar.title', | ||
type: 'boolean', | ||
default: true, | ||
isLayout: true, | ||
}, | ||
showLogin: { | ||
title: 'editor.header.show.login.title', | ||
type: 'boolean', | ||
default: true, | ||
isLayout: true, | ||
}, | ||
}, | ||
} | ||
|
||
export default Header |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.