blue-react 10.2.0 → 11.0.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.
Files changed (76) hide show
  1. package/README.md +41 -84
  2. package/dist/components/A.js +13 -6
  3. package/dist/components/ActionMenu.js +27 -22
  4. package/dist/components/Actions.js +30 -22
  5. package/dist/components/Button.d.ts +31 -0
  6. package/dist/components/Button.js +119 -0
  7. package/dist/components/Chevron.js +11 -9
  8. package/dist/components/HashRouter.js +9 -6
  9. package/dist/components/Header.js +5 -3
  10. package/dist/components/HeaderTitle.js +31 -26
  11. package/dist/components/IconMenuItem.d.ts +2 -2
  12. package/dist/components/IconMenuItem.js +17 -10
  13. package/dist/components/Intro.js +23 -17
  14. package/dist/components/Layout.js +79 -71
  15. package/dist/{types/components/MenuItem.d.ts → components/LegacyMenuItem.d.ts} +150 -149
  16. package/dist/components/LegacyMenuItem.js +170 -0
  17. package/dist/components/MenuItem.d.ts +13 -149
  18. package/dist/components/MenuItem.js +168 -153
  19. package/dist/components/Modal.js +62 -49
  20. package/dist/components/ModalProvider.js +43 -35
  21. package/dist/components/Outside.js +5 -3
  22. package/dist/components/Search.js +69 -60
  23. package/dist/components/SidebarMenu.js +9 -6
  24. package/dist/components/SimpleLayout.js +16 -11
  25. package/dist/components/SlimContainer.js +8 -5
  26. package/dist/components/Status.js +56 -40
  27. package/dist/components/StatusProvider.js +22 -14
  28. package/dist/components/Tab.js +28 -19
  29. package/dist/components/Tabs.js +8 -5
  30. package/dist/components/ToastProvider.js +55 -44
  31. package/dist/components/shared.js +4 -1
  32. package/index.d.ts +5 -5
  33. package/index.js +4 -2
  34. package/package.json +14 -12
  35. package/dist/components/ActionMenuItem.js +0 -73
  36. package/dist/components/ActionMenuSwitch.js +0 -44
  37. package/dist/components/Body.d.ts +0 -21
  38. package/dist/components/Body.js +0 -25
  39. package/dist/components/Caret.js +0 -25
  40. package/dist/components/Layout/LayoutHeader.d.ts +0 -4
  41. package/dist/components/Layout/LayoutHeader.js +0 -25
  42. package/dist/components/Layout/LayoutMain.d.ts +0 -5
  43. package/dist/components/Layout/LayoutMain.js +0 -17
  44. package/dist/components/Page.d.ts +0 -13
  45. package/dist/components/Page.js +0 -39
  46. package/dist/components/SidebarMenuItem.js +0 -115
  47. package/dist/components/SidebarToggler.d.ts +0 -11
  48. package/dist/components/SidebarToggler.js +0 -24
  49. package/dist/components/Switch.js +0 -65
  50. package/dist/types/components/A.d.ts +0 -9
  51. package/dist/types/components/ActionMenu.d.ts +0 -25
  52. package/dist/types/components/ActionMenuItem.d.ts +0 -35
  53. package/dist/types/components/ActionMenuSwitch.d.ts +0 -12
  54. package/dist/types/components/Body.d.ts +0 -21
  55. package/dist/types/components/Caret.d.ts +0 -18
  56. package/dist/types/components/Chevron.d.ts +0 -17
  57. package/dist/types/components/Header.d.ts +0 -8
  58. package/dist/types/components/HeaderTitle.d.ts +0 -40
  59. package/dist/types/components/IconMenuItem.d.ts +0 -19
  60. package/dist/types/components/Intro.d.ts +0 -23
  61. package/dist/types/components/Layout.d.ts +0 -144
  62. package/dist/types/components/Modal.d.ts +0 -30
  63. package/dist/types/components/ModalProvider.d.ts +0 -21
  64. package/dist/types/components/Outside.d.ts +0 -17
  65. package/dist/types/components/Page.d.ts +0 -12
  66. package/dist/types/components/Search.d.ts +0 -36
  67. package/dist/types/components/SidebarMenu.d.ts +0 -32
  68. package/dist/types/components/SidebarMenuItem.d.ts +0 -22
  69. package/dist/types/components/SidebarToggler.d.ts +0 -10
  70. package/dist/types/components/SlimContainer.d.ts +0 -10
  71. package/dist/types/components/Status.d.ts +0 -12
  72. package/dist/types/components/StatusProvider.d.ts +0 -15
  73. package/dist/types/components/Switch.d.ts +0 -33
  74. package/dist/types/components/ToastProvider.d.ts +0 -22
  75. package/dist/types/components/Utilities.d.ts +0 -41
  76. package/dist/types/components/shared.d.ts +0 -15
