Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass props to custom resolver #42

Merged
merged 2 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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