Skip to content

Commit

Permalink
Merge pull request #11 from author-more/feat/bootstrap-icons
Browse files Browse the repository at this point in the history
feat: add bootstrap icons
  • Loading branch information
Belar authored Sep 3, 2024
2 parents c1178fe + 6c2ff04 commit d3b4186
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 27 deletions.
20 changes: 16 additions & 4 deletions bin/config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
export const iconPackages = [
{
id: "lucide-regular",
id: "lucide",
variant: "regular",
iconsDir: "../node_modules/lucide-static/icons",
},
...["regular", "solid"].map((variant) => ({
id: `iconoir-${variant}`,
id: `iconoir`,
variant,
iconsDir: `../node_modules/iconoir/icons/${variant}`,
})),
...["bold", "duotone", "fill", "light", "regular", "thin"].map((variant) => ({
id: `phosphor-${variant}`,
id: `phosphor`,
variant,
iconsDir: `../node_modules/@phosphor-icons/core/assets/${variant}`,
})),
...["filled", "outlined", "round", "sharp", "two-tone"].map((variant) => ({
id: `material-design-${variant}`,
id: `material-design`,
variant,
iconsDir: `../node_modules/@material-design-icons/svg/${variant}`,
})),
{
id: "bootstrap",
getVariantFromIconName: (iconName: string) => {
if (iconName.endsWith("fill")) return "fill";
return "regular";
},
iconsDir: "../node_modules/bootstrap-icons/icons",
},
];
59 changes: 36 additions & 23 deletions bin/generateIconSets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,44 @@ type Icon = {
};
};

iconPackages.forEach(({ id, iconsDir }: (typeof iconPackages)[number]) => {
const files = getFilesByExtension(iconsDir, ".svg");

const icons: Record<string, Icon> = {};
for (const file of files) {
const svg = readFile(iconsDir, file);

const attributes = svg.match(/<svg([^>]*)>/)?.[1];
const elements = svg.match(/<svg[^>]*>([\s\S]*)<\/svg>/)?.[1];

if (!attributes || !elements) {
throw new Error(`Failed to parse the SVG: ${file}`);
iconPackages.forEach(
({
id,
iconsDir,
variant,
getVariantFromIconName,
}: (typeof iconPackages)[number]) => {
const files = getFilesByExtension(iconsDir, ".svg");

const icons: Record<string, Record<string, Icon>> = {};
for (const file of files) {
const svg = readFile(iconsDir, file);

const attributes = svg.match(/<svg([^>]*)>/)?.[1];
const elements = svg.match(/<svg[^>]*>([\s\S]*)<\/svg>/)?.[1];

if (!attributes || !elements) {
throw new Error(`Failed to parse the SVG: ${file}`);
}

const iconName = file.replace(".svg", "");
const variantName =
variant ?? getVariantFromIconName?.(iconName) ?? "regular";

icons[variantName] = icons[variantName] || {};
icons[variantName][iconName] = {
svg: {
attributes: normaliseWhitespace(attributes),
elements: normaliseWhitespace(elements),
},
};
}

const iconName = file.replace(".svg", "");
icons[iconName] = {
svg: {
attributes: normaliseWhitespace(attributes),
elements: normaliseWhitespace(elements),
},
};
}

writeToJSONFile("../data/icons", id, icons);
});
for (const [variantName, iconSet] of Object.entries(icons)) {
writeToJSONFile("../data/icons", `${id}-${variantName}`, iconSet);
}
},
);

function normaliseWhitespace(text: string): string {
return text
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@material-design-icons/svg": "^0.14.13",
"@penpot/plugin-styles": "^0.10.0",
"@phosphor-icons/core": "^2.1.1",
"bootstrap-icons": "^1.11.3",
"iconoir": "^7.8.0",
"lucide-react": "^0.427.0",
"lucide-static": "^0.427.0",
Expand Down
10 changes: 10 additions & 0 deletions src/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ export const iconLibraries: IconLibrary[] = [
},
defaultSettings: { selectedVariant: "outlined" },
},
{
id: "bootstrap",
name: "Bootstrap",
website: "https://icons.getbootstrap.com/",
license: {
name: "MIT",
url: "https://github.com/twbs/icons/blob/main/LICENSE",
},
icons: generateVariants("bootstrap", ["regular", "fill"]),
},
];

export const defaultIconSetSettings: Record<string, IconSetSettings> =
Expand Down

0 comments on commit d3b4186

Please sign in to comment.