From 03ab2eef46ebea2dbc0a277dce379362e91e80a1 Mon Sep 17 00:00:00 2001
From: Nik Tverd <61203447+niktverd@users.noreply.github.com>
Date: Fri, 15 Dec 2023 17:45:37 +0600
Subject: [PATCH] fix: resetPaddings for base-block (#756)
---
src/components/BlockBase/BlockBase.scss | 2 ++
src/components/BlockBase/BlockBase.tsx | 10 ++++++--
.../BlockBase/__tests__/BlockBase.test.tsx | 24 ++++++++++++++++++-
.../ConstructorBlock/ConstructorBlock.tsx | 11 +++------
src/grid/types.ts | 2 ++
src/models/constructor-items/blocks.ts | 6 ++++-
src/models/constructor.ts | 7 +-----
7 files changed, 44 insertions(+), 18 deletions(-)
diff --git a/src/components/BlockBase/BlockBase.scss b/src/components/BlockBase/BlockBase.scss
index 565884c30..01221dfc3 100644
--- a/src/components/BlockBase/BlockBase.scss
+++ b/src/components/BlockBase/BlockBase.scss
@@ -10,6 +10,8 @@ $block: '.#{$ns}block-base';
@include block();
+ @include indents(&);
+
@include add-specificity(&) {
@media only screen and (max-width: map-get($gridBreakpoints, 'sm')) {
margin-top: $indentM;
diff --git a/src/components/BlockBase/BlockBase.tsx b/src/components/BlockBase/BlockBase.tsx
index de9b07613..588b2b649 100644
--- a/src/components/BlockBase/BlockBase.tsx
+++ b/src/components/BlockBase/BlockBase.tsx
@@ -12,11 +12,17 @@ const b = block('block-base');
export type BlockBaseFullProps = BlockBaseProps & ClassNameProps & PropsWithChildren & QAProps;
const BlockBase = (props: BlockBaseFullProps) => {
- const {anchor, visible, children, className, resetPaddings, qa} = props;
+ const {anchor, indent, visible, children, className, resetPaddings, qa} = props;
+
+ const {top, bottom} =
+ indent || (resetPaddings ? {top: '0', bottom: '0'} : {top: 'l', bottom: 'l'});
return (
;
describe('BlockBase', () => {
@@ -57,4 +59,24 @@ describe('BlockBase', () => {
expect(component).toBeInTheDocument();
expect(component).toHaveAttribute('id', anchor.url);
});
+
+ test.each(new Array(...indentValues))(
+ 'render with given "%s" top indent',
+ (indentValue) => {
+ render();
+ const component = screen.getByTestId(qa);
+
+ expect(component).toHaveClass(`pc-block-base_indentTop_${indentValue}`);
+ },
+ );
+
+ test.each(new Array(...indentValues))(
+ 'render with given "%s" bottom indent',
+ (indentValue) => {
+ render();
+ const component = screen.getByTestId(qa);
+
+ expect(component).toHaveClass(`pc-block-base_indentBottom_${indentValue}`);
+ },
+ );
});
diff --git a/src/containers/PageConstructor/components/ConstructorBlock/ConstructorBlock.tsx b/src/containers/PageConstructor/components/ConstructorBlock/ConstructorBlock.tsx
index c10385d8f..3ca274fb5 100644
--- a/src/containers/PageConstructor/components/ConstructorBlock/ConstructorBlock.tsx
+++ b/src/containers/PageConstructor/components/ConstructorBlock/ConstructorBlock.tsx
@@ -24,20 +24,15 @@ export const ConstructorBlock: React.FC> = (
data,
children,
}) => {
- const {type, indent} = data;
+ const {type} = data;
const blockBaseProps = useMemo(
- () => pick(data, ['anchor', 'visible', 'resetPaddings']),
+ () => pick(data, ['anchor', 'visible', 'resetPaddings', 'indent']),
[data],
);
- const {top, bottom} = indent || {top: 'l', bottom: 'l'};
-
return (
-
+
{children}
diff --git a/src/grid/types.ts b/src/grid/types.ts
index 8b4766706..fbd017c6e 100644
--- a/src/grid/types.ts
+++ b/src/grid/types.ts
@@ -58,3 +58,5 @@ export interface GridColumnClassParams {
justifyContent?: GridJustifyContent;
reset?: boolean;
}
+
+export type IndentValue = '0' | 'xs' | 's' | 'm' | 'l' | 'xl';
diff --git a/src/models/constructor-items/blocks.ts b/src/models/constructor-items/blocks.ts
index 75337bb83..181863704 100644
--- a/src/models/constructor-items/blocks.ts
+++ b/src/models/constructor-items/blocks.ts
@@ -2,7 +2,7 @@ import React from 'react';
import {ButtonSize} from '@gravity-ui/uikit';
-import {GridColumnSize, GridColumnSizesType} from '../../grid/types';
+import {GridColumnSize, GridColumnSizesType, IndentValue} from '../../grid/types';
import {ThemeSupporting} from '../../utils';
import {AnalyticsEventsBase} from '../common';
@@ -73,6 +73,10 @@ export interface BlockBaseProps {
visible?: GridColumnSize;
/** @deprecated */
resetPaddings?: boolean;
+ indent?: {
+ top?: IndentValue;
+ bottom?: IndentValue;
+ };
qa?: string;
}
diff --git a/src/models/constructor.ts b/src/models/constructor.ts
index 7c1ef8a20..b38649f4a 100644
--- a/src/models/constructor.ts
+++ b/src/models/constructor.ts
@@ -16,12 +16,7 @@ export interface Menu {
title: string;
}
-export type ConstructorBlock = (ConstructorItem | CustomBlock) & {
- indent?: {
- top?: string;
- bottom?: string;
- };
-};
+export type ConstructorBlock = ConstructorItem | CustomBlock;
export interface PageContent extends Animatable {
blocks: ConstructorBlock[];