@bundle-stats/ui 4.0.0 → 4.0.4

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 (55) hide show
  1. package/lib/components/bundle-assets/bundle-assets.js +3 -3
  2. package/lib/components/bundle-assets/bundle-assets.utils.js +1 -1
  3. package/lib/components/metric/metric.js +40 -25
  4. package/lib/components/metric/metric.module.css +4 -14
  5. package/lib/components/metrics-table-title/metrics-table-title.js +1 -1
  6. package/lib/components/metrics-table-title/metrics-table-title.module.css +3 -3
  7. package/lib/components/summary-item/summary-item.js +1 -1
  8. package/lib/components/summary-item/summary-item.module.css +0 -9
  9. package/lib/components/total-size-type-title/total-size-type-title.js +6 -3
  10. package/lib/components/total-size-type-title/total-size-type-title.module.css +9 -1
  11. package/lib/i18n.js +2 -2
  12. package/lib/ui/dropdown/dropdown.module.css +3 -2
  13. package/lib/ui/filters/filters.js +11 -8
  14. package/lib/ui/filters/filters.module.css +11 -12
  15. package/lib/ui/hover-card/hover-card.js +8 -2
  16. package/lib/ui/index.js +8 -0
  17. package/lib/ui/sort-dropdown/sort-dropdown.js +90 -30
  18. package/lib/ui/sort-dropdown/sort-dropdown.module.css +5 -3
  19. package/lib-esm/components/bundle-assets/bundle-assets.js +3 -3
  20. package/lib-esm/components/bundle-assets/bundle-assets.utils.js +1 -1
  21. package/lib-esm/components/metric/metric.js +40 -15
  22. package/lib-esm/components/metric/metric.module.css +4 -14
  23. package/lib-esm/components/metrics-table-title/metrics-table-title.js +1 -1
  24. package/lib-esm/components/metrics-table-title/metrics-table-title.module.css +3 -3
  25. package/lib-esm/components/summary-item/summary-item.js +1 -1
  26. package/lib-esm/components/summary-item/summary-item.module.css +0 -9
  27. package/lib-esm/components/total-size-type-title/total-size-type-title.js +6 -3
  28. package/lib-esm/components/total-size-type-title/total-size-type-title.module.css +9 -1
  29. package/lib-esm/i18n.js +2 -2
  30. package/lib-esm/ui/dropdown/dropdown.module.css +3 -2
  31. package/lib-esm/ui/filters/filters.js +9 -7
  32. package/lib-esm/ui/filters/filters.module.css +11 -12
  33. package/lib-esm/ui/hover-card/hover-card.js +8 -2
  34. package/lib-esm/ui/index.js +1 -0
  35. package/lib-esm/ui/sort-dropdown/sort-dropdown.js +72 -23
  36. package/lib-esm/ui/sort-dropdown/sort-dropdown.module.css +5 -3
  37. package/package.json +8 -8
  38. package/src/components/bundle-assets/bundle-assets.jsx +3 -3
  39. package/src/components/bundle-assets/bundle-assets.utils.js +1 -1
  40. package/src/components/metric/metric.jsx +32 -24
  41. package/src/components/metric/metric.module.css +4 -14
  42. package/src/components/metrics-table-title/metrics-table-title.jsx +1 -1
  43. package/src/components/metrics-table-title/metrics-table-title.module.css +3 -3
  44. package/src/components/summary-item/summary-item.jsx +1 -1
  45. package/src/components/summary-item/summary-item.module.css +0 -9
  46. package/src/components/total-size-type-title/total-size-type-title.jsx +3 -3
  47. package/src/components/total-size-type-title/total-size-type-title.module.css +9 -1
  48. package/src/i18n.js +2 -2
  49. package/src/ui/dropdown/dropdown.module.css +3 -2
  50. package/src/ui/filters/filters.jsx +24 -18
  51. package/src/ui/filters/filters.module.css +11 -12
  52. package/src/ui/hover-card/hover-card.jsx +11 -3
  53. package/src/ui/index.js +1 -0
  54. package/src/ui/sort-dropdown/sort-dropdown.jsx +70 -27
  55. package/src/ui/sort-dropdown/sort-dropdown.module.css +5 -3
package/src/ui/index.js CHANGED
@@ -5,6 +5,7 @@ export { EmptySet } from './empty-set';
5
5
  export { FileName } from './file-name';
6
6
  export { Filters } from './filters';
7
7
  export { HorizontalBarChart } from './horizontal-bar-chart';
8
+ export { HoverCard } from './hover-card';
8
9
  export { Icon } from './icon';
9
10
  export { Input } from './input';
