Skip to content

Commit 03ab2ee

Browse files
authored
fix: resetPaddings for base-block (#756)
1 parent b6f4ddf commit 03ab2ee

File tree

7 files changed

+44
-18
lines changed

7 files changed

+44
-18
lines changed

src/components/BlockBase/BlockBase.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ $block: '.#{$ns}block-base';
1010

1111
@include block();
1212

13+
@include indents(&);
14+
1315
@include add-specificity(&) {
1416
@media only screen and (max-width: map-get($gridBreakpoints, 'sm')) {
1517
margin-top: $indentM;

src/components/BlockBase/BlockBase.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ const b = block('block-base');
1212
export type BlockBaseFullProps = BlockBaseProps & ClassNameProps & PropsWithChildren & QAProps;
1313

1414
const BlockBase = (props: BlockBaseFullProps) => {
15-
const {anchor, visible, children, className, resetPaddings, qa} = props;
15+
const {anchor, indent, visible, children, className, resetPaddings, qa} = props;
16+
17+
const {top, bottom} =
18+
indent || (resetPaddings ? {top: '0', bottom: '0'} : {top: 'l', bottom: 'l'});
1619

1720
return (
1821
<Col
19-
className={b({['reset-paddings']: resetPaddings}, className)}
22+
className={b(
23+
{['reset-paddings']: resetPaddings, indentTop: top, indentBottom: bottom},
24+
className,
25+
)}
2026
visible={visible}
2127
reset={true}
2228
qa={qa}

src/components/BlockBase/__tests__/BlockBase.test.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import {render, screen} from '@testing-library/react';
44

55
import {testCustomClassName} from '../../../../test-utils/shared/common';
66
import {qaIdByDefault} from '../../../components/Anchor/Anchor';
7-
import {GridColumnSize} from '../../../grid';
7+
import {GridColumnSize, IndentValue} from '../../../grid';
88
import {ClassNameProps, WithChildren} from '../../../models';
99
import BlockBase, {BlockBaseFullProps} from '../BlockBase';
1010

1111
const qa = 'block-base-component';
1212

13+
const indentValues: IndentValue[] = ['0', 'xs', 's', 'm', 'l', 'xl'];
14+
1315
type ComponentProps = WithChildren<BlockBaseFullProps & ClassNameProps>;
1416

1517
describe('BlockBase', () => {
@@ -57,4 +59,24 @@ describe('BlockBase', () => {
5759
expect(component).toBeInTheDocument();
5860
expect(component).toHaveAttribute('id', anchor.url);
5961
});
62+
63+
test.each(new Array<IndentValue>(...indentValues))(
64+
'render with given "%s" top indent',
65+
(indentValue) => {
66+
render(<BlockBase qa={qa} indent={{top: indentValue}} />);
67+
const component = screen.getByTestId(qa);
68+
69+
expect(component).toHaveClass(`pc-block-base_indentTop_${indentValue}`);
70+
},
71+
);
72+
73+
test.each(new Array<IndentValue>(...indentValues))(
74+
'render with given "%s" bottom indent',
75+
(indentValue) => {
76+
render(<BlockBase qa={qa} indent={{bottom: indentValue}} />);
77+
const component = screen.getByTestId(qa);
78+
79+
expect(component).toHaveClass(`pc-block-base_indentBottom_${indentValue}`);
80+
},
81+
);
6082
});

src/containers/PageConstructor/components/ConstructorBlock/ConstructorBlock.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,15 @@ export const ConstructorBlock: React.FC<WithChildren<ConstructorBlockProps>> = (
2424
data,
2525
children,
2626
}) => {
27-
const {type, indent} = data;
27+
const {type} = data;
2828
const blockBaseProps = useMemo(
29-
() => pick(data, ['anchor', 'visible', 'resetPaddings']),
29+
() => pick(data, ['anchor', 'visible', 'resetPaddings', 'indent']),
3030
[data],
3131
);
3232

33-
const {top, bottom} = indent || {top: 'l', bottom: 'l'};
34-
3533
return (
3634
<BlockDecoration type={type} index={index} {...blockBaseProps}>
37-
<BlockBase
38-
className={b({type, indentTop: top, indentBottom: bottom})}
39-
{...blockBaseProps}
40-
>
35+
<BlockBase className={b({type})} {...blockBaseProps}>
4136
{children}
4237
</BlockBase>
4338
</BlockDecoration>

src/grid/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ export interface GridColumnClassParams {
5858
justifyContent?: GridJustifyContent;
5959
reset?: boolean;
6060
}
61+
62+
export type IndentValue = '0' | 'xs' | 's' | 'm' | 'l' | 'xl';

src/models/constructor-items/blocks.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22

33
import {ButtonSize} from '@gravity-ui/uikit';
44

5-
import {GridColumnSize, GridColumnSizesType} from '../../grid/types';
5+
import {GridColumnSize, GridColumnSizesType, IndentValue} from '../../grid/types';
66
import {ThemeSupporting} from '../../utils';
77
import {AnalyticsEventsBase} from '../common';
88

@@ -73,6 +73,10 @@ export interface BlockBaseProps {
7373
visible?: GridColumnSize;
7474
/** @deprecated */
7575
resetPaddings?: boolean;
76+
indent?: {
77+
top?: IndentValue;
78+
bottom?: IndentValue;
79+
};
7680
qa?: string;
7781
}
7882

src/models/constructor.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ export interface Menu {
1616
title: string;
1717
}
1818

19-
export type ConstructorBlock = (ConstructorItem | CustomBlock) & {
20-
indent?: {
21-
top?: string;
22-
bottom?: string;
23-
};
24-
};
19+
export type ConstructorBlock = ConstructorItem | CustomBlock;
2520

2621
export interface PageContent extends Animatable {
2722
blocks: ConstructorBlock[];

0 commit comments

Comments
 (0)