@datarobot/design-system 28.6.2 → 28.7.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.
@@ -1,4 +1,5 @@
1
1
  import { DropdownMenuOption } from '../dropdown-menu';
2
+ import { IconSidebarLinkType } from './types';
2
3
  import './icon-sidebar.less';
3
4
  export declare enum ICON_SIDEBAR_POSITION {
4
5
  LEFT = "left",
@@ -8,15 +9,16 @@ export type IconSidebarProps = {
8
9
  className?: string;
9
10
  options: DropdownMenuOption[];
10
11
  selected?: string | number;
11
- onSelect: (option: DropdownMenuOption) => void;
12
+ onSelect?: (option: DropdownMenuOption) => void;
12
13
  footerOption?: DropdownMenuOption;
13
14
  moreButtonText?: string;
14
15
  position?: ICON_SIDEBAR_POSITION;
16
+ LinkComponent?: IconSidebarLinkType;
15
17
  };
16
18
  /**
17
19
  * @midnight-gray-supported
18
20
  * @uxr-only-supported
19
21
  * @alpine-light-supported
20
22
  */
21
- declare function IconSidebar({ className, options, selected, onSelect, footerOption, position, moreButtonText, }: IconSidebarProps): import("react/jsx-runtime").JSX.Element;
23
+ declare function IconSidebar({ className, options, selected, onSelect, footerOption, position, moreButtonText, LinkComponent, }: IconSidebarProps): import("react/jsx-runtime").JSX.Element;
22
24
  export default IconSidebar;
@@ -8,9 +8,9 @@ var _react = _interopRequireDefault(require("react"));
8
8
  var _classnames = _interopRequireDefault(require("classnames"));
9
9
  var _faEllipsisVertical = require("@fortawesome/free-solid-svg-icons/faEllipsisVertical");
10
10
  var _dropdownMenu = require("../dropdown-menu");
11
- var _iconSidebarButton = require("./icon-sidebar-button");
12
11
  var _adaptiveList = require("../adaptive-list");
13
12
  var _useTranslation = require("../hooks/use-translation");
13
+ var _withIconSidebarItem = require("./with-icon-sidebar-item");
14
14
  var _jsxRuntime = require("react/jsx-runtime");
15
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
16
  let ICON_SIDEBAR_POSITION = exports.ICON_SIDEBAR_POSITION = /*#__PURE__*/function (ICON_SIDEBAR_POSITION) {
@@ -30,11 +30,13 @@ function IconSidebar({
30
30
  onSelect,
31
31
  footerOption,
32
32
  position = ICON_SIDEBAR_POSITION.LEFT,
33
- moreButtonText
33
+ moreButtonText,
34
+ LinkComponent
34
35
  }) {
35
36
  const {
36
37
  t
37
38
  } = (0, _useTranslation.useTranslation)();
39
+ const ItemComponent = (0, _withIconSidebarItem.withIconSidebarItem)(LinkComponent);
38
40
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
39
41
  className: (0, _classnames.default)('icon-sidebar-container', className, position),
40
42
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
@@ -42,7 +44,7 @@ function IconSidebar({
42
44
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_adaptiveList.AdaptiveList, {
43
45
  selected: selected,
44
46
  onSelect: onSelect,
45
- Component: _iconSidebarButton.IconSidebarButton,
47
+ Component: ItemComponent,
46
48
  target: "offsetHeight",
47
49
  triggerOffset: 62,
48
50
  options: options,
@@ -51,7 +53,7 @@ function IconSidebar({
51
53
  placement: position === ICON_SIDEBAR_POSITION.LEFT ? _dropdownMenu.DROPDOWN_MENU_PLACEMENT_TYPES.RIGHT_START : _dropdownMenu.DROPDOWN_MENU_PLACEMENT_TYPES.LEFT_START,
52
54
  triggerDynamicContent: ({
53
55
  isOpen
54
- }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_iconSidebarButton.IconSidebarButton, {
56
+ }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(ItemComponent, {
55
57
  option: {
56
58
  key: 'more-trigger',
57
59
  title: moreButtonText ?? t('More'),
@@ -63,7 +65,7 @@ function IconSidebar({
63
65
  })
64
66
  }), footerOption && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
65
67
  className: "icon-sidebar-footer-container",
66
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_iconSidebarButton.IconSidebarButton, {
68
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ItemComponent, {
67
69
  option: footerOption,
68
70
  onSelect: onSelect,
69
71
  selected: selected
@@ -0,0 +1,25 @@
1
+ import { ComponentType, ReactNode, MouseEvent, AnchorHTMLAttributes } from 'react';
2
+ import { IconProp } from '@fortawesome/fontawesome-svg-core';
3
+ import { DropdownMenuOption } from '../dropdown-menu';
4
+ export type IconSidebarItemProps = {
5
+ option: DropdownMenuOption & {
6
+ selectedIcon?: IconProp;
7
+ divider?: boolean;
8
+ ariaLabel?: string;
9
+ };
10
+ onSelect?: (option: DropdownMenuOption) => void;
11
+ selected?: number | string | (number | string)[];
12
+ isLimited?: boolean;
13
+ children?: ReactNode;
14
+ };
15
+ export type IconSidebarLinkProps = {
16
+ className: string;
17
+ href: string;
18
+ children: ReactNode;
19
+ tabIndex?: number;
20
+ onClick: (e: MouseEvent) => void;
21
+ };
22
+ export type IconSidebarLinkType = ComponentType<IconSidebarLinkProps>;
23
+ export type DefaultLinkProps = {
24
+ children: ReactNode;
25
+ } & AnchorHTMLAttributes<HTMLAnchorElement>;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,3 @@
1
+ import './icon-sidebar.less';
2
+ import { IconSidebarItemProps, IconSidebarLinkType } from './types';
3
+ export declare const withIconSidebarItem: (LinkComponent?: IconSidebarLinkType) => ({ option, selected, isLimited, onSelect, }: IconSidebarItemProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.withIconSidebarItem = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _classnames = _interopRequireDefault(require("classnames"));
9
+ var _tooltip = require("../tooltip");
10
+ var _fontAwesomeIcon = require("../font-awesome-icon");
11
+ var _truncateWithTooltip = require("../truncate-with-tooltip");
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ const DefaultLink = ({
15
+ children,
16
+ ...props
17
+ }) => /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
18
+ rel: "noopener noreferrer",
19
+ ...props,
20
+ children: children
21
+ });
22
+ const withIconSidebarItem = (LinkComponent = DefaultLink) => {
23
+ const IconSidebarItem = ({
24
+ option,
25
+ selected,
26
+ isLimited,
27
+ onSelect
28
+ }) => {
29
+ const isSelected = option.key === selected;
30
+ const icon = isSelected && option.selectedIcon ? option.selectedIcon : option.icon;
31
+ const getTitle = () => {
32
+ if (option.title) {
33
+ if (option.tooltipText) {
34
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
35
+ className: "icon-sidebar-text",
36
+ children: option.title
37
+ });
38
+ }
39
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_truncateWithTooltip.TruncateWithTooltip, {
40
+ className: "icon-sidebar-text",
41
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
42
+ children: option.title
43
+ })
44
+ });
45
+ }
46
+ };
47
+ const onClick = e => {
48
+ if (option.disabled) {
49
+ e.preventDefault();
50
+ e.stopPropagation();
51
+ return;
52
+ }
53
+
54
+ // Prevent calling onSelect when link is opened in a new tab
55
+ if (e.metaKey || e.ctrlKey) {
56
+ return;
57
+ }
58
+ onSelect?.(option);
59
+ };
60
+ const content = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
61
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
62
+ className: "icon-sidebar-button-icon-container",
63
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
64
+ icon: icon
65
+ })
66
+ }), getTitle(), option.divider && !isLimited && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
67
+ className: "icon-sidebar-divider"
68
+ })]
69
+ });
70
+ const props = {
71
+ className: (0, _classnames.default)('icon-sidebar-button-container', option.className, option.disabled && 'disabled', isSelected && 'selected'),
72
+ 'test-id': option.testId,
73
+ 'aria-label': option.title && typeof option.title === 'string' ? option.title : option.ariaLabel
74
+ };
75
+ if (option.link) {
76
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.Tooltip, {
77
+ content: option.tooltipText,
78
+ placement: option.tooltipPlacement,
79
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
80
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkComponent, {
81
+ ...props,
82
+ tabIndex: option.disabled ? -1 : 0,
83
+ href: option.link,
84
+ onClick: onClick,
85
+ children: content
86
+ })
87
+ })
88
+ });
89
+ }
90
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.Tooltip, {
91
+ content: option.tooltipText,
92
+ placement: option.tooltipPlacement,
93
+ children: onSelect ? /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
94
+ ...props,
95
+ onClick: onClick,
96
+ disabled: option.disabled,
97
+ children: content
98
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
99
+ ...props,
100
+ children: content
101
+ })
102
+ });
103
+ };
104
+ return IconSidebarItem;
105
+ };
106
+ exports.withIconSidebarItem = withIconSidebarItem;
@@ -1,4 +1,5 @@
1
1
  import { DropdownMenuOption } from '../dropdown-menu';
