@bundle-stats/ui 4.22.2 → 4.23.0-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 (227) hide show
  1. package/.babelrc.js +65 -24
  2. package/globals.d.ts +13 -0
  3. package/lib/app/app.js +3 -0
  4. package/lib/app/app.js.map +1 -1
  5. package/lib/app/app.module.css +11 -1
  6. package/lib/components/bundle-modules/index.js.map +1 -1
  7. package/lib/components/delta/delta.js +3 -13
  8. package/lib/components/delta/delta.js.map +1 -1
  9. package/lib/components/delta/delta.module.css +13 -12
  10. package/lib/components/delta/index.js.map +1 -1
  11. package/lib/components/index.js +3 -1
  12. package/lib/components/index.js.map +1 -1
  13. package/lib/components/insight-icon/insight-icon.module.css +6 -6
  14. package/lib/components/job-name/job-name.js +1 -2
  15. package/lib/components/job-name/job-name.js.map +1 -1
  16. package/lib/components/metric-change-legend/index.js +18 -0
  17. package/lib/components/metric-change-legend/index.js.map +1 -0
  18. package/lib/components/metric-change-legend/metric-change-legend.js +91 -0
  19. package/lib/components/metric-change-legend/metric-change-legend.js.map +1 -0
  20. package/lib/components/metric-change-legend/metric-change-legend.module.css +69 -0
  21. package/lib/components/metric-run-info/metric-run-info.js +30 -7
  22. package/lib/components/metric-run-info/metric-run-info.js.map +1 -1
  23. package/lib/components/metrics-display-selector/metrics-display-selector.js +7 -9
  24. package/lib/components/metrics-display-selector/metrics-display-selector.js.map +1 -1
  25. package/lib/components/metrics-display-selector/metrics-display-selector.module.css +0 -25
  26. package/lib/components/metrics-table-header/metrics-table-header.js +8 -8
  27. package/lib/components/metrics-table-header/metrics-table-header.js.map +1 -1
  28. package/lib/components/metrics-table-header/metrics-table-header.module.css +8 -12
  29. package/lib/components/metrics-table-options/metrics-table-options.js +1 -1
  30. package/lib/components/metrics-table-options/metrics-table-options.js.map +1 -1
  31. package/lib/components/metrics-table-title/metrics-table-title.js +1 -1
  32. package/lib/components/metrics-table-title/metrics-table-title.js.map +1 -1
  33. package/lib/components/run-info/run-info.js +26 -14
  34. package/lib/components/run-info/run-info.js.map +1 -1
  35. package/lib/components/run-info/run-info.module.css +35 -26
  36. package/lib/components/summary/summary.js +9 -10
  37. package/lib/components/summary/summary.js.map +1 -1
  38. package/lib/components/summary/summary.module.css +60 -10
  39. package/lib/constants.js +13 -1
  40. package/lib/constants.js.map +1 -1
  41. package/lib/css/default.css +1 -1
  42. package/lib/css/variables.css +71 -58
  43. package/lib/hooks/rows-sort.js +13 -12
  44. package/lib/hooks/rows-sort.js.map +1 -1
  45. package/lib/ui/button/button.js.map +1 -1
  46. package/lib/ui/dialog/dialog.js +4 -2
  47. package/lib/ui/dialog/dialog.js.map +1 -1
  48. package/lib/ui/dialog/dialog.module.css +22 -0
  49. package/lib/ui/dropdown/dropdown.js +4 -3
  50. package/lib/ui/dropdown/dropdown.js.map +1 -1
  51. package/lib/ui/dropdown/dropdown.module.css +11 -0
  52. package/lib/ui/empty-set/empty-set.js +3 -3
  53. package/lib/ui/empty-set/empty-set.js.map +1 -1
  54. package/lib/ui/hover-card/hover-card.js +1 -1
  55. package/lib/ui/hover-card/hover-card.js.map +1 -1
  56. package/lib/ui/hover-card/hover-card.module.css +14 -0
  57. package/lib/ui/table/table.module.css +0 -1
  58. package/lib/ui/tooltip/tooltip.js +1 -1
  59. package/lib/ui/tooltip/tooltip.js.map +1 -1
  60. package/lib/ui/tooltip/tooltip.module.css +11 -0
  61. package/lib-esm/app/app.js +4 -1
  62. package/lib-esm/app/app.js.map +1 -1
  63. package/lib-esm/app/app.module.css +11 -1
  64. package/lib-esm/components/bundle-modules/index.js.map +1 -1
  65. package/lib-esm/components/delta/delta.js +3 -13
  66. package/lib-esm/components/delta/delta.js.map +1 -1
  67. package/lib-esm/components/delta/delta.module.css +13 -12
  68. package/lib-esm/components/delta/index.js.map +1 -1
  69. package/lib-esm/components/index.js +1 -0
  70. package/lib-esm/components/index.js.map +1 -1
  71. package/lib-esm/components/insight-icon/insight-icon.module.css +6 -6
  72. package/lib-esm/components/job-name/job-name.js +1 -2
  73. package/lib-esm/components/job-name/job-name.js.map +1 -1
  74. package/lib-esm/components/metric-change-legend/index.js +2 -0
  75. package/lib-esm/components/metric-change-legend/index.js.map +1 -0
  76. package/lib-esm/components/metric-change-legend/metric-change-legend.js +84 -0
  77. package/lib-esm/components/metric-change-legend/metric-change-legend.js.map +1 -0
  78. package/lib-esm/components/metric-change-legend/metric-change-legend.module.css +69 -0
  79. package/lib-esm/components/metric-run-info/metric-run-info.js +31 -8
  80. package/lib-esm/components/metric-run-info/metric-run-info.js.map +1 -1
  81. package/lib-esm/components/metrics-display-selector/metrics-display-selector.js +7 -9
  82. package/lib-esm/components/metrics-display-selector/metrics-display-selector.js.map +1 -1
  83. package/lib-esm/components/metrics-display-selector/metrics-display-selector.module.css +0 -25
  84. package/lib-esm/components/metrics-table-header/metrics-table-header.js +8 -8
  85. package/lib-esm/components/metrics-table-header/metrics-table-header.js.map +1 -1
  86. package/lib-esm/components/metrics-table-header/metrics-table-header.module.css +8 -12
  87. package/lib-esm/components/metrics-table-options/metrics-table-options.js +1 -1
  88. package/lib-esm/components/metrics-table-options/metrics-table-options.js.map +1 -1
  89. package/lib-esm/components/metrics-table-title/metrics-table-title.js +1 -1
  90. package/lib-esm/components/metrics-table-title/metrics-table-title.js.map +1 -1
  91. package/lib-esm/components/run-info/run-info.js +26 -14
  92. package/lib-esm/components/run-info/run-info.js.map +1 -1
  93. package/lib-esm/components/run-info/run-info.module.css +35 -26
  94. package/lib-esm/components/summary/summary.js +10 -11
  95. package/lib-esm/components/summary/summary.js.map +1 -1
  96. package/lib-esm/components/summary/summary.module.css +60 -10
  97. package/lib-esm/constants.js +12 -0
  98. package/lib-esm/constants.js.map +1 -1
  99. package/lib-esm/css/default.css +1 -1
  100. package/lib-esm/css/variables.css +71 -58
  101. package/lib-esm/hooks/rows-sort.js +10 -8
  102. package/lib-esm/hooks/rows-sort.js.map +1 -1
  103. package/lib-esm/ui/button/button.js.map +1 -1
  104. package/lib-esm/ui/dialog/dialog.js +4 -2
  105. package/lib-esm/ui/dialog/dialog.js.map +1 -1
  106. package/lib-esm/ui/dialog/dialog.module.css +22 -0
  107. package/lib-esm/ui/dropdown/dropdown.js +4 -3
  108. package/lib-esm/ui/dropdown/dropdown.js.map +1 -1
  109. package/lib-esm/ui/dropdown/dropdown.module.css +11 -0
  110. package/lib-esm/ui/empty-set/empty-set.js +3 -3
  111. package/lib-esm/ui/empty-set/empty-set.js.map +1 -1
  112. package/lib-esm/ui/hover-card/hover-card.js +1 -1
  113. package/lib-esm/ui/hover-card/hover-card.js.map +1 -1
  114. package/lib-esm/ui/hover-card/hover-card.module.css +14 -0
  115. package/lib-esm/ui/table/table.module.css +0 -1
  116. package/lib-esm/ui/tooltip/tooltip.js +1 -1
  117. package/lib-esm/ui/tooltip/tooltip.js.map +1 -1
  118. package/lib-esm/ui/tooltip/tooltip.module.css +11 -0
  119. package/package.json +26 -15
  120. package/src/app/app.jsx +6 -1
  121. package/src/app/app.module.css +11 -1
  122. package/src/app/app.stories.tsx +2 -2
  123. package/src/components/asset-info/asset-info.stories.tsx +47 -39
  124. package/src/components/asset-name/asset-name.stories.tsx +1 -3
  125. package/src/components/asset-not-predictive/asset-not-predictive.stories.tsx +22 -15
  126. package/src/components/browsertime-table/browsertime-table.stories.tsx +45 -0
  127. package/src/components/bundle-assets-totals/bundle-assets-totals.stories.tsx +47 -0
  128. package/src/components/bundle-modules/bundle-modules.stories.tsx +191 -0
  129. package/src/components/bundle-modules/bundle-modules.tsx +1 -1
  130. package/src/components/bundle-modules/index.tsx +4 -0
  131. package/src/components/bundle-packages/bundle-packages.stories.tsx +87 -0
  132. package/src/components/delta/delta.module.css +13 -12
  133. package/src/components/delta/delta.stories.tsx +57 -0
  134. package/src/components/delta/delta.tsx +32 -0
  135. package/src/components/entry-info/entry-info.stories.tsx +49 -54
  136. package/src/components/{index.js → index.ts} +7 -2
  137. package/src/components/insight-icon/insight-icon.module.css +6 -6
  138. package/src/components/insights/insights.stories.tsx +36 -33
  139. package/src/components/job-name/job-name.jsx +2 -3
  140. package/src/components/job-name/job-name.stories.tsx +46 -0
  141. package/src/components/jobs-header/jobs-header.stories.tsx +19 -15
  142. package/src/components/lighthouse-table/lighthouse-table.stories.tsx +30 -0
  143. package/src/components/metric/metric.stories.tsx +24 -22
  144. package/src/components/metric-change-legend/index.ts +1 -0
  145. package/src/components/metric-change-legend/metric-change-legend.module.css +69 -0
  146. package/src/components/metric-change-legend/metric-change-legend.stories.tsx +13 -0
  147. package/src/components/metric-change-legend/metric-change-legend.tsx +148 -0
  148. package/src/components/metric-run-info/metric-run-info.stories.tsx +45 -41
  149. package/src/components/metric-run-info/metric-run-info.tsx +41 -17
  150. package/src/components/metrics-display-selector/metrics-display-selector.module.css +0 -25
  151. package/src/components/metrics-display-selector/metrics-display-selector.tsx +25 -37
  152. package/src/components/metrics-table/metrics-table.stories.tsx +33 -13
  153. package/src/components/metrics-table/metrics-table.tsx +1 -1
  154. package/src/components/metrics-table-header/metrics-table-header.module.css +8 -12
  155. package/src/components/metrics-table-header/metrics-table-header.tsx +14 -10
  156. package/src/components/metrics-table-options/metrics-table-options.tsx +1 -1
  157. package/src/components/metrics-table-title/metrics-table-title.jsx +1 -1
  158. package/src/components/module-info/module-info.stories.tsx +41 -30
  159. package/src/components/package-info/package-info.stories.tsx +20 -15
  160. package/src/components/run-info/run-info.module.css +35 -26
  161. package/src/components/run-info/run-info.stories.tsx +47 -39
  162. package/src/components/run-info/run-info.tsx +132 -73
  163. package/src/components/summary/summary.module.css +60 -10
  164. package/src/components/summary/summary.stories.tsx +26 -32
  165. package/src/components/summary/summary.tsx +47 -50
  166. package/src/constants.ts +13 -0
  167. package/src/css/default.css +1 -1
  168. package/src/css/variables.css +71 -58
  169. package/src/hooks/rows-sort.ts +9 -6
  170. package/src/layout/box/box.stories.tsx +35 -28
  171. package/src/layout/flex-stack/flex-stack.stories.tsx +79 -48
  172. package/src/layout/footer/footer.stories.tsx +30 -0
  173. package/src/layout/stack/stack.stories.tsx +68 -44
  174. package/src/ui/alert/alert.stories.tsx +25 -21
  175. package/src/ui/button/button.stories.tsx +181 -176
  176. package/src/ui/button/button.tsx +8 -1
  177. package/src/ui/container/container.stories.tsx +28 -21
  178. package/src/ui/control-group/control-group.stories.tsx +23 -16
  179. package/src/ui/dialog/dialog.module.css +22 -0
  180. package/src/ui/dialog/dialog.tsx +9 -2
  181. package/src/ui/dropdown/dropdown.module.css +11 -0
  182. package/src/ui/dropdown/dropdown.stories.tsx +23 -15
  183. package/src/ui/dropdown/dropdown.tsx +5 -1
  184. package/src/ui/empty-set/empty-set.jsx +16 -4
  185. package/src/ui/empty-set/empty-set.stories.tsx +41 -0
  186. package/src/ui/file-name/file-name.stories.tsx +45 -0
  187. package/src/ui/filters/filters.stories.tsx +29 -26
  188. package/src/ui/hover-card/hover-card.module.css +14 -0
  189. package/src/ui/hover-card/hover-card.stories.tsx +35 -26
  190. package/src/ui/hover-card/hover-card.tsx +1 -1
  191. package/src/ui/icon/icon.stories.tsx +36 -28
  192. package/src/ui/input/input.stories.tsx +17 -5
  193. package/src/ui/input-search/input-search.stories.tsx +31 -0
  194. package/src/ui/loader/loader.stories.tsx +22 -0
  195. package/src/ui/skeleton/skeleton.stories.tsx +42 -0
  196. package/src/ui/table/table.module.css +0 -1
  197. package/src/ui/table/table.stories.tsx +244 -218
  198. package/src/ui/tag/tag.stories.tsx +11 -10
  199. package/src/ui/toolbar/toolbar.stories.tsx +41 -0
  200. package/src/ui/tooltip/tooltip.module.css +11 -0
  201. package/src/ui/tooltip/tooltip.tsx +1 -1
  202. package/types/components/bundle-modules/bundle-modules.d.ts +1 -1
  203. package/types/components/bundle-modules/index.d.ts +2 -1
  204. package/types/components/delta/delta.d.ts +7 -21
  205. package/types/components/delta/index.d.ts +1 -1
  206. package/types/components/index.d.ts +25 -20
  207. package/types/components/metric-change-legend/index.d.ts +1 -0
  208. package/types/components/metric-change-legend/metric-change-legend.d.ts +4 -0
  209. package/types/components/metric-run-info/metric-run-info.d.ts +2 -6
  210. package/types/components/metrics-table/metrics-table.d.ts +1 -1
  211. package/types/components/metrics-table-header/metrics-table-header.d.ts +1 -1
  212. package/types/components/run-info/run-info.d.ts +16 -7
  213. package/types/constants.d.ts +12 -0
  214. package/types/hooks/rows-sort.d.ts +2 -2
  215. package/types/ui/button/button.d.ts +1 -1
  216. package/types/ui/dialog/dialog.d.ts +3 -2
  217. package/types/ui/dropdown/dropdown.d.ts +1 -0
  218. package/vitest.config.ts +47 -0
  219. package/vitest.setup.ts +26 -0
  220. package/lib/assets/icons.svg.js +0 -100
  221. package/lib/assets/icons.svg.js.map +0 -1
  222. package/lib-esm/assets/icons.svg.js +0 -63
  223. package/lib-esm/assets/icons.svg.js.map +0 -1
  224. package/src/assets/icons.svg.jsx +0 -279
  225. package/src/components/delta/delta.jsx +0 -22
  226. package/types/assets/icons.svg.d.ts +0 -2
  227. /package/src/components/delta/{index.js → index.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  .title {
2
- color: var(--color-text-ultra-light);
2
+ color: var(--color-text-light);
3
3
  font-weight: bold;
4
4
  font-size: var(--size-xsmall);
5
5
  text-transform: uppercase;
@@ -16,14 +16,11 @@
16
16
 
17
17
  .titleIcon {
18
18
  flex: 0 0 var(--space-small);
19
+ /* compensate for the button icon spacing */
19
20
  margin-top: -3px !important;
20
21
  margin-bottom: -3px !important;
21
22
  }
22
23
 
23
- .title + .info {
24
- margin-top: var(--space-xxsmall);
25
- }
26
-
27
24
  .currentMetric {
28
25
  color: var(--color-heading);
29
26
  white-space: nowrap;
@@ -32,33 +29,32 @@
32
29
  height: var(--line-height-number);
33
30
  }
34
31
 
35
- .delta {
36
- font-weight: bold;
37
- }
38
-
39
- .deltaValue + .deltaValue::before {
40
- margin-left: calc(var(--space-xxxsmall) / 2);
41
- margin-right: calc(var(--space-xxxsmall) / 2);
42
- content: '/';
43
- color: var(--color-text-ultra-light);
44
- }
45
-
46
32
  .baselineMetric {
47
33
  color: var(--color-text-ultra-light);
48
34
  font-size: var(--size-small);
35
+ font-family: var(--font-family-fixed);
36
+ font-weight: normal;
49
37
  line-height: var(--line-height-number);
50
38
  height: var(--line-height-number);
51
39
  }
52
40
 
53
- /* Loading state */
54
- .loading.currentMetric {
55
- min-width: 0;
56
- max-width: 8em;
41
+ .baselineMetricValue {
42
+ color: var(--color-text-light);
43
+ line-height: inherit;
57
44
  }
58
45
 
59
- .loading.baselineMetric {
60
- min-width: 0;
61
- max-width: 8em;
46
+
47
+ .delta {
48
+ font-weight: bold;
49
+ font-size: var(--size-small);
50
+ line-height: var(--line-height-number);
51
+ }
52
+
53
+ .deltaValue + .deltaValue::before {
54
+ margin-left: var(--space-xxxsmall);
55
+ margin-right: var(--space-xxxsmall);
56
+ content: '/';
57
+ color: var(--color-outline-dark);
62
58
  }
63
59
 
64
60
  /* Hover state */
@@ -82,15 +78,28 @@
82
78
  visibility 0s;
83
79
  }
84
80
 
85
- /* Size variation */
86
- .currentMetric {
87
- font-size: var(--size-xxlarge);
81
+ /* Loading state */
82
+ .loading .currentMetric {
83
+ max-width: 6em;
88
84
  }
89
85
 
86
+ .loading .baselineMetric {
87
+ max-width: 6em;
88
+ }
89
+
90
+ .loading .delta {
91
+ max-width: 12em;
92
+ }
93
+
94
+ /* Size variation */
90
95
  .small .currentMetric {
91
96
  font-size: var(--size-medium);
92
97
  }
93
98
 
99
+ .currentMetric {
100
+ font-size: var(--size-xxlarge);
101
+ }
102
+
94
103
  .large .currentMetric {
95
104
  font-size: var(--size-xxxlarge);
96
105
  }
@@ -1,65 +1,73 @@
1
- import React from 'react';
2
- import { Meta, Story } from '@storybook/react';
1
+ import type { Meta, StoryObj } from '@storybook/react';
3
2
 
4
3
  import { RunInfo } from './run-info';
5
4
 
6
- export default {
5
+ const meta = {
7
6
  title: 'Components/RunInfo',
8
7
  component: RunInfo,
9
8
  args: {
9
+ id: 'webpack.totalSizeByTypeALL',
10
10
  size: 'medium',
11
+ loading: false,
12
+ showBaseline: true,
13
+ showDelta: true,
11
14
  },
12
15
  argTypes: {
13
16
  size: {
14
17
  options: ['small', 'medium', 'large', 'xlarge'],
15
18
  control: { type: 'select' },
16
19
  },
20
+ loading: {
21
+ control: { type: 'boolean' },
22
+ },
23
+ showBaseline: {
24
+ control: { type: 'boolean' },
25
+ },
26
+ showDelta: {
27
+ control: { type: 'boolean' },
28
+ },
17
29
  },
18
- } as Meta;
19
-
20
- const Template: Story = (args) => <RunInfo id="webpack.totalSizeByTypeALL" {...args} />;
21
-
22
- export const Default = Template.bind({});
30
+ } satisfies Meta<typeof RunInfo>;
23
31
 
24
- Default.args = {
25
- title: 'Bundle Size',
26
- current: '120KiB',
27
- baseline: '100KiB',
28
- delta: '+20%',
29
- deltaType: 'HIGH_NEGATIVE',
30
- };
32
+ export default meta;
31
33
 
32
- export const DeltaPercentage = Template.bind({});
34
+ type Story = StoryObj<typeof meta>;
33
35
 
34
- DeltaPercentage.args = {
35
- ...Default.args,
36
- deltaPercentage: '+20KiB',
36
+ export const Default: Story = {
37
+ args: {
38
+ title: 'Bundle Size',
39
+ current: '678.91MiB',
40
+ baseline: '123.45MiB',
41
+ delta: '+555.46MiB',
42
+ deltaPercentage: '+549.94%',
43
+ deltaType: 'HIGH_NEGATIVE',
44
+ },
37
45
  };
38
46
 
39
- export const SizeLarge = Template.bind({});
40
-
41
- SizeLarge.args = {
42
- ...Default.args,
43
- size: 'large',
47
+ export const SizeLarge: Story = {
48
+ args: {
49
+ ...Default.args,
50
+ size: 'large',
51
+ },
44
52
  };
45
53
 
46
- export const TitleHoverCard = Template.bind({});
47
-
48
- TitleHoverCard.args = {
49
- ...Default.args,
50
- titleHoverCard: 'Info',
54
+ export const TitleHoverCard: Story = {
55
+ args: {
56
+ ...Default.args,
57
+ titleHoverCard: 'Info',
58
+ },
51
59
  };
52
60
 
53
- export const TitleTooltip = Template.bind({});
54
-
55
- TitleTooltip.args = {
56
- ...Default.args,
57
- titleTooltip: 'Info',
61
+ export const TitleTooltip: Story = {
62
+ args: {
63
+ ...Default.args,
64
+ titleTooltip: 'Info',
65
+ },
58
66
  };
59
67
 
60
- export const Loading = Template.bind({});
61
-
62
- Loading.args = {
63
- title: 'Bundle Size',
64
- loading: true,
68
+ export const Loading: Story = {
69
+ args: {
70
+ title: 'Bundle Size',
71
+ loading: true,
72
+ },
65
73
  };
@@ -1,5 +1,6 @@
1
1
  import React, { type ReactNode, useMemo } from 'react';
2
2
  import cx from 'classnames';
3
+ import type { MetricRunInfoDeltaType } from '@bundle-stats/utils';
3
4
 
4
5
  import { Icon } from '../../ui/icon';
5
6
  import { HoverCard } from '../../ui/hover-card';
@@ -24,23 +25,125 @@ const getMetricParams = (value: string): [string, string?] => {
24
25
  return [matches[1], matches[2]];
25
26
  };
26
27
 
27
- export interface RunInfoProps {
28
+ type RunInfoTitleProps = {
29
+ className?: string;
28
30
  title?: ReactNode;
29
31
  titleHoverCard?: ReactNode;
30
32
  titleTooltip?: ReactNode;
33
+ };
34
+
35
+ const RunInfoTitle = ({ className, title, titleHoverCard, titleTooltip }: RunInfoTitleProps) => (
36
+ <FlexStack space="xxxsmall" alignItems="center" as="h3" className={cx(css.title, className)}>
37
+ <span className={css.titleText}>{title}</span>
38
+ {titleHoverCard && (
39
+ <HoverCard
40
+ label={<Icon glyph={Icon.ICONS.HELP} />}
41
+ className={cx(css.titleIcon, css.titleHoverCardIcon)}
42
+ >
43
+ {titleHoverCard}
44
+ </HoverCard>
45
+ )}
46
+ {titleTooltip && (
47
+ <Tooltip title={titleTooltip} className={cx(css.titleIcon, css.titleTooltipIcon)}>
48
+ <Icon glyph={Icon.ICONS.HELP} />
49
+ </Tooltip>
50
+ )}
51
+ </FlexStack>
52
+ );
53
+
54
+ type RunInfoContentProps = {
55
+ className?: string;
56
+ loading?: boolean;
31
57
  current?: ReactNode;
58
+ enhance?: boolean;
32
59
  baseline?: string;
33
60
  delta?: string;
34
61
  deltaPercentage?: string;
35
- deltaType?: string;
62
+ deltaType?: MetricRunInfoDeltaType;
63
+ showBaseline?: boolean;
64
+ showDelta?: boolean;
65
+ };
36
66
 
37
- as?: React.ElementType;
38
- size?: 'small' | 'medium' | 'large' | 'xlarge';
67
+ const RunInfoContent = ({
68
+ className,
69
+ loading = false,
70
+ current = '',
71
+ enhance = false,
72
+ baseline = '',
73
+ delta = '',
74
+ deltaPercentage = '',
75
+ deltaType = 'NO_CHANGE',
76
+ showBaseline = true,
77
+ showDelta = true,
78
+ }: RunInfoContentProps) => {
79
+ const currentValueParams: [ReactNode, string?] = useMemo(() => {
80
+ if (!enhance || typeof current !== 'string') {
81
+ return [current];
82
+ }
39
83
 
40
- showBaseline?: boolean;
41
- loading?: boolean;
42
- enhance?: boolean;
43
- }
84
+ return getMetricParams(current);
85
+ }, [current, enhance]);
86
+
87
+ const contentClassName = cx(css.content, className);
88
+
89
+ if (loading) {
90
+ return (
91
+ <Stack space="xxxsmall" className={contentClassName}>
92
+ <Skeleton className={css.currentMetric} />
93
+ {showBaseline && <Skeleton className={css.baselineMetric} />}
94
+ </Stack>
95
+ );
96
+ }
97
+
98
+ return (
99
+ <Stack space="xxxsmall" className={contentClassName}>
100
+ <Metric
101
+ value={currentValueParams[0]}
102
+ unit={currentValueParams[1]}
103
+ inline
104
+ className={css.currentMetric}
105
+ >
106
+ {showDelta && (
107
+ <div className={css.delta}>
108
+ {deltaPercentage && (
109
+ <Delta
110
+ displayValue={deltaPercentage}
111
+ deltaType={deltaType}
112
+ className={css.deltaValue}
113
+ />
114
+ )}
115
+ {delta && (
116
+ <Delta displayValue={delta} deltaType={deltaType} className={css.deltaValue} />
117
+ )}
118
+ </div>
119
+ )}
120
+ </Metric>
121
+ {showBaseline && (
122
+ <FlexStack alignItems="center" space="xxxsmall" className={css.baselineMetric}>
123
+ <span className={css.baselineMetricLabel}>vs</span>
124
+ <Metric value={baseline} inline className={css.baselineMetricValue} />
125
+ </FlexStack>
126
+ )}
127
+ </Stack>
128
+ );
129
+ };
130
+
131
+ export type RunInfoProps = Pick<RunInfoTitleProps, 'title' | 'titleHoverCard' | 'titleTooltip'> &
132
+ Pick<
133
+ RunInfoContentProps,
134
+ | 'current'
135
+ | 'baseline'
136
+ | 'delta'
137
+ | 'deltaPercentage'
138
+ | 'deltaType'
139
+ | 'showBaseline'
140
+ | 'showDelta'
141
+ | 'loading'
142
+ | 'enhance'
143
+ > & {
144
+ as?: React.ElementType;
145
+ size?: 'small' | 'medium' | 'large' | 'xlarge';
146
+ };
44
147
 
45
148
  export const RunInfo = ({
46
149
  className = '',
@@ -51,81 +154,37 @@ export const RunInfo = ({
51
154
  baseline = '',
52
155
  delta = '',
53
156
  deltaPercentage = '',
54
- deltaType = '',
157
+ deltaType = 'NO_CHANGE',
55
158
  as: Component = 'div',
56
159
  size = 'medium',
57
160
  showBaseline = true,
161
+ showDelta = true,
58
162
  loading = false,
59
163
  enhance = false,
164
+ children,
60
165
  ...restProps
61
166
  }: RunInfoProps & Omit<React.ComponentProps<'div'>, 'title'>) => {
62
- const rootClassName = cx(
63
- css.root,
64
- className,
65
- css[size],
66
- (delta || deltaPercentage) && css.showDelta,
67
- );
68
-
69
- const currentValueParams: [ReactNode, string?] = useMemo(() => {
70
- if (!enhance || typeof current !== 'string') {
71
- return [current];
72
- }
73
-
74
- return getMetricParams(current);
75
- }, [current, enhance]);
167
+ const rootClassName = cx(css.root, loading && css.loading, css[size], className);
76
168
 
77
169
  return (
78
170
  <Component className={rootClassName} {...restProps}>
79
- {title && (
80
- <FlexStack space="xxxsmall" alignItems="center" as="h3" className={css.title}>
81
- <span className={css.titleText}>{title}</span>
82
- {titleHoverCard && (
83
- <HoverCard
84
- label={<Icon glyph={Icon.ICONS.HELP} />}
85
- className={cx(css.titleIcon, css.titleHoverCardIcon)}
86
- >
87
- {titleHoverCard}
88
- </HoverCard>
89
- )}
90
- {titleTooltip && (
91
- <Tooltip title={titleTooltip} className={cx(css.titleIcon, css.titleTooltipIcon)}>
92
- <Icon glyph={Icon.ICONS.HELP} />
93
- </Tooltip>
94
- )}
95
- </FlexStack>
96
- )}
97
-
98
- {!loading ? (
99
- <Stack space="xxxsmall" className={css.info}>
100
- <Metric
101
- value={currentValueParams[0]}
102
- unit={currentValueParams[1]}
103
- inline
104
- className={css.currentMetric}
105
- >
106
- {(delta || deltaPercentage) && (
107
- <span className={css.delta}>
108
- {deltaPercentage && (
109
- <Delta
110
- displayValue={deltaPercentage}
111
- deltaType={deltaType}
112
- className={css.deltaValue}
113
- />
114
- )}
115
- {delta && (
116
- <Delta displayValue={delta} deltaType={deltaType} className={css.deltaValue} />
117
- )}
118
- </span>
119
- )}
120
- </Metric>
121
- {showBaseline && <Metric className={css.baselineMetric} value={baseline} />}
122
- </Stack>
123
- ) : (
124
- <Stack space="xxxsmall" className={css.info}>
125
- <Skeleton className={cx(css.currentMetric, css.loading)} />
126
- {showBaseline && <Skeleton as="p" className={cx(css.baselineMetric, css.loading)} />}
127
- </Stack>
128
- )}
171
+ <Stack space="xsmall">
172
+ {title && (
173
+ <RunInfoTitle title={title} titleHoverCard={titleHoverCard} titleTooltip={titleTooltip} />
174
+ )}
175
+ <RunInfoContent
176
+ loading={loading}
177
+ current={current}
178
+ enhance={enhance}
179
+ baseline={baseline}
180
+ delta={delta}
181
+ deltaPercentage={deltaPercentage}
182
+ deltaType={deltaType}
183
+ showBaseline={showBaseline}
184
+ showDelta={showDelta}
185
+ />
186
+ {children}
187
+ </Stack>
129
188
  </Component>
130
189
  );
131
190
  };
@@ -3,29 +3,79 @@
3
3
  width: 100%;
4
4
  }
5
5
 
6
- .wrapper {
6
+ .row {
7
7
  width: 100%;
8
+ display: flex;
9
+ align-items: stretch;
10
+ flex-wrap: wrap;
11
+ gap: var(--space-small);
12
+ }
13
+
14
+ .rowGroup {
15
+ flex: 1 1 auto;
8
16
  }
9
17
 
10
- .wrapper + .wrapper {
18
+ .rowGroupTitle {
19
+ position: absolute;
20
+ font-size: 0;
21
+ width: 0;
22
+ left: -99999px;
23
+ }
24
+
25
+ .row + .row {
11
26
  margin-top: var(--summary-gap);
12
27
  }
13
28
 
14
29
  .items {
15
30
  display: flex;
31
+ align-items: stretch;
16
32
  flex-wrap: wrap;
17
- width: calc(100% + var(--summary-gap));
18
- margin-top: calc(0px - var(--summary-gap));
19
- margin-left: calc(0px - var(--summary-gap));
33
+ gap: var(--space-medium);
20
34
  }
21
35
 
22
36
  .item {
23
- margin: var(--summary-gap) 0 0 var(--summary-gap);
24
- flex: 1 0 10%; /* force equal sizes */
25
- min-width: 12em;
37
+ flex: 1 1 10%; /* force equal sizes */
38
+ min-width: 8em;
26
39
  text-decoration: none;
40
+ position: relative;
41
+ z-index: 0;
27
42
  }
28
43
 
29
- .itemSmall {
30
- min-width: 8em;
44
+ .item::before {
45
+ content: "";
46
+ border-radius: var(--radius-medium);
47
+ background: var(--color-highlight);
48
+ display: block;
49
+ position: absolute;
50
+ z-index: -1;
51
+ top: calc(0px - var(--space-xsmall));
52
+ right: calc(0px - var(--space-xsmall));
53
+ bottom: calc(0px - var(--space-xsmall));
54
+ left: calc(0px - var(--space-xsmall));
55
+ opacity: 0;
56
+ transition: var(--transition-out);
57
+ }
58
+
59
+ .item:hover::before {
60
+ opacity: 1;
61
+ transition: var(--transition-in);
62
+ }
63
+
64
+ .item + .item::after {
65
+ content: "";
66
+ border-radius: var(--radius-medium);
67
+ background: var(--color-outline);
68
+ display: block;
69
+ width: 1px;
70
+ position: absolute;
71
+ left: calc(0px - var(--space-xsmall));
72
+ top: var(--space-xxsmall);
73
+ bottom: var(--space-xxsmall);
74
+ opacity: 1;
75
+ transition: var(--transition-out);
76
+ }
77
+
78
+ .item:hover::after, .item:hover + .item::after {
79
+ opacity: 0;
80
+ transition: var(--transition-in);
31
81
  }
@@ -1,12 +1,11 @@
1
1
  import React from 'react';
2
- import { Meta, Story } from '@storybook/react';
2
+ import type { Meta, StoryObj } from '@storybook/react';
3
3
  import { createJobs } from '@bundle-stats/utils';
4
4
 
5
5
  /* eslint-disable import/no-relative-packages */
6
6
  import baselineData from '../../../../../fixtures/webpack-stats.baseline.json';
7
7
  import currentData from '../../../../../fixtures/webpack-stats.current.json';
8
8
  /* eslint-enable import/no-relative-packages */
9
- import { METRICS_WEBPACK_ASSETS } from '../../constants';
10
9
  import { getWrapperDecorator } from '../../stories';
11
10
  import { Summary } from '.';
12
11
 
@@ -14,46 +13,41 @@ const MULTIPLE_JOBS = createJobs([{ webpack: currentData }, { webpack: baselineD
14
13
 
15
14
  const SINGLE_JOB = createJobs([{ webpack: currentData }]);
16
15
 
17
- export default {
16
+ const meta = {
18
17
  title: 'Components/Summary',
19
18
  component: Summary,
20
19
  decorators: [getWrapperDecorator()],
21
- } as Meta;
20
+ } satisfies Meta<typeof Summary>;
22
21
 
23
- const Template: Story = (args) => <Summary {...args} />;
22
+ export default meta;
24
23
 
25
- export const Default = Template.bind({});
24
+ type Story = StoryObj<typeof meta>;
26
25
 
27
- Default.args = {
28
- data: MULTIPLE_JOBS[0].summary,
26
+ export const Default: Story = {
27
+ args: {
28
+ data: MULTIPLE_JOBS[0].summary!.webpack,
29
+ },
29
30
  };
30
31
 
31
- export const CustomKeys = Template.bind({});
32
-
33
- CustomKeys.args = {
34
- keys: METRICS_WEBPACK_ASSETS,
35
- data: MULTIPLE_JOBS[0].summary,
36
- };
37
-
38
- export const Loading = Template.bind({});
39
-
40
- Loading.args = {
41
- loading: true,
32
+ export const Loading: Story = {
33
+ args: {
34
+ loading: true,
35
+ },
42
36
  };
43
37
 
44
- export const SingleRun = Template.bind({});
45
-
46
- SingleRun.args = {
47
- data: SINGLE_JOB[0].summary,
48
- showSummaryItemDelta: false,
49
- showSummaryItemBaseline: false,
38
+ export const SingleRun: Story = {
39
+ args: {
40
+ data: SINGLE_JOB[0].summary!.webpack,
41
+ showSummaryItemDelta: false,
42
+ showSummaryItemBaseline: false,
43
+ },
50
44
  };
51
45
 
52
- export const WithLink = Template.bind({});
53
-
54
- WithLink.args = {
55
- data: MULTIPLE_JOBS[0].summary,
56
- summaryItemLink: (linkProps: React.ComponentProps<'button'>) => (
57
- <button {...linkProps} type="button" onClick={() => alert(JSON.stringify(linkProps))} />
58
- ),
46
+ export const WithLink: Story = {
47
+ args: {
48
+ data: MULTIPLE_JOBS[0].summary!.webpack,
49
+ summaryItemLink: (linkProps) => (
50
+ <button {...linkProps} type="button" onClick={() => alert(JSON.stringify(linkProps))} />
51
+ ),
52
+ },
59
53
  };