Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Popovers to have close button #57

Merged
merged 4 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "es-components",
"version": "3.9.0",
"version": "3.10.0",
"description": "React components built for Exchange Solutions products",
"repository": "https://github.com/TWExchangeSolutions/es-components",
"main": "lib/index.js",
Expand Down
29 changes: 26 additions & 3 deletions src/components/containers/popover/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import styled from 'styled-components';
import { colors, sizes } from '../../theme';
import classNames from 'classnames';
import DismissButton from '../../controls/DismissButton';

const ArrowBase = styled.div`
border-color: transparent;
Expand Down Expand Up @@ -132,12 +133,26 @@ const PopoverTitle = styled.div`
background-color: ${colors.accent};
color: ${colors.white};
padding: 8px 14px;
flex-grow: 1;
`;

const PopoverBodyContent = styled.div`
padding: 9px 14px;
`;

const DismissPopover = styled(DismissButton)`
background-color: ${props => (props.hasTitle ? colors.accent : 'none')};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there are some discrepancies between the heights of the title and the close button that results in the title section background looking like this. I think the easiest fix would be to apply the background color to the PopoverHeader instead.

screen shot 2017-06-28 at 12 39 17 pm

color: ${props => (props.hasTitle ? colors.white : colors.grayDark)};
padding: ${props => (props.hasTitle ? '5px 14px' : '0px 14px')};
margin-left: auto;
`;

const PopoverHeader = styled.div`
display: flex;
justify-content: space-between;
height: ${props => (props.hasTitle || props.containsFormElement ? 'auto' : '7px')};
`;

// className, positionLeft and positionTop props get passed to by the Overlay component
const Popover = props => {
const {
Expand All @@ -147,7 +162,8 @@ const Popover = props => {
positionTop,
children,
containsFormElement,
className
className,
dismissPopover
} = props;

const popoverClassNames = classNames(className, arrowPlacement);
Expand All @@ -163,7 +179,13 @@ const Popover = props => {
positionTop={positionTop}
tabIndex={containsFormElement ? 0 : null}
>
{popoverTitle}
<PopoverHeader
hasTitle={hasTitle}
containsFormElement={containsFormElement}
>
{popoverTitle}
<DismissPopover hasTitle={hasTitle} onClick={dismissPopover} />
</PopoverHeader>
<PopoverBodyContent>
{children}
</PopoverBodyContent>
Expand All @@ -179,7 +201,8 @@ Popover.propTypes = {
positionTop: PropTypes.number,
children: PropTypes.node,
containsFormElement: PropTypes.bool,
className: PropTypes.string
className: PropTypes.string,
dismissPopover: PropTypes.func
};

Popover.defaultProps = {
Expand Down
1 change: 1 addition & 0 deletions src/components/containers/popover/PopoverTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function PopoverTrigger({
title={popoverTitle}
arrowPlacement={arrowPlacement}
containsFormElement={containsFormElement}
dismissPopover={onHideOverlay}
>
<FocusTrap
active={containsFormElement}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ exports[`popoverLink component renders as expected 1`] = `
<span>
<button
aria-haspopup="dialog"
className="sc-fjdhpX jzETuU sc-bZQynM kMNeGw sc-bwzfXH ebzKCJ"
className="sc-chPdSV gDBNOW sc-bZQynM kMNeGw sc-bwzfXH ebzKCJ"
data-trigger="focus"
onClick={[Function]}>
This is the popover link text.
Expand Down