@gravity-ui/page-constructor 1.16.4 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/build/cjs/components/BackLink/__tests__/BackLink.test.d.ts +1 -0
  3. package/build/cjs/components/BackLink/__tests__/BackLink.test.js +63 -0
  4. package/build/cjs/components/Button/Button.css +2 -0
  5. package/build/cjs/components/OverflowScroller/OverflowScroller.css +16 -5
  6. package/build/cjs/components/OverflowScroller/OverflowScroller.d.ts +1 -1
  7. package/build/cjs/components/OverflowScroller/OverflowScroller.js +13 -5
  8. package/build/cjs/models/navigation.d.ts +9 -3
  9. package/build/cjs/models/navigation.js +1 -0
  10. package/build/cjs/navigation/components/Header/Header.css +2 -2
  11. package/build/cjs/navigation/components/Header/Header.js +1 -1
  12. package/build/cjs/navigation/components/NavigationItem/NavigationItem.css +0 -35
  13. package/build/cjs/navigation/components/NavigationItem/NavigationItem.js +9 -39
  14. package/build/cjs/navigation/components/NavigationItem/components/ContentWrapper/ContentWrapper.css +7 -0
  15. package/build/cjs/navigation/components/NavigationItem/components/ContentWrapper/ContentWrapper.d.ts +6 -0
  16. package/build/cjs/navigation/components/NavigationItem/components/ContentWrapper/ContentWrapper.js +12 -0
  17. package/build/cjs/navigation/components/NavigationItem/components/GithubStars/GithubStars.css +10 -0
  18. package/build/cjs/navigation/components/NavigationItem/components/GithubStars/GithubStars.d.ts +5 -0
  19. package/build/cjs/navigation/components/NavigationItem/components/GithubStars/GithubStars.js +11 -0
  20. package/build/cjs/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.css +3 -0
  21. package/build/cjs/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.d.ts +6 -0
  22. package/build/cjs/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.js +15 -0
  23. package/build/cjs/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.css +4 -0
  24. package/build/cjs/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.d.ts +6 -0
  25. package/build/cjs/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.js +19 -0
  26. package/build/cjs/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.css +21 -0
  27. package/build/cjs/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.d.ts +6 -0
  28. package/build/cjs/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.js +30 -0
  29. package/build/esm/components/BackLink/__tests__/BackLink.test.d.ts +1 -0
  30. package/build/esm/components/BackLink/__tests__/BackLink.test.js +60 -0
  31. package/build/esm/components/Button/Button.css +2 -0
  32. package/build/esm/components/OverflowScroller/OverflowScroller.css +16 -5
  33. package/build/esm/components/OverflowScroller/OverflowScroller.d.ts +1 -1
  34. package/build/esm/components/OverflowScroller/OverflowScroller.js +13 -5
  35. package/build/esm/models/navigation.d.ts +9 -3
  36. package/build/esm/models/navigation.js +1 -0
  37. package/build/esm/navigation/components/Header/Header.css +2 -2
  38. package/build/esm/navigation/components/Header/Header.js +1 -1
  39. package/build/esm/navigation/components/NavigationItem/NavigationItem.css +0 -35
  40. package/build/esm/navigation/components/NavigationItem/NavigationItem.js +9 -39
  41. package/build/esm/navigation/components/NavigationItem/components/ContentWrapper/ContentWrapper.css +7 -0
  42. package/build/esm/navigation/components/NavigationItem/components/ContentWrapper/ContentWrapper.d.ts +7 -0
  43. package/build/esm/navigation/components/NavigationItem/components/ContentWrapper/ContentWrapper.js +8 -0
  44. package/build/esm/navigation/components/NavigationItem/components/GithubStars/GithubStars.css +10 -0
  45. package/build/esm/navigation/components/NavigationItem/components/GithubStars/GithubStars.d.ts +6 -0
  46. package/build/esm/navigation/components/NavigationItem/components/GithubStars/GithubStars.js +7 -0
  47. package/build/esm/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.css +3 -0
  48. package/build/esm/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.d.ts +7 -0
  49. package/build/esm/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.js +11 -0
  50. package/build/esm/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.css +4 -0
  51. package/build/esm/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.d.ts +7 -0
  52. package/build/esm/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.js +16 -0
  53. package/build/esm/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.css +21 -0
  54. package/build/esm/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.d.ts +7 -0
  55. package/build/esm/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.js +27 -0
  56. package/package.json +2 -1
  57. package/server/models/navigation.d.ts +9 -3
  58. package/server/models/navigation.js +1 -0
  59. package/styles/mixins.scss +10 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.18.0](https://github.com/gravity-ui/page-constructor/compare/v1.17.0...v1.18.0) (2023-02-28)
4
+
5
+
6
+ ### Features
7
+
8
+ * monochrome mixin moved from 'Button.css' to 'mixins.css' ([#173](https://github.com/gravity-ui/page-constructor/issues/173)) ([6bb35cf](https://github.com/gravity-ui/page-constructor/commit/6bb35cfea50f7c62682404da02f594dd4f90a011))
9
+
10
+ ## [1.17.0](https://github.com/gravity-ui/page-constructor/compare/v1.16.4...v1.17.0) (2023-02-28)
11
+
12
+
13
+ ### Features
14
+
15
+ * **Navigation:** add github star button in navigation ([#159](https://github.com/gravity-ui/page-constructor/issues/159)) ([829d358](https://github.com/gravity-ui/page-constructor/commit/829d3582772378940993c4f676fe08676693266a))
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * remove background from Overlowscroller ([#153](https://github.com/gravity-ui/page-constructor/issues/153)) ([652adfa](https://github.com/gravity-ui/page-constructor/commit/652adfaf92156e1f96a9292d034c5139aac7894c))
21
+
3
22
  ## [1.16.4](https://github.com/gravity-ui/page-constructor/compare/v1.16.3...v1.16.4) (2023-02-22)
4
23
 
5
24
 
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = tslib_1.__importDefault(require("react"));
5
+ const react_2 = require("@testing-library/react");
6
+ const user_event_1 = tslib_1.__importDefault(require("@testing-library/user-event"));
7
+ const BackLink_1 = tslib_1.__importDefault(require("../BackLink"));
8
+ const locationContext_1 = require("../../../context/locationContext");
9
+ const backLinkProps = {
10
+ url: '#',
11
+ title: 'Button Title',
12
+ theme: 'default',
13
+ size: 's',
14
+ className: 'customClassName',
15
+ shouldHandleBackAction: true,
16
+ onClick: () => { },
17
+ };
18
+ describe('BackLink', () => {
19
+ test('Default render', async () => {
20
+ (0, react_2.render)(react_1.default.createElement(BackLink_1.default, Object.assign({}, backLinkProps)));
21
+ const backLink = react_2.screen.getByRole('button');
22
+ expect(backLink).toBeInTheDocument();
23
+ });
24
+ test('Has custom class', async () => {
25
+ (0, react_2.render)(react_1.default.createElement(BackLink_1.default, Object.assign({}, backLinkProps)));
26
+ const backLink = react_2.screen.getByRole('button');
27
+ expect(backLink).toHaveClass(backLinkProps.className);
28
+ });
29
+ test('Should render <a /> tag', async () => {
30
+ (0, react_2.render)(react_1.default.createElement(BackLink_1.default, Object.assign({}, backLinkProps, { shouldHandleBackAction: false })));
31
+ const backLink = react_2.screen.getByRole('link');
32
+ expect(backLink).toBeVisible();
33
+ expect(backLink).toHaveAttribute('href', backLinkProps.url);
34
+ });
35
+ test('Should render title', async () => {
36
+ (0, react_2.render)(react_1.default.createElement(BackLink_1.default, Object.assign({}, backLinkProps)));
37
+ const backLink = react_2.screen.getByText(backLinkProps.title);
38
+ expect(backLink).toBeInTheDocument();
39
+ });
40
+ test('Call onClick', async () => {
41
+ const user = user_event_1.default.setup();
42
+ const handleClick = jest.fn();
43
+ (0, react_2.render)(react_1.default.createElement(locationContext_1.LocationContext.Provider, { value: { history: { push: jest.fn() } } },
44
+ react_1.default.createElement(BackLink_1.default, Object.assign({}, backLinkProps, { onClick: handleClick }))));
45
+ const backLink = react_2.screen.getByRole('button');
46
+ await user.click(backLink);
47
+ expect(handleClick).toHaveBeenCalledTimes(1);
48
+ });
49
+ test.each(new Array('s', 'm', 'l', 'xl'))('Render with given "%s" size', (size) => {
50
+ (0, react_2.render)(react_1.default.createElement(BackLink_1.default, Object.assign({}, backLinkProps, { size: size })));
51
+ const backLink = react_2.screen.getByRole('button');
52
+ expect(backLink).toHaveClass(`yc-button_size_${size}`);
53
+ });
54
+ test.each(new Array('default', 'special'))('Render with given "%s" theme', (theme) => {
55
+ const matchView = {
56
+ default: 'flat-secondary',
57
+ special: 'flat-contrast',
58
+ };
59
+ (0, react_2.render)(react_1.default.createElement(BackLink_1.default, Object.assign({}, backLinkProps, { theme: theme })));
60
+ const backLink = react_2.screen.getByRole('button');
61
+ expect(backLink).toHaveClass(`yc-button_view_${matchView[theme]}`);
62
+ });
63
+ });
@@ -1,3 +1,5 @@
1
+ /* use this for style redefinitions to awoid problems with
2
+ unpredictable css rules order in build */
1
3
  .pc-button-block__content {
2
4
  display: flex;
3
5
  align-items: center;
@@ -1,12 +1,24 @@
1
1
  .pc-overflow-scroller {
2
+ display: flex;
3
+ align-items: center;
2
4
  position: relative;
3
5
  overflow-x: hidden;
4
6
  }
7
+ .pc-overflow-scroller__container {
8
+ width: 100%;
9
+ position: relative;
10
+ }
11
+ .pc-overflow-scroller__container_padding-left {
12
+ padding-left: 24px;
13
+ }
14
+ .pc-overflow-scroller__container_padding-right {
15
+ padding-right: 24px;
16
+ }
5
17
  .pc-overflow-scroller__wrapper {
6
18
  position: relative;
7
- transition: left 0.3s;
19
+ transition: left 0.6s;
8
20
  }
9
- .pc-overflow-scroller__scroller {
21
+ .pc-overflow-scroller__arrow {
10
22
  position: absolute;
11
23
  z-index: 10;
12
24
  top: 0;
@@ -17,12 +29,11 @@
17
29
  height: calc(100% - 1px);
18
30
  cursor: pointer;
19
31
  color: var(--yc-color-text-secondary);
20
- background: linear-gradient(to left, var(--yc-color-base-background) 70%, var(--pc-transparent) 100%) no-repeat;
21
32
  }
22
- .pc-overflow-scroller__scroller_type_left {
33
+ .pc-overflow-scroller__arrow_type_left {
23
34
  left: 0;
24
35
  transform: rotate(180deg);
25
36
  }
26
- .pc-overflow-scroller__scroller_type_right {
37
+ .pc-overflow-scroller__arrow_type_right {
27
38
  right: 0;
28
39
  }
@@ -11,7 +11,7 @@ export interface OverflowScrollerState {
11
11
  }
12
12
  export default class OverflowScroller extends React.Component<PropsWithChildren<OverflowScrollerProps>, OverflowScrollerState> {
13
13
  state: {
14
- arrows: never[];
14
+ arrows: Arrow[];
15
15
  scrollValue: number;
16
16
  };
17
17
  containerRef: React.RefObject<HTMLDivElement>;
@@ -7,6 +7,7 @@ const utils_1 = require("../../utils");
7
7
  const __1 = require("..");
8
8
  const b = (0, utils_1.block)('overflow-scroller');
9
9
  const TRANSITION_TIME = 300;
10
+ const PADDING_SIZE = 24;
10
11
  class OverflowScroller extends react_1.default.Component {
11
12
  constructor() {
12
13
  super(...arguments);
@@ -30,7 +31,7 @@ class OverflowScroller extends react_1.default.Component {
30
31
  }
31
32
  }, 100);
32
33
  this.handleScrollClick = (e, arrow) => {
33
- const { scrollValue } = this.state;
34
+ const { scrollValue, arrows } = this.state;
34
35
  const { onScrollStart } = this.props;
35
36
  if (this.containerRef &&
36
37
  this.containerRef.current &&
@@ -39,8 +40,9 @@ class OverflowScroller extends react_1.default.Component {
39
40
  const containerWidth = this.containerRef.current.offsetWidth;
40
41
  const wrapperWidth = this.wrapperRef.current.offsetWidth;
41
42
  const hiddenWidth = arrow === 'right' ? wrapperWidth - (containerWidth + scrollValue) : scrollValue;
43
+ const padding = arrows.length > 1 && hiddenWidth + PADDING_SIZE > containerWidth ? PADDING_SIZE : 0;
42
44
  const delta = containerWidth > hiddenWidth ? hiddenWidth : containerWidth;
43
- const newScrollValue = arrow === 'right' ? scrollValue + delta : scrollValue - delta;
45
+ const newScrollValue = arrow === 'right' ? scrollValue + delta + padding : scrollValue - delta - padding;
44
46
  let newArrows = ['left', 'right'];
45
47
  if (newScrollValue + containerWidth >= wrapperWidth) {
46
48
  newArrows = ['left'];
@@ -73,9 +75,15 @@ class OverflowScroller extends react_1.default.Component {
73
75
  const { className, children } = this.props;
74
76
  const { arrows, scrollValue } = this.state;
75
77
  const wrapperStyle = arrows.length ? { left: -scrollValue } : { left: 0 };
76
- return (react_1.default.createElement("div", { className: b(null, className), ref: this.containerRef },
77
- react_1.default.createElement("div", { className: b('wrapper'), style: wrapperStyle, ref: this.wrapperRef }, children),
78
- arrows.map((direction) => (react_1.default.createElement("div", { key: direction, className: b('scroller', { type: direction }), onClick: (e) => this.handleScrollClick(e, direction) },
78
+ const paddingLeft = arrows.includes('left');
79
+ const paddingRight = arrows.includes('right');
80
+ return (react_1.default.createElement("div", { className: b('container', {
81
+ 'padding-left': paddingLeft,
82
+ 'padding-right': paddingRight,
83
+ }) },
84
+ react_1.default.createElement("div", { className: b(null, className), ref: this.containerRef },
85
+ react_1.default.createElement("div", { className: b('wrapper'), style: wrapperStyle, ref: this.wrapperRef }, children)),
86
+ arrows.map((direction) => (react_1.default.createElement("div", { key: direction, className: b('arrow', { type: direction }), onClick: (e) => this.handleScrollClick(e, direction) },
79
87
  react_1.default.createElement(__1.ToggleArrow, { size: 18, type: 'horizontal', iconType: "navigation" }))))));
80
88
  }
81
89
  }
@@ -4,13 +4,19 @@ export declare enum NavigationItemType {
4
4
  Link = "link",
5
5
  Dropdown = "dropdown",
6
6
  Button = "button",
7
- Social = "social"
7
+ Social = "social",
8
+ GithubStars = "github-stars"
8
9
  }
9
10
  export interface NavigationItemBase {
10
11
  text: string;
11
12
  icon?: ImageProps;
12
13
  url?: string;
13
14
  }
15
+ export interface NavigationGithubButton extends Omit<NavigationItemBase, 'icon'> {
16
+ type: NavigationItemType.GithubStars;
17
+ url: string;
18
+ label?: string;
19
+ }
14
20
  export interface NavigationLinkItem extends Omit<NavigationItemBase, 'url'> {
15
21
  type: NavigationItemType.Link;
16
22
  url: string;
@@ -29,8 +35,8 @@ export interface NavigationSocialItem extends Omit<NavigationItemBase, 'text'> {
29
35
  icon: ImageProps;
30
36
  url: string;
31
37
  }
32
- export type NavigationItemModel = NavigationLinkItem | NavigationButtonItem | NavigationDropdownItem;
33
- export type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | DropdownItemData;
38
+ export type NavigationItemModel = NavigationLinkItem | NavigationButtonItem | NavigationDropdownItem | NavigationGithubButton;
39
+ export type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | DropdownItemData | NavigationGithubButton;
34
40
  export type DropdownItemData = Omit<NavigationDropdownItem, 'items'>;
35
41
  export interface NavigationLogoData {
36
42
  icon: ImageProps;
@@ -7,4 +7,5 @@ var NavigationItemType;
7
7
  NavigationItemType["Dropdown"] = "dropdown";
8
8
  NavigationItemType["Button"] = "button";
9
9
  NavigationItemType["Social"] = "social";
10
+ NavigationItemType["GithubStars"] = "github-stars";
10
11
  })(NavigationItemType = exports.NavigationItemType || (exports.NavigationItemType = {}));
@@ -29,7 +29,6 @@ unpredictable css rules order in build */
29
29
  }
30
30
  .pc-header__navigation.pc-header__navigation {
31
31
  position: relative;
32
- margin-right: 20px;
33
32
  flex: 1 0 0;
34
33
  justify-content: flex-start;
35
34
  }
@@ -49,10 +48,11 @@ unpredictable css rules order in build */
49
48
  flex: 1 0 0;
50
49
  justify-content: space-between;
51
50
  align-items: center;
52
- margin-right: 20px;
51
+ margin-right: 32px;
53
52
  }
54
53
  .pc-header__buttons {
55
54
  display: flex;
55
+ align-items: center;
56
56
  }
57
57
  @media (max-width: 768px) {
58
58
  .pc-header__buttons {
@@ -47,7 +47,7 @@ const Header = ({ data, logo }) => {
47
47
  react_1.default.createElement(Navigation_1.default, { className: b('navigation'), links: leftItems, activeItemIndex: activeItemIndex, onActiveItemChange: onActiveItemChange })),
48
48
  react_1.default.createElement("div", { className: b('right') },
49
49
  react_1.default.createElement(MobileMenuButton, { isSidebarOpened: isSidebarOpened, onSidebarOpenedChange: onSidebarOpenedChange }),
50
- 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') })))))),
50
+ rightItems && (react_1.default.createElement("div", { className: b('buttons') }, rightItems.map((button) => (react_1.default.createElement(NavigationItem_1.default, { key: button.text, data: button })))))),
51
51
  react_1.default.createElement(OutsideClick_1.default, { onOutsideClick: () => onSidebarOpenedChange(false) },
52
52
  react_1.default.createElement(MobileNavigation_1.default, { topItems: leftItems, bottomItems: rightItems, isOpened: isSidebarOpened, activeItemIndex: activeItemIndex, onActiveItemChange: onActiveItemChange, onClose: hideSidebar })))))));
53
53
  };
@@ -1,41 +1,6 @@
1
- /* use this for style redefinitions to awoid problems with
2
- unpredictable css rules order in build */
3
1
  .pc-navigation-item {
4
2
  position: relative;
5
3
  display: flex;
6
4
  align-items: center;
7
5
  white-space: nowrap;
8
- }
9
- .pc-navigation-item_type_link {
10
- color: var(--yc-color-text-primary);
11
- color: inherit;
12
- text-decoration: none;
13
- outline: none;
14
- }
15
- .utilityfocus .pc-navigation-item_type_link:focus {
16
- outline: 2px solid #ffdb4d;
17
- }
18
- .pc-navigation-item_type_link:hover, .pc-navigation-item_type_link_active {
19
- color: var(--yc-color-text-link);
20
- }
21
- .pc-navigation-item_type_button {
22
- display: inline-block;
23
- }
24
- .pc-navigation-item__arrow {
25
- position: relative;
26
- top: -2px;
27
- width: 9px;
28
- height: 9px;
29
- margin-left: 5px;
30
- }
31
- .pc-navigation-item__icon {
32
- display: flex;
33
- width: 20px;
34
- height: 20px;
35
- margin-right: 8px;
36
- object-fit: cover;
37
- }
38
- .pc-navigation-item__dropdown {
39
- margin-left: 7px;
40
- color: var(--yc-color-text-secondary);
41
6
  }
@@ -3,57 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const react_1 = tslib_1.__importStar(require("react"));
5
5
  const utils_1 = require("../../../utils");
6
- const components_1 = require("../../../components");
7
- const locationContext_1 = require("../../../context/locationContext");
8
6
  const models_1 = require("../../../models");
9
- const icons_1 = require("../../../icons");
10
7
  const SocialIcon_1 = tslib_1.__importDefault(require("../SocialIcon/SocialIcon"));
11
- const utils_2 = require("../../../components/Media/Image/utils");
8
+ const NavigationButton_1 = require("./components/NavigationButton/NavigationButton");
9
+ const NavigationDropdown_1 = require("./components/NavigationDropdown/NavigationDropdown");
10
+ const NavigationLink_1 = require("./components/NavigationLink/NavigationLink");
11
+ const GithubStars_1 = require("./components/GithubStars/GithubStars");
12
12
  const b = (0, utils_1.block)('navigation-item');
13
- const Content = ({ text, icon }) => (react_1.default.createElement(react_1.Fragment, null,
14
- icon && typeof icon !== 'string' && react_1.default.createElement(components_1.Image, Object.assign({ className: b('icon') }, icon)),
15
- react_1.default.createElement("span", { className: b('text') }, text)));
16
- const NavigationDropdown = (_a) => {
17
- var { text, icon, isOpened } = _a, props = tslib_1.__rest(_a, ["text", "icon", "isOpened"]);
18
- const iconData = icon && (0, utils_2.getMediaImage)(icon);
19
- return (react_1.default.createElement("span", Object.assign({}, props),
20
- react_1.default.createElement(Content, { text: text, icon: iconData }),
21
- react_1.default.createElement(components_1.ToggleArrow, { className: b('dropdown'), size: 12, type: 'vertical', iconType: "navigation", open: isOpened })));
22
- };
23
- const NavigationLink = (props) => {
24
- const { hostname, Link } = (0, react_1.useContext)(locationContext_1.LocationContext);
25
- const { url, text, icon, arrow, target } = props, rest = tslib_1.__rest(props, ["url", "text", "icon", "arrow", "target"]);
26
- const linkExtraProps = (0, utils_1.getLinkProps)(url, hostname, target);
27
- const iconData = icon && (0, utils_2.getMediaImage)(icon);
28
- const content = (react_1.default.createElement(react_1.Fragment, null,
29
- react_1.default.createElement(Content, { text: text, icon: iconData }),
30
- arrow && react_1.default.createElement(icons_1.NavigationArrow, { className: b('arrow') })));
31
- if ((linkExtraProps === null || linkExtraProps === void 0 ? void 0 : linkExtraProps.target) || !Link) {
32
- return (react_1.default.createElement("a", Object.assign({ href: url, title: text }, rest, linkExtraProps), content));
33
- }
34
- else {
35
- return (react_1.default.createElement(components_1.RouterLink, { href: url, passHref: true },
36
- react_1.default.createElement("a", Object.assign({}, rest), content)));
37
- }
38
- };
39
- const NavigationButton = (props) => {
40
- const { url, target } = props;
41
- return target ? (react_1.default.createElement(components_1.Button, Object.assign({}, props, { url: url }))) : (react_1.default.createElement(components_1.RouterLink, { href: url },
42
- react_1.default.createElement(components_1.Button, Object.assign({}, props, { url: url }))));
43
- };
44
13
  //todo: add types support form component in map
45
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
15
  const NavigationItemsMap = {
47
- [models_1.NavigationItemType.Button]: NavigationButton,
16
+ [models_1.NavigationItemType.Button]: NavigationButton_1.NavigationButton,
48
17
  [models_1.NavigationItemType.Social]: SocialIcon_1.default,
49
- [models_1.NavigationItemType.Dropdown]: NavigationDropdown,
50
- [models_1.NavigationItemType.Link]: NavigationLink,
18
+ [models_1.NavigationItemType.Dropdown]: NavigationDropdown_1.NavigationDropdown,
19
+ [models_1.NavigationItemType.Link]: NavigationLink_1.NavigationLink,
20
+ [models_1.NavigationItemType.GithubStars]: GithubStars_1.GithubStars,
51
21
  };
52
22
  const NavigationItem = (_a) => {
53
23
  var { data, className } = _a, props = tslib_1.__rest(_a, ["data", "className"]);
54
24
  const { type = models_1.NavigationItemType.Link } = data;
55
25
  const Component = NavigationItemsMap[type];
56
- const componentProps = (0, react_1.useMemo)(() => (Object.assign(Object.assign({ className: b({ type }, className) }, data), props)), [className, data, props, type]);
26
+ const componentProps = (0, react_1.useMemo)(() => (Object.assign(Object.assign({ className: b(null, className) }, data), props)), [className, data, props]);
57
27
  return react_1.default.createElement(Component, Object.assign({}, componentProps));
58
28
  };
59
29
  exports.default = NavigationItem;
@@ -0,0 +1,7 @@
1
+ .pc-content-wrapper__icon {
2
+ display: flex;
3
+ width: 20px;
4
+ height: 20px;
5
+ margin-right: 8px;
6
+ object-fit: cover;
7
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { ImageProps } from '../../../../../models';
3
+ export declare const ContentWrapper: React.FC<{
4
+ text: string;
5
+ icon?: ImageProps;
6
+ }>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContentWrapper = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importStar(require("react"));
6
+ const utils_1 = require("../../../../../utils");
7
+ const components_1 = require("../../../../../components");
8
+ const b = (0, utils_1.block)('content-wrapper');
9
+ const ContentWrapper = ({ text, icon }) => (react_1.default.createElement(react_1.Fragment, null,
10
+ icon && typeof icon !== 'string' && react_1.default.createElement(components_1.Image, Object.assign({ className: b('icon') }, icon)),
11
+ react_1.default.createElement("span", { className: b('text') }, text)));
12
+ exports.ContentWrapper = ContentWrapper;
@@ -0,0 +1,10 @@
1
+ .pc-github-stars {
2
+ display: flex;
3
+ align-items: center;
4
+ height: 100%;
5
+ }
6
+ .pc-github-stars span {
7
+ display: flex;
8
+ flex-direction: column;
9
+ justify-content: center;
10
+ }
@@ -0,0 +1,5 @@
1
+ import { NavigationItemProps } from '../../NavigationItem';
2
+ import { NavigationGithubButton } from '../../../../../models';
3
+ type NavigationGithubButtonProps = NavigationItemProps & NavigationGithubButton;
4
+ export declare const GithubStars: ({ text, url, className, label }: NavigationGithubButtonProps) => JSX.Element;
5
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GithubStars = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const react_github_btn_1 = tslib_1.__importDefault(require("react-github-btn"));
7
+ const utils_1 = require("../../../../../utils");
8
+ const b = (0, utils_1.block)('github-stars');
9
+ const GithubStars = ({ text, url, className, label }) => (react_1.default.createElement("div", { className: b(null, className) },
10
+ react_1.default.createElement(react_github_btn_1.default, { href: url, "data-show-count": "true", "aria-label": label || 'Stars on GitHub' }, text)));
11
+ exports.GithubStars = GithubStars;
@@ -0,0 +1,3 @@
1
+ .pc-navigation-button {
2
+ display: inline-block;
3
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { ButtonProps } from '../../../../../models';
3
+ import { NavigationItemProps } from '../../NavigationItem';
4
+ type NavigationButtonProps = Pick<NavigationItemProps, 'className'> & ButtonProps;
5
+ export declare const NavigationButton: React.FC<NavigationButtonProps>;
6
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NavigationButton = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const utils_1 = require("../../../../../utils");
7
+ const components_1 = require("../../../../../components");
8
+ const b = (0, utils_1.block)('navigation-button');
9
+ const NavigationButton = (props) => {
10
+ const { url, target, className } = props;
11
+ const classes = b(null, className);
12
+ return target ? (react_1.default.createElement(components_1.Button, Object.assign({ className: classes }, props, { url: url }))) : (react_1.default.createElement(components_1.RouterLink, { href: url },
13
+ react_1.default.createElement(components_1.Button, Object.assign({}, props, { className: classes, url: url }))));
14
+ };
15
+ exports.NavigationButton = NavigationButton;
@@ -0,0 +1,4 @@
1
+ .pc-navigation-dropdown {
2
+ margin-left: 7px;
3
+ color: var(--yc-color-text-secondary);
4
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { NavigationItemProps } from '../../NavigationItem';
3
+ import { DropdownItemData } from '../../../../../models';
4
+ type NavigationDropdownProps = NavigationItemProps & DropdownItemData;
5
+ export declare const NavigationDropdown: React.FC<NavigationDropdownProps>;
6
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NavigationDropdown = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const ContentWrapper_1 = require("../ContentWrapper/ContentWrapper");
7
+ const components_1 = require("../../../../../components");
8
+ const utils_1 = require("../../../../../utils");
9
+ const utils_2 = require("../../../../../components/Media/Image/utils");
10
+ const b = (0, utils_1.block)('navigation-dropdown');
11
+ const TOGGLE_ARROW_SIZE = 12;
12
+ const NavigationDropdown = (_a) => {
13
+ var { text, icon, isOpened } = _a, props = tslib_1.__rest(_a, ["text", "icon", "isOpened"]);
14
+ const iconData = icon && (0, utils_2.getMediaImage)(icon);
15
+ return (react_1.default.createElement("span", Object.assign({}, props),
16
+ react_1.default.createElement(ContentWrapper_1.ContentWrapper, { text: text, icon: iconData }),
17
+ react_1.default.createElement(components_1.ToggleArrow, { className: b(), size: TOGGLE_ARROW_SIZE, type: 'vertical', iconType: "navigation", open: isOpened })));
18
+ };
19
+ exports.NavigationDropdown = NavigationDropdown;
@@ -0,0 +1,21 @@
1
+ /* use this for style redefinitions to awoid problems with
2
+ unpredictable css rules order in build */
3
+ .pc-navigation-link {
4
+ color: var(--yc-color-text-primary);
5
+ color: inherit;
6
+ text-decoration: none;
7
+ outline: none;
8
+ }
9
+ .utilityfocus .pc-navigation-link:focus {
10
+ outline: 2px solid #ffdb4d;
11
+ }
12
+ .pc-navigation-link:hover, .pc-navigation-link_active {
13
+ color: var(--yc-color-text-link);
14
+ }
15
+ .pc-navigation-link__arrow {
16
+ position: relative;
17
+ top: -2px;
18
+ width: 9px;
19
+ height: 9px;
20
+ margin-left: 5px;
21
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { NavigationItemProps } from '../../NavigationItem';
3
+ import { NavigationLinkItem } from '../../../../../models';
4
+ type NavigationLinkProps = NavigationItemProps & NavigationLinkItem;
5
+ export declare const NavigationLink: React.FC<NavigationLinkProps>;
6
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NavigationLink = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importStar(require("react"));
6
+ const ContentWrapper_1 = require("../ContentWrapper/ContentWrapper");
7
+ const icons_1 = require("../../../../../icons");
8
+ const components_1 = require("../../../../../components");
9
+ const utils_1 = require("../../../../../utils");
10
+ const utils_2 = require("../../../../../components/Media/Image/utils");
11
+ const locationContext_1 = require("../../../../../context/locationContext");
12
+ const b = (0, utils_1.block)('navigation-link');
13
+ const NavigationLink = (props) => {
14
+ const { hostname, Link } = (0, react_1.useContext)(locationContext_1.LocationContext);
15
+ const { url, text, icon, arrow, target, className } = props, rest = tslib_1.__rest(props, ["url", "text", "icon", "arrow", "target", "className"]);
16
+ const linkExtraProps = (0, utils_1.getLinkProps)(url, hostname, target);
17
+ const iconData = icon && (0, utils_2.getMediaImage)(icon);
18
+ const classes = b(null, className);
19
+ const content = (react_1.default.createElement(react_1.Fragment, null,
20
+ react_1.default.createElement(ContentWrapper_1.ContentWrapper, { text: text, icon: iconData }),
21
+ arrow && react_1.default.createElement(icons_1.NavigationArrow, { className: b('arrow') })));
22
+ if ((linkExtraProps === null || linkExtraProps === void 0 ? void 0 : linkExtraProps.target) || !Link) {
23
+ return (react_1.default.createElement("a", Object.assign({ href: url, title: text, className: classes }, rest, linkExtraProps), content));
24
+ }
25
+ else {
26
+ return (react_1.default.createElement(components_1.RouterLink, { href: url, passHref: true },
27
+ react_1.default.createElement("a", Object.assign({}, rest, { className: classes }), content)));
28
+ }
29
+ };
30
+ exports.NavigationLink = NavigationLink;
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import BackLink from '../BackLink';
5
+ import { LocationContext } from '../../../context/locationContext';
6
+ const backLinkProps = {
7
+ url: '#',
8
+ title: 'Button Title',
9
+ theme: 'default',
10
+ size: 's',
11
+ className: 'customClassName',
12
+ shouldHandleBackAction: true,
13
+ onClick: () => { },
14
+ };
15
+ describe('BackLink', () => {
16
+ test('Default render', async () => {
17
+ render(React.createElement(BackLink, Object.assign({}, backLinkProps)));
18
+ const backLink = screen.getByRole('button');
19
+ expect(backLink).toBeInTheDocument();
20
+ });
21
+ test('Has custom class', async () => {
22
+ render(React.createElement(BackLink, Object.assign({}, backLinkProps)));
23
+ const backLink = screen.getByRole('button');
24
+ expect(backLink).toHaveClass(backLinkProps.className);
25
+ });
26
+ test('Should render <a /> tag', async () => {
27
+ render(React.createElement(BackLink, Object.assign({}, backLinkProps, { shouldHandleBackAction: false })));
28
+ const backLink = screen.getByRole('link');
29
+ expect(backLink).toBeVisible();
30
+ expect(backLink).toHaveAttribute('href', backLinkProps.url);
31
+ });
32
+ test('Should render title', async () => {
33
+ render(React.createElement(BackLink, Object.assign({}, backLinkProps)));
34
+ const backLink = screen.getByText(backLinkProps.title);
35
+ expect(backLink).toBeInTheDocument();
36
+ });
37
+ test('Call onClick', async () => {
38
+ const user = userEvent.setup();
39
+ const handleClick = jest.fn();
40
+ render(React.createElement(LocationContext.Provider, { value: { history: { push: jest.fn() } } },
41
+ React.createElement(BackLink, Object.assign({}, backLinkProps, { onClick: handleClick }))));
42
+ const backLink = screen.getByRole('button');
43
+ await user.click(backLink);
44
+ expect(handleClick).toHaveBeenCalledTimes(1);
45
+ });
46
+ test.each(new Array('s', 'm', 'l', 'xl'))('Render with given "%s" size', (size) => {
47
+ render(React.createElement(BackLink, Object.assign({}, backLinkProps, { size: size })));
48
+ const backLink = screen.getByRole('button');
49
+ expect(backLink).toHaveClass(`yc-button_size_${size}`);
50
+ });
51
+ test.each(new Array('default', 'special'))('Render with given "%s" theme', (theme) => {
52
+ const matchView = {
53
+ default: 'flat-secondary',
54
+ special: 'flat-contrast',
55
+ };
56
+ render(React.createElement(BackLink, Object.assign({}, backLinkProps, { theme: theme })));
57
+ const backLink = screen.getByRole('button');
58
+ expect(backLink).toHaveClass(`yc-button_view_${matchView[theme]}`);
59
+ });
60
+ });
@@ -1,3 +1,5 @@
1
+ /* use this for style redefinitions to awoid problems with
2
+ unpredictable css rules order in build */
1
3
  .pc-button-block__content {
2
4
  display: flex;
3
5
  align-items: center;
@@ -1,12 +1,24 @@
1
1
  .pc-overflow-scroller {
2
+ display: flex;
3
+ align-items: center;
2
4
  position: relative;
3
5
  overflow-x: hidden;
4
6
  }
7
+ .pc-overflow-scroller__container {
8
+ width: 100%;
9
+ position: relative;
10
+ }
11
+ .pc-overflow-scroller__container_padding-left {
12
+ padding-left: 24px;
13
+ }
14
+ .pc-overflow-scroller__container_padding-right {
15
+ padding-right: 24px;
16
+ }
5
17
  .pc-overflow-scroller__wrapper {
6
18
  position: relative;
7
- transition: left 0.3s;
19
+ transition: left 0.6s;
8
20
  }
9
- .pc-overflow-scroller__scroller {
21
+ .pc-overflow-scroller__arrow {
10
22
  position: absolute;
11
23
  z-index: 10;
12
24
  top: 0;
@@ -17,12 +29,11 @@
17
29
  height: calc(100% - 1px);
18
30
  cursor: pointer;
19
31
  color: var(--yc-color-text-secondary);
20
- background: linear-gradient(to left, var(--yc-color-base-background) 70%, var(--pc-transparent) 100%) no-repeat;
21
32
  }
22
- .pc-overflow-scroller__scroller_type_left {
33
+ .pc-overflow-scroller__arrow_type_left {
23
34
  left: 0;
24
35
  transform: rotate(180deg);
25
36
  }
26
- .pc-overflow-scroller__scroller_type_right {
37
+ .pc-overflow-scroller__arrow_type_right {
27
38
  right: 0;
28
39
  }
@@ -12,7 +12,7 @@ export interface OverflowScrollerState {
12
12
  }
13
13
  export default class OverflowScroller extends React.Component<PropsWithChildren<OverflowScrollerProps>, OverflowScrollerState> {
14
14
  state: {
15
- arrows: never[];
15
+ arrows: Arrow[];
16
16
  scrollValue: number;
17
17
  };
18
18
  containerRef: React.RefObject<HTMLDivElement>;
@@ -5,6 +5,7 @@ import { ToggleArrow } from '..';
5
5
  import './OverflowScroller.css';
6
6
  const b = block('overflow-scroller');
7
7
  const TRANSITION_TIME = 300;
8
+ const PADDING_SIZE = 24;
8
9
  export default class OverflowScroller extends React.Component {
9
10
  constructor() {
10
11
  super(...arguments);
@@ -28,7 +29,7 @@ export default class OverflowScroller extends React.Component {
28
29
  }
29
30
  }, 100);
30
31
  this.handleScrollClick = (e, arrow) => {
31
- const { scrollValue } = this.state;
32
+ const { scrollValue, arrows } = this.state;
32
33
  const { onScrollStart } = this.props;
33
34
  if (this.containerRef &&
34
35
  this.containerRef.current &&
@@ -37,8 +38,9 @@ export default class OverflowScroller extends React.Component {
37
38
  const containerWidth = this.containerRef.current.offsetWidth;
38
39
  const wrapperWidth = this.wrapperRef.current.offsetWidth;
39
40
  const hiddenWidth = arrow === 'right' ? wrapperWidth - (containerWidth + scrollValue) : scrollValue;
41
+ const padding = arrows.length > 1 && hiddenWidth + PADDING_SIZE > containerWidth ? PADDING_SIZE : 0;
40
42
  const delta = containerWidth > hiddenWidth ? hiddenWidth : containerWidth;
41
- const newScrollValue = arrow === 'right' ? scrollValue + delta : scrollValue - delta;
43
+ const newScrollValue = arrow === 'right' ? scrollValue + delta + padding : scrollValue - delta - padding;
42
44
  let newArrows = ['left', 'right'];
43
45
  if (newScrollValue + containerWidth >= wrapperWidth) {
44
46
  newArrows = ['left'];
@@ -71,9 +73,15 @@ export default class OverflowScroller extends React.Component {
71
73
  const { className, children } = this.props;
72
74
  const { arrows, scrollValue } = this.state;
73
75
  const wrapperStyle = arrows.length ? { left: -scrollValue } : { left: 0 };
74
- return (React.createElement("div", { className: b(null, className), ref: this.containerRef },
75
- React.createElement("div", { className: b('wrapper'), style: wrapperStyle, ref: this.wrapperRef }, children),
76
- arrows.map((direction) => (React.createElement("div", { key: direction, className: b('scroller', { type: direction }), onClick: (e) => this.handleScrollClick(e, direction) },
76
+ const paddingLeft = arrows.includes('left');
77
+ const paddingRight = arrows.includes('right');
78
+ return (React.createElement("div", { className: b('container', {
79
+ 'padding-left': paddingLeft,
80
+ 'padding-right': paddingRight,
81
+ }) },
82
+ React.createElement("div", { className: b(null, className), ref: this.containerRef },
83
+ React.createElement("div", { className: b('wrapper'), style: wrapperStyle, ref: this.wrapperRef }, children)),
84
+ arrows.map((direction) => (React.createElement("div", { key: direction, className: b('arrow', { type: direction }), onClick: (e) => this.handleScrollClick(e, direction) },
77
85
  React.createElement(ToggleArrow, { size: 18, type: 'horizontal', iconType: "navigation" }))))));
78
86
  }
79
87
  }
@@ -4,13 +4,19 @@ export declare enum NavigationItemType {
4
4
  Link = "link",
5
5
  Dropdown = "dropdown",
6
6
  Button = "button",
7
- Social = "social"
7
+ Social = "social",
8
+ GithubStars = "github-stars"
8
9
  }
9
10
  export interface NavigationItemBase {
10
11
  text: string;
11
12
  icon?: ImageProps;
12
13
  url?: string;
13
14
  }
15
+ export interface NavigationGithubButton extends Omit<NavigationItemBase, 'icon'> {
16
+ type: NavigationItemType.GithubStars;
17
+ url: string;
18
+ label?: string;
19
+ }
14
20
  export interface NavigationLinkItem extends Omit<NavigationItemBase, 'url'> {
15
21
  type: NavigationItemType.Link;
16
22
  url: string;
@@ -29,8 +35,8 @@ export interface NavigationSocialItem extends Omit<NavigationItemBase, 'text'> {
29
35
  icon: ImageProps;
30
36
  url: string;
31
37
  }
32
- export type NavigationItemModel = NavigationLinkItem | NavigationButtonItem | NavigationDropdownItem;
33
- export type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | DropdownItemData;
38
+ export type NavigationItemModel = NavigationLinkItem | NavigationButtonItem | NavigationDropdownItem | NavigationGithubButton;
39
+ export type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | DropdownItemData | NavigationGithubButton;
34
40
  export type DropdownItemData = Omit<NavigationDropdownItem, 'items'>;
35
41
  export interface NavigationLogoData {
36
42
  icon: ImageProps;
@@ -4,4 +4,5 @@ export var NavigationItemType;
4
4
  NavigationItemType["Dropdown"] = "dropdown";
5
5
  NavigationItemType["Button"] = "button";
6
6
  NavigationItemType["Social"] = "social";
7
+ NavigationItemType["GithubStars"] = "github-stars";
7
8
  })(NavigationItemType || (NavigationItemType = {}));
@@ -29,7 +29,6 @@ unpredictable css rules order in build */
29
29
  }
30
30
  .pc-header__navigation.pc-header__navigation {
31
31
  position: relative;
32
- margin-right: 20px;
33
32
  flex: 1 0 0;
34
33
  justify-content: flex-start;
35
34
  }
@@ -49,10 +48,11 @@ unpredictable css rules order in build */
49
48
  flex: 1 0 0;
50
49
  justify-content: space-between;
51
50
  align-items: center;
52
- margin-right: 20px;
51
+ margin-right: 32px;
53
52
  }
54
53
  .pc-header__buttons {
55
54
  display: flex;
55
+ align-items: center;
56
56
  }
57
57
  @media (max-width: 768px) {
58
58
  .pc-header__buttons {
@@ -44,7 +44,7 @@ export const Header = ({ data, logo }) => {
44
44
  React.createElement(Navigation, { className: b('navigation'), links: leftItems, activeItemIndex: activeItemIndex, onActiveItemChange: onActiveItemChange })),
45
45
  React.createElement("div", { className: b('right') },
46
46
  React.createElement(MobileMenuButton, { isSidebarOpened: isSidebarOpened, onSidebarOpenedChange: onSidebarOpenedChange }),
47
- rightItems && (React.createElement("div", { className: b('buttons') }, rightItems.map((button) => (React.createElement(NavigationItem, { key: button.text, data: button, className: b('button') })))))),
47
+ rightItems && (React.createElement("div", { className: b('buttons') }, rightItems.map((button) => (React.createElement(NavigationItem, { key: button.text, data: button })))))),
48
48
  React.createElement(OutsideClick, { onOutsideClick: () => onSidebarOpenedChange(false) },
49
49
  React.createElement(MobileNavigation, { topItems: leftItems, bottomItems: rightItems, isOpened: isSidebarOpened, activeItemIndex: activeItemIndex, onActiveItemChange: onActiveItemChange, onClose: hideSidebar })))))));
50
50
  };
@@ -1,41 +1,6 @@
1
- /* use this for style redefinitions to awoid problems with
2
- unpredictable css rules order in build */
3
1
  .pc-navigation-item {
4
2
  position: relative;
5
3
  display: flex;
6
4
  align-items: center;
7
5
  white-space: nowrap;
8
- }
9
- .pc-navigation-item_type_link {
10
- color: var(--yc-color-text-primary);
11
- color: inherit;
12
- text-decoration: none;
13
- outline: none;
14
- }
15
- .utilityfocus .pc-navigation-item_type_link:focus {
16
- outline: 2px solid #ffdb4d;
17
- }
18
- .pc-navigation-item_type_link:hover, .pc-navigation-item_type_link_active {
19
- color: var(--yc-color-text-link);
20
- }
21
- .pc-navigation-item_type_button {
22
- display: inline-block;
23
- }
24
- .pc-navigation-item__arrow {
25
- position: relative;
26
- top: -2px;
27
- width: 9px;
28
- height: 9px;
29
- margin-left: 5px;
30
- }
31
- .pc-navigation-item__icon {
32
- display: flex;
33
- width: 20px;
34
- height: 20px;
35
- margin-right: 8px;
36
- object-fit: cover;
37
- }
38
- .pc-navigation-item__dropdown {
39
- margin-left: 7px;
40
- color: var(--yc-color-text-secondary);
41
6
  }
@@ -1,45 +1,14 @@
1
1
  import { __rest } from "tslib";
2
- import React, { Fragment, useContext, useMemo } from 'react';
3
- import { block, getLinkProps } from '../../../utils';
4
- import { RouterLink, ToggleArrow, Button, Image } from '../../../components';
5
- import { LocationContext } from '../../../context/locationContext';
6
- import { NavigationItemType, } from '../../../models';
7
- import { NavigationArrow } from '../../../icons';
2
+ import React, { useMemo } from 'react';
3
+ import { block } from '../../../utils';
4
+ import { NavigationItemType } from '../../../models';
8
5
  import SocialIcon from '../SocialIcon/SocialIcon';
9
- import { getMediaImage } from '../../../components/Media/Image/utils';
6
+ import { NavigationButton } from './components/NavigationButton/NavigationButton';
7
+ import { NavigationDropdown } from './components/NavigationDropdown/NavigationDropdown';
8
+ import { NavigationLink } from './components/NavigationLink/NavigationLink';
9
+ import { GithubStars } from './components/GithubStars/GithubStars';
10
10
  import './NavigationItem.css';
11
11
  const b = block('navigation-item');
12
- const Content = ({ text, icon }) => (React.createElement(Fragment, null,
13
- icon && typeof icon !== 'string' && React.createElement(Image, Object.assign({ className: b('icon') }, icon)),
14
- React.createElement("span", { className: b('text') }, text)));
15
- const NavigationDropdown = (_a) => {
16
- var { text, icon, isOpened } = _a, props = __rest(_a, ["text", "icon", "isOpened"]);
17
- const iconData = icon && getMediaImage(icon);
18
- return (React.createElement("span", Object.assign({}, props),
19
- React.createElement(Content, { text: text, icon: iconData }),
20
- React.createElement(ToggleArrow, { className: b('dropdown'), size: 12, type: 'vertical', iconType: "navigation", open: isOpened })));
21
- };
22
- const NavigationLink = (props) => {
23
- const { hostname, Link } = useContext(LocationContext);
24
- const { url, text, icon, arrow, target } = props, rest = __rest(props, ["url", "text", "icon", "arrow", "target"]);
25
- const linkExtraProps = getLinkProps(url, hostname, target);
26
- const iconData = icon && getMediaImage(icon);
27
- const content = (React.createElement(Fragment, null,
28
- React.createElement(Content, { text: text, icon: iconData }),
29
- arrow && React.createElement(NavigationArrow, { className: b('arrow') })));
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 }))));
42
- };
43
12
  //todo: add types support form component in map
44
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
14
  const NavigationItemsMap = {
@@ -47,12 +16,13 @@ const NavigationItemsMap = {
47
16
  [NavigationItemType.Social]: SocialIcon,
48
17
  [NavigationItemType.Dropdown]: NavigationDropdown,
49
18
  [NavigationItemType.Link]: NavigationLink,
19
+ [NavigationItemType.GithubStars]: GithubStars,
50
20
  };
51
21
  const NavigationItem = (_a) => {
52
22
  var { data, className } = _a, props = __rest(_a, ["data", "className"]);
53
23
  const { type = NavigationItemType.Link } = data;
54
24
  const Component = NavigationItemsMap[type];
55
- const componentProps = useMemo(() => (Object.assign(Object.assign({ className: b({ type }, className) }, data), props)), [className, data, props, type]);
25
+ const componentProps = useMemo(() => (Object.assign(Object.assign({ className: b(null, className) }, data), props)), [className, data, props]);
56
26
  return React.createElement(Component, Object.assign({}, componentProps));
57
27
  };
58
28
  export default NavigationItem;
@@ -0,0 +1,7 @@
1
+ .pc-content-wrapper__icon {
2
+ display: flex;
3
+ width: 20px;
4
+ height: 20px;
5
+ margin-right: 8px;
6
+ object-fit: cover;
7
+ }
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { ImageProps } from '../../../../../models';
3
+ import './ContentWrapper.css';
4
+ export declare const ContentWrapper: React.FC<{
5
+ text: string;
6
+ icon?: ImageProps;
7
+ }>;
@@ -0,0 +1,8 @@
1
+ import React, { Fragment } from 'react';
2
+ import { block } from '../../../../../utils';
3
+ import { Image } from '../../../../../components';
4
+ import './ContentWrapper.css';
5
+ const b = block('content-wrapper');
6
+ export const ContentWrapper = ({ text, icon }) => (React.createElement(Fragment, null,
7
+ icon && typeof icon !== 'string' && React.createElement(Image, Object.assign({ className: b('icon') }, icon)),
8
+ React.createElement("span", { className: b('text') }, text)));
@@ -0,0 +1,10 @@
1
+ .pc-github-stars {
2
+ display: flex;
3
+ align-items: center;
4
+ height: 100%;
5
+ }
6
+ .pc-github-stars span {
7
+ display: flex;
8
+ flex-direction: column;
9
+ justify-content: center;
10
+ }
@@ -0,0 +1,6 @@
1
+ import { NavigationItemProps } from '../../NavigationItem';
2
+ import { NavigationGithubButton } from '../../../../../models';
3
+ import './GithubStars.css';
4
+ type NavigationGithubButtonProps = NavigationItemProps & NavigationGithubButton;
5
+ export declare const GithubStars: ({ text, url, className, label }: NavigationGithubButtonProps) => JSX.Element;
6
+ export {};
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import GitHubButton from 'react-github-btn';
3
+ import { block } from '../../../../../utils';
4
+ import './GithubStars.css';
5
+ const b = block('github-stars');
6
+ export const GithubStars = ({ text, url, className, label }) => (React.createElement("div", { className: b(null, className) },
7
+ React.createElement(GitHubButton, { href: url, "data-show-count": "true", "aria-label": label || 'Stars on GitHub' }, text)));
@@ -0,0 +1,3 @@
1
+ .pc-navigation-button {
2
+ display: inline-block;
3
+ }
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { ButtonProps } from '../../../../../models';
3
+ import { NavigationItemProps } from '../../NavigationItem';
4
+ import './NavigationButton.css';
5
+ type NavigationButtonProps = Pick<NavigationItemProps, 'className'> & ButtonProps;
6
+ export declare const NavigationButton: React.FC<NavigationButtonProps>;
7
+ export {};
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { block } from '../../../../../utils';
3
+ import { RouterLink, Button } from '../../../../../components';
4
+ import './NavigationButton.css';
5
+ const b = block('navigation-button');
6
+ export const NavigationButton = (props) => {
7
+ const { url, target, className } = props;
8
+ const classes = b(null, className);
9
+ return target ? (React.createElement(Button, Object.assign({ className: classes }, props, { url: url }))) : (React.createElement(RouterLink, { href: url },
10
+ React.createElement(Button, Object.assign({}, props, { className: classes, url: url }))));
11
+ };
@@ -0,0 +1,4 @@
1
+ .pc-navigation-dropdown {
2
+ margin-left: 7px;
3
+ color: var(--yc-color-text-secondary);
4
+ }
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { NavigationItemProps } from '../../NavigationItem';
3
+ import { DropdownItemData } from '../../../../../models';
4
+ import './NavigationDropdown.css';
5
+ type NavigationDropdownProps = NavigationItemProps & DropdownItemData;
6
+ export declare const NavigationDropdown: React.FC<NavigationDropdownProps>;
7
+ export {};
@@ -0,0 +1,16 @@
1
+ import { __rest } from "tslib";
2
+ import React from 'react';
3
+ import { ContentWrapper } from '../ContentWrapper/ContentWrapper';
4
+ import { ToggleArrow } from '../../../../../components';
5
+ import { block } from '../../../../../utils';
6
+ import { getMediaImage } from '../../../../../components/Media/Image/utils';
7
+ import './NavigationDropdown.css';
8
+ const b = block('navigation-dropdown');
9
+ const TOGGLE_ARROW_SIZE = 12;
10
+ export const NavigationDropdown = (_a) => {
11
+ var { text, icon, isOpened } = _a, props = __rest(_a, ["text", "icon", "isOpened"]);
12
+ const iconData = icon && getMediaImage(icon);
13
+ return (React.createElement("span", Object.assign({}, props),
14
+ React.createElement(ContentWrapper, { text: text, icon: iconData }),
15
+ React.createElement(ToggleArrow, { className: b(), size: TOGGLE_ARROW_SIZE, type: 'vertical', iconType: "navigation", open: isOpened })));
16
+ };
@@ -0,0 +1,21 @@
1
+ /* use this for style redefinitions to awoid problems with
2
+ unpredictable css rules order in build */
3
+ .pc-navigation-link {
4
+ color: var(--yc-color-text-primary);
5
+ color: inherit;
6
+ text-decoration: none;
7
+ outline: none;
8
+ }
9
+ .utilityfocus .pc-navigation-link:focus {
10
+ outline: 2px solid #ffdb4d;
11
+ }
12
+ .pc-navigation-link:hover, .pc-navigation-link_active {
13
+ color: var(--yc-color-text-link);
14
+ }
15
+ .pc-navigation-link__arrow {
16
+ position: relative;
17
+ top: -2px;
18
+ width: 9px;
19
+ height: 9px;
20
+ margin-left: 5px;
21
+ }
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { NavigationItemProps } from '../../NavigationItem';
3
+ import { NavigationLinkItem } from '../../../../../models';
4
+ import './NavigationLink.css';
5
+ type NavigationLinkProps = NavigationItemProps & NavigationLinkItem;
6
+ export declare const NavigationLink: React.FC<NavigationLinkProps>;
7
+ export {};
@@ -0,0 +1,27 @@
1
+ import { __rest } from "tslib";
2
+ import React, { Fragment, useContext } from 'react';
3
+ import { ContentWrapper } from '../ContentWrapper/ContentWrapper';
4
+ import { NavigationArrow } from '../../../../../icons';
5
+ import { RouterLink } from '../../../../../components';
6
+ import { block, getLinkProps } from '../../../../../utils';
7
+ import { getMediaImage } from '../../../../../components/Media/Image/utils';
8
+ import { LocationContext } from '../../../../../context/locationContext';
9
+ import './NavigationLink.css';
10
+ const b = block('navigation-link');
11
+ export const NavigationLink = (props) => {
12
+ const { hostname, Link } = useContext(LocationContext);
13
+ const { url, text, icon, arrow, target, className } = props, rest = __rest(props, ["url", "text", "icon", "arrow", "target", "className"]);
14
+ const linkExtraProps = getLinkProps(url, hostname, target);
15
+ const iconData = icon && getMediaImage(icon);
16
+ const classes = b(null, className);
17
+ const content = (React.createElement(Fragment, null,
18
+ React.createElement(ContentWrapper, { text: text, icon: iconData }),
19
+ arrow && React.createElement(NavigationArrow, { className: b('arrow') })));
20
+ if ((linkExtraProps === null || linkExtraProps === void 0 ? void 0 : linkExtraProps.target) || !Link) {
21
+ return (React.createElement("a", Object.assign({ href: url, title: text, className: classes }, rest, linkExtraProps), content));
22
+ }
23
+ else {
24
+ return (React.createElement(RouterLink, { href: url, passHref: true },
25
+ React.createElement("a", Object.assign({}, rest, { className: classes }), content)));
26
+ }
27
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "1.16.4",
3
+ "version": "1.18.0",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -49,6 +49,7 @@
49
49
  "@gravity-ui/i18n": "^1.0.0",
50
50
  "bem-cn-lite": "^4.0.0",
51
51
  "lodash": "^4.17.21",
52
+ "react-github-btn": "^1.4.0",
52
53
  "react-player": "^2.9.0",
53
54
  "react-slick": "^0.28.1",
54
55
  "react-spring": "^9.3.0",
@@ -4,13 +4,19 @@ export declare enum NavigationItemType {
4
4
  Link = "link",
5
5
  Dropdown = "dropdown",
6
6
  Button = "button",
7
- Social = "social"
7
+ Social = "social",
8
+ GithubStars = "github-stars"
8
9
  }
9
10
  export interface NavigationItemBase {
10
11
  text: string;
11
12
  icon?: ImageProps;
12
13
  url?: string;
13
14
  }
15
+ export interface NavigationGithubButton extends Omit<NavigationItemBase, 'icon'> {
16
+ type: NavigationItemType.GithubStars;
17
+ url: string;
18
+ label?: string;
19
+ }
14
20
  export interface NavigationLinkItem extends Omit<NavigationItemBase, 'url'> {
15
21
  type: NavigationItemType.Link;
16
22
  url: string;
@@ -29,8 +35,8 @@ export interface NavigationSocialItem extends Omit<NavigationItemBase, 'text'> {
29
35
  icon: ImageProps;
30
36
  url: string;
31
37
  }
32
- export type NavigationItemModel = NavigationLinkItem | NavigationButtonItem | NavigationDropdownItem;
33
- export type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | DropdownItemData;
38
+ export type NavigationItemModel = NavigationLinkItem | NavigationButtonItem | NavigationDropdownItem | NavigationGithubButton;
39
+ export type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | DropdownItemData | NavigationGithubButton;
34
40
  export type DropdownItemData = Omit<NavigationDropdownItem, 'items'>;
35
41
  export interface NavigationLogoData {
36
42
  icon: ImageProps;
@@ -7,4 +7,5 @@ var NavigationItemType;
7
7
  NavigationItemType["Dropdown"] = "dropdown";
8
8
  NavigationItemType["Button"] = "button";
9
9
  NavigationItemType["Social"] = "social";
10
+ NavigationItemType["GithubStars"] = "github-stars";
10
11
  })(NavigationItemType = exports.NavigationItemType || (exports.NavigationItemType = {}));
@@ -480,3 +480,13 @@ unpredictable css rules order in build */
480
480
  color: var(--yc-color-text-link);
481
481
  }
482
482
  }
483
+
484
+ @mixin monochromeButton() {
485
+ --yc-button-background-color: var(--pc-monochrome-button-background-color);
486
+ --yc-button-background-color-hover: var(--pc-monochrome-button-background-color-hover);
487
+ color: var(--pc-monochrome-button-color);
488
+
489
+ &:hover {
490
+ color: var(--pc-monochrome-button-color);
491
+ }
492
+ }