Skip to content

Commit

Permalink
feat(UX-1021): Add inline icon previews for dart (#5)
Browse files Browse the repository at this point in the history
refactor: add getIconPreview
  • Loading branch information
thelukewalton authored Jul 4, 2024
1 parent ccb0e64 commit 1908294
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/fetch_icons/hash.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
684c4d8d5f5a51f3dabb8c0474ec81bf
17 changes: 16 additions & 1 deletion scripts/generators/generateFonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { webfont } from "webfont";
import { createFolder, getIconFileName } from "../utils/fileUtils.js";
import { writeFileSync } from "fs";

const GITHUB_URL = "https://raw.githubusercontent.com/ZebraDevs/zeta-icons/main/ouputs/png/";
/**
* Generates font files from optimized SVGs.
*
Expand Down Expand Up @@ -106,13 +107,27 @@ const buildFontFile = async (type: FontType, fontResult: GenerateFontResult, inp
* @returns {string} Dart definition line used in body of `Icons.dart`.
*/
function getDartIconDefinition(iconName: string, unicode: string, type: FontType | undefined): string {
const iconPreview = getIconPreview(iconName, type);

if (type == undefined) {
iconName = iconName.toSnakeCase();
} else {
iconName = getIconFileName(iconName, type);
}

return ` static const IconData ${iconName} = IconData(0x${unicode}, fontFamily: family${
return `${iconPreview}
static const IconData ${iconName} = IconData(0x${unicode}, fontFamily: family${
type?.capitalize() ?? ""
}, fontPackage: package);`;
}

function getIconPreview(iconName: string, type: FontType | undefined) {
const name_link = `${iconName}_${type === undefined ? "round" : type}`;
const readableName = iconName
.split("_")
.map((e) => e.capitalize())
.join(" ");
return ` /// <i> <img width='48' src="${GITHUB_URL}${name_link}.png"></br>${readableName} icon ${
type != undefined ? `(${type})` : ""
}</i>`;
}
1 change: 1 addition & 0 deletions scripts/generators/generatePNGs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const generatePNGs = (inputDir: string, outputDir: string, categories: st
const name = split.pop()?.slice(0, -3);
sharp(inputDir + "/" + cat + "/" + svg)
.resize(512)
.modulate({ lightness: 44 })
.png()
.toFile(outputDir + "/" + name + "png");
}
Expand Down
2 changes: 1 addition & 1 deletion test/data/documentResponse.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/data/generatedFontResponse.json

Large diffs are not rendered by default.

0 comments on commit 1908294

Please sign in to comment.