@telia/teddy 0.0.38 → 0.0.40

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.
@@ -6,4 +6,7 @@ require("../navigation-menu.cjs");
6
6
  const components_navigationMenu_globalNavigation_globalNavigationMyPages = require("./global-navigation-my-pages.cjs");
7
7
  require("./utils.cjs");
8
8
  require("../../box/box.cjs");
9
+ require("../../../utils/useSize.cjs");
10
+ require("../../../utils/generate-styling/index.cjs");
11
+ require("../../../utils/useCallbackRef.cjs");
9
12
  exports.Desktop = components_navigationMenu_globalNavigation_globalNavigationMyPages.Desktop;
@@ -4,6 +4,9 @@ import "../navigation-menu.js";
4
4
  import { D } from "./global-navigation-my-pages.js";
5
5
  import "./utils.js";
6
6
  import "../../box/box.js";
7
+ import "../../../utils/useSize.js";
8
+ import "../../../utils/generate-styling/index.js";
9
+ import "../../../utils/useCallbackRef.js";
7
10
  export {
8
11
  D as Desktop
9
12
  };
@@ -19,18 +19,29 @@ const utils_composeRefs = require("../../../utils/composeRefs.cjs");
19
19
  require("../../badge/badge.cjs");
20
20
  require("../../badge/alert-badge.cjs");
21
21
  const components_badge_counterBadge = require("../../badge/counter-badge.cjs");
22
+ const utils_useSize = require("../../../utils/useSize.cjs");
23
+ const utils_generateStyling_index = require("../../../utils/generate-styling/index.cjs");
24
+ const utils_useCallbackRef = require("../../../utils/useCallbackRef.cjs");
22
25
  const components_flex_flex = require("../../flex/flex.cjs");
23
26
  const components_accordion_index = require("../../accordion/index.cjs");
24
27
  const components_visuallyHidden_visuallyHidden = require("../../visually-hidden/visually-hidden.cjs");
25
28
  const components_link_link = require("../../link/link.cjs");
26
29
  const components_list_index = require("../../list/index.cjs");
27
30
  const styles = {
28
- "teddy-global-navigation": "_teddy-global-navigation_y8nb6_1",
29
- "teddy-global-navigation__mobile": "_teddy-global-navigation__mobile_y8nb6_6",
30
- "teddy-global-navigation__link": "_teddy-global-navigation__link_y8nb6_20",
31
- "teddy-global-navigation__viewport": "_teddy-global-navigation__viewport_y8nb6_23",
32
- "teddy-global-navigation__item-wrapper": "_teddy-global-navigation__item-wrapper_y8nb6_26",
33
- "teddy-global-navigation__item-count": "_teddy-global-navigation__item-count_y8nb6_29"
31
+ "teddy-global-navigation": "_teddy-global-navigation_1ue02_1",
32
+ "teddy-global-navigation__mobile-trigger": "_teddy-global-navigation__mobile-trigger_1ue02_6",
33
+ "teddy-global-navigation__mobile-header": "_teddy-global-navigation__mobile-header_1ue02_9",
34
+ "teddy-global-navigation__mobile": "_teddy-global-navigation__mobile_1ue02_6",
35
+ "teddy-global-navigation__link": "_teddy-global-navigation__link_1ue02_26",
36
+ "teddy-global-navigation__viewport": "_teddy-global-navigation__viewport_1ue02_29",
37
+ "teddy-global-navigation__item-wrapper": "_teddy-global-navigation__item-wrapper_1ue02_32",
38
+ "teddy-global-navigation__item-count": "_teddy-global-navigation__item-count_1ue02_35",
39
+ "teddy-global-navigation__viewport-wrapper": "_teddy-global-navigation__viewport-wrapper_1ue02_43",
40
+ "expand-viewport": "_expand-viewport_1ue02_1",
41
+ "close-viewport": "_close-viewport_1ue02_1",
42
+ "teddy-global-navigation__top-menu-wrapper": "_teddy-global-navigation__top-menu-wrapper_1ue02_53",
43
+ "expand-top-menu": "_expand-top-menu_1ue02_1",
44
+ "close-top-menu": "_close-top-menu_1ue02_1"
34
45
  };
