@dbcdk/react-components 0.0.206 → 0.0.207

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/client.d.ts CHANGED
@@ -177,3 +177,4 @@ export { FileUpload } from './components/forms/file-upload/FileUpload';
177
177
  export type { FileUploadProps, FileUploadHandle } from './components/forms/file-upload/FileUpload';
178
178
  export { HighlightedText } from './components/highlighted-text/HighlightedText';
179
179
  export type { HighlightedTextProps } from './components/highlighted-text/HighlightedText';
180
+ export type { MenuActionItem, MenuButtonItem, MenuLinkItem } from './components/menu/Menu.types';
@@ -9,6 +9,7 @@ var Popover = require('../../components/popover/Popover');
9
9
  var styles = require('./Lightbox.module.css');
10
10
  var Button = require('../button/Button');
11
11
  var Menu = require('../menu/Menu');
12
+ var MenuAction = require('../menu/MenuAction');
12
13
 
13
14
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
15
 
@@ -262,28 +263,7 @@ function ThumbnailContextMenu({
262
263
  }
263
264
  );
264
265
  },
265
- children: (close) => /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu, { children: menuItems.map((menuItem, menuItemIndex) => /* @__PURE__ */ jsxRuntime.jsx(
266
- Menu.Menu.Item,
267
- {
268
- active: menuItem.active,
269
- selected: menuItem.selected,
270
- disabled: menuItem.disabled,
271
- variant: menuItem.variant,
272
- children: /* @__PURE__ */ jsxRuntime.jsx(
273
- "button",
274
- {
275
- type: "button",
276
- onClick: (e) => {
277
- e.stopPropagation();
278
- menuItem.onClick();
279
- close();
280
- },
281
- children: menuItem.label
282
- }
283
- )
284
- },
285
- menuItemIndex
286
- )) })
266
+ children: (close) => /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu, { children: menuItems.map((menuItem, menuItemIndex) => /* @__PURE__ */ jsxRuntime.jsx(MenuAction.MenuAction, { item: menuItem, onActivate: close }, menuItemIndex)) })
287
267
  }
288
268
  );
289
269
  }
@@ -1,5 +1,6 @@
1
1
  import type { ReactElement, ReactNode } from 'react';
2
2
  import { type MetaItem } from '../../components/meta-bar/MetaBar';
3
+ import type { MenuActionItem } from '../menu/Menu.types';
3
4
  export type LightboxItem = {
4
5
  thumbnail: ReactNode;
5
6
  preview?: ReactNode;
@@ -10,14 +11,7 @@ export type LightboxItem = {
10
11
  height?: number;
11
12
  metaAddition?: MetaItem[];
12
13
  };
13
- export type LightboxContextMenuItem = {
14
- label: ReactNode;
15
- onClick: () => void;
16
- active?: boolean;
17
- selected?: boolean;
18
- disabled?: boolean;
19
- variant?: 'default' | 'danger';
20
- };
14
+ export type LightboxContextMenuItem = MenuActionItem;
21
15
  export interface LightboxProps {
22
16
  items: LightboxItem[];
23
17
  title?: string;
@@ -7,6 +7,7 @@ import { Popover } from '../../components/popover/Popover';
7
7
  import styles from './Lightbox.module.css';
8
8
  import { Button } from '../button/Button';
9
9
  import { Menu } from '../menu/Menu';
10
+ import { MenuAction } from '../menu/MenuAction';
10
11
 
11
12
  function extFromMime(mime) {
12
13
  var _a;
@@ -256,28 +257,7 @@ function ThumbnailContextMenu({
256
257
  }
257
258
  );
258
259
  },
259
- children: (close) => /* @__PURE__ */ jsx(Menu, { children: menuItems.map((menuItem, menuItemIndex) => /* @__PURE__ */ jsx(
260
- Menu.Item,
261
- {
262
- active: menuItem.active,
263
- selected: menuItem.selected,
264
- disabled: menuItem.disabled,
265
- variant: menuItem.variant,
266
- children: /* @__PURE__ */ jsx(
267
- "button",
268
- {
269
- type: "button",
270
- onClick: (e) => {
271
- e.stopPropagation();
272
- menuItem.onClick();
273
- close();
274
- },
275
- children: menuItem.label
276
- }
277
- )
278
- },
279
- menuItemIndex
280
- )) })
260
+ children: (close) => /* @__PURE__ */ jsx(Menu, { children: menuItems.map((menuItem, menuItemIndex) => /* @__PURE__ */ jsx(MenuAction, { item: menuItem, onActivate: close }, menuItemIndex)) })
281
261
  }
282
262
  );
283
263
  }
