@entur/menu 5.2.1-beta.9 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/menu.esm.js CHANGED
@@ -1,347 +1,318 @@
1
- import { useOnClickOutside, useOnEscape, getNodeText, useRandomId, warnAboutMissingStyles } from '@entur/utils';
2
- import React, { useState, useEffect, useRef, cloneElement, useContext } from 'react';
3
- import classNames from 'classnames';
4
- import { RightArrowIcon, MenuIcon, LeftArrowIcon, VerticalDotsIcon, DownArrowIcon } from '@entur/icons';
5
- import { useFloating, offset, flip, shift, autoUpdate, useListNavigation, useTypeahead, useRole, useInteractions, FloatingList, useListItem } from '@floating-ui/react';
6
- import { IconButton } from '@entur/button';
7
- import { standardisePlacement } from '@entur/tooltip';
8
- import { space } from '@entur/tokens';
9
- import { VisuallyHidden } from '@entur/a11y';
10
- import { Label } from '@entur/typography';
11
- import { ExpandArrow, BaseExpand } from '@entur/expand';
12
-
13
- var BreadcrumbNavigation = function BreadcrumbNavigation(_ref) {
14
- var _ref$ariaLabel = _ref['aria-label'],
15
- ariaLabel = _ref$ariaLabel === void 0 ? 'Brødsmulesti' : _ref$ariaLabel,
16
- children = _ref.children;
17
- return React.createElement("nav", {
18
- "aria-label": ariaLabel
19
- }, React.createElement("ol", {
20
- className: "eds-breadcrumbs"
21
- }, React.Children.map(children, function (child, index) {
22
- // @ts-expect-error should check if children are correct but for now it is only mentioned in the documentation
1
+ import { useOnClickOutside, useOnEscape, getNodeText, useRandomId, warnAboutMissingStyles } from "@entur/utils";
2
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
+ import React, { useState, useEffect, useRef, cloneElement, useContext } from "react";
4
+ import classNames from "classnames";
5
+ import { RightArrowIcon, MenuIcon, LeftArrowIcon, VerticalDotsIcon, DownArrowIcon } from "@entur/icons";
6
+ import { useFloating, offset, flip, shift, autoUpdate, useListNavigation, useTypeahead, useRole, useInteractions, FloatingList, useListItem } from "@floating-ui/react";
7
+ import { IconButton } from "@entur/button";
8
+ import { standardisePlacement } from "@entur/tooltip";
9
+ import { space } from "@entur/tokens";
10
+ import { VisuallyHidden } from "@entur/a11y";
11
+ import { Label } from "@entur/typography";
12
+ import { ExpandArrow, BaseExpand } from "@entur/expand";
13
+ const BreadcrumbNavigation = ({
14
+ "aria-label": ariaLabel = "Brødsmulesti",
15
+ children
16
+ }) => {
17
+ return /* @__PURE__ */ jsx("nav", { "aria-label": ariaLabel, children: /* @__PURE__ */ jsx("ol", { className: "eds-breadcrumbs", children: React.Children.map(children, (child, index) => {
23
18
  return React.cloneElement(child, {
24
19
  isCurrent: index + 1 === React.Children.count(children)
25
20
  });
26
- })));
21
+ }) }) });
27
22
  };
28
-
29
- function _extends() {
30
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
31
- for (var e = 1; e < arguments.length; e++) {
32
- var t = arguments[e];
33
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
34
- }
35
- return n;
36
- }, _extends.apply(null, arguments);
37
- }
38
- function _objectWithoutPropertiesLoose(r, e) {
39
- if (null == r) return {};
40
- var t = {};
41
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
42
- if (-1 !== e.indexOf(n)) continue;
43
- t[n] = r[n];
44
- }
45
- return t;
46
- }
47
-
48
- var _excluded$8 = ["className", "isCurrent", "as"];
49
- var defaultElement$1 = 'a';
50
- var BreadcrumbItem = function BreadcrumbItem(_ref) {
51
- var className = _ref.className,
52
- isCurrent = _ref.isCurrent,
53
- as = _ref.as,
54
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$8);
55
- var Element = as || defaultElement$1;
56
- return React.createElement(React.Fragment, null, React.createElement("li", {
57
- className: classNames('eds-breadcrumb__item', className)
58
- }, React.createElement(Element, _extends({
59
- "aria-current": isCurrent ? 'page' : undefined,
60
- className: classNames('eds-breadcrumb__link', {
61
- 'eds-breadcrumb__link--current': isCurrent
62
- })
63
- }, rest))), !isCurrent && React.createElement(RightArrowIcon, {
64
- className: "eds-breadcrumb__separator",
65
- inline: true,
66
- role: "presentation"
67
- }));
23
+ const defaultElement$1 = "a";
24
+ const BreadcrumbItem = ({
25
+ className,
26
+ isCurrent,
27
+ as,
28
+ ...rest
29
+ }) => {
30
+ const Element = as || defaultElement$1;
31
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
32
+ /* @__PURE__ */ jsx("li", { className: classNames("eds-breadcrumb__item", className), children: /* @__PURE__ */ jsx(
33
+ Element,
34
+ {
35
+ "aria-current": isCurrent ? "page" : void 0,
36
+ className: classNames("eds-breadcrumb__link", {
37
+ "eds-breadcrumb__link--current": isCurrent
38
+ }),
39
+ ...rest
40
+ }
41
+ ) }),
42
+ !isCurrent && /* @__PURE__ */ jsx(
43
+ RightArrowIcon,
44
+ {
45
+ className: "eds-breadcrumb__separator",
46
+ inline: true,
47
+ role: "presentation"
48
+ }
49
+ )
50
+ ] });
68
51
  };
