Skip to content

Commit b02d282

Browse files
committed
Skip card box bottom padding when last element has margin
When the last content element in a card box has a custom bottom margin, the card's built-in bottom padding is suppressed to avoid double spacing. The card's margin and border radius at the end are preserved. REDMINE-21191
1 parent 0191f1d commit b02d282

6 files changed

Lines changed: 96 additions & 0 deletions

File tree

entry_types/scrolled/package/spec/frontend/Layout-spec.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,70 @@ describe('Layout', () => {
943943
expect(container.textContent).toEqual('1 2 ]');
944944
});
945945
});
946+
947+
describe('lastMarginBottom prop', () => {
948+
const LastMarginBox = function LastMarginBox({lastMarginBottom, children}) {
949+
return (
950+
<div>{children}{lastMarginBottom ? `(${lastMarginBottom})` : ''}</div>
951+
);
952+
};
953+
954+
it('passes lastMarginBottom of last item in two column variant', () => {
955+
const items = [
956+
{id: 1, type: 'probe', position: 'inline'},
957+
{id: 2, type: 'probe', position: 'inline', props: {marginBottom: 'lg'}},
958+
];
959+
const {container} = renderInEntry(
960+
<Layout sectionProps={{layout: 'left'}} items={items}>
961+
{(children, boxProps) => <LastMarginBox {...boxProps}>{children}</LastMarginBox>}
962+
</Layout>
963+
);
964+
965+
expect(container.textContent).toContain('(lg)');
966+
});
967+
968+
it('does not pass lastMarginBottom when last item has no margin in two column variant', () => {
969+
const items = [
970+
{id: 1, type: 'probe', position: 'inline', props: {marginBottom: 'lg'}},
971+
{id: 2, type: 'probe', position: 'inline'},
972+
];
973+
const {container} = renderInEntry(
974+
<Layout sectionProps={{layout: 'left'}} items={items}>
975+
{(children, boxProps) => <LastMarginBox {...boxProps}>{children}</LastMarginBox>}
976+
</Layout>
977+
);
978+
979+
expect(container.textContent).not.toContain('(');
980+
});
981+
982+
it('passes lastMarginBottom of last item in center variant', () => {
983+
const items = [
984+
{id: 1, type: 'probe', position: 'inline'},
985+
{id: 2, type: 'probe', position: 'inline', props: {marginBottom: 'md'}},
986+
];
987+
const {container} = renderInEntry(
988+
<Layout sectionProps={{layout: 'center'}} items={items}>
989+
{(children, boxProps) => <LastMarginBox {...boxProps}>{children}</LastMarginBox>}
990+
</Layout>
991+
);
992+
993+
expect(container.textContent).toContain('(md)');
994+
});
995+
996+
it('does not pass lastMarginBottom when last item has no margin in center variant', () => {
997+
const items = [
998+
{id: 1, type: 'probe', position: 'inline', props: {marginBottom: 'lg'}},
999+
{id: 2, type: 'probe', position: 'inline'},
1000+
];
1001+
const {container} = renderInEntry(
1002+
<Layout sectionProps={{layout: 'center'}} items={items}>
1003+
{(children, boxProps) => <LastMarginBox {...boxProps}>{children}</LastMarginBox>}
1004+
</Layout>
1005+
);
1006+
1007+
expect(container.textContent).not.toContain('(');
1008+
});
1009+
});
9461010
});
9471011

9481012
describe('floating items in centered variant', () => {

entry_types/scrolled/package/spec/frontend/foregroundBoxes/CardBoxWrapper-spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import '@testing-library/jest-dom/extend-expect';
44

55
import CardBoxWrapper from 'frontend/foregroundBoxes/CardBoxWrapper';
66

7+
import cardBoxStyles from 'frontend/foregroundBoxes/CardBoxWrapper.module.css';
78
import boundaryMarginStyles from 'frontend/foregroundBoxes/BoxBoundaryMargin.module.css';
89

910
describe('CardBoxWrapper', () => {
@@ -48,4 +49,28 @@ describe('CardBoxWrapper', () => {
4849
expect(container.firstChild).toHaveClass(boundaryMarginStyles.noBottomMargin);
4950
});
5051
});
52+
53+
describe('cardEnd padding', () => {
54+
it('does not have cardEndPadding class when lastMarginBottom is set', () => {
55+
const {container} = render(
56+
<CardBoxWrapper openStart={true} openEnd={false} lastMarginBottom="lg">
57+
Content
58+
</CardBoxWrapper>
59+
);
60+
61+
expect(container.firstChild).toHaveClass(cardBoxStyles.cardEnd);
62+
expect(container.firstChild).not.toHaveClass(cardBoxStyles.cardEndPadding);
63+
});
64+
65+
it('has cardEndPadding class when lastMarginBottom is not set', () => {
66+
const {container} = render(
67+
<CardBoxWrapper openStart={true} openEnd={false}>
68+
Content
69+
</CardBoxWrapper>
70+
);
71+
72+
expect(container.firstChild).toHaveClass(cardBoxStyles.cardEnd);
73+
expect(container.firstChild).toHaveClass(cardBoxStyles.cardEndPadding);
74+
});
75+
});
5176
});

entry_types/scrolled/package/src/frontend/foregroundBoxes/CardBoxWrapper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function className(props) {
4040
{[styles.blur]: props.cardSurfaceTransparency > 0},
4141
{[styles.cardStart]: !props.openStart},
4242
{[styles.cardEnd]: !props.openEnd},
43+
{[styles.cardEndPadding]: !props.openEnd && !props.lastMarginBottom},
4344
{[boundaryMarginStyles.noTopMargin]: props.atSectionStart},
4445
{[boundaryMarginStyles.noBottomMargin]: props.atSectionEnd}
4546
);

entry_types/scrolled/package/src/frontend/foregroundBoxes/CardBoxWrapper.module.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
.cardEnd {
3131
margin-bottom: 3em;
32+
}
33+
34+
.cardEndPadding {
3235
padding-bottom: 1.5em;
3336
}
3437

entry_types/scrolled/package/src/frontend/layouts/Center.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ function groupItems(items) {
8383

8484
function boxProps(groups, index, isContentPadded) {
8585
const group = groups[index];
86+
const lastItem = group.items[group.items.length - 1];
8687

8788
return {
8889
position: group.position,
8990
width: group.width,
9091
customMargin: group.customMargin,
92+
lastMarginBottom: lastItem.marginBottom,
9193
atSectionStart: index === 0 && !isContentPadded,
9294
atSectionEnd: index === groups.length - 1
9395
}

entry_types/scrolled/package/src/frontend/layouts/TwoColumn.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function renderItemGroup(props, box, key) {
8181
position: box.position,
8282
width: box.width,
8383
customMargin: box.customMargin,
84+
lastMarginBottom: box.items[box.items.length - 1].marginBottom,
8485
openStart: box.openStart,
8586
openEnd: box.openEnd,
8687
atSectionStart: box.atSectionStart,

0 commit comments

Comments
 (0)