@@ -31,7 +31,7 @@ function _interopNamespace(e) {
31
31
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
32
32
  var styles__default = /*#__PURE__*/_interopDefault(styles);
33
33
 
34
- const INTERACTIVE_SELECTOR = 'a:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"]):not([aria-disabled="true"]), [role="menuitem"]:not([aria-disabled="true"]), [role="menuitemradio"]:not([aria-disabled="true"]), [role="menuitemcheckbox"]:not([aria-disabled="true"]), [role="option"]:not([aria-disabled="true"])';
34
+ const INTERACTIVE_SELECTOR = 'a[href]:not([aria-disabled="true"]), button:not([disabled]), [tabindex]:not([tabindex="-1"]):not([aria-disabled="true"]), [role="menuitem"]:not([aria-disabled="true"]), [role="menuitemradio"]:not([aria-disabled="true"]), [role="menuitemcheckbox"]:not([aria-disabled="true"]), [role="option"]:not([aria-disabled="true"])';
35
35
  function getMenuItems(el) {
36
36
  return Array.from(el.querySelectorAll(INTERACTIVE_SELECTOR));
37
37
  }
@@ -6,7 +6,7 @@ import { Checkbox } from '../forms/checkbox/Checkbox';
6
6
  import { RadioButton } from '../forms/radio-buttons/RadioButton';
7
7
  import { Switch } from '../forms/switch/Switch';
8
8
 
9
- const INTERACTIVE_SELECTOR = 'a:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"]):not([aria-disabled="true"]), [role="menuitem"]:not([aria-disabled="true"]), [role="menuitemradio"]:not([aria-disabled="true"]), [role="menuitemcheckbox"]:not([aria-disabled="true"]), [role="option"]:not([aria-disabled="true"])';
9
+ const INTERACTIVE_SELECTOR = 'a[href]:not([aria-disabled="true"]), button:not([disabled]), [tabindex]:not([tabindex="-1"]):not([aria-disabled="true"]), [role="menuitem"]:not([aria-disabled="true"]), [role="menuitemradio"]:not([aria-disabled="true"]), [role="menuitemcheckbox"]:not([aria-disabled="true"]), [role="option"]:not([aria-disabled="true"])';
10
10
  function getMenuItems(el) {
11
11
  return Array.from(el.querySelectorAll(INTERACTIVE_SELECTOR));
12
12
  }
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,19 @@
1
+ import type { AnchorHTMLAttributes, ReactNode } from 'react';
2
+ type MenuItemBase = {
3
+ label: ReactNode;
4
+ icon?: ReactNode;
5
+ active?: boolean;
6
+ selected?: boolean;
7
+ disabled?: boolean;
8
+ variant?: 'default' | 'danger';
9
+ };
10
+ export type MenuButtonItem = MenuItemBase & {
11
+ href?: undefined;
12
+ onClick: () => void;
13
+ };
14
+ export type MenuLinkItem = MenuItemBase & Pick<AnchorHTMLAttributes<HTMLAnchorElement>, 'download' | 'target' | 'rel'> & {
15
+ href: string;
16
+ onClick?: () => void;
17
+ };
18
+ export type MenuActionItem = MenuButtonItem | MenuLinkItem;
19
+ export {};
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,61 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+ var Menu = require('./Menu');
6
+
7
+ function MenuAction({
8
+ item,
9
+ onActivate,
10
+ children
11
+ }) {
12
+ var _a;
13
+ function handleClick(event) {
14
+ var _a2;
15
+ event.stopPropagation();
16
+ if (item.disabled) {
17
+ event.preventDefault();
18
+ return;
19
+ }
20
+ (_a2 = item.onClick) == null ? void 0 : _a2.call(item);
21
+ onActivate();
22
+ }
23
+ function handleKeyDown(event) {
24
+ if (event.key !== "Enter" && event.key !== " ") return;
25
+ event.stopPropagation();
26
+ if (item.href !== void 0) {
27
+ if (event.key === "Enter" && (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey))
28
+ return;
29
+ event.preventDefault();
30
+ if (!item.disabled && !event.repeat) event.currentTarget.click();
31
+ }
32
+ }
33
+ const content = children != null ? children : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
34
+ item.icon,
35
+ item.label
36
+ ] });
37
+ return /* @__PURE__ */ jsxRuntime.jsx(
38
+ Menu.Menu.Item,
39
+ {
40
+ active: item.active,
41
+ selected: item.selected,
42
+ disabled: item.disabled,
43
+ variant: item.variant,
44
+ children: item.href !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx(
45
+ "a",
46
+ {
47
+ href: item.disabled ? void 0 : item.href,
48
+ download: item.download,
49
+ target: item.target,
50
+ rel: (_a = item.rel) != null ? _a : item.target === "_blank" ? "noopener noreferrer" : void 0,
51
+ tabIndex: item.disabled ? -1 : 0,
52
+ onClick: handleClick,
53
+ onKeyDown: handleKeyDown,
54
+ children: content
55
+ }
56
+ ) : /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: handleClick, onKeyDown: handleKeyDown, children: content })
57
+ }
58
+ );
59
+ }
60
+
61
+ exports.MenuAction = MenuAction;
@@ -0,0 +1,7 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ import type { MenuActionItem } from './Menu.types';
3
+ export declare function MenuAction({ item, onActivate, children, }: {
4
+ item: MenuActionItem;
5
+ onActivate: () => void;
6
+ children?: ReactNode;
7
+ }): ReactElement;
@@ -0,0 +1,59 @@
1
+ 'use client';
2
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
3
+ import { Menu } from './Menu';
4
+
5
+ function MenuAction({
6
+ item,
7
+ onActivate,
8
+ children
9
+ }) {
10
+ var _a;
11
+ function handleClick(event) {
12
+ var _a2;
13
+ event.stopPropagation();
14
+ if (item.disabled) {
15
+ event.preventDefault();
16
+ return;
17
+ }
18
+ (_a2 = item.onClick) == null ? void 0 : _a2.call(item);
19
+ onActivate();
20
+ }
21
+ function handleKeyDown(event) {
22
+ if (event.key !== "Enter" && event.key !== " ") return;
23
+ event.stopPropagation();
24
+ if (item.href !== void 0) {
25
+ if (event.key === "Enter" && (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey))
26
+ return;
27
+ event.preventDefault();
28
+ if (!item.disabled && !event.repeat) event.currentTarget.click();
29
+ }
30
+ }
31
+ const content = children != null ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
32
+ item.icon,
33
+ item.label
34
+ ] });
35
+ return /* @__PURE__ */ jsx(
36
+ Menu.Item,
37
+ {
38
+ active: item.active,
39
+ selected: item.selected,
40
+ disabled: item.disabled,
41
+ variant: item.variant,
42
+ children: item.href !== void 0 ? /* @__PURE__ */ jsx(
43
+ "a",
44
+ {
45
+ href: item.disabled ? void 0 : item.href,
46
+ download: item.download,
47
+ target: item.target,
48
+ rel: (_a = item.rel) != null ? _a : item.target === "_blank" ? "noopener noreferrer" : void 0,
49
+ tabIndex: item.disabled ? -1 : 0,
50
+ onClick: handleClick,
51
+ onKeyDown: handleKeyDown,
52
+ children: content
53
+ }
54
+ ) : /* @__PURE__ */ jsx("button", { type: "button", onClick: handleClick, onKeyDown: handleKeyDown, children: content })
55
+ }
56
+ );
57
+ }
58
+
59
+ export { MenuAction };
@@ -1,4 +1,5 @@
1
1
  import type { HTMLAttributes, ReactNode, Ref } from 'react';
