2019-09-12 12:15:22 +00:00
|
|
|
import React from "react";
|
2020-02-10 14:34:56 +00:00
|
|
|
import styled from "styled-components";
|
2019-12-23 13:41:52 +00:00
|
|
|
import { utils } from "asc-web-components";
|
2020-08-11 12:35:24 +00:00
|
|
|
import isEqual from "lodash/isEqual";
|
2020-10-27 08:16:59 +00:00
|
|
|
import classnames from "classnames";
|
2020-08-11 12:35:24 +00:00
|
|
|
|
2019-12-23 13:41:52 +00:00
|
|
|
const { tablet } = utils.device;
|
2019-07-20 09:48:29 +00:00
|
|
|
|
|
|
|
const StyledSectionHeader = styled.div`
|
2020-10-26 07:31:04 +00:00
|
|
|
|
|
|
|
|
2019-09-12 12:15:22 +00:00
|
|
|
border-bottom: 1px solid #eceef1;
|
2019-07-20 09:48:29 +00:00
|
|
|
height: 56px;
|
2019-12-23 13:41:52 +00:00
|
|
|
margin-right: 24px;
|
|
|
|
|
|
|
|
@media ${tablet} {
|
|
|
|
margin-right: 16px;
|
2020-08-18 14:02:20 +00:00
|
|
|
border-bottom: none;
|
|
|
|
height: 44px;
|
2020-10-26 07:31:04 +00:00
|
|
|
|
2020-10-27 08:16:59 +00:00
|
|
|
|
2019-12-23 13:41:52 +00:00
|
|
|
}
|
2020-10-27 08:16:59 +00:00
|
|
|
.section-header--hidden {
|
|
|
|
@media ${tablet} {
|
|
|
|
top: -50px;
|
|
|
|
}
|
2020-01-15 12:58:57 +00:00
|
|
|
|
2020-10-27 08:16:59 +00:00
|
|
|
}
|
2020-01-15 12:58:57 +00:00
|
|
|
.section-header {
|
|
|
|
width: calc(100% - 76px);
|
|
|
|
|
|
|
|
@media ${tablet} {
|
2020-10-16 12:38:04 +00:00
|
|
|
width: 100%;
|
2020-10-27 08:16:59 +00:00
|
|
|
background-color: #fff;
|
|
|
|
position: fixed;
|
|
|
|
top: 56px;
|
|
|
|
padding-right:100%;
|
|
|
|
transition: top 0.3s;
|
|
|
|
z-index:1;
|
2020-01-15 12:58:57 +00:00
|
|
|
}
|
2020-01-16 09:25:28 +00:00
|
|
|
|
2020-10-16 12:38:04 +00:00
|
|
|
h1,
|
|
|
|
h2,
|
|
|
|
h3,
|
|
|
|
h4,
|
|
|
|
h5,
|
|
|
|
h6 {
|
2020-01-16 09:25:28 +00:00
|
|
|
max-width: calc(100vw - 435px);
|
|
|
|
|
|
|
|
@media ${tablet} {
|
2020-10-16 12:38:04 +00:00
|
|
|
max-width: ${(props) =>
|
|
|
|
props.isArticlePinned ? `calc(100vw - 320px)` : `calc(100vw - 96px)`};
|
2020-01-16 09:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-15 12:58:57 +00:00
|
|
|
}
|
2019-07-20 09:48:29 +00:00
|
|
|
`;
|
|
|
|
|
2020-08-11 12:35:24 +00:00
|
|
|
class SectionHeader extends React.Component {
|
2020-10-26 07:31:04 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-10-27 08:16:59 +00:00
|
|
|
this.state = {
|
|
|
|
prevScrollpos: window.pageYOffset || document.documentElement.scrollTop,
|
|
|
|
visible: true
|
|
|
|
};
|
2020-10-26 07:31:04 +00:00
|
|
|
this.focusRef = React.createRef();
|
|
|
|
}
|
|
|
|
|
2020-10-27 08:16:59 +00:00
|
|
|
componentDidMount() {
|
|
|
|
|
|
|
|
window.addEventListener("scroll", this.scrolledTheVerticalAxis);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
window.removeEventListener("scroll", this.scrolledTheVerticalAxis);
|
|
|
|
}
|
|
|
|
|
|
|
|
scrolledTheVerticalAxis = () => {
|
|
|
|
const { prevScrollpos } = this.state;
|
|
|
|
|
|
|
|
const currentScrollPos = window.pageYOffset || document.documentElement.scrollTop;
|
|
|
|
const visible = prevScrollpos > currentScrollPos;
|
|
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
prevScrollpos: currentScrollPos,
|
|
|
|
visible
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-08-11 12:35:24 +00:00
|
|
|
shouldComponentUpdate(nextProps) {
|
|
|
|
return !isEqual(this.props, nextProps);
|
|
|
|
}
|
2020-10-27 08:16:59 +00:00
|
|
|
|
2020-08-11 12:35:24 +00:00
|
|
|
render() {
|
2020-10-26 07:31:04 +00:00
|
|
|
|
2020-08-11 12:35:24 +00:00
|
|
|
//console.log("PageLayout SectionHeader render");
|
|
|
|
// eslint-disable-next-line react/prop-types
|
|
|
|
const { isArticlePinned, ...rest } = this.props;
|
|
|
|
return (
|
|
|
|
<StyledSectionHeader isArticlePinned={isArticlePinned}>
|
2020-10-27 08:16:59 +00:00
|
|
|
<div id="scroll" className={classnames("section-header" , {
|
|
|
|
"section-header--hidden": !this.state.visible
|
|
|
|
})} {...rest} />
|
2020-08-11 12:35:24 +00:00
|
|
|
</StyledSectionHeader>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-07-20 09:48:29 +00:00
|
|
|
|
2019-09-12 12:15:22 +00:00
|
|
|
SectionHeader.displayName = "SectionHeader";
|
|
|
|
|
|
|
|
export default SectionHeader;
|