10
11
  export { Loader } from './loader';
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useMemo } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import cx from 'classnames';
4
4
 
@@ -6,6 +6,65 @@ import { Dropdown } from '../dropdown';
6
6
  import { Icon } from '../icon';
7
7
  import css from './sort-dropdown.module.css';
8
8
 
9
+ const Item = ({
10
+ className,
11
+ as: Component,
12
+ id,
13
+ label,
14
+ active,
15
+ direction,
16
+ defaultDirection,
17
+ getButtonOnClick,
18
+ ...restProps }) => {
19
+
20
+ const buttonProps = useMemo(() => {
21
+ let resolveNextDirection = defaultDirection;
22
+
23
+ if (active) {
24
+ resolveNextDirection = direction === 'asc' ? 'desc' : 'asc';
25
+ }
26
+
27
+ if (resolveNextDirection === 'desc') {
28
+ return {
29
+ className: css.itemAsc,
30
+ onClick: getButtonOnClick(id, 'desc'),
31
+ title: `Order data by ${label} descending`,
32
+ };
33
+ }
34
+
35
+ return {
36
+ onClick: getButtonOnClick(id, 'asc'),
37
+ title: `Order data by ${label} ascending`,
38
+ };
39
+ }, [active, direction, defaultDirection, id, label]);
40
+
41
+ return (
42
+ <Component
43
+ {...restProps}
44
+ {...buttonProps}
45
+ className={cx(className, css.item, active && css.itemActive, buttonProps.className)}
46
+ >
47
+ <Icon className={css.itemIcon} glyph="arrow" />
48
+ <span className={css.itemLabel}>{label}</span>
49
+ </Component>
50
+ );
51
+ };
52
+
53
+ Item.propTypes = {
54
+ className: PropTypes.string,
55
+ as: PropTypes.element.isRequired,
56
+ id: PropTypes.string.isRequired,
57
+ label: PropTypes.string.isRequired,
58
+ active: PropTypes.bool.isRequired,
59
+ direction: PropTypes.string.isRequired,
60
+ defaultDirection: PropTypes.string.isRequired,
61
+ getButtonOnClick: PropTypes.func.isRequired,
62
+ };
63
+
64
+ Item.defaultProps = {
65
+ className: '',
66
+ };
67
+
9
68
  export const SortDropdown = (props) => {
10
69
  const { className, label, fields, field, direction, onChange } = props;
11
70
  const rootClassName = cx(css.root, className);
@@ -23,36 +82,20 @@ export const SortDropdown = (props) => {
23
82
  return (
24
83
  <div className={css.items}>
25
84
  {Object.entries(fields).map(([key, item]) => {
26
- const buttonProps =
27
- direction === 'asc'
28
- ? {
29
- className: css.itemAsc,
30
- onClick: getButtonOnClick(key, 'desc'),
31
- title: `Order data by ${item.label} descending`,
32
- }
33
- : {
34
- onClick: getButtonOnClick(key, 'asc'),
35
- title: `Order data by ${item.label} ascending`,
36
- };
37
-
38
85
  const isActive = field === key;
39
86
 
40
87
  return (
41
- <MenuItem
88
+ <Item
42
89
  key={key}
43
- {...menu}
44
- {...buttonProps}
45
- className={cx(
46
- buttonProps.className,
47
- menuItemClassName,
48
- css.item,
49
- isActive && menuItemActiveClassName,
50
- isActive && css.active,
51
- )}
52
- >
53
- <span className={css.itemLabel}>{item.label}</span>
54
- <Icon className={css.itemIcon} glyph="arrow" />
55
- </MenuItem>
90
+ as={MenuItem}
91
+ className={cx(menuItemClassName, isActive && menuItemActiveClassName)}
92
+ id={key}
93
+ label={item.label}
94
+ direction={direction}
95
+ defaultDirection={item.defaultDirection}
96
+ active={isActive}
97
+ getButtonOnClick={getButtonOnClick}
98
+ />
56
99
  );
57
100
  })}
58
101
  </div>
@@ -4,7 +4,9 @@
4
4
  }
5
5
 
6
6
  .itemIcon {
7
- display: none;
7
+ flex: 0 0 auto;
8
+ visibility: hidden;
9
+ margin-right: var(--space-xxxsmall);
8
10
  }
9
11
 
10
12
  .itemLabel {
@@ -15,6 +17,6 @@
15
17
  transform: rotate(180deg);
16
18
  }
17
19
 
18
- .item.active .itemIcon {
19
- display: block;
20
+ .itemActive .itemIcon {
21
+ visibility: visible;
20
22
  }