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

Commit 39c3a94

Browse files
authored
Support custom modifiers with double dashes (#164)
1 parent e68bfe2 commit 39c3a94

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

src/lib/generateRules.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,29 @@ function getClassNameFromSelector(selector) {
1616
// ['ring-offset-blue', '100']
1717
// ['ring-offset', 'blue-100']
1818
// ['ring', 'offset-blue-100']
19-
function* candidatePermutations(prefix, modifier = '') {
19+
function* candidatePermutations(candidate, lastIndex = Infinity) {
20+
if (lastIndex < 0) {
21+
return
22+
}
23+
2024
let dashIdx
2125

22-
if (modifier.endsWith(']')) {
23-
dashIdx = prefix.lastIndexOf('[') - 1
26+
if (candidate.endsWith(']')) {
27+
dashIdx = candidate.lastIndexOf('[') - 1
2428
} else {
25-
dashIdx = prefix.lastIndexOf('-')
29+
dashIdx = candidate.lastIndexOf('-', lastIndex)
2630
}
2731

2832
if (dashIdx < 0) {
2933
return
3034
}
3135

32-
modifier = [prefix.slice(dashIdx + 1), modifier].filter(Boolean).join('-')
33-
prefix = prefix.slice(0, dashIdx)
36+
let prefix = candidate.slice(0, dashIdx)
37+
let modifier = candidate.slice(dashIdx + 1)
3438

3539
yield [prefix, modifier]
3640

37-
yield* candidatePermutations(prefix, modifier)
41+
yield* candidatePermutations(candidate, dashIdx - 1)
3842
}
3943

4044
function applyPrefix(matches, context) {

tests/00-kitchen-sink.test.css

+3
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ div {
291291
.bg-gradient-to-r {
292292
background-image: linear-gradient(to right, var(--tw-gradient-stops));
293293
}
294+
.bg-hero--home-1 {
295+
background-image: url('/images/homepage-1.jpg');
296+
}
294297
.from-foo {
295298
--tw-gradient-from: #bada55;
296299
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to, rgba(186, 218, 85, 0));

tests/00-kitchen-sink.test.html

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<div class="focus:hover:font-light"></div>
4040
<div class="first:pt-0"></div>
4141
<div class="container"></div>
42+
<div class="bg-hero--home-1"></div>
4243
<div class="group-hover:opacity-100"></div>
4344
<div class="group-active:opacity-10"></div>
4445
<div class="sm:motion-safe:group-active:focus:opacity-10"></div>

tests/00-kitchen-sink.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ test('it works', () => {
2222
gradientColorStops: {
2323
foo: '#bada55',
2424
},
25+
backgroundImage: {
26+
'hero--home-1': "url('/images/homepage-1.jpg')",
27+
},
2528
},
2629
},
2730
plugins: [

0 commit comments

Comments
 (0)