2
+ import { IconSidebarLinkType } from './types';
2
3
  import './icon-sidebar.less';
3
4
  export declare enum ICON_SIDEBAR_POSITION {
4
5
  LEFT = "left",
@@ -8,15 +9,16 @@ export type IconSidebarProps = {
8
9
  className?: string;
9
10
  options: DropdownMenuOption[];
10
11
  selected?: string | number;
11
- onSelect: (option: DropdownMenuOption) => void;
12
+ onSelect?: (option: DropdownMenuOption) => void;
12
13
  footerOption?: DropdownMenuOption;
13
14
  moreButtonText?: string;
14
15
  position?: ICON_SIDEBAR_POSITION;
16
+ LinkComponent?: IconSidebarLinkType;
15
17
  };
16
18
  /**
17
19
  * @midnight-gray-supported
18
20
  * @uxr-only-supported
19
21
  * @alpine-light-supported
20
22
  */
21
- declare function IconSidebar({ className, options, selected, onSelect, footerOption, position, moreButtonText, }: IconSidebarProps): import("react/jsx-runtime").JSX.Element;
23
+ declare function IconSidebar({ className, options, selected, onSelect, footerOption, position, moreButtonText, LinkComponent, }: IconSidebarProps): import("react/jsx-runtime").JSX.Element;
22
24
  export default IconSidebar;
@@ -2,9 +2,9 @@ import React from 'react';
2
2
  import classNames from 'classnames';
3
3
  import { faEllipsisVertical } from '@fortawesome/free-solid-svg-icons/faEllipsisVertical';
4
4
  import { DROPDOWN_MENU_PLACEMENT_TYPES } from '../dropdown-menu';
5
- import { IconSidebarButton } from './icon-sidebar-button';
6
5
  import { AdaptiveList } from '../adaptive-list';
7
6
  import { useTranslation } from '../hooks/use-translation';
7
+ import { withIconSidebarItem } from './with-icon-sidebar-item';
8
8
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
9
  export let ICON_SIDEBAR_POSITION = /*#__PURE__*/function (ICON_SIDEBAR_POSITION) {
10
10
  ICON_SIDEBAR_POSITION["LEFT"] = "left";
@@ -23,11 +23,13 @@ function IconSidebar({
23
23
  onSelect,
24
24
  footerOption,
25
25
  position = ICON_SIDEBAR_POSITION.LEFT,
26
- moreButtonText
26
+ moreButtonText,
27
+ LinkComponent
27
28
  }) {
28
29
  const {
29
30
  t
30
31
  } = useTranslation();
32
+ const ItemComponent = withIconSidebarItem(LinkComponent);
31
33
  return /*#__PURE__*/_jsxs("div", {
32
34
  className: classNames('icon-sidebar-container', className, position),
33
35
  children: [/*#__PURE__*/_jsx("div", {
@@ -35,7 +37,7 @@ function IconSidebar({
35
37
  children: /*#__PURE__*/_jsx(AdaptiveList, {
36
38
  selected: selected,
37
39
  onSelect: onSelect,
38
- Component: IconSidebarButton,
40
+ Component: ItemComponent,
39
41
  target: "offsetHeight",
40
42
  triggerOffset: 62,
41
43
  options: options,
@@ -44,7 +46,7 @@ function IconSidebar({
44
46
  placement: position === ICON_SIDEBAR_POSITION.LEFT ? DROPDOWN_MENU_PLACEMENT_TYPES.RIGHT_START : DROPDOWN_MENU_PLACEMENT_TYPES.LEFT_START,
45
47
  triggerDynamicContent: ({
46
48
  isOpen
47
- }) => /*#__PURE__*/_jsx(IconSidebarButton, {
49
+ }) => /*#__PURE__*/_jsx(ItemComponent, {
48
50
  option: {
49
51
  key: 'more-trigger',
50
52
  title: moreButtonText ?? t('More'),
@@ -56,7 +58,7 @@ function IconSidebar({
56
58
  })
57
59
  }), footerOption && /*#__PURE__*/_jsx("div", {
58
60
  className: "icon-sidebar-footer-container",
59
- children: /*#__PURE__*/_jsx(IconSidebarButton, {
61
+ children: /*#__PURE__*/_jsx(ItemComponent, {
60
62
  option: footerOption,
61
63
  onSelect: onSelect,
62
64
  selected: selected
@@ -0,0 +1,25 @@
1
+ import { ComponentType, ReactNode, MouseEvent, AnchorHTMLAttributes } from 'react';
2
+ import { IconProp } from '@fortawesome/fontawesome-svg-core';
3
+ import { DropdownMenuOption } from '../dropdown-menu';
4
+ export type IconSidebarItemProps = {
5
+ option: DropdownMenuOption & {
6
+ selectedIcon?: IconProp;
7
+ divider?: boolean;
8
+ ariaLabel?: string;
9
+ };
10
+ onSelect?: (option: DropdownMenuOption) => void;
11
+ selected?: number | string | (number | string)[];
12
+ isLimited?: boolean;
13
+ children?: ReactNode;
14
+ };
15
+ export type IconSidebarLinkProps = {
16
+ className: string;
17
+ href: string;
18
+ children: ReactNode;
19
+ tabIndex?: number;
20
+ onClick: (e: MouseEvent) => void;
21
+ };
22
+ export type IconSidebarLinkType = ComponentType<IconSidebarLinkProps>;
23
+ export type DefaultLinkProps = {
24
+ children: ReactNode;
25
+ } & AnchorHTMLAttributes<HTMLAnchorElement>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import './icon-sidebar.less';
2
+ import { IconSidebarItemProps, IconSidebarLinkType } from './types';
3
+ export declare const withIconSidebarItem: (LinkComponent?: IconSidebarLinkType) => ({ option, selected, isLimited, onSelect, }: IconSidebarItemProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,98 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import { Tooltip } from '../tooltip';
4
+ import { FontAwesomeIcon } from '../font-awesome-icon';
5
+ import { TruncateWithTooltip } from '../truncate-with-tooltip';
6
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
7
+ const DefaultLink = ({
8
+ children,
9
+ ...props
10
+ }) => /*#__PURE__*/_jsx("a", {
11
+ rel: "noopener noreferrer",
12
+ ...props,
13
+ children: children
14
+ });
15
+ export const withIconSidebarItem = (LinkComponent = DefaultLink) => {
16
+ const IconSidebarItem = ({
17
+ option,
18
+ selected,
19
+ isLimited,
20
+ onSelect
21
+ }) => {
22
+ const isSelected = option.key === selected;
23
+ const icon = isSelected && option.selectedIcon ? option.selectedIcon : option.icon;
24
+ const getTitle = () => {
25
+ if (option.title) {
26
+ if (option.tooltipText) {
27
+ return /*#__PURE__*/_jsx("span", {
28
+ className: "icon-sidebar-text",
29
+ children: option.title
30
+ });
31
+ }
32
+ return /*#__PURE__*/_jsx(TruncateWithTooltip, {
33
+ className: "icon-sidebar-text",
34
+ children: /*#__PURE__*/_jsx("span", {
35
+ children: option.title
36
+ })
37
+ });
38
+ }
39
+ };
40
+ const onClick = e => {
41
+ if (option.disabled) {
42
+ e.preventDefault();
43
+ e.stopPropagation();
44
+ return;
45
+ }
46
+
47
+ // Prevent calling onSelect when link is opened in a new tab
48
+ if (e.metaKey || e.ctrlKey) {
49
+ return;
50
+ }
51
+ onSelect?.(option);
52
+ };
53
+ const content = /*#__PURE__*/_jsxs(_Fragment, {
54
+ children: [/*#__PURE__*/_jsx("div", {
55
+ className: "icon-sidebar-button-icon-container",
56
+ children: /*#__PURE__*/_jsx(FontAwesomeIcon, {
57
+ icon: icon
58
+ })
59
+ }), getTitle(), option.divider && !isLimited && /*#__PURE__*/_jsx("div", {
60
+ className: "icon-sidebar-divider"
61
+ })]
62
+ });
63
+ const props = {
64
+ className: classNames('icon-sidebar-button-container', option.className, option.disabled && 'disabled', isSelected && 'selected'),
65
+ 'test-id': option.testId,
66
+ 'aria-label': option.title && typeof option.title === 'string' ? option.title : option.ariaLabel
67
+ };
68
+ if (option.link) {
69
+ return /*#__PURE__*/_jsx(Tooltip, {
70
+ content: option.tooltipText,
71
+ placement: option.tooltipPlacement,
72
+ children: /*#__PURE__*/_jsx("span", {
73
+ children: /*#__PURE__*/_jsx(LinkComponent, {
74
+ ...props,
75
+ tabIndex: option.disabled ? -1 : 0,
76
+ href: option.link,
77
+ onClick: onClick,
78
+ children: content
79
+ })
80
+ })
81
+ });
82
+ }
83
+ return /*#__PURE__*/_jsx(Tooltip, {
84
+ content: option.tooltipText,
85
+ placement: option.tooltipPlacement,
86
+ children: onSelect ? /*#__PURE__*/_jsx("button", {
87
+ ...props,
88
+ onClick: onClick,
89
+ disabled: option.disabled,
90
+ children: content
91
+ }) : /*#__PURE__*/_jsx("div", {
92
+ ...props,
93
+ children: content
94
+ })
95
+ });
96
+ };
97
+ return IconSidebarItem;
98
+ };