@@ -0,0 +1,170 @@
1
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
7
+ import clsx from "clsx";
8
+ import React, { createElement, useEffect, useRef, useState } from "react";
9
+ import Outside from "./Outside.js";
10
+ import Chevron from "./Chevron.js";
11
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
12
+ function findParentWithClass(element, className) {
13
+ while (element && !element.classList.contains(className)) {
14
+ element = element.parentElement;
15
+ }
16
+ return element;
17
+ }
18
+ /**
19
+ * @deprecated
20
+ * Link, button or custom component for Sidebar, Actions or ActionMenu
21
+ */
22
+ export default function LegacyMenuItem(props) {
23
+ var id = "blue-menu-item-wrapper-".concat(Math.random().toString(36).substring(7));
24
+ var _useState = useState(false),
25
+ _useState2 = _slicedToArray(_useState, 2),
26
+ showDropdown = _useState2[0],
27
+ setShowDropdown = _useState2[1];
28
+ var _useState3 = useState(false),
29
+ _useState4 = _slicedToArray(_useState3, 2),
30
+ active = _useState4[0],
31
+ setActive = _useState4[1];
32
+ var menuRef = useRef(null);
33
+ var checkActive = function checkActive() {
34
+ setActive(props.href && window.location.hash.indexOf(props.href) > -1 || props.isHome && (window.location.hash === "" || window.location.hash === "#/") ? true : false);
35
+ };
36
+ var onClick = function onClick(event) {
37
+ if (props.href === "#") {
38
+ event.preventDefault();
39
+ }
40
+ if (props.onClick) {
41
+ props.onClick(event);
42
+ }
43
+ if (props.children) {
44
+ setShowDropdown(!showDropdown);
45
+ }
46
+ if (props.onClickAttached !== undefined) {
47
+ props.onClickAttached(event);
48
+ }
49
+ };
50
+ var onClickOutside = function onClickOutside(_ref) {
51
+ var target = _ref.target;
52
+ var ignoreClasses = props.outsideIgnoreClasses || [id];
53
+ if (ignoreClasses && target) {
54
+ for (var i = 0; i < ignoreClasses.length; i++) {
55
+ if (target !== null && target !== void 0 && target.classList.contains(ignoreClasses[i]) || findParentWithClass(target, ignoreClasses[i])) {
56
+ return;
57
+ }
58
+ }
59
+ }
60
+ setShowDropdown(false);
61
+ };
62
+ useEffect(function () {
63
+ checkActive();
64
+ window.addEventListener("hashchange", function () {
65
+ checkActive();
66
+ });
67
+ }, []);
68
+ useEffect(function () {
69
+ if (props.showDropdown !== undefined) setShowDropdown(props.showDropdown);
70
+ }, [props.showDropdown]);
71
+ useEffect(function () {
72
+ if (props.onShowDropdown) {
73
+ props.onShowDropdown(showDropdown);
74
+ }
75
+ }, [props.onShowDropdown, showDropdown]);
76
+ useEffect(function () {
77
+ if (menuRef && menuRef.current) {
78
+ var el = menuRef.current;
79
+ var rect = el.getBoundingClientRect();
80
+ el.style.setProperty("--offset-top", Math.round(rect.top) + "px");
81
+ }
82
+ }, [menuRef, showDropdown]);
83
+ var className = "blue-menu-item btn" + (props.isActive ? " active" : "") + (props.className ? " " + props.className : "") + (props.children ? " blue-menu-item-dropdown-toggle w-100" : "") + (props.highlighted ? " highlighted" : "");
84
+ var icon, iconForActive;
85
+ if (typeof props.icon === "string") {
86
+ // is className
87
+ icon = /*#__PURE__*/_jsx("span", {
88
+ className: props.icon + (props.children ? " blue-menu-item-dropdown-icon" : "")
89
+ });
90
+ } else {
91
+ // is element / component
92
+ icon = props.icon;
93
+ }
94
+ if (typeof props.iconForActive === "string") {
95
+ // is className
96
+ iconForActive = /*#__PURE__*/_jsx("span", {
97
+ className: props.iconForActive + (props.children ? " blue-menu-item-dropdown-icon" : "")
98
+ });
99
+ } else {
100
+ // is element / component
101
+ iconForActive = props.iconForActive;
102
+ }
103
+ return /*#__PURE__*/_jsxs("div", {
104
+ className: "blue-menu-item-wrapper ".concat(id),
105
+ children: [/*#__PURE__*/createElement(props.elementType || (props.href ? "a" : "button"), {
106
+ to: props.to,
107
+ href: props.href,
108
+ exact: props.exact,
109
+ className: className + (props.isActive || active ? " active" : "") + (props.label ? " has-label" : ""),
110
+ onClick: onClick,
111
+ target: props.target,
112
+ rel: props.rel,
113
+ title: props.title,
114
+ onDragStart: props.onDragStart,
115
+ onDrag: props.onDrag,
116
+ onDragEnd: props.onDragEnd,
117
+ onDragEnter: props.onDragEnter,
118
+ onDragOver: props.onDragOver,
119
+ onDragLeave: props.onDragLeave,
120
+ onDrop: props.onDrop,
121
+ draggable: props.draggable,
122
+ "data-tooltip": props["data-tooltip"],
123
+ disabled: props.disabled,
124
+ style: props.style,
125
+ type: props.type,
126
+ id: props.id
127
+ }, /*#__PURE__*/_jsxs(_Fragment, {
128
+ children: [props.draggable && props.hideDraggableIcon !== true && /*#__PURE__*/_jsxs(_Fragment, {
129
+ children: [/*#__PURE__*/_jsx("svg", {
130
+ xmlns: "http://www.w3.org/2000/svg",
131
+ width: ".5em",
132
+ height: "1em",
133
+ fill: "currentColor",
134
+ className: "bi bi-grip-vertical opacity-50",
135
+ viewBox: "0 0 8 16",
136
+ children: /*#__PURE__*/_jsx("path", {
137
+ d: "M3.376 1.876c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m-3 3c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m-3 3c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m-3 3c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m-3 3c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1"
138
+ })
139
+ }), " "]
140
+ }), props.icon !== undefined && /*#__PURE__*/_jsx("span", {
141
+ className: clsx("blue-menu-item-icon", props.iconClassName, {
142
+ hasIconForActive: iconForActive
143
+ }),
144
+ children: icon
145
+ }), iconForActive && /*#__PURE__*/_jsx("span", {
146
+ className: clsx("blue-menu-item-icon iconForActive", props.iconClassName),
147
+ children: iconForActive
148
+ }), props.label && /*#__PURE__*/_jsx("span", {
149
+ className: clsx("blue-menu-item-label text-truncate", props.labelClassName),
150
+ children: props.label
151
+ }), props.children && /*#__PURE__*/_jsx(Chevron, {
152
+ open: showDropdown,
153
+ mirrored: true,
154
+ className: clsx("blue-menu-item-dropdown-caret ms-auto", props.caretClassName),
155
+ style: props.caretStyle
156
+ })]
157
+ })), showDropdown && (props.supportOutside ? /*#__PURE__*/_jsx(Outside, {
158
+ wrapperRef: menuRef,
159
+ className: clsx("blue-menu-item-dropdown", props.dropdownClassName),
160
+ onClickOutside: onClickOutside,
161
+ style: props.dropdownStyle,
162
+ children: props.children
163
+ }) : /*#__PURE__*/_jsx("div", {
164
+ ref: menuRef,
165
+ className: clsx("blue-menu-item-dropdown", props.dropdownClassName),
166
+ style: props.dropdownStyle,
167
+ children: props.children
168
+ }))]
169
+ });
170
+ }
@@ -1,149 +1,13 @@
1
- import React, { CSSProperties } from "react";
2
- export interface MenuItemProps {
3
- /**
4
- * Sets `to` prop, e.g. when you use the `NavLink` component from React Router.
5
- */
6
- to?: string;
7
- /**
8
- * Prop for components by React Router.
9
- */
10
- exact?: boolean;
11
- href?: string;
12
- onClick?: (event: React.MouseEvent) => void;
13
- /**
14
- * Will be fired after `onClick`
15
- */
16
- onClickAttached?: (event: React.MouseEvent) => void;
17
- /**
18
- * Icon component or a class name.
19
- */
20
- icon?: any;
21
- /**
22
- * Addition to class name of icon wrapper element
23
- */
24
- iconClassName?: string;
25
- /**
26
- * Icon component or a class name when the MenuItem is active.
27
- */
28
- iconForActive?: any;
29
- /**
30
- * Label of the link.
31
- */
32
- label?: any;
33
- /**
34
- * Addition to class name of label wrapper element
35
- */
36
- labelClassName?: string;
37
- /**
38
- * Addition to class name of caret
39
- */
40
- caretClassName?: string;
41
- /**
42
- * Addition to style of caret
43
- */
44
- caretStyle?: CSSProperties;
45
- /**
46
- * Should be set as active.
47
- */
48
- isActive?: boolean;
49
- /**
50
- * Set true to highlight the current menu item.
51
- */
52
- highlighted?: boolean;
53
- /**
54
- * When using Blue React's routing system: define this link as home page link.
55
- */
56
- isHome?: boolean;
57
- /**
58
- * Extends class name of the dropdown menu.
59
- */
60
- dropdownClassName?: string;
61
- /**
62
- * Extends style of the dropdown menu.
63
- */
64
- dropdownStyle?: CSSProperties;
65
- /**
66
- * Set children to create a nested `MenuItem` as a dropdown.
67
- */
68
- children?: any;
69
- /**
70
- * Defines class name.
71
- */
72
- className?: any;
73
- /**
74
- * Defines dropdown status from outside.
75
- */
76
- showDropdown?: boolean;
77
- /**
78
- * Callback when `showDropdown` changes.
79
- */
80
- onShowDropdown?: (showDropdown: boolean) => void;
81
- /**
82
- * Close on click outside.
83
- */
84
- supportOutside?: boolean;
85
- /**
86
- * Overrides default class list to be ignored on click outside.
87
- * Hint: If you want this menu item to stay open when others will open, set:
88
- * `outsideIgnoreClasses={["blue-menu-item-wrapper"]}`.
89
- */
90
- outsideIgnoreClasses?: string[];
91
- /**
92
- * By default, MenuItem is a `"button"`. If you set a `href`, it's a `"a"`.
93
- * If you want to have it another type, you can pass a component reference with this prop (e.g. `Link`).
94
- */
95
- elementType?: any;
96
- target?: string;
97
- rel?: string;
98
- title?: string;
99
- type?: string;
100
- /**
101
- * Fired on the draggable target (the source element): occurs when the user starts to drag an element
102
- */
103
- onDragStart?: (event: React.DragEvent) => void | React.DragEventHandler;
104
- /**
105
- * Fired on the draggable target (the source element): occurs when an element is being dragged
106
- */
107
- onDrag?: (event: React.DragEvent) => void | React.DragEventHandler;
108
- /**
109
- * Fired on the draggable target (the source element): occurs when the user has finished dragging the element
110
- */
111
- onDragEnd?: (event: React.DragEvent) => void | React.DragEventHandler;
112
- /**
113
- * Fired on the drop target: occurs when the dragged element enters the drop target
114
- */
115
- onDragEnter?: (event: React.DragEvent) => void | React.DragEventHandler;
116
- /**
117
- * Fired on the drop target: occurs when the dragged element is over the drop target
118
- */
119
- onDragOver?: (event: React.DragEvent) => void | React.DragEventHandler;
120
- /**
121
- * Fired on the drop target: occurs when the dragged element leaves the drop target
122
- */
123
- onDragLeave?: (event: React.DragEvent) => void | React.DragEventHandler;
124
- /**
125
- * Fired on the drop target: occurs when the dragged element is dropped on the drop target
126
- */
127
- onDrop?: (event: React.DragEvent) => void | React.DragEventHandler;
128
- /**
129
- * Specifies whether an element is draggable or not.
130
- *
131
- * **Important:** To make draggable menu items work in Firefox, the elementType must not be `"button"`. Set it to something else, like `"div"`.
132
- */
133
- draggable?: boolean;
134
- hideDraggableIcon?: boolean;
135
- "data-tooltip"?: string;
136
- /**
137
- * Specifies whether an element is disabled or not.
138
- */
139
- disabled?: boolean;
140
- /**
141
- * Specifies style of an element.
142
- */
143
- style?: React.CSSProperties;
144
- id?: string;
145
- }
146
- /**
147
- * Link, button or custom component for Sidebar, Actions or ActionMenu
148
- */
149
- export default function MenuItem(props: MenuItemProps): import("react/jsx-runtime").JSX.Element;
1
+ import { ReactNode } from "react";
2
+ import { ButtonProps } from "./Button";
3
+ export type MenuItemProps = ButtonProps & {
4
+ current?: boolean;
5
+ defaultDisplay?: boolean;
6
+ buttonContent?: ReactNode;
7
+ /** Uses `iconBefore` slot. If `iconForCurrent` and menu item is current, this will be hidden. */
8
+ icon?: ReactNode;
9
+ /** Uses `iconBefore` slot. If menu item is current, this will be visible. */
10
+ iconForCurrent?: ReactNode;
11
+ as?: "collapse" | "collapse-group" | "popover-group";
12
+ };
13
+ export default function MenuItem({ as, ...props }: MenuItemProps): import("react/jsx-runtime").JSX.Element;
@@ -1,157 +1,172 @@
1
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _excluded = ["className", "children"],
3
+ _excluded2 = ["current", "className", "defaultDisplay", "children", "buttonContent", "icon", "iconForCurrent"],
4
+ _excluded3 = ["className", "children"],
5
+ _excluded4 = ["children", "iconAfter"],
6
+ _excluded5 = ["as"];
7
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
10
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
11
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
12
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
13
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
14
+ import { useId } from "react";
15
+ import Button from "./Button.js";
7
16
  import clsx from "clsx";
