Skip to content

Commit dac7091

Browse files
authored
Merge pull request #186 from kevinweber/kw--grid-shorthand-span
Support "span" in CSS Grid shorthand
2 parents 07f2d52 + 6f24971 commit dac7091

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

modules/__tests__/createPrefixer-test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,16 @@ describe('Static Prefixer', () => {
526526
expect(prefix(input)).toEqual(output)
527527
})
528528

529+
it('should expand the shorthand column syntax with span', () => {
530+
const input = { gridColumn: '3 / span 1' }
531+
const output = {
532+
gridColumn: '3 / span 1',
533+
msGridColumn: 3,
534+
msGridColumnSpan: 1,
535+
}
536+
expect(prefix(input)).toEqual(output)
537+
})
538+
529539
it('should expand the shorthand row syntax', () => {
530540
const input = { gridRow: '2 / 7' }
531541
const output = {
@@ -536,11 +546,12 @@ describe('Static Prefixer', () => {
536546
expect(prefix(input)).toEqual(output)
537547
})
538548

539-
it('should not expand non-numerical values', () => {
549+
it('should expand the shorthand row syntax with span', () => {
540550
const input = { gridRow: '2 / span 3' }
541551
const output = {
542552
gridRow: '2 / span 3',
543553
msGridRow: 2,
554+
msGridRowSpan: 3,
544555
}
545556
expect(prefix(input)).toEqual(output)
546557
})

modules/plugins/grid.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ const propertyConverters = {
2222
if (isSimplePositionValue(value)) {
2323
style.msGridColumn = value
2424
} else {
25-
const [start, end] = value.split('/').map(position => +position)
26-
propertyConverters.gridColumnStart(start, style)
27-
propertyConverters.gridColumnEnd(end, style)
25+
const [start, end] = value.split('/')
26+
propertyConverters.gridColumnStart(+start, style)
27+
28+
const [maybeSpan, maybeNumber] = end.split(/ ?span /)
29+
if (maybeSpan === '') {
30+
propertyConverters.gridColumnEnd(+start + +maybeNumber, style)
31+
} else {
32+
propertyConverters.gridColumnEnd(+end, style)
33+
}
2834
}
2935
},
3036

@@ -45,9 +51,15 @@ const propertyConverters = {
4551
if (isSimplePositionValue(value)) {
4652
style.msGridRow = value
4753
} else {
48-
const [start, end] = value.split('/').map(position => +position)
49-
propertyConverters.gridRowStart(start, style)
50-
propertyConverters.gridRowEnd(end, style)
54+
const [start, end] = value.split('/')
55+
propertyConverters.gridRowStart(+start, style)
56+
57+
const [maybeSpan, maybeNumber] = end.split(/ ?span /)
58+
if (maybeSpan === '') {
59+
propertyConverters.gridRowEnd(+start + +maybeNumber, style)
60+
} else {
61+
propertyConverters.gridRowEnd(+end, style)
62+
}
5163
}
5264
},
5365

0 commit comments

Comments
 (0)