Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/stale-lines-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@tapsioss/react-icons": patch
"@tapsioss/web-icons": patch
"@tapsioss/icons": patch
---

Add preview of icons in JSDocs.

9 changes: 9 additions & 0 deletions packages/icons/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
};

Expand Down Expand Up @@ -100,10 +102,17 @@ const generatePaths = async () => {
const name = toPascalCase(pathInfo.name, "-");
const shouldAttachComma = i !== 0;

const base64 = Buffer.from(
data.replace("<svg", '<svg style="background: #ffffff;"'),
).toString("base64");

const dataUrl = `data:image/svg+xml;base64,${base64}`;

const iconInfo: SVGIconInfo = {
pascalName: name,
kebabName: pathInfo.name,
paths: pathsInfo,
dataUrl,
};

await fs.appendFile(
Expand Down
1 change: 1 addition & 0 deletions packages/icons/templates/entry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type SVGPathInfo = {
type SVGIconInfo = {
kebabName: string;
pascalName: string;
dataUrl: string;
paths: SVGPathInfo[];
};

Expand Down
1 change: 1 addition & 0 deletions packages/react-icons/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const generateComponents = async () => {
{
name: iconInfo.pascalName,
paths: paths.join(""),
dataUrl: iconInfo.dataUrl,
},
{},
{ escape: v => v as string },
Expand Down
11 changes: 11 additions & 0 deletions packages/react-icons/templates/react-icon.txt
Original file line number Diff line number Diff line change
@@ -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<Props, "children">) => {
const paths = <>{{paths}}</>;

Expand Down
1 change: 1 addition & 0 deletions packages/web-icons/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const generateComponents = async () => {
name: iconInfo.pascalName,
paths: paths.join(""),
elementTag: iconInfo.kebabName,
dataUrl: iconInfo.dataUrl,
},
{},
{ escape: v => v as string },
Expand Down
11 changes: 11 additions & 0 deletions packages/web-icons/templates/web-icon.txt
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 2 additions & 0 deletions types/@tapsioss/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
};

Expand Down