Skip to content

Commit

Permalink
feat: pass props to custom resolver (#42)
Browse files Browse the repository at this point in the history
Co-authored-by: Nate Moore <[email protected]>
  • Loading branch information
germanz and natemoo-re authored Oct 20, 2022
1 parent 33dc49f commit ae0a7f7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-camels-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-icon": minor
---

Pass props to custom resolvers
6 changes: 6 additions & 0 deletions demo/src/icons/custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default async (name: string, { size }): Promise<string> => {
return `
<svg viewBox="0 0 ${size} ${size}">
<circle cx="${size / 2}" cy="${size / 2}" r="${size / 2}"/>
</svg>`;
};
12 changes: 9 additions & 3 deletions demo/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Icon } from 'astro-icon';
<p>The <code>Icon</code> component will optimize and inline any SVG file inside of <code>src/icons/</code></p>

<p>Alternatively, see <a href="/sprite">the Sprite method</a>.</p>

<article>
<h2>Local</h2>
<!-- This will inline your SVG directly -->
Expand All @@ -39,9 +39,15 @@ import { Icon } from 'astro-icon';
<article>
<h2>Custom remote source</h2>
<!-- Pull your icon from a custom remote source -->
<Icon size={24} pack="radix" name="github-logo" />
<Icon size={24} pack="radix" name="github-logo" />
</article>

<article>
<h2>Custom SVG resolver</h2>
<!-- Pull your icon from a custom remote source -->
<Icon size={24} pack="custom" name="circle" />
</article>

<article>
<h2>Local dependencies</h2>
<!-- Pull your icon from a local dependency -->
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default async function load(
if (typeof get === "undefined") {
get = getFromService.bind(null, pack);
}
const contents = await get(name);
const contents = await get(name, inputProps);
if (!contents) {
throw new Error(
`<Icon pack="${pack}" name="${name}" /> did not return an icon!`
Expand Down

2 comments on commit ae0a7f7

@vercel
Copy link

@vercel vercel bot commented on ae0a7f7 Oct 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

astroicon – ./packages/www/

astroicon-git-main-nmoo.vercel.app
astro-icon-www.vercel.app
astroicon-nmoo.vercel.app
www.astroicon.dev
astroicon.dev

@vercel
Copy link

@vercel vercel bot commented on ae0a7f7 Oct 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

api-astroicon – ./packages/service

api.astroicon.dev
api-astroicon-nmoo.vercel.app
api-astroicon-git-main-nmoo.vercel.app

Please sign in to comment.