gatsby-core-theme 22.0.15 → 23.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 (90) hide show
  1. package/.storybook/preview.js +3 -2
  2. package/.storybook/storybook-styles/global.module.scss +4 -0
  3. package/.storybook/storybook-styles/navigation.module.scss +36 -0
  4. package/.storybook/storybook-styles.module.scss +5 -0
  5. package/CHANGELOG.md +48 -0
  6. package/package.json +1 -1
  7. package/src/components/atoms/author/author.stories.js +1 -1
  8. package/src/components/atoms/author-box/author-box.stories.js +1 -1
  9. package/src/components/atoms/bonus/bonus.stories.js +1 -1
  10. package/src/components/atoms/breadcrumbs/breadcrumbs.stories.js +1 -1
  11. package/src/components/atoms/button/button.stories.js +1 -1
  12. package/src/components/atoms/collapse/collpase.stories.js +1 -1
  13. package/src/components/atoms/content-box/content-box.stories.js +1 -1
  14. package/src/components/atoms/custom-select/custom-select.stories.js +1 -1
  15. package/src/components/atoms/faq/faq.stories.js +1 -1
  16. package/src/components/atoms/iframe/iframe.stories.js +1 -1
  17. package/src/components/atoms/image/image.stories.js +1 -1
  18. package/src/components/atoms/info-grid/info-grid.stories.js +1 -1
  19. package/src/components/atoms/label/label.stories.js +1 -1
  20. package/src/components/atoms/menu/items/index.js +76 -82
  21. package/src/components/atoms/menu/items/item/index.js +11 -92
  22. package/src/components/atoms/menu/items/item/item.module.scss +18 -57
  23. package/src/components/atoms/menu/items/item/item.moduleOriginal.scss +67 -0
  24. package/src/components/atoms/menu/items/items.module.scss +204 -58
  25. package/src/components/atoms/menu/items/items.test.js +33 -0
  26. package/src/components/atoms/menu/menu-icon/index.js +2 -2
  27. package/src/components/atoms/menu/menu-icon/menu-icon.module.scss +5 -4
  28. package/src/components/atoms/menu/menu-icon/menu-icon.test.js +44 -0
  29. package/src/components/atoms/menu/variables/index.js +26 -0
  30. package/src/components/atoms/menu/variables/variable.module.scss +0 -0
  31. package/src/components/atoms/module-title/module-title.stories.js +1 -1
  32. package/src/components/atoms/number-rating/number-rating.stories.js +1 -1
  33. package/src/components/atoms/open-graph/open-graph.stories.js +1 -1
  34. package/src/components/atoms/operator-cta/operator-cta.stories.js +1 -1
  35. package/src/components/atoms/operator-cta-button/operator-cta-button.stories.js +1 -1
  36. package/src/components/atoms/operator-info-block/operator-info-block.stories.js +1 -1
  37. package/src/components/atoms/scroll-to-top/stroll-to-top.stories.js +1 -1
  38. package/src/components/atoms/selling-points/selling-points.stories.js +1 -1
  39. package/src/components/atoms/sitemap/sitemap.stories.js +1 -1
  40. package/src/components/atoms/spotlights/spotlights.stories.js +1 -1
  41. package/src/components/atoms/timeline/timeline.stories.js +1 -1
  42. package/src/components/molecules/content/content.stories.js +1 -1
  43. package/src/components/molecules/content-and-custom-module/content-and-custom-module.stories.js +1 -1
  44. package/src/components/molecules/counter/counter-item/count-date/count-date.stories.js +1 -1
  45. package/src/components/molecules/counter/counter-item/count-number/count-number.stories.js +1 -1
  46. package/src/components/molecules/counter/counter.stories.js +1 -1
  47. package/src/components/molecules/footer/footer.stories.js +1 -1
  48. package/src/components/molecules/header/header.module.scss +1 -0
  49. package/src/components/molecules/header/{header.storiesssss.js → header.stories.js} +1 -1
  50. package/src/components/molecules/link-list/link-list.stories.js +1 -1
  51. package/src/components/molecules/menu/index.js +23 -43
  52. package/src/components/molecules/menu/menu.module.scss +76 -97
  53. package/src/components/molecules/menu/menu.test.js +111 -83
  54. package/src/components/molecules/operator-banner/operator-banner.stories.js +1 -1
  55. package/src/components/molecules/pagination/pagination.stories.js +1 -1
  56. package/src/components/molecules/pagination/with-midpoint.stories.js +1 -1
  57. package/src/components/molecules/pros-cons/pros-cons.stories.js +1 -1
  58. package/src/components/molecules/slider/slider.stories.js +1 -1
  59. package/src/components/molecules/star-rating/star-rating.stories.js +1 -1
  60. package/src/components/molecules/sticky/sticky.stories.js +1 -1
  61. package/src/components/molecules/tnc/tnc.stories.js +1 -1
  62. package/src/components/organisms/accordion/accordion.stories.js +1 -1
  63. package/src/components/organisms/anchor/anchor.module.scss +21 -16
  64. package/src/components/organisms/anchor/anchor.stories.js +3 -3
  65. package/src/components/organisms/archive/archive.stories.js +1 -1
  66. package/src/components/organisms/cards/cards.stories.js +1 -1
  67. package/src/components/organisms/cookie-consent/cookie-consent.stories.js +1 -1
  68. package/src/components/organisms/form/form.stories.js +1 -1
  69. package/src/components/organisms/navigation/index.js +26 -34
  70. package/src/components/organisms/navigation/navigation.module.scss +35 -39
  71. package/src/components/organisms/navigation/navigation.stories.js +163 -119
  72. package/src/components/organisms/navigation/navigation.test.js +28 -3
  73. package/src/components/organisms/search/search.stories.js +1 -1
  74. package/src/components/organisms/toplist/toplist.stories.js +1 -1
  75. package/src/components/pages/body/index.js +4 -12
  76. package/src/components/pages/tracker/tracker.stories.js +1 -1
  77. package/src/helpers/menu.js +24 -0
  78. package/src/helpers/menu.test.js +30 -0
  79. package/src/hooks/lazy-image/lazy-image.stories.js +1 -1
  80. package/src/hooks/lazy-picture/lazy-picture.stories.js +1 -1
  81. package/src/hooks/modal/modal.stories.js +1 -1
  82. package/src/hooks/tabs/tabs.stories.js +1 -1
  83. package/src/styles/utils/_animations.scss +4 -3
  84. package/src/styles/utils/_media-queries.scss +0 -10
  85. package/src/styles/utils/variables/_colors.scss +2 -0
  86. package/src/styles/utils/variables/_main.scss +29 -1
  87. package/static/images/bell.svg +3 -0
  88. package/static/images/notification-bubble.svg +4 -0
  89. package/tests/factories/sections/navigationStatic.factory.js +229 -0
  90. package/src/components/molecules/menu/menu.stories.js +0 -155
