@gravity-ui/page-constructor 2.0.2 → 2.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.0.3](https://github.com/gravity-ui/page-constructor/compare/v2.0.2...v2.0.3) (2023-03-27)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **Tabs:** wrap tabs on desktop ([#237](https://github.com/gravity-ui/page-constructor/issues/237)) ([68dd965](https://github.com/gravity-ui/page-constructor/commit/68dd965b8d5ad9439f8c59211232911695c30fd3))
9
+
3
10
  ## [2.0.2](https://github.com/gravity-ui/page-constructor/compare/v2.0.1...v2.0.2) (2023-03-24)
4
11
 
5
12
 
@@ -16,18 +16,14 @@ unpredictable css rules order in build */
16
16
  .pc-filter-block__tabs {
17
17
  margin-bottom: 0;
18
18
  display: flex;
19
- flex-wrap: nowrap;
19
+ flex-wrap: wrap;
20
20
  justify-content: flex-start;
21
- overflow: auto;
22
21
  }
23
22
  .pc-filter-block__tabs_centered {
24
- display: flex;
25
23
  justify-content: center;
26
- flex-wrap: wrap;
27
24
  }
28
25
  @media (max-width: 769px) {
29
26
  .pc-filter-block__tabs {
30
- display: flex;
31
27
  flex-wrap: nowrap;
32
28
  justify-content: flex-start;
33
29
  overflow: auto;
@@ -16,18 +16,14 @@ unpredictable css rules order in build */
16
16
  .pc-tabs-block__tabs {
17
17
  margin-bottom: 20px;
18
18
  display: flex;
19
- flex-wrap: nowrap;
19
+ flex-wrap: wrap;
20
20
  justify-content: flex-start;
21
- overflow: auto;
22
21
  }
23
22
  .pc-tabs-block__tabs_centered {
24
- display: flex;
25
23
  justify-content: center;
26
- flex-wrap: wrap;
27
24
  }
28
25
  @media (max-width: 769px) {
29
26
  .pc-tabs-block__tabs {
30
- display: flex;
31
27
  flex-wrap: nowrap;
32
28
  justify-content: flex-start;
33
29
  overflow: auto;
@@ -3,6 +3,7 @@ export interface ButtonProps extends Omit<ButtonParams, 'url'> {
3
3
  className?: string;
4
4
  url?: string;
5
5
  onClick?: () => void;
6
+ qa?: string;
6
7
  }
7
8
  declare const Button: (props: ButtonProps) => JSX.Element;
8
9
  export default Button;
@@ -38,7 +38,7 @@ const Button = (props) => {
38
38
  let icon;
39
39
  let image = img && react_1.default.createElement("img", { className: b('image'), src: buttonImg.url, alt: buttonImg.alt });
40
40
  if (theme === 'github') {
41
- icon = react_1.default.createElement(uikit_1.Icon, { className: b('icon'), data: icons_1.Github, size: 24 });
41
+ icon = react_1.default.createElement(uikit_1.Icon, { className: b('icon'), data: icons_1.Github, size: 24, qa: utils_2.ICON_QA });
42
42
  image = undefined;
43
43
  }
44
44
  const buttonTheme = theme === 'scale' ? 'accent' : theme;
@@ -0,0 +1,91 @@
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 utils_1 = require("../utils");
8
+ const Button_1 = tslib_1.__importDefault(require("../Button"));
9
+ const qaId = 'button-component';
10
+ const buttonProps = {
11
+ text: 'Button Text',
12
+ url: 'https://github.com/gravity-ui/',
13
+ target: '_blank',
14
+ img: {
15
+ url: 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_1_light.svg',
16
+ position: 'left',
17
+ alt: 'alt-text',
18
+ },
19
+ };
20
+ const buttonViews = [
21
+ 'normal',
22
+ 'action',
23
+ 'outlined',
24
+ 'outlined-info',
25
+ 'outlined-danger',
26
+ 'raised',
27
+ 'flat',
28
+ 'flat-info',
29
+ 'flat-danger',
30
+ 'flat-secondary',
31
+ 'normal-contrast',
32
+ 'outlined-contrast',
33
+ 'flat-contrast',
34
+ 'github',
35
+ 'scale',
36
+ 'monochrome',
37
+ ];
38
+ describe('Button', () => {
39
+ test('render button by default', async () => {
40
+ (0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text }));
41
+ const button = react_2.screen.getByRole('button');
42
+ expect(button).toBeInTheDocument();
43
+ expect(button).toBeVisible();
44
+ expect(button).not.toBeDisabled();
45
+ });
46
+ test('should render <a /> tag', async () => {
47
+ (0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, url: buttonProps.url, target: buttonProps.target }));
48
+ const button = react_2.screen.getByRole('link');
49
+ expect(button).toBeVisible();
50
+ expect(button).toHaveAttribute('href', buttonProps.url);
51
+ expect(button).toHaveAttribute('target', buttonProps.target);
52
+ });
53
+ test('call onClick', async () => {
54
+ const user = user_event_1.default.setup();
55
+ const handleOnClick = jest.fn();
56
+ (0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, onClick: handleOnClick }));
57
+ const button = react_2.screen.getByRole('button');
58
+ await user.click(button);
59
+ expect(handleOnClick).toHaveBeenCalledTimes(1);
60
+ });
61
+ test.each(new Array('s', 'm', 'l', 'xl'))('render with given "%s" size', (size) => {
62
+ (0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, size: size, qa: qaId }));
63
+ const button = react_2.screen.getByTestId(qaId);
64
+ expect(button).toHaveClass(`pc-button-block_size_${size}`);
65
+ });
66
+ test.each(new Array(...buttonViews))('render with given "%s" view', (theme) => {
67
+ (0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, theme: theme, qa: qaId }));
68
+ const button = react_2.screen.getByTestId(qaId);
69
+ expect(button).toHaveClass(`pc-button-block_theme_${theme}`);
70
+ });
71
+ test('add className', () => {
72
+ const className = 'my-class';
73
+ (0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, className: className, qa: qaId }));
74
+ const button = react_2.screen.getByTestId(qaId);
75
+ expect(button).toHaveClass(className);
76
+ });
77
+ test('should render icon', () => {
78
+ (0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, img: buttonProps.img }));
79
+ const button = react_2.screen.getByRole('button');
80
+ const iconComponent = react_2.screen.getByRole('img');
81
+ expect(iconComponent).toBeVisible();
82
+ expect(button).toContainElement(iconComponent);
83
+ });
84
+ test('should render github icon', () => {
85
+ (0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, img: buttonProps.img, theme: "github" }));
86
+ const button = react_2.screen.getByRole('button');
87
+ const iconComponent = react_2.screen.getByTestId(utils_1.ICON_QA);
88
+ expect(iconComponent).toBeVisible();
89
+ expect(button).toContainElement(iconComponent);
90
+ });
91
+ });
@@ -1,4 +1,5 @@
1
1
  import { ButtonSize, ButtonView } from '@gravity-ui/uikit';
