@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.
- package/lib/components/bundle-assets/bundle-assets.js +3 -3
- package/lib/components/bundle-assets/bundle-assets.utils.js +1 -1
- package/lib/components/metric/metric.js +40 -25
- package/lib/components/metric/metric.module.css +4 -14
- package/lib/components/metrics-table-title/metrics-table-title.js +1 -1
- package/lib/components/metrics-table-title/metrics-table-title.module.css +3 -3
- package/lib/components/summary-item/summary-item.js +1 -1
- package/lib/components/summary-item/summary-item.module.css +0 -9
- package/lib/components/total-size-type-title/total-size-type-title.js +6 -3
- package/lib/components/total-size-type-title/total-size-type-title.module.css +9 -1
- package/lib/i18n.js +2 -2
- package/lib/ui/dropdown/dropdown.module.css +3 -2
- package/lib/ui/filters/filters.js +11 -8
- package/lib/ui/filters/filters.module.css +11 -12
- package/lib/ui/hover-card/hover-card.js +8 -2
- package/lib/ui/index.js +8 -0
- package/lib/ui/sort-dropdown/sort-dropdown.js +90 -30
- package/lib/ui/sort-dropdown/sort-dropdown.module.css +5 -3
- package/lib-esm/components/bundle-assets/bundle-assets.js +3 -3
- package/lib-esm/components/bundle-assets/bundle-assets.utils.js +1 -1
- package/lib-esm/components/metric/metric.js +40 -15
- package/lib-esm/components/metric/metric.module.css +4 -14
- package/lib-esm/components/metrics-table-title/metrics-table-title.js +1 -1
- package/lib-esm/components/metrics-table-title/metrics-table-title.module.css +3 -3
- package/lib-esm/components/summary-item/summary-item.js +1 -1
- package/lib-esm/components/summary-item/summary-item.module.css +0 -9
- package/lib-esm/components/total-size-type-title/total-size-type-title.js +6 -3
- package/lib-esm/components/total-size-type-title/total-size-type-title.module.css +9 -1
- package/lib-esm/i18n.js +2 -2
- package/lib-esm/ui/dropdown/dropdown.module.css +3 -2
- package/lib-esm/ui/filters/filters.js +9 -7
- package/lib-esm/ui/filters/filters.module.css +11 -12
- package/lib-esm/ui/hover-card/hover-card.js +8 -2
- package/lib-esm/ui/index.js +1 -0
- package/lib-esm/ui/sort-dropdown/sort-dropdown.js +72 -23
- package/lib-esm/ui/sort-dropdown/sort-dropdown.module.css +5 -3
- package/package.json +8 -8
- package/src/components/bundle-assets/bundle-assets.jsx +3 -3
- package/src/components/bundle-assets/bundle-assets.utils.js +1 -1
- package/src/components/metric/metric.jsx +32 -24
- package/src/components/metric/metric.module.css +4 -14
- package/src/components/metrics-table-title/metrics-table-title.jsx +1 -1
- package/src/components/metrics-table-title/metrics-table-title.module.css +3 -3
- package/src/components/summary-item/summary-item.jsx +1 -1
- package/src/components/summary-item/summary-item.module.css +0 -9
- package/src/components/total-size-type-title/total-size-type-title.jsx +3 -3
- package/src/components/total-size-type-title/total-size-type-title.module.css +9 -1
- package/src/i18n.js +2 -2
- package/src/ui/dropdown/dropdown.module.css +3 -2
- package/src/ui/filters/filters.jsx +24 -18
- package/src/ui/filters/filters.module.css +11 -12
- package/src/ui/hover-card/hover-card.jsx +11 -3
- package/src/ui/index.js +1 -0
- package/src/ui/sort-dropdown/sort-dropdown.jsx +70 -27
- 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
|
-
<
|
|
88
|
+
<Item
|
|
42
89
|
key={key}
|
|
43
|
-
{
|
|
44
|
-
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
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
|
-
.
|
|
19
|
-
|
|
20
|
+
.itemActive .itemIcon {
|
|
21
|
+
visibility: visible;
|
|
20
22
|
}
|