diff --git a/.changeset/stale-lines-hug.md b/.changeset/stale-lines-hug.md new file mode 100644 index 00000000..3cffd8db --- /dev/null +++ b/.changeset/stale-lines-hug.md @@ -0,0 +1,8 @@ +--- +"@tapsioss/react-icons": patch +"@tapsioss/web-icons": patch +"@tapsioss/icons": patch +--- + +Add preview of icons in JSDocs. + \ No newline at end of file diff --git a/packages/icons/scripts/build.ts b/packages/icons/scripts/build.ts index 9395961d..77d0a6be 100644 --- a/packages/icons/scripts/build.ts +++ b/packages/icons/scripts/build.ts @@ -30,9 +30,11 @@ type SVGPathInfo = { d: string; }; +// NOTE: In case of any changes, update this file too: `types/@tapsioss/icons.ts` type SVGIconInfo = { kebabName: string; pascalName: string; + dataUrl: string; paths: SVGPathInfo[]; }; @@ -100,10 +102,17 @@ const generatePaths = async () => { const name = toPascalCase(pathInfo.name, "-"); const shouldAttachComma = i !== 0; + const base64 = Buffer.from( + data.replace(" { { name: iconInfo.pascalName, paths: paths.join(""), + dataUrl: iconInfo.dataUrl, }, {}, { escape: v => v as string }, diff --git a/packages/react-icons/templates/react-icon.txt b/packages/react-icons/templates/react-icon.txt index e64c6330..70fc6b72 100644 --- a/packages/react-icons/templates/react-icon.txt +++ b/packages/react-icons/templates/react-icon.txt @@ -1,5 +1,16 @@ import BaseIcon, { type Props } from "./base-icon.ts"; +/** +* "{{name}}" Icon Component +* +* --- +* +* Preview: +* +* ![icon preview]({{dataUrl}}) +* +* @see https://tap30.github.io/web-components/icons +*/ const {{name}} = (props: Omit) => { const paths = <>{{paths}}; diff --git a/packages/web-icons/scripts/build.ts b/packages/web-icons/scripts/build.ts index 98f05c56..8f40ee6e 100644 --- a/packages/web-icons/scripts/build.ts +++ b/packages/web-icons/scripts/build.ts @@ -60,6 +60,7 @@ const generateComponents = async () => { name: iconInfo.pascalName, paths: paths.join(""), elementTag: iconInfo.kebabName, + dataUrl: iconInfo.dataUrl, }, {}, { escape: v => v as string }, diff --git a/packages/web-icons/templates/web-icon.txt b/packages/web-icons/templates/web-icon.txt index 5f48372e..978ddad1 100644 --- a/packages/web-icons/templates/web-icon.txt +++ b/packages/web-icons/templates/web-icon.txt @@ -1,5 +1,16 @@ import BaseIcon from "../base-icon.ts"; +/** +* "{{name}}" Icon Component +* +* --- +* +* Preview: +* +* ![icon preview]({{dataUrl}}) +* +* @see https://tap30.github.io/web-components/icons +*/ export class {{name}} extends BaseIcon { constructor() { super(); diff --git a/types/@tapsioss/icons.ts b/types/@tapsioss/icons.ts index 37f68b0f..852c4c79 100644 --- a/types/@tapsioss/icons.ts +++ b/types/@tapsioss/icons.ts @@ -5,9 +5,11 @@ type SVGPathInfo = { d: string; }; +// NOTE: In case of any changes, update this file too: `packages/icons/scripts/build.ts` type SVGIconInfo = { kebabName: string; pascalName: string; + dataUrl: string; paths: SVGPathInfo[]; };