@gravity-ui/page-constructor 1.7.0-alpha.4 → 1.7.0-alpha.6

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 (22) hide show
  1. package/build/cjs/components/navigation/components/Header/Header.css +1 -1
  2. package/build/cjs/components/navigation/components/Header/Header.d.ts +1 -21
  3. package/build/cjs/components/navigation/components/Header/Header.js +40 -64
  4. package/build/cjs/components/navigation/components/MobileNavigation/MobileNavigation.css +1 -1
  5. package/build/cjs/components/navigation/components/NavigationItem/NavigationItem.d.ts +0 -1
  6. package/build/cjs/components/navigation/components/NavigationItem/NavigationItem.js +10 -6
  7. package/build/cjs/components/navigation/components/NavigationPopup/NavigationPopup.js +1 -3
  8. package/build/cjs/models/navigation.d.ts +0 -1
  9. package/build/esm/components/navigation/components/Header/Header.css +1 -1
  10. package/build/esm/components/navigation/components/Header/Header.d.ts +1 -21
  11. package/build/esm/components/navigation/components/Header/Header.js +38 -64
  12. package/build/esm/components/navigation/components/MobileNavigation/MobileNavigation.css +1 -1
  13. package/build/esm/components/navigation/components/NavigationItem/NavigationItem.d.ts +0 -1
  14. package/build/esm/components/navigation/components/NavigationItem/NavigationItem.js +10 -6
  15. package/build/esm/components/navigation/components/NavigationPopup/NavigationPopup.js +2 -4
  16. package/build/esm/models/navigation.d.ts +0 -1
  17. package/package.json +1 -1
  18. package/server/models/navigation.d.ts +0 -1
  19. package/build/cjs/components/navigation/components/NavigationPopup/NavigationPopup-class.d.ts +0 -24
  20. package/build/cjs/components/navigation/components/NavigationPopup/NavigationPopup-class.js +0 -57
  21. package/build/esm/components/navigation/components/NavigationPopup/NavigationPopup-class.d.ts +0 -25
  22. package/build/esm/components/navigation/components/NavigationPopup/NavigationPopup-class.js +0 -54
@@ -28,9 +28,9 @@ unpredictable css rules order in build */
28
28
  }
29
29
  .header__navigation {
30
30
  position: relative;
31
+ margin-right: 20px;
31
32
  flex: 1 0 0;
32
33
  justify-content: flex-start;
33
- margin-right: 20px;
34
34
  }
