generated from egoist/ts-lib-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.ts
36 lines (32 loc) · 907 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { IconifyJSON } from "@iconify/types"
import plugin from "tailwindcss/plugin.js"
import { parseIconSet } from "@iconify/utils"
import { generateIconComponent, getIconCollections } from "./core"
export { getIconCollections }
export const iconsPlugin = ({
collections,
}: {
collections: Record<string, IconifyJSON>
}) => {
const components: Record<string, Record<string, string>> = {}
for (const prefix of Object.keys(collections)) {
const collection = collections[prefix]
parseIconSet(collection, (name, data) => {
if (!data) return
components[`${prefix}-${name}`] = generateIconComponent(data)
})
}
return plugin(({ matchComponents }) => {
matchComponents(
{
i: (value) => {
if (typeof value === "string") return components[value]
return value
},
},
{
values: components,
},
)
})
}