DocSpace-buildtools/web/ASC.Web.Common/src/components/PageLayout/sub-components/section-header.js

152 lines
3.7 KiB
JavaScript
Raw Normal View History

import React from "react";
import styled, { css } from "styled-components";
2020-11-17 08:36:49 +00:00
import { utils } from "asc-web-components";
import equal from "fast-deep-equal/react";
import classnames from "classnames";
import { connect } from "react-redux";
import PropTypes from "prop-types";
import { LayoutContextConsumer } from "../../Layout/context";
2020-11-17 08:36:49 +00:00
import { getIsLoaded } from "../../../store/auth/selectors";
const { tablet } = utils.device;
const StyledSectionHeader = styled.div`
border-bottom: 1px solid #eceef1;
height: 55px;
margin-right: 24px;
margin-top: -1px;
@media ${tablet} {
margin-right: 16px;
2020-08-18 14:02:20 +00:00
border-bottom: none;
${(props) =>
props.isLoaded &&
css`
position: absolute;
top: 56px;
`}
${(props) =>
props.borderBottom &&
`
border-bottom: 1px solid #eceef1;
padding-bottom: 16px
`};
height: 49px;
width: ${(props) => !props.isLoaded && "100%"};
}
.section-header {
@media ${tablet} {
max-width: calc(100vw - 32px);
width: 100%;
//padding-top: 4px;
${(props) =>
props.isLoaded &&
css`
position: fixed;
top: 56px;
width: ${(props) =>
props.isArticlePinned ? `calc(100% - 272px)` : "100%"};
background-color: #fff;
z-index: ${(props) => (!props.isHeaderVisible ? "149" : "160")};
padding-right: 16px;
`}
}
}
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);
}
.group-button-menu-container {
& > div:first-child {
top: ${(props) =>
!props.isSectionHeaderVisible ? "56px" : "0px"} !important;
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-17 08:36:49 +00:00
}
.section-header--hidden {
@media ${tablet} {
2020-11-11 09:09:19 +00:00
top: -61px;
}
}
`;
class SectionHeader extends React.Component {
constructor(props) {
super(props);
2020-11-17 08:36:49 +00:00
this.focusRef = React.createRef();
}
shouldComponentUpdate(nextProps) {
return !equal(this.props, nextProps);
}
render() {
//console.log("PageLayout SectionHeader render");
// eslint-disable-next-line react/prop-types
2020-11-17 08:36:49 +00:00
const {
isArticlePinned,
borderBottom,
isHeaderVisible,
dispatch,
isLoaded,
2020-11-17 08:36:49 +00:00
...rest
} = this.props;
return (
<LayoutContextConsumer>
{(value) => (
<StyledSectionHeader
isHeaderVisible={isHeaderVisible}
isArticlePinned={isArticlePinned}
borderBottom={borderBottom}
isLoaded={isLoaded}
isSectionHeaderVisible={value.isVisible}
>
2020-11-17 08:36:49 +00:00
<div
className={classnames(
"section-header needToCancelAnimationWithTransition",
{
"section-header--hidden": !value.isVisible,
}
)}
2020-11-17 08:36:49 +00:00
{...rest}
/>
</StyledSectionHeader>
)}
</LayoutContextConsumer>
);
}
}
SectionHeader.displayName = "SectionHeader";
SectionHeader.propTypes = {
isLoaded: PropTypes.bool,
};
const mapStateToProps = (state) => {
return {
isLoaded: getIsLoaded(state),
};
};
export default connect(mapStateToProps)(SectionHeader);