77 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-07-24 17:13:48 -04:00
import React from 'react';
import styled, { css } from 'react-emotion';
2018-07-24 17:13:48 -04:00
import Icon from './Icon';
import { colors, buttons } from './styles';
const TopBarContainer = styled.div`
align-items: center;
background-color: ${colors.textFieldBorder};
display: flex;
justify-content: space-between;
margin: 0 -14px;
padding: 13px;
`;
2018-07-24 17:13:48 -04:00
const ExpandButtonContainer = styled.div`
${props =>
props.hasHeading &&
css`
display: flex;
align-items: center;
font-size: 14px;
font-weight: 500;
line-height: 1;
`};
`;
2018-07-24 17:13:48 -04:00
const ExpandButton = styled.button`
${buttons.button};
padding: 4px;
background-color: transparent;
color: inherit;
&:last-of-type {
margin-right: 4px;
}
`;
2018-07-24 17:13:48 -04:00
const AddButton = styled.button`
${buttons.button};
display: flex;
justify-content: center;
align-items: center;
padding: 2px 12px;
font-size: 12px;
font-weight: bold;
border-radius: 3px;
${Icon} {
margin-left: 6px;
}
`;
2018-07-24 17:13:48 -04:00
const ObjectWidgetTopBar = ({
allowAdd,
onAdd,
onCollapseToggle,
collapsed,
heading = null,
label,
}) => (
2018-07-24 17:13:48 -04:00
<TopBarContainer>
<ExpandButtonContainer hasHeading={!!heading}>
<ExpandButton onClick={onCollapseToggle}>
<Icon type="chevron" direction={collapsed ? 'right' : 'down'} size="small" />
</ExpandButton>
{heading}
</ExpandButtonContainer>
{!allowAdd ? null : (
2018-07-24 17:13:48 -04:00
<AddButton onClick={onAdd}>
Add {label} <Icon type="add" size="xsmall" />
</AddButton>
)}
2018-07-24 17:13:48 -04:00
</TopBarContainer>
);
export default ObjectWidgetTopBar;