8
- import React, { createElement, useEffect, useRef, useState } from "react";
9
- import Outside from "./Outside.js";
10
- import Chevron from "./Chevron.js";
11
- function findParentWithClass(element, className) {
12
- while (element && !element.classList.contains(className)) {
13
- element = element.parentElement;
14
- }
15
- return element;
17
+ import { getPhrase } from "./shared.js";
18
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
19
+ // & {
20
+ // popoverClassName?: string
21
+ // popoverStyle?: CSSProperties
22
+ // } & {
23
+ // collapseGroupClassName?: string
24
+ // collapseGroupStyle?: CSSProperties
25
+ // } & {
26
+ // collapseClassName?: string
27
+ // collapseStyle?: CSSProperties
28
+ // }
29
+
30
+ function ChevronSummary(_ref) {
31
+ var className = _ref.className,
32
+ children = _ref.children,
33
+ props = _objectWithoutProperties(_ref, _excluded);
34
+ return /*#__PURE__*/_jsxs("summary", _objectSpread(_objectSpread({
35
+ className: clsx("btn blue-collapse-header blue-menu-item icon-link", {
36
+ "blue-btn-square": children === undefined
37
+ }, className)
38
+ }, props), {}, {
39
+ children: [children, children === undefined && /*#__PURE__*/_jsx("span", {
40
+ className: "visually-hidden",
41
+ children: getPhrase("Toggle details")
42
+ }), /*#__PURE__*/_jsx("div", {
43
+ className: "blue-btn-icon-wrapper",
44
+ "aria-hidden": true,
45
+ children: /*#__PURE__*/_jsx("svg", {
46
+ xmlns: "http://www.w3.org/2000/svg",
47
+ className: clsx("blue-collapse-chevron", {
48
+ "ms-auto": children !== undefined
49
+ }),
50
+ viewBox: "0 0 16 16",
51
+ children: /*#__PURE__*/_jsx("path", {
52
+ fillRule: "evenodd",
53
+ d: "M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708"
54
+ })
55
+ })
56
+ })]
57
+ }));
16
58
  }
17
- /**
18
- * Link, button or custom component for Sidebar, Actions or ActionMenu
19
- */
20
- export default function MenuItem(props) {
21
- var id = "blue-menu-item-wrapper-".concat(Math.random().toString(36).substring(7));
22
- var _useState = useState(false),
23
- _useState2 = _slicedToArray(_useState, 2),
24
- showDropdown = _useState2[0],
25
- setShowDropdown = _useState2[1];
26
- var _useState3 = useState(false),
27
- _useState4 = _slicedToArray(_useState3, 2),
28
- active = _useState4[0],
29
- setActive = _useState4[1];
30
- var menuRef = useRef(null);
31
- var checkActive = function checkActive() {
32
- setActive(props.href && window.location.hash.indexOf(props.href) > -1 || props.isHome && (window.location.hash === "" || window.location.hash === "#/") ? true : false);
33
- };
34
- var onClick = function onClick(event) {
35
- if (props.href === "#") {
36
- event.preventDefault();
37
- }
38
- if (props.onClick) {
39
- props.onClick(event);
40
- }
41
- if (props.children) {
42
- setShowDropdown(!showDropdown);
43
- }
44
- if (props.onClickAttached !== undefined) {
45
- props.onClickAttached(event);
46
- }
47
- };
48
- var onClickOutside = function onClickOutside(_ref) {
49
- var target = _ref.target;
50
- var ignoreClasses = props.outsideIgnoreClasses || [id];
51
- if (ignoreClasses && target) {
52
- for (var i = 0; i < ignoreClasses.length; i++) {
53
- if (target !== null && target !== void 0 && target.classList.contains(ignoreClasses[i]) || findParentWithClass(target, ignoreClasses[i])) {
54
- return;
55
- }
56
- }
57
- }
58
- setShowDropdown(false);
59
- };
60
- useEffect(function () {
61
- checkActive();
62
- window.addEventListener("hashchange", function () {
63
- checkActive();
64
- });
65
- }, []);
66
- useEffect(function () {
67
- if (props.showDropdown !== undefined) setShowDropdown(props.showDropdown);
68
- }, [props.showDropdown]);
69
- useEffect(function () {
70
- if (props.onShowDropdown) {
71
- props.onShowDropdown(showDropdown);
72
- }
73
- }, [props.onShowDropdown, showDropdown]);
74
- useEffect(function () {
75
- if (menuRef && menuRef.current) {
76
- var el = menuRef.current;
77
- var rect = el.getBoundingClientRect();
78
- el.style.setProperty("--offset-top", Math.round(rect.top) + "px");
79
- }
80
- }, [menuRef, showDropdown]);
81
- var className = "blue-menu-item btn" + (props.isActive ? " active" : "") + (props.className ? " " + props.className : "") + (props.children ? " blue-menu-item-dropdown-toggle w-100" : "") + (props.highlighted ? " highlighted" : "");
82
- var icon, iconForActive;
83
- if (typeof props.icon === "string") {
84
- // is className
85
- icon = /*#__PURE__*/React.createElement("span", {
86
- className: props.icon + (props.children ? " blue-menu-item-dropdown-icon" : "")
87
- });
88
- } else {
89
- // is element / component
90
- icon = props.icon;
91
- }
92
- if (typeof props.iconForActive === "string") {
93
- // is className
94
- iconForActive = /*#__PURE__*/React.createElement("span", {
95
- className: props.iconForActive + (props.children ? " blue-menu-item-dropdown-icon" : "")
96
- });
97
- } else {
98
- // is element / component
99
- iconForActive = props.iconForActive;
100
- }
101
- return /*#__PURE__*/React.createElement("div", {
102
- className: "blue-menu-item-wrapper ".concat(id)
103
- }, /*#__PURE__*/createElement(props.elementType || (props.href ? "a" : "button"), {
104
- to: props.to,
105
- href: props.href,
106
- exact: props.exact,
107
- className: className + (props.isActive || active ? " active" : "") + (props.label ? " has-label" : ""),
108
- onClick: onClick,
109
- target: props.target,
110
- rel: props.rel,
111
- title: props.title,
112
- onDragStart: props.onDragStart,
113
- onDrag: props.onDrag,
114
- onDragEnd: props.onDragEnd,
115
- onDragEnter: props.onDragEnter,
116
- onDragOver: props.onDragOver,
117
- onDragLeave: props.onDragLeave,
118
- onDrop: props.onDrop,
119
- draggable: props.draggable,
120
- "data-tooltip": props["data-tooltip"],
121
- disabled: props.disabled,
122
- style: props.style,
123
- type: props.type,
124
- id: props.id
125
- }, /*#__PURE__*/React.createElement(React.Fragment, null, props.draggable && props.hideDraggableIcon !== true && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("svg", {
126
- xmlns: "http://www.w3.org/2000/svg",
127
- width: ".5em",
128
- height: "1em",
129
- fill: "currentColor",
130
- className: "bi bi-grip-vertical opacity-50",
131
- viewBox: "0 0 8 16"
132
- }, /*#__PURE__*/React.createElement("path", {
133
- d: "M3.376 1.876c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m-3 3c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m-3 3c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m-3 3c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m-3 3c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1"
134
- })), " "), props.icon !== undefined && /*#__PURE__*/React.createElement("span", {
135
- className: clsx("blue-menu-item-icon", props.iconClassName, {
136
- hasIconForActive: iconForActive
59
+ function Base(_ref2) {
60
+ var current = _ref2.current,
61
+ className = _ref2.className,
62
+ _ref2$defaultDisplay = _ref2.defaultDisplay,
63
+ defaultDisplay = _ref2$defaultDisplay === void 0 ? false : _ref2$defaultDisplay,
64
+ children = _ref2.children,
65
+ buttonContent = _ref2.buttonContent,
66
+ icon = _ref2.icon,
67
+ iconForCurrent = _ref2.iconForCurrent,
68
+ props = _objectWithoutProperties(_ref2, _excluded2);
69
+ return /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({
70
+ variant: "menu-item",
71
+ className: clsx({
72
+ current: current,
73
+ "d-flex": !defaultDisplay
74
+ }, className),
75
+ iconBefore: props.iconBefore || (icon || iconForCurrent) && /*#__PURE__*/_jsxs(_Fragment, {
76
+ children: [icon !== null && /*#__PURE__*/_jsx("span", {
77
+ className: clsx({
78
+ "blue-menu-item-current-hidden": iconForCurrent !== undefined
79
+ }),
80
+ style: {
81
+ display: "contents"
82
+ },
83
+ children: icon
84
+ }), iconForCurrent !== undefined && /*#__PURE__*/_jsx("span", {
85
+ className: "blue-menu-item-default-hidden",
86
+ style: {
87
+ display: "contents"
88
+ },
89
+ children: iconForCurrent
90
+ }), buttonContent]
137
91
  })
138
- }, icon), iconForActive && /*#__PURE__*/React.createElement("span", {
139
- className: clsx("blue-menu-item-icon iconForActive", props.iconClassName)
140
- }, iconForActive), props.label && /*#__PURE__*/React.createElement("span", {
141
- className: clsx("blue-menu-item-label text-truncate", props.labelClassName)
142
- }, props.label), props.children && /*#__PURE__*/React.createElement(Chevron, {
143
- open: showDropdown,
144
- mirrored: true,
145
- className: clsx("blue-menu-item-dropdown-caret ms-auto", props.caretClassName),
146
- style: props.caretStyle
147
- }))), showDropdown && (props.supportOutside ? /*#__PURE__*/React.createElement(Outside, {
148
- wrapperRef: menuRef,
149
- className: clsx("blue-menu-item-dropdown", props.dropdownClassName),
150
- onClickOutside: onClickOutside,
151
- style: props.dropdownStyle
152
- }, props.children) : /*#__PURE__*/React.createElement("div", {
153
- ref: menuRef,
154
- className: clsx("blue-menu-item-dropdown", props.dropdownClassName),
155
- style: props.dropdownStyle
156
- }, props.children)));
92
+ }, props), {}, {
93
+ children: buttonContent
94
+ }));
95
+ }
96
+ function Collapse(_ref3) {
97
+ var children = _ref3.children,
98
+ iconBefore = _ref3.iconBefore,
99
+ label = _ref3.label,
100
+ labelHidden = _ref3.labelHidden,
101
+ iconAfter = _ref3.iconAfter,
102
+ buttonContent = _ref3.buttonContent;
103
+ return /*#__PURE__*/_jsxs("details", {
104
+ className: "blue-collapse",
105
+ children: [/*#__PURE__*/_jsxs(ChevronSummary, {
106
+ className: "d-flex",
107
+ children: [iconBefore !== null && /*#__PURE__*/_jsx("span", {
108
+ className: "blue-btn-icon-wrapper",
109
+ "aria-hidden": true,
110
+ children: iconBefore
111
+ }), labelHidden ? /*#__PURE__*/_jsx("span", {
112
+ className: "visually-hidden",
113
+ children: label
114
+ }) : label, buttonContent, iconAfter != null && /*#__PURE__*/_jsx("span", {
115
+ className: "blue-btn-icon-wrapper",
116
+ "aria-hidden": true,
117
+ children: iconAfter
118
+ })]
119
+ }), /*#__PURE__*/_jsx("div", {
120
+ className: "blue-collapse-indent vstack border-start",
121
+ children: children
122
+ })]
123
+ });
124
+ }
125
+ function CollapseGroup(_ref4) {
126
+ var className = _ref4.className,
127
+ children = _ref4.children,
128
+ props = _objectWithoutProperties(_ref4, _excluded3);
129
+ return /*#__PURE__*/_jsxs("div", {
130
+ className: clsx("blue-collapse-group"),
131
+ children: [/*#__PURE__*/_jsx(Base, _objectSpread({}, props)), /*#__PURE__*/_jsxs("details", {
132
+ className: "blue-collapse",
133
+ children: [/*#__PURE__*/_jsx(ChevronSummary, {}), /*#__PURE__*/_jsx("div", {
134
+ className: "blue-collapse-indent vstack border-start",
135
+ children: children
136
+ })]
137
+ })]
138
+ });
139
+ }
140
+ function PopoverGroup(_ref5) {
141
+ var children = _ref5.children,
142
+ iconAfter = _ref5.iconAfter,
143
+ props = _objectWithoutProperties(_ref5, _excluded4);
144
+ var id = useId();
145
+ return /*#__PURE__*/_jsxs(_Fragment, {
146
+ children: [/*#__PURE__*/_jsx(Base, _objectSpread({
147
+ popoverTarget: id,
148
+ iconAfter: iconAfter || /*#__PURE__*/_jsx("svg", {
149
+ xmlns: "http://www.w3.org/2000/svg",
150
+ viewBox: "0 0 16 16",
151
+ children: /*#__PURE__*/_jsx("path", {
152
+ fillRule: "evenodd",
153
+ d: "M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708"
154
+ })
155
+ })
156
+ }, props)), /*#__PURE__*/_jsx("div", {
157
+ id: id,
158
+ popover: "",
159
+ className: clsx("blue-anchored blue-anchored-fallback border rounded-4 shadow"),
160
+ children: /*#__PURE__*/_jsx("div", {
161
+ className: "vstack",
162
+ children: children
163
+ })
164
+ })]
165
+ });
166
+ }
167
+ export default function MenuItem(_ref6) {
168
+ var as = _ref6.as,
169
+ props = _objectWithoutProperties(_ref6, _excluded5);
170
+ var Comp = as === "collapse" ? Collapse : as === "collapse-group" ? CollapseGroup : as === "popover-group" ? PopoverGroup : Base;
171
+ return /*#__PURE__*/_jsx(Comp, _objectSpread({}, props));
157
172
  }