35
35
  @media (max-width: 768px) {
36
36
  .header__navigation {
@@ -4,25 +4,5 @@ export interface HeaderProps {
4
4
  logo: NavigationLogo;
5
5
  data: HeaderData;
6
6
  }
7
- interface HeaderState {
8
- isSidebarOpened: boolean;
9
- activeItemIndex: number;
10
- }
11
- declare class Header extends React.Component<HeaderProps, HeaderState> {
12
- ref: React.RefObject<unknown>;
13
- state: {
14
- isSidebarOpened: boolean;
15
- activeItemIndex: number;
16
- };
17
- render(): JSX.Element;
18
- private renderLeft;
19
- private renderLogo;
20
- private renderRight;
21
- private renderRightItems;
22
- private renderMobileMenuButton;
23
- private renderMobileNavigation;
24
- private onActiveItemChange;
25
- private onSidebarOpenedChange;
26
- private hideSidebar;
27
- }
7
+ export declare const Header: React.FC<HeaderProps>;
28
8
  export default Header;
@@ -1,81 +1,57 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Header = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  const react_1 = (0, tslib_1.__importStar)(require("react"));
5
6
  const bem_cn_lite_1 = (0, tslib_1.__importDefault)(require("bem-cn-lite"));
6
7
  const grid_1 = require("../../../../grid");
7
8
  const OutsideClick_1 = (0, tslib_1.__importDefault)(require("../../../OutsideClick/OutsideClick"));
8
9
  const Control_1 = (0, tslib_1.__importDefault)(require("../../../Control/Control"));
9
- const Logo_1 = (0, tslib_1.__importDefault)(require("../Logo/Logo"));
10
10
  const Navigation_1 = (0, tslib_1.__importDefault)(require("../Navigation/Navigation"));
11
11
  const MobileNavigation_1 = (0, tslib_1.__importDefault)(require("../MobileNavigation/MobileNavigation"));
12
12
  const NavigationItem_1 = (0, tslib_1.__importDefault)(require("../NavigationItem/NavigationItem"));
13
+ const Logo_1 = (0, tslib_1.__importDefault)(require("../Logo/Logo"));
13
14
  const icons_1 = require("../../../../icons");
14
15
  const b = (0, bem_cn_lite_1.default)('header');
15
- class Header extends react_1.default.Component {
16
- constructor() {
17
- super(...arguments);
18
- this.ref = (0, react_1.createRef)();
19
- this.state = {
20
- isSidebarOpened: false,
21
- activeItemIndex: -1,
22
- };
23
- this.onActiveItemChange = (index) => {
24
- this.setState({ activeItemIndex: index });
25
- };
26
- this.onSidebarOpenedChange = (isSidebarOpened) => {
27
- this.setState({ isSidebarOpened });
28
- };
29
- this.hideSidebar = () => {
30
- this.setState({ isSidebarOpened: false });
31
- };
32
- }
33
- render() {
34
- return (react_1.default.createElement(grid_1.Grid, { className: b() },
35
- react_1.default.createElement(grid_1.Row, null,
36
- react_1.default.createElement(grid_1.Col, null,
37
- react_1.default.createElement("header", { className: b('wrapper') },
38
- this.renderLogo(),
39
- this.renderLeft(),
40
- this.renderRight(),
41
- this.renderMobileNavigation())))));
42
- }
43
- renderLeft() {
44
- const { activeItemIndex } = this.state;
45
- const { leftItems } = this.props.data;
46
- return (leftItems && (react_1.default.createElement("div", { className: b('navigation-container') },
47
- react_1.default.createElement(Navigation_1.default, { className: b('navigation'), links: leftItems, activeItemIndex: activeItemIndex, onActiveItemChange: this.onActiveItemChange }))));
48
- }
49
- renderLogo() {
50
- const { logo } = this.props;
51
- if (!logo) {
52
- return null;
53
- }
54
- return (react_1.default.createElement("div", { className: b('left') },
55
- react_1.default.createElement(Logo_1.default, Object.assign({}, logo, { className: b('logo') }))));
56
- }
57
- renderRight() {
58
- return (react_1.default.createElement("div", { className: b('right') },
59
- this.renderMobileMenuButton(),
60
- this.renderRightItems()));
61
- }
62
- renderRightItems() {
63
- const { rightItems } = this.props.data;
64
- return (rightItems && (react_1.default.createElement("div", { className: b('buttons') }, rightItems.map((button) => (react_1.default.createElement(NavigationItem_1.default, { key: button.text, data: button, className: b('button') }))))));
65
- }
66
- renderMobileMenuButton() {
67
- const { isSidebarOpened } = this.state;
16
+ const Header = ({ data, logo }) => {
17
+ const { leftItems, rightItems } = data;
18
+ const [isSidebarOpened, setIsSidebarOpened] = (0, react_1.useState)(false);
19
+ const [activeItemIndex, setActiveItemIndex] = (0, react_1.useState)(-1);
20
+ const onActiveItemChange = (0, react_1.useCallback)((index) => {
21
+ setActiveItemIndex(index);
22
+ }, []);
23
+ const onSidebarOpenedChange = (0, react_1.useCallback)((isOpen) => {
24
+ setIsSidebarOpened(isOpen);
25
+ }, []);
26
+ const hideSidebar = (0, react_1.useCallback)(() => {
27
+ setIsSidebarOpened(false);
28
+ }, []);
29
+ const renderLogo = (react_1.default.createElement("div", { className: b('left') },
30
+ react_1.default.createElement(Logo_1.default, Object.assign({}, logo, { className: b('logo') }))));
31
+ const renderLeft = (react_1.default.createElement("div", { className: b('navigation-container') },
32
+ react_1.default.createElement(Navigation_1.default, { className: b('navigation'), links: leftItems, activeItemIndex: activeItemIndex, onActiveItemChange: onActiveItemChange })));
33
+ const renderMobileMenuButton = () => {
68
34
  const iconProps = { icon: isSidebarOpened ? icons_1.NavigationClose : icons_1.NavigationOpen, iconSize: 36 };
69
35
  return (react_1.default.createElement(Control_1.default, Object.assign({ className: b('mobile-menu-button'), onClick: (e) => {
70
36
  e.stopPropagation();
71
- this.onSidebarOpenedChange(!isSidebarOpened);
37
+ onSidebarOpenedChange(!isSidebarOpened);
72
38
  }, size: "l" }, iconProps)));
73
- }
74
- renderMobileNavigation() {
75
- const { leftItems, rightItems } = this.props.data;
76
- const { isSidebarOpened, activeItemIndex } = this.state;
77
- return (react_1.default.createElement(OutsideClick_1.default, { onOutsideClick: () => this.onSidebarOpenedChange(false) },
78
- react_1.default.createElement(MobileNavigation_1.default, { topItems: leftItems, bottomItems: rightItems, isOpened: isSidebarOpened, activeItemIndex: activeItemIndex, onActiveItemChange: this.onActiveItemChange, onClose: this.hideSidebar })));
79
- }
80
- }
81
- exports.default = Header;
39
+ };
40
+ const renderRightItems = (react_1.default.createElement("div", { className: b('buttons') }, rightItems &&
41
+ rightItems.map((button) => (react_1.default.createElement(NavigationItem_1.default, { key: button.text, data: button, className: b('button') })))));
42
+ const renderRight = (react_1.default.createElement("div", { className: b('right') },
43
+ renderMobileMenuButton(),
44
+ rightItems && renderRightItems));
45
+ const renderMobileNavigation = (react_1.default.createElement(OutsideClick_1.default, { onOutsideClick: () => onSidebarOpenedChange(false) },
46
+ react_1.default.createElement(MobileNavigation_1.default, { topItems: leftItems, bottomItems: rightItems, isOpened: isSidebarOpened, activeItemIndex: activeItemIndex, onActiveItemChange: onActiveItemChange, onClose: hideSidebar })));
47
+ return (react_1.default.createElement(grid_1.Grid, { className: b() },
48
+ react_1.default.createElement(grid_1.Row, null,
49
+ react_1.default.createElement(grid_1.Col, null,
50
+ react_1.default.createElement("header", { className: b('wrapper') },
51
+ logo && renderLogo,
52
+ leftItems && renderLeft,
53
+ renderRight,
54
+ renderMobileNavigation)))));
55
+ };
56
+ exports.Header = Header;
57
+ exports.default = exports.Header;
@@ -9,7 +9,7 @@ unpredictable css rules order in build */
9
9
  border-bottom-right-radius: var(--pc-border-radius);
10
10
  border-bottom-left-radius: var(--pc-border-radius);
11
11
  background-color: var(--yc-color-base-background);
12
- box-shadow: 0px 3px 10px var(--yc-color-sfx-shadow);
12
+ box-shadow: 0 3px 10px var(--yc-color-sfx-shadow);
13
13
  font-size: var(--yc-text-body-2-font-size);
14
14
  line-height: var(--yc-text-body-2-line-height);
15
15
  }
@@ -7,7 +7,6 @@ export interface NavigationItemProps {
7
7
  className?: string;
8
8
  onClick?: MouseEventHandler;
9
9
  isOpened?: boolean;
10
- hostname?: string;
11
10
  }
12
11
  declare const NavigationItem: React.FC<NavigationItemProps>;
13
12
  export default NavigationItem;
@@ -22,16 +22,20 @@ const NavigationDropdown = (_a) => {
22
22
  react_1.default.createElement(index_1.ToggleArrow, { className: b('dropdown'), size: 12, type: 'vertical', iconType: "navigation", open: isOpened })));
