DocSpace-client/packages/asc-web-common/components/PageLayout/sub-components/section-header.js

152 lines
3.6 KiB
JavaScript
Raw Normal View History

import React from 'react';
import styled, { css } from 'styled-components';
import equal from 'fast-deep-equal/react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { LayoutContextConsumer } from 'studio/Layout/context';
import { isMobile } from 'react-device-detect';
import { tablet, desktop } from '@appserver/components/utils/device';
import NoUserSelect from '@appserver/components/utils/commonStyles';
const StyledSectionHeader = styled.div`
position: relative;
height: 41px;
margin-right: 24px;
margin-top: -1px;
${NoUserSelect}
2021-05-18 14:59:34 +00:00
${isMobile &&
css`
height: 20px;
/* height: 49px;
2021-05-18 14:59:34 +00:00
min-height: 48px;
max-height: 49px; */
width: ${(props) => !props.isLoaded && '100%'};
2021-05-18 14:59:34 +00:00
margin-top: 64px;
/* @media ${tablet} {
2021-05-18 14:59:34 +00:00
margin-top: 55px;
} */
2021-05-18 14:59:34 +00:00
`}
@media ${desktop} {
${(props) =>
(props.viewAs === "table" || props.viewAs === "tile") &&
"margin-left: -4px"};
}
2021-10-06 12:44:39 +00:00
@media ${tablet} {
${(props) =>
props.viewAs !== 'tablet' &&
2021-10-06 12:44:39 +00:00
css`
height: 49px;
2021-10-06 12:44:39 +00:00
.arrow-button {
svg {
width: 14px !important;
}
margin-right: 10px !important;
}
`}
}
@media ${tablet} {
margin-right: 16px;
}
.section-header {
2021-05-18 14:59:34 +00:00
${isMobile &&
css`
max-width: calc(100vw - 32px);
width: 100%;
`}
${isMobile &&
2021-05-18 14:59:34 +00:00
css`
position: fixed;
2021-10-06 09:22:28 +00:00
top: 48px;
width: ${(props) => (props.isArticlePinned ? `calc(100% - 272px)` : '100%')};
2021-05-18 14:59:34 +00:00
background-color: #fff;
z-index: 149;
padding-right: 16px;
`}
}
2021-05-18 14:59:34 +00:00
${isMobile &&
css`
.section-header,
.section-header--hidden {
&,
.group-button-menu-container > div:first-child {
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 {
padding-bottom: 0 !important;
> div:first-child {
top: ${(props) => (!props.isSectionHeaderVisible ? '56px' : '0px')} !important;
2020-11-17 08:36:49 +00:00
2021-05-18 14:59:34 +00:00
@media ${desktop} {
${isMobile &&
css`
position: absolute;
`}
}
}
}
}
2021-05-18 14:59:34 +00:00
`}
.section-header--hidden {
${isMobile &&
css`
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
2021-10-06 12:44:39 +00:00
const { isArticlePinned, isHeaderVisible, viewAs, ...rest } = this.props;
return (
<LayoutContextConsumer>
{(value) => (
<StyledSectionHeader
isArticlePinned={isArticlePinned}
isSectionHeaderVisible={value.isVisible}
viewAs={viewAs}>
2020-11-17 08:36:49 +00:00
<div
className={classnames('section-header hidingHeader', {
'section-header--hidden': value.isVisible === undefined ? false : !value.isVisible,
2021-01-26 15:21:50 +00:00
})}
2020-11-17 08:36:49 +00:00
{...rest}
/>
</StyledSectionHeader>
)}
</LayoutContextConsumer>
);
}
}
SectionHeader.displayName = 'SectionHeader';
2021-01-26 15:21:50 +00:00
SectionHeader.propTypes = {
isArticlePinned: PropTypes.bool,
isHeaderVisible: PropTypes.bool,
};
export default SectionHeader;