@balena/ui-shared-components 12.2.0-build-add-horizontal-bar-chart-d6011a8905d18b98afdadfd7fd669fd599a42369-1 → 12.2.0-build-add-horizontal-bar-chart-a33ee389063b822f47c870ee754354c0372aa9b0-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.
@@ -1,12 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Stack, styled, Tooltip, Typography } from '@mui/material';
3
3
  import { token } from '../../utils/token';
4
+ import { useTranslation } from '../../hooks/useTranslations';
4
5
  const Bar = styled('div', {
5
6
  name: 'Bar',
6
7
  slot: 'bar',
7
8
  })({
8
9
  width: '100%',
9
- height: 30,
10
+ height: 24,
10
11
  display: 'flex',
11
12
  borderRadius: token('shape.borderRadius.sm'),
12
13
  overflow: 'hidden',
@@ -37,9 +38,17 @@ const LegendItem = styled('li')({
37
38
  },
38
39
  });
39
40
  export const HorizontalBarChart = ({ items }) => {
41
+ const { t } = useTranslation();
40
42
  const total = items.reduce((partialSum, a) => partialSum + a.count, 0);
41
- return (_jsxs(Stack, { sx: { gap: token('spacing.2') }, children: [_jsx(Bar, { children: items.map((item) => (_jsx(Tooltip, { title: `${item.title}: ${item.count} devices`, children: _jsx(BarItem, { sx: {
43
+ const getTotalDevicesLabel = (count) => count > 1
44
+ ? t('labels.total_devices_other', { count })
45
+ : t('labels.total_devices_one', { count });
46
+ return (_jsxs(Stack, { sx: { gap: token('spacing.2') }, children: [_jsx(Bar, { children: items
47
+ .filter((item) => item.count > 0)
48
+ .map((item) => (_jsx(Tooltip, { title: `${item.title}: ${getTotalDevicesLabel(item.count)}`, children: _jsx(BarItem, { sx: {
42
49
  backgroundColor: item.color,
43
50
  width: `${(item.count / total) * 100}%`,
44
- } }) }, item.title))) }), _jsx(Legend, { children: items.map((item) => (_jsx(Tooltip, { title: `${item.count} devices`, children: _jsx(LegendItem, { style: { color: item.color }, children: _jsx(Typography, { variant: "bodySm", color: token('color.text.subtle'), children: item.title }) }) }, item.title))) })] }));
51
+ } }) }, item.title))) }), _jsx(Legend, { children: items
52
+ .filter((item) => item.count > 0)
53
+ .map((item) => (_jsx(Tooltip, { title: getTotalDevicesLabel(item.count), children: _jsx(LegendItem, { style: { color: item.color }, children: _jsx(Typography, { variant: "bodySm", color: token('color.text.subtle'), children: item.title }) }) }, item.title))) })] }));
45
54
  };
@@ -59,6 +59,8 @@ const translationMap = {
59
59
  'labels.views': 'Views',
60
60
  'labels.filter_one': 'Filter',
61
61
  'labels.filter_other': 'Filters',
62
+ 'labels.total_devices_one': '{{count}} device',
63
+ 'labels.total_devices_other': '{{count}} devices',
62
64
  'labels.save_current_view': 'Save current view',
63
65
  'aria_labels.remove_view': 'Delete the selected view',
64
66
  'aria_labels.create_view': 'Create named view',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@balena/ui-shared-components",
3
- "version": "12.2.0-build-add-horizontal-bar-chart-d6011a8905d18b98afdadfd7fd669fd599a42369-1",
3
+ "version": "12.2.0-build-add-horizontal-bar-chart-a33ee389063b822f47c870ee754354c0372aa9b0-1",
4
4
  "main": "./dist/index.js",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -138,6 +138,6 @@
138
138
  },
139
139
  "homepage": "https://github.com/balena-io/ui-shared-components#readme",
140
140
  "versionist": {
141
- "publishedAt": "2025-04-10T19:39:24.632Z"
141
+ "publishedAt": "2025-04-10T20:36:44.104Z"
142
142
  }
143
143
  }