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

feat(ui): Add HoverCard component #2084

Merged
merged 8 commits into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
36,212 changes: 28,599 additions & 7,613 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Storyshots UI/HoverCard Default 1`] = `
<div>
<Component />
<IconSprite
height="16"
style={
Object {
"height": 0,
"position": "absolute",
"width": 0,
}
}
width="16"
/>
</div>
`;

exports[`Storyshots UI/HoverCard With Render Fn 1`] = `
<div>
<Component />
<IconSprite
height="16"
style={
Object {
"height": 0,
"position": "absolute",
"width": 0,
}
}
width="16"
/>
</div>
`;
21 changes: 21 additions & 0 deletions packages/ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"generate-svg-sprite": "npx svg-sprite -s --si --no-svg-namespace-classnames src/assets/icons/*.svg && mv symbol/svg/sprite.symbol.svg src/assets/icons.svg",
"lint": "../../node_modules/.bin/eslint . --ext .jsx,.js",
"start": "cross-env NODE_ENV=development start-storybook -c ./build/storybook -p 8080",
"test": "npm run test:unit && npm run test:storyshots",
"test": "npm run test:unit",
"test:unit": "jest src --passWithNoTests",
"test:storyshots": "jest build/storybook ",
"chromatic": "chromatic --exit-zero-on-changes"
Expand Down Expand Up @@ -86,10 +86,10 @@
},
"dependencies": {
"@bundle-stats/utils": "^3.2.5",
"ariakit": "2.0.0-alpha.18",
"date-fns": "2.28.0",
"modern-css-reset": "1.4.0",
"query-string": "7.1.1",
"reakit": "1.3.11",
"use-query-params": "1.2.3"
}
}
74 changes: 38 additions & 36 deletions packages/ui/src/components/bundle-assets/bundle-assets.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import I18N from '../../i18n';
import { FlexStack } from '../../layout/flex-stack';
import { Icon } from '../../ui/icon';
import { FileName } from '../../ui/file-name';
import { Popover } from '../../ui/popover';
import { HoverCard } from '../../ui/hover-card';
import { Tooltip } from '../../ui/tooltip';
import { Tag } from '../../ui/tag';
import { Filters } from '../../ui/filters';
Expand Down Expand Up @@ -83,40 +83,42 @@ const getRenderRowHeader =
const { label, isNotPredictive, runs, isChunk, isEntry, isInitial } = item;

return (
<Popover
label={<FileName name={label} />}
icon={
<div className={css.assetInfoFlags}>
{isNotPredictive && (
<Tooltip className={css.notPredictive} title={<TooltipNotPredictive runs={runs} />}>
<Icon className={css.notPredictiveIcon} glyph="warning" />
</Tooltip>
)}
{isChunk && (
<Tag
title="Chunk"
size={Tag.SIZES.SMALL}
kind={Tag.KINDS.INFO}
className={cx(css.tag, css.tagChunk)}
/>
)}
{isEntry && (
<Tag
title="Entrypoint"
size={Tag.SIZES.SMALL}
kind={Tag.KINDS.INFO}
className={cx(css.tag, css.tagEntry)}
/>
)}
{isInitial && (
<Tag
title="Initial"
size={Tag.SIZES.SMALL}
kind={Tag.KINDS.INFO}
className={cx(css.tag, css.tagInitial)}
/>
)}
</div>
<HoverCard
label={
<FlexStack space="xxxsmall" className={css.assetName}>
<div className={css.assetInfoFlags}>
{isNotPredictive && (
<Tooltip className={css.notPredictive} title={<TooltipNotPredictive runs={runs} />}>
<Icon className={css.notPredictiveIcon} glyph="warning" />
</Tooltip>
)}
{isChunk && (
<Tag
title="Chunk"
size={Tag.SIZES.SMALL}
kind={Tag.KINDS.INFO}
className={cx(css.tag, css.tagChunk)}
/>
)}
{isEntry && (
<Tag
title="Entrypoint"
size={Tag.SIZES.SMALL}
kind={Tag.KINDS.INFO}
className={cx(css.tag, css.tagEntry)}
/>
)}
{isInitial && (
<Tag
title="Initial"
size={Tag.SIZES.SMALL}
kind={Tag.KINDS.INFO}
className={cx(css.tag, css.tagInitial)}
/>
)}
</div>
<FileName name={label} />
</FlexStack>
}
>
<AssetInfo
Expand All @@ -126,7 +128,7 @@ const getRenderRowHeader =
chunks={chunks}
CustomComponentLink={CustomComponentLink}
/>
</Popover>
</HoverCard>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
margin-right: -1px; /** collapse border */
}

.assetName {
display: inline-flex;
align-items: center;
}

.notPredictive {
margin-right: var(--space-xxsmall);
display: inline-block;
Expand Down
38 changes: 24 additions & 14 deletions packages/ui/src/components/bundle-modules/bundle-modules.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { FlexStack } from '../../layout/flex-stack';
import { EmptySet } from '../../ui/empty-set';
import { FileName } from '../../ui/file-name';
import { Filters } from '../../ui/filters';
import { Popover } from '../../ui/popover';
import { HoverCard } from '../../ui/hover-card';
import { SortDropdown } from '../../ui/sort-dropdown';
import { Toolbar } from '../../ui/toolbar';
import { MetricsTable } from '../metrics-table';
Expand All @@ -37,22 +37,22 @@ const RowHeader = ({ row, chunks, labels, CustomComponentLink }) => {

return (
<div onMouseEnter={handleOnMouseEnter}>
{!showPopopver ?
{!showPopopver ? (
content
: (
<Popover ariaLabel="View module info" label={content}>
{({ popoverToggle }) => (
) : (
<HoverCard label={content}>
{({ close }) => (
<ModuleInfo
className={css.namePopover}
item={row}
chunks={chunks}
chunkIds={chunkIds}
labels={labels}
customComponentLink={CustomComponentLink}
onClick={popoverToggle}
onClick={close}
/>
)}
</Popover>
</HoverCard>
)}
</div>
);
Expand All @@ -76,9 +76,17 @@ RowHeader.defaultProps = {
chunks: [],
};

const getRenderRowHeader = ({ labels, chunks, CustomComponentLink }) => (row) => (
<RowHeader row={row} chunks={chunks} labels={labels} CustomComponentLink={CustomComponentLink} />
);
const getRenderRowHeader =
({ labels, chunks, CustomComponentLink }) =>
(row) =>
(
<RowHeader
row={row}
chunks={chunks}
labels={labels}
CustomComponentLink={CustomComponentLink}
/>
);

export const BundleModules = ({
className,
Expand Down Expand Up @@ -240,10 +248,12 @@ BundleModules.propTypes = {
jobs: PropTypes.array, // eslint-disable-line react/forbid-prop-types

/** Chunks data */
chunks: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string,
name: PropTypes.string,
})).isRequired,
chunks: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string,
name: PropTypes.string,
}),
).isRequired,

/** total row count */
totalRowCount: PropTypes.number,
Expand Down
14 changes: 11 additions & 3 deletions packages/ui/src/components/bundle-packages/bundle-packages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Stack } from '../../layout/stack';
import { FlexStack } from '../../layout/flex-stack';
import { EmptySet } from '../../ui/empty-set';
import { Filters } from '../../ui/filters';
import { Popover } from '../../ui/popover';
import { HoverCard } from '../../ui/hover-card';
import { SortDropdown } from '../../ui/sort-dropdown';
import { Tag } from '../../ui/tag';
import { Toolbar } from '../../ui/toolbar';
Expand Down Expand Up @@ -116,15 +116,23 @@ const PackageRowHeader = ({ item, CustomComponentLink }) => {
);

return (
<Popover className={css.packageName} icon={duplicateFlag} label={packageName}>
<HoverCard
className={css.packageName}
label={
<FlexStack space="xxxsmall" className={css.packageNameLabel}>
{duplicateFlag}
<span>{packageName}</span>
</FlexStack>
}
>
<PackagePopoverContent
name={packageName}
path={path}
fullName={item.label}
duplicate={item.duplicate}
CustomComponentLink={CustomComponentLink}
/>
</Popover>
</HoverCard>
);
})}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
color: var(--color-text-ultra-light);
}

.packageNameLabel {
align-items: center;
}

.packagePopover {
min-width: 320px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,33 @@ import cx from 'classnames';
import I18N from '../../i18n';
import { FlexStack } from '../../layout/flex-stack';
import { Stack } from '../../layout/stack';
import { Popover } from '../../ui/popover';
import { Icon } from '../../ui/icon';
import { HoverCard } from '../../ui/hover-card';
import css from './metrics-table-title.module.css';

export const MetricsTableTitle = (props) => {
const { className, title, info, popoverInfo, popoverHref } = props;
const rootClassName = cx(css.root, className);

return (
<Stack space="xxxsmall" className={rootClassName}>
<FlexStack space="xxxsmall">
<span>{title}</span>
{info && <span className={css.info}>{info}</span>}
{(popoverInfo || popoverHref) && (
<Popover icon="help">
<Stack space="xxxsmall">
{popoverInfo && <p>{popoverInfo}</p>}
{popoverHref && (
<p>
<a href={popoverHref} target="_blank" rel="noreferrer">
{I18N.READ_MORE}
</a>
</p>
)}
</Stack>
</Popover>
)}
</FlexStack>
</Stack>
<FlexStack space="xxxsmall" className={rootClassName}>
<span>{title}</span>
{info && <span className={css.info}>{info}</span>}
{(popoverInfo || popoverHref) && (
<HoverCard label={<Icon glyph="help" />}>
<Stack space="xxxsmall">
{popoverInfo && <p>{popoverInfo}</p>}
{popoverHref && (
<p>
<a href={popoverHref} target="_blank" rel="noreferrer">
{I18N.READ_MORE}
</a>
</p>
)}
</Stack>
</HoverCard>
)}
</FlexStack>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.root {
align-items: center;
font-weight: bold;
line-height: var(--space-small);
text-transform: uppercase;
color: var(--color-text-light);
}
Expand Down
6 changes: 1 addition & 5 deletions packages/ui/src/components/module-info/module-info.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ export const ModuleInfo = (props) => {
</div>
)}

<FileName
className={css.fileName}
as="code"
name={run?.name || '-'}
/>
<FileName className={css.fileName} as="code" name={run?.name || '-'} />
</Stack>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
}

.fileName {
max-width: 100%;
padding: 2px;
background: var(--color-highlight-warning);
}
Loading