@bundle-stats/ui 4.2.5-beta.0 → 4.2.5-beta.1

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.
Files changed (89) hide show
  1. package/globals.d.ts +4 -0
  2. package/lib/components/bundle-assets-totals-chart-bars/bundle-assets-totals-chart-bars.js +13 -5
  3. package/lib/components/bundle-assets-totals-chart-bars/bundle-assets-totals-chart-bars.js.map +1 -1
  4. package/lib/components/index.js +3 -3
  5. package/lib/components/index.js.map +1 -1
  6. package/lib/components/insight-icon/insight-icon.js.map +1 -1
  7. package/lib/components/insights/insights.js.map +1 -1
  8. package/lib/components/metric/index.js.map +1 -1
  9. package/lib/components/metric/metric.js +7 -64
  10. package/lib/components/metric/metric.js.map +1 -1
  11. package/lib/components/metric/metric.module.css +2 -2
  12. package/lib/components/{summary-item → metric-run-info}/index.js +1 -1
  13. package/lib/components/metric-run-info/index.js.map +1 -0
  14. package/lib/components/metric-run-info/metric-run-info.js +45 -0
  15. package/lib/components/metric-run-info/metric-run-info.js.map +1 -0
  16. package/lib/components/{summary-item/summary-item.module.css → metric-run-info/metric-run-info.module.css} +0 -18
  17. package/lib/components/summary/index.js.map +1 -1
  18. package/lib/components/summary/summary.js +50 -30
  19. package/lib/components/summary/summary.js.map +1 -1
  20. package/lib/components/summary/summary.module.css +19 -0
  21. package/lib/layout/box/box.js.map +1 -1
  22. package/lib/layout/flex-stack/flex-stack.js.map +1 -1
  23. package/lib/ui/container/container.js.map +1 -1
  24. package/lib/ui/tooltip/tooltip.js.map +1 -1
  25. package/lib-esm/components/bundle-assets-totals-chart-bars/bundle-assets-totals-chart-bars.js +12 -6
  26. package/lib-esm/components/bundle-assets-totals-chart-bars/bundle-assets-totals-chart-bars.js.map +1 -1
  27. package/lib-esm/components/index.js +1 -1
  28. package/lib-esm/components/index.js.map +1 -1
  29. package/lib-esm/components/insight-icon/insight-icon.js.map +1 -1
  30. package/lib-esm/components/insights/insights.js.map +1 -1
  31. package/lib-esm/components/metric/index.js.map +1 -1
  32. package/lib-esm/components/metric/metric.js +7 -41
  33. package/lib-esm/components/metric/metric.js.map +1 -1
  34. package/lib-esm/components/metric/metric.module.css +2 -2
  35. package/lib-esm/components/metric-run-info/index.js +2 -0
  36. package/lib-esm/components/metric-run-info/index.js.map +1 -0
  37. package/lib-esm/components/metric-run-info/metric-run-info.js +38 -0
  38. package/lib-esm/components/metric-run-info/metric-run-info.js.map +1 -0
  39. package/lib-esm/components/{summary-item/summary-item.module.css → metric-run-info/metric-run-info.module.css} +0 -18
  40. package/lib-esm/components/summary/index.js.map +1 -1
  41. package/lib-esm/components/summary/summary.js +27 -30
  42. package/lib-esm/components/summary/summary.js.map +1 -1
  43. package/lib-esm/components/summary/summary.module.css +19 -0
  44. package/lib-esm/layout/box/box.js.map +1 -1
  45. package/lib-esm/layout/flex-stack/flex-stack.js.map +1 -1
  46. package/lib-esm/ui/container/container.js.map +1 -1
  47. package/lib-esm/ui/tooltip/tooltip.js.map +1 -1
  48. package/package.json +7 -6
  49. package/src/components/bundle-assets-totals-chart-bars/bundle-assets-totals-chart-bars.jsx +23 -15
  50. package/src/components/index.js +1 -1
  51. package/src/components/insight-icon/insight-icon.tsx +0 -2
  52. package/src/components/insights/insights.tsx +0 -1
  53. package/src/components/metric/metric.module.css +2 -2
  54. package/src/components/metric/metric.stories.tsx +41 -0
  55. package/src/components/metric/metric.tsx +42 -0
  56. package/src/components/metric-run-info/index.ts +1 -0
  57. package/src/components/{summary-item/summary-item.module.css → metric-run-info/metric-run-info.module.css} +0 -18
  58. package/src/components/metric-run-info/metric-run-info.stories.tsx +49 -0
  59. package/src/components/metric-run-info/metric-run-info.tsx +101 -0
  60. package/src/components/summary/summary.module.css +19 -0
  61. package/src/components/summary/summary.stories.tsx +56 -0
  62. package/src/components/summary/summary.tsx +124 -0
  63. package/src/layout/box/box.tsx +0 -1
  64. package/src/layout/flex-stack/flex-stack.tsx +1 -2
  65. package/src/ui/container/container.tsx +0 -1
  66. package/src/ui/tooltip/tooltip.tsx +0 -1
  67. package/types/components/index.d.ts +1 -1
  68. package/types/components/metric/index.d.ts +1 -1
  69. package/types/components/metric/metric.d.ts +6 -32
  70. package/types/components/metric-run-info/index.d.ts +1 -0
  71. package/types/components/metric-run-info/metric-run-info.d.ts +14 -0
  72. package/types/components/summary/index.d.ts +1 -1
  73. package/types/components/summary/summary.d.ts +15 -36
  74. package/types/layout/flex-stack/flex-stack.d.ts +2 -1
  75. package/lib/components/summary-item/index.js.map +0 -1
  76. package/lib/components/summary-item/summary-item.js +0 -97
  77. package/lib/components/summary-item/summary-item.js.map +0 -1
  78. package/lib-esm/components/summary-item/index.js +0 -2
  79. package/lib-esm/components/summary-item/index.js.map +0 -1
  80. package/lib-esm/components/summary-item/summary-item.js +0 -67
  81. package/lib-esm/components/summary-item/summary-item.js.map +0 -1
  82. package/src/components/metric/metric.jsx +0 -63
  83. package/src/components/summary/summary.jsx +0 -74
  84. package/src/components/summary-item/index.js +0 -1
  85. package/src/components/summary-item/summary-item.jsx +0 -142
  86. package/types/components/summary-item/index.d.ts +0 -1
  87. package/types/components/summary-item/summary-item.d.ts +0 -40
  88. /package/src/components/metric/{index.js → index.ts} +0 -0
  89. /package/src/components/summary/{index.js → index.ts} +0 -0
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { Meta, Story } from '@storybook/react';
3
+
4
+ import { MetricRunInfo } from './metric-run-info';
5
+
6
+ export default {
7
+ title: 'Components/MetricRunInfo',
8
+ component: MetricRunInfo,
9
+ } as Meta;
10
+
11
+ const Template: Story = (args) => <MetricRunInfo 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,101 @@
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 './metric-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 MetricRunInfoProps {
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 MetricRunInfo = ({
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
+ }: MetricRunInfoProps & 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
+
68
+ {titleHoverCard && (
69
+ <HoverCard label={<Icon glyph={Icon.ICONS.HELP} />} className={css.titleIcon}>
70
+ {titleHoverCard}
71
+ </HoverCard>
72
+ )}
73
+ {titleTooltip && (
74
+ <Tooltip title={titleTooltip} className={css.titleIcon}>
75
+ <Icon glyph={Icon.ICONS.HELP} />
76
+ </Tooltip>
77
+ )}
78
+ </FlexStack>
79
+ )}
80
+
81
+ {!loading ? (
82
+ <Stack>
83
+ <Metric
84
+ className={css.currentMetric}
85
+ value={metricParams.value}
86
+ unit={metricParams.unit}
87
+ inline
88
+ >
89
+ {delta && <Delta className={css.delta} displayValue={delta} deltaType={deltaType} />}
90
+ </Metric>
91
+ <Metric className={css.baselineMetric} value={baseline} />
92
+ </Stack>
93
+ ) : (
94
+ <Stack>
95
+ <Skeleton as="p" className={cx(css.currentMetric, css.loading)} />
96
+ <Skeleton as="p" className={cx(css.baselineMetric, css.loading)} />
97
+ </Stack>
98
+ )}
99
+ </Stack>
100
+ );
101
+ };
@@ -7,3 +7,22 @@
7
7
  min-width: 16em;
