Skip to content

Commit

Permalink
fix(ui): SummaryItem - use HoverCard
Browse files Browse the repository at this point in the history
  • Loading branch information
vio committed Feb 27, 2022
1 parent 3d58ee1 commit 40ce2f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 45 deletions.
50 changes: 24 additions & 26 deletions packages/ui/src/components/summary-item/summary-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,34 @@ import PropTypes from 'prop-types';
import cx from 'classnames';
import { getGlobalMetricType, getMetricRunInfo } from '@bundle-stats/utils';

import { Popover } from '../../ui/popover';
import { HoverCard } from '../../ui/hover-card';
import { Icon } from '../../ui/icon';
import { Skeleton } from '../../ui/skeleton';
import { Stack } from '../../layout/stack';
import { FlexStack } from '../../layout/flex-stack';
import { Metric } from '../metric';
import { Delta } from '../delta';
import css from './summary-item.module.css';

const MetricInfoPopover = ({ description, url }) => {
// Workaround cases where the parent is a link
const readMoreOnClick = () => {
window.open(url);
};

return (
<Stack space="xxxsmall">
<p>{description}</p>
{url && (
<p>
<button type="button" className={css.readMoreBtn} onClick={readMoreOnClick}>
Read more
</button>
</p>
)}
</Stack>
);
};

MetricInfoPopover.propTypes = {
const MetricInfo = ({ description, url }) => (
<Stack space="xxxsmall">
<p>{description}</p>
{url && (
<p>
<a href={url} className={css.readMoreLink}>
Read more
</a>
</p>
)}
</Stack>
);

MetricInfo.propTypes = {
description: PropTypes.string.isRequired,
url: PropTypes.string,
};

MetricInfoPopover.defaultProps = {
MetricInfo.defaultProps = {
url: '',
};

Expand Down Expand Up @@ -65,9 +59,13 @@ export const SummaryItem = ({
<span>{metric.label}</span>

{showMetricDescriptionTooltip && (
<Popover className={css.icon} icon="help">
<MetricInfoPopover {...metric} />
</Popover>
<HoverCard
className={css.icon}
href={metric.url}
hoverContent={<MetricInfo {...metric} />}
>
<Icon glyph="help" />
</HoverCard>
)}
</FlexStack>

Expand Down
19 changes: 0 additions & 19 deletions packages/ui/src/components/summary-item/summary-item.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,6 @@
white-space: nowrap;
}

.readMoreBtn {
appearance: none;
padding: 0;
border: 0;
background: none;
cursor: pointer;
/* simulate link */
color: var(--color-primary);
text-decoration: underline;
line-height: var(--space-small);
}

.readMoreBtn:hover,
.readMoreBtn:active,
.readMoreBtn:focus {
color: var(--color-primary-dark);
text-decoration: none;
}

.currentMetric {
display: block;
color: var(--color-heading);
Expand Down

0 comments on commit 40ce2f4

Please sign in to comment.