Skip to content

Commit 893f5c0

Browse files
committed
Add first-child and last-child variants
1 parent c9bba9d commit 893f5c0

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

__tests__/variantsAtRule.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,48 @@ test('it can generate focus-within variants', () => {
135135
})
136136
})
137137

138+
test('it can generate first-child variants', () => {
139+
const input = `
140+
@variants first-child {
141+
.banana { color: yellow; }
142+
.chocolate { color: brown; }
143+
}
144+
`
145+
146+
const output = `
147+
.banana { color: yellow; }
148+
.chocolate { color: brown; }
149+
.first-child\\:banana:first-child { color: yellow; }
150+
.first-child\\:chocolate:first-child { color: brown; }
151+
`
152+
153+
return run(input).then(result => {
154+
expect(result.css).toMatchCss(output)
155+
expect(result.warnings().length).toBe(0)
156+
})
157+
})
158+
159+
test('it can generate last-child variants', () => {
160+
const input = `
161+
@variants last-child {
162+
.banana { color: yellow; }
163+
.chocolate { color: brown; }
164+
}
165+
`
166+
167+
const output = `
168+
.banana { color: yellow; }
169+
.chocolate { color: brown; }
170+
.last-child\\:banana:last-child { color: yellow; }
171+
.last-child\\:chocolate:last-child { color: brown; }
172+
`
173+
174+
return run(input).then(result => {
175+
expect(result.css).toMatchCss(output)
176+
expect(result.warnings().length).toBe(0)
177+
})
178+
})
179+
138180
test('it can generate group-hover variants', () => {
139181
const input = `
140182
@variants group-hover {

src/lib/substituteVariantsAtRules.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const defaultVariantGenerators = {
3838
active: generatePseudoClassVariant('active'),
3939
visited: generatePseudoClassVariant('visited'),
4040
disabled: generatePseudoClassVariant('disabled'),
41+
'first-child': generatePseudoClassVariant('first-child'),
42+
'last-child': generatePseudoClassVariant('last-child'),
4143
}
4244

4345
export default function(config, { variantGenerators: pluginVariantGenerators }) {

0 commit comments

Comments
 (0)