Skip to content

Commit 81d0213

Browse files
committed
Moved icons to component layer
This is more accurate and also allows them to be. auto sorted at the beginning of the class list by the official class name sorter
1 parent 1a03828 commit 81d0213

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ export function createPluginIcons(options: IconsOptions = {}): PluginCreator {
3636
return JSON.parse(svg)
3737
}
3838

39-
return function ({ matchUtilities }) {
39+
return function ({ matchComponents }) {
4040
const _prefix = (options.prefix || 'i-').replace(/-$/, '')
4141

42-
matchUtilities({
42+
matchComponents({
4343
[_prefix]: (value: string) => getCSS(value, 'def'),
4444
[_prefix + '-bg']: (value: string) => getCSS(value, 'bg'),
4545
[_prefix + '-auto']: (value: string) => getCSS(value, 'auto'),

tests/index.test.js

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const iconsPlugin = require('../dist/index.js')
33
const postcss = require('postcss')
44
const tailwindcss = require('tailwindcss')
55

6-
function run(config, css = '@tailwind utilities', plugin = tailwindcss) {
6+
function run(config, css = '@tailwind components', plugin = tailwindcss) {
77
let { currentTestName } = expect.getState()
88
config = {
99
...{
@@ -25,36 +25,25 @@ it('makesIcon', () => {
2525
content: [{ raw: String.raw`<div class="i-[carbon-add]"></div>` }],
2626
}
2727

28-
return run(config, '@tailwind base; @tailwind utilities').then(result => {
29-
const h1 = String.raw`--tw-icon`
30-
const width = String.raw`width: 1em; height: 1em`
28+
return run(config).then(result => {
29+
const icon = String.raw`--tw-icon`
30+
const width = String.raw`width: 1em;
31+
height: 1em`
3132

32-
expect(result.css).toContain(h1)
33+
expect(result.css).toContain(icon)
3334
expect(result.css).toContain(width)
3435
})
3536
})
3637

37-
it('makesIcon', () => {
38-
const config = {
39-
content: [{ raw: String.raw`<div class="i-[carbon-add]"></div>` }],
40-
}
41-
42-
return run(config, '@tailwind base; @tailwind utilities').then(result => {
43-
const h1 = String.raw`--tw-icon`
44-
45-
expect(result.css).toContain(h1)
46-
})
47-
})
48-
4938
it('ignoresBadIcons', () => {
5039
const config = {
5140
content: [{ raw: String.raw`<div class="i-[carbon-ad]"></div>` }],
5241
}
5342

54-
return run(config, '@tailwind base; @tailwind utilities').then(result => {
55-
const h1 = String.raw`--tw-icon`
43+
return run(config).then(result => {
44+
const icon = String.raw`--tw-icon`
5645

57-
expect(result.css).toEqual(expect.not.stringContaining(h1))
46+
expect(result.css).toEqual(expect.not.stringContaining(icon))
5847
})
5948
})
6049

@@ -63,11 +52,11 @@ it('makesBgIcon', () => {
6352
content: [{ raw: String.raw`<div class="i-bg-[carbon-add]"></div>` }],
6453
}
6554

66-
return run(config, '@tailwind base; @tailwind utilities').then(result => {
67-
const h1 = String.raw`--tw-icon`
55+
return run(config).then(result => {
56+
const icon = String.raw`--tw-icon`
6857
const bg = String.raw`background: url("data:image/svg+`
6958

70-
expect(result.css).toEqual(expect.not.stringContaining(h1))
59+
expect(result.css).toEqual(expect.not.stringContaining(icon))
7160
expect(result.css).toContain(bg)
7261
})
7362
})
@@ -80,8 +69,9 @@ it('usesUnits', () => {
8069
},
8170
}
8271

83-
return run(config, '@tailwind base; @tailwind utilities').then(result => {
84-
const width = String.raw`width: 1px; height: 1px`
72+
return run(config).then(result => {
73+
const width = String.raw`width: 1px;
74+
height: 1px`
8575
expect(result.css).toContain(width)
8676
})
8777
})
@@ -94,8 +84,9 @@ it('usesScale', () => {
9484
},
9585
}
9686

97-
return run(config, '@tailwind base; @tailwind utilities').then(result => {
98-
const width = String.raw`width: 1.2em; height: 1.2em`
87+
return run(config).then(result => {
88+
const width = String.raw`width: 1.2em;
89+
height: 1.2em`
9990
expect(result.css).toContain(width)
10091
})
10192
})
@@ -109,8 +100,9 @@ it('usesScaleAndUnits', () => {
109100
},
110101
}
111102

112-
return run(config, '@tailwind base; @tailwind utilities').then(result => {
113-
const width = String.raw`width: 20px; height: 20px`
103+
return run(config).then(result => {
104+
const width = String.raw`width: 20px;
105+
height: 20px`
114106
expect(result.css).toContain(width)
115107
})
116108
})

0 commit comments

Comments
 (0)