@riosst100/pwa-marketplace 1.2.3 → 1.2.5
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/package.json +1 -1
- package/src/componentOverrideMapping.js +2 -1
- package/src/components/Filter/index.js +7 -7
- package/src/components/OperatingHours/index.js +1 -0
- package/src/components/OperatingHours/operatingHours.js +32 -0
- package/src/components/Pagination/index.js +26 -17
- package/src/components/Search/index.js +1 -1
- package/src/components/Seller/index.js +1 -0
- package/src/components/Seller/seller.js +250 -0
- package/src/components/Seller/sellerAddressCard.js +48 -0
- package/src/components/SellerDetail/index.js +1 -0
- package/src/components/SellerDetail/sellerDetail.js +158 -0
- package/src/components/SellerInformation/sellerInformation.js +54 -44
- package/src/components/SellerLocation/sellerLocation.js +6 -2
- package/src/components/SellerLocation/sellerLocationItem.js +6 -8
- package/src/components/SellerPage/sellerPage.js +2 -112
- package/src/components/SellerProducts/sellerProducts.js +33 -12
- package/src/components/SellerReview/sellerReview.js +29 -29
- package/src/components/SellerReviewItem/sellerReviewItem.js +8 -8
- package/src/components/SortBy/index.js +13 -5
- package/src/components/commons/Slider/index.js +2 -2
- package/src/components/commons/Tabs/index.js +11 -9
- package/src/overwrites/venia-ui/lib/components/Header/header.js +46 -34
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/MegaMenu.spec.js +91 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/MegaMenuItem.spec.js +123 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/Submenu.spec.js +61 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/SubmenuColumn.spec.js +50 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/MegaMenu.spec.js.snap +114 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/MegaMenuItem.spec.js.snap +71 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/Submenu.spec.js.snap +59 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/SubmenuColumn.spec.js.snap +34 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/index.js +1 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenu.js +90 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenu.module.css +12 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenuItem.js +156 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenuItem.module.css +31 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenu.js +89 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenu.module.css +43 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenuColumn.js +99 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenuColumn.module.css +28 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__stories__/searchBar.js +11 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/searchField.spec.js.snap +72 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedCategories.spec.js.snap +30 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedProduct.spec.js.snap +69 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedProducts.spec.js.snap +7 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestions.spec.js.snap +12 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/autocomplete.spec.js +52 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/searchBar.spec.js +82 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/searchField.spec.js +87 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedCategories.spec.js +45 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedProduct.spec.js +43 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedProducts.spec.js +45 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestions.spec.js +110 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/autocomplete.js +172 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/autocomplete.module.css +62 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/index.js +1 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/searchBar.js +74 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/searchBar.module.css +50 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/searchField.js +40 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategories.js +48 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategories.module.css +13 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategory.js +49 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategory.module.css +0 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProduct.js +97 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProduct.module.css +24 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProducts.js +43 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProducts.module.css +13 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestions.js +75 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestions.module.css +6 -0
- package/src/talons/Seller/seller.gql.js +204 -0
- package/src/talons/Seller/useSeller.js +71 -0
- package/src/talons/SellerProducts/useSellerProducts.js +129 -0
- package/src/theme/vars.js +7 -0
- package/src/util/mapSeller.js +7 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createTestInstance } from '@magento/peregrine';
|
|
3
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
+
|
|
5
|
+
import Submenu from '../submenu';
|
|
6
|
+
|
|
7
|
+
jest.mock('../../../classify');
|
|
8
|
+
jest.mock('../submenuColumn', () => props => <mock-SubmenuColumn {...props} />);
|
|
9
|
+
jest.mock('react', () => {
|
|
10
|
+
const React = jest.requireActual('react');
|
|
11
|
+
const callbackSpy = jest.spyOn(React, 'useCallback');
|
|
12
|
+
|
|
13
|
+
return Object.assign(React, {
|
|
14
|
+
callbackSpy: callbackSpy
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const handleCloseSubMenu = jest.fn().mockName('handleCloseSubMenu');
|
|
19
|
+
|
|
20
|
+
describe('Submenu renders correctly', () => {
|
|
21
|
+
const props = {
|
|
22
|
+
items: [
|
|
23
|
+
{
|
|
24
|
+
id: 1,
|
|
25
|
+
name: 'Bottoms',
|
|
26
|
+
url_path: 'bottoms',
|
|
27
|
+
children: [
|
|
28
|
+
{
|
|
29
|
+
id: 3,
|
|
30
|
+
name: 'Pants',
|
|
31
|
+
url_path: 'pants',
|
|
32
|
+
isActive: false,
|
|
33
|
+
children: []
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 2,
|
|
39
|
+
name: 'Tops',
|
|
40
|
+
url_path: 'tops',
|
|
41
|
+
isActive: false,
|
|
42
|
+
children: []
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
rootCategoryName: 'Clothing',
|
|
46
|
+
firstLevelCategoryName: 'Women',
|
|
47
|
+
categoryUrlSuffix: '.html',
|
|
48
|
+
handleCloseSubMenu,
|
|
49
|
+
isFocused: false,
|
|
50
|
+
subMenuState: false
|
|
51
|
+
};
|
|
52
|
+
test('it renders correctly', () => {
|
|
53
|
+
const instance = createTestInstance(
|
|
54
|
+
<MemoryRouter>
|
|
55
|
+
<Submenu {...props} />
|
|
56
|
+
</MemoryRouter>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(instance.toJSON()).toMatchSnapshot();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createTestInstance } from '@magento/peregrine';
|
|
3
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
+
|
|
5
|
+
import SubmenuColumn from '../submenuColumn';
|
|
6
|
+
|
|
7
|
+
jest.mock('../../../classify');
|
|
8
|
+
|
|
9
|
+
describe('Submenu column renders correctly', () => {
|
|
10
|
+
const props = {
|
|
11
|
+
category: {
|
|
12
|
+
id: 1,
|
|
13
|
+
name: 'Pants',
|
|
14
|
+
url_path: 'pants',
|
|
15
|
+
children: [
|
|
16
|
+
{
|
|
17
|
+
id: 2,
|
|
18
|
+
name: 'Jeans',
|
|
19
|
+
url_path: 'jeans',
|
|
20
|
+
isActive: true,
|
|
21
|
+
children: []
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
categoryUrlSuffix: '.html'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
test('it renders correctly', () => {
|
|
29
|
+
const instance = createTestInstance(
|
|
30
|
+
<MemoryRouter>
|
|
31
|
+
<SubmenuColumn {...props} />
|
|
32
|
+
</MemoryRouter>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(instance.toJSON()).toMatchSnapshot();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('it renders active state', () => {
|
|
39
|
+
const instance = createTestInstance(
|
|
40
|
+
<MemoryRouter>
|
|
41
|
+
<SubmenuColumn {...props} />
|
|
42
|
+
</MemoryRouter>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const activeLink = instance.root.findByProps({
|
|
46
|
+
className: 'linkActive'
|
|
47
|
+
});
|
|
48
|
+
expect(activeLink.props.children).toEqual('Jeans');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`#MegaMenu renders empty div if not in viewport 1`] = `
|
|
4
|
+
<nav
|
|
5
|
+
className="megaMenu"
|
|
6
|
+
role="navigation"
|
|
7
|
+
/>
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
exports[`#MegaMenu renders menu if in viewport 1`] = `
|
|
11
|
+
<nav
|
|
12
|
+
className="megaMenu"
|
|
13
|
+
role="navigation"
|
|
14
|
+
>
|
|
15
|
+
<div
|
|
16
|
+
className="megaMenuItem"
|
|
17
|
+
onFocus={[Function]}
|
|
18
|
+
onMouseEnter={[Function]}
|
|
19
|
+
onMouseLeave={[Function]}
|
|
20
|
+
onTouchStart={[Function]}
|
|
21
|
+
>
|
|
22
|
+
<a
|
|
23
|
+
aria-label="Category: Women. 1 sub-categories"
|
|
24
|
+
className="megaMenuLink"
|
|
25
|
+
href="/women.html"
|
|
26
|
+
onClick={[Function]}
|
|
27
|
+
onKeyDown={[Function]}
|
|
28
|
+
>
|
|
29
|
+
Women
|
|
30
|
+
<span
|
|
31
|
+
className="arrowDown"
|
|
32
|
+
>
|
|
33
|
+
<svg
|
|
34
|
+
className="icon"
|
|
35
|
+
fill="none"
|
|
36
|
+
height={16}
|
|
37
|
+
stroke="currentColor"
|
|
38
|
+
strokeLinecap="round"
|
|
39
|
+
strokeLinejoin="round"
|
|
40
|
+
strokeWidth="2"
|
|
41
|
+
viewBox="0 0 24 24"
|
|
42
|
+
width={16}
|
|
43
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
44
|
+
>
|
|
45
|
+
<polyline
|
|
46
|
+
points="6 9 12 15 18 9"
|
|
47
|
+
/>
|
|
48
|
+
</svg>
|
|
49
|
+
</span>
|
|
50
|
+
</a>
|
|
51
|
+
<div
|
|
52
|
+
className="submenu_inactive"
|
|
53
|
+
>
|
|
54
|
+
<div
|
|
55
|
+
className="submenuItems"
|
|
56
|
+
style={
|
|
57
|
+
Object {
|
|
58
|
+
"minWidth": 20,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
>
|
|
62
|
+
<div
|
|
63
|
+
className="submenuColumn"
|
|
64
|
+
>
|
|
65
|
+
<a
|
|
66
|
+
className="link"
|
|
67
|
+
href="/bottoms.html"
|
|
68
|
+
onClick={[Function]}
|
|
69
|
+
onKeyDown={[Function]}
|
|
70
|
+
>
|
|
71
|
+
<span
|
|
72
|
+
className="heading"
|
|
73
|
+
>
|
|
74
|
+
Bottoms
|
|
75
|
+
</span>
|
|
76
|
+
</a>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
<div
|
|
82
|
+
className="megaMenuItem"
|
|
83
|
+
onFocus={[Function]}
|
|
84
|
+
onMouseEnter={[Function]}
|
|
85
|
+
onMouseLeave={[Function]}
|
|
86
|
+
onTouchStart={[Function]}
|
|
87
|
+
>
|
|
88
|
+
<a
|
|
89
|
+
className="megaMenuLink"
|
|
90
|
+
href="/men.html"
|
|
91
|
+
onClick={[Function]}
|
|
92
|
+
onKeyDown={[Function]}
|
|
93
|
+
>
|
|
94
|
+
Men
|
|
95
|
+
</a>
|
|
96
|
+
</div>
|
|
97
|
+
<div
|
|
98
|
+
className="megaMenuItem"
|
|
99
|
+
onFocus={[Function]}
|
|
100
|
+
onMouseEnter={[Function]}
|
|
101
|
+
onMouseLeave={[Function]}
|
|
102
|
+
onTouchStart={[Function]}
|
|
103
|
+
>
|
|
104
|
+
<a
|
|
105
|
+
className="megaMenuLink"
|
|
106
|
+
href="/gear.html"
|
|
107
|
+
onClick={[Function]}
|
|
108
|
+
onKeyDown={[Function]}
|
|
109
|
+
>
|
|
110
|
+
Gear
|
|
111
|
+
</a>
|
|
112
|
+
</div>
|
|
113
|
+
</nav>
|
|
114
|
+
`;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Mega menu item renders correctly it does not render submenu when item does not have children 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
className="megaMenuItem"
|
|
6
|
+
onFocus={[Function]}
|
|
7
|
+
onMouseEnter={[Function]}
|
|
8
|
+
onMouseLeave={[Function]}
|
|
9
|
+
onTouchStart={[Function]}
|
|
10
|
+
>
|
|
11
|
+
<mock-Submenu
|
|
12
|
+
categoryUrlSuffix=".html"
|
|
13
|
+
handleCloseSubMenu={[MockFunction]}
|
|
14
|
+
isFocused={false}
|
|
15
|
+
items={
|
|
16
|
+
Array [
|
|
17
|
+
Object {
|
|
18
|
+
"children": Array [],
|
|
19
|
+
"id": 2,
|
|
20
|
+
"name": "Bottoms",
|
|
21
|
+
"url_path": "bottoms",
|
|
22
|
+
},
|
|
23
|
+
Object {
|
|
24
|
+
"children": Array [],
|
|
25
|
+
"id": 3,
|
|
26
|
+
"isActive": false,
|
|
27
|
+
"name": "Tops",
|
|
28
|
+
"url_path": "tops",
|
|
29
|
+
},
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
mainNavWidth={200}
|
|
33
|
+
subMenuState="test"
|
|
34
|
+
/>
|
|
35
|
+
</div>
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
exports[`Mega menu item renders correctly it renders correctly 1`] = `
|
|
39
|
+
<div
|
|
40
|
+
className="megaMenuItem"
|
|
41
|
+
onFocus={[Function]}
|
|
42
|
+
onMouseEnter={[Function]}
|
|
43
|
+
onMouseLeave={[Function]}
|
|
44
|
+
onTouchStart={[Function]}
|
|
45
|
+
>
|
|
46
|
+
<mock-Submenu
|
|
47
|
+
categoryUrlSuffix=".html"
|
|
48
|
+
handleCloseSubMenu={[MockFunction]}
|
|
49
|
+
isFocused={false}
|
|
50
|
+
items={
|
|
51
|
+
Array [
|
|
52
|
+
Object {
|
|
53
|
+
"children": Array [],
|
|
54
|
+
"id": 2,
|
|
55
|
+
"name": "Bottoms",
|
|
56
|
+
"url_path": "bottoms",
|
|
57
|
+
},
|
|
58
|
+
Object {
|
|
59
|
+
"children": Array [],
|
|
60
|
+
"id": 3,
|
|
61
|
+
"isActive": false,
|
|
62
|
+
"name": "Tops",
|
|
63
|
+
"url_path": "tops",
|
|
64
|
+
},
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
mainNavWidth={200}
|
|
68
|
+
subMenuState="test"
|
|
69
|
+
/>
|
|
70
|
+
</div>
|
|
71
|
+
`;
|
package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/Submenu.spec.js.snap
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Submenu renders correctly it renders correctly 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
className="submenu_inactive"
|
|
6
|
+
>
|
|
7
|
+
<div
|
|
8
|
+
className="submenuItems"
|
|
9
|
+
style={
|
|
10
|
+
Object {
|
|
11
|
+
"minWidth": NaN,
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
>
|
|
15
|
+
<mock-SubmenuColumn
|
|
16
|
+
category={
|
|
17
|
+
Object {
|
|
18
|
+
"children": Array [
|
|
19
|
+
Object {
|
|
20
|
+
"children": Array [],
|
|
21
|
+
"id": 3,
|
|
22
|
+
"isActive": false,
|
|
23
|
+
"name": "Pants",
|
|
24
|
+
"url_path": "pants",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
"id": 1,
|
|
28
|
+
"name": "Bottoms",
|
|
29
|
+
"url_path": "bottoms",
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
categoryUrlSuffix=".html"
|
|
33
|
+
handleCloseSubMenu={[MockFunction handleCloseSubMenu]}
|
|
34
|
+
index={0}
|
|
35
|
+
keyboardProps={Object {}}
|
|
36
|
+
/>
|
|
37
|
+
<mock-SubmenuColumn
|
|
38
|
+
category={
|
|
39
|
+
Object {
|
|
40
|
+
"children": Array [],
|
|
41
|
+
"id": 2,
|
|
42
|
+
"isActive": false,
|
|
43
|
+
"name": "Tops",
|
|
44
|
+
"url_path": "tops",
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
categoryUrlSuffix=".html"
|
|
48
|
+
handleCloseSubMenu={[MockFunction handleCloseSubMenu]}
|
|
49
|
+
index={1}
|
|
50
|
+
keyboardProps={
|
|
51
|
+
Object {
|
|
52
|
+
"onKeyDown": [Function],
|
|
53
|
+
"onKeyUp": undefined,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
`;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Submenu column renders correctly it renders correctly 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
className="submenuColumn"
|
|
6
|
+
>
|
|
7
|
+
<a
|
|
8
|
+
className="link"
|
|
9
|
+
href="/pants.html"
|
|
10
|
+
onClick={[Function]}
|
|
11
|
+
>
|
|
12
|
+
<span
|
|
13
|
+
className="heading"
|
|
14
|
+
>
|
|
15
|
+
Pants
|
|
16
|
+
</span>
|
|
17
|
+
</a>
|
|
18
|
+
<ul
|
|
19
|
+
className="submenuChild"
|
|
20
|
+
>
|
|
21
|
+
<li
|
|
22
|
+
className="submenuChildItem"
|
|
23
|
+
>
|
|
24
|
+
<a
|
|
25
|
+
className="linkActive"
|
|
26
|
+
href="/jeans.html"
|
|
27
|
+
onClick={[Function]}
|
|
28
|
+
>
|
|
29
|
+
Jeans
|
|
30
|
+
</a>
|
|
31
|
+
</li>
|
|
32
|
+
</ul>
|
|
33
|
+
</div>
|
|
34
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './megaMenu';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useIsInViewport } from '@magento/peregrine/lib/hooks/useIsInViewport';
|
|
4
|
+
import { useMegaMenu } from '@magento/peregrine/lib/talons/MegaMenu/useMegaMenu';
|
|
5
|
+
import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
6
|
+
|
|
7
|
+
import MegaMenuItem from './megaMenuItem';
|
|
8
|
+
import defaultClasses from './megaMenu.module.css';
|
|
9
|
+
import cn from 'classnames';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The MegaMenu component displays menu with categories on desktop devices
|
|
13
|
+
*/
|
|
14
|
+
const MegaMenu = (props) => {
|
|
15
|
+
const { rootClassName, megaMenuItemClassname, titleClassName } = props
|
|
16
|
+
const mainNavRef = useRef(null);
|
|
17
|
+
|
|
18
|
+
const classes = useStyle(defaultClasses, props.classes);
|
|
19
|
+
// const rootClass = cn(classes.megaMenu, rootClassName);
|
|
20
|
+
const rootClass = cn('xs_hidden xl_flex flex-grow justify-self-center', rootClassName);
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
megaMenuData,
|
|
24
|
+
activeCategoryId,
|
|
25
|
+
subMenuState,
|
|
26
|
+
disableFocus,
|
|
27
|
+
handleSubMenuFocus,
|
|
28
|
+
categoryUrlSuffix,
|
|
29
|
+
handleNavigate,
|
|
30
|
+
handleClickOutside
|
|
31
|
+
} = useMegaMenu({ mainNavRef });
|
|
32
|
+
|
|
33
|
+
const [mainNavWidth, setMainNavWidth] = useState(0);
|
|
34
|
+
const shouldRenderItems = useIsInViewport({
|
|
35
|
+
elementRef: mainNavRef
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const handleResize = () => {
|
|
40
|
+
const navWidth = mainNavRef.current
|
|
41
|
+
? mainNavRef.current.offsetWidth
|
|
42
|
+
: null;
|
|
43
|
+
|
|
44
|
+
setMainNavWidth(navWidth);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
window.addEventListener('resize', handleResize);
|
|
48
|
+
|
|
49
|
+
handleResize();
|
|
50
|
+
|
|
51
|
+
return () => {
|
|
52
|
+
window.removeEventListener('resize', handleResize);
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const items = megaMenuData.children
|
|
57
|
+
? megaMenuData.children.map(category => {
|
|
58
|
+
return (
|
|
59
|
+
<MegaMenuItem
|
|
60
|
+
category={category}
|
|
61
|
+
activeCategoryId={activeCategoryId}
|
|
62
|
+
categoryUrlSuffix={categoryUrlSuffix}
|
|
63
|
+
mainNavWidth={mainNavWidth}
|
|
64
|
+
onNavigate={handleNavigate}
|
|
65
|
+
key={category.uid}
|
|
66
|
+
subMenuState={subMenuState}
|
|
67
|
+
disableFocus={disableFocus}
|
|
68
|
+
handleSubMenuFocus={handleSubMenuFocus}
|
|
69
|
+
handleClickOutside={handleClickOutside}
|
|
70
|
+
megaMenuItemClassname={megaMenuItemClassname}
|
|
71
|
+
titleClassName={titleClassName}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
})
|
|
75
|
+
: null;
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<nav
|
|
79
|
+
ref={mainNavRef}
|
|
80
|
+
className={rootClass}
|
|
81
|
+
data-cy="MegaMenu-megaMenu"
|
|
82
|
+
role="navigation"
|
|
83
|
+
onFocus={handleSubMenuFocus}
|
|
84
|
+
>
|
|
85
|
+
{shouldRenderItems ? items : null}
|
|
86
|
+
</nav>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default MegaMenu;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
.megaMenu {
|
|
2
|
+
composes: col-end-10 from global;
|
|
3
|
+
composes: col-start-3 from global;
|
|
4
|
+
composes: flex-grow from global;
|
|
5
|
+
composes: hidden from global;
|
|
6
|
+
composes: justify-self-center from global;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/* Large screen styles */
|
|
10
|
+
.megaMenu {
|
|
11
|
+
composes: lg_flex from global;
|
|
12
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { ChevronDown as ArrowDown } from 'react-feather';
|
|
3
|
+
import { Link } from 'react-router-dom';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
|
|
6
|
+
import resourceUrl from '@magento/peregrine/lib/util/makeUrl';
|
|
7
|
+
import { useMegaMenuItem } from '@magento/peregrine/lib/talons/MegaMenu/useMegaMenuItem';
|
|
8
|
+
|
|
9
|
+
import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
10
|
+
import defaultClasses from './megaMenuItem.module.css';
|
|
11
|
+
import Submenu from './submenu';
|
|
12
|
+
import { ArrowDown2 } from 'iconsax-react';
|
|
13
|
+
import { textPrimary } from '@riosst100/pwa-marketplace/src/theme/vars';
|
|
14
|
+
import cn from 'classnames';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The MegaMenuItem component displays mega menu item
|
|
18
|
+
*
|
|
19
|
+
* @param {MegaMenuCategory} props.category
|
|
20
|
+
* @param {String} props.activeCategoryId - uid of active category
|
|
21
|
+
* @param {int} props.mainNavWidth - width of the main nav. It's used for setting min-width of the submenu
|
|
22
|
+
* @param {function} props.onNavigate - function called when clicking on Link
|
|
23
|
+
*/
|
|
24
|
+
const MegaMenuItem = props => {
|
|
25
|
+
const {
|
|
26
|
+
activeCategoryId,
|
|
27
|
+
category,
|
|
28
|
+
mainNavWidth,
|
|
29
|
+
categoryUrlSuffix,
|
|
30
|
+
subMenuState,
|
|
31
|
+
disableFocus,
|
|
32
|
+
onNavigate,
|
|
33
|
+
handleSubMenuFocus,
|
|
34
|
+
handleClickOutside,
|
|
35
|
+
megaMenuItemClassname,
|
|
36
|
+
titleClassName,
|
|
37
|
+
} = props;
|
|
38
|
+
|
|
39
|
+
const classes = useStyle(defaultClasses, props.classes);
|
|
40
|
+
const categoryUrl = resourceUrl(
|
|
41
|
+
`/${category.url_path}${categoryUrlSuffix || ''}`
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const talonProps = useMegaMenuItem({
|
|
45
|
+
category,
|
|
46
|
+
activeCategoryId,
|
|
47
|
+
subMenuState,
|
|
48
|
+
disableFocus
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const {
|
|
52
|
+
isFocused,
|
|
53
|
+
isActive,
|
|
54
|
+
handleMenuItemFocus,
|
|
55
|
+
handleCloseSubMenu,
|
|
56
|
+
isMenuActive,
|
|
57
|
+
handleKeyDown
|
|
58
|
+
} = talonProps;
|
|
59
|
+
|
|
60
|
+
const itemClassName = isMenuActive
|
|
61
|
+
? classes.megaMenuItem_active
|
|
62
|
+
: classes.megaMenuItem;
|
|
63
|
+
|
|
64
|
+
const children = useMemo(() => {
|
|
65
|
+
return category.children.length ? (
|
|
66
|
+
<Submenu
|
|
67
|
+
isFocused={isFocused}
|
|
68
|
+
subMenuState={subMenuState}
|
|
69
|
+
items={category.children}
|
|
70
|
+
mainNavWidth={mainNavWidth}
|
|
71
|
+
handleCloseSubMenu={handleCloseSubMenu}
|
|
72
|
+
categoryUrlSuffix={categoryUrlSuffix}
|
|
73
|
+
onNavigate={onNavigate}
|
|
74
|
+
/>
|
|
75
|
+
) : null;
|
|
76
|
+
}, [
|
|
77
|
+
category,
|
|
78
|
+
isFocused,
|
|
79
|
+
mainNavWidth,
|
|
80
|
+
subMenuState,
|
|
81
|
+
handleCloseSubMenu,
|
|
82
|
+
categoryUrlSuffix,
|
|
83
|
+
onNavigate
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
const maybeDownArrowIcon = category.children.length ? (
|
|
87
|
+
<ArrowDown2 className='ml-2' size="16" color={textPrimary} variant="Outline" />
|
|
88
|
+
) : null;
|
|
89
|
+
|
|
90
|
+
const linkAttributes = category.children.length
|
|
91
|
+
? {
|
|
92
|
+
'aria-label': `Category: ${category.name}. ${category.children.length
|
|
93
|
+
} sub-categories`
|
|
94
|
+
}
|
|
95
|
+
: {};
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<div
|
|
99
|
+
className={cn(itemClassName, megaMenuItemClassname)}
|
|
100
|
+
data-cy="MegaMenu-MegaMenuItem-megaMenuItem"
|
|
101
|
+
onMouseEnter={() => {
|
|
102
|
+
handleSubMenuFocus();
|
|
103
|
+
handleMenuItemFocus();
|
|
104
|
+
}}
|
|
105
|
+
onFocus={() => {
|
|
106
|
+
handleSubMenuFocus();
|
|
107
|
+
handleMenuItemFocus();
|
|
108
|
+
}}
|
|
109
|
+
onTouchStart={() => {
|
|
110
|
+
handleSubMenuFocus();
|
|
111
|
+
handleMenuItemFocus();
|
|
112
|
+
}}
|
|
113
|
+
onMouseLeave={e => {
|
|
114
|
+
handleClickOutside(e);
|
|
115
|
+
handleCloseSubMenu();
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
<Link
|
|
119
|
+
{...linkAttributes}
|
|
120
|
+
onKeyDown={handleKeyDown}
|
|
121
|
+
className={cn(
|
|
122
|
+
isActive ? classes.megaMenuLinkActive : classes.megaMenuLink,
|
|
123
|
+
titleClassName
|
|
124
|
+
)}
|
|
125
|
+
data-cy="MegaMenu-MegaMenuItem-link"
|
|
126
|
+
to={categoryUrl}
|
|
127
|
+
onClick={onNavigate}
|
|
128
|
+
>
|
|
129
|
+
{category.name}
|
|
130
|
+
{maybeDownArrowIcon}
|
|
131
|
+
</Link>
|
|
132
|
+
{children}
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export default MegaMenuItem;
|
|
138
|
+
|
|
139
|
+
MegaMenuItem.propTypes = {
|
|
140
|
+
category: PropTypes.shape({
|
|
141
|
+
children: PropTypes.array,
|
|
142
|
+
uid: PropTypes.string.isRequired,
|
|
143
|
+
include_in_menu: PropTypes.number,
|
|
144
|
+
isActive: PropTypes.bool.isRequired,
|
|
145
|
+
name: PropTypes.string.isRequired,
|
|
146
|
+
path: PropTypes.array.isRequired,
|
|
147
|
+
position: PropTypes.number.isRequired,
|
|
148
|
+
url_path: PropTypes.string.isRequired
|
|
149
|
+
}).isRequired,
|
|
150
|
+
activeCategoryId: PropTypes.string,
|
|
151
|
+
mainNavWidth: PropTypes.number.isRequired,
|
|
152
|
+
categoryUrlSuffix: PropTypes.string,
|
|
153
|
+
onNavigate: PropTypes.func.isRequired,
|
|
154
|
+
handleSubMenuFocus: PropTypes.func.isRequired,
|
|
155
|
+
handleClickOutside: PropTypes.func.isRequired
|
|
156
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
.megaMenuItem {
|
|
2
|
+
/* composes: px-3 from global;
|
|
3
|
+
composes: py-0 from global; */
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.megaMenuLink {
|
|
7
|
+
composes: items-center from global;
|
|
8
|
+
composes: inline-flex from global;
|
|
9
|
+
/* min-height: 5rem; */
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.megaMenuLinkActive {
|
|
13
|
+
composes: megaMenuLink;
|
|
14
|
+
composes: underline from global;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.megaMenuItem_active {
|
|
18
|
+
composes: megaMenuItem;
|
|
19
|
+
composes: flex from global;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.arrowDown {
|
|
23
|
+
composes: leading-[0] from global;
|
|
24
|
+
composes: pl-2xs from global;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* TODO @TW: cannot compose */
|
|
28
|
+
.megaMenuItem:hover .megaMenuLink,
|
|
29
|
+
.megaMenuItem:focus .megaMenuLink {
|
|
30
|
+
text-decoration: underline;
|
|
31
|
+
}
|