8
8
  text-decoration: none;
9
9
  }
10
+
11
+ .readMoreLink {
12
+ appearance: none;
13
+ background: none;
14
+ margin: 0;
15
+ border: 0;
16
+ padding: 0;
17
+ color: var(--color-primary);
18
+ text-decoration: underline;
19
+ cursor: pointer;
20
+ }
21
+
22
+ .readMoreLink:hover,
23
+ .readMoreLink:active,
24
+ .readMoreLink:focus {
25
+ color: var(--color-primary-dark);
26
+ text-decoration: none;
27
+ }
28
+
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+ import { Meta, Story } from '@storybook/react';
3
+ import { createJobs } from '@bundle-stats/utils';
4
+
5
+ import baselineData from '../../../__mocks__/webpack-stats.baseline.json';
6
+ import currentData from '../../../__mocks__/webpack-stats.current.json';
7
+ import { METRICS_WEBPACK_ASSETS } from '../../constants';
8
+ import { getWrapperDecorator } from '../../stories';
9
+ import { Summary } from '.';
10
+
11
+ const MULTIPLE_JOBS = createJobs([{ webpack: currentData }, { webpack: baselineData }]);
12
+
13
+ const SINGLE_JOB = createJobs([{ webpack: currentData }]);
14
+
15
+ export default {
16
+ title: 'Components/Summary',
17
+ component: Summary,
18
+ decorators: [getWrapperDecorator()],
19
+ } as Meta;
20
+
21
+ const Template: Story = (args) => <Summary {...args} />;
22
+
23
+ export const Default = Template.bind({});
24
+
25
+ Default.args = {
26
+ data: MULTIPLE_JOBS[0].summary,
27
+ };
28
+
29
+ export const CustomKeys = Template.bind({});
30
+
31
+ CustomKeys.args = {
32
+ keys: METRICS_WEBPACK_ASSETS,
33
+ data: MULTIPLE_JOBS[0].summary,
34
+ };
35
+
36
+ export const Loading = Template.bind({});
37
+
38
+ Loading.args = {
39
+ loading: true,
40
+ };
41
+
42
+ export const SingleRun = Template.bind({});
43
+
44
+ SingleRun.args = {
45
+ data: SINGLE_JOB[0].summary,
46
+ showSummaryItemDelta: false,
47
+ };
48
+
49
+ export const WithLink = Template.bind({});
50
+
51
+ WithLink.args = {
52
+ data: MULTIPLE_JOBS[0].summary,
53
+ summaryItemLink: (linkProps: React.ComponentProps<'button'>) => (
54
+ <button {...linkProps} type="button" onClick={() => alert(JSON.stringify(linkProps))} />
55
+ ),
56
+ };
@@ -0,0 +1,124 @@
1
+ import React, { useCallback } from 'react';
2
+ import cx from 'classnames';
3
+ import get from 'lodash/get';
4
+ import { METRIC_COMPONENT_LINKS, getGlobalMetricType, getMetricRunInfo } from '@bundle-stats/utils';
5
+
6
+ import { METRICS_WEBPACK_GENERAL } from '../../constants';
7
+ import { Box } from '../../layout/box';
8
+ import { FlexStack } from '../../layout/flex-stack';
9
+ import { Stack } from '../../layout/stack';
10
+ import { ComponentLink } from '../component-link';
11
+ import { MetricRunInfo, MetricRunInfoProps } from '../metric-run-info';
12
+ import css from './summary.module.css';
13
+
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
+ interface SummaryItemData {
42
+ current: number;
43
+ baseline: number;
44
+ }
45
+
46
+ interface SummaryProps {
47
+ size?: MetricRunInfoProps['size'];
48
+ keys?: Array<string>;
49
+ data?: Record<string, SummaryItemData> | null;
50
+ loading?: boolean;
51
+ showSummaryItemDelta?: boolean;
52
+ summaryItemLink?: React.ElementType;
53
+ }
54
+
55
+ interface SummaryItemProps {
56
+ metricId: string;
57
+ data?: SummaryProps['data'];
58
+ summaryItemLink: SummaryProps['summaryItemLink'];
59
+ size: SummaryProps['size'];
60
+ loading: SummaryProps['loading'];
61
+ showSummaryItemDelta: SummaryProps['showSummaryItemDelta'];
62
+ }
63
+
64
+ const SummaryItem = (props: SummaryItemProps & React.ComponentProps<'div'>) => {
65
+ const { className = '', metricId, data, summaryItemLink: SummaryItemCustomLink, size, loading, showSummaryItemDelta } = props;
66
+
67
+ const componentLink = METRIC_COMPONENT_LINKS.get(metricId);
68
+
69
+ const metricData = get(data, metricId, { current: 0, baseline: 0 });
70
+ const metric = getGlobalMetricType(metricId);
71
+ const metricRunInfo = getMetricRunInfo(metric, metricData.current, metricData.baseline);
72
+
73
+ return (
74
+ <Box
75
+ key={metricId}
76
+ outline
77
+ outlineHover
78
+ padding="small"
79
+ as={SummaryItemCustomLink}
80
+ {...componentLink?.link}
81
+ className={className}
82
+ >
83
+ <MetricRunInfo
84
+ title={metric.label}
85
+ titleHoverCard={<MetricInfo description={metric.description} url={metric.url} />}
86
+ current={metricRunInfo.displayValue}
87
+ baseline={metric.formatter(metricData.baseline)}
88
+ size={size}
89
+ loading={loading}
90
+ {...(showSummaryItemDelta && componentLink?.showDelta !== false && {
91
+ delta: metricRunInfo.displayDeltaPercentage,
92
+ deltaType: metricRunInfo.deltaType,
93
+ })}
94
+ />
95
+ </Box>
96
+ );
97
+ };
98
+
99
+ export const Summary = ({
100
+ className = '',
101
+ size = 'medium',
102
+ keys = METRICS_WEBPACK_GENERAL,
103
+ data = null,
104
+ loading = false,
105
+ showSummaryItemDelta = true,
106
+ summaryItemLink = ComponentLink,
107
+ }: SummaryProps & React.ComponentProps<'div'>) => (
108
+ <Box className={cx(css.root, className)}>
109
+ <FlexStack space="small" className={css.items}>
110
+ {keys.map((metricId) => (
111
+ <SummaryItem
112
+ key={metricId}
113
+ className={css.item}
114
+ metricId={metricId}
115
+ data={data}
116
+ summaryItemLink={summaryItemLink}
117
+ size={size}
118
+ loading={loading}
119
+ showSummaryItemDelta={showSummaryItemDelta}
120
+ />
121
+ ))}
122
+ </FlexStack>
123
+ </Box>
124
+ );
@@ -2,7 +2,6 @@ import React from 'react';
2
2
  import cx from 'classnames';