2
+ import type { MenuButtonItem, MenuLinkItem } from '../../components/menu/Menu.types';
2
3
  import type { PageChangeEvent } from '../../components/pagination/Pagination';
3
4
  import type { Severity } from '../../constants/severity.types';
4
5
  export type ViewMode = 'compact' | 'wrapped';
@@ -69,21 +70,17 @@ export type HeaderExtrasArgs<T> = {
69
70
  column: ColumnItem<T>;
70
71
  index: number;
71
72
  };
72
- export type TableContextMenuActionItem = {
73
+ export type TableContextMenuActionItem = MenuButtonItem & {
74
+ type?: 'item';
75
+ };
76
+ export type TableContextMenuLinkItem = MenuLinkItem & {
73
77
  type?: 'item';
74
- label: ReactNode;
75
- icon?: ReactNode;
76
- onClick: () => void;
77
- active?: boolean;
78
- selected?: boolean;
79
- disabled?: boolean;
80
- variant?: 'default' | 'danger';
81
78
  };
82
79
  export type TableContextMenuHeaderItem = {
83
80
  type: 'header';
84
81
  label: ReactNode;
85
82
  };
86
- export type TableContextMenuItem = TableContextMenuActionItem | TableContextMenuHeaderItem;
83
+ export type TableContextMenuItem = TableContextMenuActionItem | TableContextMenuLinkItem | TableContextMenuHeaderItem;
87
84
  export type StickyHeader = false | 'app-header' | number;
88
85
  export type TableVariant = 'primary' | 'embedded';
89
86
  export type SortDirection = 'asc' | 'desc' | null;
@@ -9,6 +9,7 @@ var Popover = require('../../../components/popover/Popover');
9
9
  var severity = require('../../../constants/severity');
10
10
  var Button = require('../../button/Button');
11
11
  var Menu = require('../../menu/Menu');
12
+ var MenuAction = require('../../menu/MenuAction');
12
13
  var useTableRowInteractions = require('../hooks/useTableRowInteractions');
13
14
  var table_classes = require('../table.classes');
14
15
  var styles = require('../Table.module.css');
@@ -252,32 +253,10 @@ function RowActions({
252
253
  );
253
254
  },
254
255
  children: (close) => /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu, { children: menuItems.map(
255
- (item, index) => item.type === "header" ? /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu.Header, { children: item.label }, index) : /* @__PURE__ */ jsxRuntime.jsx(
256
- Menu.Menu.Item,
257
- {
258
- active: item.active,
259
- selected: item.selected,
260
- disabled: item.disabled,
261
- variant: item.variant,
262
- children: /* @__PURE__ */ jsxRuntime.jsx(
263
- "button",
264
- {
265
- type: "button",
266
- "data-row-context-menu": "true",
267
- onClick: (e) => {
268
- e.stopPropagation();
269
- item.onClick();
270
- close();
271
- },
272
- children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: styles__default.default.contextMenuItemLabel, children: [
273
- item.icon,
274
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles__default.default.contextMenuItemText, children: item.label })
275
- ] })
276
- }
277
- )
278
- },
279
- index
280
- )
256
+ (item, index) => item.type === "header" ? /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu.Header, { children: item.label }, index) : /* @__PURE__ */ jsxRuntime.jsx(MenuAction.MenuAction, { item, onActivate: close, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: styles__default.default.contextMenuItemLabel, children: [
257
+ item.icon,
258
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles__default.default.contextMenuItemText, children: item.label })
259
+ ] }) }, index)
281
260
  ) })