69
-
70
- function useControllableProp(_ref) {
71
- var prop = _ref.prop,
72
- _ref$updater = _ref.updater,
73
- updater = _ref$updater === void 0 ? function () {
74
- return undefined;
75
- } : _ref$updater,
76
- defaultValue = _ref.defaultValue;
77
- var _useState = useState(defaultValue),
78
- internalState = _useState[0],
79
- setInternalState = _useState[1];
80
- useEffect(function () {
81
- if (prop !== undefined) {
52
+ function useControllableProp({
53
+ prop,
54
+ updater = () => void 0,
55
+ defaultValue
56
+ }) {
57
+ const [internalState, setInternalState] = useState(defaultValue);
58
+ useEffect(() => {
59
+ if (prop !== void 0) {
82
60
  setInternalState(prop);
83
61
  }
84
62
  }, [prop]);
85
- return prop === undefined ? [internalState, setInternalState] : [prop, updater];
63
+ return prop === void 0 ? [internalState, setInternalState] : [prop, updater];
86
64
  }
87
-
88
- var _excluded$7 = ["className", "children", "size", "collapsed", "onCollapseToggle", "collapsibleButtonPosition", "openSideMenuAriaLabel", "closeSideMenuAriaLabel"];
89
- var CollapsibleSideNavigation = function CollapsibleSideNavigation(_ref) {
90
- var className = _ref.className,
91
- children = _ref.children,
92
- size = _ref.size,
93
- collapsible = _ref.collapsed,
94
- onCollapseToggle = _ref.onCollapseToggle,
95
- _ref$collapsibleButto = _ref.collapsibleButtonPosition,
96
- collapsibleButtonPosition = _ref$collapsibleButto === void 0 ? '50%' : _ref$collapsibleButto,
97
- _ref$openSideMenuAria = _ref.openSideMenuAriaLabel,
98
- openSideMenuAriaLabel = _ref$openSideMenuAria === void 0 ? 'Åpne sidemeny' : _ref$openSideMenuAria,
99
- _ref$closeSideMenuAri = _ref.closeSideMenuAriaLabel,
100
- closeSideMenuAriaLabel = _ref$closeSideMenuAri === void 0 ? 'Lukk sidemeny' : _ref$closeSideMenuAri,
101
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$7);
102
- var _useControllableProp = useControllableProp({
103
- prop: collapsible,
104
- defaultValue: false,
105
- updater: onCollapseToggle
106
- }),
107
- collapsedMenu = _useControllableProp[0],
108
- setCollapsedMenu = _useControllableProp[1];
109
- return React.createElement(SideNavigationContext.Provider, {
110
- value: {
111
- isCollapsed: collapsedMenu
112
- }
113
- }, React.createElement("ul", _extends({
114
- className: classNames('eds-side-navigation', {
115
- 'eds-side-navigation--small': size === 'small'
116
- }, {
117
- 'eds-side-navigation--collapsed': collapsedMenu
118
- }, className)
119
- }, rest), children, React.createElement("button", {
120
- className: "eds-side-navigation__collapse-button",
121
- onClick: function onClick() {
122
- return setCollapsedMenu(!collapsedMenu);
123
- },
124
- style: {
125
- top: "" + collapsibleButtonPosition
65
+ const CollapsibleSideNavigation = ({
66
+ className,
67
+ children,
68
+ size,
69
+ collapsed: collapsible,
70
+ onCollapseToggle,
71
+ collapsibleButtonPosition = "50%",
72
+ openSideMenuAriaLabel = "Åpne sidemeny",
73
+ closeSideMenuAriaLabel = "Lukk sidemeny",
74
+ ...rest
75
+ }) => {
76
+ const [collapsedMenu, setCollapsedMenu] = useControllableProp({
77
+ prop: collapsible,
78
+ defaultValue: false,
79
+ updater: onCollapseToggle
80
+ });
81
+ return /* @__PURE__ */ jsx(
82
+ SideNavigationContext.Provider,
83
+ {
84
+ value: {
85
+ isCollapsed: collapsedMenu
86
+ },
87
+ children: /* @__PURE__ */ jsxs(
88
+ "ul",
89
+ {
90
+ className: classNames(
91
+ "eds-side-navigation",
92
+ { "eds-side-navigation--small": size === "small" },
93
+ { "eds-side-navigation--collapsed": collapsedMenu },
94
+ className
95
+ ),
96
+ ...rest,
97
+ children: [
98
+ children,
99
+ /* @__PURE__ */ jsx(
100
+ "button",
101
+ {
102
+ className: "eds-side-navigation__collapse-button",
103
+ onClick: () => setCollapsedMenu(!collapsedMenu),
104
+ style: { top: `${collapsibleButtonPosition}` },
105
+ children: collapsedMenu ? /* @__PURE__ */ jsx(MenuIcon, { "aria-label": openSideMenuAriaLabel }) : /* @__PURE__ */ jsx(LeftArrowIcon, { "aria-label": closeSideMenuAriaLabel })
106
+ }
107
+ )
108
+ ]
109
+ }
110
+ )
126
111
  }
127
- }, collapsedMenu ? React.createElement(MenuIcon, {
128
- "aria-label": openSideMenuAriaLabel
129
- }) : React.createElement(LeftArrowIcon, {
130
- "aria-label": closeSideMenuAriaLabel
131
- }))));
112
+ );
132
113
  };
133
- var SideNavigationContext = /*#__PURE__*/React.createContext({
114
+ const SideNavigationContext = React.createContext({
134
115
  isCollapsed: false
135
116
  });
136
- var useSideNavigationContext = function useSideNavigationContext() {
137
- var context = React.useContext(SideNavigationContext);
117
+ const useSideNavigationContext = () => {
118
+ const context = React.useContext(SideNavigationContext);
138
119
  if (!context) {
139
- console.error('Error reading SideNavigationContext. Please contact maintainer of @entur/menu');
120
+ console.error(
121
+ "Error reading SideNavigationContext. Please contact maintainer of @entur/menu"
122
+ );
140
123
  }
141
124
  return context;
142
125
  };
143
-
144
- var _excluded$6 = ["children", "className", "button", "buttonIcon", "placement", "aria-label"],
145
- _excluded2$1 = ["children", "className", "onSelect", "href", "disabled", "as"];
146
- var SelectContext = /*#__PURE__*/React.createContext({});
147
- var OverflowMenu = function OverflowMenu(_ref) {
148
- var children = _ref.children,
149
- className = _ref.className,
150
- button = _ref.button,
151
- buttonIcon = _ref.buttonIcon,
152
- _ref$placement = _ref.placement,
153
- placement = _ref$placement === void 0 ? 'bottom-start' : _ref$placement,
154
- _ref$ariaLabel = _ref['aria-label'],
155
- ariaLabel = _ref$ariaLabel === void 0 ? 'åpne valgmeny' : _ref$ariaLabel,
156
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
157
- var _useState = useState(false),
158
- isOpen = _useState[0],
159
- setIsOpen = _useState[1];
160
- var _useState2 = useState(null),
161
- activeIndex = _useState2[0],
162
- setActiveIndex = _useState2[1];
163
- var listRef = useRef([]);
164
- var labelsRef = useRef([]);
165
- var _useFloating = useFloating({
166
- placement: standardisePlacement(
126
+ const SelectContext = React.createContext(
127
+ {}
128
+ );
129
+ const OverflowMenu = ({
130
+ children,
131
+ className,
132
+ button,
133
+ buttonIcon,
134
+ placement = "bottom-start",
135
+ "aria-label": ariaLabel = "åpne valgmeny",
136
+ ...rest
137
+ }) => {
138
+ const [isOpen, setIsOpen] = useState(false);
139
+ const [activeIndex, setActiveIndex] = useState(null);
140
+ const listRef = useRef([]);
141
+ const labelsRef = useRef([]);
142
+ const { refs, floatingStyles, context, elements, update } = useFloating({
143
+ placement: standardisePlacement(
167
144
  // check for left is added for backwards compatibility
168
- rest.position === 'left' ? 'bottom-end' : placement),
169
- open: isOpen,
170
- onOpenChange: setIsOpen,
171
- middleware: [offset(space.extraSmall2), flip(), shift({
172
- padding: space.extraSmall
173
- })]
174
- }),
175
- refs = _useFloating.refs,
176
- floatingStyles = _useFloating.floatingStyles,
177
- context = _useFloating.context,
178
- elements = _useFloating.elements,
179
- update = _useFloating.update;
180
- // Since we use CSS instead of conditional rendering when hiding dropdownlist
181
- // we can't use the whileElementsMounted option and need to handle
182
- // cleanup ourselves. See https://floating-ui.com/docs/autoupdate
183
- useEffect(function () {
145
+ rest.position === "left" ? "bottom-end" : placement
146
+ ),
147
+ open: isOpen,
148
+ onOpenChange: setIsOpen,
149
+ middleware: [
150
+ offset(space.extraSmall2),
151
+ flip(),
152
+ shift({ padding: space.extraSmall })
153
+ ]
154
+ });
155
+ useEffect(() => {
184
156
  if (isOpen && elements.reference && elements.floating) {
185
- var cleanup = autoUpdate(elements.reference, elements.floating, update);
157
+ const cleanup = autoUpdate(elements.reference, elements.floating, update);
186
158
  return cleanup;
187
159
  }
188
160
  }, [isOpen, elements, update]);
189
- var listNav = useListNavigation(context, {
190
- listRef: listRef,
191
- activeIndex: activeIndex,
161
+ const listNav = useListNavigation(context, {
162
+ listRef,
163
+ activeIndex,
192
164
  onNavigate: setActiveIndex
193
165
  });
194
- var typeahead = useTypeahead(context, {
166
+ const typeahead = useTypeahead(context, {
195
167
  listRef: labelsRef,
196
- activeIndex: activeIndex,
197
- onMatch: function onMatch(index) {
198
- return isOpen && setActiveIndex(index);
199
- }
168
+ activeIndex,
169
+ onMatch: (index) => isOpen && setActiveIndex(index)
200
170
  });
201
- var role = useRole(context, {
202
- role: 'menu'
203
- });
204
- var _useInteractions = useInteractions([listNav, typeahead, role]),
205
- getReferenceProps = _useInteractions.getReferenceProps,
206
- getFloatingProps = _useInteractions.getFloatingProps,
207
- getItemProps = _useInteractions.getItemProps;
208
- var closeMenuAndReturnFocus = function closeMenuAndReturnFocus() {
209
- var _refs$reference$curre;
171
+ const role = useRole(context, { role: "menu" });
172
+ const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions(
173
+ [listNav, typeahead, role]
174
+ );
175
+ const closeMenuAndReturnFocus = () => {
210
176
  setIsOpen(false);
211
- // @ts-expect-error the reference element is actually focusable
212
- (_refs$reference$curre = refs.reference.current) == null || _refs$reference$curre.focus == null || _refs$reference$curre.focus();
177
+ refs.reference.current?.focus?.();
213
178
  };
214
- useOnClickOutside([refs.floating, refs.reference], function () {
215
- return setIsOpen(false);
216
- });
179
+ useOnClickOutside([refs.floating, refs.reference], () => setIsOpen(false));
217
180
  useOnEscape(refs.floating, closeMenuAndReturnFocus);
218
181
  useOnEscape(refs.reference, closeMenuAndReturnFocus);
219
- var selectContext = React.useMemo(function () {
220
- return {
221
- activeIndex: activeIndex,
222
- getItemProps: getItemProps,
223
- closeMenuAndReturnFocus: closeMenuAndReturnFocus
224
- };
225
- }, [activeIndex, getItemProps, closeMenuAndReturnFocus]);
226
- var _buttonIcon = buttonIcon != null ? buttonIcon : React.createElement(VerticalDotsIcon, null);
227
- return React.createElement(React.Fragment, null, !button ? React.createElement(IconButton, _extends({
228
- ref: refs.setReference
229
- }, getReferenceProps({
230
- onClick: function onClick() {
231
- return setIsOpen(!isOpen);
232
- },
233
- className: className,
234
- 'aria-label': ariaLabel,
235
- type: 'button'
236
- }), rest), _buttonIcon) : cloneElement(button, _extends({
237
- ref: refs.setReference
238
- }, getReferenceProps({
239
- onClick: function onClick() {
240
- return setIsOpen(!isOpen);
241
- },
242
- className: className,
243
- 'aria-label': ariaLabel,
244
- type: 'button'
245
- }), rest)), React.createElement(SelectContext.Provider, {
246
- value: selectContext
247
- }, React.createElement("div", _extends({
248
- ref: refs.setFloating,
249
- style: _extends({}, floatingStyles, {
250
- display: isOpen ? 'initial' : 'none'
251
- })
252
- }, getFloatingProps({
253
- className: 'eds-overflow-menu__menu-list'
254
- })), React.createElement(FloatingList, {
255
- elementsRef: listRef,
256
- labelsRef: labelsRef
257
- }, children))));
258
- };
259
- var OverflowMenuItem = function OverflowMenuItem(_ref2) {
260
- var children = _ref2.children,
261
- className = _ref2.className,
262
- _ref2$onSelect = _ref2.onSelect,
263
- onSelect = _ref2$onSelect === void 0 ? function () {
264
- return undefined;
265
- } : _ref2$onSelect,
266
- href = _ref2.href,
267
- disabled = _ref2.disabled,
268
- as = _ref2.as,
269
- rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$1);
270
- var _useContext = useContext(SelectContext),
271
- activeIndex = _useContext.activeIndex,
272
- getItemProps = _useContext.getItemProps,
273
- closeMenuAndReturnFocus = _useContext.closeMenuAndReturnFocus;
274
- var _useListItem = useListItem({
275
- label: !disabled ? getNodeText(children) : null
182
+ const selectContext = React.useMemo(
183
+ () => ({
184
+ activeIndex,
185
+ getItemProps,
186
+ closeMenuAndReturnFocus
276
187
  }),
277
- listItemRef = _useListItem.ref,
278
- index = _useListItem.index;
279
- var isHighlighted = activeIndex === index;
280
- var isLink = href !== undefined;
281
- var Element = as != null ? as : isLink ? 'a' : 'button';
282
- return React.createElement(Element, _extends({
283
- ref: listItemRef,
284
- className: classNames('eds-overflow-menu__item', {
285
- 'eds-overflow-menu__item--disabled': disabled,
286
- 'eds-overflow-menu__item--highlighted': isHighlighted
287
- }, className),
288
- role: "menuitem",
289
- type: Element === 'button' ? 'button' : undefined,
290
- "aria-disabled": disabled,
291
- "aria-selected": isHighlighted
292
- }, getItemProps({
293
- onClick: isLink || disabled ? undefined : function () {
294
- onSelect();
295
- closeMenuAndReturnFocus();
296
- },
297
- href: disabled ? undefined : href,
298
- tabIndex: isHighlighted ? 0 : -1
299
- }), rest), children);
188
+ [activeIndex, getItemProps, closeMenuAndReturnFocus]
189
+ );
190
+ const _buttonIcon = buttonIcon ?? /* @__PURE__ */ jsx(VerticalDotsIcon, {});
191
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
192
+ !button ? /* @__PURE__ */ jsx(
193
+ IconButton,
194
+ {
195
+ ref: refs.setReference,
196
+ ...getReferenceProps({
197
+ onClick: () => setIsOpen(!isOpen),
198
+ className,
199
+ "aria-label": ariaLabel,
200
+ type: "button"
201
+ }),
202
+ ...rest,
203
+ children: _buttonIcon
204
+ }
205
+ ) : cloneElement(button, {
206
+ ref: refs.setReference,
207
+ ...getReferenceProps({
208
+ onClick: () => setIsOpen(!isOpen),
209
+ className,
210
+ "aria-label": ariaLabel,
211
+ type: "button"
212
+ }),
213
+ ...rest
214
+ }),
215
+ /* @__PURE__ */ jsx(SelectContext.Provider, { value: selectContext, children: /* @__PURE__ */ jsx(
216
+ "div",
217
+ {
218
+ ref: refs.setFloating,
219
+ style: { ...floatingStyles, display: isOpen ? "initial" : "none" },
220
+ ...getFloatingProps({
221
+ className: "eds-overflow-menu__menu-list"
222
+ }),
223
+ children: /* @__PURE__ */ jsx(FloatingList, { elementsRef: listRef, labelsRef, children })
224
+ }
225
+ ) })
226
+ ] });
300
227
  };
301
- var OverflowMenuLink = function OverflowMenuLink(props) {
302
- return React.createElement(OverflowMenuItem, _extends({}, props));
228
+ const OverflowMenuItem = ({
229
+ children,
230
+ className,
231
+ onSelect = () => void 0,
232
+ href,
233
+ disabled,
234
+ as,
235
+ ...rest
236
+ }) => {
237
+ const { activeIndex, getItemProps, closeMenuAndReturnFocus } = useContext(SelectContext);
238
+ const { ref: listItemRef, index } = useListItem({
239
+ label: !disabled ? getNodeText(children) : null
240
+ });
241
+ const isHighlighted = activeIndex === index;
242
+ const isLink = href !== void 0;
243
+ const Element = as ?? (isLink ? "a" : "button");
244
+ return /* @__PURE__ */ jsx(
245
+ Element,
246
+ {
247
+ ref: listItemRef,
248
+ className: classNames(
249
+ "eds-overflow-menu__item",
250
+ {
251
+ "eds-overflow-menu__item--disabled": disabled,
252
+ "eds-overflow-menu__item--highlighted": isHighlighted
253
+ },
254
+ className
255
+ ),
256
+ role: "menuitem",
257
+ type: Element === "button" ? "button" : void 0,
258
+ "aria-disabled": disabled,
259
+ "aria-selected": isHighlighted,
260
+ ...getItemProps({
261
+ onClick: isLink || disabled ? void 0 : () => {
262
+ onSelect();
263
+ closeMenuAndReturnFocus();
264
+ },
265
+ href: disabled ? void 0 : href,
266
+ tabIndex: isHighlighted ? 0 : -1
267
+ }),
268
+ ...rest,
269
+ children
270
+ }
271
+ );
303
272
  };
304
-
305
- var PaginationPage = function PaginationPage(_ref) {
306
- var children = _ref.children,
307
- className = _ref.className,
308
- selected = _ref.selected,
309
- disabled = _ref.disabled,
310
- onClick = _ref.onClick,
311
- ariaLabel = _ref['aria-label'],
312
- ariaDescribedby = _ref['aria-describedby'];
313
- return React.createElement("button", {
314
- className: classNames('eds-pagination__controls__page', {
315
- 'eds-pagination__controls__page--selected': selected
316
- }, {
317
- 'eds-pagination__controls__page--disabled': disabled
318
- }, className),
273
+ const OverflowMenuLink = (props) => {
274
+ return /* @__PURE__ */ jsx(OverflowMenuItem, { ...props });
275
+ };
276
+ const PaginationPage = ({
277
+ children,
278
+ className,
279
+ selected,
280
+ disabled,
281
+ onClick,
282
+ "aria-label": ariaLabel,
283
+ "aria-describedby": ariaDescribedby
284
+ }) => /* @__PURE__ */ jsx(
285
+ "button",
286
+ {
287
+ className: classNames(
288
+ "eds-pagination__controls__page",
289
+ { "eds-pagination__controls__page--selected": selected },
290
+ { "eds-pagination__controls__page--disabled": disabled },
291
+ className
292
+ ),
319
293
  disabled: selected || disabled,
320
294
  type: "button",
321
- onClick: onClick,
295
+ onClick,
322
296
  "aria-label": ariaLabel,
323
297
  "aria-describedby": ariaDescribedby,
324
- "aria-current": selected ? 'page' : false
325
- }, children);
326
- };
327
-
328
- var PaginationInput = function PaginationInput(_ref) {
329
- var currentPage = _ref.currentPage,
330
- pageCount = _ref.pageCount,
331
- _ref$label = _ref.label,
332
- label = _ref$label === void 0 ? 'Gå til side' : _ref$label,
333
- onPageChange = _ref.onPageChange;
334
- var _React$useState = React.useState(String(currentPage)),
335
- input = _React$useState[0],
336
- setInput = _React$useState[1];
337
- // If the currentPage prop changes, we want to reset the input field
338
- React.useEffect(function () {
298
+ "aria-current": selected ? "page" : false,
299
+ children
300
+ }
301
+ );
302
+ const PaginationInput = ({
303
+ currentPage,
304
+ pageCount,
305
+ label = "Gå til side",
306
+ onPageChange
307
+ }) => {
308
+ const [input, setInput] = React.useState(String(currentPage));
309
+ React.useEffect(() => {
339
310
  setInput(String(currentPage));
340
311
  }, [currentPage]);
341
- var handleSubmit = function handleSubmit(e) {
312
+ const handleSubmit = (e) => {
342
313
  e.preventDefault();
343
314
  e.stopPropagation();
344
- var pageNumber = Number(input);
315
+ let pageNumber = Number(input);
345
316
  if (pageNumber === currentPage) {
346
317
  return;
347
318
  }
@@ -359,210 +330,232 @@ var PaginationInput = function PaginationInput(_ref) {
359
330
  }
360
331
  onPageChange(pageNumber);
361
332
  };
362
- var handleChange = function handleChange(e) {
333
+ const handleChange = (e) => {
363
334
  setInput(e.target.value);
364
335
  };
365
- return React.createElement("form", {
366
- onSubmit: handleSubmit,
367
- noValidate: true,
368
- "aria-label": "form"
369
- }, React.createElement("label", {
370
- className: "eds-pagination__controls__input__wrapper"
371
- }, React.createElement("span", {
372
- className: "eds-pagination__controls__input__label"
373
- }, label), React.createElement("input", {
374
- type: "number",
375
- max: pageCount,
376
- className: "eds-pagination__controls__input__field",
377
- value: input,
378
- onChange: handleChange
379
- })));
336
+ return /* @__PURE__ */ jsx("form", { onSubmit: handleSubmit, noValidate: true, "aria-label": "form", children: /* @__PURE__ */ jsxs("label", { className: "eds-pagination__controls__input__wrapper", children: [
337
+ /* @__PURE__ */ jsx("span", { className: "eds-pagination__controls__input__label", children: label }),
338
+ /* @__PURE__ */ jsx(
339
+ "input",
340
+ {
341
+ type: "number",
342
+ max: pageCount,
343
+ className: "eds-pagination__controls__input__field",
344
+ value: input,
345
+ onChange: handleChange
346
+ }
347
+ )
348
+ ] }) });
380
349
  };
381
-
382
- var _excluded$5 = ["className", "currentPage", "inputLabel", "onPageChange", "pageCount", "pageLabel", "previousPageLabel", "currentPageLabelForScreenreader", "lastPageLabelForScreenreader", "showInput", "numberOfResults", "resultsPerPage", "resultsPerPageOptions", "onResultsPerPageChange", "showNumberOfResultsLabel", "nextPageLabel", "showingResultsLabel", "changeNumberOfResultsLabelForScreenreader", "hideNextButton", "hidePrevButton"];
383
- var Pagination = function Pagination(_ref) {
384
- var className = _ref.className,
385
- currentPage = _ref.currentPage,
386
- inputLabel = _ref.inputLabel,
387
- onPageChange = _ref.onPageChange,
388
- pageCount = _ref.pageCount,
389
- _ref$pageLabel = _ref.pageLabel,
390
- pageLabel = _ref$pageLabel === void 0 ? function (pageNumber) {
391
- return "G\xE5 til side " + pageNumber;
392
- } : _ref$pageLabel,
393
- _ref$previousPageLabe = _ref.previousPageLabel,
394
- previousPageLabel = _ref$previousPageLabe === void 0 ? 'Gå til forrige side' : _ref$previousPageLabe,
395
- _ref$currentPageLabel = _ref.currentPageLabelForScreenreader,
396
- currentPageLabelForScreenreader = _ref$currentPageLabel === void 0 ? 'Nåværende side:' : _ref$currentPageLabel,
397
- _ref$lastPageLabelFor = _ref.lastPageLabelForScreenreader,
398
- lastPageLabelForScreenreader = _ref$lastPageLabelFor === void 0 ? ', siste side' : _ref$lastPageLabelFor,
399
- showInput = _ref.showInput,
400
- numberOfResults = _ref.numberOfResults,
401
- resultsPerPage = _ref.resultsPerPage,
402
- _ref$resultsPerPageOp = _ref.resultsPerPageOptions,
403
- resultsPerPageOptions = _ref$resultsPerPageOp === void 0 ? [10, 25, 50] : _ref$resultsPerPageOp,
404
- onResultsPerPageChange = _ref.onResultsPerPageChange,
405
- _ref$showNumberOfResu = _ref.showNumberOfResultsLabel,
406
- showNumberOfResultsLabel = _ref$showNumberOfResu === void 0 ? 'Vis' : _ref$showNumberOfResu,
407
- _ref$nextPageLabel = _ref.nextPageLabel,
408
- nextPageLabel = _ref$nextPageLabel === void 0 ? 'Gå til neste side' : _ref$nextPageLabel,
409
- _ref$showingResultsLa = _ref.showingResultsLabel,
410
- showingResultsLabel = _ref$showingResultsLa === void 0 ? function (minPage, maxPage, pageCount) {
411
- return "Viser resultat " + minPage + "\u2013" + maxPage + " av " + pageCount;
412
- } : _ref$showingResultsLa,
413
- _ref$changeNumberOfRe = _ref.changeNumberOfResultsLabelForScreenreader,
414
- changeNumberOfResultsLabelForScreenreader = _ref$changeNumberOfRe === void 0 ? "Viser " + resultsPerPage + " resultater. Trykk for \xE5 endre antall. \xC5pner en flervalgsmeny." : _ref$changeNumberOfRe,
415
- _ref$hideNextButton = _ref.hideNextButton,
416
- hideNextButton = _ref$hideNextButton === void 0 ? false : _ref$hideNextButton,
417
- _ref$hidePrevButton = _ref.hidePrevButton,
418
- hidePrevButton = _ref$hidePrevButton === void 0 ? false : _ref$hidePrevButton,
419
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
420
- var _useState = useState([]),
421
- listedEntries = _useState[0],
422
- setListedEntries = _useState[1];
423
- var paginationId = useRandomId('eds-pagination');
424
- var isFirstPostSelected = currentPage === 1;
425
- var isLastPostSelected = currentPage === pageCount;
426
- var noEllipsis = pageCount <= 7;
427
- var onlyLeadingEllipsis = !noEllipsis && currentPage < 5;
428
- var onlyTrailingEllipsis = !noEllipsis && pageCount - currentPage <= 3;
429
- useEffect(function () {
350
+ const Pagination = ({
351
+ className,
352
+ currentPage,
353
+ inputLabel,
354
+ onPageChange,
355
+ pageCount,
356
+ pageLabel = (pageNumber) => `Gå til side ${pageNumber}`,
357
+ previousPageLabel = "Gå til forrige side",
358
+ currentPageLabelForScreenreader = "Nåværende side:",
359
+ lastPageLabelForScreenreader = ", siste side",
360
+ showInput,
361
+ numberOfResults,
362
+ resultsPerPage,
363
+ resultsPerPageOptions = [10, 25, 50],
364
+ onResultsPerPageChange,
365
+ showNumberOfResultsLabel = "Vis",
366
+ nextPageLabel = "Gå til neste side",
367
+ showingResultsLabel = (minPage, maxPage, pageCount2) => `Viser resultat ${minPage}–${maxPage} av ${pageCount2}`,
368
+ changeNumberOfResultsLabelForScreenreader = `Viser ${resultsPerPage} resultater. Trykk for å endre antall. Åpner en flervalgsmeny.`,
369
+ hideNextButton = false,
370
+ hidePrevButton = false,
371
+ ...rest
372
+ }) => {
373
+ const [listedEntries, setListedEntries] = useState([]);
374
+ const paginationId = useRandomId("eds-pagination");
375
+ const isFirstPostSelected = currentPage === 1;
376
+ const isLastPostSelected = currentPage === pageCount;
377
+ const noEllipsis = pageCount <= 7;
378
+ const onlyLeadingEllipsis = !noEllipsis && currentPage < 5;
379
+ const onlyTrailingEllipsis = !noEllipsis && pageCount - currentPage <= 3;
380
+ useEffect(() => {
430
381
  if (pageCount < 1) return;
431
382
  if (noEllipsis) {
432
- setListedEntries(Array(pageCount).fill(null).map(function (_, i) {
433
- return i + 1;
434
- }));
383
+ setListedEntries(
384
+ Array(pageCount).fill(null).map((_, i) => i + 1)
385
+ );
435
386
  } else if (onlyLeadingEllipsis) {
436
- setListedEntries([1, 2, 3, 4, 5, '', pageCount]);
387
+ setListedEntries([1, 2, 3, 4, 5, "", pageCount]);
437
388
  } else if (onlyTrailingEllipsis) {
438
- setListedEntries([1, '…', pageCount - 4, pageCount - 3, pageCount - 2, pageCount - 1, pageCount]);
389
+ setListedEntries([
390
+ 1,
391
+ "…",
392
+ pageCount - 4,
393
+ pageCount - 3,
394
+ pageCount - 2,
395
+ pageCount - 1,
396
+ pageCount
397
+ ]);
439
398
  } else {
440
- // leading and trailing ellipsis
441
- setListedEntries([1, '…', currentPage - 1, currentPage, currentPage + 1, '…', pageCount]);
399
+ setListedEntries([
400
+ 1,
401
+ "…",
402
+ currentPage - 1,
403
+ currentPage,
404
+ currentPage + 1,
405
+ "…",
406
+ pageCount
407
+ ]);
442
408
  }
443
- }, [noEllipsis, onlyLeadingEllipsis, onlyTrailingEllipsis, currentPage, pageCount]);
409
+ }, [
410
+ noEllipsis,
411
+ onlyLeadingEllipsis,
412
+ onlyTrailingEllipsis,
413
+ currentPage,
414
+ pageCount
415
+ ]);
444
416
  if (pageCount < 1) {
445
417
  return null;
446
418
  }
447
- return React.createElement("nav", _extends({
448
- className: classNames('eds-pagination', className),
449
- "aria-label": "Paginering"
450
- }, rest), resultsPerPage && numberOfResults && React.createElement("div", {
451
- className: "eds-pagination__results"
452
- }, onResultsPerPageChange && React.createElement(React.Fragment, null, React.createElement(Label, {
453
- as: "p",
454
- "aria-hidden": "true"
455
- }, showNumberOfResultsLabel), React.createElement(OverflowMenu, {
456
- className: "eds-pagination__results__change-number-of-results",
457
- buttonIcon: React.createElement(React.Fragment, null, resultsPerPage, ' ', React.createElement(DownArrowIcon, {
458
- className: "eds-pagination__results__change-number-of-results__arrow",
459
- "aria-hidden": "true"
460
- })),
461
- "aria-label": changeNumberOfResultsLabelForScreenreader,
462
- placement: "bottom-end"
463
- }, resultsPerPageOptions.map(function (option, key) {
464
- return React.createElement(OverflowMenuItem, {
465
- key: key,
466
- onSelect: function onSelect() {
467
- return onResultsPerPageChange(option);
468
- }
469
- }, option);
470
- }))), React.createElement(Label, {
471
- as: "p"
472
- }, showingResultsLabel((currentPage - 1) * resultsPerPage + 1, currentPage * resultsPerPage > numberOfResults ? numberOfResults : currentPage * resultsPerPage, numberOfResults))), React.createElement("div", {
473
- className: "eds-pagination__controls"
474
- }, !hidePrevButton && React.createElement(PaginationPage, {
475
- onClick: function onClick() {
476
- return onPageChange(currentPage - 1);
477
- },
478
- "aria-label": previousPageLabel,
479
- "aria-describedby": paginationId,
480
- disabled: isFirstPostSelected
481
- }, React.createElement(LeftArrowIcon, {
482
- "aria-hidden": "true"
483
- })), listedEntries.map(function (entry, index) {
484
- return entry === '…' ? React.createElement(Ellipsis, {
485
- key: "ellipsis-" + index
486
- }) : React.createElement(PaginationPage, {
487
- selected: entry === currentPage,
488
- onClick: function onClick() {
489
- return onPageChange(entry);
490
- },
491
- "aria-label": "" + pageLabel(entry) + (entry === pageCount ? lastPageLabelForScreenreader : ''),
492
- "aria-describedby": entry !== currentPage ? paginationId : undefined,
493
- key: entry
494
- }, entry);
495
- }), !hideNextButton && React.createElement(PaginationPage, {
496
- onClick: function onClick() {
497
- return onPageChange(currentPage + 1);
498
- },
499
- "aria-label": nextPageLabel,
500
- "aria-describedby": paginationId,
501
- disabled: isLastPostSelected
502
- }, React.createElement(RightArrowIcon, {
503
- "aria-hidden": "true"
504
- })), showInput && React.createElement(PaginationInput, {
505
- pageCount: pageCount,
506
- currentPage: currentPage,
507
- onPageChange: onPageChange,
508
- label: inputLabel
509
- })), React.createElement(VisuallyHidden, {
510
- id: paginationId
511
- }, currentPageLabelForScreenreader, " ", currentPage));
512
- };
513
- var Ellipsis = function Ellipsis() {
514
- return React.createElement("span", {
515
- className: "eds-pagination__controls__page__ellipsis",
516
- "aria-hidden": "true"
517
- }, "\u2026");
419
+ return /* @__PURE__ */ jsxs(
420
+ "nav",
421
+ {
422
+ className: classNames("eds-pagination", className),
423
+ "aria-label": "Paginering",
424
+ ...rest,
425
+ children: [
426
+ resultsPerPage && numberOfResults && /* @__PURE__ */ jsxs("div", { className: "eds-pagination__results", children: [
427
+ onResultsPerPageChange && /* @__PURE__ */ jsxs(Fragment, { children: [
428
+ /* @__PURE__ */ jsx(Label, { as: "p", "aria-hidden": "true", children: showNumberOfResultsLabel }),
429
+ /* @__PURE__ */ jsx(
430
+ OverflowMenu,
431
+ {
432
+ className: "eds-pagination__results__change-number-of-results",
433
+ buttonIcon: /* @__PURE__ */ jsxs(Fragment, { children: [
434
+ resultsPerPage,
435
+ " ",
436
+ /* @__PURE__ */ jsx(
437
+ DownArrowIcon,
438
+ {
439
+ className: "eds-pagination__results__change-number-of-results__arrow",
440
+ "aria-hidden": "true"
441
+ }
442
+ )
443
+ ] }),
444
+ "aria-label": changeNumberOfResultsLabelForScreenreader,
445
+ placement: "bottom-end",
446
+ children: resultsPerPageOptions.map((option, key) => /* @__PURE__ */ jsx(
447
+ OverflowMenuItem,
448
+ {
449
+ onSelect: () => onResultsPerPageChange(option),
450
+ children: option
451
+ },
452
+ key
453
+ ))
454
+ }
455
+ )
456
+ ] }),
457
+ /* @__PURE__ */ jsx(Label, { as: "p", children: showingResultsLabel(
458
+ (currentPage - 1) * resultsPerPage + 1,
459
+ currentPage * resultsPerPage > numberOfResults ? numberOfResults : currentPage * resultsPerPage,
460
+ numberOfResults
461
+ ) })
462
+ ] }),
463
+ /* @__PURE__ */ jsxs("div", { className: "eds-pagination__controls", children: [
464
+ !hidePrevButton && /* @__PURE__ */ jsx(
465
+ PaginationPage,
466
+ {
467
+ onClick: () => onPageChange(currentPage - 1),
468
+ "aria-label": previousPageLabel,
469
+ "aria-describedby": paginationId,
470
+ disabled: isFirstPostSelected,
471
+ children: /* @__PURE__ */ jsx(LeftArrowIcon, { "aria-hidden": "true" })
472
+ }
473
+ ),
474
+ listedEntries.map(
475
+ (entry, index) => entry === "" ? /* @__PURE__ */ jsx(Ellipsis, {}, `ellipsis-${index}`) : /* @__PURE__ */ jsx(
476
+ PaginationPage,
477
+ {
478
+ selected: entry === currentPage,
479
+ onClick: () => onPageChange(entry),
480
+ "aria-label": `${pageLabel(entry)}${entry === pageCount ? lastPageLabelForScreenreader : ""}`,
481
+ "aria-describedby": entry !== currentPage ? paginationId : void 0,
482
+ children: entry
483
+ },
484
+ entry
485
+ )
486
+ ),
487
+ !hideNextButton && /* @__PURE__ */ jsx(
488
+ PaginationPage,
489
+ {
490
+ onClick: () => onPageChange(currentPage + 1),
491
+ "aria-label": nextPageLabel,
492
+ "aria-describedby": paginationId,
493
+ disabled: isLastPostSelected,
494
+ children: /* @__PURE__ */ jsx(RightArrowIcon, { "aria-hidden": "true" })
495
+ }
496
+ ),
497
+ showInput && /* @__PURE__ */ jsx(
498
+ PaginationInput,
499
+ {
500
+ pageCount,
501
+ currentPage,
502
+ onPageChange,
503
+ label: inputLabel
504
+ }
505
+ )
506
+ ] }),
507
+ /* @__PURE__ */ jsxs(VisuallyHidden, { id: paginationId, children: [
508
+ currentPageLabelForScreenreader,
509
+ " ",
510
+ currentPage
511
+ ] })
512
+ ]
513
+ }
514
+ );
518
515
  };
519
-
520
- var _excluded$4 = ["className", "children", "size"];
521
- var SideNavigation = function SideNavigation(_ref) {
522
- var className = _ref.className,
523
- children = _ref.children,
524
- _ref$size = _ref.size,
525
- size = _ref$size === void 0 ? 'medium' : _ref$size,
526
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
516
+ const Ellipsis = () => /* @__PURE__ */ jsx("span", { className: "eds-pagination__controls__page__ellipsis", "aria-hidden": "true", children: "…" });
517
+ const SideNavigation = ({
518
+ className,
519
+ children,
520
+ size = "medium",
521
+ ...rest
522
+ }) => {
527
523
  if (!children || !React.Children.count(children)) {
528
524
  return null;
529
525
  }
530
- return React.createElement("ul", _extends({
531
- className: classNames('eds-side-navigation', {
532
- 'eds-side-navigation--small': size === 'small'
533
- }, className)
534
- }, rest), children);
526
+ return /* @__PURE__ */ jsx(
527
+ "ul",
528
+ {
529
+ className: classNames(
530
+ "eds-side-navigation",
531
+ { "eds-side-navigation--small": size === "small" },
532
+ className
533
+ ),
534
+ ...rest,
535
+ children
536
+ }
537
+ );
535
538
  };
536
- /** This is required to check that the Menu */
537
539
  SideNavigation.__IS_ENTUR_MENU__ = true;
538
-
539
- var useShowDelayedLabel = function useShowDelayedLabel(isCollapsed) {
540
- var _useState = useState(true),
541
- showLabel = _useState[0],
542
- setShowLabel = _useState[1];
543
- var hideDelay = 50;
544
- var showDelay = 200;
545
- useEffect(function () {
540
+ const useShowDelayedLabel = (isCollapsed) => {
541
+ const [showLabel, setShowLabel] = useState(true);
542
+ const hideDelay = 50;
543
+ const showDelay = 200;
544
+ useEffect(() => {
546
545
  if (isCollapsed) {
547
- setTimeout(function () {
546
+ setTimeout(() => {
548
547
  setShowLabel(false);
549
548
  }, hideDelay);
550
549
  }
551
550
  if (!isCollapsed) {
552
- setTimeout(function () {
551
+ setTimeout(() => {
553
552
  setShowLabel(true);
554
553
  }, showDelay);
555
554
  }
556
- return function () {
557
- return undefined;
558
- };
555
+ return () => void 0;
559
556
  }, [isCollapsed]);
560
557
  return [showLabel];
561
558
  };
562
-
563
- var _excluded$3 = ["className", "active", "subMenu", "icon", "children", "as"],
564
- _excluded2 = ["children"],
565
- _excluded3 = ["active", "disabled", "children", "forceExpandSubMenus", "as"];
566
559
  function isActiveRecursively(child) {
567
560
  if (!child.props) {
568
561
  return false;
@@ -573,205 +566,255 @@ function isActiveRecursively(child) {
573
566
  if (!child.props.children) {
574
567
  return false;
575
568
  }
576
- return React.Children.toArray(child.props.children).some(function (child) {
577
- return isActiveRecursively(child);
578
- });
569
+ return React.Children.toArray(child.props.children).some(
570
+ (child2) => isActiveRecursively(child2)
571
+ );
579
572
  }
580
- var defaultElementBaseItem = 'a';
581
- var BaseSideNavigationItem = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
582
- var className = _ref.className,
583
- _ref$active = _ref.active,
584
- active = _ref$active === void 0 ? false : _ref$active,
585
- subMenu = _ref.subMenu,
586
- icon = _ref.icon,
587
- children = _ref.children,
588
- as = _ref.as,
589
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
590
- var Element = as || defaultElementBaseItem;
591
- var _useSideNavigationCon = useSideNavigationContext(),
592
- isCollapsed = _useSideNavigationCon.isCollapsed;
593
- var _useShowDelayedLabel = useShowDelayedLabel(isCollapsed),
594
- showLabel = _useShowDelayedLabel[0];
595
- return React.createElement("li", {
596
- className: classNames('eds-side-navigation__item', className)
597
- }, React.createElement(Element, _extends({
598
- className: classNames('eds-side-navigation__click-target', {
599
- 'eds-side-navigation__click-target--active': active
600
- }),
601
- "aria-label": isCollapsed ? children : undefined,
602
- "aria-current": active ? 'page' : undefined,
603
- ref: ref
604
- }, rest), icon, showLabel && children), subMenu);
605
- });
606
- var DisabledSideNavigationItem = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
607
- var children = _ref2.children,
608
- rest = _objectWithoutPropertiesLoose(_ref2, _excluded2);
609
- return React.createElement(BaseSideNavigationItem, _extends({
573
+ const defaultElementBaseItem = "a";
574
+ const BaseSideNavigationItem = React.forwardRef(
575
+ ({
576
+ className,
577
+ active = false,
578
+ subMenu,
579
+ icon,
580
+ children,
581
+ as,
582
+ ...rest
583
+ }, ref) => {
584
+ const Element = as || defaultElementBaseItem;
585
+ const { isCollapsed } = useSideNavigationContext();
586
+ const [showLabel] = useShowDelayedLabel(isCollapsed);
587
+ return /* @__PURE__ */ jsxs("li", { className: classNames("eds-side-navigation__item", className), children: [
588
+ /* @__PURE__ */ jsxs(
589
+ Element,
590
+ {
591
+ className: classNames("eds-side-navigation__click-target", {
592
+ "eds-side-navigation__click-target--active": active
593
+ }),
594
+ "aria-label": isCollapsed ? children : void 0,
595
+ "aria-current": active ? "page" : void 0,
596
+ ref,
597
+ ...rest,
598
+ children: [
599
+ icon,
600
+ showLabel && children
601
+ ]
602
+ }
603
+ ),
604
+ subMenu
605
+ ] });
606
+ }
607
+ );
608
+ const DisabledSideNavigationItem = React.forwardRef(({ children, ...rest }, ref) => /* @__PURE__ */ jsx(
609
+ BaseSideNavigationItem,
610
+ {
610
611
  as: "button",
611
612
  disabled: true,
612
613
  "aria-disabled": true,
613
- ref: ref,
614
- type: "button"
615
- }, rest), children);
616
- });
617
- var defaultElementItem = 'a';
618
- var SideNavigationItem = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
619
- var active = _ref3.active,
620
- disabled = _ref3.disabled,
621
- children = _ref3.children,
622
- forceExpandSubMenus = _ref3.forceExpandSubMenus,
623
- as = _ref3.as,
624
- rest = _objectWithoutPropertiesLoose(_ref3, _excluded3);
625
- var Element = as || defaultElementItem;
626
- var childrenArray = React.Children.toArray(children);
627
- var subMenu = childrenArray.find(function (child) {
628
- return child && child.type && child.type.__IS_ENTUR_MENU__;
629
- });
630
- var label = subMenu ? childrenArray.filter(function (child) {
631
- return child !== subMenu;
632
- }) : children;
633
- if (disabled) {
634
- return React.createElement(DisabledSideNavigationItem, _extends({
635
- ref: ref
636
- }, rest), label);
637
- }
638
- if (!subMenu) {
639
- return React.createElement(BaseSideNavigationItem, _extends({
640
- as: Element,
641
- active: active,
642
- ref: ref
643
- }, rest), label);
614
+ ref,
615
+ type: "button",
616
+ ...rest,
617
+ children
644
618
  }
645
- var isExpanded = forceExpandSubMenus || isActiveRecursively({
646
- props: {
647
- children: children,
648
- active: active
619
+ ));
620
+ const defaultElementItem = "a";
621
+ const SideNavigationItem = React.forwardRef(
622
+ ({
623
+ active,
624
+ disabled,
625
+ children,
626
+ forceExpandSubMenus,
627
+ as,
628
+ ...rest
629
+ }, ref) => {
630
+ const Element = as || defaultElementItem;
631
+ const childrenArray = React.Children.toArray(children);
632
+ const subMenu = childrenArray.find(
633
+ (child) => child && child.type && child.type.__IS_ENTUR_MENU__
634
+ );
635
+ const label = subMenu ? childrenArray.filter((child) => child !== subMenu) : children;
636
+ if (disabled) {
637
+ return /* @__PURE__ */ jsx(DisabledSideNavigationItem, { ref, ...rest, children: label });
649
638
  }
639
+ if (!subMenu) {
640
+ return /* @__PURE__ */ jsx(
641
+ BaseSideNavigationItem,
642
+ {
643
+ as: Element,
644
+ active,
645
+ ref,
646
+ ...rest,
647
+ children: label
648
+ }
649
+ );
650
+ }
651
+ const isExpanded = forceExpandSubMenus || isActiveRecursively({ props: { children, active } });
652
+ return /* @__PURE__ */ jsx(
653
+ BaseSideNavigationItem,
654
+ {
655
+ active,
656
+ subMenu: isExpanded && subMenu,
657
+ "aria-expanded": isExpanded,
658
+ as: Element,
659
+ ref,
660
+ ...rest,
661
+ children: label
662
+ }
663
+ );
664
+ }
665
+ );
666
+ const SideNavigationGroup = ({
667
+ defaultOpen = false,
668
+ open,
669
+ onToggle,
670
+ className,
671
+ children,
672
+ title,
673
+ icon,
674
+ ...rest
675
+ }) => {
676
+ const [isOpen, setOpen] = useControllableProp({
677
+ prop: open,
678
+ updater: onToggle,
679
+ defaultValue: defaultOpen
650
680
  });
651
- return React.createElement(BaseSideNavigationItem, _extends({
652
- active: active,
653
- subMenu: isExpanded && subMenu,
654
- "aria-expanded": isExpanded,
655
- as: Element,
656
- ref: ref
657
- }, rest), label);
658
- });
659
-
660
- var _excluded$2 = ["defaultOpen", "open", "onToggle", "className", "children", "title", "icon"];
661
- var SideNavigationGroup = function SideNavigationGroup(_ref) {
662
- var _ref$defaultOpen = _ref.defaultOpen,
663
- defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
664
- open = _ref.open,
665
- onToggle = _ref.onToggle,
666
- className = _ref.className,
667
- children = _ref.children,
668
- title = _ref.title,
669
- icon = _ref.icon,
670
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
671
- var _useControllableProp = useControllableProp({
672
- prop: open,
673
- updater: onToggle,
674
- defaultValue: defaultOpen
675
- }),
676
- isOpen = _useControllableProp[0],
677
- setOpen = _useControllableProp[1];
678
- var _useSideNavigationCon = useSideNavigationContext(),
679
- isCollapsed = _useSideNavigationCon.isCollapsed;
680
- var _useShowDelayedLabel = useShowDelayedLabel(isCollapsed),
681
- showLabel = _useShowDelayedLabel[0];
682
- return React.createElement("div", _extends({
683
- className: classNames('eds-side-navigation-group', className)
684
- }, rest), React.createElement("button", {
685
- onClick: function onClick() {
686
- return setOpen(!isOpen);
687
- },
688
- type: "button",
689
- className: "eds-side-navigation-group__trigger",
690
- "aria-label": title + ", utvidbar meny, " + (isOpen ? 'åpen' : 'lukket')
691
- }, React.createElement("span", null, icon && React.createElement("span", {
692
- className: "eds-side-navigation-group__trigger-icon"
693
- }, icon), showLabel && title), showLabel && React.createElement(ExpandArrow, {
694
- open: isOpen,
695
- className: "eds-side-navigation-group__expand-icon"
696
- })), React.createElement(BaseExpand, {
697
- className: "eds-side-navigation-group__expand-content",
698
- open: isOpen
699
- }, children));
681
+ const { isCollapsed } = useSideNavigationContext();
682
+ const [showLabel] = useShowDelayedLabel(isCollapsed);
683
+ return /* @__PURE__ */ jsxs(
684
+ "div",
685
+ {
686
+ className: classNames("eds-side-navigation-group", className),
687
+ ...rest,
688
+ children: [
689
+ /* @__PURE__ */ jsxs(
690
+ "button",
691
+ {
692
+ onClick: () => setOpen(!isOpen),
693
+ type: "button",
694
+ className: "eds-side-navigation-group__trigger",
695
+ "aria-label": `${title}, utvidbar meny, ${isOpen ? "åpen" : "lukket"}`,
696
+ children: [
697
+ /* @__PURE__ */ jsxs("span", { children: [
698
+ icon && /* @__PURE__ */ jsx("span", { className: "eds-side-navigation-group__trigger-icon", children: icon }),
699
+ showLabel && title
700
+ ] }),
701
+ showLabel && /* @__PURE__ */ jsx(
702
+ ExpandArrow,
703
+ {
704
+ open: isOpen,
705
+ className: "eds-side-navigation-group__expand-icon"
706
+ }
707
+ )
708
+ ]
709
+ }
710
+ ),
711
+ /* @__PURE__ */ jsx(
712
+ BaseExpand,
713
+ {
714
+ className: "eds-side-navigation-group__expand-content",
715
+ open: isOpen,
716
+ children
717
+ }
718
+ )
719
+ ]
720
+ }
721
+ );
700
722
  };
701
-
702
- var _excluded$1 = ["activeIndex", "className", "interactive", "onStepClick", "showStepperIndex", "steps", "ariaLabelStep", "ariaLabelOf", "ariaLabelCompleted", "ariaLabelSummary"];
703
- var Stepper = function Stepper(_ref) {
704
- var activeIndex = _ref.activeIndex,
705
- className = _ref.className,
706
- _ref$interactive = _ref.interactive,
707
- interactive = _ref$interactive === void 0 ? false : _ref$interactive,
708
- onStepClick = _ref.onStepClick,
709
- _ref$showStepperIndex = _ref.showStepperIndex,
710
- showStepperIndex = _ref$showStepperIndex === void 0 ? true : _ref$showStepperIndex,
711
- steps = _ref.steps,
712
- _ref$ariaLabelStep = _ref.ariaLabelStep,
713
- ariaLabelStep = _ref$ariaLabelStep === void 0 ? 'Steg' : _ref$ariaLabelStep,
714
- _ref$ariaLabelOf = _ref.ariaLabelOf,
715
- ariaLabelOf = _ref$ariaLabelOf === void 0 ? 'av' : _ref$ariaLabelOf,
716
- _ref$ariaLabelComplet = _ref.ariaLabelCompleted,
717
- ariaLabelCompleted = _ref$ariaLabelComplet === void 0 ? 'fullført' : _ref$ariaLabelComplet,
718
- _ref$ariaLabelSummary = _ref.ariaLabelSummary,
719
- ariaLabelSummary = _ref$ariaLabelSummary === void 0 ? "Stegindikator med " + steps.length + " steg, du er p\xE5 steg " + (activeIndex + 1) + " " + steps[activeIndex] + "," : _ref$ariaLabelSummary,
720
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
721
- return React.createElement("ol", _extends({
722
- className: classNames('eds-stepper', className),
723
- "aria-label": ariaLabelSummary
724
- }, rest), steps.map(function (step, i) {
725
- var isCurrent = i === activeIndex;
726
- var isInteractive = interactive && activeIndex > i;
727
- var Element = isInteractive ? 'button' : 'div';
728
- var isCompleted = activeIndex > i;
729
- var currentStepSummary = ariaLabelStep + " " + (i + 1) + " " + ariaLabelOf + " " + steps.length + ", " + step + " " + (isCompleted ? ", " + ariaLabelCompleted : '');
730
- var props = isInteractive ? {
731
- onClick: function onClick() {
732
- return onStepClick == null ? void 0 : onStepClick(i);
733
- }
734
- } : {};
735
- return React.createElement("li", {
736
- key: step,
737
- className: "eds-stepper__step__wrapper"
738
- }, React.createElement(Element, _extends({
739
- className: classNames('eds-stepper__step', {
740
- 'eds-stepper__step--active': isCurrent
741
- }, {
742
- 'eds-stepper__step--completed': isCompleted
743
- }, {
744
- 'eds-stepper__step--interactive': isInteractive
745
- }),
746
- "aria-current": isCurrent ? 'step' : undefined,
747
- type: Element === 'button' ? 'button' : undefined
748
- }, props), React.createElement("div", {
749
- className: "eds-stepper__step__line",
750
- "aria-hidden": true
751
- }), React.createElement("span", {
752
- className: "eds-stepper__step__label",
753
- "aria-hidden": true
754
- }, showStepperIndex && i + 1 + '.', " ", step), React.createElement(VisuallyHidden, null, currentStepSummary)));
755
- }));
723
+ const Stepper = ({
724
+ activeIndex,
725
+ className,
726
+ interactive = false,
727
+ onStepClick,
728
+ showStepperIndex = true,
729
+ steps,
730
+ ariaLabelStep = "Steg",
731
+ ariaLabelOf = "av",
732
+ ariaLabelCompleted = "fullført",
733
+ ariaLabelSummary = `Stegindikator med ${steps.length} steg, du er på steg ${activeIndex + 1} ${steps[activeIndex]},`,
734
+ ...rest
735
+ }) => {
736
+ return /* @__PURE__ */ jsx(
737
+ "ol",
738
+ {
739
+ className: classNames("eds-stepper", className),
740
+ "aria-label": ariaLabelSummary,
741
+ ...rest,
742
+ children: steps.map((step, i) => {
743
+ const isCurrent = i === activeIndex;
744
+ const isInteractive = interactive && activeIndex > i;
745
+ const Element = isInteractive ? "button" : "div";
746
+ const isCompleted = activeIndex > i;
747
+ const currentStepSummary = `${ariaLabelStep} ${i + 1} ${ariaLabelOf} ${steps.length}, ${step} ${isCompleted ? `, ${ariaLabelCompleted}` : ""}`;
748
+ const props = isInteractive ? { onClick: () => onStepClick?.(i) } : {};
749
+ return /* @__PURE__ */ jsx("li", { className: "eds-stepper__step__wrapper", children: /* @__PURE__ */ jsxs(
750
+ Element,
751
+ {
752
+ className: classNames(
753
+ "eds-stepper__step",
754
+ { "eds-stepper__step--active": isCurrent },
755
+ { "eds-stepper__step--completed": isCompleted },
756
+ { "eds-stepper__step--interactive": isInteractive }
757
+ ),
758
+ "aria-current": isCurrent ? "step" : void 0,
759
+ type: Element === "button" ? "button" : void 0,
760
+ ...props,
761
+ children: [
762
+ /* @__PURE__ */ jsx("div", { className: "eds-stepper__step__line", "aria-hidden": true }),
763
+ /* @__PURE__ */ jsxs("span", { className: "eds-stepper__step__label", "aria-hidden": true, children: [
764
+ showStepperIndex && i + 1 + ".",
765
+ " ",
766
+ step
767
+ ] }),
768
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: currentStepSummary })
769
+ ]
770
+ }
771
+ ) }, step);
772
+ })
773
+ }
774
+ );
775
+ };
776
+ const defaultElement = "a";
777
+ const TopNavigationItem = ({
778
+ active = false,
779
+ className,
780
+ as,
781
+ ...rest
782
+ }) => {
783
+ const Element = as || defaultElement;
784
+ return /* @__PURE__ */ jsx(
785
+ Element,
786
+ {
787
+ className: classNames([
788
+ "eds-top-navigation-item",
789
+ className,
790
+ { "eds-top-navigation-item--active": active }
791
+ ]),
792
+ ...rest
793
+ }
794
+ );
756
795
  };
757
-
758
- var _excluded = ["active", "className", "as"];
759
- var defaultElement = 'a';
760
- var TopNavigationItem = function TopNavigationItem(_ref) {
761
- var _ref$active = _ref.active,
762
- active = _ref$active === void 0 ? false : _ref$active,
763
- className = _ref.className,
764
- as = _ref.as,
765
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
766
- var Element = as || defaultElement;
767
- return React.createElement(Element, _extends({
768
- className: classNames(['eds-top-navigation-item', className, {
769
- 'eds-top-navigation-item--active': active
770
- }])
771
- }, rest));
796
+ warnAboutMissingStyles(
797
+ "menu",
798
+ "expand",
799
+ "icons",
800
+ "typography",
801
+ "button",
802
+ "layout",
803
+ "a11y"
804
+ );
805
+ export {
806
+ BreadcrumbItem,
807
+ BreadcrumbNavigation,
808
+ CollapsibleSideNavigation,
809
+ OverflowMenu,
810
+ OverflowMenuItem,
811
+ OverflowMenuLink,
812
+ Pagination,
813
+ SideNavigation,
814
+ SideNavigationGroup,
815
+ SideNavigationItem,
816
+ Stepper,
817
+ TopNavigationItem,
818
+ useSideNavigationContext
772
819
  };
773
-
774
- warnAboutMissingStyles('menu', 'expand', 'icons', 'typography', 'button', 'layout', 'a11y');
775
-
776
- export { BreadcrumbItem, BreadcrumbNavigation, CollapsibleSideNavigation, OverflowMenu, OverflowMenuItem, OverflowMenuLink, Pagination, SideNavigation, SideNavigationGroup, SideNavigationItem, Stepper, TopNavigationItem, useSideNavigationContext };
777
820
  //# sourceMappingURL=menu.esm.js.map