2019-08-07 10:57:54 +00:00
|
|
|
import React from "react";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import styled from "styled-components";
|
2020-03-11 14:18:47 +00:00
|
|
|
import { utils, Scrollbar, ProgressBar } from "asc-web-components";
|
2019-12-20 11:35:53 +00:00
|
|
|
const { tablet } = utils.device;
|
2019-07-20 09:48:29 +00:00
|
|
|
|
|
|
|
const StyledSectionBody = styled.div`
|
2019-07-29 12:51:56 +00:00
|
|
|
${props => props.displayBorder && `outline: 1px dotted;`}
|
2019-07-20 09:48:29 +00:00
|
|
|
flex-grow: 1;
|
2019-09-10 12:41:52 +00:00
|
|
|
height: 100%;
|
2020-01-17 10:54:07 +00:00
|
|
|
|
|
|
|
${props => props.withScroll && `
|
|
|
|
margin-left: -24px;
|
|
|
|
`}
|
2020-03-11 14:18:47 +00:00
|
|
|
|
|
|
|
.sectionWrapper {
|
|
|
|
flex: 1 0 auto;
|
|
|
|
padding: 16px 8px 16px 24px;
|
|
|
|
outline: none;
|
|
|
|
|
|
|
|
@media ${tablet} {
|
|
|
|
padding: 16px 0 16px 24px;
|
|
|
|
}
|
|
|
|
}
|
2019-12-25 14:51:38 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledSectionWrapper = styled.div`
|
2020-03-11 14:18:47 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
min-height: 100%;
|
2019-12-23 13:41:52 +00:00
|
|
|
|
2020-03-11 14:18:47 +00:00
|
|
|
.layout-progress-bar {
|
|
|
|
flex: 0 0 auto;
|
|
|
|
margin-right: -16px;
|
2019-12-23 13:41:52 +00:00
|
|
|
}
|
2019-07-20 09:48:29 +00:00
|
|
|
`;
|
|
|
|
|
2019-11-14 12:13:54 +00:00
|
|
|
const StyledSpacer = styled.div`
|
|
|
|
display: none;
|
|
|
|
min-height: 64px;
|
|
|
|
|
|
|
|
@media ${tablet} {
|
|
|
|
display: ${props => (props.pinned ? "none" : "block")};
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2020-01-24 08:23:12 +00:00
|
|
|
class SectionBody extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2019-07-20 09:48:29 +00:00
|
|
|
|
2020-01-24 08:23:12 +00:00
|
|
|
this.focusRef = React.createRef();
|
2020-03-11 14:18:47 +00:00
|
|
|
this.ref = React.createRef();
|
2020-01-24 08:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
if (!this.props.autoFocus) return;
|
|
|
|
|
|
|
|
this.focusRef.current.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
//console.log("PageLayout SectionBody render");
|
2020-04-28 08:58:09 +00:00
|
|
|
const { children, withScroll, autoFocus, pinned, showProgressBar, progressBarValue, progressBarDropDownContent, progressBarLabel } = this.props;
|
2020-01-24 08:23:12 +00:00
|
|
|
|
|
|
|
const focusProps = autoFocus ? {
|
|
|
|
ref: this.focusRef,
|
|
|
|
tabIndex: 1
|
|
|
|
} : {};
|
|
|
|
|
2020-03-11 14:18:47 +00:00
|
|
|
const width = this.ref.current && this.ref.current.offsetWidth;
|
|
|
|
|
2020-01-24 08:23:12 +00:00
|
|
|
return (
|
2020-03-11 14:18:47 +00:00
|
|
|
<StyledSectionBody ref={this.ref} withScroll={withScroll}>
|
2020-01-24 08:23:12 +00:00
|
|
|
{withScroll ? (
|
|
|
|
<Scrollbar stype="mediumBlack">
|
2020-03-11 14:18:47 +00:00
|
|
|
<StyledSectionWrapper>
|
|
|
|
<div className="sectionWrapper" {...focusProps}>
|
|
|
|
{children}
|
|
|
|
<StyledSpacer pinned={pinned}/>
|
|
|
|
</div>
|
|
|
|
{showProgressBar && (
|
|
|
|
<ProgressBar
|
|
|
|
className="layout-progress-bar"
|
|
|
|
label={progressBarLabel}
|
2020-04-28 08:58:09 +00:00
|
|
|
percent={progressBarValue}
|
2020-03-11 14:18:47 +00:00
|
|
|
width={width}
|
|
|
|
dropDownContent={progressBarDropDownContent}
|
|
|
|
/>
|
|
|
|
)}
|
2020-01-24 08:23:12 +00:00
|
|
|
</StyledSectionWrapper>
|
|
|
|
</Scrollbar>
|
|
|
|
) : (
|
2020-01-27 10:58:37 +00:00
|
|
|
<StyledSectionWrapper>
|
2019-12-25 14:51:38 +00:00
|
|
|
{children}
|
|
|
|
<StyledSpacer pinned={pinned}/>
|
|
|
|
</StyledSectionWrapper>
|
2020-01-24 08:23:12 +00:00
|
|
|
)}
|
|
|
|
</StyledSectionBody>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-07-20 09:48:29 +00:00
|
|
|
|
2019-09-10 12:41:52 +00:00
|
|
|
SectionBody.displayName = "SectionBody";
|
|
|
|
|
2019-08-07 10:57:54 +00:00
|
|
|
SectionBody.propTypes = {
|
2019-09-10 12:41:52 +00:00
|
|
|
withScroll: PropTypes.bool,
|
2020-01-24 08:23:12 +00:00
|
|
|
autoFocus: PropTypes.bool,
|
2019-11-14 12:13:54 +00:00
|
|
|
pinned: PropTypes.bool,
|
2020-03-11 14:18:47 +00:00
|
|
|
showProgressBar: PropTypes.bool,
|
|
|
|
progressBarValue: PropTypes.number,
|
|
|
|
progressBarLabel: PropTypes.string,
|
|
|
|
progressBarDropDownContent: PropTypes.any,
|
2019-09-10 12:41:52 +00:00
|
|
|
children: PropTypes.oneOfType([
|
|
|
|
PropTypes.arrayOf(PropTypes.node),
|
2019-09-12 12:15:22 +00:00
|
|
|
PropTypes.node,
|
|
|
|
PropTypes.any
|
2019-09-10 12:41:52 +00:00
|
|
|
])
|
2019-08-07 10:57:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SectionBody.defaultProps = {
|
2019-11-14 12:13:54 +00:00
|
|
|
withScroll: true,
|
2020-01-24 08:23:12 +00:00
|
|
|
autoFocus: false,
|
2019-11-14 12:13:54 +00:00
|
|
|
pinned: false
|
2019-08-07 10:57:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default SectionBody;
|