2019-09-12 12:15:22 +00:00
|
|
|
import React from "react";
|
2020-11-19 13:34:34 +00:00
|
|
|
import styled, { css } from "styled-components";
|
2020-11-17 08:36:49 +00:00
|
|
|
import { utils } from "asc-web-components";
|
2020-12-08 11:09:46 +00:00
|
|
|
import equal from "fast-deep-equal/react";
|
2020-10-27 08:16:59 +00:00
|
|
|
import classnames from "classnames";
|
2020-11-19 14:53:12 +00:00
|
|
|
import { connect } from "react-redux";
|
|
|
|
import PropTypes from "prop-types";
|
2020-11-19 07:24:52 +00:00
|
|
|
import { LayoutContextConsumer } from "../../Layout/context";
|
2020-11-17 08:36:49 +00:00
|
|
|
|
2020-11-19 14:53:12 +00:00
|
|
|
import { getIsLoaded } from "../../../store/auth/selectors";
|
|
|
|
|
2019-12-23 13:41:52 +00:00
|
|
|
const { tablet } = utils.device;
|
2019-07-20 09:48:29 +00:00
|
|
|
|
|
|
|
const StyledSectionHeader = styled.div`
|
2019-09-12 12:15:22 +00:00
|
|
|
border-bottom: 1px solid #eceef1;
|
2020-10-26 10:53:42 +00:00
|
|
|
height: 55px;
|
2019-12-23 13:41:52 +00:00
|
|
|
margin-right: 24px;
|
2020-11-06 13:15:03 +00:00
|
|
|
margin-top: -1px;
|
2019-12-23 13:41:52 +00:00
|
|
|
|
|
|
|
@media ${tablet} {
|
|
|
|
margin-right: 16px;
|
2020-08-18 14:02:20 +00:00
|
|
|
border-bottom: none;
|
2020-11-26 13:24:57 +00:00
|
|
|
|
|
|
|
${(props) =>
|
2020-11-27 15:47:44 +00:00
|
|
|
props.isLoaded &&
|
|
|
|
css`
|
|
|
|
position: absolute;
|
|
|
|
top: 56px;
|
|
|
|
`}
|
2020-11-26 13:24:57 +00:00
|
|
|
|
2020-10-27 12:15:57 +00:00
|
|
|
${(props) =>
|
|
|
|
props.borderBottom &&
|
|
|
|
`
|
|
|
|
border-bottom: 1px solid #eceef1;
|
|
|
|
padding-bottom: 16px
|
|
|
|
`};
|
2020-10-26 10:53:42 +00:00
|
|
|
height: 49px;
|
2020-11-27 15:47:44 +00:00
|
|
|
width: ${(props) => !props.isLoaded && "100%"};
|
2019-12-23 13:41:52 +00:00
|
|
|
}
|
2020-01-15 12:58:57 +00:00
|
|
|
|
|
|
|
.section-header {
|
|
|
|
@media ${tablet} {
|
2020-11-25 10:30:12 +00:00
|
|
|
max-width: calc(100vw - 32px);
|
2020-11-27 15:47:44 +00:00
|
|
|
width: 100%;
|
2020-10-26 10:53:42 +00:00
|
|
|
padding-top: 4px;
|
2020-11-27 15:47:44 +00:00
|
|
|
${(props) =>
|
|
|
|
props.isLoaded &&
|
|
|
|
css`
|
|
|
|
position: fixed;
|
|
|
|
top: ${(props) => (!props.isHeaderVisible ? "56px" : "0")};
|
|
|
|
width: ${(props) =>
|
|
|
|
props.isArticlePinned ? `calc(100% - 272px)` : "100%"};
|
|
|
|
background-color: #fff;
|
|
|
|
z-index: 155;
|
|
|
|
padding-right: 16px;
|
|
|
|
`}
|
2020-01-15 12:58:57 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-02 08:55:59 +00:00
|
|
|
|
2020-11-17 08:36:49 +00:00
|
|
|
.section-header,
|
|
|
|
.section-header--hidden {
|
|
|
|
@media ${tablet} {
|
|
|
|
transition: top 0.3s cubic-bezier(0, 0, 0.8, 1);
|
|
|
|
-moz-transition: top 0.3s cubic-bezier(0, 0, 0.8, 1);
|
|
|
|
-ms-transition: top 0.3s cubic-bezier(0, 0, 0.8, 1);
|
|
|
|
-webkit-transition: top 0.3s cubic-bezier(0, 0, 0.8, 1);
|
|
|
|
-o-transition: top 0.3s cubic-bezier(0, 0, 0.8, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 08:55:59 +00:00
|
|
|
.section-header--hidden {
|
|
|
|
@media ${tablet} {
|
2020-11-11 09:09:19 +00:00
|
|
|
top: -61px;
|
2020-11-02 08:55:59 +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-11-17 08:36:49 +00:00
|
|
|
|
2020-10-26 07:31:04 +00:00
|
|
|
this.focusRef = React.createRef();
|
|
|
|
}
|
|
|
|
|
2020-08-11 12:35:24 +00:00
|
|
|
shouldComponentUpdate(nextProps) {
|
2020-12-08 11:09:46 +00:00
|
|
|
return !equal(this.props, nextProps);
|
2020-08-11 12:35:24 +00:00
|
|
|
}
|
2020-10-27 08:16:59 +00:00
|
|
|
|
2020-08-11 12:35:24 +00:00
|
|
|
render() {
|
|
|
|
//console.log("PageLayout SectionHeader render");
|
|
|
|
// eslint-disable-next-line react/prop-types
|
2020-11-11 07:13:03 +00:00
|
|
|
|
2020-11-17 08:36:49 +00:00
|
|
|
const {
|
|
|
|
isArticlePinned,
|
|
|
|
borderBottom,
|
|
|
|
isHeaderVisible,
|
2020-11-19 14:53:12 +00:00
|
|
|
dispatch,
|
2020-11-19 13:34:34 +00:00
|
|
|
isLoaded,
|
2020-11-17 08:36:49 +00:00
|
|
|
...rest
|
|
|
|
} = this.props;
|
2020-10-27 12:15:57 +00:00
|
|
|
|
2020-08-11 12:35:24 +00:00
|
|
|
return (
|
2020-10-27 12:15:57 +00:00
|
|
|
<StyledSectionHeader
|
2020-11-17 08:36:49 +00:00
|
|
|
isHeaderVisible={isHeaderVisible}
|
2020-10-27 12:15:57 +00:00
|
|
|
isArticlePinned={isArticlePinned}
|
|
|
|
borderBottom={borderBottom}
|
2020-11-19 13:34:34 +00:00
|
|
|
isLoaded={isLoaded}
|
2020-10-27 12:15:57 +00:00
|
|
|
>
|
2020-11-17 08:36:49 +00:00
|
|
|
<LayoutContextConsumer>
|
|
|
|
{(value) => (
|
|
|
|
<div
|
|
|
|
className={classnames("section-header", {
|
|
|
|
"section-header--hidden": !value.isVisible,
|
|
|
|
})}
|
|
|
|
{...rest}
|
|
|
|
/>
|
|
|
|
)}
|
2020-11-15 16:15:48 +00:00
|
|
|
</LayoutContextConsumer>
|
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";
|
2020-11-19 14:53:12 +00:00
|
|
|
SectionHeader.propTypes = {
|
|
|
|
isLoaded: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
return {
|
|
|
|
isLoaded: getIsLoaded(state),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
export default connect(mapStateToProps)(SectionHeader);
|