23
23
  };
24
24
  const NavigationLink = (props) => {
25
- const { hostname: locationHostname } = (0, react_1.useContext)(locationContext_1.LocationContext);
26
- const { url, text, icon, arrow, target, hostname } = props, rest = (0, tslib_1.__rest)(props, ["url", "text", "icon", "arrow", "target", "hostname"]);
27
- const currentHostname = locationHostname || hostname;
28
- const linkExtraProps = (0, utils_1.getLinkProps)(url, currentHostname, target);
25
+ const { hostname, Link } = (0, react_1.useContext)(locationContext_1.LocationContext);
26
+ const { url, text, icon, arrow, target } = props, rest = (0, tslib_1.__rest)(props, ["url", "text", "icon", "arrow", "target"]);
27
+ const linkExtraProps = (0, utils_1.getLinkProps)(url, hostname, target);
29
28
  const iconData = icon && (0, utils_2.getMediaImage)(icon);
30
29
  const content = (react_1.default.createElement(react_1.Fragment, null,
31
30
  react_1.default.createElement(Content, { text: text, icon: iconData }),
32
31
  arrow && react_1.default.createElement(icons_1.NavigationArrow, { className: b('arrow') })));
33
- return (linkExtraProps === null || linkExtraProps === void 0 ? void 0 : linkExtraProps.target) ? (react_1.default.createElement("a", Object.assign({ href: url, title: text }, rest, linkExtraProps), content)) : (react_1.default.createElement(index_1.RouterLink, { href: url, passHref: true },
34
- react_1.default.createElement("a", Object.assign({}, rest), content)));
32
+ if ((linkExtraProps === null || linkExtraProps === void 0 ? void 0 : linkExtraProps.target) || !Link) {
33
+ return (react_1.default.createElement("a", Object.assign({ href: url, title: text }, rest, linkExtraProps), content));
34
+ }
35
+ else {
36
+ return (react_1.default.createElement(index_1.RouterLink, { href: url, passHref: true },
37
+ react_1.default.createElement("a", Object.assign({}, rest), content)));
38
+ }
35
39
  };