@@ -1,5 +1,6 @@
1
1
  import '../gatsby-browser';
2
2
  import React from 'react';
3
+ import styles from './storybook-styles.module.scss';
3
4
 
4
5
  global.___loader = {
5
6
  enqueue: () => {},
@@ -19,7 +20,7 @@ export const parameters = {
19
20
  options: {
20
21
  storySort: {
21
22
  method: 'alphabetical',
22
- order: ['Gatsby-Theme', ['Atoms', 'Molecules', 'Organisms', 'Pages', 'Hooks']],
23
+ order: ['Theme', ['Layout', 'Modules', 'Atoms', 'Molecules', 'Organisms', 'Pages', 'Hooks']],
23
24
  },
24
25
  },
25
26
  };
@@ -27,7 +28,7 @@ export const parameters = {
27
28
  // Global decorators for stories
28
29
  export const decorators = [
29
30
  (Story) => (
30
- <div style={{ margin: '1.5rem auto 0', maxWidth: '96rem' }}>
31
+ <div className={styles.storyMainContainer}>
31
32
  <Story />
32
33
  </div>
33
34
  ),
@@ -0,0 +1,4 @@
1
+ .storyMainContainer {
2
+ margin: 1.5rem auto 0;
3
+ max-width: 96rem;
4
+ }
@@ -0,0 +1,36 @@
1
+ .navStoryContainer {
2
+ position: relative;
3
+ width: 100%;
4
+ height: calc(100vh - 5rem);
5
+
6
+ // added so that nav is visible on storybook without stretched beyond the viewport due to position:fixed
7
+ > div {
8
+ max-width: 96rem;
9
+ width: calc(100vw - 20px);
10
+ }
11
+
12
+ nav {
13
+ padding: 0 10px;
14
+ }
15
+
16
+ // dummy content styles
17
+ main {
18
+ padding-top: var(--nav-height);
19
+ background-color: var(--color-4);
20
+
21
+ pre {
22
+ display: inline;
23
+ }
24
+
25
+ .dummyContent {
26
+ letter-spacing: 0.2rem;
27
+ margin: 5rem auto;
28
+ width: 80vw;
29
+
30
+ @include min(laptop) {
31
+ margin: 10rem auto;
32
+ width: 60vw;
33
+ }
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,5 @@
1
+ // Storybook styles extended in each theme
2
+
3
+ // Storybook Styles
4
+ @import './storybook-styles/global.module.scss';
5
+ @import './storybook-styles/navigation.module.scss';
package/CHANGELOG.md CHANGED
@@ -1,3 +1,51 @@
1
+ # [23.0.0](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/compare/v22.0.15...v23.0.0) (2023-06-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * fix for tests ([77425fc](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/77425fc2037aeb3606db730df4e304a3a3697a90))
7
+ * fix for tests ([d2871a2](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/d2871a26364aff6b39273c62c144eb83760ad082))
8
+ * storybook paths ([c7c5087](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/c7c50872e52adfa4d88d995a81f2ea0e81847dc1))
9
+
10
+
11
+ ### Code Refactoring
12
+
13
+ * add changes to custom component ([929f141](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/929f14142d9611cd0847dda2be7a09faf927afa3))
14
+ * add logo width to align with sitelevel ([38cf693](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/38cf69332560717397dc51292b192eac3ac00097))
15
+ * added page context back and new custom component ([4663159](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/4663159caff6ab8c57fa75b485a48a4b68173d37))
16
+ * changes to code review ([59e3bc9](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/59e3bc9113591615ce30ff52ecd9415708bca39b))
17
+ * changes to mobile menu open/close ([8dcba1e](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/8dcba1e6d8e72319b314893a65a5e10903781fd2))
18
+ * changes to nav click even when clicking on child nav links ([d9cfc69](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/d9cfc692929362cc7e5adac148812a46e36a6c3b))
19
+ * changes to storybook ([1f9978a](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/1f9978af14422e351cd82f6f14f59e61ec91c2b0))
20
+ * changes to storybook styles ([0687026](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/0687026192912092a789d67178bcab9279862795))
21
+ * changes to styles ([eed0288](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/eed028825fe4e766d5051116c1a215f1b9262f49))
22
+ * clean up css files ([afeed74](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/afeed747071d3b970fbf03416f52e37f6bd6cd49))
23
+ * close all menus if when opening one if its enabled ([4ac8878](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/4ac88788e64b6a45461612ab0cb47999c9547fe4))
24
+ * code review changes ([131a303](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/131a303feb0775d4511716b2aea7f9a3d1f7b321))
25
+ * code review changes, file rename to fix typo ([4ac8e2a](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/4ac8e2af06504f9107b4acd8c29d260baedfd4d4))
26
+ * correction to li style ([588167b](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/588167b33767c34972cb77fbaffbdd2df2ee1a43))
27
+ * correction to menu item labeling long words ([542bc16](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/542bc16a6c4aad77948880bf17a44442051880d8))
28
+ * correction to storybook, fix unwanted props ([e63c438](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/e63c43870446ffad2723e7b10dda49604c4bf14c))
29
+ * initial commit ([a23307c](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/a23307c61f7a8e905e3c3f8ee63800636faa7ae9))
30
+ * initial storybook changes ([c358380](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/c358380002f110c26b513567bd1566600667f4b8))
31
+ * minor css changes ([2253833](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/225383340ebcc3fc49545fc1c1f208a8475723e6))
32
+ * remove temp variable ([f2fb5f7](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/f2fb5f788a42680a828a595217c9cf4d2856034a))
33
+ * remove unused vars ([746bb19](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/746bb19dc9ffd2790609ee4d2e78a217d30fd850))
34
+
35
+
36
+ * Merge branch 'tm-3475-main-menu' into 'master' ([1029e54](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/1029e54fecebabdf76647e759c9a763cd24edea4))
37
+ * Merge branch 'master' into tm-3475-main-menu ([7771485](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/77714850e6c86a4ba7670db47d6843239a4e2183))
38
+ * Merge branch 'master' into tm-3475-main-menu ([3805342](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/380534213add828157336133a33eab5bd9064cfb))
39
+ * Merge branch 'master' into tm-3475-main-menu ([531e98e](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/531e98e0be3128b829fec83eb6b9719af6c5465f))
40
+ * Merge branch 'master' into tm-3475-main-menu ([1074e24](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/1074e24d608f4ef4b74ca338e3f7e9ff2f27a725))
41
+
42
+
43
+ ### Tests
44
+
45
+ * add test ([1926693](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/19266937454c7926c48d652f22d0f20120a5f52e))
46
+ * fix for tests ([054dca9](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/054dca90f302772ef4c8b3bc171b80cee87eea35))
47
+ * temp changes to test ([f760d93](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/f760d9383f80f1bd0c98766380adecc59cc6ffd8))
48
+
1
49
  ## [22.0.15](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/compare/v22.0.14...v22.0.15) (2023-06-19)
2
50
 
3
51
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-core-theme",
3
- "version": "22.0.15",
3
+ "version": "23.0.0",
4
4
  "description": "Gatsby Theme NPM Package",
5
5
  "main": "index.js",
6
6
  "GATSBY_RECAPTCHA_SITEKEY": "6LfoyvMUAAAAAO4nl_MQnqHb4XdHxEiu5cXgIqeB",
@@ -11,7 +11,7 @@ import { FaTwitter } from '@react-icons/all-files/fa/FaTwitter';
11
11
  import Author from '.';
12
12
 
13
13
  export default {
14
- title: 'Gatsby-Theme/Atoms/Author Byline',
14
+ title: 'Theme/Atoms/Author Byline',
15
15
  component: Author,
16
16
  argTypes: {
17
17
  name: {
@@ -15,7 +15,7 @@ import checkCircle from '../../../../../storybook-images/checkCircle.svg';
15
15
  import AuthorBox from '.';
16
16
 
17
17
  export default {
18
- title: 'Gatsby-Theme/Atoms/Author Box',
18
+ title: 'Theme/Atoms/Author Box',
19
19
  component: AuthorBox,
20
20
  argTypes: {
21
21
  author: {
@@ -11,7 +11,7 @@ import Bonus from '.';
11
11
  import { getToplistItem } from '~tests/factories/modules/toplist.factory';
12
12
 
13
13
  export default {
14
- title: 'Gatsby-Theme/Atoms/Bonus',
14
+ title: 'Theme/Atoms/Bonus',
15
15
  component: Bonus,
16
16
  argTypes: {
17
17
  item: {
@@ -11,7 +11,7 @@ import Breadcrumbs from '.';
11
11
  import getPageData from '~tests/factories/pages/default.factory';
12
12
 
13
13
  export default {
14
- title: 'Gatsby-Theme/Atoms/Breadcrumbs',
14
+ title: 'Theme/Atoms/Breadcrumbs',
15
15
  component: Breadcrumbs,
16
16
  argTypes: {
17
17
  page: {
@@ -10,7 +10,7 @@ import {
10
10
  import Button from '.';
11
11
 
12
12
  export default {
13
- title: 'Gatsby-Theme/Atoms/Button',
13
+ title: 'Theme/Atoms/Button',
14
14
  component: Button,
15
15
  argTypes: {
16
16
  to: {
@@ -10,7 +10,7 @@ import {
10
10
  import Collapse from '.';
11
11
 
12
12
  export default {
13
- title: 'Gatsby-Theme/Atoms/Collapse',
13
+ title: 'Theme/Atoms/Collapse',
14
14
  component: Collapse,
15
15
  argTypes: {
16
16
  buttonText: {
@@ -13,7 +13,7 @@ import content_3 from '../../../../static/images/content-3.png';
13
13
  import ContentBox from '.';
14
14
 
15
15
  export default {
16
- title: 'Gatsby-Theme/Atoms/Content Box',
16
+ title: 'Theme/Atoms/Content Box',
17
17
  component: ContentBox,
18
18
  argTypes: {
19
19
  data: {
@@ -10,7 +10,7 @@ import {
10
10
  import CustomSelect from '.';
11
11
 
12
12
  export default {
13
- title: 'Gatsby-Theme/Atoms/Custom Select',
13
+ title: 'Theme/Atoms/Custom Select',
14
14
  component: CustomSelect,
15
15
  argTypes: {
16
16
  items: {
@@ -11,7 +11,7 @@ import {
11
11
  import Faq from '.';
12
12
 
13
13
  export default {
14
- title: 'Gatsby-Theme/Atoms/Faq',
14
+ title: 'Theme/Atoms/Faq',
15
15
  component: Faq,
16
16
  argTypes: {
17
17
  module: {
@@ -11,7 +11,7 @@ import {
11
11
  import Iframe from '.';
12
12
 
13
13
  export default {
14
- title: 'Gatsby-Theme/Atoms/Iframe',
14
+ title: 'Theme/Atoms/Iframe',
15
15
  component: Iframe,
16
16
  argTypes: {
17
17
  src: {
@@ -11,7 +11,7 @@ import {
11
11
  import Image from '.';
12
12
 
13
13
  export default {
14
- title: 'Gatsby-Theme/Atoms/Image',
14
+ title: 'Theme/Atoms/Image',
15
15
  component: Image,
16
16
  argTypes: {
17
17
  module: {
@@ -11,7 +11,7 @@ import InfoGrid from '.';
11
11
  import getInfoGrids from '~tests/factories/modules/info-grid';
12
12
 
13
13
  export default {
14
- title: 'Gatsby-Theme/Atoms/Info Grid',
14
+ title: 'Theme/Atoms/Info Grid',
15
15
  component: InfoGrid,
16
16
  argTypes: {
17
17
  data: {
@@ -10,7 +10,7 @@ import {
10
10
  import Label from '.';
11
11
 
12
12
  export default {
13
- title: 'Gatsby-Theme/Atoms/Label',
13
+ title: 'Theme/Atoms/Label',
14
14
  component: Label,
15
15
  argTypes: {
16
16
  title: {
@@ -1,110 +1,107 @@
1
- /* eslint-disable jsx-a11y/mouse-events-have-key-events */
2
- /* eslint-disable react/jsx-no-bind */
3
- /* eslint-disable no-restricted-syntax */
4
1
  /* eslint-disable no-unused-expressions */
5
- /* eslint-disable arrow-body-style */
2
+ /* eslint-disable no-restricted-syntax */
6
3
  import React, { useRef } from 'react';
7
4
  import PropTypes from 'prop-types';
8
5
  import keygen from '~helpers/keygen';
9
6
  import Item from './item';
10
7
  import styles from './items.module.scss';
11
-
12
- const addPositionClass = ({ target }) => {
13
- const children = target?.parentNode?.parentNode?.children || [];
14
- for (const element of children) {
15
- if (element?.tagName === 'UL' && element?.className === styles.subMenuList) {
16
- const { left, width } = element.getBoundingClientRect();
17
- left + width > document.body.clientWidth &&
18
- element.classList.add(styles.staticLeft, styles.hoverLeft);
19
- break;
20
- }
21
- }
22
- };
8
+ import { getPositionClass, itemHasChildren } from '~helpers/menu';
23
9
 
24
10
  // Test included with menu molecule test
25
11
  const Items = ({
26
12
  item,
27
13
  menuListRef,
28
- options = {
29
- mobile: {
30
- canOpenAllSubMenus: false,
31
- subMenuDropDownButton: true,
32
- },
33
- },
34
14
  gtmClass = '',
15
+ level = 1,
16
+ dropdownButtonWidth = 64,
17
+ canOpenAllSubMenus = true,
35
18
  }) => {
36
19
  let link;
37
20
  let menu;
38
21
 
39
- const subMenuList = useRef(null);
22
+ const parentMenuRef = useRef(null);
23
+ const subMenuListRef = useRef(null);
40
24
 
41
- function showSubMenu(itemStyles) {
42
- if (!options.mobile.canOpenAllSubMenus) {
43
- const showingSubMenu = menuListRef.current.querySelector(`.${styles.show || ''}`);
25
+ const closeOtherMenus = (target) => {
26
+ const parentsWithOpenSubMenu = target.parentNode.getElementsByClassName(styles.showSubMenu)[0];
27
+ const openSubmenus = parentsWithOpenSubMenu?.getElementsByClassName(styles.show)[0];
44
28
 
45
- if (showingSubMenu && showingSubMenu !== subMenuList.current) {
46
- showingSubMenu.classList.toggle(styles.show);
29
+ if (parentsWithOpenSubMenu && parentsWithOpenSubMenu !== target) {
30
+ // close other opened levels except the target
31
+ parentsWithOpenSubMenu && parentsWithOpenSubMenu.classList.remove(styles.showSubMenu);
32
+ openSubmenus && openSubmenus.classList.remove(styles.show);
47
33
 
48
- if (itemStyles !== null) {
49
- if (options.mobile.subMenuDropDownButton) {
50
- showingSubMenu.parentNode.querySelector('button').classList.toggle(itemStyles.active);
51
- }
52
- }
53
- }
34
+ // if other levels have open submenus, close them too
35
+ openSubmenus
36
+ .getElementsByClassName(styles.showSubMenu)[0]
37
+ ?.classList.remove(styles.showSubMenu);
38
+ openSubmenus.getElementsByClassName(styles.show)[0]?.classList.remove(styles.show);
54
39
  }
40
+ };
55
41
 
56
- if (subMenuList.current) {
57
- subMenuList.current.classList.toggle(styles.show);
42
+ const onClick = (e) => {
43
+ const { target } = e;
44
+ const { width } = target.getBoundingClientRect();
45
+
46
+ // check if clicked within the arrow area which has a padding of 4.8rem on the li tag
47
+ if (e.nativeEvent.layerX > width - dropdownButtonWidth) {
48
+ // check if multiple submenus can be opened at same time, if not close them
49
+ if (!canOpenAllSubMenus) {
50
+ closeOtherMenus(target);
51
+ }
52
+
53
+ // toggle the clicked menu item
54
+ target.classList.toggle(styles.showSubMenu);
55
+ target.getElementsByTagName('UL')[0]?.classList.toggle(styles.show);
58
56
  }
59
- }
57
+ };
60
58
 
61
59
  if (item.children) {
62
- link = (
63
- <Item
64
- hasChildren
65
- item={item}
66
- showSubMenuHandler={showSubMenu}
67
- gtmClass={gtmClass}
68
- options={{
69
- mobile: {
70
- subMenuDropDownButton: options.mobile.subMenuDropDownButton,
71
- },
72
- }}
73
- />
74
- );
60
+ link = <Item item={item} gtmClass={gtmClass} />;
75
61
  menu = (
76
- <ul ref={subMenuList} className={styles.subMenuList || ''}>
77
- {item.children.map((child) => {
78
- return (
79
- <Items
80
- key={keygen()}
81
- item={child}
82
- menuListRef={menuListRef}
83
- gtmClass={gtmClass}
84
- options={{
85
- mobile: {
86
- canOpenAllSubMenus: options.mobile.canOpenAllSubMenus,
87
- subMenuDropDownButton: options.mobile.subMenuDropDownButton,
88
- },
89
- }}
90
- />
91
- );
92
- })}
62
+ <ul
63
+ ref={subMenuListRef}
64
+ className={`${styles.subMenuList || ''} ${
65
+ itemHasChildren(item) ? styles.hasChildWithSubmenu || '' : ''
66
+ }`}
67
+ >
68
+ {item.children.map((child) => (
69
+ <Items
70
+ key={keygen()}
71
+ item={child}
72
+ menuListRef={menuListRef}
73
+ gtmClass={gtmClass}
74
+ canOpenAllSubMenus={canOpenAllSubMenus}
75
+ level={level + 1}
76
+ />
77
+ ))}
93
78
  </ul>
94
79
  );
95
80
  } else {
96
- link = (
97
- <Item
98
- hasChildren={false}
99
- item={item}
100
- gtmClass={gtmClass}
101
- options={{ mobile: { subMenuDropDownButton: options.mobile.subMenuDropDownButton } }}
102
- />
103
- );
81
+ link = <Item item={item} gtmClass={gtmClass} />;
104
82
  }
105
83
 
106
84
  return (
107
- <li className={styles.menuItem || ''} onMouseOver={addPositionClass}>
85
+ <li
86
+ ref={parentMenuRef}
87
+ className={`${styles.menuItem || ''} ${styles[`level${level.toString()}`] || ''}
88
+ ${item.children !== undefined ? styles.hasChildren || '' : ''}
89
+ `}
90
+ onFocus={(e) => getPositionClass(e.target, styles)}
91
+ onMouseOver={(e) => getPositionClass(e.target, styles)}
92
+ role="menuitem"
93
+ tabIndex="0"
94
+ onKeyDown={(e) => {
95
+ if (e.defaultPrevented) return;
96
+ e.preventDefault();
97
+ onClick(e);
98
+ }}
99
+ onClick={(e) => {
100
+ if (e.defaultPrevented) return;
101
+ e.preventDefault();
102
+ onClick(e);
103
+ }}
104
+ >
108
105
  {link}
109
106
  {menu}
110
107
  </li>
@@ -123,13 +120,10 @@ Items.propTypes = {
123
120
  ),
124
121
  }).isRequired,
125
122
  menuListRef: PropTypes.oneOfType([PropTypes.element, PropTypes.any]),
126
- options: PropTypes.shape({
127
- mobile: PropTypes.shape({
128
- canOpenAllSubMenus: PropTypes.bool,
129
- subMenuDropDownButton: PropTypes.bool,
130
- }),
131
- }),
132
123
  gtmClass: PropTypes.string,
124
+ level: PropTypes.number,
125
+ dropdownButtonWidth: PropTypes.number,
126
+ canOpenAllSubMenus: PropTypes.bool,
133
127
  };
134
128
 
135
129
  export default Items;
@@ -1,64 +1,26 @@
1
1
  /* eslint-disable no-nested-ternary */
2
- import React, { useState, useEffect, useContext } from 'react';
2
+ import React, { useContext } from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import Link from '~hooks/link';
5
- import ConditionalWrapper from '~atoms/conditional-wrapper';
6
5
  import { imagePrettyUrl } from '~helpers/getters';
7
6
  import { NavigationContext } from '~organisms/navigation/navigationContext';
8
7
 
9
8
  import styles from './item.module.scss';
10
9
 
11
- export default function Item({
12
- item,
13
- hasChildren,
14
- showSubMenuHandler,
15
- options = {
16
- mobile: {
17
- subMenuDropDownButton: true,
18
- },
19
- },
20
- gtmClass = '',
21
- }) {
22
- const [active, setActive] = useState('');
23
- const [opened, setOpened] = useState(false);
24
-
10
+ export default function Item({ item, gtmClass = '' }) {
25
11
  const { setShowMenu } = useContext(NavigationContext);
26
12
 
27
- useEffect(() => {
28
- const url = typeof window !== 'undefined' ? new URL(window.location.href) : '';
29
- setActive(
30
- url.pathname === item.value || url.pathname.substr(1) === item.value ? styles.active : ''
31
- );
32
- }, [active, item]);
33
-
34
13
  const handleClose = () => {
35
14
  setShowMenu(false);
36
15
  };
37
16
 
38
- const toggleDropDown = (e) => {
39
- e.target.classList.toggle(styles.active);
40
- setOpened(e.target.classList.contains(styles.active));
41
- };
42
-
43
17
  const ItemImage = () =>
44
18
  item.image ? (
45
- <img width="20" height="20" src={imagePrettyUrl(item.image)} alt={item.title} />
19
+ <img width="32" height="32" src={imagePrettyUrl(item.image, 32, 32)} alt={item.title} />
46
20
  ) : null;
47
21
 
48
22
  return (
49
- <ConditionalWrapper
50
- condition={hasChildren}
51
- wrapper={(items) => (
52
- <div
53
- className={`${styles.itemWrapper || ''} ${
54
- item.image ? styles?.itemWrapperIcon || '' : ''
55
- }`}
56
- onTouchStart={!options.mobile.subMenuDropDownButton ? showSubMenuHandler : null}
57
- >
58
- {items}
59
- </div>
60
- )}
61
- >
23
+ <>
62
24
  {item.value?.includes('http') || item.value?.includes('www') ? (
63
25
  <a
64
26
  aria-label={`${item?.title} link`}
@@ -66,61 +28,31 @@ export default function Item({
66
28
  title={item.title}
67
29
  rel={`noreferrer ${item.nofollow && 'nofollow'}`}
68
30
  target="_blank"
69
- className={`${gtmClass || ''} ${styles.item || ''} ${
70
- opened ? styles.openedLink || '' : ''
71
- } ${active || ''} ${
72
- !options?.mobile?.subMenuDropDownButton
73
- ? hasChildren || ''
74
- ? styles.inactiveLink
75
- : ''
76
- : ''
77
- } ${hasChildren ? styles.hasChildren || '' : ''} ${
78
- !options?.mobile?.subMenuDropDownButton ? styles.noDropDownButton || '' : ''
79
- }`}
31
+ className={`${styles.item || ''} ${gtmClass || ''}`}
32
+ onClick={() => handleClose()}
80
33
  >
81
34
  <ItemImage />
82
35
  {item.title}
83
36
  </a>
84
37
  ) : item.value !== null ? (
85
38
  <Link
86
- className={`${gtmClass || ''} ${styles.item || ''} ${
87
- opened && (styles.openedLink || '')
88
- } ${active || ''} ${
89
- (!options?.mobile?.subMenuDropDownButton && hasChildren) || ''
90
- ? styles.inactiveLink || ''
91
- : ''
92
- } ${hasChildren ? styles.hasChildren || '' : ''} ${
93
- !options.mobile.subMenuDropDownButton ? styles.noDropDownButton || '' : ''
94
- }`}
95
39
  disabled={item.value === null}
96
40
  to={item.value}
97
41
  title={item.title}
98
42
  rel={item.nofollow && 'nofollow'}
99
43
  aria-label={`${item?.title} link`}
100
- onClick={handleClose}
44
+ className={`${styles.item || ''} ${gtmClass || ''}`}
45
+ onClick={() => handleClose()}
101
46
  >
102
47
  <ItemImage />
103
48
  {item.title}
104
49
  </Link>
105
50
  ) : (
106
- <div className={`${styles.item || ''} ${opened && (styles.openedLink || '')}`}>
51
+ <span className={`${styles.item || ''} ${gtmClass || ''} ${styles.inactiveLink}`}>
107
52
  {item.title}
108
- </div>
109
- )}
110
- {options.mobile.subMenuDropDownButton && hasChildren && (
111
- <button
112
- aria-label={`${item?.title} Dropdown`}
113
- type="button"
114
- className={`${gtmClass || ''} btn-cta`}
115
- onClick={(e) => {
116
- showSubMenuHandler(styles);
117
- toggleDropDown(e);
118
- }}
119
- >
120
- {' '}
121
- </button>
53
+ </span>
122
54
  )}
123
- </ConditionalWrapper>
55
+ </>
124
56
  );
125
57
  }
126
58
 
@@ -130,19 +62,6 @@ Item.propTypes = {
130
62
  value: PropTypes.string,
131
63
  nofollow: PropTypes.bool,
132
64
  image: PropTypes.string,
133
- children: PropTypes.arrayOf(
134
- PropTypes.shape({
135
- title: PropTypes.string,
136
- value: PropTypes.string,
137
- })
138
- ),
139
65
  }).isRequired,
140
- hasChildren: PropTypes.bool,
141
- showSubMenuHandler: PropTypes.func,
142
- options: PropTypes.shape({
143
- mobile: PropTypes.shape({
144
- subMenuDropDownButton: PropTypes.bool,
145
- }),
146
- }),
147
66
  gtmClass: PropTypes.string,
148
67
  };