@bundle-stats/ui 4.2.5-beta.1 → 4.2.5-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/bundle-assets-totals-chart-bars/bundle-assets-totals-chart-bars.js +2 -8
- package/lib/components/bundle-assets-totals-chart-bars/bundle-assets-totals-chart-bars.js.map +1 -1
- package/lib/components/index.js +3 -1
- package/lib/components/index.js.map +1 -1
- package/lib/components/metric-run-info/metric-run-info.js +47 -33
- package/lib/components/metric-run-info/metric-run-info.js.map +1 -1
- package/lib/components/metric-run-info/metric-run-info.module.css +14 -36
- package/lib/components/metrics-table-title/metrics-table-title.module.css +1 -0
- package/lib/components/run-info/index.js +18 -0
- package/lib/components/run-info/index.js.map +1 -0
- package/lib/components/run-info/run-info.js +45 -0
- package/lib/components/run-info/run-info.js.map +1 -0
- package/lib/components/run-info/run-info.module.css +41 -0
- package/lib/components/summary/summary.js +3 -43
- package/lib/components/summary/summary.js.map +1 -1
- package/lib-esm/components/bundle-assets-totals-chart-bars/bundle-assets-totals-chart-bars.js +2 -8
- package/lib-esm/components/bundle-assets-totals-chart-bars/bundle-assets-totals-chart-bars.js.map +1 -1
- package/lib-esm/components/index.js +1 -0
- package/lib-esm/components/index.js.map +1 -1
- package/lib-esm/components/metric-run-info/metric-run-info.js +24 -33
- package/lib-esm/components/metric-run-info/metric-run-info.js.map +1 -1
- package/lib-esm/components/metric-run-info/metric-run-info.module.css +14 -36
- package/lib-esm/components/metrics-table-title/metrics-table-title.module.css +1 -0
- package/lib-esm/components/run-info/index.js +2 -0
- package/lib-esm/components/run-info/index.js.map +1 -0
- package/lib-esm/components/run-info/run-info.js +38 -0
- package/lib-esm/components/run-info/run-info.js.map +1 -0
- package/lib-esm/components/run-info/run-info.module.css +41 -0
- package/lib-esm/components/summary/summary.js +4 -21
- package/lib-esm/components/summary/summary.js.map +1 -1
- package/package.json +6 -6
- package/src/components/bundle-assets-totals-chart-bars/bundle-assets-totals-chart-bars.jsx +5 -10
- package/src/components/index.js +1 -0
- package/src/components/metric-run-info/metric-run-info.module.css +14 -36
- package/src/components/metric-run-info/metric-run-info.stories.tsx +13 -29
- package/src/components/metric-run-info/metric-run-info.tsx +52 -86
- package/src/components/metrics-table-title/metrics-table-title.module.css +1 -0
- package/src/components/run-info/index.ts +1 -0
- package/src/components/run-info/run-info.module.css +41 -0
- package/src/components/run-info/run-info.stories.tsx +49 -0
- package/src/components/run-info/run-info.tsx +100 -0
- package/src/components/summary/summary.tsx +14 -41
- package/types/components/index.d.ts +1 -0
- package/types/components/metric-run-info/metric-run-info.d.ts +9 -11
- package/types/components/run-info/index.d.ts +1 -0
- package/types/components/run-info/run-info.d.ts +14 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, Story } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import { RunInfo } from './run-info';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Components/RunInfo',
|
|
8
|
+
component: RunInfo,
|
|
9
|
+
} as Meta;
|
|
10
|
+
|
|
11
|
+
const Template: Story = (args) => <RunInfo id="webpack.totalSizeByTypeALL" {...args} />;
|
|
12
|
+
|
|
13
|
+
export const Default = Template.bind({});
|
|
14
|
+
|
|
15
|
+
Default.args = {
|
|
16
|
+
title: 'Bundle Size',
|
|
17
|
+
current: '120KiB',
|
|
18
|
+
baseline: '100KiB',
|
|
19
|
+
delta: '+20%',
|
|
20
|
+
deltaType: 'HIGH_NEGATIVE',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const SizeLarge = Template.bind({});
|
|
24
|
+
|
|
25
|
+
SizeLarge.args = {
|
|
26
|
+
...Default.args,
|
|
27
|
+
size: 'large',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const TitleHoverCard = Template.bind({});
|
|
31
|
+
|
|
32
|
+
TitleHoverCard.args = {
|
|
33
|
+
...Default.args,
|
|
34
|
+
titleHoverCard: 'Info',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const TitleTooltip = Template.bind({});
|
|
38
|
+
|
|
39
|
+
TitleTooltip.args = {
|
|
40
|
+
...Default.args,
|
|
41
|
+
titleTooltip: 'Info',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const Loading = Template.bind({});
|
|
45
|
+
|
|
46
|
+
Loading.args = {
|
|
47
|
+
title: 'Bundle Size',
|
|
48
|
+
loading: true,
|
|
49
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import cx from 'classnames';
|
|
3
|
+
|
|
4
|
+
import { Icon } from '../../ui/icon';
|
|
5
|
+
import { HoverCard } from '../../ui/hover-card';
|
|
6
|
+
import { Tooltip } from '../../ui/tooltip';
|
|
7
|
+
import { Skeleton } from '../../ui/skeleton';
|
|
8
|
+
import { FlexStack } from '../../layout/flex-stack';
|
|
9
|
+
import { Stack } from '../../layout/stack';
|
|
10
|
+
import { Metric } from '../metric';
|
|
11
|
+
import { Delta } from '../delta';
|
|
12
|
+
import css from './run-info.module.css';
|
|
13
|
+
|
|
14
|
+
// Separate value and unit
|
|
15
|
+
const EXTRACT_VALUE_UNIT_PATTERN = /([\d|.|,| ]*)(\w*|%)$/;
|
|
16
|
+
|
|
17
|
+
const getMetricParams = (value: string) => {
|
|
18
|
+
const matches = value.match(EXTRACT_VALUE_UNIT_PATTERN);
|
|
19
|
+
|
|
20
|
+
if (!matches) {
|
|
21
|
+
return { value, unit: '' };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
value: matches[1],
|
|
26
|
+
unit: matches[2],
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export interface RunInfoProps {
|
|
31
|
+
title?: string;
|
|
32
|
+
titleHoverCard?: React.ReactNode;
|
|
33
|
+
titleTooltip?: React.ReactNode;
|
|
34
|
+
current?: string;
|
|
35
|
+
baseline?: string;
|
|
36
|
+
delta?: string;
|
|
37
|
+
deltaType?: string;
|
|
38
|
+
|
|
39
|
+
as?: React.ElementType;
|
|
40
|
+
size?: 'medium' | 'large';
|
|
41
|
+
|
|
42
|
+
loading?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const RunInfo = ({
|
|
46
|
+
className = '',
|
|
47
|
+
title = '',
|
|
48
|
+
titleHoverCard = null,
|
|
49
|
+
titleTooltip = null,
|
|
50
|
+
current = '',
|
|
51
|
+
baseline = '',
|
|
52
|
+
delta = '',
|
|
53
|
+
deltaType = '',
|
|
54
|
+
as: Component = 'div',
|
|
55
|
+
size = 'medium',
|
|
56
|
+
loading = false,
|
|
57
|
+
...restProps
|
|
58
|
+
}: RunInfoProps & React.ComponentProps<'div'>) => {
|
|
59
|
+
const metricParams = getMetricParams(current);
|
|
60
|
+
const rootClassName = cx(css.root, className, css[size], delta && css.showDelta);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<Stack space="xxsmall" as={Component} className={rootClassName} {...restProps}>
|
|
64
|
+
{title && (
|
|
65
|
+
<FlexStack space="xxxsmall" alignItems="center" as="h3" className={css.title}>
|
|
66
|
+
<span>{title}</span>
|
|
67
|
+
{titleHoverCard && (
|
|
68
|
+
<HoverCard label={<Icon glyph={Icon.ICONS.HELP} />} className={css.titleIcon}>
|
|
69
|
+
{titleHoverCard}
|
|
70
|
+
</HoverCard>
|
|
71
|
+
)}
|
|
72
|
+
{titleTooltip && (
|
|
73
|
+
<Tooltip title={titleTooltip} className={css.titleIcon}>
|
|
74
|
+
<Icon glyph={Icon.ICONS.HELP} />
|
|
75
|
+
</Tooltip>
|
|
76
|
+
)}
|
|
77
|
+
</FlexStack>
|
|
78
|
+
)}
|
|
79
|
+
|
|
80
|
+
{!loading ? (
|
|
81
|
+
<Stack>
|
|
82
|
+
<Metric
|
|
83
|
+
className={css.currentMetric}
|
|
84
|
+
value={metricParams.value}
|
|
85
|
+
unit={metricParams.unit}
|
|
86
|
+
inline
|
|
87
|
+
>
|
|
88
|
+
{delta && <Delta className={css.delta} displayValue={delta} deltaType={deltaType} />}
|
|
89
|
+
</Metric>
|
|
90
|
+
<Metric className={css.baselineMetric} value={baseline} />
|
|
91
|
+
</Stack>
|
|
92
|
+
) : (
|
|
93
|
+
<Stack>
|
|
94
|
+
<Skeleton as="p" className={cx(css.currentMetric, css.loading)} />
|
|
95
|
+
<Skeleton as="p" className={cx(css.baselineMetric, css.loading)} />
|
|
96
|
+
</Stack>
|
|
97
|
+
)}
|
|
98
|
+
</Stack>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
@@ -1,43 +1,15 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import cx from 'classnames';
|
|
3
3
|
import get from 'lodash/get';
|
|
4
|
-
import { METRIC_COMPONENT_LINKS
|
|
4
|
+
import { METRIC_COMPONENT_LINKS } from '@bundle-stats/utils';
|
|
5
5
|
|
|
6
6
|
import { METRICS_WEBPACK_GENERAL } from '../../constants';
|
|
7
7
|
import { Box } from '../../layout/box';
|
|
8
8
|
import { FlexStack } from '../../layout/flex-stack';
|
|
9
|
-
import { Stack } from '../../layout/stack';
|
|
10
9
|
import { ComponentLink } from '../component-link';
|
|
11
10
|
import { MetricRunInfo, MetricRunInfoProps } from '../metric-run-info';
|
|
12
11
|
import css from './summary.module.css';
|
|
13
12
|
|
|
14
|
-
interface MetricInfoProps {
|
|
15
|
-
description: string;
|
|
16
|
-
url?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const MetricInfo = ({ description, url }: MetricInfoProps) => {
|
|
20
|
-
// The component parent can be rendered inside a link, use button to avoid using nested links
|
|
21
|
-
const onClick = useCallback(() => {
|
|
22
|
-
if (url) {
|
|
23
|
-
window.open(url);
|
|
24
|
-
}
|
|
25
|
-
}, [url]);
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<Stack space="xxxsmall">
|
|
29
|
-
<p>{description}</p>
|
|
30
|
-
{url && (
|
|
31
|
-
<p>
|
|
32
|
-
<button type="button" onClick={onClick} className={css.readMoreLink}>
|
|
33
|
-
Read more
|
|
34
|
-
</button>
|
|
35
|
-
</p>
|
|
36
|
-
)}
|
|
37
|
-
</Stack>
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
13
|
interface SummaryItemData {
|
|
42
14
|
current: number;
|
|
43
15
|
baseline: number;
|
|
@@ -62,13 +34,18 @@ interface SummaryItemProps {
|
|
|
62
34
|
}
|
|
63
35
|
|
|
64
36
|
const SummaryItem = (props: SummaryItemProps & React.ComponentProps<'div'>) => {
|
|
65
|
-
const {
|
|
37
|
+
const {
|
|
38
|
+
className = '',
|
|
39
|
+
metricId,
|
|
40
|
+
data,
|
|
41
|
+
summaryItemLink: SummaryItemCustomLink,
|
|
42
|
+
size,
|
|
43
|
+
loading,
|
|
44
|
+
showSummaryItemDelta,
|
|
45
|
+
} = props;
|
|
66
46
|
|
|
67
47
|
const componentLink = METRIC_COMPONENT_LINKS.get(metricId);
|
|
68
|
-
|
|
69
48
|
const metricData = get(data, metricId, { current: 0, baseline: 0 });
|
|
70
|
-
const metric = getGlobalMetricType(metricId);
|
|
71
|
-
const metricRunInfo = getMetricRunInfo(metric, metricData.current, metricData.baseline);
|
|
72
49
|
|
|
73
50
|
return (
|
|
74
51
|
<Box
|
|
@@ -81,16 +58,12 @@ const SummaryItem = (props: SummaryItemProps & React.ComponentProps<'div'>) => {
|
|
|
81
58
|
className={className}
|
|
82
59
|
>
|
|
83
60
|
<MetricRunInfo
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
61
|
+
metricId={metricId}
|
|
62
|
+
current={metricData.current}
|
|
63
|
+
baseline={metricData.baseline}
|
|
64
|
+
showDelta={showSummaryItemDelta && componentLink?.showDelta}
|
|
88
65
|
size={size}
|
|
89
66
|
loading={loading}
|
|
90
|
-
{...(showSummaryItemDelta && componentLink?.showDelta !== false && {
|
|
91
|
-
delta: metricRunInfo.displayDeltaPercentage,
|
|
92
|
-
deltaType: metricRunInfo.deltaType,
|
|
93
|
-
})}
|
|
94
67
|
/>
|
|
95
68
|
</Box>
|
|
96
69
|
);
|
|
@@ -21,3 +21,4 @@ export { ModuleInfo } from "./module-info";
|
|
|
21
21
|
export { Summary } from "./summary";
|
|
22
22
|
export { TotalSizeTypeTitle } from "./total-size-type-title";
|
|
23
23
|
export { MetricRunInfo, MetricRunInfoProps } from "./metric-run-info";
|
|
24
|
+
export { RunInfo, RunInfoProps } from "./run-info";
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { RunInfoProps } from '../run-info';
|
|
2
3
|
export interface MetricRunInfoProps {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
as?: React.ElementType;
|
|
11
|
-
size?: 'medium' | 'large';
|
|
12
|
-
loading?: boolean;
|
|
4
|
+
metricId: string;
|
|
5
|
+
current: number;
|
|
6
|
+
baseline?: number;
|
|
7
|
+
showDelta?: boolean;
|
|
8
|
+
showMetridDescription?: boolean;
|
|
9
|
+
size?: RunInfoProps['size'];
|
|
10
|
+
loading?: RunInfoProps['loading'];
|
|
13
11
|
}
|
|
14
|
-
export declare const MetricRunInfo: (
|
|
12
|
+
export declare const MetricRunInfo: (props: MetricRunInfoProps & React.ComponentProps<'div'>) => JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './run-info';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface RunInfoProps {
|
|
3
|
+
title?: string;
|
|
4
|
+
titleHoverCard?: React.ReactNode;
|
|
5
|
+
titleTooltip?: React.ReactNode;
|
|
6
|
+
current?: string;
|
|
7
|
+
baseline?: string;
|
|
8
|
+
delta?: string;
|
|
9
|
+
deltaType?: string;
|
|
10
|
+
as?: React.ElementType;
|
|
11
|
+
size?: 'medium' | 'large';
|
|
12
|
+
loading?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const RunInfo: ({ className, title, titleHoverCard, titleTooltip, current, baseline, delta, deltaType, as: Component, size, loading, ...restProps }: RunInfoProps & React.ComponentProps<'div'>) => JSX.Element;
|