Skip to content

Commit

Permalink
feat(desc): support desc svg tag. (#247)
Browse files Browse the repository at this point in the history
* feat(desc): support desc svg tag.

* Create curvy-lions-dream.md

---------

Co-authored-by: christinamartinez <[email protected]>
Co-authored-by: Nate Moore <[email protected]>
  • Loading branch information
3 people authored Nov 5, 2024
1 parent 4060744 commit fce07f1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/curvy-lions-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-icon": patch
---

Adds a `desc` prop shorthand which maps to the SVG `<desc>` tag, similar to `title`.
1 change: 1 addition & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ interface Props extends HTMLAttributes<"svg"> {
name: string;
"is:inline"?: boolean;
title?: string;
desc?: string;
size?: number | string;
width?: number | string;
height?: number | string;
Expand Down
4 changes: 3 additions & 1 deletion packages/core/components/Icon.astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Props extends HTMLAttributes<"svg"> {
name: Icon;
"is:inline"?: boolean;
title?: string;
desc?: string;
size?: number | string;
width?: number | string;
height?: number | string;
Expand All @@ -25,7 +26,7 @@ class AstroIconError extends Error {
}
const req = Astro.request;
const { name = "", title, "is:inline": inline = false, ...props } = Astro.props;
const { name = "", title, desc, "is:inline": inline = false, ...props } = Astro.props;
const map = cache.get(req) ?? new Map();
const i = map.get(name) ?? 0;
map.set(name, i + 1);
Expand Down Expand Up @@ -116,6 +117,7 @@ const normalizedBody = renderData.body;

<svg {...normalizedProps} data-icon={name}>
{title && <title>{title}</title>}
{desc && <desc>{desc}</desc>}
{
inline ? (
<Fragment id={id} set:html={normalizedBody} />
Expand Down
2 changes: 2 additions & 0 deletions packages/www/src/content/docs/guides/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ interface Props extends HTMLAttributes<"svg"> {
name: string;
/** Shorthand for including a <title>{props.title}</title> element in the SVG */
title?: string;
/** Shorthand for including a <desc>{props.desc}</desc> element in the SVG */
desc?: string;
/** Shorthand for setting width and height */
size?: number | string;
width?: number | string;
Expand Down

0 comments on commit fce07f1

Please sign in to comment.