Skip to content

Commit

Permalink
feat: extraProperties option (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban authored Oct 2, 2023
1 parent f186e03 commit 44b26c8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ test("generateComponent", () => {
{ icons: collections["mdi"], name: "home" },
{
scale: 1.5,
extraProperties: {
"-webkit-mask-size": "contain",
"-webkit-mask-position": "center",
},
},
),
).toMatchInlineSnapshot(`
{
"--svg": "url(\\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath fill='black' d='M10 20v-6h4v6h5v-8h3L12 3L2 12h3v8h5Z'/%3E%3C/svg%3E\\")",
"-webkit-mask": "no-repeat center / 100%",
"-webkit-mask-image": "var(--svg)",
"-webkit-mask-position": "center",
"-webkit-mask-size": "contain",
"background-color": "currentColor",
"display": "inline-block",
"height": "1.5em",
Expand Down
8 changes: 4 additions & 4 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IconifyIcon, IconifyJSON } from "@iconify/types"
import { getIconCSS, getIconData } from "@iconify/utils"
import { createRequire } from "module"
import { CollectionNames } from "../types"
import { GenerateOptions } from "./types"

declare const TSUP_FORMAT: "esm" | "cjs"
const req =
Expand Down Expand Up @@ -60,10 +61,6 @@ export const getIconCollections = (
return collections
}

export type GenerateOptions = {
scale: number
}

export const generateIconComponent = (
data: IconifyIcon,
options: GenerateOptions,
Expand All @@ -78,6 +75,9 @@ export const generateIconComponent = (
}
return ""
})
if (options.extraProperties) {
Object.assign(rules, options.extraProperties)
}
return rules
}

Expand Down
13 changes: 11 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
export interface IconsOptions {
export type GenerateOptions = {
/**
* Scale relative to the current font size (1em).
*
* @default 1
*/
scale?: number
/**
* Extra CSS properties applied to the generated CSS.
*
* @default `{}`
*/
extraProperties?: Record<string, string>
}

export type IconsOptions = {
/**
* Class prefix for matching icon rules.
*
* @default `i`
*/
prefix?: string
}
} & GenerateOptions

0 comments on commit 44b26c8

Please sign in to comment.