Skip to content

Commit

Permalink
Aside: Add support for icons attribute.
Browse files Browse the repository at this point in the history
Only built-icons will be supported for now. This commit does not
add support for the `:::` markdown shorthand for defining an aside,
that will be done in the next commit.
  • Loading branch information
shubham-padia committed Aug 27, 2024
1 parent 4825271 commit 5ff47bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/src/content/docs/guides/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ Other content is also supported in asides.
</Aside>

<Aside type="danger">Do not give your password to anyone.</Aside>

<Aside icon="heart">
Aside with a custom icon. The icon must be part of starlight's icon list.
</Aside>
````

The above code generates the following on the page:
Expand All @@ -306,6 +310,10 @@ Other content is also supported in asides.

<Aside type="danger">Do not give your password to anyone.</Aside>

<Aside icon="heart">
Aside with a custom icon. The icon must be part of starlight's icon list.
</Aside>

Starlight also provides a custom syntax for rendering asides in Markdown and MDX as an alternative to the `<Aside>` component.
See the [“Authoring Content in Markdown”](/guides/authoring-content/#asides) guide for details of the custom syntax.

Expand Down
4 changes: 2 additions & 2 deletions packages/starlight/user-components/Aside.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Props {
title?: string;
}
let { type = 'note', title } = Astro.props;
let { type = 'note', title, icon } = Astro.props;
if (!asideVariants.includes(type)) {
throw new AstroError(
Expand All @@ -30,7 +30,7 @@ if (!title) {

<aside aria-label={title} class={`starlight-aside starlight-aside--${type}`}>
<p class="starlight-aside__title" aria-hidden="true">
<Icon name={icons[type]} class="starlight-aside__icon" />{title}
<Icon name={icon || icons[type]} class="starlight-aside__icon" />{title}
</p>
<section class="starlight-aside__content">
<slot />
Expand Down

0 comments on commit 5ff47bc

Please sign in to comment.