3
3
 
4
4
  import { NO_SPACE, SPACES } from '../../tokens';
5
- // @ts-ignore
6
5
  import css from './box.module.css';
7
6
 
8
7
  type SpaceValue = (typeof SPACES)[number];
@@ -3,14 +3,13 @@ import cx from 'classnames';
3
3
 
4
4
  import { NO_SPACE, SPACES } from '../../tokens';
5
5
  import { getRenderChildWithClassName } from '../../utils';
6
- // @ts-ignore
7
6
  import css from './flex-stack.module.css';
8
7
 
9
8
  type SpaceValue = (typeof SPACES)[number];
10
9
 
11
10
  interface FlexStackProps<T extends React.ElementType> {
12
11
  as?: T;
13
- space?: typeof SPACES[number];
12
+ space?: SpaceValue;
14
13
  inline?: boolean;
15
14
  alignItems?: 'top' | 'center' | 'bottom';
16
15
  }
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
2
  import cx from 'classnames';
3
3
 
4
- // @ts-ignore
5
4
  import css from './container.module.css';
6
5
 
7
6
  interface ContainerProps extends React.HTMLAttributes<HTMLDivElement> {
@@ -7,7 +7,6 @@ import {
7
7
  useTooltipState,
8
8
  } from 'ariakit/tooltip';
9
9
 
10
- // @ts-ignore
11
10
  import css from './tooltip.module.css';
12
11
 
13
12
  interface TooltipProps<T extends React.ElementType> {
@@ -18,6 +18,6 @@ export { MetricsTableOptions } from "./metrics-table-options";
18
18
  export { MetricsTableSearch } from "./metrics-table-search";
19
19
  export { MetricsTableTitle } from "./metrics-table-title";
20
20
  export { ModuleInfo } from "./module-info";
21
- export { SummaryItem } from "./summary-item";
22
21
  export { Summary } from "./summary";
23
22
  export { TotalSizeTypeTitle } from "./total-size-type-title";
23
+ export { MetricRunInfo, MetricRunInfoProps } from "./metric-run-info";
@@ -1 +1 @@
1
- export * from "./metric";
1
+ export * from './metric';
@@ -1,33 +1,7 @@
1
- export function Metric({ className, value, formatter, inline, children, enhanced }: {
2
- className: any;
3
- value: any;
4
- formatter: any;
5
- inline: any;
6
- children: any;
7
- enhanced: any;
8
- }): JSX.Element;
9
- export namespace Metric {
10
- namespace defaultProps {
11
- const className: string;
12
- const enhanced: boolean;
13
- const inline: boolean;
14
- const value: number;
15
- const children: never[];
16
- function formatter(val: any): any;
17
- }
18
- namespace propTypes {
19
- const className_1: PropTypes.Requireable<string>;
20
- export { className_1 as className };
21
- const enhanced_1: PropTypes.Requireable<boolean>;
22
- export { enhanced_1 as enhanced };
23
- const inline_1: PropTypes.Requireable<boolean>;
24
- export { inline_1 as inline };
25
- const value_1: PropTypes.Requireable<NonNullable<string | number | null | undefined>>;
26
- export { value_1 as value };
27
- const formatter_1: PropTypes.Requireable<(...args: any[]) => any>;
28
- export { formatter_1 as formatter };
29
- const children_1: PropTypes.Requireable<PropTypes.ReactNodeLike>;
30
- export { children_1 as children };
31
- }
1
+ import React from 'react';
2
+ export interface MetricProps {
3
+ value?: string;
4
+ unit?: string;
5
+ inline?: boolean;
32
6
  }
33
- import PropTypes from "prop-types";
7
+ export declare const Metric: (props: MetricProps & React.ComponentProps<'div'>) => JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './metric-run-info';
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ export interface MetricRunInfoProps {
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 MetricRunInfo: ({ className, title, titleHoverCard, titleTooltip, current, baseline, delta, deltaType, as: Component, size, loading, ...restProps }: MetricRunInfoProps & React.ComponentProps<'div'>) => JSX.Element;
@@ -1 +1 @@
1
- export * from "./summary";
1
+ export * from './summary';
@@ -1,37 +1,16 @@
1
- export function Summary({ className, size, keys, data, loading, showSummaryItemDelta, summaryItemLink: SummaryItemCustomLink, }: {
2
- className: any;
3
- size: any;
4
- keys: any;
5
- data: any;
6
- loading: any;
7
- showSummaryItemDelta: any;
8
- summaryItemLink: any;
9
- }): JSX.Element;
10
- export namespace Summary {
11
- namespace defaultProps {
12
- export const className: string;
13
- export const data: null;
14
- export const loading: boolean;
15
- export const size: string;
16
- export { METRICS_WEBPACK_GENERAL as keys };
17
- export const showSummaryItemDelta: boolean;
18
- export { ComponentLink as summaryItemLink };
19
- }
20
- namespace propTypes {
21
- const className_1: PropTypes.Requireable<string>;
22
- export { className_1 as className };
23
- const size_1: PropTypes.Requireable<string>;
24
- export { size_1 as size };
25
- export const keys: PropTypes.Requireable<(string | null | undefined)[]>;
26
- const data_1: PropTypes.Requireable<PropTypes.InferProps<{}>>;
27
- export { data_1 as data };
28
- const loading_1: PropTypes.Requireable<boolean>;
29
- export { loading_1 as loading };
30
- const showSummaryItemDelta_1: PropTypes.Requireable<boolean>;
31
- export { showSummaryItemDelta_1 as showSummaryItemDelta };
32
- export const summaryItemLink: PropTypes.Requireable<PropTypes.ReactComponentLike>;
33
- }
1
+ import React from 'react';
2
+ import { MetricRunInfoProps } from '../metric-run-info';
3
+ interface SummaryItemData {
4
+ current: number;
5
+ baseline: number;
34
6
  }
35
- import { METRICS_WEBPACK_GENERAL } from "../../constants";
36
- import { ComponentLink } from "../component-link";
37
- import PropTypes from "prop-types";
7
+ interface SummaryProps {
8
+ size?: MetricRunInfoProps['size'];
9
+ keys?: Array<string>;
10
+ data?: Record<string, SummaryItemData> | null;
11
+ loading?: boolean;
12
+ showSummaryItemDelta?: boolean;
13
+ summaryItemLink?: React.ElementType;
14
+ }
15
+ export declare const Summary: ({ className, size, keys, data, loading, showSummaryItemDelta, summaryItemLink, }: SummaryProps & React.ComponentProps<'div'>) => JSX.Element;
16
+ export {};
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
2
  import { SPACES } from '../../tokens';
3
+ type SpaceValue = (typeof SPACES)[number];
3
4
  interface FlexStackProps<T extends React.ElementType> {
4
5
  as?: T;
5
- space?: typeof SPACES[number];
6
+ space?: SpaceValue;
6
7
  inline?: boolean;
7
8
  alignItems?: 'top' | 'center' | 'bottom';
8
9
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/summary-item/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B"}
@@ -1,97 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.SummaryItem = void 0;
30
- const react_1 = __importStar(require("react"));
31
- const prop_types_1 = __importDefault(require("prop-types"));
32
- const classnames_1 = __importDefault(require("classnames"));
33
- const utils_1 = require("@bundle-stats/utils");
34
- const icon_1 = require("../../ui/icon");
35
- const hover_card_1 = require("../../ui/hover-card");
36
- const skeleton_1 = require("../../ui/skeleton");
37
- const flex_stack_1 = require("../../layout/flex-stack");
38
- const stack_1 = require("../../layout/stack");
39
- const metric_1 = require("../metric");
40
- const delta_1 = require("../delta");
41
- const summary_item_module_css_1 = __importDefault(require("./summary-item.module.css"));
42
- const MetricInfo = ({ description, url }) => {
43
- const onClick = (0, react_1.useCallback)(() => {
44
- if (url) {
45
- window.open(url);
46
- }
47
- }, [url]);
48
- return (react_1.default.createElement(stack_1.Stack, { space: "xxxsmall" },
49
- react_1.default.createElement("p", null, description),
50
- url && (react_1.default.createElement("p", null,
51
- react_1.default.createElement("button", { type: "button", onClick: onClick, className: summary_item_module_css_1.default.readMoreLink }, "Read more")))));
52
- };
53
- MetricInfo.propTypes = {
54
- description: prop_types_1.default.string.isRequired,
55
- url: prop_types_1.default.string,
56
- };
57
- MetricInfo.defaultProps = {
58
- url: '',
59
- };
60
- const SummaryItem = ({ className, as: Component, size, id, data, loading, showDelta, showMetricDescription, ...props }) => {
61
- const { baseline, current } = data || { baseline: 0, current: 0 };
62
- const metric = (0, utils_1.getGlobalMetricType)(id);
63
- const runInfo = (0, utils_1.getMetricRunInfo)(metric, current, baseline);
64
- const showMetricDescriptionTooltip = showMetricDescription && metric?.description;
65
- const rootClassName = (0, classnames_1.default)(summary_item_module_css_1.default.root, className, summary_item_module_css_1.default[size], showDelta && summary_item_module_css_1.default.showDelta);
66
- return (react_1.default.createElement(stack_1.Stack, { space: "xxsmall", as: Component, className: rootClassName, ...props },
67
- react_1.default.createElement(flex_stack_1.FlexStack, { space: "xxxsmall", alignItems: "center", as: "h3", className: summary_item_module_css_1.default.title },
68
- react_1.default.createElement("span", null, metric.label),
69
- showMetricDescriptionTooltip && (react_1.default.createElement(hover_card_1.HoverCard, { label: react_1.default.createElement(icon_1.Icon, { glyph: icon_1.Icon.ICONS.HELP }), className: summary_item_module_css_1.default.titleIcon },
70
- react_1.default.createElement(MetricInfo, { ...metric })))),
71
- !loading ? (react_1.default.createElement(stack_1.Stack, null,
72
- react_1.default.createElement(metric_1.Metric, { className: summary_item_module_css_1.default.currentMetric, value: current, formatter: metric.formatter, enhanced: true, inline: true }, showDelta && (react_1.default.createElement(delta_1.Delta, { className: summary_item_module_css_1.default.delta, displayValue: runInfo.displayDeltaPercentage, deltaType: runInfo.deltaType }))),
73
- react_1.default.createElement(metric_1.Metric, { className: summary_item_module_css_1.default.baselineMetric, value: baseline, formatter: metric.formatter }))) : (react_1.default.createElement(stack_1.Stack, null,
74
- react_1.default.createElement(skeleton_1.Skeleton, { as: "p", className: (0, classnames_1.default)(summary_item_module_css_1.default.currentMetric, summary_item_module_css_1.default.loading) }),
75
- react_1.default.createElement(skeleton_1.Skeleton, { as: "p", className: (0, classnames_1.default)(summary_item_module_css_1.default.baselineMetric, summary_item_module_css_1.default.loading) })))));
76
- };
77
- exports.SummaryItem = SummaryItem;
78
- exports.SummaryItem.defaultProps = {
79
- className: '',
80
- as: 'div',
81
- data: null,
82
- size: 'medium',
83
- loading: false,
84
- showMetricDescription: false,
85
- showDelta: true,
86
- };
87
- exports.SummaryItem.propTypes = {
88
- className: prop_types_1.default.string,
89
- as: prop_types_1.default.elementType,
90
- size: prop_types_1.default.oneOf(['medium', 'large']),
91
- id: prop_types_1.default.string.isRequired,
92
- loading: prop_types_1.default.bool,
93
- data: prop_types_1.default.object,
94
- showMetricDescription: prop_types_1.default.bool,
95
- showDelta: prop_types_1.default.bool,
96
- };
97
- //# sourceMappingURL=summary-item.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"summary-item.js","sourceRoot":"","sources":["../../../src/components/summary-item/summary-item.jsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA2C;AAC3C,4DAAmC;AACnC,4DAA4B;AAC5B,+CAA4E;AAE5E,wCAAqC;AACrC,oDAAgD;AAChD,gDAA6C;AAC7C,wDAAoD;AACpD,8CAA2C;AAC3C,sCAAmC;AACnC,oCAAiC;AACjC,wFAA4C;AAE5C,MAAM,UAAU,GAAG,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,EAAE,EAAE;IAE1C,MAAM,OAAO,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC/B,IAAI,GAAG,EAAE;YACP,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAClB;IACH,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEV,OAAO,CACL,8BAAC,aAAK,IAAC,KAAK,EAAC,UAAU;QACrB,yCAAI,WAAW,CAAK;QACnB,GAAG,IAAI,CACN;YACE,0CAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,iCAAG,CAAC,YAAY,gBAE1D,CACP,CACL,CACK,CACT,CAAC;AACJ,CAAC,CAAC;AAEF,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AC,SAAS,GAAG;IAEtB,SAAS,EAAE,oBAAS,CAAC,MAAM;IAG3B,EAAE,EAAE,oBAAS,CAAC,WAAW;IAGzB,IAAI,EAAE,oBAAS,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAG1C,EAAE,EAAE,oBAAS,CAAC,MAAM,CAAC,UAAU;IAG/B,OAAO,EAAE,oBAAS,CAAC,IAAI;IAGvB,IAAI,EAAE,oBAAS,CAAC,MAAM;IAGtB,qBAAqB,EAAE,oBAAS,CAAC,IAAI;IAGrC,SAAS,EAAE,oBAAS,CAAC,IAAI;CAC1B,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './summary-item';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/summary-item/index.js"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}