Skip to content

Commit

Permalink
[grid-template-areas] Repetitive grid-area declarations (#983)
Browse files Browse the repository at this point in the history
* [grid-template-areas] Add test for repetitive grid-area declarations

* [grid-template-areas] Fix prefixing of repetitive grid-area declarations
  • Loading branch information
yepninja authored and ai committed Feb 9, 2018
1 parent 15a54ab commit aaecf3b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
13 changes: 8 additions & 5 deletions lib/hacks/grid-template-areas.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,20 @@ class GridTemplateAreas extends Declaration {
if (prefix !== '-ms-') return super.insert(decl, prefix, prefixes);

const areas = parseGridAreas(decl.value);
let missed = Object.keys(areas);

this.getRoot(decl.parent).walkDecls('grid-area', gridArea => {
const value = gridArea.value;
const area = areas[value];
delete areas[value];

if (gridArea.parent.some(i => i.prop === '-ms-grid-row')) {
return undefined;
}
missed = missed.filter(e => e !== value);

if (area) {
gridArea.parent
.walkDecls(/-ms-grid-(row|column)/, (d) => {
d.remove();
});

gridArea.cloneBefore({
prop: '-ms-grid-row',
value: String(area.row.start)
Expand All @@ -92,7 +96,6 @@ class GridTemplateAreas extends Declaration {
return undefined;
});

const missed = Object.keys(areas);
if (missed.length > 0) {
decl.warn(result, 'Can not find grid areas: ' + missed.join(', '));
}
Expand Down
11 changes: 10 additions & 1 deletion test/cases/grid-template-areas.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
grid-template-areas:
"head head"
"nav main"
"nav foot";
"nav foot"
"another";
}

.b {
Expand All @@ -21,6 +22,10 @@
grid-area: foot;
}

.f {
grid-area: foot;
}

@media (max-width: 1000px) {
.a {
grid-template-areas: "head main";
Expand All @@ -33,4 +38,8 @@
.c {
grid-area: main;
}

.d {
grid-area: main;
}
}
15 changes: 14 additions & 1 deletion test/cases/grid-template-areas.out.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
grid-template-areas:
"head head"
"nav main"
"nav foot";
"nav foot"
"another";
}

.b {
Expand Down Expand Up @@ -31,6 +32,12 @@
grid-area: foot;
}

.f {
-ms-grid-row: 3;
-ms-grid-column: 2;
grid-area: foot;
}

@media (max-width: 1000px) {
.a {
grid-template-areas: "head main";
Expand All @@ -47,4 +54,10 @@
-ms-grid-column: 2;
grid-area: main;
}

.d {
-ms-grid-row: 1;
-ms-grid-column: 2;
grid-area: main;
}
}

0 comments on commit aaecf3b

Please sign in to comment.