2
+ export declare const ICON_QA = "button-icon";
2
3
  export type OldButtonTheme = 'normal' | 'action' | 'flat' | 'light' | 'clear' | 'raised' | 'pseudo' | 'link' | 'accent' | 'websearch' | 'flat-special' | 'normal-special' | 'normal-dark' | 'pseudo-special';
3
4
  export type OldButtonSize = 'xs' | 'ns' | 's' | 'm' | 'l' | 'n' | 'head' | 'promo';
4
5
  export declare const toCommonView: (theme: OldButtonTheme) => ButtonView;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toCommonSize = exports.toCommonView = void 0;
3
+ exports.toCommonSize = exports.toCommonView = exports.ICON_QA = void 0;
4
+ exports.ICON_QA = 'button-icon';
4
5
  const themeMap = {
5
6
  normal: 'normal',
6
7
  action: 'action',
@@ -130,20 +130,22 @@ export interface FileLinkProps extends ClassNameProps {
130
130
  theme?: ContentTheme;
131
131
  onClick?: () => void;
132
132
  }
133
+ export type ButtonTheme = ButtonView | 'github' | 'app-store' | 'google-play' | 'scale' | 'monochrome';
133
134
  export interface ButtonProps extends AnalyticsEventsBase {
134
135
  text: string;
135
136
  url: string;
136
137
  primary?: boolean;
137
138
  size?: ButtonSize;
138
- theme?: ButtonView | 'github' | 'app-store' | 'google-play' | 'scale' | 'monochrome';
139
+ theme?: ButtonTheme;
139
140
  img?: ButtonImageProps | string;
140
141
  metrikaGoals?: MetrikaGoal;
141
142
  pixelEvents?: ButtonPixel;
142
143
  target?: string;
143
144
  }
145
+ export type ButtonImagePosition = 'left' | 'right';
144
146
  export interface ButtonImageProps {
145
147
  url: string;
146
- position?: 'left' | 'right';
148
+ position?: ButtonImagePosition;
147
149
  alt?: string;
148
150
  }
149
151
  export interface PlayButtonProps extends ClassNameProps {
@@ -16,18 +16,14 @@ unpredictable css rules order in build */
16
16
  .pc-filter-block__tabs {
17
17
  margin-bottom: 0;
18
18
  display: flex;
19
- flex-wrap: nowrap;
19
+ flex-wrap: wrap;
20
20
  justify-content: flex-start;
21
- overflow: auto;
22
21
  }
23
22
  .pc-filter-block__tabs_centered {
24
- display: flex;
25
23
  justify-content: center;
26
- flex-wrap: wrap;
27
24
  }
28
25
  @media (max-width: 769px) {
29
26
  .pc-filter-block__tabs {
30
- display: flex;
31
27
  flex-wrap: nowrap;
32
28
  justify-content: flex-start;
33
29
  overflow: auto;
@@ -16,18 +16,14 @@ unpredictable css rules order in build */
16
16
  .pc-tabs-block__tabs {
17
17
  margin-bottom: 20px;
18
18
  display: flex;
19
- flex-wrap: nowrap;
19
+ flex-wrap: wrap;
20
20
  justify-content: flex-start;
21
- overflow: auto;
22
21
  }
23
22
  .pc-tabs-block__tabs_centered {
24
- display: flex;
25
23
  justify-content: center;
26
- flex-wrap: wrap;
27
24
  }
28
25
  @media (max-width: 769px) {
29
26
  .pc-tabs-block__tabs {
30
- display: flex;
31
27
  flex-wrap: nowrap;
32
28
  justify-content: flex-start;
33
29
  overflow: auto;
@@ -4,6 +4,7 @@ export interface ButtonProps extends Omit<ButtonParams, 'url'> {
4
4
  className?: string;
5
5
  url?: string;
6
6
  onClick?: () => void;
7
+ qa?: string;
7
8
  }
8
9
  declare const Button: (props: ButtonProps) => JSX.Element;
9
10
  export default Button;
@@ -3,7 +3,7 @@ import React, { useCallback, useContext } from 'react';
3
3
  import { Platform, Button as CommonButton, Icon, StoreBadge } from '@gravity-ui/uikit';
4
4
  import { block, setUrlTld } from '../../utils';
5
5
  import { DefaultEventNames } from '../../models';
6
- import { toCommonSize, toCommonView } from './utils';
6
+ import { toCommonSize, toCommonView, ICON_QA } from './utils';
7
7
  import { LocaleContext } from '../../context/localeContext/localeContext';
8
8
  import { useMetrika } from '../../hooks/useMetrika';
9
9
  import { useAnalytics } from '../../hooks';
@@ -37,7 +37,7 @@ const Button = (props) => {
37
37
  let icon;
38
38
  let image = img && React.createElement("img", { className: b('image'), src: buttonImg.url, alt: buttonImg.alt });
39
39
  if (theme === 'github') {
40
- icon = React.createElement(Icon, { className: b('icon'), data: Github, size: 24 });
40
+ icon = React.createElement(Icon, { className: b('icon'), data: Github, size: 24, qa: ICON_QA });
41
41
  image = undefined;
42
42
  }
43
43
  const buttonTheme = theme === 'scale' ? 'accent' : theme;
@@ -0,0 +1,88 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { ICON_QA } from '../utils';
5
+ import Button from '../Button';
6
+ const qaId = 'button-component';
7
+ const buttonProps = {
8
+ text: 'Button Text',
9
+ url: 'https://github.com/gravity-ui/',
10
+ target: '_blank',
11
+ img: {
12
+ url: 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_1_light.svg',
13
+ position: 'left',
14
+ alt: 'alt-text',
15
+ },
16
+ };
17
+ const buttonViews = [
18
+ 'normal',
19
+ 'action',
20
+ 'outlined',
21
+ 'outlined-info',
22
+ 'outlined-danger',
23
+ 'raised',
24
+ 'flat',
25
+ 'flat-info',
26
+ 'flat-danger',
27
+ 'flat-secondary',
28
+ 'normal-contrast',
29
+ 'outlined-contrast',
30
+ 'flat-contrast',
31
+ 'github',
32
+ 'scale',
33
+ 'monochrome',
34
+ ];
35
+ describe('Button', () => {
36
+ test('render button by default', async () => {
37
+ render(React.createElement(Button, { text: buttonProps.text }));
38
+ const button = screen.getByRole('button');
39
+ expect(button).toBeInTheDocument();
40
+ expect(button).toBeVisible();
41
+ expect(button).not.toBeDisabled();
42
+ });
43
+ test('should render <a /> tag', async () => {
44
+ render(React.createElement(Button, { text: buttonProps.text, url: buttonProps.url, target: buttonProps.target }));
45
+ const button = screen.getByRole('link');
46
+ expect(button).toBeVisible();
47
+ expect(button).toHaveAttribute('href', buttonProps.url);
48
+ expect(button).toHaveAttribute('target', buttonProps.target);
49
+ });
50
+ test('call onClick', async () => {
51
+ const user = userEvent.setup();
52
+ const handleOnClick = jest.fn();
53
+ render(React.createElement(Button, { text: buttonProps.text, onClick: handleOnClick }));
54
+ const button = screen.getByRole('button');
55
+ await user.click(button);
56
+ expect(handleOnClick).toHaveBeenCalledTimes(1);
57
+ });
58
+ test.each(new Array('s', 'm', 'l', 'xl'))('render with given "%s" size', (size) => {
59
+ render(React.createElement(Button, { text: buttonProps.text, size: size, qa: qaId }));
60
+ const button = screen.getByTestId(qaId);
61
+ expect(button).toHaveClass(`pc-button-block_size_${size}`);
62
+ });
63
+ test.each(new Array(...buttonViews))('render with given "%s" view', (theme) => {
64
+ render(React.createElement(Button, { text: buttonProps.text, theme: theme, qa: qaId }));
65
+ const button = screen.getByTestId(qaId);
66
+ expect(button).toHaveClass(`pc-button-block_theme_${theme}`);
67
+ });
68
+ test('add className', () => {
69
+ const className = 'my-class';
70
+ render(React.createElement(Button, { text: buttonProps.text, className: className, qa: qaId }));
71
+ const button = screen.getByTestId(qaId);
72
+ expect(button).toHaveClass(className);
73
+ });
74
+ test('should render icon', () => {
75
+ render(React.createElement(Button, { text: buttonProps.text, img: buttonProps.img }));
76
+ const button = screen.getByRole('button');
77
+ const iconComponent = screen.getByRole('img');
78
+ expect(iconComponent).toBeVisible();
79
+ expect(button).toContainElement(iconComponent);
80
+ });
81
+ test('should render github icon', () => {
82
+ render(React.createElement(Button, { text: buttonProps.text, img: buttonProps.img, theme: "github" }));
83
+ const button = screen.getByRole('button');
84
+ const iconComponent = screen.getByTestId(ICON_QA);
85
+ expect(iconComponent).toBeVisible();
86
+ expect(button).toContainElement(iconComponent);
87
+ });
88
+ });
@@ -1,4 +1,5 @@
1
1
  import { ButtonSize, ButtonView } from '@gravity-ui/uikit';
2
+ export declare const ICON_QA = "button-icon";
2
3
  export type OldButtonTheme = 'normal' | 'action' | 'flat' | 'light' | 'clear' | 'raised' | 'pseudo' | 'link' | 'accent' | 'websearch' | 'flat-special' | 'normal-special' | 'normal-dark' | 'pseudo-special';
3
4
  export type OldButtonSize = 'xs' | 'ns' | 's' | 'm' | 'l' | 'n' | 'head' | 'promo';
4
5
  export declare const toCommonView: (theme: OldButtonTheme) => ButtonView;
@@ -1,3 +1,4 @@
1
+ export const ICON_QA = 'button-icon';
1
2
  const themeMap = {
2
3
  normal: 'normal',
3
4
  action: 'action',
@@ -130,20 +130,22 @@ export interface FileLinkProps extends ClassNameProps {
130
130
  theme?: ContentTheme;
131
131
  onClick?: () => void;
132
132
  }
133
+ export type ButtonTheme = ButtonView | 'github' | 'app-store' | 'google-play' | 'scale' | 'monochrome';
133
134
  export interface ButtonProps extends AnalyticsEventsBase {
134
135
  text: string;
135
136
  url: string;
136
137
  primary?: boolean;
137
138
  size?: ButtonSize;
138
- theme?: ButtonView | 'github' | 'app-store' | 'google-play' | 'scale' | 'monochrome';
139
+ theme?: ButtonTheme;
139
140
  img?: ButtonImageProps | string;
140
141
  metrikaGoals?: MetrikaGoal;
141
142
  pixelEvents?: ButtonPixel;
142
143
  target?: string;
143
144
  }
145
+ export type ButtonImagePosition = 'left' | 'right';
144
146
  export interface ButtonImageProps {
145
147
  url: string;
146
- position?: 'left' | 'right';
148
+ position?: ButtonImagePosition;
147
149
  alt?: string;
148
150
  }
149
151
  export interface PlayButtonProps extends ClassNameProps {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -130,20 +130,22 @@ export interface FileLinkProps extends ClassNameProps {
130
130
  theme?: ContentTheme;
131
131
  onClick?: () => void;
132
132
  }
133
+ export type ButtonTheme = ButtonView | 'github' | 'app-store' | 'google-play' | 'scale' | 'monochrome';
133
134
  export interface ButtonProps extends AnalyticsEventsBase {
134
135
  text: string;
135
136
  url: string;
136
137
  primary?: boolean;
137
138
  size?: ButtonSize;
138
- theme?: ButtonView | 'github' | 'app-store' | 'google-play' | 'scale' | 'monochrome';
139
+ theme?: ButtonTheme;
139
140
  img?: ButtonImageProps | string;
140
141
  metrikaGoals?: MetrikaGoal;
141
142
  pixelEvents?: ButtonPixel;
142
143
  target?: string;
143
144
  }
145
+ export type ButtonImagePosition = 'left' | 'right';
144
146
  export interface ButtonImageProps {
145
147
  url: string;
146
- position?: 'left' | 'right';
148
+ position?: ButtonImagePosition;
147
149
  alt?: string;
148
150
  }
149
151
  export interface PlayButtonProps extends ClassNameProps {
@@ -518,18 +518,14 @@ unpredictable css rules order in build */
518
518
 
519
519
  @mixin tab-panel() {
520
520
  display: flex;
521
- flex-wrap: nowrap;
521
+ flex-wrap: wrap;
522
522
  justify-content: flex-start;
523
- overflow: auto;
524
523
 
525
524
  &_centered {
526
- display: flex;
527
525
  justify-content: center;
528
- flex-wrap: wrap;
529
526
  }
530
527
 
531
528
  @media (max-width: map-get($gridBreakpoints, 'md')) {
532
- display: flex;
533
529
  flex-wrap: nowrap;
534
530
  justify-content: flex-start;
535
531
  overflow: auto;