@gravity-ui/page-constructor 1.7.0-alpha.0 → 1.7.0-alpha.10
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/README.md +58 -36
- package/build/cjs/components/OverflowScroller/OverflowScroller.css +2 -0
- package/build/cjs/components/RouterLink/RouterLink.d.ts +1 -1
- package/build/cjs/components/index.d.ts +2 -0
- package/build/cjs/components/index.js +40 -39
- package/build/cjs/components/navigation/components/Header/Header.css +19 -19
- package/build/cjs/components/navigation/components/Header/Header.d.ts +2 -22
- package/build/cjs/components/navigation/components/Header/Header.js +40 -70
- package/build/cjs/components/navigation/components/Logo/Logo.css +13 -8
- package/build/cjs/components/navigation/components/Logo/Logo.d.ts +1 -1
- package/build/cjs/components/navigation/components/Logo/Logo.js +11 -7
- package/build/cjs/components/navigation/components/MobileNavigation/MobileNavigation.css +17 -11
- package/build/cjs/components/navigation/components/MobileNavigation/MobileNavigation.js +3 -3
- package/build/cjs/components/navigation/components/Navigation/Navigation.css +8 -8
- package/build/cjs/components/navigation/components/Navigation/Navigation.d.ts +9 -2
- package/build/cjs/components/navigation/components/Navigation/Navigation.js +18 -19
- package/build/cjs/components/navigation/components/NavigationItem/NavigationItem.css +9 -9
- package/build/cjs/components/navigation/components/NavigationItem/NavigationItem.d.ts +1 -3
- package/build/cjs/components/navigation/components/NavigationItem/NavigationItem.js +27 -15
- package/build/cjs/components/navigation/components/NavigationPopup/NavigationPopup.css +4 -4
- package/build/cjs/components/navigation/components/NavigationPopup/NavigationPopup.d.ts +4 -18
- package/build/cjs/components/navigation/components/NavigationPopup/NavigationPopup.js +34 -46
- package/build/cjs/components/navigation/components/SocialIcon/SocialIcon.css +3 -3
- package/build/cjs/components/navigation/components/SocialIcon/SocialIcon.d.ts +1 -1
- package/build/cjs/components/navigation/components/SocialIcon/SocialIcon.js +8 -4
- package/build/cjs/components/navigation/components/index.d.ts +7 -0
- package/build/cjs/components/navigation/components/index.js +20 -0
- package/build/cjs/components/navigation/containers/Layout/Layout.css +10 -0
- package/build/cjs/components/navigation/containers/Layout/Layout.d.ts +8 -0
- package/build/cjs/components/navigation/containers/Layout/Layout.js +11 -0
- package/build/cjs/containers/PageConstructor/PageConstructor.d.ts +3 -4
- package/build/cjs/containers/PageConstructor/PageConstructor.js +11 -11
- package/build/cjs/models/index.d.ts +1 -0
- package/build/cjs/models/index.js +1 -0
- package/build/cjs/models/navigation.d.ts +8 -5
- package/build/esm/components/OverflowScroller/OverflowScroller.css +2 -0
- package/build/esm/components/RouterLink/RouterLink.d.ts +1 -1
- package/build/esm/components/index.d.ts +2 -0
- package/build/esm/components/index.js +2 -0
- package/build/esm/components/navigation/components/Header/Header.css +19 -19
- package/build/esm/components/navigation/components/Header/Header.d.ts +2 -22
- package/build/esm/components/navigation/components/Header/Header.js +37 -69
- package/build/esm/components/navigation/components/Logo/Logo.css +13 -8
- package/build/esm/components/navigation/components/Logo/Logo.d.ts +1 -1
- package/build/esm/components/navigation/components/Logo/Logo.js +10 -6
- package/build/esm/components/navigation/components/MobileNavigation/MobileNavigation.css +17 -11
- package/build/esm/components/navigation/components/MobileNavigation/MobileNavigation.js +2 -2
- package/build/esm/components/navigation/components/Navigation/Navigation.css +8 -8
- package/build/esm/components/navigation/components/Navigation/Navigation.d.ts +9 -2
- package/build/esm/components/navigation/components/Navigation/Navigation.js +17 -18
- package/build/esm/components/navigation/components/NavigationItem/NavigationItem.css +9 -9
- package/build/esm/components/navigation/components/NavigationItem/NavigationItem.d.ts +1 -3
- package/build/esm/components/navigation/components/NavigationItem/NavigationItem.js +23 -11
- package/build/esm/components/navigation/components/NavigationPopup/NavigationPopup.css +4 -4
- package/build/esm/components/navigation/components/NavigationPopup/NavigationPopup.d.ts +4 -18
- package/build/esm/components/navigation/components/NavigationPopup/NavigationPopup.js +32 -45
- package/build/esm/components/navigation/components/SocialIcon/SocialIcon.css +3 -3
- package/build/esm/components/navigation/components/SocialIcon/SocialIcon.d.ts +1 -1
- package/build/esm/components/navigation/components/SocialIcon/SocialIcon.js +7 -3
- package/build/esm/components/navigation/components/index.d.ts +7 -0
- package/build/esm/components/navigation/components/index.js +7 -0
- package/build/esm/components/navigation/containers/Layout/Layout.css +10 -0
- package/build/esm/components/navigation/containers/Layout/Layout.d.ts +9 -0
- package/build/esm/components/navigation/containers/Layout/Layout.js +9 -0
- package/build/esm/containers/PageConstructor/PageConstructor.d.ts +3 -4
- package/build/esm/containers/PageConstructor/PageConstructor.js +11 -11
- package/build/esm/models/index.d.ts +1 -0
- package/build/esm/models/index.js +1 -0
- package/build/esm/models/navigation.d.ts +8 -5
- package/package.json +1 -4
- package/server/models/index.d.ts +1 -0
- package/server/models/index.js +1 -0
- package/server/models/navigation.d.ts +62 -0
- package/server/models/navigation.js +10 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import _ from 'lodash';
|
|
3
|
-
import block from 'bem-cn-lite';
|
|
4
3
|
import React, { Fragment, useState, useEffect, useCallback, useContext, useRef, } from 'react';
|
|
4
|
+
import { block } from '../../../../utils';
|
|
5
5
|
import OverflowScroller from '../../../OverflowScroller/OverflowScroller';
|
|
6
6
|
import { NavigationItemType, } from '../../../../models/navigation';
|
|
7
7
|
import NavigationPopup from '../NavigationPopup/NavigationPopup';
|
|
@@ -9,6 +9,12 @@ import NavigationItem from '../NavigationItem/NavigationItem';
|
|
|
9
9
|
import { LocationContext } from '../../../../context/locationContext';
|
|
10
10
|
import './Navigation.css';
|
|
11
11
|
const b = block('navigation');
|
|
12
|
+
const NavigationDropdown = ({ data, isActive, position, hidePopup, onClick, }) => {
|
|
13
|
+
const { text, items } = data, popupProps = __rest(data, ["text", "items"]);
|
|
14
|
+
return (React.createElement(Fragment, null,
|
|
15
|
+
React.createElement(NavigationItem, { className: b('link'), onClick: onClick, isOpened: isActive, data: { text, type: NavigationItemType.Dropdown } }),
|
|
16
|
+
isActive && (React.createElement(NavigationPopup, Object.assign({ left: position, onClose: hidePopup, items: items }, popupProps)))));
|
|
17
|
+
};
|
|
12
18
|
const Navigation = ({ className, onActiveItemChange, links, activeItemIndex, highlightActiveItem, }) => {
|
|
13
19
|
const { asPath, pathname } = useContext(LocationContext);
|
|
14
20
|
const itemRefs = useRef([]);
|
|
@@ -21,22 +27,6 @@ const Navigation = ({ className, onActiveItemChange, links, activeItemIndex, hig
|
|
|
21
27
|
e.stopPropagation();
|
|
22
28
|
onActiveItemChange(index === activeItemIndex ? -1 : index);
|
|
23
29
|
}, [activeItemIndex, onActiveItemChange]);
|
|
24
|
-
const renderNavDropdown = (data, onClick, isActive, position) => {
|
|
25
|
-
const { text, items } = data, popupProps = __rest(data, ["text", "items"]);
|
|
26
|
-
return (React.createElement(Fragment, null,
|
|
27
|
-
React.createElement(NavigationItem, { className: b('link'), onClick: onClick, isOpened: isActive, data: { text, type: NavigationItemType.Dropdown } }),
|
|
28
|
-
isActive && (React.createElement(NavigationPopup, Object.assign({ left: position, onClose: hidePopup, items: items }, popupProps)))));
|
|
29
|
-
};
|
|
30
|
-
const slider = (React.createElement("div", { className: b('slider-container') },
|
|
31
|
-
React.createElement("div", { className: b('slider') })));
|
|
32
|
-
const content = (React.createElement("nav", null,
|
|
33
|
-
React.createElement("ul", { className: b('links') }, links.map((link, index) => {
|
|
34
|
-
const isActive = index === activeItemIndex;
|
|
35
|
-
const onClick = getItemClickHandler(index);
|
|
36
|
-
return (React.createElement("li", { ref: (el) => itemRefs.current.push(el), key: index, className: b('links-item') },
|
|
37
|
-
link.type === NavigationItemType.Dropdown ? (renderNavDropdown(link, onClick, isActive, itemPositions[index])) : (React.createElement(NavigationItem, { data: link, onClick: onClick })),
|
|
38
|
-
highlightActiveItem && isActive && slider));
|
|
39
|
-
}))));
|
|
40
30
|
const calculateItemPositions = useCallback(() => {
|
|
41
31
|
if (itemRefs.current.length) {
|
|
42
32
|
const currentItemPositions = itemRefs.current.map((itemRef) => (itemRef && itemRef.getBoundingClientRect().left) || 0);
|
|
@@ -64,6 +54,15 @@ const Navigation = ({ className, onActiveItemChange, links, activeItemIndex, hig
|
|
|
64
54
|
useEffect(() => {
|
|
65
55
|
hidePopup();
|
|
66
56
|
}, [hidePopup, asPath, pathname]);
|
|
67
|
-
return (React.createElement(OverflowScroller, { className: b(null, className), onScrollStart: hidePopup, onScrollEnd: calculateItemPositions },
|
|
57
|
+
return (React.createElement(OverflowScroller, { className: b(null, className), onScrollStart: hidePopup, onScrollEnd: calculateItemPositions },
|
|
58
|
+
React.createElement("nav", null,
|
|
59
|
+
React.createElement("ul", { className: b('links') }, links.map((link, index) => {
|
|
60
|
+
const isActive = index === activeItemIndex;
|
|
61
|
+
const onClick = getItemClickHandler(index);
|
|
62
|
+
return (React.createElement("li", { ref: (el) => itemRefs.current.push(el), key: index, className: b('links-item') },
|
|
63
|
+
link.type === NavigationItemType.Dropdown ? (React.createElement(NavigationDropdown, { data: link, onClick: onClick, isActive: isActive, position: itemPositions[index], hidePopup: hidePopup })) : (React.createElement(NavigationItem, { data: link, onClick: onClick })),
|
|
64
|
+
highlightActiveItem && isActive && (React.createElement("div", { className: b('slider-container') },
|
|
65
|
+
React.createElement("div", { className: b('slider') })))));
|
|
66
|
+
})))));
|
|
68
67
|
};
|
|
69
68
|
export default Navigation;
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
/* use this for style redefinitions to awoid problems with
|
|
2
2
|
unpredictable css rules order in build */
|
|
3
|
-
.navigation-item {
|
|
3
|
+
.pc-navigation-item {
|
|
4
4
|
position: relative;
|
|
5
5
|
display: flex;
|
|
6
6
|
align-items: center;
|
|
7
7
|
}
|
|
8
|
-
.navigation-item_type_link {
|
|
8
|
+
.pc-navigation-item_type_link {
|
|
9
9
|
color: var(--yc-color-text-primary);
|
|
10
10
|
color: inherit;
|
|
11
11
|
text-decoration: none;
|
|
12
12
|
outline: none;
|
|
13
13
|
}
|
|
14
|
-
.utilityfocus .navigation-item_type_link:focus {
|
|
14
|
+
.utilityfocus .pc-navigation-item_type_link:focus {
|
|
15
15
|
outline: 2px solid #ffdb4d;
|
|
16
16
|
}
|
|
17
|
-
.navigation-item_type_link:hover, .navigation-item_type_link_active {
|
|
17
|
+
.pc-navigation-item_type_link:hover, .pc-navigation-item_type_link_active {
|
|
18
18
|
color: var(--yc-color-text-link);
|
|
19
19
|
}
|
|
20
|
-
.navigation-item_type_button {
|
|
20
|
+
.pc-navigation-item_type_button {
|
|
21
21
|
display: inline-block;
|
|
22
22
|
}
|
|
23
|
-
.navigation-item__arrow {
|
|
23
|
+
.pc-navigation-item__arrow {
|
|
24
24
|
position: relative;
|
|
25
25
|
top: -2px;
|
|
26
26
|
width: 9px;
|
|
27
27
|
height: 9px;
|
|
28
28
|
margin-left: 5px;
|
|
29
29
|
}
|
|
30
|
-
.navigation-item__icon {
|
|
30
|
+
.pc-navigation-item__icon {
|
|
31
|
+
display: flex;
|
|
31
32
|
width: 20px;
|
|
32
33
|
height: 20px;
|
|
33
34
|
margin-right: 8px;
|
|
34
|
-
border-radius: 50%;
|
|
35
35
|
object-fit: cover;
|
|
36
36
|
}
|
|
37
|
-
.navigation-item__dropdown {
|
|
37
|
+
.pc-navigation-item__dropdown {
|
|
38
38
|
margin-left: 7px;
|
|
39
39
|
color: var(--yc-color-text-secondary);
|
|
40
40
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import React, { MouseEventHandler } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { NavigationItemData } from '../../../../models';
|
|
3
3
|
import './NavigationItem.css';
|
|
4
|
-
declare type DropdownItemData = Omit<NavigationDropdownItem, 'items'>;
|
|
5
|
-
export declare type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | DropdownItemData;
|
|
6
4
|
export interface NavigationItemProps {
|
|
7
5
|
data: NavigationItemData;
|
|
8
6
|
className?: string;
|
|
@@ -1,37 +1,49 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import React, { Fragment, useContext, useMemo } from 'react';
|
|
3
|
-
import block from '
|
|
4
|
-
import { RouterLink, ToggleArrow } from '../../../index';
|
|
5
|
-
import { getLinkProps } from '../../../../utils';
|
|
3
|
+
import { block, getLinkProps } from '../../../../utils';
|
|
4
|
+
import { RouterLink, ToggleArrow, Button, Image } from '../../../index';
|
|
6
5
|
import { LocationContext } from '../../../../context/locationContext';
|
|
7
|
-
import { NavigationItemType, } from '../../../../models
|
|
6
|
+
import { NavigationItemType, } from '../../../../models';
|
|
8
7
|
import { NavigationArrow } from '../../../../icons';
|
|
9
8
|
import SocialIcon from '../SocialIcon/SocialIcon';
|
|
9
|
+
import { getMediaImage } from '../../../Media/Image/utils';
|
|
10
10
|
import './NavigationItem.css';
|
|
11
11
|
const b = block('navigation-item');
|
|
12
12
|
const Content = ({ text, icon }) => (React.createElement(Fragment, null,
|
|
13
|
-
icon && React.createElement(
|
|
13
|
+
icon && React.createElement(Image, Object.assign({ className: b('icon') }, icon)),
|
|
14
14
|
React.createElement("span", { className: b('text') }, text)));
|
|
15
15
|
const NavigationDropdown = (_a) => {
|
|
16
16
|
var { text, icon, isOpened } = _a, props = __rest(_a, ["text", "icon", "isOpened"]);
|
|
17
|
+
const iconData = icon && getMediaImage(icon);
|
|
17
18
|
return (React.createElement("span", Object.assign({}, props),
|
|
18
|
-
React.createElement(Content, { text: text, icon:
|
|
19
|
+
React.createElement(Content, { text: text, icon: iconData }),
|
|
19
20
|
React.createElement(ToggleArrow, { className: b('dropdown'), size: 12, type: 'vertical', iconType: "navigation", open: isOpened })));
|
|
20
21
|
};
|
|
21
22
|
const NavigationLink = (props) => {
|
|
22
|
-
const { hostname } = useContext(LocationContext);
|
|
23
|
+
const { hostname, Link } = useContext(LocationContext);
|
|
23
24
|
const { url, text, icon, arrow, target } = props, rest = __rest(props, ["url", "text", "icon", "arrow", "target"]);
|
|
24
25
|
const linkExtraProps = getLinkProps(url, hostname, target);
|
|
26
|
+
const iconData = icon && getMediaImage(icon);
|
|
25
27
|
const content = (React.createElement(Fragment, null,
|
|
26
|
-
React.createElement(Content, { text: text, icon:
|
|
28
|
+
React.createElement(Content, { text: text, icon: iconData }),
|
|
27
29
|
arrow && React.createElement(NavigationArrow, { className: b('arrow') })));
|
|
28
|
-
|
|
29
|
-
React.createElement("a", Object.assign({}, rest), content))
|
|
30
|
+
if ((linkExtraProps === null || linkExtraProps === void 0 ? void 0 : linkExtraProps.target) || !Link) {
|
|
31
|
+
return (React.createElement("a", Object.assign({ href: url, title: text }, rest, linkExtraProps), content));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return (React.createElement(RouterLink, { href: url, passHref: true },
|
|
35
|
+
React.createElement("a", Object.assign({}, rest), content)));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const NavigationButton = (props) => {
|
|
39
|
+
const { url, target } = props;
|
|
40
|
+
return target ? (React.createElement(Button, Object.assign({}, props, { url: url }))) : (React.createElement(RouterLink, { href: url },
|
|
41
|
+
React.createElement(Button, Object.assign({}, props, { url: url }))));
|
|
30
42
|
};
|
|
31
43
|
//todo: add types support form component in map
|
|
32
44
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
45
|
const NavigationItemsMap = {
|
|
34
|
-
[NavigationItemType.Button]:
|
|
46
|
+
[NavigationItemType.Button]: NavigationButton,
|
|
35
47
|
[NavigationItemType.Social]: SocialIcon,
|
|
36
48
|
[NavigationItemType.Dropdown]: NavigationDropdown,
|
|
37
49
|
[NavigationItemType.Link]: NavigationLink,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* use this for style redefinitions to awoid problems with
|
|
2
2
|
unpredictable css rules order in build */
|
|
3
|
-
.navigation-popup {
|
|
3
|
+
.pc-navigation-popup {
|
|
4
4
|
position: fixed;
|
|
5
5
|
top: calc(var(--header-height) - 16px);
|
|
6
6
|
padding-right: 4px;
|
|
@@ -18,16 +18,16 @@ unpredictable css rules order in build */
|
|
|
18
18
|
box-shadow: 0 3px 10px var(--yc-color-sfx-shadow);
|
|
19
19
|
}
|
|
20
20
|
@media (max-width: 768px) {
|
|
21
|
-
.navigation-popup {
|
|
21
|
+
.pc-navigation-popup {
|
|
22
22
|
display: none;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
.navigation-popup__link {
|
|
25
|
+
.pc-navigation-popup__link {
|
|
26
26
|
height: 36px;
|
|
27
27
|
padding: 8px 12px;
|
|
28
28
|
border-radius: 8px;
|
|
29
29
|
}
|
|
30
|
-
.navigation-popup__link:hover {
|
|
30
|
+
.pc-navigation-popup__link:hover {
|
|
31
31
|
color: var(--yc-color-text-primary);
|
|
32
32
|
background-color: var(--yc-color-base-simple-hover);
|
|
33
33
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { NavigationLinkItem } from '../../../../models
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NavigationLinkItem } from '../../../../models';
|
|
3
3
|
import './NavigationPopup.css';
|
|
4
4
|
export interface NavigationPopupProps {
|
|
5
5
|
items: NavigationLinkItem[];
|
|
@@ -7,19 +7,5 @@ export interface NavigationPopupProps {
|
|
|
7
7
|
left?: number;
|
|
8
8
|
className?: string;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
export default class NavigationPopup extends React.Component<NavigationPopupProps, NavigationPopupState> {
|
|
14
|
-
ref: RefObject<HTMLDivElement>;
|
|
15
|
-
state: {
|
|
16
|
-
calculatedLeft: number | undefined;
|
|
17
|
-
};
|
|
18
|
-
private calculateLeft;
|
|
19
|
-
componentDidMount(): void;
|
|
20
|
-
componentDidUpdate(prevProps: NavigationPopupProps): void;
|
|
21
|
-
componentWillUnmount(): void;
|
|
22
|
-
render(): JSX.Element | null;
|
|
23
|
-
private renderDefaultPopup;
|
|
24
|
-
}
|
|
25
|
-
export {};
|
|
10
|
+
export declare const NavigationPopup: React.FC<NavigationPopupProps>;
|
|
11
|
+
export default NavigationPopup;
|
|
@@ -1,54 +1,41 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import
|
|
3
|
-
import React, { Fragment, createRef } from 'react';
|
|
2
|
+
import React, { useRef, useState, useEffect, useCallback } from 'react';
|
|
4
3
|
import { Portal } from '@gravity-ui/uikit';
|
|
4
|
+
import { block } from '../../../../utils';
|
|
5
5
|
import { OutsideClick } from '../../../index';
|
|
6
6
|
import NavigationItem from '../NavigationItem/NavigationItem';
|
|
7
7
|
import './NavigationPopup.css';
|
|
8
8
|
const b = block('navigation-popup');
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (this.ref && this.ref.current && left) {
|
|
19
|
-
const right = left + this.ref.current.offsetWidth;
|
|
20
|
-
const docWidth = document.body.clientWidth;
|
|
21
|
-
const calculatedLeft = right > docWidth ? left - (right - docWidth) : left;
|
|
22
|
-
this.setState({ calculatedLeft });
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
this.setState({ calculatedLeft: left });
|
|
26
|
-
}
|
|
27
|
-
}, 100);
|
|
28
|
-
}
|
|
29
|
-
componentDidMount() {
|
|
30
|
-
this.calculateLeft();
|
|
31
|
-
window.addEventListener('resize', this.calculateLeft);
|
|
32
|
-
}
|
|
33
|
-
componentDidUpdate(prevProps) {
|
|
34
|
-
if (prevProps.left !== this.props.left) {
|
|
35
|
-
this.calculateLeft();
|
|
9
|
+
export const NavigationPopup = ({ items, left, onClose }) => {
|
|
10
|
+
const [calculatedLeft, setCalculatedLeft] = useState(left);
|
|
11
|
+
const popupRef = useRef(null);
|
|
12
|
+
const calculateLeft = useCallback(() => {
|
|
13
|
+
if (popupRef && popupRef.current && left) {
|
|
14
|
+
const right = left + popupRef.current.offsetWidth;
|
|
15
|
+
const docWidth = document.body.clientWidth;
|
|
16
|
+
const currentLeft = right > docWidth ? left - (right - docWidth) : left;
|
|
17
|
+
setCalculatedLeft(currentLeft);
|
|
36
18
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
window.removeEventListener('resize', this.calculateLeft);
|
|
40
|
-
}
|
|
41
|
-
render() {
|
|
42
|
-
if (!document || !document.body) {
|
|
43
|
-
return null;
|
|
19
|
+
else {
|
|
20
|
+
setCalculatedLeft(left);
|
|
44
21
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
22
|
+
}, [left]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const debounceCalculateLeft = _.debounce(calculateLeft, 100);
|
|
25
|
+
calculateLeft();
|
|
26
|
+
window.addEventListener('resize', debounceCalculateLeft);
|
|
27
|
+
return () => {
|
|
28
|
+
window.removeEventListener('resize', debounceCalculateLeft);
|
|
29
|
+
};
|
|
30
|
+
}, [calculateLeft]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
calculateLeft();
|
|
33
|
+
}, [calculateLeft, left]);
|
|
34
|
+
if (!document || !document.body) {
|
|
35
|
+
return null;
|
|
53
36
|
}
|
|
54
|
-
|
|
37
|
+
return (React.createElement(Portal, null,
|
|
38
|
+
React.createElement("div", { ref: popupRef, className: b(), style: { left: calculatedLeft } },
|
|
39
|
+
React.createElement(OutsideClick, { onOutsideClick: onClose }, items.map((item) => (React.createElement(NavigationItem, { key: item.text, className: b('link'), data: item })))))));
|
|
40
|
+
};
|
|
41
|
+
export default NavigationPopup;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* use this for style redefinitions to awoid problems with
|
|
2
2
|
unpredictable css rules order in build */
|
|
3
|
-
.social-icon {
|
|
3
|
+
.pc-social-icon {
|
|
4
4
|
display: flex;
|
|
5
5
|
justify-content: center;
|
|
6
6
|
align-items: center;
|
|
@@ -11,10 +11,10 @@ unpredictable css rules order in build */
|
|
|
11
11
|
border-radius: 50%;
|
|
12
12
|
background-color: var(--yc-color-base-generic);
|
|
13
13
|
}
|
|
14
|
-
.social-icon:hover {
|
|
14
|
+
.pc-social-icon:hover {
|
|
15
15
|
background-color: var(--yc-color-base-generic-hover);
|
|
16
16
|
}
|
|
17
|
-
.social-icon__icon {
|
|
17
|
+
.pc-social-icon__icon {
|
|
18
18
|
width: 16px;
|
|
19
19
|
height: 16px;
|
|
20
20
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { NavigationSocialItem } from '../../../../models
|
|
2
|
+
import { NavigationSocialItem } from '../../../../models';
|
|
3
3
|
import './SocialIcon.css';
|
|
4
4
|
export interface NavigationSocialItemProps extends NavigationSocialItem {
|
|
5
5
|
className?: string;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import block from '
|
|
2
|
+
import { block } from '../../../../utils';
|
|
3
3
|
import { Image } from '../../../index';
|
|
4
|
+
import { getMediaImage } from '../../../Media/Image/utils';
|
|
4
5
|
import './SocialIcon.css';
|
|
5
6
|
const b = block('social-icon');
|
|
6
|
-
const SocialIcon = ({ icon, url, className }) =>
|
|
7
|
-
|
|
7
|
+
const SocialIcon = ({ icon, url, className }) => {
|
|
8
|
+
const iconData = getMediaImage(icon);
|
|
9
|
+
return (React.createElement("a", { href: url, target: "_blank", rel: "noopener noreferrer", className: b(null, className) },
|
|
10
|
+
React.createElement(Image, Object.assign({ className: b('icon') }, iconData))));
|
|
11
|
+
};
|
|
8
12
|
export default SocialIcon;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as Header } from './Header/Header';
|
|
2
|
+
export { default as NavigationItem } from './NavigationItem/NavigationItem';
|
|
3
|
+
export { default as Logo } from './Logo/Logo';
|
|
4
|
+
export { default as MobileNavigation } from './MobileNavigation/MobileNavigation';
|
|
5
|
+
export { default as Navigation } from './Navigation/Navigation';
|
|
6
|
+
export { default as NavigationPopup } from './NavigationPopup/NavigationPopup';
|
|
7
|
+
export { default as SocialIcon } from './SocialIcon/SocialIcon';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as Header } from './Header/Header';
|
|
2
|
+
export { default as NavigationItem } from './NavigationItem/NavigationItem';
|
|
3
|
+
export { default as Logo } from './Logo/Logo';
|
|
4
|
+
export { default as MobileNavigation } from './MobileNavigation/MobileNavigation';
|
|
5
|
+
export { default as Navigation } from './Navigation/Navigation';
|
|
6
|
+
export { default as NavigationPopup } from './NavigationPopup/NavigationPopup';
|
|
7
|
+
export { default as SocialIcon } from './SocialIcon/SocialIcon';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NavigationData } from '../../../../models';
|
|
3
|
+
import './Layout.css';
|
|
4
|
+
export interface LayoutProps {
|
|
5
|
+
navigation?: NavigationData;
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
declare const Layout: React.FC<LayoutProps>;
|
|
9
|
+
export default Layout;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { block } from '../../../../utils';
|
|
3
|
+
import Header from '../../components/Header/Header';
|
|
4
|
+
import './Layout.css';
|
|
5
|
+
const b = block('layout');
|
|
6
|
+
const Layout = ({ children, navigation }) => (React.createElement("div", { className: b() },
|
|
7
|
+
navigation && React.createElement(Header, { data: navigation.header, logo: navigation.logo }),
|
|
8
|
+
React.createElement("main", { className: b('content') }, children)));
|
|
9
|
+
export default Layout;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ShouldRenderBlock, CustomConfig, PageContent, CustomItems } from '../../models';
|
|
3
|
-
import { blockMap, subBlockMap } from '../../constructor-items';
|
|
4
|
-
import { NavigationData } from '../../models/navigation';
|
|
5
2
|
import '@doc-tools/transform/dist/js/yfm';
|
|
3
|
+
import { ShouldRenderBlock, CustomConfig, PageContent, CustomItems, NavigationData } from '../../models';
|
|
4
|
+
import { blockMap, subBlockMap } from '../../constructor-items';
|
|
6
5
|
import './PageConstructor.css';
|
|
7
6
|
export declare type ItemMap = typeof blockMap & typeof subBlockMap & CustomItems;
|
|
8
7
|
export interface PageConstructorProps {
|
|
@@ -10,7 +9,7 @@ export interface PageConstructorProps {
|
|
|
10
9
|
shouldRenderBlock?: ShouldRenderBlock;
|
|
11
10
|
custom?: CustomConfig;
|
|
12
11
|
renderMenu?: () => React.ReactNode;
|
|
13
|
-
|
|
12
|
+
navigation?: NavigationData;
|
|
14
13
|
}
|
|
15
14
|
export declare const Constructor: (props: PageConstructorProps) => JSX.Element;
|
|
16
15
|
export declare const PageConstructor: (props: PageConstructorProps) => JSX.Element;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import React, { useContext, useMemo } from 'react';
|
|
3
|
+
import '@doc-tools/transform/dist/js/yfm';
|
|
3
4
|
import { HeaderBlockTypes, BlockTypes, } from '../../models';
|
|
4
5
|
import { blockMap, subBlockMap } from '../../constructor-items';
|
|
5
6
|
import { Grid } from '../../grid';
|
|
@@ -12,8 +13,7 @@ import { ConstructorRow } from './components/ConstructorRow';
|
|
|
12
13
|
import { ConstructorFootnotes } from './components/ConstructorFootnotes';
|
|
13
14
|
import { ConstructorHeader } from './components/ConstructorItem';
|
|
14
15
|
import { ConstructorBlocks } from './components/ConstructorBlocks';
|
|
15
|
-
import
|
|
16
|
-
import '@doc-tools/transform/dist/js/yfm';
|
|
16
|
+
import Layout from '../../components/navigation/containers/Layout/Layout';
|
|
17
17
|
import './PageConstructor.css';
|
|
18
18
|
const b = cnBlock('page-constructor');
|
|
19
19
|
export const Constructor = (props) => {
|
|
@@ -29,7 +29,7 @@ export const Constructor = (props) => {
|
|
|
29
29
|
});
|
|
30
30
|
}, [props.custom]);
|
|
31
31
|
const { themeValue: theme } = useContext(ThemeValueContext);
|
|
32
|
-
const { content: { blocks = [], background = {}, footnotes = [] } = {}, renderMenu, shouldRenderBlock,
|
|
32
|
+
const { content: { blocks = [], background = {}, footnotes = [] } = {}, renderMenu, shouldRenderBlock, navigation, } = props;
|
|
33
33
|
const hasFootnotes = footnotes.length > 0;
|
|
34
34
|
const isHeaderBlock = (block) => headerBlockTypes.includes(block.type);
|
|
35
35
|
const header = blocks === null || blocks === void 0 ? void 0 : blocks.find(isHeaderBlock);
|
|
@@ -39,14 +39,14 @@ export const Constructor = (props) => {
|
|
|
39
39
|
React.createElement("div", { className: b() },
|
|
40
40
|
React.createElement("div", { className: b('wrapper') },
|
|
41
41
|
themedBackground && (React.createElement(BackgroundMedia, Object.assign({}, themedBackground, { className: b('background') }))),
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
React.createElement(Layout, { navigation: navigation },
|
|
43
|
+
renderMenu && renderMenu(),
|
|
44
|
+
header && React.createElement(ConstructorHeader, { data: header }),
|
|
45
|
+
React.createElement(Grid, null,
|
|
46
|
+
restBlocks && (React.createElement(ConstructorRow, null,
|
|
47
|
+
React.createElement(ConstructorBlocks, { items: restBlocks, shouldRenderBlock: shouldRenderBlock }))),
|
|
48
|
+
hasFootnotes && (React.createElement(ConstructorRow, null,
|
|
49
|
+
React.createElement(ConstructorFootnotes, { items: footnotes })))))))));
|
|
50
50
|
};
|
|
51
51
|
export const PageConstructor = (props) => {
|
|
52
52
|
const { content: { animated = true } = {} } = props, rest = __rest(props, ["content"]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ButtonProps } from '
|
|
1
|
+
import { ImageProps, ButtonProps } from './constructor-items';
|
|
2
2
|
export declare enum NavigationItemType {
|
|
3
3
|
Link = "link",
|
|
4
4
|
Dropdown = "dropdown",
|
|
@@ -7,7 +7,7 @@ export declare enum NavigationItemType {
|
|
|
7
7
|
}
|
|
8
8
|
export interface NavigationItemBase {
|
|
9
9
|
text: string;
|
|
10
|
-
icon?:
|
|
10
|
+
icon?: ImageProps;
|
|
11
11
|
url?: string;
|
|
12
12
|
}
|
|
13
13
|
export interface NavigationLinkItem extends NavigationItemBase {
|
|
@@ -27,13 +27,16 @@ export interface NavigationDropdownItem extends NavigationItemBase {
|
|
|
27
27
|
}
|
|
28
28
|
export interface NavigationSocialItem extends Omit<NavigationItemBase, 'text'> {
|
|
29
29
|
type: NavigationItemType.Social;
|
|
30
|
-
icon:
|
|
30
|
+
icon: ImageProps;
|
|
31
31
|
url: string;
|
|
32
32
|
}
|
|
33
33
|
export declare type NavigationItem = NavigationLinkItem | NavigationButtonItem | NavigationDropdownItem;
|
|
34
|
-
export
|
|
35
|
-
|
|
34
|
+
export declare type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | DropdownItemData;
|
|
35
|
+
export declare type DropdownItemData = Omit<NavigationDropdownItem, 'items'>;
|
|
36
|
+
export interface NavigationLogo {
|
|
37
|
+
icon: ImageProps;
|
|
36
38
|
text?: string;
|
|
39
|
+
url?: string;
|
|
37
40
|
}
|
|
38
41
|
export interface HeaderData {
|
|
39
42
|
leftItems: NavigationItem[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/page-constructor",
|
|
3
|
-
"version": "1.7.0-alpha.
|
|
3
|
+
"version": "1.7.0-alpha.10",
|
|
4
4
|
"description": "Gravity UI Page Constructor",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -121,8 +121,5 @@
|
|
|
121
121
|
"*.{json,yaml,yml,md}": [
|
|
122
122
|
"prettier --write"
|
|
123
123
|
]
|
|
124
|
-
},
|
|
125
|
-
"publishConfig": {
|
|
126
|
-
"tag": "alpha"
|
|
127
124
|
}
|
|
128
125
|
}
|
package/server/models/index.d.ts
CHANGED
package/server/models/index.js
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ImageProps, ButtonProps } from './constructor-items';
|
|
2
|
+
export declare enum NavigationItemType {
|
|
3
|
+
Link = "link",
|
|
4
|
+
Dropdown = "dropdown",
|
|
5
|
+
Button = "button",
|
|
6
|
+
Social = "social"
|
|
7
|
+
}
|
|
8
|
+
export interface NavigationItemBase {
|
|
9
|
+
text: string;
|
|
10
|
+
icon?: ImageProps;
|
|
11
|
+
url?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface NavigationLinkItem extends NavigationItemBase {
|
|
14
|
+
type: NavigationItemType.Link;
|
|
15
|
+
url: string;
|
|
16
|
+
arrow?: boolean;
|
|
17
|
+
target?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface NavigationButtonItem extends ButtonProps {
|
|
20
|
+
type: NavigationItemType.Button;
|
|
21
|
+
url: string;
|
|
22
|
+
target?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface NavigationDropdownItem extends NavigationItemBase {
|
|
25
|
+
type: NavigationItemType.Dropdown;
|
|
26
|
+
items: NavigationLinkItem[];
|
|
27
|
+
}
|
|
28
|
+
export interface NavigationSocialItem extends Omit<NavigationItemBase, 'text'> {
|
|
29
|
+
type: NavigationItemType.Social;
|
|
30
|
+
icon: ImageProps;
|
|
31
|
+
url: string;
|
|
32
|
+
}
|
|
33
|
+
export declare type NavigationItem = NavigationLinkItem | NavigationButtonItem | NavigationDropdownItem;
|
|
34
|
+
export declare type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | DropdownItemData;
|
|
35
|
+
export declare type DropdownItemData = Omit<NavigationDropdownItem, 'items'>;
|
|
36
|
+
export interface NavigationLogo {
|
|
37
|
+
icon: ImageProps;
|
|
38
|
+
text?: string;
|
|
39
|
+
url?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface HeaderData {
|
|
42
|
+
leftItems: NavigationItem[];
|
|
43
|
+
rightItems?: NavigationItem[];
|
|
44
|
+
}
|
|
45
|
+
export interface FooterColumn {
|
|
46
|
+
title: string;
|
|
47
|
+
links: NavigationItem[];
|
|
48
|
+
}
|
|
49
|
+
export interface FooterUnderline {
|
|
50
|
+
links?: NavigationItem[];
|
|
51
|
+
copyright?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface FooterData {
|
|
54
|
+
columns: FooterColumn[];
|
|
55
|
+
social?: NavigationSocialItem[];
|
|
56
|
+
underline?: FooterUnderline;
|
|
57
|
+
}
|
|
58
|
+
export interface NavigationData {
|
|
59
|
+
logo: NavigationLogo;
|
|
60
|
+
header: HeaderData;
|
|
61
|
+
footer?: FooterData;
|
|
62
|
+
}
|