Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 990586b

Browse files
authored
feat(layout-gap): add x/y options for grid mode (#1234)
1 parent 6d0cd00 commit 990586b

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

src/apps/demo-app/src/app/layout/layout-gap/layout-gap.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const DIRECTIONS = ['row', 'row-reverse', 'column', 'column-reverse'];
1313
<div fxFlexFill>
1414
<div fxFlexFill
1515
[fxLayout]="direction + ' wrap'"
16-
fxLayoutGap="10px grid"
16+
fxLayoutGap="10px 5px grid"
1717
style="cursor: pointer;"
1818
(click)="toggleDirection()">
1919
<div fxFlex="25">

src/lib/flex/layout-gap/layout-gap.spec.ts

+21
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,27 @@ describe('layout-gap directive', () => {
509509
expectNativeEl(fixture).toHaveStyle(expectedMargin, styler);
510510
});
511511

512+
it('should add gap styles correctly between option', () => {
513+
let template = `
514+
<div fxLayoutGap='13px 12px grid'>
515+
<div fxFlex></div>
516+
<div fxFlex></div>
517+
<div fxFlex></div>
518+
</div>
519+
`;
520+
createTestComponent(template);
521+
fixture.detectChanges();
522+
523+
let nodes = queryFor(fixture, '[fxFlex]');
524+
let expectedMargin = {'margin': '0px -13px -12px 0px'};
525+
let expectedPadding = {'padding': '0px 13px 12px 0px'};
526+
expect(nodes.length).toEqual(3);
527+
expectEl(nodes[0]).toHaveStyle(expectedPadding, styler);
528+
expectEl(nodes[1]).toHaveStyle(expectedPadding, styler);
529+
expectEl(nodes[2]).toHaveStyle(expectedPadding, styler);
530+
expectNativeEl(fixture).toHaveStyle(expectedMargin, styler);
531+
});
532+
512533
it('should set gap without fallback', () => {
513534
let template = `
514535
<div fxLayoutAlign='center center' fxLayoutGap.md="24px grid">

src/lib/flex/layout-gap/layout-gap.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -252,27 +252,32 @@ const layoutGapCacheColumnLtr: Map<string, StyleDefinition> = new Map();
252252
const GRID_SPECIFIER = ' grid';
253253

254254
function buildGridPadding(value: string, directionality: string): StyleDefinition {
255-
let paddingTop = '0px', paddingRight = '0px', paddingBottom = value, paddingLeft = '0px';
255+
const [between, below] = value.split(' ');
256+
const bottom = below || between;
257+
let paddingRight = '0px', paddingBottom = bottom, paddingLeft = '0px';
256258

257259
if (directionality === 'rtl') {
258-
paddingLeft = value;
260+
paddingLeft = between;
259261
} else {
260-
paddingRight = value;
262+
paddingRight = between;
261263
}
262264

263-
return {'padding': `${paddingTop} ${paddingRight} ${paddingBottom} ${paddingLeft}`};
265+
return {'padding': `0px ${paddingRight} ${paddingBottom} ${paddingLeft}`};
264266
}
265267

266268
function buildGridMargin(value: string, directionality: string): StyleDefinition {
267-
let marginTop = '0px', marginRight = '0px', marginBottom = '-' + value, marginLeft = '0px';
269+
const [between, below] = value.split(' ');
270+
const bottom = below || between;
271+
const minus = (str: string) => `-${str}`;
272+
let marginRight = '0px', marginBottom = minus(bottom), marginLeft = '0px';
268273

269274
if (directionality === 'rtl') {
270-
marginLeft = '-' + value;
275+
marginLeft = minus(between);
271276
} else {
272-
marginRight = '-' + value;
277+
marginRight = minus(between);
273278
}
274279

275-
return {'margin': `${marginTop} ${marginRight} ${marginBottom} ${marginLeft}`};
280+
return {'margin': `0px ${marginRight} ${marginBottom} ${marginLeft}`};
276281
}
277282

278283
function getMarginType(directionality: string, layout: string) {

0 commit comments

Comments
 (0)