282
261
  }
283
262
  ) : null
@@ -7,6 +7,7 @@ import { Popover } from '../../../components/popover/Popover';
7
7
  import { SeverityBgColor } from '../../../constants/severity';
8
8
  import { Button } from '../../button/Button';
9
9
  import { Menu } from '../../menu/Menu';
10
+ import { MenuAction } from '../../menu/MenuAction';
10
11
  import { useTableRowInteractions } from '../hooks/useTableRowInteractions';
11
12
  import { cx } from '../table.classes';
12
13
  import styles from '../Table.module.css';
@@ -246,32 +247,10 @@ function RowActions({
246
247
  );
247
248
  },
248
249
  children: (close) => /* @__PURE__ */ jsx(Menu, { children: menuItems.map(
249
- (item, index) => item.type === "header" ? /* @__PURE__ */ jsx(Menu.Header, { children: item.label }, index) : /* @__PURE__ */ jsx(
250
- Menu.Item,
251
- {
252
- active: item.active,
253
- selected: item.selected,
254
- disabled: item.disabled,
255
- variant: item.variant,
256
- children: /* @__PURE__ */ jsx(
257
- "button",
258
- {
259
- type: "button",
260
- "data-row-context-menu": "true",
261
- onClick: (e) => {
262
- e.stopPropagation();
263
- item.onClick();
264
- close();
265
- },
266
- children: /* @__PURE__ */ jsxs("span", { className: styles.contextMenuItemLabel, children: [
267
- item.icon,
268
- /* @__PURE__ */ jsx("span", { className: styles.contextMenuItemText, children: item.label })
269
- ] })
270
- }
271
- )
272
- },
273
- index
274
- )
250
+ (item, index) => item.type === "header" ? /* @__PURE__ */ jsx(Menu.Header, { children: item.label }, index) : /* @__PURE__ */ jsx(MenuAction, { item, onActivate: close, children: /* @__PURE__ */ jsxs("span", { className: styles.contextMenuItemLabel, children: [
251
+ item.icon,
252
+ /* @__PURE__ */ jsx("span", { className: styles.contextMenuItemText, children: item.label })
253
+ ] }) }, index)
275
254
  ) })
276
255
  }
277
256
  ) : null
package/dist/index.d.ts CHANGED
@@ -51,3 +51,4 @@ export * from './components/tree-view/TreeView';
51
51
  export * from './components/split-button/SplitButton';
52
52
  export * from './components/filtering/chip-multi-toggle/ChipMultiToggle';
53
53
  export * from './components/forms/checkbox-group/CheckboxGroup';
54
+ export type { MenuActionItem, MenuButtonItem, MenuLinkItem } from './components/menu/Menu.types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcdk/react-components",
3
- "version": "0.0.206",
3
+ "version": "0.0.207",
4
4
  "description": "Reusable React components for DBC projects",
5
5
  "license": "ISC",
6
6
  "author": "",