@bundle-stats/ui 4.0.3 → 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 (31) hide show
  1. package/lib/components/metric/metric.js +40 -25
  2. package/lib/components/metric/metric.module.css +4 -14
  3. package/lib/components/summary-item/summary-item.js +1 -1
  4. package/lib/components/summary-item/summary-item.module.css +0 -9
  5. package/lib/ui/dropdown/dropdown.module.css +3 -2
  6. package/lib/ui/filters/filters.js +11 -8
  7. package/lib/ui/filters/filters.module.css +11 -12
  8. package/lib/ui/hover-card/hover-card.js +2 -1
  9. package/lib/ui/sort-dropdown/sort-dropdown.js +90 -30
  10. package/lib/ui/sort-dropdown/sort-dropdown.module.css +5 -3
  11. package/lib-esm/components/metric/metric.js +40 -15
  12. package/lib-esm/components/metric/metric.module.css +4 -14
  13. package/lib-esm/components/summary-item/summary-item.js +1 -1
  14. package/lib-esm/components/summary-item/summary-item.module.css +0 -9
  15. package/lib-esm/ui/dropdown/dropdown.module.css +3 -2
  16. package/lib-esm/ui/filters/filters.js +9 -7
  17. package/lib-esm/ui/filters/filters.module.css +11 -12
  18. package/lib-esm/ui/hover-card/hover-card.js +2 -1
  19. package/lib-esm/ui/sort-dropdown/sort-dropdown.js +72 -23
  20. package/lib-esm/ui/sort-dropdown/sort-dropdown.module.css +5 -3
  21. package/package.json +5 -5
  22. package/src/components/metric/metric.jsx +32 -24
  23. package/src/components/metric/metric.module.css +4 -14
  24. package/src/components/summary-item/summary-item.jsx +1 -1
  25. package/src/components/summary-item/summary-item.module.css +0 -9
  26. package/src/ui/dropdown/dropdown.module.css +3 -2
  27. package/src/ui/filters/filters.jsx +24 -18
  28. package/src/ui/filters/filters.module.css +11 -12
  29. package/src/ui/hover-card/hover-card.jsx +1 -1
  30. package/src/ui/sort-dropdown/sort-dropdown.jsx +70 -27
  31. package/src/ui/sort-dropdown/sort-dropdown.module.css +5 -3
@@ -1,5 +1,9 @@
1
1
  /* Checkbox + label + button */
2
2
  .filter {
3
+ /* Update MenuItem padding */
4
+ padding-top: calc(var(--space-xxxsmall) / 2);
5
+ padding-bottom: calc(var(--space-xxxsmall) / 2);
6
+
3
7
  position: relative;
4
8
  width: 100%;
5
9
  max-width: 240px;
@@ -11,7 +15,6 @@
11
15
  }
12
16
 
13
17
  .filterInput {
14
- border-radius: var(--radius-small) 0 0 var(--radius-small);
15
18
  flex: 0 0 auto;
16
19
  height: 1em;
17
20
  cursor: pointer;
@@ -26,17 +29,17 @@
26
29
  }
27
30
 
28
31
  .filterOnlyButton {
29
- padding: var(--space-xxsmall);
32
+ padding: var(--space-xxxsmall) var(--space-xsmall);
30
33
  display: none;
31
34
  appearance: none;
32
35
  border: none;
33
36
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255) 30%);
34
37
  cursor: pointer;
35
- line-height: 1;
36
38
  position: absolute;
37
39
  right: 0;
38
- top: 50%;
39
- transform: translateY(-50%);
40
+ top: 0;
41
+ bottom: 0;
42
+ line-height: var(--space-xsmall);
40
43
  }
41
44
 
42
45
  /** filter disabled state */
@@ -63,6 +66,7 @@
63
66
 
64
67
  /** Filter standard variation */
65
68
  .filterStandalone {
69
+ padding: 0;
66
70
  width: auto;
67
71
  color: var(--color-text-light);
68
72
  z-index: var(--layout-xlow); /* show collapsed border */
@@ -95,16 +99,11 @@
95
99
  overflow: auto;
96
100
  }
97
101
 
98
- .filterGroupItem {
99
- padding-top: 2px;
100
- padding-bottom: 2px;
101
- }
102
-
103
102
  .filterGroupActions {
104
- margin-top: var(--space-xxsmall);
103
+ margin-top: var(--space-xxxsmall);
105
104
  padding-top: var(--space-xxxsmall);
106
105
  padding-bottom: var(--space-xxxsmall);
107
- margin-bottom: calc(0px - var(--space-xsmall));
106
+ margin-bottom: calc(0px - var(--space-xxsmall));
108
107
  border-top: 1px solid var(--color-outline);
109
108
  }
110
109
 
@@ -25,7 +25,7 @@ const resolveComponent = (as, href) => {
25
25
 
26
26
  export const HoverCard = (props) => {
27
27
  const { className, anchorClassName, hoverCardClassName, href, as, label, children } = props;
28
- const state = useHovercardState({ gutter: 8 });
28
+ const state = useHovercardState({ gutter: 8, timeout: 700 });
29
29
  const hoverCardProps = useHovercard({ state, portal: true });
30
30
 
31
31
  // Fallback to span if no href
@@ -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
  }