2020-06-16 20:38:43 +00:00
|
|
|
import React from 'react';
|
|
|
|
import styled from 'styled-components';
|
2020-06-30 22:11:48 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2020-06-16 20:38:43 +00:00
|
|
|
import { prop, remSize } from '../../theme';
|
|
|
|
|
2020-07-24 21:43:07 +00:00
|
|
|
|
|
|
|
const background = ({ transparent, inverted }) => prop(transparent === true
|
|
|
|
? 'backgroundColor'
|
|
|
|
: `MobilePanel.default.${inverted === true ? 'foreground' : 'background'}`);
|
|
|
|
|
|
|
|
const textColor = ({ transparent, inverted }) => prop((transparent === false && inverted === true)
|
|
|
|
? 'MobilePanel.default.background'
|
|
|
|
: 'primaryTextColor');
|
2020-06-16 20:38:43 +00:00
|
|
|
|
2020-06-30 22:11:48 +00:00
|
|
|
|
|
|
|
const HeaderDiv = styled.div`
|
2020-08-06 19:24:47 +00:00
|
|
|
${props => props.fixed && 'position: fixed;'}
|
2020-06-16 20:38:43 +00:00
|
|
|
width: 100%;
|
2020-07-24 21:43:07 +00:00
|
|
|
background: ${props => background(props)};
|
2020-06-16 20:38:43 +00:00
|
|
|
color: ${textColor};
|
2020-07-28 20:13:55 +00:00
|
|
|
padding: ${props => remSize(props.slim === true ? 2 : 12)};
|
2020-06-29 22:54:48 +00:00
|
|
|
padding-left: ${remSize(16)};
|
|
|
|
padding-right: ${remSize(16)};
|
2020-06-16 20:38:43 +00:00
|
|
|
z-index: 1;
|
|
|
|
|
|
|
|
display: flex;
|
|
|
|
flex: 1;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: center;
|
2020-06-29 22:54:48 +00:00
|
|
|
|
|
|
|
svg {
|
2020-06-30 22:11:48 +00:00
|
|
|
max-height: ${remSize(32)};
|
2020-07-28 20:13:55 +00:00
|
|
|
padding: ${remSize(4)};
|
2020-06-29 22:54:48 +00:00
|
|
|
}
|
2020-07-28 20:13:55 +00:00
|
|
|
|
|
|
|
& svg path { fill: ${textColor} !important; }
|
2020-08-12 13:55:54 +00:00
|
|
|
|
|
|
|
.editor__unsaved-changes svg {
|
|
|
|
width: ${remSize(16)};
|
2020-08-28 18:02:07 +00:00
|
|
|
padding: 0;
|
2020-08-12 13:55:54 +00:00
|
|
|
vertical-align: top
|
|
|
|
}
|
2020-06-16 20:38:43 +00:00
|
|
|
`;
|
|
|
|
|
2020-06-30 22:11:48 +00:00
|
|
|
const IconContainer = styled.div`
|
|
|
|
margin-left: ${props => (props.leftButton ? remSize(32) : remSize(4))};
|
2020-07-29 20:52:57 +00:00
|
|
|
list-style: none;
|
2020-06-30 22:11:48 +00:00
|
|
|
display: flex;
|
2020-07-29 20:52:57 +00:00
|
|
|
flex-direction: horizontal;
|
2020-06-30 22:11:48 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
const TitleContainer = styled.div`
|
|
|
|
margin-left: ${remSize(4)};
|
|
|
|
margin-right: auto;
|
|
|
|
|
|
|
|
${props => props.padded && `h2{
|
|
|
|
padding-top: ${remSize(10)};
|
|
|
|
padding-bottom: ${remSize(10)};
|
|
|
|
}`}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Header = ({
|
2020-07-28 20:13:55 +00:00
|
|
|
title, subtitle, leftButton, children,
|
2020-08-06 19:24:47 +00:00
|
|
|
transparent, inverted, slim, fixed
|
2020-06-30 22:11:48 +00:00
|
|
|
}) => (
|
2020-08-06 19:24:47 +00:00
|
|
|
<HeaderDiv transparent={transparent} slim={slim} inverted={inverted} fixed={fixed}>
|
2020-06-30 22:11:48 +00:00
|
|
|
{leftButton}
|
|
|
|
<TitleContainer padded={subtitle === null}>
|
|
|
|
{title && <h2>{title}</h2>}
|
|
|
|
{subtitle && <h3>{subtitle}</h3>}
|
|
|
|
</TitleContainer>
|
|
|
|
<IconContainer>
|
|
|
|
{children}
|
|
|
|
</IconContainer>
|
|
|
|
</HeaderDiv>
|
|
|
|
);
|
|
|
|
|
2020-08-13 21:29:39 +00:00
|
|
|
|
2020-06-30 22:11:48 +00:00
|
|
|
Header.propTypes = {
|
2020-08-13 21:29:39 +00:00
|
|
|
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
2020-06-30 22:11:48 +00:00
|
|
|
subtitle: PropTypes.string,
|
|
|
|
leftButton: PropTypes.element,
|
2020-07-01 20:36:25 +00:00
|
|
|
children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]),
|
2020-07-24 21:43:07 +00:00
|
|
|
transparent: PropTypes.bool,
|
2020-07-28 20:13:55 +00:00
|
|
|
inverted: PropTypes.bool,
|
|
|
|
slim: PropTypes.bool,
|
2020-08-06 19:24:47 +00:00
|
|
|
fixed: PropTypes.bool,
|
2020-06-30 22:11:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Header.defaultProps = {
|
|
|
|
title: null,
|
|
|
|
subtitle: null,
|
|
|
|
leftButton: null,
|
|
|
|
children: [],
|
2020-07-24 21:43:07 +00:00
|
|
|
transparent: false,
|
2020-07-28 20:13:55 +00:00
|
|
|
inverted: false,
|
2020-08-06 19:24:47 +00:00
|
|
|
slim: false,
|
|
|
|
fixed: true
|
2020-06-30 22:11:48 +00:00
|
|
|
};
|
|
|
|
|
2020-06-16 20:38:43 +00:00
|
|
|
export default Header;
|