@gravity-ui/page-constructor 1.22.1-alpha.1 → 1.22.1-alpha.3
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/build/cjs/navigation/components/Header/Header.css +2 -0
- package/build/cjs/navigation/components/Header/Header.js +1 -18
- package/build/cjs/navigation/components/NavigationDropdownItem/NavigationDropdownItem.js +2 -2
- package/build/cjs/navigation/components/NavigationListItem/NavigationListItem.d.ts +2 -2
- package/build/cjs/navigation/components/NavigationListItem/NavigationListItem.js +5 -3
- package/build/esm/navigation/components/Header/Header.css +2 -0
- package/build/esm/navigation/components/Header/Header.js +2 -19
- package/build/esm/navigation/components/NavigationDropdownItem/NavigationDropdownItem.js +2 -2
- package/build/esm/navigation/components/NavigationListItem/NavigationListItem.d.ts +2 -2
- package/build/esm/navigation/components/NavigationListItem/NavigationListItem.js +5 -3
- package/package.json +1 -1
|
@@ -41,6 +41,8 @@ unpredictable css rules order in build */
|
|
|
41
41
|
.pc-header__right {
|
|
42
42
|
flex: 0;
|
|
43
43
|
justify-content: flex-end;
|
|
44
|
+
font-size: var(--yc-text-body-2-font-size);
|
|
45
|
+
line-height: var(--yc-text-body-2-line-height);
|
|
44
46
|
}
|
|
45
47
|
.pc-header__navigation-container {
|
|
46
48
|
display: flex;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Header = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
7
6
|
const utils_1 = require("../../../utils");
|
|
8
7
|
const grid_1 = require("../../../grid");
|
|
9
8
|
const OutsideClick_1 = tslib_1.__importDefault(require("../../../components/OutsideClick/OutsideClick"));
|
|
@@ -30,8 +29,6 @@ const Header = ({ data, logo }) => {
|
|
|
30
29
|
const { leftItems, rightItems } = data;
|
|
31
30
|
const [isSidebarOpened, setIsSidebarOpened] = (0, react_1.useState)(false);
|
|
32
31
|
const [activeItemId, setactiveItemId] = (0, react_1.useState)('');
|
|
33
|
-
const [itemPositions, setItemPosition] = (0, react_1.useState)([]);
|
|
34
|
-
const itemRefs = (0, react_1.useRef)([]);
|
|
35
32
|
const onActiveItemChange = (0, react_1.useCallback)((index = '') => {
|
|
36
33
|
setactiveItemId(index);
|
|
37
34
|
}, []);
|
|
@@ -44,20 +41,6 @@ const Header = ({ data, logo }) => {
|
|
|
44
41
|
const hideSidebar = (0, react_1.useCallback)(() => {
|
|
45
42
|
setIsSidebarOpened(false);
|
|
46
43
|
}, []);
|
|
47
|
-
const calculateItemPositions = (0, react_1.useCallback)(() => {
|
|
48
|
-
if (itemRefs.current.length) {
|
|
49
|
-
const currentItemPositions = itemRefs.current.map((itemRef) => (itemRef && itemRef.getBoundingClientRect().left) || 0);
|
|
50
|
-
setItemPosition(currentItemPositions);
|
|
51
|
-
}
|
|
52
|
-
}, []);
|
|
53
|
-
(0, react_1.useEffect)(() => {
|
|
54
|
-
const debouncedCalculateItemPositions = lodash_1.default.debounce(calculateItemPositions, 100);
|
|
55
|
-
calculateItemPositions();
|
|
56
|
-
window.addEventListener('resize', debouncedCalculateItemPositions);
|
|
57
|
-
return () => {
|
|
58
|
-
window.removeEventListener(`resize`, calculateItemPositions);
|
|
59
|
-
};
|
|
60
|
-
}, [calculateItemPositions, itemRefs]);
|
|
61
44
|
return (react_1.default.createElement(grid_1.Grid, { className: b() },
|
|
62
45
|
react_1.default.createElement(grid_1.Row, null,
|
|
63
46
|
react_1.default.createElement(grid_1.Col, null,
|
|
@@ -68,7 +51,7 @@ const Header = ({ data, logo }) => {
|
|
|
68
51
|
react_1.default.createElement(Navigation_1.default, { className: b('navigation'), links: leftItems, activeItemId: activeItemId, onActiveItemChange: onActiveItemChange })),
|
|
69
52
|
react_1.default.createElement("div", { className: b('right') },
|
|
70
53
|
react_1.default.createElement(MobileMenuButton, { isSidebarOpened: isSidebarOpened, onSidebarOpenedChange: onSidebarOpenedChange }),
|
|
71
|
-
rightItems && (react_1.default.createElement("ul", { className: b('buttons') }, rightItems.map((button, index) => (react_1.default.createElement(NavigationListItem_1.NavigationListItem, { key: index, className: b('buttons-item'), item: button,
|
|
54
|
+
rightItems && (react_1.default.createElement("ul", { className: b('buttons') }, rightItems.map((button, index) => (react_1.default.createElement(NavigationListItem_1.NavigationListItem, { key: index, className: b('buttons-item'), item: button, index: index, activeItemId: activeItemId, hidePopup: hidePopup, column: constants_1.ItemColumnName.Right, onActiveItemChange: onActiveItemChange })))))),
|
|
72
55
|
react_1.default.createElement(OutsideClick_1.default, { onOutsideClick: () => onSidebarOpenedChange(false) },
|
|
73
56
|
react_1.default.createElement(MobileNavigation_1.default, { topItems: leftItems, bottomItems: rightItems, isOpened: isSidebarOpened, activeItemId: activeItemId, onActiveItemChange: onActiveItemChange, onClose: hideSidebar })))))));
|
|
74
57
|
};
|
|
@@ -6,9 +6,9 @@ const models_1 = require("../../../models");
|
|
|
6
6
|
const NavigationItem_1 = tslib_1.__importDefault(require("../NavigationItem/NavigationItem"));
|
|
7
7
|
const NavigationPopup_1 = tslib_1.__importDefault(require("../NavigationPopup/NavigationPopup"));
|
|
8
8
|
const NavigationDropdown = ({ data, isActive, position, hidePopup, onClick, }) => {
|
|
9
|
-
const { text, items } = data, popupProps = tslib_1.__rest(data, ["text", "items"]);
|
|
9
|
+
const { text, icon, items } = data, popupProps = tslib_1.__rest(data, ["text", "icon", "items"]);
|
|
10
10
|
return (react_1.default.createElement(react_1.Fragment, null,
|
|
11
|
-
react_1.default.createElement(NavigationItem_1.default, { onClick: onClick, isOpened: isActive, data: { text, type: models_1.NavigationItemType.Dropdown } }),
|
|
11
|
+
react_1.default.createElement(NavigationItem_1.default, { onClick: onClick, isOpened: isActive, data: { text, type: models_1.NavigationItemType.Dropdown, icon } }),
|
|
12
12
|
isActive && (react_1.default.createElement(NavigationPopup_1.default, Object.assign({ left: position, onClose: hidePopup, items: items }, popupProps)))));
|
|
13
13
|
};
|
|
14
14
|
exports.default = NavigationDropdown;
|
|
@@ -3,13 +3,13 @@ import { ClassNameProps, NavigationItemModel } from '../../../models';
|
|
|
3
3
|
import { ItemColumnName } from '../../constants';
|
|
4
4
|
type NavigationListItemProps = {
|
|
5
5
|
item: NavigationItemModel;
|
|
6
|
-
itemRefs: React.MutableRefObject<(HTMLLIElement | null)[]>;
|
|
7
6
|
index: number;
|
|
8
7
|
activeItemId: string;
|
|
9
8
|
hidePopup: () => void;
|
|
10
|
-
itemPositions: number[];
|
|
11
9
|
column: ItemColumnName;
|
|
12
10
|
onActiveItemChange: (index: string) => void;
|
|
11
|
+
itemPositions?: number[];
|
|
12
|
+
itemRefs?: React.MutableRefObject<(HTMLLIElement | null)[]>;
|
|
13
13
|
highlightActiveItem?: boolean;
|
|
14
14
|
} & ClassNameProps;
|
|
15
15
|
export declare const NavigationListItem: ({ item, itemRefs, className, index, activeItemId, highlightActiveItem, hidePopup, itemPositions, column, onActiveItemChange, }: NavigationListItemProps) => JSX.Element;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NavigationListItem = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const react_1 = tslib_1.
|
|
5
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
const models_1 = require("../../../models");
|
|
8
8
|
const utils_2 = require("../../utils");
|
|
@@ -10,6 +10,8 @@ const NavigationDropdownItem_1 = tslib_1.__importDefault(require("../NavigationD
|
|
|
10
10
|
const NavigationItem_1 = tslib_1.__importDefault(require("../NavigationItem/NavigationItem"));
|
|
11
11
|
const b = (0, utils_1.block)('navigation');
|
|
12
12
|
const NavigationListItem = ({ item, itemRefs, className, index, activeItemId, highlightActiveItem, hidePopup, itemPositions, column, onActiveItemChange, }) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const ref = (0, react_1.useRef)(null);
|
|
13
15
|
const id = `${column}-${index}`;
|
|
14
16
|
const isActive = id === activeItemId;
|
|
15
17
|
const onClick = (0, utils_2.getItemClickHandler)({
|
|
@@ -18,8 +20,8 @@ const NavigationListItem = ({ item, itemRefs, className, index, activeItemId, hi
|
|
|
18
20
|
activeItemId,
|
|
19
21
|
onActiveItemChange,
|
|
20
22
|
});
|
|
21
|
-
return (react_1.default.createElement("li", { ref: (el) => itemRefs.current.push(el), className: className },
|
|
22
|
-
item.type === models_1.NavigationItemType.Dropdown ? (react_1.default.createElement(NavigationDropdownItem_1.default, { data: item, onClick: onClick, isActive: isActive, position: itemPositions[index], hidePopup: hidePopup })) : (react_1.default.createElement(NavigationItem_1.default, { data: item, onClick: onClick })),
|
|
23
|
+
return (react_1.default.createElement("li", { ref: itemRefs ? (el) => itemRefs.current.push(el) : ref, className: className },
|
|
24
|
+
item.type === models_1.NavigationItemType.Dropdown ? (react_1.default.createElement(NavigationDropdownItem_1.default, { data: item, onClick: onClick, isActive: isActive, position: (itemPositions === null || itemPositions === void 0 ? void 0 : itemPositions[index]) || ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().left) || 0, hidePopup: hidePopup })) : (react_1.default.createElement(NavigationItem_1.default, { data: item, onClick: onClick })),
|
|
23
25
|
highlightActiveItem && isActive && (react_1.default.createElement("div", { className: b('slider-container') },
|
|
24
26
|
react_1.default.createElement("div", { className: b('slider') })))));
|
|
25
27
|
};
|
|
@@ -41,6 +41,8 @@ unpredictable css rules order in build */
|
|
|
41
41
|
.pc-header__right {
|
|
42
42
|
flex: 0;
|
|
43
43
|
justify-content: flex-end;
|
|
44
|
+
font-size: var(--yc-text-body-2-font-size);
|
|
45
|
+
line-height: var(--yc-text-body-2-line-height);
|
|
44
46
|
}
|
|
45
47
|
.pc-header__navigation-container {
|
|
46
48
|
display: flex;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import React, { useCallback,
|
|
2
|
-
import _ from 'lodash';
|
|
1
|
+
import React, { useCallback, useState } from 'react';
|
|
3
2
|
import { block } from '../../../utils';
|
|
4
3
|
import { Col, Grid, Row } from '../../../grid';
|
|
5
4
|
import OutsideClick from '../../../components/OutsideClick/OutsideClick';
|
|
@@ -27,8 +26,6 @@ export const Header = ({ data, logo }) => {
|
|
|
27
26
|
const { leftItems, rightItems } = data;
|
|
28
27
|
const [isSidebarOpened, setIsSidebarOpened] = useState(false);
|
|
29
28
|
const [activeItemId, setactiveItemId] = useState('');
|
|
30
|
-
const [itemPositions, setItemPosition] = useState([]);
|
|
31
|
-
const itemRefs = useRef([]);
|
|
32
29
|
const onActiveItemChange = useCallback((index = '') => {
|
|
33
30
|
setactiveItemId(index);
|
|
34
31
|
}, []);
|
|
@@ -41,20 +38,6 @@ export const Header = ({ data, logo }) => {
|
|
|
41
38
|
const hideSidebar = useCallback(() => {
|
|
42
39
|
setIsSidebarOpened(false);
|
|
43
40
|
}, []);
|
|
44
|
-
const calculateItemPositions = useCallback(() => {
|
|
45
|
-
if (itemRefs.current.length) {
|
|
46
|
-
const currentItemPositions = itemRefs.current.map((itemRef) => (itemRef && itemRef.getBoundingClientRect().left) || 0);
|
|
47
|
-
setItemPosition(currentItemPositions);
|
|
48
|
-
}
|
|
49
|
-
}, []);
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
const debouncedCalculateItemPositions = _.debounce(calculateItemPositions, 100);
|
|
52
|
-
calculateItemPositions();
|
|
53
|
-
window.addEventListener('resize', debouncedCalculateItemPositions);
|
|
54
|
-
return () => {
|
|
55
|
-
window.removeEventListener(`resize`, calculateItemPositions);
|
|
56
|
-
};
|
|
57
|
-
}, [calculateItemPositions, itemRefs]);
|
|
58
41
|
return (React.createElement(Grid, { className: b() },
|
|
59
42
|
React.createElement(Row, null,
|
|
60
43
|
React.createElement(Col, null,
|
|
@@ -65,7 +48,7 @@ export const Header = ({ data, logo }) => {
|
|
|
65
48
|
React.createElement(Navigation, { className: b('navigation'), links: leftItems, activeItemId: activeItemId, onActiveItemChange: onActiveItemChange })),
|
|
66
49
|
React.createElement("div", { className: b('right') },
|
|
67
50
|
React.createElement(MobileMenuButton, { isSidebarOpened: isSidebarOpened, onSidebarOpenedChange: onSidebarOpenedChange }),
|
|
68
|
-
rightItems && (React.createElement("ul", { className: b('buttons') }, rightItems.map((button, index) => (React.createElement(NavigationListItem, { key: index, className: b('buttons-item'), item: button,
|
|
51
|
+
rightItems && (React.createElement("ul", { className: b('buttons') }, rightItems.map((button, index) => (React.createElement(NavigationListItem, { key: index, className: b('buttons-item'), item: button, index: index, activeItemId: activeItemId, hidePopup: hidePopup, column: ItemColumnName.Right, onActiveItemChange: onActiveItemChange })))))),
|
|
69
52
|
React.createElement(OutsideClick, { onOutsideClick: () => onSidebarOpenedChange(false) },
|
|
70
53
|
React.createElement(MobileNavigation, { topItems: leftItems, bottomItems: rightItems, isOpened: isSidebarOpened, activeItemId: activeItemId, onActiveItemChange: onActiveItemChange, onClose: hideSidebar })))))));
|
|
71
54
|
};
|
|
@@ -4,9 +4,9 @@ import { NavigationItemType } from '../../../models';
|
|
|
4
4
|
import NavigationItem from '../NavigationItem/NavigationItem';
|
|
5
5
|
import NavigationPopup from '../NavigationPopup/NavigationPopup';
|
|
6
6
|
const NavigationDropdown = ({ data, isActive, position, hidePopup, onClick, }) => {
|
|
7
|
-
const { text, items } = data, popupProps = __rest(data, ["text", "items"]);
|
|
7
|
+
const { text, icon, items } = data, popupProps = __rest(data, ["text", "icon", "items"]);
|
|
8
8
|
return (React.createElement(Fragment, null,
|
|
9
|
-
React.createElement(NavigationItem, { onClick: onClick, isOpened: isActive, data: { text, type: NavigationItemType.Dropdown } }),
|
|
9
|
+
React.createElement(NavigationItem, { onClick: onClick, isOpened: isActive, data: { text, type: NavigationItemType.Dropdown, icon } }),
|
|
10
10
|
isActive && (React.createElement(NavigationPopup, Object.assign({ left: position, onClose: hidePopup, items: items }, popupProps)))));
|
|
11
11
|
};
|
|
12
12
|
export default NavigationDropdown;
|
|
@@ -4,13 +4,13 @@ import { ItemColumnName } from '../../constants';
|
|
|
4
4
|
import './NavigationListItem.css';
|
|
5
5
|
type NavigationListItemProps = {
|
|
6
6
|
item: NavigationItemModel;
|
|
7
|
-
itemRefs: React.MutableRefObject<(HTMLLIElement | null)[]>;
|
|
8
7
|
index: number;
|
|
9
8
|
activeItemId: string;
|
|
10
9
|
hidePopup: () => void;
|
|
11
|
-
itemPositions: number[];
|
|
12
10
|
column: ItemColumnName;
|
|
13
11
|
onActiveItemChange: (index: string) => void;
|
|
12
|
+
itemPositions?: number[];
|
|
13
|
+
itemRefs?: React.MutableRefObject<(HTMLLIElement | null)[]>;
|
|
14
14
|
highlightActiveItem?: boolean;
|
|
15
15
|
} & ClassNameProps;
|
|
16
16
|
export declare const NavigationListItem: ({ item, itemRefs, className, index, activeItemId, highlightActiveItem, hidePopup, itemPositions, column, onActiveItemChange, }: NavigationListItemProps) => JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
2
|
import { block } from '../../../utils';
|
|
3
3
|
import { NavigationItemType } from '../../../models';
|
|
4
4
|
import { getItemClickHandler } from '../../utils';
|
|
@@ -7,6 +7,8 @@ import NavigationItem from '../NavigationItem/NavigationItem';
|
|
|
7
7
|
import './NavigationListItem.css';
|
|
8
8
|
const b = block('navigation');
|
|
9
9
|
export const NavigationListItem = ({ item, itemRefs, className, index, activeItemId, highlightActiveItem, hidePopup, itemPositions, column, onActiveItemChange, }) => {
|
|
10
|
+
var _a;
|
|
11
|
+
const ref = useRef(null);
|
|
10
12
|
const id = `${column}-${index}`;
|
|
11
13
|
const isActive = id === activeItemId;
|
|
12
14
|
const onClick = getItemClickHandler({
|
|
@@ -15,8 +17,8 @@ export const NavigationListItem = ({ item, itemRefs, className, index, activeIte
|
|
|
15
17
|
activeItemId,
|
|
16
18
|
onActiveItemChange,
|
|
17
19
|
});
|
|
18
|
-
return (React.createElement("li", { ref: (el) => itemRefs.current.push(el), className: className },
|
|
19
|
-
item.type === NavigationItemType.Dropdown ? (React.createElement(NavigationDropdownItem, { data: item, onClick: onClick, isActive: isActive, position: itemPositions[index], hidePopup: hidePopup })) : (React.createElement(NavigationItem, { data: item, onClick: onClick })),
|
|
20
|
+
return (React.createElement("li", { ref: itemRefs ? (el) => itemRefs.current.push(el) : ref, className: className },
|
|
21
|
+
item.type === NavigationItemType.Dropdown ? (React.createElement(NavigationDropdownItem, { data: item, onClick: onClick, isActive: isActive, position: (itemPositions === null || itemPositions === void 0 ? void 0 : itemPositions[index]) || ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().left) || 0, hidePopup: hidePopup })) : (React.createElement(NavigationItem, { data: item, onClick: onClick })),
|
|
20
22
|
highlightActiveItem && isActive && (React.createElement("div", { className: b('slider-container') },
|
|
21
23
|
React.createElement("div", { className: b('slider') })))));
|
|
22
24
|
};
|