35
46
  function MyPages(props) {
36
47
  var _a, _b;
@@ -162,6 +173,8 @@ const ShoppingCart = React.forwardRef(() => {
162
173
  const shoppingCartContent = rootContext == null ? void 0 : rootContext.shoppingCart;
163
174
  const numberOfItemsInCart = (rootContext == null ? void 0 : rootContext.shoppingCartNumberOfItems) || 0;
164
175
  const titleSuffix = numberOfItemsInCart > 0 ? `(${numberOfItemsInCart})` : "";
176
+ if (!numberOfItemsInCart)
177
+ return null;
165
178
  return /* @__PURE__ */ jsxRuntime.jsxs(components_drawer_index.Drawer, { open: rootContext == null ? void 0 : rootContext.isCartOpen, onOpenChange: rootContext == null ? void 0 : rootContext.onCartOpenChange, children: [
166
179
  /* @__PURE__ */ jsxRuntime.jsx(components_navigationMenu_navigationMenu.NavigationMenu.Link, { asChild: true, variant: "button", children: /* @__PURE__ */ jsxRuntime.jsx(components_drawer_index.Drawer.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsxs("button", { children: [
167
180
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: clsx([styles[`${rootClassName}__item-wrapper`]]), children: [
@@ -182,15 +195,79 @@ const ShoppingCart = React.forwardRef(() => {
182
195
  ] });
183
196
  });
184
197
  ShoppingCart.displayName = "ShoppingCart";
198
+ const scrollDistanceDownThreshold = 200;
199
+ const scrollDistanceUpThreshold = 50;
200
+ const ANIMATION_DURATION = 300;
185
201
  const Desktop = React.forwardRef(() => {
186
202
  const rootContext = React.useContext(RootContext);
203
+ const [hideMenu, setHideMenu] = React.useState(false);
204
+ const lastScrollDirection = React.useRef();
205
+ const scrollStartPos = React.useRef(0);
206
+ const lastScrollPos = React.useRef(0);
207
+ const topMenuRef = React.useRef(null);
208
+ const viewPortRef = React.useRef(null);
209
+ const viewPortSize = utils_useSize.useSize(viewPortRef.current);
210
+ const topMenuSize = utils_useSize.useSize(topMenuRef.current);
211
+ const topMenuHeight = (topMenuSize == null ? void 0 : topMenuSize.height) ? `${topMenuSize.height}px` : void 0;
212
+ const viewPortHeight = (viewPortSize == null ? void 0 : viewPortSize.height) ? `${viewPortSize.height}px` : void 0;
213
+ const animationTimer = React.useRef(0);
214
+ const handleScroll = () => {
215
+ let compensateHight = 0;
216
+ if (animationTimer.current > 0) {
217
+ const currentTime = (/* @__PURE__ */ new Date()).getTime();
218
+ if (animationTimer.current + ANIMATION_DURATION > currentTime) {
219
+ compensateHight = ((topMenuSize == null ? void 0 : topMenuSize.height) || 0) + ((viewPortSize == null ? void 0 : viewPortSize.height) || 0);
220
+ } else {
221
+ animationTimer.current = 0;
222
+ }
223
+ }
224
+ const scrollY = window.scrollY;
225
+ const scrollDirection = scrollY > lastScrollPos.current ? "down" : "up";
226
+ const scrollDistance = Math.abs(scrollStartPos.current - scrollY);
227
+ if (scrollDirection !== lastScrollDirection.current) {
228
+ scrollStartPos.current = scrollY;
229
+ }
230
+ if (!hideMenu && scrollDirection === lastScrollDirection.current && scrollDirection === "down" && scrollDistance > scrollDistanceDownThreshold + compensateHight) {
231
+ setHideMenu(true);
232
+ const currentTime = (/* @__PURE__ */ new Date()).getTime();
233
+ animationTimer.current = currentTime;
234
+ }
235
+ if (hideMenu && scrollDirection === lastScrollDirection.current && scrollDirection === "up" && scrollDistance > scrollDistanceUpThreshold + compensateHight || scrollY === 0) {
236
+ setHideMenu(false);
237
+ const currentTime = (/* @__PURE__ */ new Date()).getTime();
238
+ animationTimer.current = currentTime;
239
+ }
240
+ lastScrollDirection.current = scrollDirection;
241
+ lastScrollPos.current = scrollY;
242
+ };
243
+ const throttledScrollHandler = useDebounceCallback(handleScroll, 5);
244
+ React.useEffect(() => {
245
+ window.addEventListener("scroll", throttledScrollHandler);
246
+ return () => {
247
+ window.removeEventListener("scroll", throttledScrollHandler);
248
+ };
249
+ }, [throttledScrollHandler]);
187
250
  if (!rootContext)
188
251
  return null;
252
+ function resetAndShowMenu() {
253
+ lastScrollDirection.current = null;
254
+ scrollStartPos.current = window.scrollY;
255
+ lastScrollPos.current = window.scrollY;
256
+ setHideMenu(false);
257
+ }
189
258
  const { setSelectedMenuItem, linkComponent: Link } = rootContext;
190
259
  const currentLocation = rootContext.pathname;
191
260
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
192
- /* @__PURE__ */ jsxRuntime.jsx(components_navigationMenu_navigationMenu.NavigationMenu.TopMenuList, { children: components_navigationMenu_globalNavigation_utils.LINKS.map((link) => /* @__PURE__ */ jsxRuntime.jsx(components_navigationMenu_navigationMenu.NavigationMenu.TopMenuItem, { children: /* @__PURE__ */ jsxRuntime.jsx(components_navigationMenu_navigationMenu.NavigationMenu.TopMenuTrigger, { value: link.name, asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(Link, { href: link.link, children: link.name }) }) }, link.name)) }),
193
- components_navigationMenu_globalNavigation_utils.LINKS.map((link) => /* @__PURE__ */ jsxRuntime.jsxs(components_navigationMenu_navigationMenu.NavigationMenu.List, { value: link.name, children: [
261
+ /* @__PURE__ */ jsxRuntime.jsx(
262
+ "div",
263
+ {
264
+ style: utils_generateStyling_index.mergeStyles({ ["--teddy-top-menu-height"]: topMenuHeight }),
265
+ className: styles[`${rootClassName}__top-menu-wrapper`],
266
+ "data-state": hideMenu ? "closed" : "open",
267
+ children: /* @__PURE__ */ jsxRuntime.jsx(components_navigationMenu_navigationMenu.NavigationMenu.TopMenuList, { onFocus: resetAndShowMenu, ref: topMenuRef, children: components_navigationMenu_globalNavigation_utils.LINKS.map((link) => /* @__PURE__ */ jsxRuntime.jsx(components_navigationMenu_navigationMenu.NavigationMenu.TopMenuItem, { children: /* @__PURE__ */ jsxRuntime.jsx(components_navigationMenu_navigationMenu.NavigationMenu.TopMenuTrigger, { value: link.name, asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(Link, { href: link.link, children: link.name }) }) }, link.name)) })
268
+ }
269
+ ),
270
+ components_navigationMenu_globalNavigation_utils.LINKS.map((link) => /* @__PURE__ */ jsxRuntime.jsxs(components_navigationMenu_navigationMenu.NavigationMenu.List, { onFocus: resetAndShowMenu, value: link.name, children: [
194
271
  link.links.map((subLink) => /* @__PURE__ */ jsxRuntime.jsxs(components_navigationMenu_navigationMenu.NavigationMenu.Item, { value: subLink.name, children: [
195
272
  subLink.name === "Logo" ? /* @__PURE__ */ jsxRuntime.jsx(components_navigationMenu_navigationMenu.NavigationMenu.Link, { asChild: true, variant: "button", children: subLink.appKey === rootContext.appKey || rootContext.appKey === "storybook" ? /* @__PURE__ */ jsxRuntime.jsx(Link, { href: subLink.link, onClick: () => setSelectedMenuItem(""), children: /* @__PURE__ */ jsxRuntime.jsx(
196
273
  "img",
@@ -221,7 +298,7 @@ const Desktop = React.forwardRef(() => {
221
298
  components_navigationMenu_navigationMenu.NavigationMenu.Link,
222
299
  {
223
300
  asChild: true,
224
- active: currentLocation === subSubLink.link,
301
+ active: currentLocation.startsWith(subSubLink.link),
225
302
  onClick: () => {
226
303
  rootContext.setPathname(subSubLink.link);
227
304
  },
@@ -235,10 +312,34 @@ const Desktop = React.forwardRef(() => {
235
312
  /* @__PURE__ */ jsxRuntime.jsx(components_navigationMenu_navigationMenu.NavigationMenu.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(ShoppingCart, {}) }),
236
313
  /* @__PURE__ */ jsxRuntime.jsx(components_navigationMenu_navigationMenu.NavigationMenu.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(MyPages, {}) })
237
314
  ] }, link.name)),
238
- /* @__PURE__ */ jsxRuntime.jsx(components_navigationMenu_navigationMenu.NavigationMenu.Viewport, { className: styles[`${rootClassName}__viewport`] })
315
+ /* @__PURE__ */ jsxRuntime.jsx(
316
+ "div",
317
+ {
318
+ style: utils_generateStyling_index.mergeStyles({ ["--teddy-viewport-wrapper-height"]: viewPortHeight }),
319
+ className: styles[`${rootClassName}__viewport-wrapper`],
320
+ "data-state": hideMenu ? "closed" : "open",
321
+ children: /* @__PURE__ */ jsxRuntime.jsx(
322
+ components_navigationMenu_navigationMenu.NavigationMenu.Viewport,
323
+ {
324
+ onFocus: resetAndShowMenu,
325
+ ref: viewPortRef,
326
+ className: styles[`${rootClassName}__viewport`]
327
+ }
328
+ )
329
+ }
330
+ )
239
331
  ] });
240
332
  });
241
333
  Desktop.displayName = "Desktop";
334
+ function useDebounceCallback(callback, delay) {
335
+ const handleCallback = utils_useCallbackRef.useCallbackRef(callback);
336
+ const debounceTimerRef = React.useRef(0);
337
+ React.useEffect(() => () => window.clearTimeout(debounceTimerRef.current), []);
338
+ return React.useCallback(() => {
339
+ window.clearTimeout(debounceTimerRef.current);
340
+ debounceTimerRef.current = window.setTimeout(handleCallback, delay);
341
+ }, [handleCallback, delay]);
342
+ }
242
343
  function Mobile(props) {
243
344
  const rootContext = React.useContext(RootContext);
244
345
  const drawerRef = React.useRef(null);
@@ -272,7 +373,7 @@ function Mobile(props) {
272
373
  value: rootContext.selectedMenuItem,
273
374
  onValueChange: rootContext.setSelectedMenuItem,
274
375
  children: link.links.filter((l) => l.name !== "Logo").map((subLink) => /* @__PURE__ */ jsxRuntime.jsxs(components_accordion_index.Accordion.Item, { value: subLink.name, children: [
275
- /* @__PURE__ */ jsxRuntime.jsxs(components_accordion_index.Accordion.Header, { children: [
376
+ /* @__PURE__ */ jsxRuntime.jsxs(components_accordion_index.Accordion.Header, { className: styles[`${rootClassName}__mobile-header`], children: [
276
377
  /* @__PURE__ */ jsxRuntime.jsx(
277
378
  components_link_link.Link,
278
379
  {
@@ -289,7 +390,7 @@ function Mobile(props) {
289
390
  children: subLink.appKey === rootContext.appKey || rootContext.appKey === "storybook" ? /* @__PURE__ */ jsxRuntime.jsx(NavLink, { href: subLink.link, children: subLink.name }) : /* @__PURE__ */ jsxRuntime.jsx("a", { href: subLink.link, children: subLink.name })
290
391
  }
291
392
  ),
292
- /* @__PURE__ */ jsxRuntime.jsx(components_accordion_index.Accordion.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsxs(components_visuallyHidden_visuallyHidden.VisuallyHidden, { children: [
393
+ /* @__PURE__ */ jsxRuntime.jsx(components_accordion_index.Accordion.Trigger, { className: styles[`${rootClassName}__mobile-trigger`], children: /* @__PURE__ */ jsxRuntime.jsxs(components_visuallyHidden_visuallyHidden.VisuallyHidden, { children: [
293
394
  subLink.name,
294
395
  " linker"
295
396
  ] }) })
@@ -299,7 +400,7 @@ function Mobile(props) {
299
400
  {
300
401
  asChild: true,
301
402
  variant: "small",
302
- active: currentLocation === subSubLink.link,
403
+ active: currentLocation.startsWith(subSubLink.link),
303
404
  onClick: () => {
304
405
  var _a;
305
406
  (_a = drawerRef.current) == null ? void 0 : _a.click();
@@ -383,12 +484,23 @@ function Root({
383
484
  onCartOpenChange,
384
485
  drawerSize = "md",
385
486
  isSimplified,
487
+ initialDomain = "Privat",
488
+ initialMenuItem,
386
489
  ...props
387
490
  }) {
388
- const [selectedMenuItem, setSelectedMenuItem] = React.useState(getInitialMenuItem());
389
- const [selectedDomainItem, setSelectedDomainItem] = React.useState(getInitialDomain());
390
- const [pathname, setPathname] = React.useState(typeof window !== "undefined" ? window.location.pathname : "");
491
+ const [selectedMenuItem, setSelectedMenuItem] = React.useState(initialMenuItem);
492
+ const [selectedDomainItem, setSelectedDomainItem] = React.useState(initialDomain);
493
+ const [pathname, setPathname] = React.useState("");
391
494
  const classes = clsx([styles[`${rootClassName}`]], className);
495
+ React.useEffect(() => {
496
+ setPathname(window.location.pathname);
497
+ if (!initialDomain) {
498
+ setSelectedDomainItem(getInitialDomain());
499
+ }
500
+ if (!initialMenuItem) {
501
+ setSelectedMenuItem(getInitialMenuItem());
502
+ }
503
+ }, []);
392
504
  return /* @__PURE__ */ jsxRuntime.jsx(
393
505
  RootContext.Provider,
394
506
  {
@@ -1,5 +1,5 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
- import React__default from "react";
2
+ import React__default, { useEffect } from "react";
3
3
  import clsx from "clsx";
4
4
  import { MY_PAGE_LINKS, LOGGED_IN_LINKS_BUSINESS, LINKS, PRIVATE_LINKS, BUSINESS_LINKS, MDU_LINKS } from "./utils.js";
5
5
  import { NavigationMenu } from "../navigation-menu.js";
@@ -17,18 +17,29 @@ import { useComposedRefs } from "../../../utils/composeRefs.js";
17
17
  import "../../badge/badge.js";
18
18
  import "../../badge/alert-badge.js";
19
19
  import { CounterBadge } from "../../badge/counter-badge.js";
20
+ import { useSize } from "../../../utils/useSize.js";
21
+ import { mergeStyles } from "../../../utils/generate-styling/index.js";
22
+ import { useCallbackRef } from "../../../utils/useCallbackRef.js";
20
23
  import { Flex } from "../../flex/flex.js";
21
24
  import { Accordion } from "../../accordion/index.js";
22
25
  import { VisuallyHidden } from "../../visually-hidden/visually-hidden.js";
23
26
  import { Link } from "../../link/link.js";
24
27
  import { List } from "../../list/index.js";
25
28
  const styles = {
26
- "teddy-global-navigation": "_teddy-global-navigation_y8nb6_1",
27
- "teddy-global-navigation__mobile": "_teddy-global-navigation__mobile_y8nb6_6",
28
- "teddy-global-navigation__link": "_teddy-global-navigation__link_y8nb6_20",
29
- "teddy-global-navigation__viewport": "_teddy-global-navigation__viewport_y8nb6_23",
30
- "teddy-global-navigation__item-wrapper": "_teddy-global-navigation__item-wrapper_y8nb6_26",
31
- "teddy-global-navigation__item-count": "_teddy-global-navigation__item-count_y8nb6_29"
29
+ "teddy-global-navigation": "_teddy-global-navigation_1ue02_1",
30
+ "teddy-global-navigation__mobile-trigger": "_teddy-global-navigation__mobile-trigger_1ue02_6",
31
+ "teddy-global-navigation__mobile-header": "_teddy-global-navigation__mobile-header_1ue02_9",
32
+ "teddy-global-navigation__mobile": "_teddy-global-navigation__mobile_1ue02_6",
33
+ "teddy-global-navigation__link": "_teddy-global-navigation__link_1ue02_26",
34
+ "teddy-global-navigation__viewport": "_teddy-global-navigation__viewport_1ue02_29",
35
+ "teddy-global-navigation__item-wrapper": "_teddy-global-navigation__item-wrapper_1ue02_32",
36
+ "teddy-global-navigation__item-count": "_teddy-global-navigation__item-count_1ue02_35",
37
+ "teddy-global-navigation__viewport-wrapper": "_teddy-global-navigation__viewport-wrapper_1ue02_43",
38
+ "expand-viewport": "_expand-viewport_1ue02_1",
39
+ "close-viewport": "_close-viewport_1ue02_1",
40
+ "teddy-global-navigation__top-menu-wrapper": "_teddy-global-navigation__top-menu-wrapper_1ue02_53",
41
+ "expand-top-menu": "_expand-top-menu_1ue02_1",
42
+ "close-top-menu": "_close-top-menu_1ue02_1"
32
43
  };
33
44
  function MyPages(props) {
34
45
  var _a, _b;
@@ -160,6 +171,8 @@ const ShoppingCart = React__default.forwardRef(() => {
160
171
  const shoppingCartContent = rootContext == null ? void 0 : rootContext.shoppingCart;
161
172
  const numberOfItemsInCart = (rootContext == null ? void 0 : rootContext.shoppingCartNumberOfItems) || 0;
162
173
  const titleSuffix = numberOfItemsInCart > 0 ? `(${numberOfItemsInCart})` : "";
174
+ if (!numberOfItemsInCart)
175
+ return null;
163
176
  return /* @__PURE__ */ jsxs(Drawer, { open: rootContext == null ? void 0 : rootContext.isCartOpen, onOpenChange: rootContext == null ? void 0 : rootContext.onCartOpenChange, children: [
164
177
  /* @__PURE__ */ jsx(NavigationMenu.Link, { asChild: true, variant: "button", children: /* @__PURE__ */ jsx(Drawer.Trigger, { children: /* @__PURE__ */ jsxs("button", { children: [
165
178
  /* @__PURE__ */ jsxs("div", { className: clsx([styles[`${rootClassName}__item-wrapper`]]), children: [
@@ -180,15 +193,79 @@ const ShoppingCart = React__default.forwardRef(() => {
180
193
  ] });
181
194
  });
182
195
  ShoppingCart.displayName = "ShoppingCart";
196
+ const scrollDistanceDownThreshold = 200;
197
+ const scrollDistanceUpThreshold = 50;
198
+ const ANIMATION_DURATION = 300;
183
199
  const Desktop = React__default.forwardRef(() => {
184
200
  const rootContext = React__default.useContext(RootContext);
201
+ const [hideMenu, setHideMenu] = React__default.useState(false);
202
+ const lastScrollDirection = React__default.useRef();
203
+ const scrollStartPos = React__default.useRef(0);
204
+ const lastScrollPos = React__default.useRef(0);
205
+ const topMenuRef = React__default.useRef(null);
206
+ const viewPortRef = React__default.useRef(null);
207
+ const viewPortSize = useSize(viewPortRef.current);
208
+ const topMenuSize = useSize(topMenuRef.current);
209
+ const topMenuHeight = (topMenuSize == null ? void 0 : topMenuSize.height) ? `${topMenuSize.height}px` : void 0;
210
+ const viewPortHeight = (viewPortSize == null ? void 0 : viewPortSize.height) ? `${viewPortSize.height}px` : void 0;
211
+ const animationTimer = React__default.useRef(0);
212
+ const handleScroll = () => {
213
+ let compensateHight = 0;
214
+ if (animationTimer.current > 0) {
215
+ const currentTime = (/* @__PURE__ */ new Date()).getTime();
216
+ if (animationTimer.current + ANIMATION_DURATION > currentTime) {
217
+ compensateHight = ((topMenuSize == null ? void 0 : topMenuSize.height) || 0) + ((viewPortSize == null ? void 0 : viewPortSize.height) || 0);
218
+ } else {
219
+ animationTimer.current = 0;
220
+ }
221
+ }
222
+ const scrollY = window.scrollY;
223
+ const scrollDirection = scrollY > lastScrollPos.current ? "down" : "up";
224
+ const scrollDistance = Math.abs(scrollStartPos.current - scrollY);
225
+ if (scrollDirection !== lastScrollDirection.current) {
226
+ scrollStartPos.current = scrollY;
227
+ }
228
+ if (!hideMenu && scrollDirection === lastScrollDirection.current && scrollDirection === "down" && scrollDistance > scrollDistanceDownThreshold + compensateHight) {
229
+ setHideMenu(true);
230
+ const currentTime = (/* @__PURE__ */ new Date()).getTime();
231
+ animationTimer.current = currentTime;
232
+ }
233
+ if (hideMenu && scrollDirection === lastScrollDirection.current && scrollDirection === "up" && scrollDistance > scrollDistanceUpThreshold + compensateHight || scrollY === 0) {
234
+ setHideMenu(false);
235
+ const currentTime = (/* @__PURE__ */ new Date()).getTime();
236
+ animationTimer.current = currentTime;
237
+ }
238
+ lastScrollDirection.current = scrollDirection;
239
+ lastScrollPos.current = scrollY;
240
+ };
241
+ const throttledScrollHandler = useDebounceCallback(handleScroll, 5);
242
+ React__default.useEffect(() => {
243
+ window.addEventListener("scroll", throttledScrollHandler);
244
+ return () => {
245
+ window.removeEventListener("scroll", throttledScrollHandler);
246
+ };
247
+ }, [throttledScrollHandler]);
185
248
  if (!rootContext)
186
249
  return null;
250
+ function resetAndShowMenu() {
251
+ lastScrollDirection.current = null;
252
+ scrollStartPos.current = window.scrollY;
253
+ lastScrollPos.current = window.scrollY;
254
+ setHideMenu(false);
255
+ }
187
256
  const { setSelectedMenuItem, linkComponent: Link2 } = rootContext;
188
257
  const currentLocation = rootContext.pathname;
189
258
  return /* @__PURE__ */ jsxs(Fragment, { children: [
190
- /* @__PURE__ */ jsx(NavigationMenu.TopMenuList, { children: LINKS.map((link) => /* @__PURE__ */ jsx(NavigationMenu.TopMenuItem, { children: /* @__PURE__ */ jsx(NavigationMenu.TopMenuTrigger, { value: link.name, asChild: true, children: /* @__PURE__ */ jsx(Link2, { href: link.link, children: link.name }) }) }, link.name)) }),
191
- LINKS.map((link) => /* @__PURE__ */ jsxs(NavigationMenu.List, { value: link.name, children: [
259
+ /* @__PURE__ */ jsx(
260
+ "div",
261
+ {
262
+ style: mergeStyles({ ["--teddy-top-menu-height"]: topMenuHeight }),
263
+ className: styles[`${rootClassName}__top-menu-wrapper`],
264
+ "data-state": hideMenu ? "closed" : "open",
265
+ children: /* @__PURE__ */ jsx(NavigationMenu.TopMenuList, { onFocus: resetAndShowMenu, ref: topMenuRef, children: LINKS.map((link) => /* @__PURE__ */ jsx(NavigationMenu.TopMenuItem, { children: /* @__PURE__ */ jsx(NavigationMenu.TopMenuTrigger, { value: link.name, asChild: true, children: /* @__PURE__ */ jsx(Link2, { href: link.link, children: link.name }) }) }, link.name)) })
266
+ }
267
+ ),
268
+ LINKS.map((link) => /* @__PURE__ */ jsxs(NavigationMenu.List, { onFocus: resetAndShowMenu, value: link.name, children: [
192
269
  link.links.map((subLink) => /* @__PURE__ */ jsxs(NavigationMenu.Item, { value: subLink.name, children: [
193
270
  subLink.name === "Logo" ? /* @__PURE__ */ jsx(NavigationMenu.Link, { asChild: true, variant: "button", children: subLink.appKey === rootContext.appKey || rootContext.appKey === "storybook" ? /* @__PURE__ */ jsx(Link2, { href: subLink.link, onClick: () => setSelectedMenuItem(""), children: /* @__PURE__ */ jsx(
194
271
  "img",
@@ -219,7 +296,7 @@ const Desktop = React__default.forwardRef(() => {
219
296
  NavigationMenu.Link,
220
297
  {
221
298
  asChild: true,
222
- active: currentLocation === subSubLink.link,
299
+ active: currentLocation.startsWith(subSubLink.link),
223
300
  onClick: () => {
224
301
  rootContext.setPathname(subSubLink.link);
225
302
  },
@@ -233,10 +310,34 @@ const Desktop = React__default.forwardRef(() => {
233
310
  /* @__PURE__ */ jsx(NavigationMenu.Item, { children: /* @__PURE__ */ jsx(ShoppingCart, {}) }),
234
311
  /* @__PURE__ */ jsx(NavigationMenu.Item, { children: /* @__PURE__ */ jsx(MyPages, {}) })
235
312
  ] }, link.name)),
236
- /* @__PURE__ */ jsx(NavigationMenu.Viewport, { className: styles[`${rootClassName}__viewport`] })
313
+ /* @__PURE__ */ jsx(
314
+ "div",
315
+ {
316
+ style: mergeStyles({ ["--teddy-viewport-wrapper-height"]: viewPortHeight }),
317
+ className: styles[`${rootClassName}__viewport-wrapper`],
318
+ "data-state": hideMenu ? "closed" : "open",
319
+ children: /* @__PURE__ */ jsx(
320
+ NavigationMenu.Viewport,
321
+ {
322
+ onFocus: resetAndShowMenu,
323
+ ref: viewPortRef,
324
+ className: styles[`${rootClassName}__viewport`]
325
+ }
326
+ )
327
+ }
328
+ )
237
329
  ] });
238
330
  });
239
331
  Desktop.displayName = "Desktop";
332
+ function useDebounceCallback(callback, delay) {
333
+ const handleCallback = useCallbackRef(callback);
334
+ const debounceTimerRef = React__default.useRef(0);
335
+ React__default.useEffect(() => () => window.clearTimeout(debounceTimerRef.current), []);
336
+ return React__default.useCallback(() => {
337
+ window.clearTimeout(debounceTimerRef.current);
338
+ debounceTimerRef.current = window.setTimeout(handleCallback, delay);
339
+ }, [handleCallback, delay]);
340
+ }
240
341
  function Mobile(props) {
241
342
  const rootContext = React__default.useContext(RootContext);
242
343
  const drawerRef = React__default.useRef(null);
@@ -270,7 +371,7 @@ function Mobile(props) {
270
371
  value: rootContext.selectedMenuItem,
271
372
  onValueChange: rootContext.setSelectedMenuItem,
272
373
  children: link.links.filter((l) => l.name !== "Logo").map((subLink) => /* @__PURE__ */ jsxs(Accordion.Item, { value: subLink.name, children: [
273
- /* @__PURE__ */ jsxs(Accordion.Header, { children: [
374
+ /* @__PURE__ */ jsxs(Accordion.Header, { className: styles[`${rootClassName}__mobile-header`], children: [
274
375
  /* @__PURE__ */ jsx(
275
376
  Link,
276
377
  {
@@ -287,7 +388,7 @@ function Mobile(props) {
287
388
  children: subLink.appKey === rootContext.appKey || rootContext.appKey === "storybook" ? /* @__PURE__ */ jsx(NavLink, { href: subLink.link, children: subLink.name }) : /* @__PURE__ */ jsx("a", { href: subLink.link, children: subLink.name })
288
389
  }
289
390
  ),
290
- /* @__PURE__ */ jsx(Accordion.Trigger, { children: /* @__PURE__ */ jsxs(VisuallyHidden, { children: [
391
+ /* @__PURE__ */ jsx(Accordion.Trigger, { className: styles[`${rootClassName}__mobile-trigger`], children: /* @__PURE__ */ jsxs(VisuallyHidden, { children: [
291
392
  subLink.name,
292
393
  " linker"
293
394
  ] }) })
@@ -297,7 +398,7 @@ function Mobile(props) {
297
398
  {
298
399
  asChild: true,
299
400
  variant: "small",
300
- active: currentLocation === subSubLink.link,
401
+ active: currentLocation.startsWith(subSubLink.link),
301
402
  onClick: () => {
302
403
  var _a;
303
404
  (_a = drawerRef.current) == null ? void 0 : _a.click();
@@ -381,12 +482,23 @@ function Root({
381
482
  onCartOpenChange,
382
483
  drawerSize = "md",
383
484
  isSimplified,
485
+ initialDomain = "Privat",
486
+ initialMenuItem,
384
487
  ...props
385
488
  }) {
386
- const [selectedMenuItem, setSelectedMenuItem] = React__default.useState(getInitialMenuItem());
387
- const [selectedDomainItem, setSelectedDomainItem] = React__default.useState(getInitialDomain());
388
- const [pathname, setPathname] = React__default.useState(typeof window !== "undefined" ? window.location.pathname : "");
489
+ const [selectedMenuItem, setSelectedMenuItem] = React__default.useState(initialMenuItem);
490
+ const [selectedDomainItem, setSelectedDomainItem] = React__default.useState(initialDomain);
491
+ const [pathname, setPathname] = React__default.useState("");
389
492
  const classes = clsx([styles[`${rootClassName}`]], className);
493
+ useEffect(() => {
494
+ setPathname(window.location.pathname);
495
+ if (!initialDomain) {
496
+ setSelectedDomainItem(getInitialDomain());
497
+ }
498
+ if (!initialMenuItem) {
499
+ setSelectedMenuItem(getInitialMenuItem());
500
+ }
501
+ }, []);
390
502
  return /* @__PURE__ */ jsx(
391
503
  RootContext.Provider,
392
504
  {
@@ -17,6 +17,8 @@ export type RootProps = React.ComponentPropsWithoutRef<'div'> & {
17
17
  onCartOpenChange?: (open: boolean) => void;
18
18
  drawerSize: 'md' | 'lg';
19
19
  isSimplified?: boolean;
20
+ initialDomain?: 'Privat' | 'Bedrift' | 'Borettslag';
21
+ initialMenuItem?: string;
20
22
  };
21
23
  type RootContext = {
22
24
  selectedMenuItem: string | undefined;
@@ -27,7 +29,7 @@ type RootContext = {
27
29
  setPathname: (v: string) => void;
28
30
  } & Pick<RootProps, 'onSearchSubmit' | 'shoppingCart' | 'shoppingCartNumberOfItems' | 'loggedInUser' | 'appKey' | 'onLogoutClick' | 'linkComponent' | 'isCartOpen' | 'onCartOpenChange' | 'drawerSize'>;
29
31
  export declare const RootContext: React.Context<RootContext | null>;
30
- export declare function Root({ className, appKey, loggedInUser, linkComponent, onLogoutClick, shoppingCart, shoppingCartNumberOfItems, onSearchSubmit, isCartOpen, onCartOpenChange, drawerSize, isSimplified, ...props }: RootProps): import("react/jsx-runtime").JSX.Element;
32
+ export declare function Root({ className, appKey, loggedInUser, linkComponent, onLogoutClick, shoppingCart, shoppingCartNumberOfItems, onSearchSubmit, isCartOpen, onCartOpenChange, drawerSize, isSimplified, initialDomain, initialMenuItem, ...props }: RootProps): import("react/jsx-runtime").JSX.Element;
31
33
  export declare namespace Root {
32
34
  var displayName: string;
33
35
  }
@@ -64,7 +64,7 @@ const BUSINESS_NET_LINKS = {
64
64
  const LOGGED_IN_LINKS_BUSINESS = [MY_BUSINESS_LINKS, MY_PORTAL_LINKS, BUSINESS_NET_LINKS];
65
65
  const LOGGED_IN_LINKS = [MY_PAGE_LINKS, ...LOGGED_IN_LINKS_BUSINESS];
66
66
  const PRIVATE_LINKS = {
67
- name: "Private",
67
+ name: "Privat",
68
68
  link: "/",
69
69
  links: [
70
70
  {
@@ -107,6 +107,11 @@ const PRIVATE_LINKS = {
107
107
  name: "Påfyll kontantkort",
108
108
  link: "/mobil/mobilabonnement/kontantkort/lade/",
109
109
  appKey: APP_KEYS["open-pages"]
110
+ },
111
+ {
112
+ name: "Hjelp Mobil",
113
+ link: "/mobil/hjelp/",
114
+ appKey: APP_KEYS["open-pages"]
110
115
  }
111
116
  ]
112
117
  },
@@ -121,28 +126,38 @@ const PRIVATE_LINKS = {
121
126
  appKey: APP_KEYS["open-pages"]
122
127
  },
123
128
  {
124
- name: "Strømmetjenester",
125
- link: "/tv/strommetjenester/",
129
+ name: "Innholdsoversikt",
130
+ link: "/tv/innholdsoversikt/",
126
131
  appKey: APP_KEYS["open-pages"]
127
132
  },
133
+ // {
134
+ // name: 'Strømmetjenester',
135
+ // link: '/tv/strommetjenester/',
136
+ // appKey: APP_KEYS['open-pages'],
137
+ // },
138
+ // {
139
+ // name: 'TV-kanaler',
140
+ // link: '/tv/tv-kanaler-og-kanalpakker/',
141
+ // appKey: APP_KEYS['open-pages'],
142
+ // },
143
+ // {
144
+ // name: 'Premiumtjenester',
145
+ // link: '/tv/premiumtjenester/',
146
+ // appKey: APP_KEYS['open-pages'],
147
+ // },
148
+ // {
149
+ // name: 'Filmer',
150
+ // link: '/tv/filmleie-og-filmkjop/',
151
+ // appKey: APP_KEYS['open-pages'],
152
+ // },
128
153
  {
129
- name: "TV-kanaler",
130
- link: "/tv/tv-kanaler-og-kanalpakker/",
131
- appKey: APP_KEYS["open-pages"]
132
- },
133
- {
134
- name: "Premiumtjenester",
135
- link: "/tv/premiumtjenester/",
136
- appKey: APP_KEYS["open-pages"]
137
- },
138
- {
139
- name: "Filmer",
140
- link: "/tv/filmleie-og-filmkjop/",
154
+ name: "TV-bokser",
155
+ link: "/tv/tv-bokser/",
141
156
  appKey: APP_KEYS["open-pages"]
142
157
  },
143
158
  {
144
- name: "TV-bokser",
145
- link: "/tv/tv-bokser/",
159
+ name: "Hjelp TV",
160
+ link: "/tv/hjelp/",
146
161
  appKey: APP_KEYS["open-pages"]
147
162
  }
148
163
  ]
@@ -181,6 +196,11 @@ const PRIVATE_LINKS = {
181
196
  name: "Speedtest",
182
197
  link: "/internett/speedtest/",
183
198
  appKey: APP_KEYS["open-pages"]
199
+ },
200
+ {
201
+ name: "Hjelp Internett",
202
+ link: "/internett/hjelp/",
203
+ appKey: APP_KEYS["open-pages"]
184
204
  }
185
205
  ]
186
206
  },
@@ -213,12 +233,12 @@ const PRIVATE_LINKS = {
213
233
  name: "Finn butikk",
214
234
  link: "/hjelp/butikker/",
215
235
  appKey: APP_KEYS["open-pages"]
216
- },
217
- {
218
- name: "Kontakt oss",
219
- link: "/hjelp/kontakt-oss/",
220
- appKey: APP_KEYS["open-pages"]
221
236
  }
237
+ // {
238
+ // name: 'Kontakt oss',
239
+ // link: '/hjelp/kontakt-oss/',
240
+ // appKey: APP_KEYS['open-pages'],
241
+ // },
222
242
  ]
223
243
  }
224
244
  ]
@@ -247,17 +267,17 @@ const BUSINESS_LINKS = {
247
267
  },
248
268
  {
249
269
  name: "Nettbutikk",
250
- link: "/bedrift/nettbutikk/",
270
+ link: "/bedrift/mobilabonnement/",
251
271
  appKey: APP_KEYS["web-shop"],
252
272
  links: [
253
273
  {
254
- name: "Mobiltelefoner",
255
- link: "/bedrift/mobiltelefoner/",
274
+ name: "Mobilabonnement",
275
+ link: "/bedrift/mobilabonnement/",
256
276
  appKey: APP_KEYS["web-shop"]
257
277
  },
258
278
  {
259
- name: "Mobilabonnement",
260
- link: "/bedrift/mobilabonnement/",
279
+ name: "Mobiltelefoner",
280
+ link: "/bedrift/mobiltelefoner/",
261
281
  appKey: APP_KEYS["web-shop"]
262
282
  },
263
283
  {
@@ -268,7 +288,13 @@ const BUSINESS_LINKS = {
268
288
  ]
269
289
  },
270
290
  {
271
- name: "Kundeservice",
291
+ name: "Sikkerhet",
292
+ link: "/bedrift/sikkerhet/",
293
+ appKey: APP_KEYS["open-pages"],
294
+ links: []
295
+ },
296
+ {
297
+ name: "Hjelp",
272
298
  link: "/bedrift/kundeservice/",
273
299
  appKey: APP_KEYS["open-pages"],
274
300
  links: []