36
40
  const NavigationButton = (props) => {
37
41
  const { url, target } = props;
@@ -8,12 +8,10 @@ const react_1 = (0, tslib_1.__importStar)(require("react"));
8
8
  const uikit_1 = require("@gravity-ui/uikit");
9
9
  const index_1 = require("../../../index");
10
10
  const NavigationItem_1 = (0, tslib_1.__importDefault)(require("../NavigationItem/NavigationItem"));
11
- const locationContext_1 = require("../../../../context/locationContext");
12
11
  const b = (0, bem_cn_lite_1.default)('navigation-popup');
13
12
  const NavigationPopup = ({ items, left, onClose }) => {
14
13
  const [calculatedLeft, setCalculatedLeft] = (0, react_1.useState)(left);
15
14
  const popupRef = (0, react_1.useRef)(null);
16
- const { hostname } = (0, react_1.useContext)(locationContext_1.LocationContext);
17
15
  const calculateLeft = (0, react_1.useCallback)(() => {
18
16
  if (popupRef && popupRef.current && left) {
19
17
  const right = left + popupRef.current.offsetWidth;
@@ -39,7 +37,7 @@ const NavigationPopup = ({ items, left, onClose }) => {
39
37
  if (!document || !document.body) {
40
38
  return null;
41
39
  }
42
- const renderDefaultPopup = (react_1.default.createElement(react_1.Fragment, null, items.map((item) => (react_1.default.createElement(NavigationItem_1.default, { key: item.text, className: b('link'), data: item, hostname: hostname })))));
40
+ const renderDefaultPopup = (react_1.default.createElement(react_1.Fragment, null, items.map((item) => (react_1.default.createElement(NavigationItem_1.default, { key: item.text, className: b('link'), data: item })))));
43
41
  return (react_1.default.createElement(uikit_1.Portal, null,
44
42
  react_1.default.createElement("div", { ref: popupRef, className: b(), style: { left: calculatedLeft } },
45
43
  react_1.default.createElement(index_1.OutsideClick, { onOutsideClick: onClose }, renderDefaultPopup))));
@@ -15,7 +15,6 @@ export interface NavigationLinkItem extends NavigationItemBase {
15
15
  url: string;
16
16
  arrow?: boolean;
17
17
  target?: string;
18
- hostname?: string;
19
18
  }
20
19
  export interface NavigationButtonItem extends ButtonProps {
21
20
  type: NavigationItemType.Button;
@@ -28,9 +28,9 @@ unpredictable css rules order in build */
28
28
  }
29
29
  .header__navigation {
30
30
  position: relative;
31
+ margin-right: 20px;
31
32
  flex: 1 0 0;
32
33
  justify-content: flex-start;
33
- margin-right: 20px;
34
34
  }
35
35
  @media (max-width: 768px) {
36
36
  .header__navigation {
@@ -5,25 +5,5 @@ export interface HeaderProps {
5
5
  logo: NavigationLogo;
6
6
  data: HeaderData;
7
7
  }
8
- interface HeaderState {
9
- isSidebarOpened: boolean;
10
- activeItemIndex: number;
11
- }
12
- declare class Header extends React.Component<HeaderProps, HeaderState> {
13
- ref: React.RefObject<unknown>;
14
- state: {
15
- isSidebarOpened: boolean;
16
- activeItemIndex: number;
17
- };
18
- render(): JSX.Element;
19
- private renderLeft;
20
- private renderLogo;
21
- private renderRight;
22
- private renderRightItems;
23
- private renderMobileMenuButton;
24
- private renderMobileNavigation;
25
- private onActiveItemChange;
26
- private onSidebarOpenedChange;
27
- private hideSidebar;
28
- }
8
+ export declare const Header: React.FC<HeaderProps>;
29
9
  export default Header;
@@ -1,79 +1,53 @@
1
- import React, { createRef } from 'react';
1
+ import React, { useCallback, useState } from 'react';
2
2
  import block from 'bem-cn-lite';
3
3
  import { Col, Grid, Row } from '../../../../grid';
4
4
  import OutsideClick from '../../../OutsideClick/OutsideClick';
5
5
  import Control from '../../../Control/Control';
6
- import Logo from '../Logo/Logo';
7
6
  import Navigation from '../Navigation/Navigation';
8
7
  import MobileNavigation from '../MobileNavigation/MobileNavigation';
9
8
  import NavigationItem from '../NavigationItem/NavigationItem';
9
+ import Logo from '../Logo/Logo';
10
10
  import { NavigationClose, NavigationOpen } from '../../../../icons';
11
11
  import './Header.css';
12
12
  const b = block('header');
13
- class Header extends React.Component {
14
- constructor() {
15
- super(...arguments);
16
- this.ref = createRef();
17
- this.state = {
18
- isSidebarOpened: false,
19
- activeItemIndex: -1,
20
- };
21
- this.onActiveItemChange = (index) => {
22
- this.setState({ activeItemIndex: index });
23
- };
24
- this.onSidebarOpenedChange = (isSidebarOpened) => {
25
- this.setState({ isSidebarOpened });
26
- };
27
- this.hideSidebar = () => {
28
- this.setState({ isSidebarOpened: false });
29
- };
30
- }
31
- render() {
32
- return (React.createElement(Grid, { className: b() },
33
- React.createElement(Row, null,
34
- React.createElement(Col, null,
35
- React.createElement("header", { className: b('wrapper') },
36
- this.renderLogo(),
37
- this.renderLeft(),
38
- this.renderRight(),
39
- this.renderMobileNavigation())))));
40
- }
41
- renderLeft() {
42
- const { activeItemIndex } = this.state;
43
- const { leftItems } = this.props.data;
44
- return (leftItems && (React.createElement("div", { className: b('navigation-container') },
45
- React.createElement(Navigation, { className: b('navigation'), links: leftItems, activeItemIndex: activeItemIndex, onActiveItemChange: this.onActiveItemChange }))));
46
- }
47
- renderLogo() {
48
- const { logo } = this.props;
49
- if (!logo) {
50
- return null;
51
- }
52
- return (React.createElement("div", { className: b('left') },
53
- React.createElement(Logo, Object.assign({}, logo, { className: b('logo') }))));
54
- }
55
- renderRight() {
56
- return (React.createElement("div", { className: b('right') },
57
- this.renderMobileMenuButton(),
58
- this.renderRightItems()));
59
- }
60
- renderRightItems() {
61
- const { rightItems } = this.props.data;
62
- return (rightItems && (React.createElement("div", { className: b('buttons') }, rightItems.map((button) => (React.createElement(NavigationItem, { key: button.text, data: button, className: b('button') }))))));
63
- }
64
- renderMobileMenuButton() {
65
- const { isSidebarOpened } = this.state;
13
+ export const Header = ({ data, logo }) => {
14
+ const { leftItems, rightItems } = data;
15
+ const [isSidebarOpened, setIsSidebarOpened] = useState(false);
16
+ const [activeItemIndex, setActiveItemIndex] = useState(-1);
17
+ const onActiveItemChange = useCallback((index) => {
18
+ setActiveItemIndex(index);
19
+ }, []);
20
+ const onSidebarOpenedChange = useCallback((isOpen) => {
21
+ setIsSidebarOpened(isOpen);
22
+ }, []);
23
+ const hideSidebar = useCallback(() => {
24
+ setIsSidebarOpened(false);
25
+ }, []);
26
+ const renderLogo = (React.createElement("div", { className: b('left') },
27
+ React.createElement(Logo, Object.assign({}, logo, { className: b('logo') }))));
28
+ const renderLeft = (React.createElement("div", { className: b('navigation-container') },
29
+ React.createElement(Navigation, { className: b('navigation'), links: leftItems, activeItemIndex: activeItemIndex, onActiveItemChange: onActiveItemChange })));
30
+ const renderMobileMenuButton = () => {
66
31
  const iconProps = { icon: isSidebarOpened ? NavigationClose : NavigationOpen, iconSize: 36 };
67
32
  return (React.createElement(Control, Object.assign({ className: b('mobile-menu-button'), onClick: (e) => {
68
33
  e.stopPropagation();
69
- this.onSidebarOpenedChange(!isSidebarOpened);
34
+ onSidebarOpenedChange(!isSidebarOpened);
70
35
  }, size: "l" }, iconProps)));
71
- }
72
- renderMobileNavigation() {
73
- const { leftItems, rightItems } = this.props.data;
74
- const { isSidebarOpened, activeItemIndex } = this.state;
75
- return (React.createElement(OutsideClick, { onOutsideClick: () => this.onSidebarOpenedChange(false) },
76
- React.createElement(MobileNavigation, { topItems: leftItems, bottomItems: rightItems, isOpened: isSidebarOpened, activeItemIndex: activeItemIndex, onActiveItemChange: this.onActiveItemChange, onClose: this.hideSidebar })));
77
- }
78
- }
36
+ };
37
+ const renderRightItems = (React.createElement("div", { className: b('buttons') }, rightItems &&
38
+ rightItems.map((button) => (React.createElement(NavigationItem, { key: button.text, data: button, className: b('button') })))));
39
+ const renderRight = (React.createElement("div", { className: b('right') },
40
+ renderMobileMenuButton(),
41
+ rightItems && renderRightItems));
42
+ const renderMobileNavigation = (React.createElement(OutsideClick, { onOutsideClick: () => onSidebarOpenedChange(false) },
43
+ React.createElement(MobileNavigation, { topItems: leftItems, bottomItems: rightItems, isOpened: isSidebarOpened, activeItemIndex: activeItemIndex, onActiveItemChange: onActiveItemChange, onClose: hideSidebar })));
44
+ return (React.createElement(Grid, { className: b() },
45
+ React.createElement(Row, null,
46
+ React.createElement(Col, null,
47
+ React.createElement("header", { className: b('wrapper') },
48
+ logo && renderLogo,
49
+ leftItems && renderLeft,
50
+ renderRight,
51
+ renderMobileNavigation)))));
52
+ };
79
53
  export default Header;
@@ -9,7 +9,7 @@ unpredictable css rules order in build */
9
9
  border-bottom-right-radius: var(--pc-border-radius);
10
10
  border-bottom-left-radius: var(--pc-border-radius);
11
11
  background-color: var(--yc-color-base-background);
12
- box-shadow: 0px 3px 10px var(--yc-color-sfx-shadow);
12
+ box-shadow: 0 3px 10px var(--yc-color-sfx-shadow);
13
13
  font-size: var(--yc-text-body-2-font-size);
14
14
  line-height: var(--yc-text-body-2-line-height);
15
15
  }
@@ -8,7 +8,6 @@ export interface NavigationItemProps {
8
8
  className?: string;
9
9
  onClick?: MouseEventHandler;
10
10
  isOpened?: boolean;
11
- hostname?: string;
12
11
  }
13
12
  declare const NavigationItem: React.FC<NavigationItemProps>;
14
13
  export default NavigationItem;
@@ -21,16 +21,20 @@ const NavigationDropdown = (_a) => {
21
21
  React.createElement(ToggleArrow, { className: b('dropdown'), size: 12, type: 'vertical', iconType: "navigation", open: isOpened })));
22
22
  };
23
23
  const NavigationLink = (props) => {
24
- const { hostname: locationHostname } = useContext(LocationContext);
25
- const { url, text, icon, arrow, target, hostname } = props, rest = __rest(props, ["url", "text", "icon", "arrow", "target", "hostname"]);
26
- const currentHostname = locationHostname || hostname;
27
- const linkExtraProps = getLinkProps(url, currentHostname, target);
24
+ const { hostname, Link } = useContext(LocationContext);
25
+ const { url, text, icon, arrow, target } = props, rest = __rest(props, ["url", "text", "icon", "arrow", "target"]);
26
+ const linkExtraProps = getLinkProps(url, hostname, target);
28
27
  const iconData = icon && getMediaImage(icon);
29
28
  const content = (React.createElement(Fragment, null,
30
29
  React.createElement(Content, { text: text, icon: iconData }),
31
30
  arrow && React.createElement(NavigationArrow, { className: b('arrow') })));
32
- return (linkExtraProps === null || linkExtraProps === void 0 ? void 0 : linkExtraProps.target) ? (React.createElement("a", Object.assign({ href: url, title: text }, rest, linkExtraProps), content)) : (React.createElement(RouterLink, { href: url, passHref: true },
33
- React.createElement("a", Object.assign({}, rest), content)));
31
+ if ((linkExtraProps === null || linkExtraProps === void 0 ? void 0 : linkExtraProps.target) || !Link) {
32
+ return (React.createElement("a", Object.assign({ href: url, title: text }, rest, linkExtraProps), content));
33
+ }
34
+ else {
35
+ return (React.createElement(RouterLink, { href: url, passHref: true },
36
+ React.createElement("a", Object.assign({}, rest), content)));
37
+ }
34
38
  };
35
39
  const NavigationButton = (props) => {
36
40
  const { url, target } = props;
@@ -1,16 +1,14 @@
1
1
  import _ from 'lodash';
2
2
  import block from 'bem-cn-lite';
3
- import React, { Fragment, useRef, useState, useEffect, useCallback, useContext } from 'react';
3
+ import React, { Fragment, useRef, useState, useEffect, useCallback } from 'react';
4
4
  import { Portal } from '@gravity-ui/uikit';
5
5
  import { OutsideClick } from '../../../index';
6
6
  import NavigationItem from '../NavigationItem/NavigationItem';
7
7
  import './NavigationPopup.css';
8
- import { LocationContext } from '../../../../context/locationContext';
9
8
  const b = block('navigation-popup');
10
9
  export const NavigationPopup = ({ items, left, onClose }) => {
11
10
  const [calculatedLeft, setCalculatedLeft] = useState(left);
12
11
  const popupRef = useRef(null);
13
- const { hostname } = useContext(LocationContext);
14
12
  const calculateLeft = useCallback(() => {
15
13
  if (popupRef && popupRef.current && left) {
16
14
  const right = left + popupRef.current.offsetWidth;
@@ -36,7 +34,7 @@ export const NavigationPopup = ({ items, left, onClose }) => {
36
34
  if (!document || !document.body) {
37
35
  return null;
38
36
  }
39
- const renderDefaultPopup = (React.createElement(Fragment, null, items.map((item) => (React.createElement(NavigationItem, { key: item.text, className: b('link'), data: item, hostname: hostname })))));
37
+ const renderDefaultPopup = (React.createElement(Fragment, null, items.map((item) => (React.createElement(NavigationItem, { key: item.text, className: b('link'), data: item })))));
40
38
  return (React.createElement(Portal, null,
41
39
  React.createElement("div", { ref: popupRef, className: b(), style: { left: calculatedLeft } },
42
40
  React.createElement(OutsideClick, { onOutsideClick: onClose }, renderDefaultPopup))));
@@ -15,7 +15,6 @@ export interface NavigationLinkItem extends NavigationItemBase {
15
15
  url: string;
16
16
  arrow?: boolean;
17
17
  target?: string;
18
- hostname?: string;
19
18
  }
20
19
  export interface NavigationButtonItem extends ButtonProps {
21
20
  type: NavigationItemType.Button;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "1.7.0-alpha.4",
3
+ "version": "1.7.0-alpha.6",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -15,7 +15,6 @@ export interface NavigationLinkItem extends NavigationItemBase {
15
15
  url: string;
16
16
  arrow?: boolean;
17
17
  target?: string;
18
- hostname?: string;
19
18
  }
20
19
  export interface NavigationButtonItem extends ButtonProps {
21
20
  type: NavigationItemType.Button;
@@ -1,24 +0,0 @@
1
- import React, { RefObject } from 'react';
2
- import { NavigationLinkItem } from '../../../../models/navigation';
3
- export interface NavigationPopupProps {
4
- items: NavigationLinkItem[];
5
- onClose: () => void;
6
- left?: number;
7
- className?: string;
8
- }
9
- interface NavigationPopupState {
10
- calculatedLeft?: number;
11
- }
12
- export default class NavigationPopup extends React.Component<NavigationPopupProps, NavigationPopupState> {
13
- ref: RefObject<HTMLDivElement>;
14
- state: {
15
- calculatedLeft: number | undefined;
16
- };
17
- private calculateLeft;
18
- componentDidMount(): void;
19
- componentDidUpdate(prevProps: NavigationPopupProps): void;
20
- componentWillUnmount(): void;
21
- render(): JSX.Element | null;
22
- private renderDefaultPopup;
23
- }
24
- export {};
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
5
- const bem_cn_lite_1 = (0, tslib_1.__importDefault)(require("bem-cn-lite"));
6
- const react_1 = (0, tslib_1.__importStar)(require("react"));
7
- const uikit_1 = require("@gravity-ui/uikit");
8
- const index_1 = require("../../../index");
9
- const NavigationItem_1 = (0, tslib_1.__importDefault)(require("../NavigationItem/NavigationItem"));
10
- const b = (0, bem_cn_lite_1.default)('navigation-popup');
11
- class NavigationPopup extends react_1.default.Component {
12
- constructor() {
13
- super(...arguments);
14
- this.ref = (0, react_1.createRef)();
15
- this.state = {
16
- calculatedLeft: this.props.left,
17
- };
18
- this.calculateLeft = lodash_1.default.debounce(() => {
19
- const { left } = this.props;
20
- if (this.ref && this.ref.current && left) {
21
- const right = left + this.ref.current.offsetWidth;
22
- const docWidth = document.body.clientWidth;
23
- const calculatedLeft = right > docWidth ? left - (right - docWidth) : left;
24
- this.setState({ calculatedLeft });
25
- }
26
- else {
27
- this.setState({ calculatedLeft: left });
28
- }
29
- }, 100);
30
- }
31
- componentDidMount() {
32
- this.calculateLeft();
33
- window.addEventListener('resize', this.calculateLeft);
34
- }
35
- componentDidUpdate(prevProps) {
36
- if (prevProps.left !== this.props.left) {
37
- this.calculateLeft();
38
- }
39
- }
40
- componentWillUnmount() {
41
- window.removeEventListener('resize', this.calculateLeft);
42
- }
43
- render() {
44
- if (!document || !document.body) {
45
- return null;
46
- }
47
- const { onClose } = this.props;
48
- const { calculatedLeft } = this.state;
49
- return (react_1.default.createElement(uikit_1.Portal, null,
50
- react_1.default.createElement("div", { ref: this.ref, className: b(), style: { left: calculatedLeft } },
51
- react_1.default.createElement(index_1.OutsideClick, { onOutsideClick: onClose }, this.renderDefaultPopup()))));
52
- }
53
- renderDefaultPopup() {
54
- return (react_1.default.createElement(react_1.Fragment, null, this.props.items.map((item) => (react_1.default.createElement(NavigationItem_1.default, { key: item.text, className: b('link'), data: item })))));
55
- }
56
- }
57
- exports.default = NavigationPopup;
@@ -1,25 +0,0 @@
1
- import React, { RefObject } from 'react';
2
- import { NavigationLinkItem } from '../../../../models/navigation';
3
- import './NavigationPopup.css';
4
- export interface NavigationPopupProps {
5
- items: NavigationLinkItem[];
6
- onClose: () => void;
7
- left?: number;
8
- className?: string;
9
- }
10
- interface NavigationPopupState {
11
- calculatedLeft?: number;
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 {};
@@ -1,54 +0,0 @@
1
- import _ from 'lodash';
2
- import block from 'bem-cn-lite';
3
- import React, { Fragment, createRef } from 'react';
4
- import { Portal } from '@gravity-ui/uikit';
5
- import { OutsideClick } from '../../../index';
6
- import NavigationItem from '../NavigationItem/NavigationItem';
7
- import './NavigationPopup.css';
8
- const b = block('navigation-popup');
9
- export default class NavigationPopup extends React.Component {
10
- constructor() {
11
- super(...arguments);
12
- this.ref = createRef();
13
- this.state = {
14
- calculatedLeft: this.props.left,
15
- };
16
- this.calculateLeft = _.debounce(() => {
17
- const { left } = this.props;
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();
36
- }
37
- }
38
- componentWillUnmount() {
39
- window.removeEventListener('resize', this.calculateLeft);
40
- }
41
- render() {
42
- if (!document || !document.body) {
43
- return null;
44
- }
45
- const { onClose } = this.props;
46
- const { calculatedLeft } = this.state;
47
- return (React.createElement(Portal, null,
48
- React.createElement("div", { ref: this.ref, className: b(), style: { left: calculatedLeft } },
49
- React.createElement(OutsideClick, { onOutsideClick: onClose }, this.renderDefaultPopup()))));
50
- }
51
- renderDefaultPopup() {
52
- return (React.createElement(Fragment, null, this.props.items.map((item) => (React.createElement(NavigationItem, { key: item.text, className: b('link'), data: item })))));
53
- }
54
- }