@balena/ui-shared-components 1.2.0 → 1.3.0
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/dist/components/ButtonWithTracking/index.js +2 -1
- package/dist/components/DropDownButton/DropDownButton.stories.d.ts +1 -2
- package/dist/components/DropDownButton/index.d.ts +23 -9
- package/dist/components/DropDownButton/index.js +66 -34
- package/dist/components/Tooltip/index.js +1 -1
- package/dist_esm5/components/ButtonWithTracking/index.js +2 -1
- package/dist_esm5/components/DropDownButton/DropDownButton.stories.d.ts +1 -2
- package/dist_esm5/components/DropDownButton/index.d.ts +23 -9
- package/dist_esm5/components/DropDownButton/index.js +58 -35
- package/dist_esm5/components/Tooltip/index.js +1 -1
- package/package.json +2 -2
|
@@ -21,8 +21,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
-
import { Button
|
|
24
|
+
import { Button } from '@mui/material';
|
|
25
25
|
import { useAnalyticsContext } from '../../contexts/AnalyticsContext';
|
|
26
|
+
import { Tooltip } from '../Tooltip';
|
|
26
27
|
/**
|
|
27
28
|
* This button will send analytics in case the analytics context is passed through the provider (AnalyticsProvider).
|
|
28
29
|
*/
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { StoryObj } from '@storybook/react';
|
|
3
2
|
declare const meta: {
|
|
4
3
|
title: string;
|
|
5
|
-
component: import("
|
|
4
|
+
component: <T extends unknown>({ items, selectedItemIndex, groupByProp, onClick, children, ...buttonProps }: import(".").DropDownButtonProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
6
5
|
tags: string[];
|
|
7
6
|
};
|
|
8
7
|
export default meta;
|
|
@@ -1,15 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
import { ButtonGroupProps } from '@mui/material';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ButtonGroupProps, MenuItemProps, ButtonProps } from '@mui/material';
|
|
3
|
+
type MenuItemType<T> = MenuItemWithTrackingProps & T & {
|
|
4
|
+
tooltip?: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
export interface DropDownButtonProps<T = unknown> extends Omit<ButtonGroupProps & ButtonProps, 'onClick'> {
|
|
7
|
+
items: Array<MenuItemType<T>>;
|
|
8
8
|
selectedItemIndex?: number;
|
|
9
|
-
|
|
9
|
+
groupByProp?: keyof T;
|
|
10
|
+
onClick?: (event: React.MouseEvent<HTMLButtonElement | HTMLLIElement, MouseEvent>, item: MenuItemWithTrackingProps) => void;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* This component implements a Dropdown button using MUI (This can be removed as soon as MUI implements it. Check
|
|
13
14
|
* progress: https://mui.com/material-ui/discover-more/roadmap/#new-components)
|
|
14
15
|
*/
|
|
15
|
-
export declare const DropDownButton:
|
|
16
|
+
export declare const DropDownButton: <T extends unknown>({ items, selectedItemIndex, groupByProp, onClick, children, ...buttonProps }: DropDownButtonProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export interface MenuItemWithTrackingProps extends Omit<MenuItemProps, 'onClick'> {
|
|
18
|
+
eventName: string;
|
|
19
|
+
eventProperties?: {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
};
|
|
22
|
+
tooltip?: string;
|
|
23
|
+
onClick?: React.MouseEventHandler<HTMLLIElement | HTMLButtonElement>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* This MenuItem will send analytics in case the analytics context is passed through the provider (AnalyticsProvider).
|
|
27
|
+
*/
|
|
28
|
+
export declare const MenuItemWithTracking: React.FC<MenuItemWithTrackingProps>;
|
|
29
|
+
export {};
|
|
@@ -36,51 +36,83 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
36
36
|
}
|
|
37
37
|
return ar;
|
|
38
38
|
};
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
40
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
41
|
+
if (ar || !(i in from)) {
|
|
42
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
43
|
+
ar[i] = from[i];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
47
|
+
};
|
|
48
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
49
|
+
import { useMemo, useState } from 'react';
|
|
41
50
|
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
|
|
42
|
-
import
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
51
|
+
import { Button, ButtonGroup, MenuItem, Menu, } from '@mui/material';
|
|
52
|
+
import { ButtonWithTracking } from '../ButtonWithTracking';
|
|
53
|
+
import { useAnalyticsContext } from '../../contexts/AnalyticsContext';
|
|
54
|
+
import groupBy from 'lodash/groupBy';
|
|
55
|
+
import flatMap from 'lodash/flatMap';
|
|
56
|
+
import { KeyboardArrowDown } from '@mui/icons-material';
|
|
57
|
+
import { Tooltip } from '../Tooltip';
|
|
45
58
|
/**
|
|
46
59
|
* This component implements a Dropdown button using MUI (This can be removed as soon as MUI implements it. Check
|
|
47
60
|
* progress: https://mui.com/material-ui/discover-more/roadmap/#new-components)
|
|
48
61
|
*/
|
|
49
62
|
export var DropDownButton = function (_a) {
|
|
50
|
-
var items = _a.items, _b = _a.selectedItemIndex, selectedItemIndex = _b === void 0 ? 0 : _b, onClick = _a.onClick,
|
|
51
|
-
var _c = __read(
|
|
52
|
-
var
|
|
53
|
-
|
|
63
|
+
var items = _a.items, _b = _a.selectedItemIndex, selectedItemIndex = _b === void 0 ? 0 : _b, groupByProp = _a.groupByProp, onClick = _a.onClick, children = _a.children, buttonProps = __rest(_a, ["items", "selectedItemIndex", "groupByProp", "onClick", "children"]);
|
|
64
|
+
var _c = __read(useState(null), 2), anchorEl = _c[0], setAnchorEl = _c[1];
|
|
65
|
+
var _d = __read(useState(selectedItemIndex), 2), selectedIndex = _d[0], setSelectedIndex = _d[1];
|
|
66
|
+
// To use the groupBy pass another property on each item and define that property on groupByProp.
|
|
67
|
+
// const items = [{...menuItem, section: 'test1'}, {...menuItem, section: 'test2'}];
|
|
68
|
+
// <Dropdown groupByProp='section' .../>
|
|
69
|
+
var memoizedItems = useMemo(function () {
|
|
70
|
+
if (!groupByProp) {
|
|
71
|
+
return items;
|
|
72
|
+
}
|
|
73
|
+
var grouped = groupBy(items, function (item) { return item[groupByProp]; });
|
|
74
|
+
var keys = Object.keys(grouped);
|
|
75
|
+
var lastKey = keys[keys.length - 1];
|
|
76
|
+
return flatMap(grouped, function (value, key) { return __spreadArray([], __read(value.map(function (v, index) {
|
|
77
|
+
return key !== lastKey && index === value.length - 1
|
|
78
|
+
? __assign(__assign({}, v), { divider: true }) : v;
|
|
79
|
+
})), false); }).filter(function (item) { return item; });
|
|
80
|
+
}, [items, groupByProp]);
|
|
54
81
|
var handleClick = function (event) {
|
|
55
|
-
var _a, _b;
|
|
56
|
-
|
|
57
|
-
|
|
82
|
+
var _a, _b, _c;
|
|
83
|
+
setAnchorEl(event.currentTarget);
|
|
84
|
+
return ((_c = (_b = (_a = items === null || items === void 0 ? void 0 : items[selectedIndex]) === null || _a === void 0 ? void 0 : _a.onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event)) !== null && _c !== void 0 ? _c : onClick === null || onClick === void 0 ? void 0 : onClick(event, items[selectedIndex]));
|
|
58
85
|
};
|
|
59
|
-
var handleMenuItemClick = function (index) {
|
|
86
|
+
var handleMenuItemClick = function (event, index) {
|
|
87
|
+
var _a, _b, _c;
|
|
60
88
|
setSelectedIndex(index);
|
|
61
|
-
|
|
89
|
+
setAnchorEl(null);
|
|
90
|
+
if (children) {
|
|
91
|
+
return ((_c = (_b = (_a = items === null || items === void 0 ? void 0 : items[index]) === null || _a === void 0 ? void 0 : _a.onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event)) !== null && _c !== void 0 ? _c : onClick === null || onClick === void 0 ? void 0 : onClick(event, items[selectedIndex]));
|
|
92
|
+
}
|
|
62
93
|
};
|
|
63
|
-
var handleToggle = function () {
|
|
64
|
-
|
|
94
|
+
var handleToggle = function (event) {
|
|
95
|
+
setAnchorEl(event.currentTarget);
|
|
65
96
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
97
|
+
return (_jsxs(_Fragment, { children: [children ? (_jsx(Button, __assign({ "aria-controls": !!anchorEl ? 'dropdown' : undefined, "aria-expanded": !!anchorEl ? 'true' : undefined, onClick: function (event) {
|
|
98
|
+
setAnchorEl(event.currentTarget);
|
|
99
|
+
}, endIcon: _jsx(KeyboardArrowDown, {}) }, buttonProps, { children: children }))) : (_jsxs(ButtonGroup, __assign({ variant: "contained", disableElevation: true }, buttonProps, { children: [_jsx(ButtonWithTracking, __assign({ onClick: handleClick, eventName: items[selectedIndex].eventName, eventProperties: items[selectedIndex].eventProperties, tooltip: items[selectedIndex].tooltip }, { children: items[selectedIndex].children })), _jsx(Button, __assign({ onClick: handleToggle,
|
|
100
|
+
// It doesn't look good without it, hence the addition.
|
|
101
|
+
sx: function (theme) { return ({ pl: 2, pr: "calc(".concat(theme.spacing(2), " + 2px)") }); } }, { children: _jsx(ArrowDropDownIcon, {}) }))] }))), _jsx(Menu, __assign({ anchorEl: anchorEl, open: !!anchorEl, onClose: function () {
|
|
102
|
+
setAnchorEl(null);
|
|
103
|
+
} }, { children: memoizedItems.map(function (item, index) { return (_jsx(MenuItemWithTracking, __assign({}, item, { onClick: function (event) { return handleMenuItemClick(event, index); } }, { children: item.children }))); }) }))] }));
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* This MenuItem will send analytics in case the analytics context is passed through the provider (AnalyticsProvider).
|
|
107
|
+
*/
|
|
108
|
+
export var MenuItemWithTracking = function (_a) {
|
|
109
|
+
var eventName = _a.eventName, eventProperties = _a.eventProperties, children = _a.children, tooltip = _a.tooltip, onClick = _a.onClick, menuItem = __rest(_a, ["eventName", "eventProperties", "children", "tooltip", "onClick"]);
|
|
110
|
+
var state = useAnalyticsContext().state;
|
|
111
|
+
var handleClick = function (event) {
|
|
112
|
+
if (state.webTracker) {
|
|
113
|
+
state.webTracker.track(eventName, eventProperties);
|
|
70
114
|
}
|
|
71
|
-
|
|
115
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
72
116
|
};
|
|
73
|
-
return (
|
|
74
|
-
// It doesn't look good without it, hence the addition.
|
|
75
|
-
sx: function (theme) { return ({ pl: 2, pr: "calc(".concat(theme.spacing(2), " + 2px)") }); } }, { children: _jsx(ArrowDropDownIcon, {}) }))] })), _jsx(Popper, __assign({ sx: {
|
|
76
|
-
zIndex: 1,
|
|
77
|
-
}, open: open, anchorEl: anchorRef.current, role: undefined, transition: true, disablePortal: true }, { children: function (_a) {
|
|
78
|
-
var TransitionProps = _a.TransitionProps, placement = _a.placement;
|
|
79
|
-
return (_jsx(Grow, __assign({}, TransitionProps, { style: {
|
|
80
|
-
transformOrigin: placement === 'bottom' ? 'center top' : 'center bottom',
|
|
81
|
-
} }, { children: _jsx(Paper, { children: _jsx(ClickAwayListener, __assign({ onClickAway: handleClose }, { children: _jsx(MenuList, __assign({ id: "split-button-menu", autoFocusItem: true }, { children: items.map(function (option, index) {
|
|
82
|
-
var _a, _b;
|
|
83
|
-
return (_jsx(Tooltip, __assign({ title: option.tooltip }, { children: _jsx(MenuItem, __assign({ disabled: option.disabled, selected: index === selectedIndex, onClick: function () { return handleMenuItemClick(index); } }, { children: option.children })) }), (_b = (_a = option.id) !== null && _a !== void 0 ? _a : option.key) !== null && _b !== void 0 ? _b : index));
|
|
84
|
-
}) })) })) }) })));
|
|
85
|
-
} }))] }));
|
|
117
|
+
return (_jsx(Tooltip, __assign({ title: tooltip }, { children: _jsx(MenuItem, __assign({}, menuItem, { onClick: handleClick }, { children: children })) })));
|
|
86
118
|
};
|
|
@@ -28,6 +28,6 @@ import { Tooltip as MuiTooltip } from '@mui/material';
|
|
|
28
28
|
*/
|
|
29
29
|
var Tooltip = function (_a) {
|
|
30
30
|
var children = _a.children, tooltipProps = __rest(_a, ["children"]);
|
|
31
|
-
return (_jsx(MuiTooltip, __assign({}, tooltipProps, { children: _jsx("span", { children: children }) })));
|
|
31
|
+
return (_jsx(MuiTooltip, __assign({}, tooltipProps, { children: children.props.disabled ? _jsx("span", { children: children }) : children })));
|
|
32
32
|
};
|
|
33
33
|
export { Tooltip };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { __assign, __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { Button
|
|
3
|
+
import { Button } from '@mui/material';
|
|
4
4
|
import { useAnalyticsContext } from '../../contexts/AnalyticsContext';
|
|
5
|
+
import { Tooltip } from '../Tooltip';
|
|
5
6
|
/**
|
|
6
7
|
* This button will send analytics in case the analytics context is passed through the provider (AnalyticsProvider).
|
|
7
8
|
*/
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { StoryObj } from '@storybook/react';
|
|
3
2
|
declare const meta: {
|
|
4
3
|
title: string;
|
|
5
|
-
component: import("
|
|
4
|
+
component: <T extends unknown>({ items, selectedItemIndex, groupByProp, onClick, children, ...buttonProps }: import(".").DropDownButtonProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
6
5
|
tags: string[];
|
|
7
6
|
};
|
|
8
7
|
export default meta;
|
|
@@ -1,15 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
import { ButtonGroupProps } from '@mui/material';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ButtonGroupProps, MenuItemProps, ButtonProps } from '@mui/material';
|
|
3
|
+
type MenuItemType<T> = MenuItemWithTrackingProps & T & {
|
|
4
|
+
tooltip?: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
export interface DropDownButtonProps<T = unknown> extends Omit<ButtonGroupProps & ButtonProps, 'onClick'> {
|
|
7
|
+
items: Array<MenuItemType<T>>;
|
|
8
8
|
selectedItemIndex?: number;
|
|
9
|
-
|
|
9
|
+
groupByProp?: keyof T;
|
|
10
|
+
onClick?: (event: React.MouseEvent<HTMLButtonElement | HTMLLIElement, MouseEvent>, item: MenuItemWithTrackingProps) => void;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* This component implements a Dropdown button using MUI (This can be removed as soon as MUI implements it. Check
|
|
13
14
|
* progress: https://mui.com/material-ui/discover-more/roadmap/#new-components)
|
|
14
15
|
*/
|
|
15
|
-
export declare const DropDownButton:
|
|
16
|
+
export declare const DropDownButton: <T extends unknown>({ items, selectedItemIndex, groupByProp, onClick, children, ...buttonProps }: DropDownButtonProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export interface MenuItemWithTrackingProps extends Omit<MenuItemProps, 'onClick'> {
|
|
18
|
+
eventName: string;
|
|
19
|
+
eventProperties?: {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
};
|
|
22
|
+
tooltip?: string;
|
|
23
|
+
onClick?: React.MouseEventHandler<HTMLLIElement | HTMLButtonElement>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* This MenuItem will send analytics in case the analytics context is passed through the provider (AnalyticsProvider).
|
|
27
|
+
*/
|
|
28
|
+
export declare const MenuItemWithTracking: React.FC<MenuItemWithTrackingProps>;
|
|
29
|
+
export {};
|
|
@@ -1,49 +1,72 @@
|
|
|
1
|
-
import { __assign, __read, __rest } from "tslib";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import
|
|
1
|
+
import { __assign, __read, __rest, __spreadArray } from "tslib";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useState } from 'react';
|
|
4
4
|
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { Button, ButtonGroup, MenuItem, Menu, } from '@mui/material';
|
|
6
|
+
import { ButtonWithTracking } from '../ButtonWithTracking';
|
|
7
|
+
import { useAnalyticsContext } from '../../contexts/AnalyticsContext';
|
|
8
|
+
import groupBy from 'lodash/groupBy';
|
|
9
|
+
import flatMap from 'lodash/flatMap';
|
|
10
|
+
import { KeyboardArrowDown } from '@mui/icons-material';
|
|
11
|
+
import { Tooltip } from '../Tooltip';
|
|
8
12
|
/**
|
|
9
13
|
* This component implements a Dropdown button using MUI (This can be removed as soon as MUI implements it. Check
|
|
10
14
|
* progress: https://mui.com/material-ui/discover-more/roadmap/#new-components)
|
|
11
15
|
*/
|
|
12
16
|
export var DropDownButton = function (_a) {
|
|
13
|
-
var items = _a.items, _b = _a.selectedItemIndex, selectedItemIndex = _b === void 0 ? 0 : _b, onClick = _a.onClick,
|
|
14
|
-
var _c = __read(
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
+
var items = _a.items, _b = _a.selectedItemIndex, selectedItemIndex = _b === void 0 ? 0 : _b, groupByProp = _a.groupByProp, onClick = _a.onClick, children = _a.children, buttonProps = __rest(_a, ["items", "selectedItemIndex", "groupByProp", "onClick", "children"]);
|
|
18
|
+
var _c = __read(useState(null), 2), anchorEl = _c[0], setAnchorEl = _c[1];
|
|
19
|
+
var _d = __read(useState(selectedItemIndex), 2), selectedIndex = _d[0], setSelectedIndex = _d[1];
|
|
20
|
+
// To use the groupBy pass another property on each item and define that property on groupByProp.
|
|
21
|
+
// const items = [{...menuItem, section: 'test1'}, {...menuItem, section: 'test2'}];
|
|
22
|
+
// <Dropdown groupByProp='section' .../>
|
|
23
|
+
var memoizedItems = useMemo(function () {
|
|
24
|
+
if (!groupByProp) {
|
|
25
|
+
return items;
|
|
26
|
+
}
|
|
27
|
+
var grouped = groupBy(items, function (item) { return item[groupByProp]; });
|
|
28
|
+
var keys = Object.keys(grouped);
|
|
29
|
+
var lastKey = keys[keys.length - 1];
|
|
30
|
+
return flatMap(grouped, function (value, key) { return __spreadArray([], __read(value.map(function (v, index) {
|
|
31
|
+
return key !== lastKey && index === value.length - 1
|
|
32
|
+
? __assign(__assign({}, v), { divider: true }) : v;
|
|
33
|
+
})), false); }).filter(function (item) { return item; });
|
|
34
|
+
}, [items, groupByProp]);
|
|
17
35
|
var handleClick = function (event) {
|
|
18
|
-
var _a, _b;
|
|
19
|
-
|
|
20
|
-
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
setAnchorEl(event.currentTarget);
|
|
38
|
+
return ((_c = (_b = (_a = items === null || items === void 0 ? void 0 : items[selectedIndex]) === null || _a === void 0 ? void 0 : _a.onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event)) !== null && _c !== void 0 ? _c : onClick === null || onClick === void 0 ? void 0 : onClick(event, items[selectedIndex]));
|
|
21
39
|
};
|
|
22
|
-
var handleMenuItemClick = function (index) {
|
|
40
|
+
var handleMenuItemClick = function (event, index) {
|
|
41
|
+
var _a, _b, _c;
|
|
23
42
|
setSelectedIndex(index);
|
|
24
|
-
|
|
43
|
+
setAnchorEl(null);
|
|
44
|
+
if (children) {
|
|
45
|
+
return ((_c = (_b = (_a = items === null || items === void 0 ? void 0 : items[index]) === null || _a === void 0 ? void 0 : _a.onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event)) !== null && _c !== void 0 ? _c : onClick === null || onClick === void 0 ? void 0 : onClick(event, items[selectedIndex]));
|
|
46
|
+
}
|
|
25
47
|
};
|
|
26
|
-
var handleToggle = function () {
|
|
27
|
-
|
|
48
|
+
var handleToggle = function (event) {
|
|
49
|
+
setAnchorEl(event.currentTarget);
|
|
28
50
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
51
|
+
return (_jsxs(_Fragment, { children: [children ? (_jsx(Button, __assign({ "aria-controls": !!anchorEl ? 'dropdown' : undefined, "aria-expanded": !!anchorEl ? 'true' : undefined, onClick: function (event) {
|
|
52
|
+
setAnchorEl(event.currentTarget);
|
|
53
|
+
}, endIcon: _jsx(KeyboardArrowDown, {}) }, buttonProps, { children: children }))) : (_jsxs(ButtonGroup, __assign({ variant: "contained", disableElevation: true }, buttonProps, { children: [_jsx(ButtonWithTracking, __assign({ onClick: handleClick, eventName: items[selectedIndex].eventName, eventProperties: items[selectedIndex].eventProperties, tooltip: items[selectedIndex].tooltip }, { children: items[selectedIndex].children })), _jsx(Button, __assign({ onClick: handleToggle,
|
|
54
|
+
// It doesn't look good without it, hence the addition.
|
|
55
|
+
sx: function (theme) { return ({ pl: 2, pr: "calc(".concat(theme.spacing(2), " + 2px)") }); } }, { children: _jsx(ArrowDropDownIcon, {}) }))] }))), _jsx(Menu, __assign({ anchorEl: anchorEl, open: !!anchorEl, onClose: function () {
|
|
56
|
+
setAnchorEl(null);
|
|
57
|
+
} }, { children: memoizedItems.map(function (item, index) { return (_jsx(MenuItemWithTracking, __assign({}, item, { onClick: function (event) { return handleMenuItemClick(event, index); } }, { children: item.children }))); }) }))] }));
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* This MenuItem will send analytics in case the analytics context is passed through the provider (AnalyticsProvider).
|
|
61
|
+
*/
|
|
62
|
+
export var MenuItemWithTracking = function (_a) {
|
|
63
|
+
var eventName = _a.eventName, eventProperties = _a.eventProperties, children = _a.children, tooltip = _a.tooltip, onClick = _a.onClick, menuItem = __rest(_a, ["eventName", "eventProperties", "children", "tooltip", "onClick"]);
|
|
64
|
+
var state = useAnalyticsContext().state;
|
|
65
|
+
var handleClick = function (event) {
|
|
66
|
+
if (state.webTracker) {
|
|
67
|
+
state.webTracker.track(eventName, eventProperties);
|
|
33
68
|
}
|
|
34
|
-
|
|
69
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
35
70
|
};
|
|
36
|
-
return (
|
|
37
|
-
// It doesn't look good without it, hence the addition.
|
|
38
|
-
sx: function (theme) { return ({ pl: 2, pr: "calc(".concat(theme.spacing(2), " + 2px)") }); } }, { children: _jsx(ArrowDropDownIcon, {}) }))] })), _jsx(Popper, __assign({ sx: {
|
|
39
|
-
zIndex: 1,
|
|
40
|
-
}, open: open, anchorEl: anchorRef.current, role: undefined, transition: true, disablePortal: true }, { children: function (_a) {
|
|
41
|
-
var TransitionProps = _a.TransitionProps, placement = _a.placement;
|
|
42
|
-
return (_jsx(Grow, __assign({}, TransitionProps, { style: {
|
|
43
|
-
transformOrigin: placement === 'bottom' ? 'center top' : 'center bottom',
|
|
44
|
-
} }, { children: _jsx(Paper, { children: _jsx(ClickAwayListener, __assign({ onClickAway: handleClose }, { children: _jsx(MenuList, __assign({ id: "split-button-menu", autoFocusItem: true }, { children: items.map(function (option, index) {
|
|
45
|
-
var _a, _b;
|
|
46
|
-
return (_jsx(Tooltip, __assign({ title: option.tooltip }, { children: _jsx(MenuItem, __assign({ disabled: option.disabled, selected: index === selectedIndex, onClick: function () { return handleMenuItemClick(index); } }, { children: option.children })) }), (_b = (_a = option.id) !== null && _a !== void 0 ? _a : option.key) !== null && _b !== void 0 ? _b : index));
|
|
47
|
-
}) })) })) }) })));
|
|
48
|
-
} }))] }));
|
|
71
|
+
return (_jsx(Tooltip, __assign({ title: tooltip }, { children: _jsx(MenuItem, __assign({}, menuItem, { onClick: handleClick }, { children: children })) })));
|
|
49
72
|
};
|
|
@@ -7,6 +7,6 @@ import { Tooltip as MuiTooltip } from '@mui/material';
|
|
|
7
7
|
*/
|
|
8
8
|
var Tooltip = function (_a) {
|
|
9
9
|
var children = _a.children, tooltipProps = __rest(_a, ["children"]);
|
|
10
|
-
return (_jsx(MuiTooltip, __assign({}, tooltipProps, { children: _jsx("span", { children: children }) })));
|
|
10
|
+
return (_jsx(MuiTooltip, __assign({}, tooltipProps, { children: children.props.disabled ? _jsx("span", { children: children }) : children })));
|
|
11
11
|
};
|
|
12
12
|
export { Tooltip };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@balena/ui-shared-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist_esm5/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -112,6 +112,6 @@
|
|
|
112
112
|
},
|
|
113
113
|
"homepage": "https://github.com/balena-io/ui-shared-components#readme",
|
|
114
114
|
"versionist": {
|
|
115
|
-
"publishedAt": "2024-01-
|
|
115
|
+
"publishedAt": "2024-01-19T10:46:14.728Z"
|
|
116
116
|
}
|
|
117
117
|
}
|